2016-12-01 04:41:04 +02:00
|
|
|
-- control.lua
|
2019-03-02 04:07:24 +02:00
|
|
|
-- Mar 2019
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-11-10 12:22:32 +02:00
|
|
|
-- Oarc's Separated Spawn Scenario
|
|
|
|
--
|
2016-12-01 04:41:04 +02:00
|
|
|
-- I wanted to create a scenario that allows you to spawn in separate locations
|
|
|
|
-- From there, I ended up adding a bunch of other minor/major features
|
2016-11-10 12:22:32 +02:00
|
|
|
--
|
2016-12-01 04:41:04 +02:00
|
|
|
-- Credit:
|
2016-12-21 03:42:10 +02:00
|
|
|
-- Tags - Taken from WOGs scenario
|
2016-12-01 04:41:04 +02:00
|
|
|
-- Rocket Silo - Taken from Frontier as an idea
|
|
|
|
--
|
|
|
|
-- Feel free to re-use anything you want. It would be nice to give me credit
|
|
|
|
-- if you can.
|
2017-07-26 00:12:55 +02:00
|
|
|
|
2016-11-10 12:22:32 +02:00
|
|
|
|
2016-11-16 14:43:03 +02:00
|
|
|
|
2019-03-02 04:07:24 +02:00
|
|
|
-- To keep the scenario more manageable (for myself) I have done the following:
|
2016-12-01 04:41:04 +02:00
|
|
|
-- 1. Keep all event calls in control.lua (here)
|
2019-04-10 19:59:57 +02:00
|
|
|
-- 2. Put all config options in config.lua and provided an example-config.lua file too.
|
2019-03-03 03:51:17 +02:00
|
|
|
-- 3. Put other stuff into their own files where possible.
|
2019-04-10 19:59:57 +02:00
|
|
|
-- 4. Put all other files into lib folder
|
|
|
|
-- 5. Provided an examples folder for example/recommended map gen settings
|
2016-11-16 14:43:03 +02:00
|
|
|
|
2016-11-10 12:22:32 +02:00
|
|
|
|
2016-12-28 18:33:09 +02:00
|
|
|
-- Generic Utility Includes
|
2019-03-02 04:07:24 +02:00
|
|
|
require("lib/oarc_utils")
|
2019-03-03 03:51:17 +02:00
|
|
|
|
|
|
|
-- Other soft-mod type features.
|
2019-03-02 06:05:23 +02:00
|
|
|
require("lib/frontier_silo")
|
|
|
|
require("lib/tag")
|
2019-03-02 04:07:24 +02:00
|
|
|
require("lib/game_opts")
|
2019-03-03 03:51:17 +02:00
|
|
|
require("lib/regrowth_map")
|
|
|
|
require("lib/player_list")
|
2019-04-28 20:13:46 +02:00
|
|
|
require("lib/rocket_launch")
|
2019-05-12 15:59:54 +02:00
|
|
|
require("lib/admin_commands")
|
2018-02-01 06:31:33 +02:00
|
|
|
|
|
|
|
-- For Philip. I currently do not use this and need to add proper support for
|
|
|
|
-- commands like this in the future.
|
2019-03-03 03:51:17 +02:00
|
|
|
-- require("lib/rgcommand")
|
|
|
|
-- require("lib/helper_commands")
|
2016-12-28 18:33:09 +02:00
|
|
|
|
|
|
|
-- Main Configuration File
|
2016-12-01 04:41:04 +02:00
|
|
|
require("config")
|
|
|
|
|
2019-04-10 19:59:57 +02:00
|
|
|
-- Save all config settings to global table.
|
|
|
|
require("lib/oarc_global_cfg.lua")
|
|
|
|
|
2016-12-28 18:33:09 +02:00
|
|
|
-- Scenario Specific Includes
|
2019-03-02 04:07:24 +02:00
|
|
|
require("lib/separate_spawns")
|
|
|
|
require("lib/separate_spawns_guis")
|
2019-03-03 03:51:17 +02:00
|
|
|
|
2019-03-19 22:46:31 +02:00
|
|
|
-- Create a new surface so we can modify map settings at the start.
|
|
|
|
GAME_SURFACE_NAME="oarc"
|
2016-11-10 12:22:32 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- ALL EVENT HANLDERS ARE HERE IN ONE PLACE!
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- On Init - only runs once the first
|
|
|
|
-- time the game starts
|
|
|
|
----------------------------------------
|
|
|
|
script.on_init(function(event)
|
2017-11-29 21:39:09 +02:00
|
|
|
|
2019-04-10 19:59:57 +02:00
|
|
|
-- FIRST
|
|
|
|
InitOarcConfig()
|
|
|
|
|
2019-03-19 22:46:31 +02:00
|
|
|
-- Create new game surface
|
|
|
|
CreateGameSurface()
|
2019-03-11 15:29:00 +02:00
|
|
|
|
2019-03-19 22:46:31 +02:00
|
|
|
-- MUST be before other stuff, but after surface creation.
|
2019-04-11 03:03:02 +02:00
|
|
|
InitSpawnGlobalsAndForces()
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2019-04-28 20:41:37 +02:00
|
|
|
-- Regardless of whether it's enabled or not, it's good to have this init.
|
|
|
|
OarcRegrowthInit()
|
|
|
|
|
2019-04-28 20:58:59 +02:00
|
|
|
-- Frontier Silo Area Generation
|
|
|
|
if (global.ocfg.frontier_rocket_silo) then
|
|
|
|
SpawnSilosAndGenerateSiloAreas()
|
2019-03-02 06:05:23 +02:00
|
|
|
end
|
2019-05-14 07:09:01 +02:00
|
|
|
|
|
|
|
-- Everyone do the shuffle. Helps avoid always starting at the same location.
|
|
|
|
global.vanillaSpawns = FYShuffle(global.vanillaSpawns)
|
|
|
|
log("Vanilla spawns:")
|
|
|
|
log(serpent.block(global.vanillaSpawns))
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
2019-04-28 20:13:46 +02:00
|
|
|
-- Rocket launch event
|
|
|
|
-- Used for end game win conditions / unlocking late game stuff
|
2016-12-01 04:41:04 +02:00
|
|
|
----------------------------------------
|
2019-03-02 06:05:23 +02:00
|
|
|
script.on_event(defines.events.on_rocket_launched, function(event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.frontier_rocket_silo then
|
2019-03-02 06:05:23 +02:00
|
|
|
RocketLaunchEvent(event)
|
|
|
|
end
|
|
|
|
end)
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
|
2019-03-15 22:15:01 +02:00
|
|
|
local first_chunk_generated_flag = false
|
2016-12-01 04:41:04 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- Chunk Generation
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_chunk_generated, function(event)
|
2019-03-15 22:15:01 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_regrowth then
|
2019-03-03 03:51:17 +02:00
|
|
|
OarcRegrowthChunkGenerate(event.area.left_top)
|
|
|
|
end
|
2017-07-29 00:02:45 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_undecorator then
|
2019-03-02 06:05:23 +02:00
|
|
|
UndecorateOnChunkGenerate(event)
|
|
|
|
end
|
2017-12-16 15:46:06 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.frontier_rocket_silo then
|
2019-03-02 06:05:23 +02:00
|
|
|
GenerateRocketSiloChunk(event)
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2019-04-11 03:03:02 +02:00
|
|
|
SeparateSpawnsGenerateChunk(event)
|
2017-05-13 04:33:57 +02:00
|
|
|
|
2019-04-11 03:33:13 +02:00
|
|
|
CreateHoldingPen(event.surface, event.area, 16, 32)
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- Gui Click
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_gui_click, function(event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_tags then
|
2019-03-02 06:05:23 +02:00
|
|
|
TagGuiClick(event)
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_player_list then
|
2019-03-02 06:05:23 +02:00
|
|
|
PlayerListGuiClick(event)
|
|
|
|
end
|
2017-04-28 22:40:59 +02:00
|
|
|
|
2019-04-11 03:03:02 +02:00
|
|
|
WelcomeTextGuiClick(event)
|
|
|
|
SpawnOptsGuiClick(event)
|
|
|
|
SpawnCtrlGuiClick(event)
|
|
|
|
SharedSpwnOptsGuiClick(event)
|
|
|
|
BuddySpawnOptsGuiClick(event)
|
|
|
|
BuddySpawnWaitMenuClick(event)
|
|
|
|
BuddySpawnRequestMenuClick(event)
|
|
|
|
SharedSpawnJoinWaitMenuClick(event)
|
2016-12-19 23:35:36 +02:00
|
|
|
|
2019-03-02 04:07:24 +02:00
|
|
|
GameOptionsGuiClick(event)
|
2019-04-28 20:13:46 +02:00
|
|
|
RocketGuiClick(event)
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
2017-12-15 21:45:01 +02:00
|
|
|
script.on_event(defines.events.on_gui_checked_state_changed, function (event)
|
2019-04-11 03:03:02 +02:00
|
|
|
SpawnOptsRadioSelect(event)
|
|
|
|
SpawnCtrlGuiOptionsSelect(event)
|
2017-12-15 21:45:01 +02:00
|
|
|
end)
|
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- Player Events
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_player_joined_game, function(event)
|
2017-04-28 23:38:49 +02:00
|
|
|
|
2019-03-02 04:07:24 +02:00
|
|
|
CreateGameOptionsGui(event)
|
2018-02-01 19:37:38 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
PlayerJoinedMessages(event)
|
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_player_list then
|
2017-04-28 03:48:28 +02:00
|
|
|
CreatePlayerListGui(event)
|
|
|
|
end
|
2017-12-15 21:45:01 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_tags then
|
2017-12-15 21:45:01 +02:00
|
|
|
CreateTagGui(event)
|
|
|
|
end
|
2018-02-01 06:31:33 +02:00
|
|
|
|
2019-04-28 20:13:46 +02:00
|
|
|
if global.satellite_sent then
|
|
|
|
CreateRocketGui(game.players[event.player_index])
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
script.on_event(defines.events.on_player_created, function(event)
|
2017-04-28 03:48:28 +02:00
|
|
|
|
|
|
|
-- Move the player to the game surface immediately.
|
|
|
|
-- May change this to Lobby in the future.
|
2019-03-15 22:15:01 +02:00
|
|
|
game.players[event.player_index].teleport({x=0,y=0}, GAME_SURFACE_NAME)
|
2017-04-27 02:59:48 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_long_reach then
|
2019-03-09 03:29:47 +02:00
|
|
|
GivePlayerLongReach(game.players[event.player_index])
|
|
|
|
end
|
|
|
|
|
2019-04-11 03:03:02 +02:00
|
|
|
SeparateSpawnsPlayerCreated(event.player_index)
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
script.on_event(defines.events.on_player_respawned, function(event)
|
2019-04-11 03:03:02 +02:00
|
|
|
SeparateSpawnsPlayerRespawned(event)
|
2017-05-12 01:42:23 +02:00
|
|
|
|
|
|
|
PlayerRespawnItems(event)
|
2016-12-14 23:45:45 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_long_reach then
|
2019-03-09 03:29:47 +02:00
|
|
|
GivePlayerLongReach(game.players[event.player_index])
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
script.on_event(defines.events.on_player_left_game, function(event)
|
2019-04-28 20:41:37 +02:00
|
|
|
FindUnusedSpawns(game.players[event.player_index], true)
|
2016-12-02 23:26:49 +02:00
|
|
|
end)
|
|
|
|
|
2019-05-12 16:00:56 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- On BUILD entity. Don't forget on_robot_built_entity too!
|
|
|
|
----------------------------------------
|
2019-03-02 06:05:23 +02:00
|
|
|
script.on_event(defines.events.on_built_entity, function(event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_autofill then
|
2019-03-09 03:29:47 +02:00
|
|
|
Autofill(event)
|
|
|
|
end
|
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_regrowth then
|
2019-04-29 05:37:12 +02:00
|
|
|
OarcRegrowthOffLimits(event.created_entity.position, 2)
|
2019-03-02 06:05:23 +02:00
|
|
|
end
|
2019-03-11 15:29:00 +02:00
|
|
|
|
|
|
|
if ENABLE_ANTI_GRIEFING then
|
|
|
|
SetItemBlueprintTimeToLive(event)
|
|
|
|
end
|
2019-05-12 16:00:56 +02:00
|
|
|
|
|
|
|
if global.ocfg.frontier_rocket_silo then
|
|
|
|
BuildSiloAttempt(event)
|
|
|
|
end
|
2019-03-02 06:05:23 +02:00
|
|
|
end)
|
2016-12-16 20:45:30 +02:00
|
|
|
|
2017-07-29 00:02:45 +02:00
|
|
|
|
2019-05-12 16:00:56 +02:00
|
|
|
|
2017-07-26 02:20:35 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- Shared vision, charts a small area around other players
|
|
|
|
----------------------------------------
|
2017-04-30 15:22:45 +02:00
|
|
|
script.on_event(defines.events.on_tick, function(event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_regrowth then
|
2019-03-03 03:51:17 +02:00
|
|
|
OarcRegrowthOnTick()
|
|
|
|
end
|
2017-11-08 16:13:34 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_abandoned_base_removal then
|
2019-03-02 06:05:23 +02:00
|
|
|
OarcRegrowthForceRemovalOnTick()
|
|
|
|
end
|
2017-07-29 00:02:45 +02:00
|
|
|
|
2019-04-11 03:03:02 +02:00
|
|
|
DelayedSpawnOnTick()
|
2018-01-25 07:04:07 +02:00
|
|
|
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.frontier_rocket_silo then
|
2019-03-03 03:51:17 +02:00
|
|
|
DelayedSiloCreationOnTick(game.surfaces[GAME_SURFACE_NAME])
|
2019-03-02 06:05:23 +02:00
|
|
|
end
|
2018-02-01 06:31:33 +02:00
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
end)
|
|
|
|
|
2017-11-29 21:39:09 +02:00
|
|
|
|
|
|
|
script.on_event(defines.events.on_sector_scanned, function (event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_regrowth then
|
2017-11-29 21:39:09 +02:00
|
|
|
OarcRegrowthSectorScan(event)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-07-29 00:02:45 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- Refreshes regrowth timers around an active timer
|
2017-08-05 15:12:20 +02:00
|
|
|
-- Refresh areas where stuff is built, and mark any chunks with player
|
|
|
|
-- built stuff as permanent.
|
2017-07-29 00:02:45 +02:00
|
|
|
----------------------------------------
|
2019-04-10 19:59:57 +02:00
|
|
|
script.on_event(defines.events.on_robot_built_entity, function (event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if global.ocfg.enable_regrowth then
|
2019-04-29 05:37:12 +02:00
|
|
|
OarcRegrowthOffLimits(event.created_entity.position, 2)
|
2019-04-10 19:59:57 +02:00
|
|
|
end
|
2019-05-12 16:00:56 +02:00
|
|
|
|
|
|
|
if global.ocfg.frontier_rocket_silo then
|
|
|
|
BuildSiloAttempt(event)
|
|
|
|
end
|
2019-04-10 19:59:57 +02:00
|
|
|
end)
|
2019-05-12 16:00:56 +02:00
|
|
|
|
2019-04-29 05:37:12 +02:00
|
|
|
-- I disabled this because it's too much overhead for too little gain!
|
|
|
|
-- script.on_event(defines.events.on_player_mined_entity, function(event)
|
|
|
|
-- if global.ocfg.enable_regrowth then
|
|
|
|
-- OarcRegrowthCheckChunkEmpty(event)
|
|
|
|
-- end
|
|
|
|
-- end)
|
|
|
|
-- script.on_event(defines.events.on_robot_mined_entity, function(event)
|
|
|
|
-- if global.ocfg.enable_regrowth then
|
|
|
|
-- OarcRegrowthCheckChunkEmpty(event)
|
|
|
|
-- end
|
|
|
|
-- end)
|
2019-04-10 19:59:57 +02:00
|
|
|
|
2017-08-08 01:27:15 +02:00
|
|
|
|
2017-07-26 02:20:35 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- Shared chat, so you don't have to type /s
|
2019-04-29 05:37:12 +02:00
|
|
|
-- But you do lose your player colors across forces.
|
2017-07-26 02:20:35 +02:00
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_console_chat, function(event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if (global.ocfg.enable_shared_chat) then
|
2017-08-09 20:11:15 +02:00
|
|
|
if (event.player_index ~= nil) then
|
2017-08-08 01:27:15 +02:00
|
|
|
ShareChatBetweenForces(game.players[event.player_index], event.message)
|
|
|
|
end
|
2017-07-26 02:20:35 +02:00
|
|
|
end
|
|
|
|
end)
|
2016-12-02 23:26:49 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- On Research Finished
|
2017-04-28 03:48:28 +02:00
|
|
|
-- This is where you can permanently remove researched techs
|
2016-12-01 04:41:04 +02:00
|
|
|
----------------------------------------
|
2019-03-02 06:05:23 +02:00
|
|
|
script.on_event(defines.events.on_research_finished, function(event)
|
2019-04-28 20:13:46 +02:00
|
|
|
|
|
|
|
-- Never allows players to build rocket-silos in "frontier" mode.
|
2019-05-15 08:40:32 +02:00
|
|
|
if global.ocfg.frontier_rocket_silo and not global.ocfg.frontier_allow_build then
|
|
|
|
RemoveRecipe(event.research.force, "rocket-silo")
|
|
|
|
end
|
2019-04-28 20:13:46 +02:00
|
|
|
|
|
|
|
if LOCK_GOODIES_UNTIL_ROCKET_LAUNCH and
|
2019-05-12 14:14:36 +02:00
|
|
|
(not global.satellite_sent or not global.satellite_sent[event.research.force.name]) then
|
2019-04-28 20:13:46 +02:00
|
|
|
RemoveRecipe(event.research.force, "productivity-module-3")
|
|
|
|
RemoveRecipe(event.research.force, "speed-module-3")
|
|
|
|
end
|
2019-05-12 16:00:56 +02:00
|
|
|
|
|
|
|
if ENABLE_LOADERS then
|
|
|
|
EnableLoaders(event)
|
|
|
|
end
|
2019-03-02 06:05:23 +02:00
|
|
|
end)
|
2016-12-19 23:35:36 +02:00
|
|
|
|
2019-03-11 15:29:00 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- On Entity Spawned
|
|
|
|
-- This is where I modify biter spawning based on location and other factors.
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_entity_spawned, function(event)
|
2019-04-11 02:40:34 +02:00
|
|
|
if (global.ocfg.modified_enemy_spawning) then
|
2019-03-11 15:29:00 +02:00
|
|
|
ModifyEnemySpawnsNearPlayerStartingAreas(event)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2019-05-03 23:52:38 +02:00
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- On Corpse Timed Out
|
|
|
|
-- Save player's stuff so they don't lose it if they can't get to the corpse fast enough.
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_character_corpse_expired, function(event)
|
|
|
|
DropGravestoneChestFromCorpse(event.corpse)
|
|
|
|
end)
|
|
|
|
|
2019-04-28 20:13:46 +02:00
|
|
|
-- on_biter_base_built -- Worth considering for later.
|