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

biter_battles_v2 desync fixes

This commit is contained in:
MewMew 2019-03-17 18:19:40 +01:00
parent a79499918d
commit 4830fc2740
12 changed files with 94 additions and 66 deletions

View File

@ -16,7 +16,6 @@ require "group"
require "player_list"
require "poll"
require "score"
require "on_tick_schedule"
---- enable modules here ----
--require "tools.cheat_mode"

View File

@ -1,5 +1,6 @@
-- Biter Battles -- mewmew made this --
require "on_tick_schedule"
require "modules.splice_double"
require "modules.explosive_biters"
require "modules.spawners_contain_biters"

View File

@ -1,24 +1,24 @@
-- Biter Battles v2 -- by MewMew
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.spawners_contain_biters"
local event = require 'utils.event'
local function init_surface()
if game.surfaces["biter_battles"] then return end
local function init_surface()
local map_gen_settings = {}
map_gen_settings.water = "0.25"
map_gen_settings.starting_area = "4.5"
map_gen_settings.cliff_settings = {cliff_elevation_interval = 12, cliff_elevation_0 = 32}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = "2.5", size = "1", richness = "1"},
["stone"] = {frequency = "2.5", size = "1", richness = "1"},
["copper-ore"] = {frequency = "2.5", size = "1", richness = "1"},
["iron-ore"] = {frequency = "2.5", size = "1", richness = "1"},
["coal"] = {frequency = "2", size = "1", richness = "1"},
["stone"] = {frequency = "2", size = "1", richness = "1"},
["copper-ore"] = {frequency = "2", size = "1", richness = "1"},
["iron-ore"] = {frequency = "2", size = "1", richness = "1"},
["uranium-ore"] = {frequency = "2", size = "1", richness = "1"},
["crude-oil"] = {frequency = "3", size = "1", richness = "1"},
["trees"] = {frequency = "0.5", size = "1", richness = "1"},
["trees"] = {frequency = "0.5", size = "0.7", richness = "0.7"},
["enemy-base"] = {frequency = "2", size = "3", richness = "1"}
}
game.create_surface("biter_battles", map_gen_settings)
@ -35,9 +35,9 @@ local function init_surface()
game.map_settings.enemy_expansion.max_expansion_cooldown = 108000
end
local function init_forces(surface)
if game.forces.north then return end
local function init_forces()
local surface = game.surfaces["biter_battles"]
game.create_force("north")
game.create_force("north_biters")
game.create_force("south")
@ -111,6 +111,7 @@ local function init_forces(surface)
global.bb_evasion = {}
global.bb_threat_income = {}
global.bb_threat = {}
global.chunks_to_mirror = {}
for _, force in pairs(game.forces) do
game.forces[force.name].technologies["artillery"].enabled = false
@ -131,10 +132,8 @@ local function init_forces(surface)
end
local function on_player_joined_game(event)
if not global.bb_first_init_done then
init_surface()
init_forces(game.surfaces["biter_battles"])
global.bb_first_init_done = true
if not game.surfaces["biter_battles"] then
end
local surface = game.surfaces["biter_battles"]
@ -153,10 +152,16 @@ local function on_player_joined_game(event)
end
end
local function on_init(surface)
if game.surfaces["biter_battles"] then return end
init_surface()
init_forces()
end
event.on_init(on_init)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
require "maps.biter_battles_v2.on_tick"
require "maps.biter_battles_v2.terrain"
require "maps.biter_battles_v2.mirror_terrain"
require "maps.biter_battles_v2.chat"
require "maps.biter_battles_v2.game_won"
require "maps.biter_battles_v2.on_tick"

View File

@ -85,14 +85,12 @@ local function process_entity(surface, entity)
surface.create_entity({name = entity.name, position = new_pos, direction = direction_translation[entity.direction], force = entity.force.name})
end
local function mirror_chunk(surface, chunk_area, chunk_position)
if not surface then return end
if not chunk_area then return end
if not chunk_position then return end
if not surface.is_chunk_generated(chunk_position) then
local function mirror_chunk(surface, chunk)
local chunk_area = {left_top = {x = chunk.x * 32, y = chunk.y * 32}, right_bottom = {x = chunk.x * 32 + 32, y = chunk.y * 32 + 32}}
if not surface.is_chunk_generated(chunk) then
surface.request_to_generate_chunks({x = chunk_area.left_top.x - 16, y = chunk_area.left_top.y - 16}, 1)
surface.force_generate_chunk_requests()
end
end
for _, tile in pairs(surface.find_tiles_filtered({area = chunk_area})) do
surface.set_tiles({{name = tile.name, position = {x = tile.position.x * -1, y = (tile.position.y * -1) - 1}}}, true)
end
@ -104,13 +102,10 @@ local function mirror_chunk(surface, chunk_area, chunk_position)
check_collision=false,
decoratives={{name = decorative.decorative.name, position = {x = decorative.position.x * -1, y = (decorative.position.y * -1) - 1}, amount = decorative.amount}}
}
end
end
end
local function on_chunk_generated(event)
if event.area.left_top.y < 0 then return end
local surface = event.surface
local function clear_chunk(surface, event)
if event.area.left_top.y > 32 or event.area.left_top.x > 32 or event.area.left_top.x < -32 then
for _, e in pairs(surface.find_entities_filtered({area = event.area})) do
if e.valid then
@ -125,19 +120,44 @@ local function on_chunk_generated(event)
end
end
end
end
end
surface.destroy_decoratives{area=event.area}
end
local function on_chunk_generated(event)
if event.area.left_top.y < 0 then return end
if event.surface.name ~= "biter_battles" then return end
clear_chunk(event.surface, event)
local x = ((event.area.left_top.x + 16) * -1) - 16
local y = ((event.area.left_top.y + 16) * -1) - 16
local mirror_chunk_area = {left_top = {x = x, y = y}, right_bottom = {x = x + 32, y = y + 32}}
if not global.on_tick_schedule[game.tick + 5] then global.on_tick_schedule[game.tick + 5] = {} end
global.on_tick_schedule[game.tick + 5][#global.on_tick_schedule[game.tick + 5] + 1] = {
func = mirror_chunk,
args = {game.surfaces["biter_battles"], mirror_chunk_area, get_chunk_position({x = x, y = y})}
}
local chunk = get_chunk_position({x = x, y = y})
local delay = 30
if not global.chunks_to_mirror[game.tick + delay] then global.chunks_to_mirror[game.tick + delay] = {} end
global.chunks_to_mirror[game.tick + delay][#global.chunks_to_mirror[game.tick + delay] + 1] = {x = chunk.x, y = chunk.y}
--mirror_chunk(game.surfaces["biter_battles"], chunk)
--local delay = 60
--if not global.on_tick_schedule[game.tick + delay] then global.on_tick_schedule[game.tick + delay] = {} end
--global.on_tick_schedule[game.tick + delay][#global.on_tick_schedule[game.tick + delay] + 1] = {
-- func = mirror_chunk,
-- args = {surface, {x = chunk.x, y = chunk.y}}
--}
end
local function mirror_map()
for i, c in pairs(global.chunks_to_mirror) do
if i < game.tick then
for _, chunk in pairs(global.chunks_to_mirror[i]) do
mirror_chunk(game.surfaces["biter_battles"], chunk)
end
global.chunks_to_mirror[i] = nil
end
end
end
event.add(defines.events.on_chunk_generated, on_chunk_generated)
return mirror_map

View File

@ -3,6 +3,7 @@ local event = require 'utils.event'
local gui = require "maps.biter_battles_v2.gui"
local ai = require "maps.biter_battles_v2.ai"
local chunk_pregen = require "maps.biter_battles_v2.pregenerate_chunks"
local mirror_map = require "maps.biter_battles_v2.mirror_terrain"
local function reveal_team(f)
local m = 32
@ -20,16 +21,16 @@ local function reveal_team(f)
end
local function on_tick(event)
if game.tick % 30 ~= 0 then return end
if game.tick % 30 ~= 15 then return end
chunk_pregen()
mirror_map()
if game.tick % 60 ~= 0 then return end
if game.tick % 60 ~= 15 then return end
global.bb_threat["north_biters"] = global.bb_threat["north_biters"] + global.bb_threat_income["north_biters"]
global.bb_threat["south_biters"] = global.bb_threat["south_biters"] + global.bb_threat_income["south_biters"]
global.bb_threat["south_biters"] = global.bb_threat["south_biters"] + global.bb_threat_income["south_biters"]
gui()
if game.tick % 300 ~= 0 then return end
if game.tick % 300 ~= 15 then return end
if global.spy_fish_timeout["south"] - game.tick > 0 then
reveal_team("north")
else
@ -41,7 +42,7 @@ local function on_tick(event)
global.spy_fish_timeout["north"] = 0
end
if game.tick % 3600 ~= 0 then return end
if game.tick % 3600 ~= 15 then return end
if global.bb_game_won_by_team then return end
ai.main_attack()
ai.send_near_biters_to_silo()

View File

@ -44,9 +44,10 @@ local function draw_gui()
end
end
local function process_chunk(surface)
if not global.chunk_gen_coords then set_chunk_coords(30) end
local function process_chunk(surface)
if global.map_generation_complete then return end
if game.tick < 600 then return end
if not global.chunk_gen_coords then set_chunk_coords(32) end
if #global.chunk_gen_coords == 0 then
global.map_generation_complete = true
draw_gui()

View File

@ -82,8 +82,8 @@ local function generate_circle_spawn(event)
tile = "deepwater"
if math_random(1, 48) == 1 then surface.create_entity({name = "fish", position = pos}) end
end
if distance_to_center < 9 then tile = "refined-concrete" end
if distance_to_center < 6 then tile = "sand-1" end
if distance_to_center < 9.5 then tile = "refined-concrete" end
if distance_to_center < 7 then tile = "sand-1" end
if tile then surface.set_tiles({{name = tile, position = pos}}, true) end
end
end
@ -134,9 +134,9 @@ local function rainbow_ore_and_ponds(event)
local pos = {x = left_top_x + x, y = left_top_y + y}
if surface.can_place_entity({name = "iron-ore", position = pos}) then
local noise = get_noise(1, pos)
if noise > 0.83 then
if noise > 0.81 then
local amount = math_random(1500, 2000) + math.sqrt(pos.x ^ 2 + pos.y ^ 2) * noise * 4
local i = math.ceil(math.abs(noise * 25)) % 4
local i = math.ceil(math.abs(noise * 30)) % 4
if i == 0 then i = 4 end
surface.create_entity({name = ores[i], position = pos, amount = amount})
end

View File

@ -1,5 +1,6 @@
--choppy-- mewmew made this --
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.satellite_score"
require "modules.spawners_contain_biters"

View File

@ -1,6 +1,7 @@
-- just an empty map for testing thingies
local event = require 'utils.event'
local map_functions = require "tools.map_functions"
require "maps.empty_map_test"
function dump_boom_layout()
local surface = game.surfaces["empty_map"]
@ -38,7 +39,6 @@ local function on_chunk_generated(event)
left_top = {x = chunk_pos_x, y = chunk_pos_y},
right_bottom = {x = chunk_pos_x + 31, y = chunk_pos_y + 31}
}
surface.destroy_decoratives({area = area})
local decoratives = {}

View File

@ -1,5 +1,6 @@
--junkyard-- mewmew made this --
require "on_tick_schedule"
require "modules.dynamic_landfill"
require "modules.satellite_score"
require "modules.mineable_wreckage_yields_scrap"

View File

@ -148,7 +148,7 @@ local function create_teleport_gui(player)
scroll_pane.style.maximal_height = 320
scroll_pane.style.minimal_height = 320
local t = scroll_pane.add({type = "table", column_count = 3})
local t = scroll_pane.add({type = "table", column_count = 3, name = "team_teleport_table"})
local player_table = get_sorted_player_table(player)
for _, k in pairs(player_table) do
@ -185,6 +185,7 @@ local function on_gui_click(event)
end
if not game.players[name] then return end
if event.element.parent.name ~= "team_teleport_table" then return end
if not player.character then return end
if not game.players[name].character then return end
if player.character.driving then return end

View File

@ -1,26 +1,24 @@
local event = require 'utils.event'
local function trigger_function(schedule)
if not schedule.args then schedule.func() return end
if not schedule.args[2] then schedule.func(schedule.args[1]) return end
if not schedule.args[3] then schedule.func(schedule.args[1], schedule.args[2]) return end
if not schedule.args[4] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3]) return end
if not schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4]) return end
if schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4], schedule.args[5]) return end
end
--local function trigger_function(schedule)
-- if not schedule.args then schedule.func() return end
-- if not schedule.args[2] then schedule.func(schedule.args[1]) return end
-- if not schedule.args[3] then schedule.func(schedule.args[1], schedule.args[2]) return end
-- if not schedule.args[4] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3]) return end
-- if not schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4]) return end
-- if schedule.args[5] then schedule.func(schedule.args[1], schedule.args[2], schedule.args[3], schedule.args[4], schedule.args[5]) return end
--end
local function on_tick()
if not global.on_tick_schedule[game.tick] then return end
local function on_tick()
if not global.on_tick_schedule[game.tick] then return end
for _, schedule in pairs(global.on_tick_schedule[game.tick]) do
trigger_function(schedule)
end
schedule.func(unpack(schedule.args))
end
global.on_tick_schedule[game.tick] = nil
end
local function on_init(event)
if not global.on_tick_schedule then global.on_tick_schedule = {} end
if not global.on_tick_schedule then global.on_tick_schedule = {} end
end
event.on_init(on_init)