2019-03-13 18:09:06 +02:00
|
|
|
-- Biter Battles v2 -- by MewMew
|
|
|
|
|
2020-01-29 06:55:30 +02:00
|
|
|
require "on_tick_schedule"
|
2020-04-13 06:31:39 +02:00
|
|
|
local Biter_health_booster = require "modules.biter_health_booster"
|
2020-01-02 17:09:24 +02:00
|
|
|
local Ai = require "maps.biter_battles_v2.ai"
|
|
|
|
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"
|
2020-01-22 09:30:41 +02:00
|
|
|
local Terrain = require "maps.biter_battles_v2.terrain"
|
2020-01-02 17:09:24 +02:00
|
|
|
|
2019-11-29 06:56:24 +02:00
|
|
|
require "maps.biter_battles_v2.map_settings_tab"
|
2019-12-31 13:20:37 +02:00
|
|
|
require "maps.biter_battles_v2.sciencelogs_tab"
|
2019-11-05 18:21:04 +02:00
|
|
|
require "modules.spawners_contain_biters"
|
2019-07-13 19:12:18 +02:00
|
|
|
require "modules.mineable_wreckage_yields_scrap"
|
2020-01-22 09:30:41 +02:00
|
|
|
require "modules.custom_death_messages"
|
2019-03-16 21:25:21 +02:00
|
|
|
|
2019-11-05 18:21:04 +02:00
|
|
|
local function on_player_joined_game(event)
|
2019-03-17 03:35:58 +02:00
|
|
|
local surface = game.surfaces["biter_battles"]
|
2020-01-04 23:34:32 +02:00
|
|
|
local player = game.players[event.player_index]
|
2019-11-05 18:21:04 +02:00
|
|
|
|
2019-03-14 05:25:54 +02:00
|
|
|
if player.online_time == 0 then
|
2019-10-01 03:16:56 +02:00
|
|
|
player.spectator = true
|
2019-09-01 02:42:14 +02:00
|
|
|
player.force = game.forces.spectator
|
2019-03-14 05:25:54 +02:00
|
|
|
if surface.is_chunk_generated({0,0}) then
|
2019-05-02 21:17:22 +02:00
|
|
|
player.teleport(surface.find_non_colliding_position("character", {0,0}, 3, 0.5), surface)
|
2019-03-14 05:25:54 +02:00
|
|
|
else
|
2019-03-14 23:50:09 +02:00
|
|
|
player.teleport({0,0}, surface)
|
2019-03-14 05:25:54 +02:00
|
|
|
end
|
|
|
|
player.character.destructible = false
|
2019-03-20 05:50:12 +02:00
|
|
|
game.permissions.get_group("spectator").add_player(player)
|
2019-11-05 18:21:04 +02:00
|
|
|
end
|
2020-01-04 23:34:32 +02:00
|
|
|
|
2020-01-02 17:09:24 +02:00
|
|
|
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
|
2020-01-04 23:34:32 +02:00
|
|
|
|
2020-01-02 17:09:24 +02:00
|
|
|
if Map_info.gui_click(player, element) then return end
|
2020-01-04 23:34:32 +02:00
|
|
|
Team_manager.gui_click(event)
|
2020-01-02 17:09:24 +02:00
|
|
|
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)
|
2020-01-22 09:30:41 +02:00
|
|
|
Terrain.deny_construction_bots(event)
|
2020-01-02 17:09:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_entity_died(event)
|
|
|
|
local entity = event.entity
|
2020-01-02 17:28:12 +02:00
|
|
|
if not entity.valid then return end
|
|
|
|
if Ai.subtract_threat(entity) then Gui.refresh_threat() end
|
2020-01-02 17:09:24 +02:00
|
|
|
if Biters_landfill.entity_died(entity) then return end
|
|
|
|
Game_over.silo_death(event)
|
|
|
|
end
|
|
|
|
|
2020-01-02 17:28:12 +02:00
|
|
|
--Prevent Players from damaging Rocket Silos
|
|
|
|
local function on_entity_damaged(event)
|
2020-01-04 23:34:32 +02:00
|
|
|
local entity = event.entity
|
2020-01-04 03:40:16 +02:00
|
|
|
if not entity.valid then return end
|
|
|
|
if entity.force.index > 5 then return end
|
2020-01-04 23:34:32 +02:00
|
|
|
|
2020-01-02 17:28:12 +02:00
|
|
|
local cause = event.cause
|
|
|
|
if cause then
|
2020-01-04 23:34:32 +02:00
|
|
|
if cause.type == "unit" then return end
|
2020-01-02 17:28:12 +02:00
|
|
|
end
|
2020-01-04 23:34:32 +02:00
|
|
|
|
|
|
|
if entity.name ~= "rocket-silo" then return end
|
2020-01-02 17:28:12 +02:00
|
|
|
entity.health = entity.health + event.final_damage_amount
|
|
|
|
end
|
|
|
|
|
2020-01-02 17:09:24 +02:00
|
|
|
local tick_minute_functions = {
|
|
|
|
[300 * 1] = Ai.raise_evo,
|
|
|
|
[300 * 2] = Ai.destroy_inactive_biters,
|
2020-01-07 05:35:18 +02:00
|
|
|
[300 * 3 + 30 * 0] = Ai.pre_main_attack, -- setup for main_attack
|
|
|
|
[300 * 3 + 30 * 1] = Ai.perform_main_attack, -- call perform_main_attack 7 times on different ticks
|
|
|
|
[300 * 3 + 30 * 2] = Ai.perform_main_attack, -- some of these might do nothing (if there are no wave left)
|
|
|
|
[300 * 3 + 30 * 3] = Ai.perform_main_attack,
|
|
|
|
[300 * 3 + 30 * 4] = Ai.perform_main_attack,
|
|
|
|
[300 * 3 + 30 * 5] = Ai.perform_main_attack,
|
|
|
|
[300 * 3 + 30 * 6] = Ai.perform_main_attack,
|
|
|
|
[300 * 3 + 30 * 7] = Ai.perform_main_attack,
|
|
|
|
[300 * 3 + 30 * 8] = Ai.post_main_attack,
|
|
|
|
[300 * 4] = Ai.send_near_biters_to_silo,
|
|
|
|
[300 * 5] = Ai.wake_up_sleepy_groups,
|
2020-01-02 17:09:24 +02:00
|
|
|
[300 * 7] = Game_over.restart_idle_map,
|
|
|
|
}
|
|
|
|
|
2020-02-03 09:35:20 +02:00
|
|
|
local function on_tick()
|
2020-01-22 09:30:41 +02:00
|
|
|
Mirror_terrain.ticking_work()
|
2020-01-07 20:51:16 +02:00
|
|
|
|
|
|
|
local tick = game.tick
|
2020-01-04 23:34:32 +02:00
|
|
|
|
2020-01-07 05:35:18 +02:00
|
|
|
if tick % 60 == 0 then
|
|
|
|
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"]
|
|
|
|
end
|
2020-01-02 17:09:24 +02:00
|
|
|
|
|
|
|
if tick % 180 == 0 then Gui.refresh() end
|
|
|
|
|
2020-01-07 05:35:18 +02:00
|
|
|
if tick % 300 == 0 then
|
|
|
|
Gui.spy_fish()
|
|
|
|
|
|
|
|
if global.bb_game_won_by_team then
|
|
|
|
Game_over.reveal_map()
|
|
|
|
Game_over.server_restart()
|
|
|
|
return
|
|
|
|
end
|
2020-01-02 17:09:24 +02:00
|
|
|
end
|
2020-01-04 23:34:32 +02:00
|
|
|
|
2020-01-07 20:51:16 +02:00
|
|
|
if tick % 30 == 0 then
|
|
|
|
local key = tick % 3600
|
|
|
|
if tick_minute_functions[key] then tick_minute_functions[key]() end
|
|
|
|
end
|
2019-03-13 18:09:06 +02:00
|
|
|
end
|
|
|
|
|
2020-01-22 09:30:41 +02:00
|
|
|
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
|
|
|
|
|
2019-11-29 06:56:24 +02:00
|
|
|
local function on_init()
|
2020-01-02 17:09:24 +02:00
|
|
|
Init.settings()
|
|
|
|
Init.surface()
|
|
|
|
Init.forces()
|
|
|
|
Team_manager.init()
|
2020-01-22 09:30:41 +02:00
|
|
|
|
|
|
|
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)
|
2019-03-17 19:19:40 +02:00
|
|
|
end
|
|
|
|
|
2020-01-02 17:09:24 +02:00
|
|
|
local Event = require 'utils.event'
|
2020-01-02 17:28:12 +02:00
|
|
|
Event.add(defines.events.on_built_entity, on_built_entity)
|
2020-01-22 15:12:04 +02:00
|
|
|
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
2020-01-02 17:09:24 +02:00
|
|
|
Event.add(defines.events.on_console_chat, on_console_chat)
|
2020-01-02 17:28:12 +02:00
|
|
|
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
2020-01-02 17:09:24 +02:00
|
|
|
Event.add(defines.events.on_entity_died, on_entity_died)
|
2020-01-02 17:28:12 +02:00
|
|
|
Event.add(defines.events.on_gui_click, on_gui_click)
|
2020-01-22 15:12:04 +02:00
|
|
|
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
|
|
|
|
Event.add(defines.events.on_player_built_tile, on_player_built_tile)
|
2020-01-02 17:28:12 +02:00
|
|
|
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
|
|
|
Event.add(defines.events.on_research_finished, on_research_finished)
|
2020-01-02 17:09:24 +02:00
|
|
|
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
2020-01-22 09:30:41 +02:00
|
|
|
Event.add(defines.events.on_robot_built_tile, on_robot_built_tile)
|
2020-01-22 15:12:04 +02:00
|
|
|
Event.add(defines.events.on_tick, on_tick)
|
2020-01-02 17:28:12 +02:00
|
|
|
Event.on_init(on_init)
|
|
|
|
|
2020-04-13 06:31:39 +02:00
|
|
|
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"})
|
|
|
|
Event.add_event_filter(defines.events.on_entity_damaged, {filter = "type", type = "unit-spawner"})
|
|
|
|
Event.add_event_filter(defines.events.on_entity_damaged, {filter = "type", type = "turret"})
|
2020-01-04 23:34:32 +02:00
|
|
|
|
2019-11-05 18:21:04 +02:00
|
|
|
require "maps.biter_battles_v2.spec_spy"
|
2020-01-07 05:35:18 +02:00
|
|
|
require "maps.biter_battles_v2.difficulty_vote"
|