(svn r23622) -Add: a set of events to trigger in a GameScript
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
@@ -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.
|
||||
*/
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user