2016-12-01 04:41:04 +02:00
|
|
|
-- control.lua
|
2017-04-26 01:33:58 +02:00
|
|
|
-- Apr 2017
|
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:
|
|
|
|
-- RSO mod to RSO author - Orzelek - I contacted him via the forum
|
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
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
-- To keep the scenario more manageable I have done the following:
|
|
|
|
-- 1. Keep all event calls in control.lua (here)
|
|
|
|
-- 2. Put all config options in config.lua
|
|
|
|
-- 3. Put mods into their own files where possible (RSO has multiple)
|
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
|
|
|
|
require("locale/oarc_utils")
|
|
|
|
require("locale/rso/rso_control")
|
|
|
|
require("locale/frontier_silo")
|
|
|
|
require("locale/tag")
|
|
|
|
|
|
|
|
-- Main Configuration File
|
2016-12-01 04:41:04 +02:00
|
|
|
require("config")
|
|
|
|
|
2016-12-28 18:33:09 +02:00
|
|
|
-- Scenario Specific Includes
|
2016-11-26 02:20:41 +02:00
|
|
|
require("separate_spawns")
|
2016-12-01 04:41:04 +02:00
|
|
|
require("separate_spawns_guis")
|
2017-07-29 00:02:45 +02:00
|
|
|
require("regrowth_map")
|
2016-11-10 12:22:32 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Rocket Launch Event Code
|
|
|
|
-- Controls the "win condition"
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function RocketLaunchEvent(event)
|
2016-11-10 12:22:32 +02:00
|
|
|
local force = event.rocket.force
|
2016-12-01 04:41:04 +02:00
|
|
|
|
2016-11-10 12:22:32 +02:00
|
|
|
if event.rocket.get_item_count("satellite") == 0 then
|
|
|
|
for index, player in pairs(force.players) do
|
|
|
|
player.print("You launched the rocket, but you didn't put a satellite inside.")
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not global.satellite_sent then
|
|
|
|
global.satellite_sent = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if global.satellite_sent[force.name] then
|
|
|
|
global.satellite_sent[force.name] = global.satellite_sent[force.name] + 1
|
|
|
|
else
|
|
|
|
game.set_game_state{game_finished=true, player_won=true, can_continue=true}
|
|
|
|
global.satellite_sent[force.name] = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
for index, player in pairs(force.players) do
|
|
|
|
if player.gui.left.rocket_score then
|
|
|
|
player.gui.left.rocket_score.rocket_count.caption = tostring(global.satellite_sent[force.name])
|
|
|
|
else
|
|
|
|
local frame = player.gui.left.add{name = "rocket_score", type = "frame", direction = "horizontal", caption="Score"}
|
|
|
|
frame.add{name="rocket_count_label", type = "label", caption={"", "Satellites launched", ":"}}
|
|
|
|
frame.add{name="rocket_count", type = "label", caption=tostring(global.satellite_sent[force.name])}
|
|
|
|
end
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- ALL EVENT HANLDERS ARE HERE IN ONE PLACE!
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- On Init - only runs once the first
|
|
|
|
-- time the game starts
|
|
|
|
----------------------------------------
|
|
|
|
script.on_init(function(event)
|
2016-12-21 03:42:10 +02:00
|
|
|
|
2017-04-28 03:48:28 +02:00
|
|
|
-- CreateLobbySurface() -- Currently unused, but have plans for future.
|
|
|
|
|
|
|
|
-- Here I create the game surface. I do this so that I don't have to worry
|
|
|
|
-- about the game menu settings and I can now generate a map from the command
|
|
|
|
-- line more easily!
|
|
|
|
--
|
|
|
|
-- If you are using RSO, map settings are ignored and you MUST configure
|
|
|
|
-- the relevant map settings in config.lua
|
|
|
|
--
|
|
|
|
-- If you disable RSO, the map settings will be set from the ones that you
|
|
|
|
-- choose from the game GUI when you start a new scenario.
|
|
|
|
if ENABLE_RSO then
|
2017-04-28 22:40:59 +02:00
|
|
|
CreateGameSurface(RSO_MODE)
|
2017-04-28 03:48:28 +02:00
|
|
|
else
|
2017-04-28 22:40:59 +02:00
|
|
|
CreateGameSurface(VANILLA_MODE)
|
2017-04-28 03:48:28 +02:00
|
|
|
end
|
2017-04-27 02:59:48 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
if ENABLE_SEPARATE_SPAWNS then
|
|
|
|
InitSpawnGlobalsAndForces()
|
|
|
|
end
|
|
|
|
|
2016-12-14 01:46:48 +02:00
|
|
|
if ENABLE_RANDOM_SILO_POSITION then
|
|
|
|
SetRandomSiloPosition()
|
2016-12-14 02:58:56 +02:00
|
|
|
else
|
|
|
|
SetFixedSiloPosition()
|
2016-12-14 01:46:48 +02:00
|
|
|
end
|
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
if FRONTIER_ROCKET_SILO_MODE then
|
2017-04-27 02:59:48 +02:00
|
|
|
ChartRocketSiloArea(game.forces[MAIN_FORCE], game.surfaces[GAME_SURFACE_NAME])
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
2016-12-16 20:45:30 +02:00
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
-- Configures the map settings for enemies
|
|
|
|
-- This controls evolution growth factors and enemy expansion settings.
|
|
|
|
ConfigureAlienStartingParams()
|
|
|
|
|
2017-05-12 01:42:23 +02:00
|
|
|
SetServerWelcomeMessages()
|
2017-07-26 00:12:55 +02:00
|
|
|
|
2017-07-29 00:02:45 +02:00
|
|
|
if ENABLE_REGROWTH then
|
|
|
|
OarcRegrowthInit()
|
|
|
|
end
|
|
|
|
|
2017-07-26 00:12:55 +02:00
|
|
|
--If any (not global.) globals are written to at this point, an error will be thrown.
|
|
|
|
--eg, x = 2 will throw an error because it's not global.x
|
2017-07-29 01:55:43 +02:00
|
|
|
-- setmetatable(_G, {
|
|
|
|
-- __newindex = function(_, n)
|
|
|
|
-- log("Attempt to write to undeclared var " .. n)
|
|
|
|
-- game.print("Attempt to write to undeclared var " .. n)
|
|
|
|
-- end
|
|
|
|
-- })
|
|
|
|
-- -- THIS REQUIRES A LOT OF CHANGES TO RSO SOFT MOD...
|
2017-07-26 00:12:55 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- Freeplay rocket launch info
|
|
|
|
-- Slightly modified for my purposes
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_rocket_launched, function(event)
|
|
|
|
if FRONTIER_ROCKET_SILO_MODE then
|
|
|
|
RocketLaunchEvent(event)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- Chunk Generation
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_chunk_generated, function(event)
|
2017-07-29 00:02:45 +02:00
|
|
|
if ENABLE_REGROWTH then
|
|
|
|
OarcRegrowthChunkGenerate(event)
|
|
|
|
end
|
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
if ENABLE_UNDECORATOR then
|
|
|
|
UndecorateOnChunkGenerate(event)
|
|
|
|
end
|
|
|
|
|
|
|
|
if ENABLE_RSO then
|
|
|
|
RSO_ChunkGenerated(event)
|
|
|
|
end
|
|
|
|
|
|
|
|
if FRONTIER_ROCKET_SILO_MODE then
|
|
|
|
GenerateRocketSiloChunk(event)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- This MUST come after RSO generation!
|
|
|
|
if ENABLE_SEPARATE_SPAWNS then
|
|
|
|
SeparateSpawnsGenerateChunk(event)
|
|
|
|
end
|
2017-05-13 04:33:57 +02:00
|
|
|
|
2017-07-29 00:02:45 +02:00
|
|
|
CreateHoldingPenGenerateChunk(event)
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- Gui Click
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_gui_click, function(event)
|
|
|
|
if ENABLE_TAGS then
|
|
|
|
TagGuiClick(event)
|
|
|
|
end
|
|
|
|
|
2017-04-28 03:48:28 +02:00
|
|
|
if ENABLE_PLAYER_LIST then
|
|
|
|
PlayerListGuiClick(event)
|
|
|
|
end
|
2017-04-28 22:40:59 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
if ENABLE_SEPARATE_SPAWNS then
|
|
|
|
WelcomeTextGuiClick(event)
|
|
|
|
SpawnOptsGuiClick(event)
|
2016-12-02 23:26:49 +02:00
|
|
|
SpawnCtrlGuiClick(event)
|
|
|
|
SharedSpwnOptsGuiClick(event)
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
2016-12-19 23:35:36 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
----------------------------------------
|
|
|
|
-- Player Events
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_player_joined_game, function(event)
|
2017-04-28 23:38:49 +02:00
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
PlayerJoinedMessages(event)
|
|
|
|
|
|
|
|
if ENABLE_TAGS then
|
|
|
|
CreateTagGui(event)
|
|
|
|
end
|
2017-04-28 03:48:28 +02:00
|
|
|
|
|
|
|
if ENABLE_PLAYER_LIST then
|
|
|
|
CreatePlayerListGui(event)
|
|
|
|
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.
|
2017-04-27 02:59:48 +02:00
|
|
|
game.players[event.player_index].teleport(game.forces[MAIN_FORCE].get_spawn_position(GAME_SURFACE_NAME), GAME_SURFACE_NAME)
|
|
|
|
|
2016-12-14 01:46:48 +02:00
|
|
|
if ENABLE_LONGREACH then
|
|
|
|
GivePlayerLongReach(game.players[event.player_index])
|
|
|
|
end
|
|
|
|
|
2016-12-01 04:41:04 +02:00
|
|
|
if not ENABLE_SEPARATE_SPAWNS then
|
|
|
|
PlayerSpawnItems(event)
|
|
|
|
else
|
|
|
|
SeparateSpawnsPlayerCreated(event)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
script.on_event(defines.events.on_player_respawned, function(event)
|
2017-05-12 01:42:23 +02:00
|
|
|
if ENABLE_SEPARATE_SPAWNS then
|
|
|
|
SeparateSpawnsPlayerRespawned(event)
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
2017-05-12 01:42:23 +02:00
|
|
|
|
|
|
|
PlayerRespawnItems(event)
|
2016-12-14 23:45:45 +02:00
|
|
|
|
|
|
|
if ENABLE_LONGREACH then
|
|
|
|
GivePlayerLongReach(game.players[event.player_index])
|
|
|
|
end
|
2016-12-01 04:41:04 +02:00
|
|
|
end)
|
|
|
|
|
2017-05-12 01:42:23 +02:00
|
|
|
script.on_event(defines.events.on_pre_player_died, function(event)
|
|
|
|
if ENABLE_GRAVESTONE_ON_DEATH then
|
|
|
|
DropGravestoneChests(game.players[event.player_index])
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
script.on_event(defines.events.on_player_left_game, function(event)
|
2017-05-12 01:42:23 +02:00
|
|
|
if ENABLE_GRAVESTONE_ON_LEAVING then
|
2017-05-13 04:33:57 +02:00
|
|
|
if (game.players[event.player_index].online_time <
|
|
|
|
ENABLE_GRAVESTONE_ON_LEAVING_TIME_MINS) then
|
|
|
|
DropGravestoneChests(game.players[event.player_index])
|
|
|
|
end
|
2017-05-12 01:42:23 +02:00
|
|
|
end
|
|
|
|
|
2016-12-02 23:26:49 +02:00
|
|
|
if ENABLE_SEPARATE_SPAWNS then
|
|
|
|
FindUnusedSpawns(event)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-12-16 20:45:30 +02:00
|
|
|
script.on_event(defines.events.on_built_entity, function(event)
|
|
|
|
if ENABLE_AUTOFILL then
|
|
|
|
Autofill(event)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2017-07-29 00:02:45 +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)
|
|
|
|
-- Every few seconds, chart all players to "share vision"
|
2017-05-12 01:42:23 +02:00
|
|
|
if ENABLE_SHARED_TEAM_VISION then
|
2017-05-21 21:33:52 +02:00
|
|
|
ShareVisionBetweenPlayers()
|
2017-04-30 15:22:45 +02:00
|
|
|
end
|
2017-07-29 00:02:45 +02:00
|
|
|
|
|
|
|
if ENABLE_REGROWTH then
|
|
|
|
OarcRegrowthOnTick(event)
|
|
|
|
end
|
|
|
|
|
2017-04-30 15:22:45 +02:00
|
|
|
end)
|
|
|
|
|
2017-07-29 00:02:45 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- Refreshes regrowth timers around an active timer
|
|
|
|
----------------------------------------
|
|
|
|
if ENABLE_REGROWTH then
|
|
|
|
script.on_event(defines.events.on_sector_scanned, function (event)
|
|
|
|
OarcRegrowthSectorScan(event)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2017-07-26 02:20:35 +02:00
|
|
|
----------------------------------------
|
|
|
|
-- Shared chat, so you don't have to type /s
|
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_console_chat, function(event)
|
|
|
|
if (ENABLE_SHARED_TEAM_CHAT) then
|
|
|
|
ShareChatBetweenForces(game.players[event.player_index], event.message)
|
|
|
|
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
|
|
|
----------------------------------------
|
|
|
|
script.on_event(defines.events.on_research_finished, function(event)
|
|
|
|
if FRONTIER_ROCKET_SILO_MODE then
|
2017-04-27 02:59:48 +02:00
|
|
|
RemoveRecipe(event.research.force, "rocket-silo")
|
2016-12-01 04:41:04 +02:00
|
|
|
end
|
2016-11-10 12:22:32 +02:00
|
|
|
end)
|
2016-12-19 23:35:36 +02:00
|
|
|
|
|
|
|
|
2017-07-29 00:02:45 +02:00
|
|
|
|
2016-12-19 23:35:36 +02:00
|
|
|
----------------------------------------
|
2017-04-26 01:33:58 +02:00
|
|
|
-- Other?
|
2016-12-19 23:35:36 +02:00
|
|
|
----------------------------------------
|
2017-04-26 01:33:58 +02:00
|
|
|
-- script.on_event(defines.events.on_robot_built_entity, function(event)
|
|
|
|
|
|
|
|
-- end)
|