1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00

biter_battles_v2 desync fixing

This commit is contained in:
MewMew 2019-03-17 02:35:58 +01:00
parent 7a4b9f0ed8
commit a79499918d
10 changed files with 224 additions and 123 deletions

View File

@ -35,7 +35,7 @@ ai.send_near_biters_to_silo = function()
},
unit_count = 8,
force = "north_biters",
unit_search_distance=160
unit_search_distance=128
})
game.surfaces["biter_battles"].set_multi_command({
@ -46,7 +46,7 @@ ai.send_near_biters_to_silo = function()
},
unit_count = 8,
force = "south_biters",
unit_search_distance=160
unit_search_distance=128
})
end
@ -63,13 +63,15 @@ local function get_random_close_spawner(surface, biter_force_name)
end
local function select_units_around_spawner(spawner, force_name, biter_force_name)
local biters = spawner.surface.find_enemy_units(spawner.position, 96, force_name)
local biters = spawner.surface.find_enemy_units(spawner.position, 128, force_name)
if not biters[1] then return false end
local valid_biters = {}
local threat = global.bb_threat[biter_force_name] * 0.5
local threat = global.bb_threat[biter_force_name] * 0.3
for _, biter in pairs(biters) do
valid_biters[#valid_biters + 1] = biter
threat = threat - threat_values[biter.name]
if biter.force.name == biter_force_name then
valid_biters[#valid_biters + 1] = biter
threat = threat - threat_values[biter.name]
end
if threat < 0 then break end
end
return valid_biters
@ -116,6 +118,7 @@ ai.main_attack = function()
local surface = game.surfaces["biter_battles"]
for _, force_name in pairs({"north", "south"}) do
create_attack_group(surface, force_name, force_name .. "_biters")
create_attack_group(surface, force_name, force_name .. "_biters")
end
end

View File

@ -2,27 +2,24 @@
require "modules.dynamic_landfill"
require "modules.spawners_contain_biters"
require "modules.custom_death_messages"
local event = require 'utils.event'
local table_insert = table.insert
local math_random = math.random
local event = require 'utils.event'
local function init_surface()
if game.surfaces["biter_battles"] then return end
local map_gen_settings = {}
map_gen_settings.water = "0.5"
map_gen_settings.starting_area = "4"
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 = "3", size = "1", richness = "1"},
["stone"] = {frequency = "3", size = "1", richness = "1"},
["copper-ore"] = {frequency = "3", size = "1", richness = "1"},
["iron-ore"] = {frequency = "3", size = "1", richness = "1"},
["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"},
["uranium-ore"] = {frequency = "2", size = "1", richness = "1"},
["crude-oil"] = {frequency = "3", size = "1", richness = "1"},
["trees"] = {frequency = "2", size = "1", richness = "1"},
["enemy-base"] = {frequency = "2", size = "4", richness = "1"}
["trees"] = {frequency = "0.5", size = "1", richness = "1"},
["enemy-base"] = {frequency = "2", size = "3", richness = "1"}
}
game.create_surface("biter_battles", map_gen_settings)
@ -134,10 +131,13 @@ local function init_forces(surface)
end
local function on_player_joined_game(event)
init_surface()
local surface = game.surfaces["biter_battles"]
init_forces(surface)
if not global.bb_first_init_done then
init_surface()
init_forces(game.surfaces["biter_battles"])
global.bb_first_init_done = true
end
local surface = game.surfaces["biter_battles"]
local player = game.players[event.player_index]
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
@ -151,8 +151,6 @@ local function on_player_joined_game(event)
player.character.destructible = false
game.permissions.get_group("spectator").add_player(player.name)
end
--player.character.destroy()
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
@ -161,5 +159,4 @@ 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"
require "maps.biter_battles_v2.pregenerate_chunks"
require "maps.biter_battles_v2.on_tick"

View File

@ -46,7 +46,7 @@ local function feed_biters(player, food)
if flask_amount >= 20 then
game.print(player.name .. " fed " .. flask_amount .. " flasks of " .. food_values[food].name .. " juice to team " .. enemy_force_name .. "'s biters!", {r = 0.98, g = 0.66, b = 0.22})
else
if flask_amount > 1 then
if flask_amount == 1 then
player.print("You fed one flask of " .. food_values[food].name .. " juice to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22})
else
player.print("You fed " .. flask_amount .. " flasks of " .. food_values[food].name .. " juice to the enemy team's biters.", {r = 0.98, g = 0.66, b = 0.22})
@ -64,7 +64,7 @@ local function feed_biters(player, food)
---SET EVOLUTION
local e = (game.forces[biter_force_name].evolution_factor * 100) + 1
local diminishing_modifier = 1 / (10 ^ (e * 0.03))
local diminishing_modifier = 1 / (10 ^ (e * 0.032))
global.bb_evolution[biter_force_name] = global.bb_evolution[biter_force_name] + (food_values[food].value * diminishing_modifier)
if global.bb_evolution[biter_force_name] < 1 then
game.forces[biter_force_name].evolution_factor = global.bb_evolution[biter_force_name]

View File

@ -1,5 +1,4 @@
local event = require 'utils.event'
local math_random = math.random
local gui_values = {
["north"] = {c1 = "Team North", color1 = {r = 0.55, g = 0.55, b = 0.99}},
@ -9,7 +8,7 @@ local gui_values = {
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math_random(size)
local rand = math.random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
@ -31,7 +30,7 @@ end
local function annihilate_base(center_pos, surface, force_name)
local entities = {}
for _, e in pairs(surface.find_entities_filtered({force = force_name})) do
for _, e in pairs(surface.find_entities_filtered({force = force_name, area = {{center_pos.x - 40, center_pos.y - 40},{center_pos.x + 40, center_pos.y + 40}}})) do
if e.name ~= "player" then
entities[#entities + 1] = e
end
@ -52,7 +51,7 @@ local function annihilate_base(center_pos, surface, force_name)
end
for i = 1, #entities, 1 do
local t = i * 8
local t = i * 6
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
local pos = global.rocket_silo[global.bb_game_won_by_team].position
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
@ -64,8 +63,8 @@ end
local function create_fireworks_rocket(surface, position)
local particles = {"coal-particle", "copper-ore-particle", "iron-ore-particle", "stone-particle"}
local particle = particles[math_random(1, #particles)]
local m = math_random(16, 36)
local particle = particles[math.random(1, #particles)]
local m = math.random(16, 36)
local m2 = m * 0.005
for i = 1, 60, 1 do
@ -75,11 +74,11 @@ local function create_fireworks_rocket(surface, position)
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
movement = {m2 - (math.random(0, m) * 0.01), m2 - (math.random(0, m) * 0.01)}
})
end
if math_random(1,12) ~= 1 then return end
if math.random(1,12) ~= 1 then return end
surface.create_entity({name = "explosion", position = position})
end
@ -93,7 +92,7 @@ local function fireworks(surface)
func = create_fireworks_rocket,
args = {
surface,
{x = (pos.x - radius) + math_random(0, radius * 2),y = (pos.y - radius) + math_random(0, radius * 2)}
{x = (pos.x - radius) + math.random(0, radius * 2),y = (pos.y - radius) + math.random(0, radius * 2)}
}
}
end

View File

@ -4,13 +4,13 @@ local spy_fish = require "maps.biter_battles_v2.spy_fish"
local feed_the_biters = require "maps.biter_battles_v2.feeding"
local food_names = {
["automation-science-pack"] = "automation science",
["logistic-science-pack"] = "logistic science",
["military-science-pack"] = "military science",
["chemical-science-pack"] = "chemical science",
["production-science-pack"] = "production science",
["utility-science-pack"] = "utility science",
["space-science-pack"] = "space science"
["automation-science-pack"] = true,
["logistic-science-pack"] = true,
["military-science-pack"] = true,
["chemical-science-pack"] = true,
["production-science-pack"] = true,
["utility-science-pack"] = true,
["space-science-pack"] = true
}
local gui_values = {
@ -357,7 +357,7 @@ local function on_player_joined_game(event)
global.bb_view_players[player.name] = false
if #game.connected_players > 1 then
global.game_lobby_timeout = math.ceil(18000 / #game.connected_players)
global.game_lobby_timeout = math.ceil(36000 / #game.connected_players)
else
global.game_lobby_timeout = 5999940
end

View File

@ -2,6 +2,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 function reveal_team(f)
local m = 32
@ -19,7 +20,11 @@ local function reveal_team(f)
end
local function on_tick(event)
if game.tick % 60 ~= 0 then return end
if game.tick % 30 ~= 0 then return end
chunk_pregen()
if game.tick % 60 ~= 0 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"]
gui()
@ -39,9 +44,7 @@ local function on_tick(event)
if game.tick % 3600 ~= 0 then return end
if global.bb_game_won_by_team then return end
ai.main_attack()
if game.tick % 7200 ~= 0 then return end
ai.send_near_biters_to_silo()
ai.send_near_biters_to_silo()
end
event.add(defines.events.on_tick, on_tick)

View File

@ -1,93 +1,73 @@
local event = require 'utils.event'
local function get_chunk_coords(radius)
local coords = {}
local function set_chunk_coords(radius)
global.chunk_gen_coords = {}
for r = radius, 1, -1 do
for x = r * -1, r - 1, 1 do
local pos = {x = x, y = r * -1}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
for y = r * -1, r - 1, 1 do
local pos = {x = r, y = y}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
for x = r, r * -1 + 1, -1 do
local pos = {x = x, y = r}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
for y = r, r * -1 + 1, -1 do
local pos = {x = r * -1, y = y}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(global.chunk_gen_coords, pos) end
end
end
return coords
end
local function draw_gui(chunks_left, connected_players)
for _, player in pairs(connected_players) do
local caption = "Map is generating... " .. chunks_left .. " chunks left."
if player.gui.left["map_pregen"] then
player.gui.left["map_pregen"].caption = caption
local function draw_gui()
for _, player in pairs(game.connected_players) do
if global.map_generation_complete then
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
else
local frame = player.gui.left.add({
type = "frame",
caption = caption,
name = "map_pregen"
})
frame.style.font_color = {r = 100, g = 100, b = 250}
frame.style.font = "heading-2"
frame.style.maximal_height = 36
local caption = "Map is generating... " .. #global.chunk_gen_coords .. " chunks left."
if player.gui.left["map_pregen"] then
player.gui.left["map_pregen"].caption = caption
else
local frame = player.gui.left.add({
type = "frame",
caption = caption,
name = "map_pregen"
})
frame.style.font_color = {r = 100, g = 100, b = 250}
frame.style.font = "heading-2"
frame.style.maximal_height = 36
end
end
end
end
local function process_chunk(surface)
if not global.chunk_gen_coords then set_chunk_coords(30) end
if global.map_generation_complete then return end
if #global.chunk_gen_coords == 0 then
global.map_generation_complete = true
draw_gui()
return
end
if not game then return end
local surface = game.surfaces["biter_battles"]
if not surface then return end
for i = #global.chunk_gen_coords, 1, -1 do
if surface.is_chunk_generated(global.chunk_gen_coords[i]) then
global.chunk_gen_coords[i] = nil
else
surface.request_to_generate_chunks({x = (global.chunk_gen_coords[i].x * 32) - 16, y = (global.chunk_gen_coords[i].y * 32) - 16}, 1)
surface.force_generate_chunk_requests()
global.chunk_gen_coords[i] = nil
break
end
end
draw_gui()
end
local function kill_gui(connected_players)
for _, player in pairs(connected_players) do
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
end
end
local function process_chunk(surface, coord)
if surface.is_chunk_generated(coord) then return end
surface.request_to_generate_chunks({x = (coord.x * 32) - 16, y = (coord.y * 32) - 16}, 1)
surface.force_generate_chunk_requests()
end
local function create_schedule(radius)
local coords = get_chunk_coords(radius)
local speed = 10
for t = speed, #coords * speed + speed, speed do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
if coords[1] then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = process_chunk,
args = {game.surfaces["biter_battles"], {x = coords[#coords].x, y = coords[#coords].y}, game}
}
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = draw_gui,
args = {#coords, game.connected_players}
}
else
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = kill_gui,
args = {game.connected_players}
}
end
coords[#coords] = nil
end
end
local function on_player_joined_game(event)
if not global.map_generation_complete then
create_schedule(32)
global.map_generation_complete = true
end
local player = game.players[event.player_index]
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
return process_chunk

View File

@ -0,0 +1,111 @@
local event = require 'utils.event'
local function get_chunk_coords(radius)
local coords = {}
for r = radius, 1, -1 do
for x = r * -1, r - 1, 1 do
local pos = {x = x, y = r * -1}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
end
for y = r * -1, r - 1, 1 do
local pos = {x = r, y = y}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
end
for x = r, r * -1 + 1, -1 do
local pos = {x = x, y = r}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
end
for y = r, r * -1 + 1, -1 do
local pos = {x = r * -1, y = y}
if math.sqrt(pos.x ^ 2 + pos.y ^ 2) <= radius then table.insert(coords, pos) end
end
end
return coords
end
local function draw_gui(chunks_left, g)
for _, player in pairs(connected_players) do
local caption = "Map is generating... " .. chunks_left .. " chunks left."
if player.gui.left["map_pregen"] then
player.gui.left["map_pregen"].caption = caption
else
local frame = player.gui.left.add({
type = "frame",
caption = caption,
name = "map_pregen"
})
frame.style.font_color = {r = 100, g = 100, b = 250}
frame.style.font = "heading-2"
frame.style.maximal_height = 36
end
end
end
local function kill_gui(connected_players)
for _, player in pairs(connected_players) do
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
end
end
local function print_progress(str, p)
p(str, {r = 100, g = 100, b = 250})
end
local function process_chunk(surface, coord)
if surface.is_chunk_generated(coord) then return end
surface.request_to_generate_chunks({x = (coord.x * 32) - 16, y = (coord.y * 32) - 16}, 1)
surface.force_generate_chunk_requests()
end
local function create_schedule(radius)
local coords = get_chunk_coords(radius)
local speed = 10
for t = speed, #coords * speed + speed, speed do
if not global.on_tick_schedule[game.tick + t] then global.on_tick_schedule[game.tick + t] = {} end
if coords[1] then
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = process_chunk,
args = {game.surfaces["biter_battles"], {x = coords[#coords].x, y = coords[#coords].y}, game}
}
if #coords % 500 == 0 then
local str = "Map is generating... " .. tostring(#coords)
str = str .. " chunks left."
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = game.print,
args = {str, {r = 100, g = 100, b = 250}}
}
end
--global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
-- func = draw_gui,
-- args = {#coords, game}
--}
else
local str = "Map is generation complete!"
global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
func = game.print,
args = {str, {r = 100, g = 100, b = 250}}
}
--global.on_tick_schedule[game.tick + t][#global.on_tick_schedule[game.tick + t] + 1] = {
-- func = kill_gui,
-- args = {game}
--}
end
coords[#coords] = nil
end
end
local function on_player_joined_game(event)
if not global.map_generation_complete then
create_schedule(32)
global.map_generation_complete = true
end
local player = game.players[event.player_index]
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -119,13 +119,13 @@ local function generate_river(event)
local distance_to_center = math.sqrt(pos.x ^ 2 + pos.y ^ 2)
if generate_horizontal_river(surface, pos) then
surface.set_tiles({{name = "deepwater", position = pos}})
if math_random(1, 48) == 1 then surface.create_entity({name = "fish", position = pos}) end
if math_random(1, 64) == 1 then surface.create_entity({name = "fish", position = pos}) end
end
end
end
end
local function generate_rainbow_ore(event)
local function rainbow_ore_and_ponds(event)
local surface = event.surface
local left_top_x = event.area.left_top.x
local left_top_y = event.area.left_top.y
@ -140,6 +140,14 @@ local function generate_rainbow_ore(event)
if i == 0 then i = 4 end
surface.create_entity({name = ores[i], position = pos, amount = amount})
end
if noise < -0.83 then
if noise < -0.9 then
surface.set_tiles({{name = "deepwater", position = pos}})
else
surface.set_tiles({{name = "water", position = pos}})
end
if math_random(1, 48) == 1 then surface.create_entity({name = "fish", position = pos}) end
end
end
end
end
@ -179,11 +187,11 @@ local function on_chunk_generated(event)
e.destroy()
end
rainbow_ore_and_ponds(event)
generate_river(event)
generate_circle_spawn(event)
generate_silos(event)
generate_rainbow_ore(event)
generate_circle_spawn(event)
generate_potential_spawn_ore(event)
generate_silos(event)
if event.area.left_top.y == -160 and event.area.left_top.x == -160 then
local area = {{-10,-10},{10,10}}