1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-26 03:52:22 +02:00

restructure

This commit is contained in:
MewMew 2020-01-02 16:09:24 +01:00
parent 66470c193c
commit 8e1868fdcc
12 changed files with 343 additions and 328 deletions

View File

@ -340,6 +340,7 @@ ai.wake_up_sleepy_groups = function()
local nearest_player_unit = entity.surface.find_nearest_enemy({position = entity.position, max_distance = 2048, force = biter_force_name})
if not nearest_player_unit then nearest_player_unit = global.rocket_silo[force_name] end
send_group(unit_group, force_name, nearest_player_unit)
print("BiterBattles: Woke up Unit Group at x" .. unit_group.position.x .. " y" .. unit_group.position.y .. ".")
end
end
end

View File

@ -1,5 +1,5 @@
-- biters will landfill tiles on death within a tiny radius
local Public = {}
local vectors = {{0,0}, {1,0}, {0,1}, {-1,0}, {0,-1}}
local math_random = math.random
local math_abs = math.abs
@ -24,12 +24,10 @@ local function create_particles(surface, position)
end
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then return end
function Public.entity_died(entity)
if not whitelist[entity.name] then return end
local position = entity.position
if math_abs(position.y) < 8 then return end
if math_abs(position.y) < 8 then return true end
local surface = entity.surface
for _, vector in pairs(vectors) do
local tile = surface.get_tile({position.x + vector[1], position.y + vector[2]})
@ -38,7 +36,7 @@ local function on_entity_died(event)
surface.set_tiles({{name = "landfill", position = tile.position}})
end
end
return true
end
local Event = require 'utils.event'
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

View File

@ -1,17 +1,11 @@
local event = require 'utils.event'
local Public = {}
----------share chat with player and spectator force-------------------
local function on_console_chat(event)
function Public.share(event)
if not event.message then return end
if not event.player_index then return end
local player = game.players[event.player_index]
local color = {}
color = player.color
color.r = color.r * 0.6 + 0.35
color.g = color.g * 0.6 + 0.35
color.b = color.b * 0.6 + 0.35
color.a = 1
local player = game.players[event.player_index]
local color = player.chat_color
if player.force.name == "north" then
game.forces.spectator.print(player.name .. " (north): ".. event.message, color)
@ -36,4 +30,4 @@ local function on_console_chat(event)
end
end
event.add(defines.events.on_console_chat, on_console_chat)
return Public

View File

@ -1,3 +1,5 @@
local Public = {}
local string_sub = string.sub
local balance_functions = {
@ -26,7 +28,7 @@ local balance_functions = {
end,
}
local function on_research_finished(event)
function Public.research_finished(event)
local research_name = event.research.name
local force_name = event.research.force.name
local key
@ -40,10 +42,4 @@ local function on_research_finished(event)
end
end
local function on_init()
global.combat_balance = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_research_finished, on_research_finished)
return Public

View File

@ -1,4 +1,4 @@
local event = require 'utils.event'
local Public = {}
local Server = require 'utils.server'
local gui_values = {
@ -14,7 +14,14 @@ local function shuffle(tbl)
end
return tbl
end
function Public.reveal_map()
for _, f in pairs({"north", "south", "player", "spectator"}) do
local r = 768
game.forces[f].chart(game.surfaces["biter_battles"], {{r * -1, r * -1}, {r, r}})
end
end
local function create_victory_gui(player)
local values = gui_values[global.bb_game_won_by_team]
local c = values.c1
@ -292,7 +299,7 @@ local enemy_team_of = {
["south"] = "north"
}
local function server_restart()
function Public.server_restart()
if not global.server_restart_timer then return end
global.server_restart_timer = global.server_restart_timer - 5
if global.server_restart_timer == 180 then return end
@ -309,6 +316,15 @@ local function server_restart()
end
end
function Public.restart_idle_map()
if game.tick < 432000 then return end
if #game.connected_players ~= 0 then global.restart_idle_map_countdown = 2 return end
if not global.restart_idle_map_countdown then global.restart_idle_map_countdown = 2 end
global.restart_idle_map_countdown = global.restart_idle_map_countdown - 1
if global.restart_idle_map_countdown ~= 0 then return end
Server.start_scenario('Biter_Battles')
end
local function set_victory_time()
local minutes = game.tick % 216000
local hours = game.tick - minutes
@ -320,7 +336,7 @@ local function set_victory_time()
global.victory_time = global.victory_time .. " minutes"
end
local function on_entity_died(event)
function Public.silo_death(event)
if not event.entity.valid then return end
if event.entity.name ~= "rocket-silo" then return end
if global.bb_game_won_by_team then return end
@ -351,10 +367,8 @@ local function on_entity_died(event)
Server.to_discord_embed(global.victory_time)
fireworks(event.entity.surface)
annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name)
annihilate_base_v2(event.entity.position, event.entity.surface, event.entity.force.name)
end
end
event.add(defines.events.on_entity_died, on_entity_died)
return server_restart
return Public

View File

@ -1,3 +1,5 @@
local Public = {}
local bb_config = require "maps.biter_battles_v2.config"
local event = require 'utils.event'
local spy_fish = require "maps.biter_battles_v2.spy_fish"
@ -234,7 +236,7 @@ local function create_main_gui(player)
end
end
local function refresh_gui()
function Public.refresh()
for _, player in pairs(game.connected_players) do
if player.gui.left["bb_main_gui"] then
create_main_gui(player)
@ -243,7 +245,7 @@ local function refresh_gui()
global.gui_refresh_delay = game.tick + 5
end
function refresh_gui_threat()
function refresh_threat()
if global.gui_refresh_delay > game.tick then return end
for _, player in pairs(game.connected_players) do
if player.gui.left["bb_main_gui"] then
@ -292,7 +294,7 @@ function join_team(player, force_name, forced_join)
player.teleport(p, surface)
player.force = game.forces[force_name]
player.character.destructible = true
refresh_gui()
Public.refresh()
game.permissions.get_group("Default").add_player(player)
game.print("Team " .. player.force.name .. " player " .. player.name .. " is no longer spectating.", {r = 0.98, g = 0.66, b = 0.22})
player.spectator = false
@ -318,7 +320,7 @@ function join_team(player, force_name, forced_join)
player.insert {name = 'iron-plate', count = 16}
global.chosen_team[player.name] = force_name
player.spectator = false
refresh_gui()
Public.refresh()
end
function spectate(player, forced_join)
@ -359,6 +361,21 @@ local function join_gui_click(name, player)
join_team(player, team[name])
end
local spy_forces = {{"north", "south"},{"south", "north"}}
function Public.spy_fish()
for _, f in pairs(spy_forces) do
if global.spy_fish_timeout[f[1]] - game.tick > 0 then
local r = 96
local surface = game.surfaces["biter_battles"]
for _, player in pairs(game.forces[f[2]].connected_players) do
game.forces[f[1]].chart(surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}})
end
else
global.spy_fish_timeout[f[1]] = 0
end
end
end
local function on_gui_click(event)
if not event.element then return end
if not event.element.valid then return end
@ -430,4 +447,4 @@ end
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
return refresh_gui
return Public

View File

@ -0,0 +1,169 @@
local Public = {}
function Public.settings()
global.gui_refresh_delay = 0
global.game_lobby_active = true
global.bb_debug = false
global.combat_balance = {}
global.bb_settings = {
--TEAM SETTINGS--
["team_balancing"] = true, --Should players only be able to join a team that has less or equal members than the opposing team?
["only_admins_vote"] = false, --Are only admins able to vote on the global difficulty?
--GENERAL SETTINGS--
["blueprint_library_importing"] = false, --Allow the importing of blueprints from the blueprint library?
["blueprint_string_importing"] = false, --Allow the importing of blueprints via blueprint strings?
}
end
function Public.surface()
local map_gen_settings = {}
map_gen_settings.water = math.random(15, 65) * 0.01
map_gen_settings.starting_area = 2.5
map_gen_settings.terrain_segmentation = math.random(30, 40) * 0.1
map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["stone"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["copper-ore"] = {frequency = 3.5, size = 0.65, richness = 0.5},
["iron-ore"] = {frequency = 3.5, size = 0.65, richness = 0.5},
["uranium-ore"] = {frequency = 2, size = 1, richness = 1},
["crude-oil"] = {frequency = 3, size = 1, richness = 0.75},
["trees"] = {frequency = math.random(8, 16) * 0.1, size = math.random(8, 16) * 0.1, richness = math.random(2, 10) * 0.1},
["enemy-base"] = {frequency = 256, size = 0.61, richness = 1}
}
game.create_surface("biter_battles", map_gen_settings)
game.map_settings.enemy_evolution.time_factor = 0
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.pollution.enabled = false
game.map_settings.enemy_expansion.enabled = false
end
function Public.forces()
local surface = game.surfaces["biter_battles"]
game.create_force("north")
game.create_force("north_biters")
game.create_force("south")
game.create_force("south_biters")
game.create_force("spectator")
local f = game.forces["north"]
f.set_spawn_position({0, -44}, surface)
f.set_cease_fire('player', true)
f.set_friend("spectator", true)
f.set_friend("south_biters", true)
f.share_chart = true
local f = game.forces["south"]
f.set_spawn_position({0, 44}, surface)
f.set_cease_fire('player', true)
f.set_friend("spectator", true)
f.set_friend("north_biters", true)
f.share_chart = true
local f = game.forces["north_biters"]
f.set_friend("south_biters", true)
f.set_friend("south", true)
f.set_friend("player", true)
f.set_friend("spectator", true)
f.share_chart = false
local f = game.forces["south_biters"]
f.set_friend("north_biters", true)
f.set_friend("north", true)
f.set_friend("player", true)
f.set_friend("spectator", true)
f.share_chart = false
local f = game.forces["spectator"]
f.set_spawn_position({0,0},surface)
f.technologies["toolbelt"].researched=true
f.set_cease_fire("north_biters", true)
f.set_cease_fire("south_biters", true)
f.set_friend("north", true)
f.set_friend("south", true)
f.set_cease_fire("player", true)
f.share_chart = true
local f = game.forces["player"]
f.set_spawn_position({0,0},surface)
f.set_cease_fire('spectator', true)
f.set_cease_fire("north_biters", true)
f.set_cease_fire("south_biters", true)
f.set_cease_fire('north', true)
f.set_cease_fire('south', true)
f.share_chart = false
if not global.bb_settings.blueprint_library_importing then
game.permissions.get_group("Default").set_allows_action(defines.input_action.grab_blueprint_record, false)
end
if not global.bb_settings.blueprint_string_importing then
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint_string, false)
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint, false)
end
local p = game.permissions.create_group("spectator")
for action_name, _ in pairs(defines.input_action) do
p.set_allows_action(defines.input_action[action_name], false)
end
local defs = {
defines.input_action.activate_copy,
defines.input_action.activate_cut,
defines.input_action.activate_paste,
defines.input_action.clean_cursor_stack,
defines.input_action.edit_permission_group,
defines.input_action.gui_click,
defines.input_action.gui_confirmed,
defines.input_action.gui_elem_changed,
defines.input_action.gui_location_changed,
defines.input_action.gui_selected_tab_changed,
defines.input_action.gui_selection_state_changed,
defines.input_action.gui_switch_state_changed,
defines.input_action.gui_text_changed,
defines.input_action.gui_value_changed,
defines.input_action.open_character_gui,
defines.input_action.open_kills_gui,
defines.input_action.rotate_entity,
defines.input_action.start_walking,
defines.input_action.toggle_show_entity_info,
defines.input_action.write_to_console,
}
for _, d in pairs(defs) do p.set_allows_action(d, true) end
global.rocket_silo = {}
global.spectator_rejoin_delay = {}
global.spy_fish_timeout = {}
global.force_area = {}
global.active_biters = {}
global.biter_raffle = {}
global.evo_raise_counter = 1
global.next_attack = "north"
if math.random(1,2) == 1 then global.next_attack = "south" end
global.bb_evolution = {}
global.bb_threat_income = {}
global.bb_threat = {}
global.chunks_to_mirror = {}
global.map_pregen_message_counter = {}
for _, force in pairs(game.forces) do
game.forces[force.name].technologies["artillery"].enabled = false
game.forces[force.name].technologies["artillery-shell-range-1"].enabled = false
game.forces[force.name].technologies["artillery-shell-speed-1"].enabled = false
game.forces[force.name].technologies["atomic-bomb"].enabled = false
game.forces[force.name].research_queue_enabled = true
global.spy_fish_timeout[force.name] = 0
global.active_biters[force.name] = {}
global.biter_raffle[force.name] = {}
global.bb_evolution[force.name] = 0
global.bb_threat_income[force.name] = 0
global.bb_threat[force.name] = 0
end
end
return Public

View File

@ -1,181 +1,26 @@
-- Biter Battles v2 -- by MewMew
local bb_config = require "maps.biter_battles_v2.config"
local Ai = require "maps.biter_battles_v2.ai"
local BiterHealthBooster = require "modules.biter_health_booster"
local Biters_landfill = require "maps.biter_battles_v2.biters_landfill"
local Chat = require "maps.biter_battles_v2.chat"
local Combat_balance = require "maps.biter_battles_v2.combat_balance"
local Game_over = require "maps.biter_battles_v2.game_over"
local Gui = require "maps.biter_battles_v2.gui"
local Init = require "maps.biter_battles_v2.init"
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"
require "on_tick_schedule"
require "maps.biter_battles_v2.map_settings_tab"
require "modules.spawners_contain_biters"
require "modules.mineable_wreckage_yields_scrap"
local event = require 'utils.event'
local function init_settings()
global.bb_settings = {
--TEAM SETTINGS--
["team_balancing"] = true, --Should players only be able to join a team that has less or equal members than the opposing team?
["only_admins_vote"] = false, --Are only admins able to vote on the global difficulty?
--GENERAL SETTINGS--
["blueprint_library_importing"] = false, --Allow the importing of blueprints from the blueprint library?
["blueprint_string_importing"] = false, --Allow the importing of blueprints via blueprint strings?
}
end
local function init_surface()
local map_gen_settings = {}
map_gen_settings.water = math.random(15, 65) * 0.01
map_gen_settings.starting_area = 2.5
map_gen_settings.terrain_segmentation = math.random(30, 40) * 0.1
map_gen_settings.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
map_gen_settings.autoplace_controls = {
["coal"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["stone"] = {frequency = 2.5, size = 0.65, richness = 0.5},
["copper-ore"] = {frequency = 3.5, size = 0.65, richness = 0.5},
["iron-ore"] = {frequency = 3.5, size = 0.65, richness = 0.5},
["uranium-ore"] = {frequency = 2, size = 1, richness = 1},
["crude-oil"] = {frequency = 3, size = 1, richness = 0.75},
["trees"] = {frequency = math.random(8, 16) * 0.1, size = math.random(8, 16) * 0.1, richness = math.random(2, 10) * 0.1},
["enemy-base"] = {frequency = 256, size = 0.61, richness = 1}
}
game.create_surface("biter_battles", map_gen_settings)
game.map_settings.enemy_evolution.time_factor = 0
game.map_settings.enemy_evolution.destroy_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.pollution.enabled = false
game.map_settings.enemy_expansion.enabled = false
end
local function init_forces()
local surface = game.surfaces["biter_battles"]
game.create_force("north")
game.create_force("north_biters")
game.create_force("south")
game.create_force("south_biters")
game.create_force("spectator")
local f = game.forces["north"]
f.set_spawn_position({0, -44}, surface)
f.set_cease_fire('player', true)
f.set_friend("spectator", true)
f.set_friend("south_biters", true)
f.share_chart = true
local f = game.forces["south"]
f.set_spawn_position({0, 44}, surface)
f.set_cease_fire('player', true)
f.set_friend("spectator", true)
f.set_friend("north_biters", true)
f.share_chart = true
local f = game.forces["north_biters"]
f.set_friend("south_biters", true)
f.set_friend("south", true)
f.set_friend("player", true)
f.set_friend("spectator", true)
f.share_chart = false
local f = game.forces["south_biters"]
f.set_friend("north_biters", true)
f.set_friend("north", true)
f.set_friend("player", true)
f.set_friend("spectator", true)
f.share_chart = false
local f = game.forces["spectator"]
f.set_spawn_position({0,0},surface)
f.technologies["toolbelt"].researched=true
f.set_cease_fire("north_biters", true)
f.set_cease_fire("south_biters", true)
f.set_friend("north", true)
f.set_friend("south", true)
f.set_cease_fire("player", true)
f.share_chart = true
local f = game.forces["player"]
f.set_spawn_position({0,0},surface)
f.set_cease_fire('spectator', true)
f.set_cease_fire("north_biters", true)
f.set_cease_fire("south_biters", true)
f.set_cease_fire('north', true)
f.set_cease_fire('south', true)
f.share_chart = false
if not global.bb_settings.blueprint_library_importing then
game.permissions.get_group("Default").set_allows_action(defines.input_action.grab_blueprint_record, false)
end
if not global.bb_settings.blueprint_string_importing then
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint_string, false)
game.permissions.get_group("Default").set_allows_action(defines.input_action.import_blueprint, false)
end
local p = game.permissions.create_group("spectator")
for action_name, _ in pairs(defines.input_action) do
p.set_allows_action(defines.input_action[action_name], false)
end
local defs = {
defines.input_action.activate_copy,
defines.input_action.activate_cut,
defines.input_action.activate_paste,
defines.input_action.clean_cursor_stack,
defines.input_action.edit_permission_group,
defines.input_action.gui_click,
defines.input_action.gui_confirmed,
defines.input_action.gui_elem_changed,
defines.input_action.gui_location_changed,
defines.input_action.gui_selected_tab_changed,
defines.input_action.gui_selection_state_changed,
defines.input_action.gui_switch_state_changed,
defines.input_action.gui_text_changed,
defines.input_action.gui_value_changed,
defines.input_action.open_character_gui,
defines.input_action.open_kills_gui,
defines.input_action.rotate_entity,
defines.input_action.start_walking,
defines.input_action.toggle_show_entity_info,
defines.input_action.write_to_console,
}
for _, d in pairs(defs) do p.set_allows_action(d, true) end
global.rocket_silo = {}
global.spectator_rejoin_delay = {}
global.spy_fish_timeout = {}
global.force_area = {}
global.active_biters = {}
global.biter_raffle = {}
global.evo_raise_counter = 1
global.next_attack = "north"
if math.random(1,2) == 1 then global.next_attack = "south" end
global.bb_evolution = {}
global.bb_threat_income = {}
global.bb_threat = {}
global.chunks_to_mirror = {}
global.map_pregen_message_counter = {}
for _, force in pairs(game.forces) do
game.forces[force.name].technologies["artillery"].enabled = false
game.forces[force.name].technologies["artillery-shell-range-1"].enabled = false
game.forces[force.name].technologies["artillery-shell-speed-1"].enabled = false
game.forces[force.name].technologies["atomic-bomb"].enabled = false
game.forces[force.name].research_queue_enabled = true
global.spy_fish_timeout[force.name] = 0
global.active_biters[force.name] = {}
global.biter_raffle[force.name] = {}
global.bb_evolution[force.name] = 0
global.bb_threat_income[force.name] = 0
global.bb_threat[force.name] = 0
end
global.game_lobby_active = true
end
local function on_player_joined_game(event)
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
local player = game.players[event.player_index]
if player.online_time == 0 then
player.spectator = true
@ -188,27 +33,96 @@ local function on_player_joined_game(event)
player.character.destructible = false
game.permissions.get_group("spectator").add_player(player)
end
Map_info.player_joined_game(player)
Team_manager.draw_top_toggle_button(player)
end
local function on_gui_click(event)
local player = game.players[event.player_index]
local element = event.element
if not element then return end
if not element.valid then return end
if Map_info.gui_click(player, element) then return end
Team_manager.gui_click(event)
end
local function on_research_finished(event)
Combat_balance.research_finished(event)
end
local function on_console_chat(event)
Chat.share(event)
end
local function on_built_entity(event)
No_turret_creep.deny_building(event)
end
local function on_robot_built_entity(event)
No_turret_creep.deny_building(event)
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then return end
if Biters_landfill.entity_died(entity) then return end
Game_over.silo_death(event)
end
local tick_minute_functions = {
[300 * 1] = Ai.raise_evo,
[300 * 2] = Ai.destroy_inactive_biters,
[300 * 3] = Ai.main_attack,
[300 * 4] = Ai.send_near_biters_to_silo,
[300 * 5] = Ai.destroy_old_age_biters,
[300 * 6] = Ai.wake_up_sleepy_groups,
[300 * 7] = Game_over.restart_idle_map,
}
local function on_tick(event)
Mirror_terrain()
local tick = game.tick
if 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"]
if tick % 180 == 0 then Gui.refresh() end
if tick % 300 ~= 0 then return end
Gui.spy_fish()
if global.bb_game_won_by_team then
Game_over.reveal_map()
Game_over.server_restart()
return
end
local key = tick % 3600
if tick_minute_functions[key] then tick_minute_functions[key]() end
end
local function on_init()
init_settings()
init_surface()
init_forces()
global.gui_refresh_delay = 0
global.bb_debug = false
Init.settings()
Init.surface()
Init.forces()
Team_manager.init()
end
event.on_init(on_init)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_tick, on_tick)
require "maps.biter_battles_v2.spec_spy"
require "maps.biter_battles_v2.on_tick"
require "maps.biter_battles_v2.terrain"
require "maps.biter_battles_v2.biters_landfill"
require "maps.biter_battles_v2.no_turret_creep"
require "maps.biter_battles_v2.chat"
require "maps.biter_battles_v2.combat_balance"
require "maps.biter_battles_v2.bb_map_intro"
require "maps.biter_battles_v2.difficulty_vote"
require "maps.biter_battles_v2.team_manager"
require "modules.custom_death_messages"

View File

@ -1,4 +1,4 @@
local event = require 'utils.event'
local Public = {}
local function create_map_intro_button(player)
if player.gui.top["map_intro_button"] then return end
@ -23,30 +23,25 @@ local function create_map_intro(player)
l.style.font_color = {r=0.7, g=0.6, b=0.99}
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
function Public.player_joined_game(player)
create_map_intro_button(player)
if player.online_time == 0 then
--create_map_intro(player)
end
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
if event.element.name == "close_map_intro_frame" then player.gui.center["map_intro_frame"].destroy() return end
if event.element.name == "biter_battles_map_intro" then player.gui.center["map_intro_frame"].destroy() return end
if event.element.name == "map_intro_button" then
function Public.gui_click(player, element)
if element.name == "close_map_intro_frame" then player.gui.center["map_intro_frame"].destroy() return true end
if element.name == "biter_battles_map_intro" then player.gui.center["map_intro_frame"].destroy() return true end
if element.name == "map_intro_button" then
if player.gui.center["map_intro_frame"] then
player.gui.center["map_intro_frame"].destroy()
return true
else
create_map_intro(player)
end
return
return true
end
end
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_gui_click, on_gui_click)
return Public

View File

@ -1,4 +1,4 @@
local event = require 'utils.event'
local Public = {}
local type_blacklist = {
["ammo-turret"] = true,
@ -7,7 +7,7 @@ local type_blacklist = {
["fluid-turret"] = true
}
local function on_built_entity(event)
function Public.deny_building(event)
local entity = event.created_entity
if not entity.valid then return end
if not type_blacklist[event.created_entity.type] then return end
@ -43,9 +43,4 @@ local function on_built_entity(event)
entity.destroy()
end
local function on_robot_built_entity(event)
on_built_entity(event)
end
event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
event.add(defines.events.on_built_entity, on_built_entity)
return Public

View File

@ -1,73 +0,0 @@
local event = require 'utils.event'
local Server = require 'utils.server'
local gui = require "maps.biter_battles_v2.gui"
local ai = require "maps.biter_battles_v2.ai"
local mirror_tick_routine = require "maps.biter_battles_v2.mirror_terrain"
local server_restart = require "maps.biter_battles_v2.game_won"
local spy_forces = {{"north", "south"},{"south", "north"}}
local function spy_fish()
for _, f in pairs(spy_forces) do
if global.spy_fish_timeout[f[1]] - game.tick > 0 then
local r = 96
local surface = game.surfaces["biter_battles"]
for _, player in pairs(game.forces[f[2]].connected_players) do
game.forces[f[1]].chart(surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}})
end
else
global.spy_fish_timeout[f[1]] = 0
end
end
end
local function reveal_map()
for _, f in pairs({"north", "south", "player", "spectator"}) do
local r = 768
game.forces[f].chart(game.surfaces["biter_battles"], {{r * -1, r * -1}, {r, r}})
end
end
local function restart_idle_map()
if game.tick < 432000 then return end
if #game.connected_players ~= 0 then global.restart_idle_map_countdown = 2 return end
if not global.restart_idle_map_countdown then global.restart_idle_map_countdown = 2 end
global.restart_idle_map_countdown = global.restart_idle_map_countdown - 1
if global.restart_idle_map_countdown ~= 0 then return end
Server.start_scenario('Biter_Battles')
end
local tick_minute_functions = {
[300 * 1] = ai.raise_evo,
[300 * 2] = ai.destroy_inactive_biters,
[300 * 3] = ai.main_attack,
[300 * 4] = ai.send_near_biters_to_silo,
[300 * 5] = ai.destroy_old_age_biters,
[300 * 6] = ai.wake_up_sleepy_groups,
[300 * 7] = restart_idle_map,
}
local function on_tick(event)
mirror_tick_routine()
local tick = game.tick
if 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"]
if tick % 180 == 0 then gui() end
if tick % 300 ~= 0 then return end
spy_fish()
if global.bb_game_won_by_team then
reveal_map()
server_restart()
return
end
local key = tick % 3600
if tick_minute_functions[key] then tick_minute_functions[key]() end
end
event.add(defines.events.on_tick, on_tick)

View File

@ -1,3 +1,5 @@
local Public = {}
local forces = {
{name = "north", color = {r = 0, g = 0, b = 200}},
{name = "spectator", color = {r = 111, g = 111, b = 111}},
@ -90,7 +92,7 @@ local function switch_force(player_name, force_name)
end
end
local function draw_manager_button(player)
function Public.draw_top_toggle_button(player)
if player.gui.top["team_manager_toggle_button"] then player.gui.top["team_manager_toggle_button"].destroy() end
local button = player.gui.top.add({type = "sprite-button", name = "team_manager_toggle_button", caption = "Team Manager", tooltip = tooltip})
button.style.font = "heading-2"
@ -329,7 +331,7 @@ local function team_manager_gui_click(event)
draw_manager_gui(player)
end
local function on_gui_click(event)
function Public.gui_click(event)
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.player_index]
@ -360,15 +362,8 @@ local function on_gui_click(event)
end
end
local function on_player_joined_game(event)
draw_manager_button(game.players[event.player_index])
end
local function on_init(surface)
function Public.init()
global.tm_custom_name = {}
end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_gui_click, on_gui_click)
return Public