mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-30 23:17:53 +02:00
update
This commit is contained in:
parent
baa92bfe6e
commit
99b66ceea5
@ -1,13 +1,9 @@
|
||||
local function reset_forces()
|
||||
local function reset_forces(new_surface, old_surface)
|
||||
for _, f in pairs(game.forces) do
|
||||
local spawn = {x = game.forces.player.get_spawn_position(old_surface).x, y = game.forces.player.get_spawn_position(old_surface).y}
|
||||
f.reset()
|
||||
f.reset_evolution()
|
||||
end
|
||||
end
|
||||
|
||||
local function set_spawn_positions(new_surface, old_surface)
|
||||
for _, f in pairs(game.forces) do
|
||||
f.set_spawn_position(f.get_spawn_position(old_surface), new_surface)
|
||||
f.set_spawn_position(spawn, new_surface)
|
||||
end
|
||||
end
|
||||
|
||||
@ -16,7 +12,7 @@ local function teleport_players(surface)
|
||||
local spawn = player.force.get_spawn_position(surface)
|
||||
local chunk = {math.floor(spawn.x / 32), math.floor(spawn.y / 32)}
|
||||
if not surface.is_chunk_generated(chunk) then
|
||||
surface.request_to_generate_chunks(spawn, 2)
|
||||
surface.request_to_generate_chunks(spawn, 1)
|
||||
surface.force_generate_chunk_requests()
|
||||
end
|
||||
local pos = surface.find_non_colliding_position("character", spawn, 3, 0.5)
|
||||
@ -42,11 +38,10 @@ function soft_reset_map(old_surface, map_gen_settings, player_starting_items)
|
||||
global.soft_reset_counter = global.soft_reset_counter + 1
|
||||
|
||||
local new_surface = game.create_surface(global.original_surface_name .. "_" .. tostring(global.soft_reset_counter), map_gen_settings)
|
||||
new_surface.request_to_generate_chunks({0,0}, 3)
|
||||
new_surface.request_to_generate_chunks({0,0}, 1)
|
||||
new_surface.force_generate_chunk_requests()
|
||||
|
||||
reset_forces()
|
||||
set_spawn_positions(new_surface, old_surface)
|
||||
reset_forces(new_surface, old_surface)
|
||||
teleport_players(new_surface)
|
||||
equip_players(player_starting_items)
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
require "modules.biter_evasion_hp_increaser"
|
||||
require "modules.wave_defense"
|
||||
--require "modules.dense_rocks"
|
||||
require "functions.soft_reset"
|
||||
require "modules.biters_yield_coins"
|
||||
require "modules.rocks_broken_paint_tiles"
|
||||
require "modules.rocks_heal_over_time"
|
||||
@ -32,7 +33,9 @@ require "maps.mountain_fortress_v2.terrain"
|
||||
require "maps.mountain_fortress_v2.locomotive"
|
||||
require "maps.mountain_fortress_v2.explosives"
|
||||
|
||||
local function init_surface()
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16}
|
||||
|
||||
local function get_gen_settings()
|
||||
local map = {
|
||||
["seed"] = math.random(1, 1000000),
|
||||
["water"] = 0,
|
||||
@ -45,7 +48,42 @@ local function init_surface()
|
||||
["decorative"] = {treat_missing_as_default = true},
|
||||
},
|
||||
}
|
||||
game.create_surface("mountain_fortress", map)
|
||||
return map
|
||||
end
|
||||
|
||||
function reset_map()
|
||||
global.chunk_queue = {}
|
||||
|
||||
if not global.active_surface then
|
||||
global.active_surface = game.create_surface("mountain_fortress", get_gen_settings())
|
||||
else
|
||||
global.active_surface = soft_reset_map(global.active_surface, get_gen_settings(), starting_items)
|
||||
end
|
||||
|
||||
global.active_surface.request_to_generate_chunks({0,0}, 2)
|
||||
global.active_surface.force_generate_chunk_requests()
|
||||
|
||||
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 = true
|
||||
game.map_settings.enemy_expansion.max_expansion_cooldown = 1800
|
||||
game.map_settings.enemy_expansion.min_expansion_cooldown = 1800
|
||||
game.map_settings.enemy_expansion.settler_group_max_size = 16
|
||||
game.map_settings.enemy_expansion.settler_group_min_size = 32
|
||||
game.map_settings.pollution.enabled = false
|
||||
|
||||
game.forces.player.technologies["steel-axe"].researched = true
|
||||
game.forces.player.technologies["railway"].researched = true
|
||||
game.forces.player.set_spawn_position({-2, 16}, global.active_surface)
|
||||
|
||||
locomotive_spawn(global.active_surface, {x = 0, y = 16})
|
||||
|
||||
reset_wave_defense()
|
||||
global.wave_defense.surface = global.active_surface
|
||||
global.wave_defense.target = global.locomotive_cargo
|
||||
|
||||
if global.rpg then rpg_reset_all_players() end
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
@ -55,6 +93,7 @@ local function on_entity_died(event)
|
||||
player.play_sound{path="utility/game_lost", volume_modifier=0.75}
|
||||
end
|
||||
game.print("The cargo was destroyed!")
|
||||
reset_map()
|
||||
--global.wave_defense.game_lost = true
|
||||
return
|
||||
end
|
||||
@ -73,46 +112,19 @@ local function on_entity_damaged(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local surface = game.surfaces["mountain_fortress"]
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if player.online_time == 0 then
|
||||
player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 3, 0.5), surface)
|
||||
player.insert({name = 'pistol', count = 1})
|
||||
player.insert({name = 'firearm-magazine', count = 16})
|
||||
player.insert({name = 'rail', count = 16})
|
||||
player.insert({name = 'wood', count = 16})
|
||||
player.teleport(global.active_surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(global.active_surface), 3, 0.5), global.active_surface)
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init(surface)
|
||||
global.chunk_queue = {}
|
||||
|
||||
init_surface()
|
||||
|
||||
local surface = game.surfaces["mountain_fortress"]
|
||||
surface.request_to_generate_chunks({0,0}, 6)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
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 = true
|
||||
game.map_settings.enemy_expansion.max_expansion_cooldown = 1800
|
||||
game.map_settings.enemy_expansion.min_expansion_cooldown = 1800
|
||||
game.map_settings.enemy_expansion.settler_group_max_size = 16
|
||||
game.map_settings.enemy_expansion.settler_group_min_size = 32
|
||||
game.map_settings.pollution.enabled = false
|
||||
|
||||
game.forces.player.technologies["steel-axe"].researched = true
|
||||
game.forces.player.technologies["railway"].researched = true
|
||||
game.forces.player.set_spawn_position({-2, 16}, surface)
|
||||
|
||||
locomotive_spawn(surface, {x = 0, y = 16})
|
||||
|
||||
global.wave_defense.surface = surface
|
||||
global.wave_defense.target = global.locomotive_cargo
|
||||
reset_map()
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
|
@ -175,10 +175,9 @@ local function out_of_map(surface, left_top)
|
||||
end
|
||||
end
|
||||
|
||||
local function process_chunk(left_top)
|
||||
local surface = game.surfaces["mountain_fortress"]
|
||||
local function process_chunk(surface, left_top)
|
||||
--game.forces.player.chart(surface, {{left_top.x, left_top.y},{left_top.x + 31, left_top.y + 31}})
|
||||
if left_top.y == 96 and left_top.x == 96 then
|
||||
if left_top.y == 64 and left_top.x == 64 then
|
||||
local p = global.locomotive.position
|
||||
for _, entity in pairs(surface.find_entities_filtered({area = {{p.x - 3, p.y - 4},{p.x + 3, p.y + 8}}, force = "neutral"})) do entity.destroy() end
|
||||
end
|
||||
@ -189,24 +188,22 @@ local function process_chunk(left_top)
|
||||
end
|
||||
|
||||
local function process_chunk_queue()
|
||||
for k, left_top in pairs(global.chunk_queue) do
|
||||
process_chunk(left_top)
|
||||
for k, chunk in pairs(global.chunk_queue) do
|
||||
if chunk.surface then
|
||||
if chunk.surface.valid then
|
||||
process_chunk(chunk.surface, chunk.left_top)
|
||||
end
|
||||
end
|
||||
global.chunk_queue[k] = nil
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
if game.surfaces["mountain_fortress"].index ~= event.surface.index then return end
|
||||
local left_top = event.area.left_top
|
||||
|
||||
if game.tick == 0 then
|
||||
process_chunk(left_top)
|
||||
else
|
||||
global.chunk_queue[#global.chunk_queue + 1] = {x = left_top.x, y = left_top.y}
|
||||
end
|
||||
if event.surface.index == 1 then return end
|
||||
global.chunk_queue[#global.chunk_queue + 1] = {left_top = event.area.left_top, surface = event.surface}
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_nth_tick(10, process_chunk_queue)
|
||||
event.on_nth_tick(15, process_chunk_queue)
|
||||
event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
@ -10,7 +10,7 @@ local threat_values = {
|
||||
["small-spitter"] = 1,
|
||||
}
|
||||
|
||||
function roll_biter_name()
|
||||
local function roll_biter_name()
|
||||
local max_chance = 0
|
||||
for k, v in pairs(global.wave_defense.biter_raffle) do
|
||||
max_chance = max_chance + v
|
||||
@ -23,7 +23,7 @@ function roll_biter_name()
|
||||
end
|
||||
end
|
||||
|
||||
function set_biter_raffle(level)
|
||||
local function set_biter_raffle(level)
|
||||
global.wave_defense.biter_raffle = {
|
||||
["small-biter"] = 1000 - level * 2,
|
||||
["small-spitter"] = 1000 - level * 2,
|
||||
@ -97,6 +97,8 @@ local function set_enemy_evolution()
|
||||
if evolution > 1 then
|
||||
global.biter_evasion_health_increase_factor = (evolution - 1) * 4
|
||||
evolution = 1
|
||||
else
|
||||
global.biter_evasion_health_increase_factor = 1
|
||||
end
|
||||
game.forces.enemy.evolution_factor = evolution
|
||||
end
|
||||
@ -135,7 +137,7 @@ local function spawn_wave()
|
||||
global.wave_defense.wave_number = global.wave_defense.wave_number + 1
|
||||
global.wave_defense.group_size = global.wave_defense.wave_number * 2
|
||||
if global.wave_defense.group_size > global.wave_defense.max_group_size then global.wave_defense.group_size = global.wave_defense.max_group_size end
|
||||
global.wave_defense.threat = global.wave_defense.threat + global.wave_defense.wave_number * 4
|
||||
global.wave_defense.threat = global.wave_defense.threat + global.wave_defense.wave_number * 3
|
||||
set_enemy_evolution()
|
||||
set_biter_raffle(global.wave_defense.wave_number)
|
||||
for a = 1, 16, 1 do
|
||||
@ -194,8 +196,8 @@ local function update_gui(player)
|
||||
if not player.gui.top.wave_defense then create_gui(player) end
|
||||
player.gui.top.wave_defense.label.caption = "Wave: " .. global.wave_defense.wave_number
|
||||
if global.wave_defense.wave_number == 0 then player.gui.top.wave_defense.label.caption = "First wave in " .. math.floor((global.wave_defense.next_wave - game.tick) / 60) + 1 end
|
||||
local v = math.round(game.tick / global.wave_defense.next_wave, 3)
|
||||
player.gui.top.wave_defense.progressbar.value = v
|
||||
local interval = global.wave_defense.next_wave - global.wave_defense.last_wave
|
||||
player.gui.top.wave_defense.progressbar.value = 1 - (global.wave_defense.next_wave - game.tick) / interval
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
@ -214,6 +216,7 @@ local function on_tick()
|
||||
if game.tick < global.wave_defense.next_wave then return end
|
||||
|
||||
if global.wave_defense.active_biter_count < global.wave_defense.max_active_biters then
|
||||
global.wave_defense.last_wave = global.wave_defense.next_wave
|
||||
global.wave_defense.next_wave = game.tick + global.wave_defense.wave_interval
|
||||
time_out_biters()
|
||||
set_target()
|
||||
@ -229,7 +232,7 @@ local function on_tick()
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
function reset_wave_defense()
|
||||
global.wave_defense = {
|
||||
surface = game.surfaces["nauvis"],
|
||||
active_biters = {},
|
||||
@ -239,7 +242,8 @@ local function on_init()
|
||||
max_biter_age = 3600 * 30,
|
||||
active_biter_count = 0,
|
||||
spawn_position = {x = 0, y = 48},
|
||||
next_wave = 3600 * 10,
|
||||
last_wave = game.tick,
|
||||
next_wave = game.tick + 36 * 10,
|
||||
wave_interval = 1800,
|
||||
wave_number = 0,
|
||||
game_lost = false,
|
||||
@ -247,6 +251,9 @@ local function on_init()
|
||||
}
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
reset_wave_defense()
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_nth_tick(30, on_tick)
|
||||
|
@ -1,66 +0,0 @@
|
||||
--this tool should provide you with smoother gameplay in heavily modified custom maps--
|
||||
--tiles will be generated first, entities will be placed, when there are no more tiles left to process--
|
||||
--by mewmew
|
||||
|
||||
local event = require 'utils.event'
|
||||
local lazy_chunk_loader = {}
|
||||
local chunk_functions = {}
|
||||
|
||||
--cut chunks into pieces and fill them into chunk_pieces tables
|
||||
local function on_chunk_generated(event)
|
||||
if not global.chunk_pieces then global.chunk_pieces = {} end
|
||||
if not global.chunk_pieces_entities then global.chunk_pieces_entities = {} end
|
||||
if not global.chunk_pieces_load_amount then global.chunk_pieces_load_amount = 128 end
|
||||
if not global.chunk_pieces_load_speed then global.chunk_pieces_load_speed = 2 end -- how many ticks until one operation happens
|
||||
if game.tick > 300 then global.chunk_pieces_load_amount = 1 end -- how many pieces are processed per one operation
|
||||
local index = event.surface.index
|
||||
for pos_y = 0, 24, 8 do
|
||||
for pos_x = 0, 24, 8 do
|
||||
table.insert(global.chunk_pieces, {{x = event.area.left_top.x + pos_x, y = event.area.left_top.y + pos_y}, index})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--process the pieces lazy, calling chunk_functions()
|
||||
local function on_tick()
|
||||
if global.chunk_pieces[1] then
|
||||
if game.tick % global.chunk_pieces_load_speed ~= 0 then return end
|
||||
local z = global.chunk_pieces_load_amount
|
||||
for x = #global.chunk_pieces, 1, -1 do
|
||||
if not global.chunk_pieces[x] then return end
|
||||
for _, f in pairs(chunk_functions) do
|
||||
f(global.chunk_pieces[x])
|
||||
end
|
||||
global.chunk_pieces[x] = nil
|
||||
z = z - 1
|
||||
if z == 0 then break end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
--process the pieces lazy, calling chunk_functions()
|
||||
local function on_tick()
|
||||
if #global.chunk_pieces > 0 then
|
||||
if game.tick % global.chunk_pieces_load_speed ~= 0 then return end
|
||||
for x = 1, global.chunk_pieces_load_amount, 1 do
|
||||
local i, z = next(global.chunk_pieces, nil)
|
||||
if not i then return end
|
||||
for _, f in pairs(chunk_functions) do
|
||||
f(global.chunk_pieces[i])
|
||||
end
|
||||
global.chunk_pieces[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
]]--
|
||||
|
||||
--add custom terrain functions here
|
||||
lazy_chunk_loader.add = function(f)
|
||||
table.insert(chunk_functions, f)
|
||||
end
|
||||
|
||||
event.add(defines.events.on_tick, on_tick)
|
||||
event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
||||
|
||||
return lazy_chunk_loader
|
Loading…
Reference in New Issue
Block a user