2021-03-24 21:14:55 +02:00
|
|
|
--luacheck: ignore
|
2021-03-24 17:46:00 +02:00
|
|
|
require 'modules.mineable_wreckage_yields_scrap'
|
|
|
|
require 'modules.wave_defense.main'
|
|
|
|
local Map = require 'modules.map_info'
|
|
|
|
local WD = require 'modules.wave_defense.table'
|
2024-10-01 16:46:06 +02:00
|
|
|
local simplex_noise = require 'utils.math.simplex_noise'.d2
|
2019-09-29 17:12:25 +02:00
|
|
|
local spawn_size = 96
|
2019-09-29 18:50:53 +02:00
|
|
|
local wall_thickness = 3
|
2021-01-25 02:37:17 +02:00
|
|
|
local small_scraps = {
|
2021-03-24 17:46:00 +02:00
|
|
|
'crash-site-spaceship-wreck-small-1',
|
|
|
|
'crash-site-spaceship-wreck-small-1',
|
|
|
|
'crash-site-spaceship-wreck-small-2',
|
|
|
|
'crash-site-spaceship-wreck-small-2',
|
|
|
|
'crash-site-spaceship-wreck-small-3',
|
|
|
|
'crash-site-spaceship-wreck-small-3',
|
|
|
|
'crash-site-spaceship-wreck-small-4',
|
|
|
|
'crash-site-spaceship-wreck-small-4',
|
|
|
|
'crash-site-spaceship-wreck-small-5',
|
|
|
|
'crash-site-spaceship-wreck-small-5',
|
|
|
|
'crash-site-spaceship-wreck-small-6'
|
2021-01-25 02:37:17 +02:00
|
|
|
}
|
2019-09-29 17:12:25 +02:00
|
|
|
|
|
|
|
local function clone_chunk(event, source_surface_name)
|
2021-03-24 17:46:00 +02:00
|
|
|
local source_surface = game.surfaces[source_surface_name]
|
|
|
|
|
|
|
|
source_surface.request_to_generate_chunks(event.area.left_top, 1)
|
|
|
|
source_surface.force_generate_chunk_requests()
|
|
|
|
|
|
|
|
source_surface.clone_area(
|
|
|
|
{
|
|
|
|
source_area = event.area,
|
|
|
|
destination_area = event.area,
|
|
|
|
destination_surface = game.surfaces[1],
|
|
|
|
--destination_force="neutral",
|
|
|
|
clone_tiles = true,
|
|
|
|
clone_entities = true,
|
|
|
|
clone_decoratives = true,
|
|
|
|
clear_destination = true,
|
|
|
|
expand_map = false
|
|
|
|
}
|
|
|
|
)
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function is_spawn_wall(p)
|
2021-03-24 17:46:00 +02:00
|
|
|
--if p.y < -32 and p.x < -32 then return false end
|
|
|
|
--if p.y > 32 and p.x > 32 then return false end
|
|
|
|
if p.x >= spawn_size - wall_thickness then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
if p.x < spawn_size * -1 + wall_thickness then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
if p.y >= spawn_size - wall_thickness then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
if p.y < spawn_size * -1 + wall_thickness then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function spawn_area(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
local left_top = event.area.left_top
|
|
|
|
|
2024-09-24 19:37:11 +02:00
|
|
|
for _, entity in pairs(event.surface.find_entities_filtered({ area = event.area, force = 'neutral' })) do
|
2021-03-24 17:46:00 +02:00
|
|
|
entity.destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
local ore = false
|
|
|
|
if left_top.x == -64 and left_top.y == -64 then
|
|
|
|
ore = 'coal'
|
|
|
|
end
|
|
|
|
if left_top.x == 32 and left_top.y == 32 then
|
|
|
|
ore = 'stone'
|
|
|
|
end
|
|
|
|
if left_top.x == 32 and left_top.y == -64 then
|
|
|
|
ore = 'iron-ore'
|
|
|
|
end
|
|
|
|
if left_top.x == -64 and left_top.y == 32 then
|
|
|
|
ore = 'copper-ore'
|
|
|
|
end
|
|
|
|
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2024-09-24 19:37:11 +02:00
|
|
|
local p = { x = left_top.x + x, y = left_top.y + y }
|
|
|
|
event.surface.set_tiles({ { name = 'stone-path', position = p } })
|
2021-03-24 17:46:00 +02:00
|
|
|
if is_spawn_wall(p) then
|
2024-09-24 19:37:11 +02:00
|
|
|
event.surface.create_entity({ name = 'stone-wall', position = p, force = 'player' })
|
2021-03-24 17:46:00 +02:00
|
|
|
else
|
|
|
|
if not ore then
|
|
|
|
if math.sqrt(p.x ^ 2 + p.y ^ 2) > 4 then
|
|
|
|
if math.random(1, 3) ~= 1 then
|
|
|
|
local noise =
|
|
|
|
simplex_noise(p.x * 0.015, p.y * 0.015, game.surfaces[1].map_gen_settings.seed) +
|
|
|
|
simplex_noise(p.x * 0.055, p.y * 0.055, game.surfaces[1].map_gen_settings.seed) * 0.5
|
|
|
|
if noise > 0.6 then
|
2024-09-24 19:37:11 +02:00
|
|
|
event.surface.create_entity({ name = small_scraps[math.random(1, #small_scraps)], position = p, force = 'neutral' })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
if noise < -0.75 then
|
|
|
|
if math.random(1, 16) == 1 then
|
2024-09-25 23:25:57 +02:00
|
|
|
event.surface.create_entity({ name = 'big-rock', position = p, force = 'neutral' })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if left_top.x == -64 and left_top.y == -64 then
|
2024-09-24 19:37:11 +02:00
|
|
|
local wreck = event.surface.create_entity({ name = 'crash-site-spaceship', position = { 0, -6 }, force = 'player' })
|
|
|
|
wreck.insert({ name = 'submachine-gun', count = 3 })
|
|
|
|
wreck.insert({ name = 'firearm-magazine', count = 32 })
|
|
|
|
wreck.insert({ name = 'grenade', count = 8 })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if not ore then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2024-09-24 19:37:11 +02:00
|
|
|
local p = { x = left_top.x + x, y = left_top.y + y }
|
|
|
|
event.surface.create_entity({ name = ore, position = p, amount = 1000 })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
2019-09-29 19:50:42 +02:00
|
|
|
local function get_quarter_name(position)
|
2021-03-24 17:46:00 +02:00
|
|
|
if position.x < 0 then
|
|
|
|
if position.y < 0 then
|
|
|
|
return 'NW'
|
|
|
|
else
|
|
|
|
return 'SW'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if position.y < 0 then
|
|
|
|
return 'NE'
|
|
|
|
else
|
|
|
|
return 'SE'
|
|
|
|
end
|
|
|
|
end
|
2019-09-29 19:50:42 +02:00
|
|
|
end
|
2019-10-30 21:00:32 +02:00
|
|
|
|
2021-03-24 17:46:00 +02:00
|
|
|
local function draw_borders(surface, left_top, area)
|
|
|
|
if left_top.x == 0 or left_top.x == -32 then
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2024-09-24 19:37:11 +02:00
|
|
|
local p = { left_top.x + x, left_top.y + y }
|
|
|
|
surface.set_tiles({ { name = 'deepwater', position = p } })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.destroy_decoratives({ area = area })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if left_top.y == 0 or left_top.y == -32 then
|
|
|
|
for x = 0, 31, 1 do
|
|
|
|
for y = 0, 31, 1 do
|
2024-09-24 19:37:11 +02:00
|
|
|
local p = { left_top.x + x, left_top.y + y }
|
|
|
|
surface.set_tiles({ { name = 'deepwater', position = p } })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
|
|
|
end
|
2024-09-24 19:37:11 +02:00
|
|
|
surface.destroy_decoratives({ area = area })
|
2021-03-24 17:46:00 +02:00
|
|
|
end
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_chunk_generated(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
if event.surface.index ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local surface = event.surface
|
|
|
|
local left_top = event.area.left_top
|
|
|
|
|
|
|
|
if left_top.x < spawn_size and left_top.y < spawn_size and left_top.x >= spawn_size * -1 and left_top.y >= spawn_size * -1 then
|
|
|
|
spawn_area(event)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if left_top.x < 0 then
|
|
|
|
if left_top.y < 0 then
|
|
|
|
clone_chunk(event, 'coal')
|
|
|
|
else
|
|
|
|
clone_chunk(event, 'copper-ore')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if left_top.y < 0 then
|
|
|
|
clone_chunk(event, 'iron-ore')
|
|
|
|
else
|
|
|
|
clone_chunk(event, 'stone')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
draw_borders(surface, left_top, event.area)
|
|
|
|
|
|
|
|
if left_top.x > 512 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if left_top.x < -512 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if left_top.y > 512 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if left_top.y < -512 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-09-24 19:37:11 +02:00
|
|
|
game.forces.player.chart(surface, { { left_top.x, left_top.y }, { left_top.x + 31, left_top.y + 31 } })
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
2019-10-26 11:47:46 +02:00
|
|
|
local function set_difficulty()
|
2021-03-24 17:46:00 +02:00
|
|
|
local wave_defense_table = WD.get_table()
|
2019-10-30 21:00:32 +02:00
|
|
|
|
2021-03-24 17:46:00 +02:00
|
|
|
wave_defense_table.threat_gain_multiplier = 2 + #game.connected_players * 0.1
|
|
|
|
--20 Players for fastest wave_interval
|
|
|
|
wave_defense_table.wave_interval = 3600 - #game.connected_players * 90
|
|
|
|
if wave_defense_table.wave_interval < 1800 then
|
|
|
|
wave_defense_table.wave_interval = 1800
|
|
|
|
end
|
2019-10-26 11:47:46 +02:00
|
|
|
end
|
|
|
|
|
2019-09-29 17:12:25 +02:00
|
|
|
local function on_player_joined_game(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
set_difficulty()
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
2019-10-26 11:47:46 +02:00
|
|
|
local function on_player_left_game(event)
|
2021-03-24 17:46:00 +02:00
|
|
|
set_difficulty()
|
2019-10-26 11:47:46 +02:00
|
|
|
end
|
|
|
|
|
2019-09-29 17:12:25 +02:00
|
|
|
local function on_init()
|
2021-03-24 17:46:00 +02:00
|
|
|
local T = Map.Pop_info()
|
|
|
|
T.main_caption = '4 Quarters'
|
|
|
|
T.sub_caption = 'coal ++ iron ++ copper ++ stone'
|
|
|
|
T.text =
|
|
|
|
table.concat(
|
2024-09-24 19:37:11 +02:00
|
|
|
{
|
|
|
|
'Green energy ore may be found in the stone area.\n',
|
|
|
|
'Oil may be found in the coal area.\n',
|
|
|
|
'\n',
|
|
|
|
'Hold the door as long as possible.\n',
|
|
|
|
"Don't let them in!\n"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
T.main_caption_color = { r = 0, g = 120, b = 0 }
|
|
|
|
T.sub_caption_color = { r = 255, g = 0, b = 255 }
|
|
|
|
for i, quarter in pairs({ 'coal', 'iron-ore', 'stone', 'copper-ore' }) do
|
2021-03-24 17:46:00 +02:00
|
|
|
local map_gen_settings = {}
|
|
|
|
map_gen_settings.seed = math.random(1, 999999999)
|
|
|
|
map_gen_settings.water = math.random(25, 50) * 0.01
|
|
|
|
map_gen_settings.starting_area = 1.5
|
|
|
|
map_gen_settings.terrain_segmentation = math.random(25, 50) * 0.1
|
2024-09-24 19:37:11 +02:00
|
|
|
map_gen_settings.cliff_settings = { cliff_elevation_interval = 0, cliff_elevation_0 = 0 }
|
2021-03-24 17:46:00 +02:00
|
|
|
map_gen_settings.autoplace_controls = {
|
2024-09-24 19:37:11 +02:00
|
|
|
['coal'] = { frequency = 0, size = 0.5, richness = 0.5 },
|
|
|
|
['stone'] = { frequency = 0, size = 0.5, richness = 0.5 },
|
|
|
|
['copper-ore'] = { frequency = 0, size = 0.5, richness = 0.5 },
|
|
|
|
['iron-ore'] = { frequency = 0, size = 0.5, richness = 0.5 },
|
|
|
|
['uranium-ore'] = { frequency = 0, size = 1, richness = 1 },
|
|
|
|
['crude-oil'] = { frequency = 0, size = 1, richness = 1 },
|
|
|
|
['trees'] = { frequency = math.random(10, 50) * 0.1, size = math.random(5, 15) * 0.1, richness = math.random(1, 10) * 0.1 },
|
|
|
|
['enemy-base'] = { frequency = 2, size = 2, richness = 1 }
|
2021-03-24 17:46:00 +02:00
|
|
|
}
|
|
|
|
map_gen_settings.autoplace_controls[quarter].frequency = 16
|
|
|
|
|
|
|
|
if quarter == 'coal' then
|
|
|
|
map_gen_settings.autoplace_controls['crude-oil'].frequency = 8
|
|
|
|
end
|
|
|
|
if quarter == 'stone' then
|
|
|
|
map_gen_settings.autoplace_controls['uranium-ore'].frequency = 8
|
|
|
|
end
|
|
|
|
|
|
|
|
game.create_surface(quarter, map_gen_settings)
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
2019-09-29 17:12:25 +02:00
|
|
|
game.map_settings.enemy_expansion.enabled = true
|
|
|
|
game.map_settings.enemy_expansion.settler_group_min_size = 8
|
|
|
|
game.map_settings.enemy_expansion.settler_group_max_size = 16
|
2019-09-29 19:50:42 +02:00
|
|
|
game.map_settings.enemy_expansion.min_expansion_cooldown = 2700
|
|
|
|
game.map_settings.enemy_expansion.max_expansion_cooldown = 2700
|
2021-03-24 17:46:00 +02:00
|
|
|
|
2019-09-29 18:50:53 +02:00
|
|
|
game.map_settings.pollution.enabled = true
|
|
|
|
game.map_settings.enemy_evolution.enabled = true
|
2021-03-24 17:46:00 +02:00
|
|
|
|
2019-09-29 18:50:53 +02:00
|
|
|
local modifier_factor = 2
|
2021-03-24 17:46:00 +02:00
|
|
|
|
2019-09-29 18:50:53 +02:00
|
|
|
--default game setting values
|
2024-09-24 19:37:11 +02:00
|
|
|
storage.enemy_evolution_destroy_factor = game.map_settings.enemy_evolution.destroy_factor * modifier_factor
|
|
|
|
storage.enemy_evolution_time_factor = game.map_settings.enemy_evolution.time_factor * modifier_factor
|
|
|
|
storage.enemy_evolution_pollution_factor = game.map_settings.enemy_evolution.pollution_factor * modifier_factor
|
2019-10-26 11:47:46 +02:00
|
|
|
]]
|
2019-09-29 17:12:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local event = require 'utils.event'
|
2019-10-26 11:47:46 +02:00
|
|
|
--event.on_nth_tick(60, tick)
|
2019-09-29 17:12:25 +02:00
|
|
|
event.on_init(on_init)
|
|
|
|
event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
2019-10-28 18:38:36 +02:00
|
|
|
--event.add(defines.events.on_entity_died, on_entity_died)
|
2019-10-26 11:47:46 +02:00
|
|
|
--event.add(defines.events.on_research_finished, on_research_finished)
|
2019-09-29 17:12:25 +02:00
|
|
|
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
2019-10-26 11:47:46 +02:00
|
|
|
event.add(defines.events.on_player_left_game, on_player_left_game)
|
2019-09-29 17:12:25 +02:00
|
|
|
|
2021-01-25 02:37:17 +02:00
|
|
|
--require "modules.difficulty_vote"
|