From 77b7366c2947a3f2545d5542021be1cc203a74e8 Mon Sep 17 00:00:00 2001 From: truebrain Date: Mon, 19 Dec 2011 20:59:36 +0000 Subject: (svn r23622) -Add: a set of events to trigger in a GameScript --- src/game/game.hpp | 7 +++++++ src/game/game_core.cpp | 25 +++++++++++++++++++++++++ src/game/game_instance.cpp | 14 ++++++++++++++ 3 files changed, 46 insertions(+) (limited to 'src/game') diff --git a/src/game/game.hpp b/src/game/game.hpp index ac85fe133..9e13bc5b6 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -18,6 +18,8 @@ /** A list that maps AI names to their AIInfo object. */ typedef std::map ScriptInfoList; +#include "../script/api/script_event_types.hpp" + /** * Main Game class. Contains all functions needed to start, stop, save and load Game Scripts. */ @@ -43,6 +45,11 @@ public: */ static void Uninitialize(bool keepConfig); + /** + * Queue a new event for a Game Script. + */ + static void NewEvent(class ScriptEvent *event); + /** * Get the current GameScript instance. */ diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index 13f9cb47d..9fd579599 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -109,6 +109,31 @@ } } +/* static */ void Game::NewEvent(ScriptEvent *event) +{ + /* AddRef() and Release() need to be called at least once, so do it here */ + event->AddRef(); + + /* Clients should ignore events */ + if (_networking && !_network_server) { + event->Release(); + return; + } + + /* Check if Game instance is alive */ + if (Game::instance == NULL) { + event->Release(); + return; + } + + /* Queue the event */ + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Game::instance->InsertEvent(event); + cur_company.Restore(); + + event->Release(); +} + /* static */ void Game::ResetConfig() { /* Check for both newgame as current game if we can reload the GameInfo insde diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp index 15447b9c1..e5b3bf08e 100644 --- a/src/game/game_instance.cpp +++ b/src/game/game_instance.cpp @@ -39,6 +39,7 @@ #include "../script/api/game/game_enginelist.hpp.sq" #include "../script/api/game/game_error.hpp.sq" #include "../script/api/game/game_event.hpp.sq" +#include "../script/api/game/game_event_types.hpp.sq" #include "../script/api/game/game_execmode.hpp.sq" #include "../script/api/game/game_game.hpp.sq" #include "../script/api/game/game_gamesettings.hpp.sq" @@ -109,7 +110,20 @@ void GameInstance::RegisterAPI() SQGSEngineList_Register(this->engine); SQGSError_Register(this->engine); SQGSEvent_Register(this->engine); + SQGSEventCompanyBankrupt_Register(this->engine); + SQGSEventCompanyInTrouble_Register(this->engine); + SQGSEventCompanyMerger_Register(this->engine); + SQGSEventCompanyNew_Register(this->engine); SQGSEventController_Register(this->engine); + SQGSEventIndustryClose_Register(this->engine); + SQGSEventIndustryOpen_Register(this->engine); + SQGSEventStationFirstVehicle_Register(this->engine); + SQGSEventSubsidyAwarded_Register(this->engine); + SQGSEventSubsidyExpired_Register(this->engine); + SQGSEventSubsidyOffer_Register(this->engine); + SQGSEventSubsidyOfferExpired_Register(this->engine); + SQGSEventTownFounded_Register(this->engine); + SQGSEventVehicleCrashed_Register(this->engine); SQGSExecMode_Register(this->engine); SQGSGame_Register(this->engine); SQGSGameSettings_Register(this->engine); -- cgit v1.2.3-54-g00ecf