1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/maps/cave_miner_v2/functions.lua

99 lines
3.7 KiB
Lua
Raw Normal View History

2020-10-10 15:30:30 +02:00
local Public = {}
2020-10-10 05:52:47 +02:00
local Constants = require 'maps.cave_miner_v2.constants'
2020-10-10 15:30:30 +02:00
local BiterRaffle = require "functions.biter_raffle"
local LootRaffle = require "functions.loot_raffle"
2020-10-10 05:52:47 +02:00
2020-10-10 15:30:30 +02:00
local math_sqrt = math.sqrt
local math_random = math.random
2020-10-10 01:33:11 +02:00
function Public.spawn_player(player)
2020-10-10 05:52:47 +02:00
if not player.character then
player.create_character()
end
local surface = player.surface
2020-10-10 03:43:49 +02:00
local position
position = surface.find_non_colliding_position("character", player.force.get_spawn_position(surface), 48, 1)
if not position then position = player.force.get_spawn_position(surface) end
player.teleport(position, surface)
2020-10-10 05:52:47 +02:00
for name, count in pairs(Constants.starting_items) do
player.insert({name = name, count = count})
end
2020-10-10 01:33:11 +02:00
end
2020-10-10 03:43:49 +02:00
function Public.set_mining_speed(cave_miner, force)
2020-10-10 15:30:30 +02:00
force.manual_mining_speed_modifier = -0.50 + cave_miner.pickaxe_tier * 0.25
2020-10-10 03:43:49 +02:00
return force.manual_mining_speed_modifier
end
2020-10-10 15:30:30 +02:00
function Public.place_worm(surface, position, multiplier)
local d = math_sqrt(position.x ^ 2 + position.y ^ 2)
surface.create_entity({name = BiterRaffle.roll("worm", d * 0.0001 * multiplier), position = position, force = "enemy"})
return
end
function Public.spawn_random_biter(surface, position, multiplier)
local d = math_sqrt(position.x ^ 2 + position.y ^ 2)
local name = BiterRaffle.roll("mixed", d * 0.0001 * multiplier)
local non_colliding_position = surface.find_non_colliding_position(name, position, 16, 1)
local unit
if non_colliding_position then
unit = surface.create_entity({name = name, position = non_colliding_position, force = "enemy"})
else
unit = surface.create_entity({name = name, position = position, force = "enemy"})
end
unit.ai_settings.allow_try_return_to_spawner = true
unit.ai_settings.allow_destroy_when_commands_fail = false
2020-10-10 16:52:51 +02:00
return unit
2020-10-10 15:30:30 +02:00
end
function Public.loot_crate(surface, position, multiplier, slots, container_name)
local d = math_sqrt(position.x ^ 2 + position.y ^ 2)
local item_stacks = LootRaffle.roll(d * multiplier, slots, loot_blacklist)
local container = surface.create_entity({name = container_name, position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do container.insert(item_stack) end
container.minable = false
end
function Public.place_crude_oil(surface, position, multiplier)
if not surface.can_place_entity({name = "crude-oil", position = position, amount = 1}) then return end
local d = math_sqrt(position.x ^ 2 + position.y ^ 2)
local amount = math_random(100000, 200000) + d * 100 * multiplier
surface.create_entity({name = "crude-oil", position = position, amount = amount})
end
function Public.create_top_gui(player)
local frame = player.gui.top.cave_miner
if frame then return end
frame = player.gui.top.add({type = "frame", name = "cave_miner", direction = "horizontal"})
frame.style.maximal_height = 38
local label = frame.add({type = "label", caption = "Loading..."})
label.style.font = "heading-2"
label.style.font_color = {225, 225, 225}
label.style.margin = 0
label.style.padding = 0
local label = frame.add({type = "label", caption = "Loading..."})
label.style.font = "heading-2"
label.style.font_color = {225, 225, 225}
label.style.margin = 0
label.style.padding = 0
end
function Public.update_top_gui(cave_miner)
local pickaxe_tiers = Constants.pickaxe_tiers
for _, player in pairs(game.connected_players) do
local element = player.gui.top.cave_miner
if element and element.valid then
element.children[1].caption = "Tier: " .. pickaxe_tiers[cave_miner.pickaxe_tier] .. " | "
element.children[1].tooltip = "Mining speed " .. (1 + game.forces.player.manual_mining_speed_modifier) * 100 .. "%"
element.children[2].caption = "Rocks broken: " .. cave_miner.rocks_broken
end
end
end
2020-10-10 01:33:11 +02:00
return Public