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

Merge remote-tracking branch 'upstream/master' into mutagenLogFilters

This commit is contained in:
Masamune 2020-01-26 09:59:11 +01:00
commit ae7f135d39
8 changed files with 83 additions and 117 deletions

5
description.json Normal file
View File

@ -0,0 +1,5 @@
{
"order": "a",
"multiplayer-compatible": true,
"is-main-game": true
}

View File

@ -89,17 +89,27 @@ local function get_threat_ratio(biter_force_name)
end
local function is_biter_inactive(biter, unit_number, biter_force_name)
if not biter.entity.valid then return true end
if not biter.entity.unit_group then return true end
if not biter.entity.unit_group.valid then return true end
if game.tick - biter.active_since < bb_config.biter_timeout then return false end
if biter.entity.surface.count_entities_filtered({area = {{biter.entity.position.x - 16, biter.entity.position.y - 16},{biter.entity.position.x + 16, biter.entity.position.y + 16}}, force = {"north", "south"}}) ~= 0 then
global.active_biters[biter_force_name][unit_number].active_since = game.tick
return false
end
if global.bb_debug then game.print(biter_force_name .. " unit " .. unit_number .. " timed out at tick age " .. game.tick - biter.active_since) end
biter.entity.destroy()
return true
if not biter.entity then
print("BiterBattles: active unit " .. unit_number .. " removed, possibly died.")
return true
end
if not biter.entity.valid then
print("BiterBattles: active unit " .. unit_number .. " removed, biter invalid.")
return true
end
if not biter.entity.unit_group then
print("BiterBattles: active unit " .. unit_number .. " at x" .. biter.entity.position.x .. " y" .. biter.entity.position.y .. " removed, had no unit group.")
return true
end
if not biter.entity.unit_group.valid then
print("BiterBattles: active unit " .. unit_number .. " removed, unit group invalid.")
return true
end
if game.tick - biter.active_since > bb_config.biter_timeout then
print("BiterBattles: " .. biter_force_name .. " unit " .. unit_number .. " timed out at tick age " .. game.tick - biter.active_since .. ".")
biter.entity.destroy()
return true
end
end
local function set_active_biters(group)
@ -114,16 +124,15 @@ local function set_active_biters(group)
end
Public.destroy_inactive_biters = function()
local biter_force_name = global.next_attack .. "_biters"
for _, group in pairs(global.unit_groups) do
if not set_active_biters(group) then
end
set_active_biters(group)
end
for _, biter_force_name in pairs({"north_biters", "south_biters"}) do
for unit_number, biter in pairs(global.active_biters[biter_force_name]) do
if is_biter_inactive(biter, unit_number, biter_force_name) then
global.active_biters[biter_force_name][unit_number] = nil
end
for unit_number, biter in pairs(global.active_biters[biter_force_name]) do
if is_biter_inactive(biter, unit_number, biter_force_name) then
global.active_biters[biter_force_name][unit_number] = nil
end
end
end

View File

@ -16,10 +16,10 @@ local bb_config = {
["random_scrap"] = true, --Generate harvestable scrap around worms randomly?
--BITER SETTINGS--
["max_active_biters"] = 1500, --Maximum total amount of attacking units per side.
["max_active_biters"] = 2000, --Maximum total amount of attacking units per side.
["max_group_size"] = 256, --Maximum unit group size.
["biter_timeout"] = 54000, --Time it takes in ticks for an attacking unit to be deleted. This prevents perma stuck units.
["bitera_area_distance"] = 416 --Distance to the biter area.
["biter_timeout"] = 162000, --Time it takes in ticks for an attacking unit to be deleted. This prevents perma stuck units.
["bitera_area_distance"] = 432 --Distance to the biter area.
}
return bb_config

View File

@ -366,8 +366,8 @@ function Public.silo_death(event)
Server.to_discord_embed(c .. " has won!")
Server.to_discord_embed(global.victory_time)
fireworks(event.entity.surface)
annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name)
--fireworks(event.entity.surface)
--annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name)
end
end

View File

@ -12,12 +12,13 @@ local Map_info = require "maps.biter_battles_v2.map_info"
local Mirror_terrain = require "maps.biter_battles_v2.mirror_terrain"
local No_turret_creep = require "maps.biter_battles_v2.no_turret_creep"
local Team_manager = require "maps.biter_battles_v2.team_manager"
local Terrain = require "maps.biter_battles_v2.terrain"
require "on_tick_schedule"
require "maps.biter_battles_v2.map_settings_tab"
require "maps.biter_battles_v2.sciencelogs_tab"
require "modules.spawners_contain_biters"
require "modules.mineable_wreckage_yields_scrap"
require "modules.custom_death_messages"
local function on_player_joined_game(event)
local surface = game.surfaces["biter_battles"]
@ -63,6 +64,7 @@ end
local function on_robot_built_entity(event)
No_turret_creep.deny_building(event)
Terrain.deny_construction_bots(event)
end
local function on_entity_died(event)
@ -99,7 +101,7 @@ local tick_minute_functions = {
}
local function on_tick(event)
Mirror_terrain()
Mirror_terrain.ticking_work()
local tick = game.tick
@ -121,29 +123,54 @@ local function on_tick(event)
if tick_minute_functions[key] then tick_minute_functions[key]() end
end
local function on_marked_for_deconstruction(event)
if not event.entity.valid then return end
if event.entity.name == "fish" then event.entity.cancel_deconstruction(game.players[event.player_index].force.name) end
end
local function on_player_built_tile(event)
local player = game.players[event.player_index]
Terrain.restrict_landfill(player.surface, player, event.tiles)
end
local function on_robot_built_tile(event)
Terrain.restrict_landfill(event.robot.surface, event.robot.get_inventory(defines.inventory.robot_cargo), event.tiles)
end
local function on_chunk_generated(event)
Terrain.generate(event)
Mirror_terrain.add_chunks(event)
end
local function on_init()
Init.settings()
Init.surface()
Init.forces()
Team_manager.init()
local surface = game.surfaces["biter_battles"]
surface.request_to_generate_chunks({x = 0, y = -256}, 8)
surface.force_generate_chunk_requests()
Terrain.generate_north_silo(surface)
end
local Event = require 'utils.event'
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
Event.add(defines.events.on_player_built_tile, on_player_built_tile)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
Event.add(defines.events.on_robot_built_tile, on_robot_built_tile)
Event.add(defines.events.on_tick, on_tick)
Event.on_init(on_init)
Event.add_event_filter(defines.events.on_entity_damaged, { filter = "name", name = "rocket-silo" })
Event.add_event_filter(defines.events.on_entity_damaged, { filter = "type", type = "unit" })
require "maps.biter_battles_v2.spec_spy"
require "maps.biter_battles_v2.terrain"
require "maps.biter_battles_v2.difficulty_vote"
require "modules.custom_death_messages"
require "maps.biter_battles_v2.difficulty_vote"

View File

@ -1,5 +1,5 @@
-- Mirrored Terrain for Biter Battles -- by MewMew
local event = require 'utils.event'
-- Mirrored Terrain for Biter Battles -- by MewMew and Serennie
local Public = {}
local direction_translation = {
[0] = 4,
@ -186,7 +186,7 @@ local function add_work(work)
global.ctp.last = idx
end
local function ocg (event)
function Public.add_chunks(event)
if event.area.left_top.y < 0 then return end
if event.surface.name ~= "biter_battles" then return end
@ -203,7 +203,7 @@ local function ocg (event)
end
local function ticking_work()
function Public.ticking_work()
if not global.ctp then return end
local work = global.mws or 512 -- define the number of work per tick here (for copies, creations, deletions)
-- 136.5333 is the number of work needed to finish 4*(32*32) operations over 30 ticks (spreading a chunk copy over 30 ticks)
@ -296,23 +296,4 @@ local function ticking_work()
end
end
local function mirror_map()
--local limit = 32
for i, c in pairs(global.chunks_to_mirror) do
if i < game.tick then
for k, chunk in pairs(global.chunks_to_mirror[i]) do
mirror_chunk(game.surfaces["biter_battles"], chunk)
--global.chunks_to_mirror[i][k] = nil
--limit = limit - 1
--if limit == 0 then return end
end
global.chunks_to_mirror[i] = nil
end
end
end
event.add(defines.events.on_chunk_generated, ocg)
-- event.add(defines.events.on_chunk_generated, on_chunk_generated)
return ticking_work
-- return mirror_map
return Public

View File

@ -1,22 +1,3 @@
local function get_border_cords(f)
local a = {{-1000,-1000},{1000,-10}}
if f == "south" then a = {{-1000,10},{1000,1000}} end
local entities = game.surfaces["biter_battles"].find_entities_filtered{area=a,force=f}
if not entities then return end
local x_top = entities[1].position.x; local y_top = entities[1].position.y; local x_bot = entities[1].position.x; local y_bot = entities[1].position.y
for _, e in pairs(entities) do
if e.position.x < x_top then x_top = e.position.x end
if e.position.y < y_top then y_top = e.position.y end
if e.position.x > x_bot then x_bot = e.position.x end
if e.position.y > y_bot then y_bot = e.position.y end
end
global.force_area[f] = {}
global.force_area[f].x_top = x_top
global.force_area[f].y_top = y_top
global.force_area[f].x_bot = x_bot
global.force_area[f].y_bot = y_bot
end
local function spy_fish(player)
if not player.character then return end
local duration_per_unit = 2700
@ -34,8 +15,7 @@ local function spy_fish(player)
if global.spy_fish_timeout[player.force.name] - game.tick > 0 then
global.spy_fish_timeout[player.force.name] = global.spy_fish_timeout[player.force.name] + duration_per_unit
player.print(math.ceil((global.spy_fish_timeout[player.force.name] - game.tick) / 60) .. " seconds of enemy vision left.", { r=0.98, g=0.66, b=0.22})
else
--get_border_cords(enemy_team)
else
game.print(player.name .. " sent a fish to spy on " .. enemy_team .. " team!", {r=0.98, g=0.66, b=0.22})
global.spy_fish_timeout[player.force.name] = game.tick + duration_per_unit
end

View File

@ -1,6 +1,5 @@
local Public = {}
local bb_config = require "maps.biter_battles_v2.config"
local event = require 'utils.event'
local Server = require 'utils.server'
local math_random = math.random
local math_abs = math.abs
local simplex_noise = require 'utils.simplex_noise'.d2
@ -255,7 +254,7 @@ local function generate_circle_spawn(event)
regenerate_decoratives(surface, event.area.left_top)
end
local function generate_north_silo(surface)
function Public.generate_north_silo(surface)
local pos = {x = -32 + math.random(0, 64), y = -72}
local mirror_position = {x = pos.x * -1, y = pos.y * -1}
@ -504,7 +503,7 @@ local function replace_cliffs_with_rocks(surface, area)
end
end
]]
local function on_chunk_generated(event)
function Public.generate(event)
if event.area.left_top.y >= 0 then return end
local surface = event.surface
local left_top = event.area.left_top
@ -559,7 +558,7 @@ local function on_chunk_generated(event)
end
--Landfill Restriction
local function restrict_landfill(surface, inventory, tiles)
function Public.restrict_landfill(surface, inventory, tiles)
for _, t in pairs(tiles) do
local distance_to_center = math.sqrt(t.position.x ^ 2 + t.position.y ^ 2)
local check_position = t.position
@ -570,13 +569,6 @@ local function restrict_landfill(surface, inventory, tiles)
end
end
end
local function on_player_built_tile(event)
local player = game.players[event.player_index]
restrict_landfill(player.surface, player, event.tiles)
end
local function on_robot_built_tile(event)
restrict_landfill(event.robot.surface, event.robot.get_inventory(defines.inventory.robot_cargo), event.tiles)
end
--Construction Robot Restriction
local robot_build_restriction = {
@ -588,7 +580,7 @@ local robot_build_restriction = {
end
}
local function on_robot_built_entity(event)
function Public.deny_construction_bots(event)
if not robot_build_restriction[event.robot.force.name] then return end
if not robot_build_restriction[event.robot.force.name](event.created_entity.position.y) then return end
local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
@ -598,32 +590,4 @@ local function on_robot_built_entity(event)
event.created_entity.destroy()
end
local function on_marked_for_deconstruction(event)
if not event.entity.valid then return end
if event.entity.name == "fish" then event.entity.cancel_deconstruction(game.players[event.player_index].force.name) end
end
local function on_init(surface)
local surface = game.surfaces["biter_battles"]
if bb_config.on_init_pregen then
Server.to_discord_embed("Generating chunks...")
print("Generating chunks...")
surface.request_to_generate_chunks({x = 0, y = -512}, 16)
surface.request_to_generate_chunks({x = 1024, y = -512}, 16)
surface.request_to_generate_chunks({x = -1024, y = -512}, 16)
surface.force_generate_chunk_requests()
else
surface.request_to_generate_chunks({x = 0, y = -256}, 8)
surface.force_generate_chunk_requests()
end
generate_north_silo(surface)
end
event.on_init(on_init)
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
event.add(defines.events.on_robot_built_tile, on_robot_built_tile)
event.add(defines.events.on_player_built_tile, on_player_built_tile)
event.add(defines.events.on_chunk_generated, on_chunk_generated)
return Public