1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-25 21:29:06 +02:00
This commit is contained in:
MewMew 2019-11-09 23:53:27 +01:00
parent c466ea9432
commit fb2ba1d49d
8 changed files with 913 additions and 38 deletions

View File

@ -70,7 +70,8 @@ require "modules.autostash"
--require "maps.mountain_fortress"
--require "maps.island_troopers.main"
--require "maps.biter_hatchery.main"
require "maps.scrapyard.main"
require "maps.junkyard_pvp.main"
--require "maps.scrapyard.main"
--require "maps.tank_conquest.tank_conquest"
--require "maps.territorial_control"
--require "maps.cave_choppy.cave_miner"

View File

@ -1,15 +1,8 @@
--deep jungle-- mewmew made this --
require "modules.railgun_enhancer"
require "modules.dynamic_landfill"
require "modules.spawners_contain_biters"
require "modules.biters_yield_coins"
require "modules.rocks_yield_coins"
require "modules.flashlight_toggle_button"
require "modules.splice_double"
require "modules.spitters_spit_biters"
require "modules.biters_double_hp"
require "modules.rocks_broken_paint_tiles"
require "modules.rocks_yield_ore"
local map_functions = require "tools.map_functions"
local simplex_noise = require 'utils.simplex_noise'
@ -203,6 +196,7 @@ local function get_noise(name, pos)
end
local rock_raffle = {"sand-rock-big","sand-rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
local tree_raffle = {"tree-04", "tree-07", "tree-09", "tree-06", "tree-04", "tree-07", "tree-09", "tree-04"}
local function process_tile(pos)
local noise_1 = get_noise(1, pos)
@ -221,11 +215,9 @@ local function process_tile(pos)
end
local noise_2 = get_noise(2, pos)
if noise_2 > 0.37 or noise_2 < -0.37 then
local tree_raffle = {"tree-04", "tree-07", "tree-09", "tree-06", "tree-04", "tree-07", "tree-09", "tree-04"}
if noise_2 > 0.37 or noise_2 < -0.37 then
if math_random(1, 4) == 1 then return false, tree_raffle[math.ceil(math.abs(noise_1 * 8))] end
end
end
local noise_3 = get_noise(3, pos)
if noise_3 > 0.5 then
if math_random(1,3) == 1 then return false, rock_raffle[math_random(1,#rock_raffle)] end
@ -311,25 +303,6 @@ end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not global.map_init_done then
local map_gen_settings = {}
map_gen_settings.water = "none"
map_gen_settings.starting_area = "normal"
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = "none", size = "none", richness = "none"},
["stone"] = {frequency = "none", size = "none", richness = "none"},
["copper-ore"] = {frequency = "none", size = "none", richness = "none"},
["iron-ore"] = {frequency = "none", size = "none", richness = "none"},
["crude-oil"] = {frequency = "very-high", size = "big", richness = "normal"},
["trees"] = {frequency = "none", size = "none", richness = "none"},
["enemy-base"] = {frequency = "high", size = "big", richness = "good"}
}
game.map_settings.pollution.pollution_restored_per_tree_damage = 0
game.create_surface("deep_jungle", map_gen_settings)
game.forces["player"].set_spawn_position({0,0},game.surfaces["deep_jungle"])
global.map_init_done = true
end
local surface = game.surfaces["deep_jungle"]
if player.online_time < 5 and surface.is_chunk_generated({0,0}) then
player.teleport(surface.find_non_colliding_position("character", {0,0}, 2, 1), "deep_jungle")
@ -352,45 +325,67 @@ end
local function on_entity_died(event)
local surface = event.entity.surface
if event.entity.type == "tree" then
if math_random(1,4) == 1 then
if math_random(1,8) == 1 then
local p = surface.find_non_colliding_position("small-biter" , event.entity.position, 2, 0.5)
if p then surface.create_entity {name="small-biter", position=event.entity.position} end
return
end
if math_random(1,8) == 1 then
if math_random(1,16) == 1 then
local p = surface.find_non_colliding_position("medium-biter" , event.entity.position, 2, 0.5)
if p then surface.create_entity {name="medium-biter", position=event.entity.position} end
return
end
if math_random(1,16) == 1 then
if math_random(1,32) == 1 then
local p = surface.find_non_colliding_position("big-biter" , event.entity.position, 2, 0.5)
if p then surface.create_entity {name="big-biter", position=event.entity.position} end
return
end
if math_random(1,256) == 1 then
if math_random(1,512) == 1 then
local p = surface.find_non_colliding_position("behemoth-biter" , event.entity.position, 2, 0.5)
if p then surface.create_entity {name="behemoth-biter", position=event.entity.position} end
return
end
end
if event.entity.type == "simple-entity" then
if math_random(1,4) == 1 then
if math_random(1,8) == 1 then
surface.create_entity {name="small-worm-turret", position=event.entity.position}
return
end
if math_random(1,8) == 1 then
if math_random(1,16) == 1 then
surface.create_entity {name="medium-worm-turret", position=event.entity.position}
return
end
if math_random(1,16) == 1 then
if math_random(1,32) == 1 then
surface.create_entity {name="big-worm-turret", position=event.entity.position}
return
end
end
end
local function on_init()
local map_gen_settings = {}
map_gen_settings.moisture = 1
map_gen_settings.water = "none"
map_gen_settings.starting_area = "normal"
map_gen_settings.cliff_settings = {cliff_elevation_interval = 4, cliff_elevation_0 = 0.1}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = "none", size = "none", richness = "none"},
["stone"] = {frequency = "none", size = "none", richness = "none"},
["copper-ore"] = {frequency = "none", size = "none", richness = "none"},
["iron-ore"] = {frequency = "none", size = "none", richness = "none"},
["crude-oil"] = {frequency = "very-high", size = "big", richness = "normal"},
["trees"] = {frequency = "none", size = "none", richness = "none"},
["enemy-base"] = {frequency = "high", size = "big", richness = "good"}
}
game.create_surface("deep_jungle", map_gen_settings)
game.forces["player"].set_spawn_position({0,0},game.surfaces["deep_jungle"])
end
event.on_init(on_init)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
event.add(defines.events.on_chunk_charted, on_chunk_charted)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
require "modules.rocks_yield_ore"

72
maps/junkyard_pvp/gui.lua Normal file
View File

@ -0,0 +1,72 @@
local Public = {}
local Team = require "maps.junkyard_pvp.team"
function Public.spectate_button(player)
if player.gui.top.spectate_button then return end
local button = player.gui.top.add({type = "button", name = "spectate_button", caption = "Spectate"})
button.style.font = "default-bold"
button.style.font_color = {r = 0.0, g = 0.0, b = 0.0}
button.style.minimal_height = 38
button.style.minimal_width = 38
button.style.top_padding = 2
button.style.left_padding = 4
button.style.right_padding = 4
button.style.bottom_padding = 2
end
local function create_spectate_confirmation(player)
if player.gui.center.spectate_confirmation_frame then return end
local frame = player.gui.center.add({type = "frame", name = "spectate_confirmation_frame", caption = "Are you sure you want to spectate this round?"})
frame.style.font = "default"
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
frame.add({type = "button", name = "confirm_spectate", caption = "Spectate"})
frame.add({type = "button", name = "cancel_spectate", caption = "Cancel"})
end
function Public.rejoin_question(player)
if player.gui.center.rejoin_question_frame then return end
local frame = player.gui.center.add({type = "frame", name = "rejoin_question_frame", caption = "Rejoin the game?"})
frame.style.font = "default"
frame.style.font_color = {r = 0.3, g = 0.65, b = 0.3}
frame.add({type = "button", name = "confirm_rejoin", caption = "Rejoin"})
frame.add({type = "button", name = "cancel_rejoin", caption = "Cancel"})
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
if event.element.name == "confirm_rejoin" then
player.gui.center["rejoin_question_frame"].destroy()
Team.assign_force_to_player(player)
Team.teleport_player_to_active_surface(player)
Team.put_player_into_random_team(player)
game.print(player.name .. " has rejoined the game!")
return
end
if event.element.name == "cancel_rejoin" then player.gui.center["rejoin_question_frame"].destroy() return end
if player.force.name == "spectator" then return end
if event.element.name == "cancel_spectate" then player.gui.center["spectate_confirmation_frame"].destroy() return end
if event.element.name == "confirm_spectate" then
player.gui.center["spectate_confirmation_frame"].destroy()
Team.set_player_to_spectator(player)
game.print(player.name .. " has turned into a spectator ghost.")
return
end
if event.element.name == "spectate_button" then
if player.gui.center["spectate_confirmation_frame"] then
player.gui.center["spectate_confirmation_frame"].destroy()
else
create_spectate_confirmation(player)
end
return
end
end
local event = require 'utils.event'
event.add(defines.events.on_gui_click, on_gui_click)
return Public

209
maps/junkyard_pvp/main.lua Normal file
View File

@ -0,0 +1,209 @@
local Tabs = require 'comfy_panel.main'
local Map_score = require "modules.map_score"
local Terrain = require "maps.junkyard_pvp.terrain"
local Gui = require "maps.junkyard_pvp.gui"
require "modules.rocks_heal_over_time"
require "maps.junkyard_pvp.share_chat"
require "modules.mineable_wreckage_yields_scrap"
local Team = require "maps.junkyard_pvp.team"
local Reset = require "functions.soft_reset"
local Map = require "modules.map_info"
local math_random = math.random
local Public = {}
local map_gen_settings = {
["seed"] = 1,
["water"] = 1,
["starting_area"] = 1,
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
["default_enable_all_autoplace_controls"] = false,
["autoplace_settings"] = {
["entity"] = {treat_missing_as_default = false},
["tile"] = {treat_missing_as_default = false},
["decorative"] = {treat_missing_as_default = false},
},
}
function Public.reset_map()
Terrain.create_mirror_surface()
if not global.active_surface_index then
global.active_surface_index = game.create_surface("pvp_junkyard", map_gen_settings).index
else
global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, Team.starting_items).index
end
local surface = game.surfaces[global.active_surface_index]
surface.request_to_generate_chunks({0,0}, 6)
surface.force_generate_chunk_requests()
game.forces.spectator.set_spawn_position({0, -128}, surface)
game.forces.west.set_spawn_position({-96, 0}, surface)
game.forces.east.set_spawn_position({96, 0}, surface)
Team.set_force_attributes()
Team.assign_random_force_to_active_players()
for _, player in pairs(game.connected_players) do
Team.teleport_player_to_active_surface(player)
end
for _, player in pairs(game.forces.spectator.connected_players) do
player.character.destroy()
Team.set_player_to_spectator(player)
end
for _, player in pairs(game.forces.spectator.players) do
Gui.rejoin_question(player)
end
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then return end
if global.game_reset_tick then return end
if entity.name ~= "cargo-wagon" then return end
if entity == global.map_forces.east.cargo_wagon or entity == global.map_forces.west.cargo_wagon then
if entity.force.name == "east" then
game.print("East lost their cargo-wagon.", {100, 100, 100})
game.print(string.upper(">>>> West team has won the game!!! <<<<"), {250, 120, 0})
game.forces.east.play_sound{path="utility/game_lost", volume_modifier=0.85}
game.forces.west.play_sound{path="utility/game_won", volume_modifier=0.85}
for _, player in pairs(game.forces.west.connected_players) do
if global.map_forces.east.player_count > 0 then
Map_score.set_score(player, Map_score.get_score(player) + 1)
end
end
else
game.print("West lost their cargo-wagon.", {100, 100, 100})
game.print(string.upper(">>>> East team has won the game!!! <<<<"), {250, 120, 0})
game.forces.west.play_sound{path="utility/game_lost", volume_modifier=0.85}
game.forces.east.play_sound{path="utility/game_won", volume_modifier=0.85}
for _, player in pairs(game.forces.east.connected_players) do
if global.map_forces.west.player_count > 0 then
Map_score.set_score(player, Map_score.get_score(player) + 1)
end
end
end
game.print("Next round starting in 60 seconds..", {150, 150, 150})
for _, player in pairs(game.forces.spectator.connected_players) do
player.play_sound{path="utility/game_won", volume_modifier=0.85}
end
global.game_reset_tick = game.tick + 3600
game.delete_surface("mirror_terrain")
for _, player in pairs(game.connected_players) do
for _, child in pairs(player.gui.left.children) do child.destroy() end
Tabs.comfy_panel_call_tab(player, "Map Scores")
end
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
local surface = game.surfaces[global.active_surface_index]
Gui.spectate_button(player)
if player.surface.index ~= global.active_surface_index then
if player.force.name == "spectator" then
Team.set_player_to_spectator(player)
Team.teleport_player_to_active_surface(player)
return
end
Team.assign_force_to_player(player)
Team.teleport_player_to_active_surface(player)
Team.put_player_into_random_team(player)
end
end
local function set_player_spawn_and_refill_fish()
for key, force in pairs(global.map_forces) do
local cargo_wagon = force.cargo_wagon
if cargo_wagon then
if cargo_wagon.valid then
local surface = cargo_wagon.surface
--fill fish in cargo wagon
cargo_wagon.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = math.random(1, 2)})
--set player spawn to cargo wagon position
local position = surface.find_non_colliding_position("stone-furnace", cargo_wagon.position, 16, 2)
if not position then return end
game.forces[key].set_spawn_position({x = position.x, y = position.y}, surface)
--set fish chart tag
if force.fish_tag then
if force.fish_tag.valid then
force.fish_tag.destroy()
end
end
force.fish_tag = cargo_wagon.force.add_chart_tag(
surface,
{icon = {type = 'item', name = 'raw-fish'},
position = cargo_wagon.position,
text = " ",
})
end
end
end
end
local function tick()
local game_tick = game.tick
if game_tick % 240 == 0 then
local surface = game.surfaces[global.active_surface_index]
local area = {{-320, -161}, {319, 160}}
game.forces.west.chart(surface, area)
game.forces.east.chart(surface, area)
end
if global.game_reset_tick then
if global.game_reset_tick < game_tick then
global.game_reset_tick = nil
Public.reset_map()
end
return
end
if game_tick % 900 == 0 then
set_player_spawn_and_refill_fish()
end
end
local function on_init()
game.difficulty_settings.technology_price_multiplier = 0.5
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.enemy_evolution.time_factor = 0
game.map_settings.enemy_expansion.enabled = false
game.map_settings.pollution.enabled = false
global.map_forces = {
["west"] = {},
["east"] = {},
}
local T = Map.Pop_info()
T.main_caption = "Junkyard PVP"
T.sub_caption = "a playground made of scrap"
T.text = table.concat({
"The opponent team wants your fish cargo!\n",
"\n",
"Destroy their cargo wagon to win the round!\n",
})
T.main_caption_color = {r = 150, g = 0, b = 255}
T.sub_caption_color = {r = 0, g = 250, b = 150}
Team.create_forces()
Public.reset_map()
end
local event = require 'utils.event'
event.on_init(on_init)
event.on_nth_tick(60, tick)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
require "modules.rocks_yield_ore"

View File

@ -0,0 +1,27 @@
----------share chat with spectator force-------------------
local function on_console_chat(event)
if not event.message then return end
if not event.player_index then return end
local player = game.players[event.player_index]
local color = {}
color = player.color
color.r = color.r * 0.6 + 0.35
color.g = color.g * 0.6 + 0.35
color.b = color.b * 0.6 + 0.35
color.a = 1
if player.force.name == "west" then
game.forces.spectator.print(player.name .. " (west): ".. event.message, color)
end
if player.force.name == "east" then
game.forces.spectator.print(player.name .. " (east): ".. event.message, color)
end
if player.force.name == "spectator" then
game.forces.west.print(player.name .. " (spectator): ".. event.message, color)
game.forces.east.print(player.name .. " (spectator): ".. event.message, color)
end
end
local event = require 'utils.event'
event.add(defines.events.on_console_chat, on_console_chat)

101
maps/junkyard_pvp/team.lua Normal file
View File

@ -0,0 +1,101 @@
local Public = {}
local math_random = math.random
Public.starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16}
function Public.set_force_attributes()
game.forces.west.set_friend("spectator", true)
game.forces.east.set_friend("spectator", true)
game.forces.spectator.set_friend("west", true)
game.forces.spectator.set_friend("east", true)
game.forces.west.share_chart = true
game.forces.east.share_chart = true
for _, force_name in pairs({"west", "east"}) do
game.forces[force_name].research_queue_enabled = true
game.forces[force_name].technologies["artillery"].enabled = false
game.forces[force_name].technologies["artillery-shell-range-1"].enabled = false
game.forces[force_name].technologies["artillery-shell-speed-1"].enabled = false
game.forces[force_name].technologies["railway"].researched = true
global.map_forces[force_name].unit_health_boost = 1
global.map_forces[force_name].unit_count = 0
global.map_forces[force_name].max_unit_count = 1024
global.map_forces[force_name].player_count = 0
end
end
function Public.create_forces()
game.create_force("west")
game.create_force("east")
game.create_force("spectator")
end
function Public.assign_random_force_to_active_players()
local player_indexes = {}
for _, player in pairs(game.connected_players) do
if player.force.name ~= "spectator" then player_indexes[#player_indexes + 1] = player.index end
end
if #player_indexes > 1 then table.shuffle_table(player_indexes) end
local a = math_random(0, 1)
for key, player_index in pairs(player_indexes) do
if key % 2 == a then
game.players[player_index].force = game.forces.west
else
game.players[player_index].force = game.forces.east
end
end
end
function Public.assign_force_to_player(player)
player.spectator = false
if math_random(1, 2) == 1 then
if #game.forces.east.connected_players > #game.forces.west.connected_players then
player.force = game.forces.west
else
player.force = game.forces.east
end
else
if #game.forces.east.connected_players < #game.forces.west.connected_players then
player.force = game.forces.east
else
player.force = game.forces.west
end
end
end
function Public.teleport_player_to_active_surface(player)
local surface = game.surfaces[global.active_surface_index]
local position
if player.force.name == "spectator" then
position = player.force.get_spawn_position(surface)
position = {x = (position.x - 160) + math_random(0, 320), y = (position.y - 16) + math_random(0, 32)}
else
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
end
player.teleport(position, surface)
end
function Public.put_player_into_random_team(player)
if player.character then
if player.character.valid then
player.character.destroy()
end
end
player.character = nil
player.set_controller({type=defines.controllers.god})
player.create_character()
for item, amount in pairs(Public.starting_items) do
player.insert({name = item, count = amount})
end
global.map_forces[player.force.name].player_count = global.map_forces[player.force.name].player_count + 1
end
function Public.set_player_to_spectator(player)
if player.character then player.character.die() end
player.force = game.forces.spectator
player.character = nil
player.spectator = true
player.set_controller({type=defines.controllers.spectator})
end
return Public

View File

@ -0,0 +1,289 @@
local math_abs = math.abs
local math_random = math.random
local math_floor = math.floor
local Treasure = require 'maps.junkyard_pvp.treasure'
local Map_functions = require "tools.map_functions"
local simplex_noise = require "utils.simplex_noise".d2
local rock_raffle = {"sand-rock-big","sand-rock-big", "rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
local spawner_raffle = {"biter-spawner", "biter-spawner", "biter-spawner", "spitter-spawner"}
local noises = {
["no_rocks"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
["no_rocks_2"] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}},
["large_caves"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
["small_caves"] = {{modifier = 0.008, weight = 1}, {modifier = 0.03, weight = 0.15}, {modifier = 0.25, weight = 0.05}},
["small_caves_2"] = {{modifier = 0.009, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.25, weight = 0.05}},
["cave_ponds"] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}},
["cave_rivers"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.25}, {modifier = 0.05, weight = 0.01}},
["cave_rivers_2"] = {{modifier = 0.003, weight = 1}, {modifier = 0.01, weight = 0.21}, {modifier = 0.05, weight = 0.01}},
["cave_rivers_3"] = {{modifier = 0.002, weight = 1}, {modifier = 0.01, weight = 0.15}, {modifier = 0.05, weight = 0.01}},
["cave_rivers_4"] = {{modifier = 0.001, weight = 1}, {modifier = 0.01, weight = 0.11}, {modifier = 0.05, weight = 0.01}},
["scrapyard"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.35}, {modifier = 0.05, weight = 0.23}, {modifier = 0.1, weight = 0.11}},
}
local cargo_wagon_position = {x = 96, y = 0}
local Public = {}
local function get_noise(name, pos, seed)
local noise = 0
local d = 0
for _, n in pairs(noises[name]) do
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
d = d + n.weight
seed = seed + 10000
end
noise = noise / d
return noise
end
local function create_objectives(surface)
local d = 6
for key, modifier in pairs({west = -1, east = 1}) do
for x = -6, 6, 2 do surface.create_entity({name = "straight-rail", position = {(cargo_wagon_position.x + x) * modifier, cargo_wagon_position.y}, force = key, direction = 2}) end
local e = surface.create_entity({name = "locomotive", position = {(cargo_wagon_position.x + 3) * modifier, cargo_wagon_position.y}, force = key, direction = d})
e.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 50})
local e = surface.create_entity({name = "cargo-wagon", position = {(cargo_wagon_position.x - 3) * modifier, cargo_wagon_position.y}, force = key})
e.minable = false
global.map_forces[key].cargo_wagon = e
d = d - 4
end
end
function Public.create_mirror_surface()
if game.surfaces["mirror_terrain"] then return end
local map_gen_settings = {}
map_gen_settings.seed = math_random(1, 99999999)
map_gen_settings.water = 0.2
map_gen_settings.starting_area = 1
map_gen_settings.terrain_segmentation = 8
map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = 10, size = 0.6, richness = 0.5,},
["stone"] = {frequency = 10, size = 0.6, richness = 0.5,},
["copper-ore"] = {frequency = 20, size = 0.6, richness = 0.75,},
["iron-ore"] = {frequency = 20, size = 0.6, richness = 1,},
["uranium-ore"] = {frequency = 5, size = 0.5, richness = 0.5,},
["crude-oil"] = {frequency = 10, size = 1, richness = 1,},
["trees"] = {frequency = math_random(5, 15) * 0.1, size = math_random(4, 8) * 0.1, richness = 0.1},
["enemy-base"] = {frequency = 0, size = 0, richness = 0}
}
local surface = game.create_surface("mirror_terrain", map_gen_settings)
local x = cargo_wagon_position.x - 16
local offset = 38
surface.request_to_generate_chunks({x, 0}, 5)
surface.force_generate_chunk_requests()
local r = 15
for x = r * -1, r, 1 do
for y = r * -1, r, 1 do
local p = {x = cargo_wagon_position.x + x, y = cargo_wagon_position.y + y}
if math.sqrt(x ^ 2 + y ^ 2) < r then
local tile = surface.get_tile(p)
if tile.collides_with("resource-layer") then
surface.set_tiles({{name = "landfill", position = p}}, true)
end
end
end
end
for _, e in pairs(surface.find_entities_filtered({area = {{cargo_wagon_position.x - r, cargo_wagon_position.y - r}, {cargo_wagon_position.x + r, cargo_wagon_position.y + r}}, force = {"neutral", "enemy"}})) do
if math.sqrt(e.position.x ^ 2 + e.position.y ^ 2) < r then
e.destroy()
end
end
end
local function mirror_chunk(event, source_surface, x_modifier)
local surface = event.surface
local left_top = event.area.left_top
local offset = 0
if x_modifier == -1 then offset = 32 end
local mirror_left_top = {x = left_top.x * x_modifier - offset, y = left_top.y * x_modifier - offset}
source_surface.request_to_generate_chunks(mirror_left_top, 1)
source_surface.force_generate_chunk_requests()
local mirror_area = {{mirror_left_top.x, mirror_left_top.y}, {mirror_left_top.x + 32, mirror_left_top.y + 32}}
for _, tile in pairs(source_surface.find_tiles_filtered({area = mirror_area})) do
surface.set_tiles({{name = tile.name, position = {x = tile.position.x * x_modifier, y = tile.position.y * x_modifier}}}, true)
end
for _, entity in pairs(source_surface.find_entities_filtered({area = mirror_area})) do
--if surface.can_place_entity({name = entity.name, position = {x = entity.position.x * x_modifier, y = entity.position.y * x_modifier}}) then
entity.clone({position = {x = entity.position.x * x_modifier, y = entity.position.y * x_modifier}, surface = surface})
--end
end
for _, decorative in pairs(source_surface.find_decoratives_filtered{area = mirror_area}) do
surface.create_decoratives{
check_collision=false,
decoratives={{name = decorative.decorative.name, position = {x = decorative.position.x * x_modifier, y = decorative.position.y * x_modifier}, amount = decorative.amount}}
}
end
end
local scrap_entities = {"crash-site-assembling-machine-1-broken", "crash-site-assembling-machine-2-broken", "crash-site-assembling-machine-1-broken", "crash-site-assembling-machine-2-broken", "crash-site-lab-broken",
"medium-ship-wreck", "small-ship-wreck", "medium-ship-wreck", "small-ship-wreck", "medium-ship-wreck", "small-ship-wreck", "medium-ship-wreck", "small-ship-wreck",
"crash-site-chest-1", "crash-site-chest-2", "crash-site-chest-1", "crash-site-chest-2", "crash-site-chest-1", "crash-site-chest-2", "crash-site-chest-1", "crash-site-chest-2", "crash-site-chest-1", "crash-site-chest-2"}
local scrap_entities_index = #scrap_entities
--SCRAPYARD
local function process_junk_position(p, seed, tiles, entities, markets, treasure)
local scrapyard = get_noise("scrapyard", p, seed)
if p.x < 5 + scrapyard * 3 then tiles[#tiles + 1] = {name = "water-shallow", position = p} return end
if p.x < cargo_wagon_position.x + 16 + scrapyard * 32 then return end
--Chasms
local noise_cave_ponds = get_noise("cave_ponds", p, seed)
local small_caves = get_noise("small_caves", p, seed)
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
if small_caves < -0.35 then
tiles[#tiles + 1] = {name = "out-of-map", position = p}
return
end
end
if scrapyard < -0.25 or scrapyard > 0.25 then
if math_random(1, 1024) == 1 then
entities[#entities + 1] = {name="gun-turret", position=p, force = "enemy"}
end
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if scrapyard < -0.55 or scrapyard > 0.55 then
if math_random(1,5) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
return
end
if scrapyard < -0.28 or scrapyard > 0.28 then
if math_random(1,2048) == 1 then
entities[#entities + 1] = {name = "small-worm-turret", position = p, force = "enemy"}
end
if math_random(1,96) == 1 then entities[#entities + 1] = {name = scrap_entities[math_random(1, scrap_entities_index)], position = p, force = "enemy"} end
if math_random(1,5) > 1 then entities[#entities + 1] = {name="mineable-wreckage", position=p} end
return
end
return
end
local cave_ponds = get_noise("cave_ponds", p, seed)
if cave_ponds < -0.6 and scrapyard > -0.2 and scrapyard < 0.2 then
tiles[#tiles + 1] = {name = "deepwater-green", position = p}
if math_random(1,128) == 1 then entities[#entities + 1] = {name="fish", position=p} end
return
end
local large_caves = get_noise("large_caves", p, seed)
if scrapyard > -0.15 and scrapyard < 0.15 then
if math_floor(large_caves * 10) % 4 < 2 then
tiles[#tiles + 1] = {name = "dirt-7", position = p}
if math_random(1,3) > 1 then entities[#entities + 1] = {name = rock_raffle[math_random(1, #rock_raffle)], position = p} end
return
end
end
if noise_cave_ponds < 0.7 then return end
tiles[#tiles + 1] = {name = "stone-path", position = p}
end
local function is_out_of_map(p)
if p.y < 96 and p.y >= -96 then return end
if (p.x + 128) * 0.4 >= math_abs(p.y) then return end
if (p.x - 128) * -0.4 > math_abs(p.y) then return end
return true
end
local function out_of_map_area(event)
local surface = event.surface
local left_top = event.area.left_top
for x = -1, 32, 1 do
for y = -1, 32, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
if is_out_of_map(p) then
surface.set_tiles({{name = "out-of-map", position = p}}, true)
end
end
end
end
local function process_main_surface(event)
local source_surface = game.surfaces["mirror_terrain"]
if not source_surface then return end
if not source_surface.valid then return end
if event.surface.index == source_surface.index then return end
local left_top = event.area.left_top
if left_top.x >= 0 then
mirror_chunk(event, source_surface, 1)
else
mirror_chunk(event, source_surface, -1)
end
out_of_map_area(event)
if left_top.x == -160 and left_top.y == -160 then
create_objectives(event.surface)
end
--game.forces.west.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
--game.forces.east.chart(event.surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
return true
end
local entity_functions = {
["turret"] = function(surface, entity) surface.create_entity(entity) end,
["simple-entity"] = function(surface, entity) surface.create_entity(entity) end,
["ammo-turret"] = function(surface, entity)
local e = surface.create_entity(entity)
e.insert({name = "firearm-magazine", count = math_random(16, 64)})
end,
["container"] = function(surface, entity)
Treasure(surface, entity.position, entity.name)
end,
}
local function process_mirror_surface(event)
local surface = event.surface
local left_top = event.area.left_top
local tiles = {}
local entities = {}
local treasure = {}
local seed = surface.map_gen_settings.seed
for y = 0, 31, 1 do
for x = 0, 31, 1 do
local p = {x = left_top.x + x, y = left_top.y + y}
process_junk_position(p, seed, tiles, entities, treasure)
end
end
surface.set_tiles(tiles, true)
for _, p in pairs(treasure) do
local name = "wooden-chest"
if math_random(1, 6) == 1 then name = "iron-chest" end
Treasure(surface, p, name)
end
for _, entity in pairs(entities) do
if entity_functions[game.entity_prototypes[entity.name].type] then
entity_functions[game.entity_prototypes[entity.name].type](surface, entity)
else
if surface.can_place_entity(entity) then
surface.create_entity(entity)
end
end
end
end
local function on_chunk_generated(event)
if process_main_surface(event) then return end
process_mirror_surface(event)
end
local event = require 'utils.event'
event.add(defines.events.on_chunk_generated, on_chunk_generated)
return Public

View File

@ -0,0 +1,181 @@
local math_random = math.random
local Public = {}
function Public.treasure_chest(surface, position, container_name)
local chest_raffle = {}
local chest_loot = {
{{name = "submachine-gun", count = math_random(1,3)}, weight = 3, d_min = 0.0, d_max = 0.1},
{{name = "slowdown-capsule", count = math_random(16,32)}, weight = 1, d_min = 0.3, d_max = 0.7},
{{name = "poison-capsule", count = math_random(8,16)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "uranium-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.6, d_max = 1},
{{name = "cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.4, d_max = 0.7},
{{name = "explosive-uranium-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.6, d_max = 1},
{{name = "explosive-cannon-shell", count = math_random(16,32)}, weight = 5, d_min = 0.4, d_max = 0.8},
{{name = "shotgun", count = 1}, weight = 2, d_min = 0.0, d_max = 0.2},
{{name = "shotgun-shell", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.2},
{{name = "combat-shotgun", count = 1}, weight = 3, d_min = 0.3, d_max = 0.8},
{{name = "piercing-shotgun-shell", count = math_random(16,32)}, weight = 10, d_min = 0.2, d_max = 1},
{{name = "flamethrower", count = 1}, weight = 3, d_min = 0.3, d_max = 0.6},
{{name = "flamethrower-ammo", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1},
{{name = "rocket-launcher", count = 1}, weight = 3, d_min = 0.2, d_max = 0.6},
{{name = "rocket", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7},
{{name = "explosive-rocket", count = math_random(16,32)}, weight = 5, d_min = 0.3, d_max = 1},
{{name = "land-mine", count = math_random(16,32)}, weight = 5, d_min = 0.2, d_max = 0.7},
{{name = "grenade", count = math_random(16,32)}, weight = 5, d_min = 0.0, d_max = 0.5},
{{name = "cluster-grenade", count = math_random(8,16)}, weight = 5, d_min = 0.4, d_max = 1},
{{name = "firearm-magazine", count = math_random(32,128)}, weight = 5, d_min = 0, d_max = 0.3},
{{name = "piercing-rounds-magazine", count = math_random(32,128)}, weight = 5, d_min = 0.1, d_max = 0.8},
{{name = "uranium-rounds-magazine", count = math_random(32,128)}, weight = 5, d_min = 0.5, d_max = 1},
{{name = "railgun", count = 1}, weight = 1, d_min = 0.2, d_max = 1},
{{name = "railgun-dart", count = math_random(16,32)}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "defender-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.0, d_max = 0.7},
{{name = "distractor-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 1},
{{name = "destroyer-capsule", count = math_random(8,16)}, weight = 2, d_min = 0.3, d_max = 1},
{{name = "atomic-bomb", count = 1}, weight = 1, d_min = 0.8, d_max = 1},
{{name = "light-armor", count = 1}, weight = 3, d_min = 0, d_max = 0.1},
{{name = "heavy-armor", count = 1}, weight = 3, d_min = 0.1, d_max = 0.3},
{{name = "modular-armor", count = 1}, weight = 2, d_min = 0.2, d_max = 0.6},
{{name = "power-armor", count = 1}, weight = 1, d_min = 0.4, d_max = 1},
--{{name = "power-armor-mk2", count = 1}, weight = 1, d_min = 0.9, d_max = 1},
{{name = "battery-equipment", count = 1}, weight = 2, d_min = 0.3, d_max = 0.7},
--{{name = "battery-mk2-equipment", count = 1}, weight = 2, d_min = 0.7, d_max = 1},
{{name = "belt-immunity-equipment", count = 1}, weight = 1, d_min = 0.5, d_max = 1},
{{name = "solar-panel-equipment", count = math_random(1,4)}, weight = 5, d_min = 0.4, d_max = 0.8},
{{name = "discharge-defense-equipment", count = 1}, weight = 1, d_min = 0.5, d_max = 1},
{{name = "energy-shield-equipment", count = math_random(1,2)}, weight = 2, d_min = 0.3, d_max = 0.8},
--{{name = "energy-shield-mk2-equipment", count = 1}, weight = 2, d_min = 0.8, d_max = 1},
{{name = "exoskeleton-equipment", count = 1}, weight = 1, d_min = 0.3, d_max = 1},
--{{name = "fusion-reactor-equipment", count = 1}, weight = 1, d_min = 0.8, d_max = 1},
{{name = "night-vision-equipment", count = 1}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = "personal-laser-defense-equipment", count = 1}, weight = 1, d_min = 0.7, d_max = 1},
{{name = "personal-roboport-equipment", count = math_random(1,2)}, weight = 3, d_min = 0.4, d_max = 1},
--{{name = "personal-roboport-mk2-equipment", count = 1}, weight = 1, d_min = 0.9, d_max = 1},
{{name = "logistic-robot", count = math_random(5,25)}, weight = 2, d_min = 0.5, d_max = 1},
{{name = "construction-robot", count = math_random(5,25)}, weight = 5, d_min = 0.4, d_max = 1},
{{name = "iron-gear-wheel", count = math_random(80,100)}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "copper-cable", count = math_random(100,200)}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "engine-unit", count = math_random(16,32)}, weight = 2, d_min = 0.1, d_max = 0.5},
{{name = "electric-engine-unit", count = math_random(16,32)}, weight = 2, d_min = 0.4, d_max = 0.8},
{{name = "battery", count = math_random(50,150)}, weight = 2, d_min = 0.3, d_max = 0.8},
{{name = "advanced-circuit", count = math_random(50,150)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "electronic-circuit", count = math_random(50,150)}, weight = 4, d_min = 0.0, d_max = 0.4},
{{name = "processing-unit", count = math_random(50,150)}, weight = 3, d_min = 0.7, d_max = 1},
{{name = "explosives", count = math_random(40,100)}, weight = 20, d_min = 0.0, d_max = 1},
{{name = "lubricant-barrel", count = math_random(4,10)}, weight = 1, d_min = 0.3, d_max = 0.5},
{{name = "rocket-fuel", count = math_random(4,10)}, weight = 2, d_min = 0.3, d_max = 0.7},
--{{name = "computer", count = 1}, weight = 2, d_min = 0, d_max = 1},
{{name = "effectivity-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "productivity-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "speed-module", count = math_random(1,4)}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "automation-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "logistic-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.1, d_max = 0.5},
{{name = "military-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.2, d_max = 1},
{{name = "chemical-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "production-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.4, d_max = 1},
{{name = "utility-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "space-science-pack", count = math_random(16,64)}, weight = 3, d_min = 0.9, d_max = 1},
{{name = "steel-plate", count = math_random(25,75)}, weight = 2, d_min = 0.1, d_max = 0.3},
{{name = "nuclear-fuel", count = 1}, weight = 2, d_min = 0.7, d_max = 1},
{{name = "burner-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.1},
{{name = "inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.4},
{{name = "long-handed-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.4},
{{name = "fast-inserter", count = math_random(8,16)}, weight = 3, d_min = 0.1, d_max = 1},
{{name = "filter-inserter", count = math_random(8,16)}, weight = 1, d_min = 0.2, d_max = 1},
{{name = "stack-filter-inserter", count = math_random(4,8)}, weight = 1, d_min = 0.4, d_max = 1},
{{name = "stack-inserter", count = math_random(4,8)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "small-electric-pole", count = math_random(16,24)}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "medium-electric-pole", count = math_random(8,16)}, weight = 3, d_min = 0.2, d_max = 1},
{{name = "big-electric-pole", count = math_random(4,8)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "substation", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "wooden-chest", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "iron-chest", count = math_random(8,16)}, weight = 3, d_min = 0.1, d_max = 0.4},
{{name = "steel-chest", count = math_random(8,16)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "small-lamp", count = math_random(16,32)}, weight = 3, d_min = 0.1, d_max = 0.3},
{{name = "rail", count = math_random(25,75)}, weight = 3, d_min = 0.1, d_max = 0.6},
{{name = "assembling-machine-1", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "assembling-machine-2", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.8},
{{name = "assembling-machine-3", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "accumulator", count = math_random(4,8)}, weight = 3, d_min = 0.4, d_max = 1},
{{name = "offshore-pump", count = math_random(1,3)}, weight = 2, d_min = 0.0, d_max = 0.2},
{{name = "beacon", count = 1}, weight = 2, d_min = 0.7, d_max = 1},
{{name = "boiler", count = math_random(3,6)}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "steam-engine", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.5},
{{name = "steam-turbine", count = math_random(1,2)}, weight = 2, d_min = 0.6, d_max = 1},
{{name = "nuclear-reactor", count = 1}, weight = 1, d_min = 0.7, d_max = 1},
{{name = "centrifuge", count = 1}, weight = 1, d_min = 0.6, d_max = 1},
{{name = "heat-pipe", count = math_random(4,8)}, weight = 2, d_min = 0.5, d_max = 1},
{{name = "heat-exchanger", count = math_random(2,4)}, weight = 2, d_min = 0.5, d_max = 1},
{{name = "arithmetic-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "constant-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "decider-combinator", count = math_random(4,8)}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "power-switch", count = 1}, weight = 2, d_min = 0.1, d_max = 1},
{{name = "programmable-speaker", count = math_random(2,4)}, weight = 1, d_min = 0.1, d_max = 1},
{{name = "green-wire", count = math_random(50,99)}, weight = 4, d_min = 0.1, d_max = 1},
{{name = "red-wire", count = math_random(50,99)}, weight = 4, d_min = 0.1, d_max = 1},
{{name = "chemical-plant", count = math_random(1,3)}, weight = 3, d_min = 0.3, d_max = 1},
{{name = "burner-mining-drill", count = math_random(2,4)}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "electric-mining-drill", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 1},
{{name = "express-transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "express-underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "express-splitter", count = math_random(1,4)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "fast-transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "fast-underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "fast-splitter", count = math_random(1,4)}, weight = 3, d_min = 0.2, d_max = 0.3},
{{name = "transport-belt", count = math_random(25,75)}, weight = 3, d_min = 0, d_max = 0.3},
{{name = "underground-belt", count = math_random(4,8)}, weight = 3, d_min = 0, d_max = 0.3},
{{name = "splitter", count = math_random(1,4)}, weight = 3, d_min = 0, d_max = 0.3},
--{{name = "oil-refinery", count = math_random(2,4)}, weight = 2, d_min = 0.3, d_max = 1},
{{name = "pipe", count = math_random(30,50)}, weight = 3, d_min = 0.0, d_max = 0.3},
{{name = "pipe-to-ground", count = math_random(4,8)}, weight = 1, d_min = 0.2, d_max = 0.5},
{{name = "pumpjack", count = math_random(1,3)}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = "pump", count = math_random(1,2)}, weight = 1, d_min = 0.3, d_max = 0.8},
{{name = "solar-panel", count = math_random(3,6)}, weight = 3, d_min = 0.4, d_max = 0.9},
{{name = "electric-furnace", count = math_random(2,4)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "steel-furnace", count = math_random(4,8)}, weight = 3, d_min = 0.2, d_max = 0.7},
{{name = "stone-furnace", count = math_random(8,16)}, weight = 3, d_min = 0.0, d_max = 0.2},
{{name = "radar", count = math_random(1,2)}, weight = 1, d_min = 0.1, d_max = 0.4},
{{name = "rail-signal", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 0.8},
{{name = "rail-chain-signal", count = math_random(8,16)}, weight = 2, d_min = 0.2, d_max = 0.8},
{{name = "stone-wall", count = math_random(33,99)}, weight = 3, d_min = 0.0, d_max = 0.7},
{{name = "gate", count = math_random(16,32)}, weight = 3, d_min = 0.0, d_max = 0.7},
{{name = "storage-tank", count = math_random(2,6)}, weight = 3, d_min = 0.3, d_max = 0.6},
{{name = "train-stop", count = math_random(1,2)}, weight = 1, d_min = 0.2, d_max = 0.7},
{{name = "express-loader", count = math_random(1,2)}, weight = 1, d_min = 0.5, d_max = 1},
{{name = "fast-loader", count = math_random(1,2)}, weight = 1, d_min = 0.2, d_max = 0.7},
{{name = "loader", count = math_random(1,2)}, weight = 1, d_min = 0.0, d_max = 0.5},
{{name = "lab", count = math_random(1,2)}, weight = 2, d_min = 0.0, d_max = 0.3},
{{name = "roboport", count = 1}, weight = 2, d_min = 0.8, d_max = 1},
{{name = "flamethrower-turret", count = 1}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "laser-turret", count = math_random(3,6)}, weight = 3, d_min = 0.5, d_max = 1},
{{name = "gun-turret", count = math_random(2,4)}, weight = 3, d_min = 0.2, d_max = 0.9},
}
local distance_to_center = (math.abs(position.y) + 1) * 0.0002
if distance_to_center > 1 then distance_to_center = 1 end
for _, t in pairs (chest_loot) do
for x = 1, t.weight, 1 do
if t.d_min <= distance_to_center and t.d_max >= distance_to_center then
table.insert(chest_raffle, t[1])
end
end
end
local e = surface.create_entity({name = container_name, position=position, force="neutral"})
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math_random(2,6), 1 do
local loot = chest_raffle[math_random(1,#chest_raffle)]
i.insert(loot)
end
end
return Public.treasure_chest