1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-03 13:12:11 +02:00
ComfyFactorio/maps/dungeons/functions.lua

123 lines
4.0 KiB
Lua
Raw Normal View History

2020-04-04 19:07:08 +02:00
local Public = {}
local BiterRaffle = require "functions.biter_raffle"
2020-04-05 00:05:13 +02:00
local LootRaffle = require "functions.loot_raffle"
local table_shuffle_table = table.shuffle_table
2020-04-04 19:07:08 +02:00
local table_insert = table.insert
local table_remove = table.remove
local math_random = math.random
local math_abs = math.abs
local math_floor = math.floor
function Public.roll_spawner_name()
if math_random(1, 3) == 1 then
return "spitter-spawner"
end
return "biter-spawner"
end
function Public.roll_worm_name()
2020-04-06 21:41:56 +02:00
return BiterRaffle.roll("worm", global.dungeons.depth * 0.001)
end
function Public.get_crude_oil_amount()
return math_random(200000, 400000) + global.dungeons.depth * 500
end
2020-04-06 21:41:56 +02:00
function Public.get_common_resource_amount()
return math_random(350, 650) + global.dungeons.depth * 10
end
2020-04-05 00:05:13 +02:00
function Public.common_loot_crate(surface, position)
2020-04-05 02:23:03 +02:00
local item_stacks = LootRaffle.roll(global.dungeons.depth * 2 + math_random(8, 16), 16)
2020-04-05 00:05:13 +02:00
local container = surface.create_entity({name = "wooden-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
2020-04-05 02:23:03 +02:00
function Public.uncommon_loot_crate(surface, position)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 4 + math_random(32, 64), 16)
2020-04-06 21:41:56 +02:00
local container = surface.create_entity({name = "iron-chest", position = position, force = "neutral"})
2020-04-05 02:23:03 +02:00
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
function Public.rare_loot_crate(surface, position)
2020-04-05 03:39:52 +02:00
local item_stacks = LootRaffle.roll(global.dungeons.depth * 8 + math_random(128, 256), 32)
2020-04-06 21:41:56 +02:00
local container = surface.create_entity({name = "steel-chest", position = position, force = "neutral"})
2020-04-05 02:23:03 +02:00
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
function Public.epic_loot_crate(surface, position)
2020-04-05 03:39:52 +02:00
local item_stacks = LootRaffle.roll(global.dungeons.depth * 16 + math_random(512, 1024), 48)
2020-04-05 02:23:03 +02:00
local container = surface.create_entity({name = "steel-chest", position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
2020-04-05 03:39:52 +02:00
function Public.crash_site_chest(surface, position)
local item_stacks = LootRaffle.roll(global.dungeons.depth * 6 + math_random(160, 320), 48)
local container = surface.create_entity({name = "crash-site-chest-" .. math_random(1, 2), position = position, force = "neutral"})
for _, item_stack in pairs(item_stacks) do
container.insert(item_stack)
end
end
2020-04-06 21:41:56 +02:00
function Public.set_spawner_tier(spawner)
local tier = math_floor(global.dungeons.depth * 0.005 - math_random(0, 5)) + 1
if tier < 1 then tier = 1 end
global.dungeons.spawner_tier[spawner.unit_number] = tier
--[[
rendering.draw_text{
text = "-Tier " .. tier .. "-",
surface = spawner.surface,
target = spawner,
target_offset = {0, -2.65},
color = {25, 0, 100, 255},
scale = 1.25,
font = "default-game",
alignment = "center",
scale_with_zoom = false
}
]]
end
2020-04-05 02:23:03 +02:00
function Public.spawn_random_biter(surface, position)
2020-04-06 21:41:56 +02:00
local name = BiterRaffle.roll("mixed", global.dungeons.depth * 0.0005)
2020-04-06 19:28:39 +02:00
local non_colliding_position = surface.find_non_colliding_position(name, position, 16, 1)
2020-04-06 21:41:56 +02:00
local unit
2020-04-06 19:28:39 +02:00
if non_colliding_position then
2020-04-06 21:41:56 +02:00
unit = surface.create_entity({name = name, position = non_colliding_position, force = "enemy"})
2020-04-06 19:28:39 +02:00
else
2020-04-06 21:41:56 +02:00
unit = surface.create_entity({name = name, position = position, force = "enemy"})
2020-04-06 19:28:39 +02:00
end
2020-04-06 21:41:56 +02:00
unit.ai_settings.allow_try_return_to_spawner = false
unit.ai_settings.allow_destroy_when_commands_fail = false
2020-04-05 02:23:03 +02:00
end
function Public.place_border_rock(surface, position)
local vectors = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}
table_shuffle_table(vectors)
local key = false
for k, v in pairs(vectors) do
local tile = surface.get_tile({position.x + v[1], position.y + v[2]})
if tile.name == "out-of-map" then
key = k
break
end
end
if not key then return end
local pos = {x = position.x + 0.5, y = position.y + 0.5}
pos = {pos.x + vectors[key][1] * 0.45, pos.y + vectors[key][2] * 0.45}
surface.create_entity({name = "rock-big", position = pos})
end
2020-04-04 19:07:08 +02:00
return Public