summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/game.hpp7
-rw-r--r--src/game/game_core.cpp25
-rw-r--r--src/game/game_instance.cpp14
3 files changed, 46 insertions, 0 deletions
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<const char *, class ScriptInfo *, StringCompare> ScriptInfoList;
+#include "../script/api/script_event_types.hpp"
+
/**
* Main Game class. Contains all functions needed to start, stop, save and load Game Scripts.
*/
@@ -44,6 +46,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.
*/
static class GameInstance *GetGameInstance() { return Game::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<CompanyByte> 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);