diff options
-rw-r--r-- | src/aircraft_cmd.cpp | 3 | ||||
-rw-r--r-- | src/company_cmd.cpp | 3 | ||||
-rw-r--r-- | src/disaster_cmd.cpp | 2 | ||||
-rw-r--r-- | src/economy.cpp | 3 | ||||
-rw-r--r-- | src/game/game.hpp | 7 | ||||
-rw-r--r-- | src/game/game_core.cpp | 25 | ||||
-rw-r--r-- | src/game/game_instance.cpp | 14 | ||||
-rw-r--r-- | src/industry_cmd.cpp | 5 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 4 | ||||
-rw-r--r-- | src/script/api/game/game_event_types.hpp.sq | 219 | ||||
-rw-r--r-- | src/script/api/script_event_types.hpp | 26 | ||||
-rw-r--r-- | src/subsidy.cpp | 5 | ||||
-rw-r--r-- | src/town_cmd.cpp | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 3 | ||||
-rw-r--r-- | src/water_cmd.cpp | 2 |
15 files changed, 310 insertions, 13 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 8ed4b1544..6581e3800 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -29,6 +29,7 @@ #include "cheat_type.h" #include "company_base.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "company_func.h" #include "effectvehicle_func.h" #include "station_base.h" @@ -1160,6 +1161,7 @@ static void CrashAirplane(Aircraft *v) } AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING)); + Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, st == NULL ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING)); AddVehicleNewsItem(newsitem, NS_ACCIDENT, @@ -1225,6 +1227,7 @@ static void AircraftEntersTerminal(Aircraft *v) st->index ); AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index)); + Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index)); } v->BeginLoading(); diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 5cd965038..d4627078f 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -35,6 +35,7 @@ #include "vehicle_func.h" #include "sprite.h" #include "smallmap_gui.h" +#include "game/game.hpp" #include "table/strings.h" @@ -563,6 +564,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) if (is_ai && (!_networking || _network_server)) AI::StartNew(c->index); AI::BroadcastNewEvent(new ScriptEventCompanyNew(c->index), c->index); + Game::NewEvent(new ScriptEventCompanyNew(c->index)); return c; } @@ -905,6 +907,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 CompanyID c_index = c->index; delete c; AI::BroadcastNewEvent(new ScriptEventCompanyBankrupt(c_index)); + Game::NewEvent(new ScriptEventCompanyBankrupt(c_index)); CompanyAdminRemove(c_index, (CompanyRemoveReason)reason); break; } diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index a551d83a6..319113a0a 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -40,6 +40,7 @@ #include "effectvehicle_func.h" #include "roadveh.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "company_base.h" #include "core/random_func.hpp" #include "core/backup_type.hpp" @@ -358,6 +359,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) u->index); // delete the news, when the roadvehicle is gone AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO)); + Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO)); } } diff --git a/src/economy.cpp b/src/economy.cpp index 5af0d787b..74f5552b8 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -47,6 +47,7 @@ #include "newgrf.h" #include "core/backup_type.hpp" #include "water.h" +#include "game/game.hpp" #include "table/strings.h" #include "table/pricebase.h" @@ -536,6 +537,7 @@ static void CompanyCheckBankrupt(Company *c) SetDParamStr(2, cni->company_name); AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_TROUBLE, cni); AI::BroadcastNewEvent(new ScriptEventCompanyInTrouble(c->index)); + Game::NewEvent(new ScriptEventCompanyInTrouble(c->index)); break; } @@ -1644,6 +1646,7 @@ static void DoAcquireCompany(Company *c) SetDParam(4, c->bankrupt_value); AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, NS_COMPANY_MERGER, cni); AI::BroadcastNewEvent(new ScriptEventCompanyMerger(ci, _current_company)); + Game::NewEvent(new ScriptEventCompanyMerger(ci, _current_company)); ChangeOwnershipOfCompanyItems(ci, _current_company); 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); diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index ca6315438..2126a6cac 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -39,6 +39,7 @@ #include "subsidy_func.h" #include "core/backup_type.hpp" #include "object_base.h" +#include "game/game.hpp" #include "table/strings.h" #include "table/industry_land.h" @@ -482,6 +483,7 @@ static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags) if (flags & DC_EXEC) { AI::BroadcastNewEvent(new ScriptEventIndustryClose(i->index)); + Game::NewEvent(new ScriptEventIndustryClose(i->index)); delete i; } return CommandCost(EXPENSES_CONSTRUCTION, indspec->GetRemovalCost()); @@ -1876,6 +1878,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin } AddIndustryNewsItem(indspec->new_industry_text, NS_INDUSTRY_OPEN, ind->index); AI::BroadcastNewEvent(new ScriptEventIndustryOpen(ind->index)); + Game::NewEvent(new ScriptEventIndustryOpen(ind->index)); } return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost()); @@ -1989,6 +1992,7 @@ static void AdvertiseIndustryOpening(const Industry *ind) } AddIndustryNewsItem(ind_spc->new_industry_text, NS_INDUSTRY_OPEN, ind->index); AI::BroadcastNewEvent(new ScriptEventIndustryOpen(ind->index)); + Game::NewEvent(new ScriptEventIndustryOpen(ind->index)); } /** @@ -2597,6 +2601,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) if (closeit) { ns = NS_INDUSTRY_CLOSE; AI::BroadcastNewEvent(new ScriptEventIndustryClose(i->index)); + Game::NewEvent(new ScriptEventIndustryClose(i->index)); } else { switch (WhoCanServiceIndustry(i)) { case 0: ns = NS_INDUSTRY_NOBODY; break; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 8b364f3c9..e4b093bec 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -27,6 +27,7 @@ #include "vehicle_func.h" #include "sound_func.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "depot_map.h" #include "effectvehicle_func.h" #include "roadstop_base.h" @@ -521,6 +522,7 @@ static void RoadVehCrash(RoadVehicle *v) uint pass = v->Crash(); AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING)); + Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING)); SetDParam(0, pass); AddVehicleNewsItem( @@ -669,6 +671,7 @@ static void RoadVehArrivesAt(const RoadVehicle *v, Station *st) st->index ); AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index)); + Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index)); } } else { /* Check if station was ever visited before */ @@ -682,6 +685,7 @@ static void RoadVehArrivesAt(const RoadVehicle *v, Station *st) st->index ); AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index)); + Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index)); } } } diff --git a/src/script/api/game/game_event_types.hpp.sq b/src/script/api/game/game_event_types.hpp.sq new file mode 100644 index 000000000..a6e806ffd --- /dev/null +++ b/src/script/api/game/game_event_types.hpp.sq @@ -0,0 +1,219 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_event_types.hpp" +#include "../template/template_event_types.hpp.sq" + + +template <> const char *GetClassName<ScriptEventVehicleCrashed, ST_GS>() { return "GSEventVehicleCrashed"; } + +void SQGSEventVehicleCrashed_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventVehicleCrashed, ST_GS> SQGSEventVehicleCrashed("GSEventVehicleCrashed"); + SQGSEventVehicleCrashed.PreRegister(engine, "GSEvent"); + + SQGSEventVehicleCrashed.DefSQConst(engine, ScriptEventVehicleCrashed::CRASH_TRAIN, "CRASH_TRAIN"); + SQGSEventVehicleCrashed.DefSQConst(engine, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, "CRASH_RV_LEVEL_CROSSING"); + SQGSEventVehicleCrashed.DefSQConst(engine, ScriptEventVehicleCrashed::CRASH_RV_UFO, "CRASH_RV_UFO"); + SQGSEventVehicleCrashed.DefSQConst(engine, ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, "CRASH_PLANE_LANDING"); + SQGSEventVehicleCrashed.DefSQConst(engine, ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT, "CRASH_AIRCRAFT_NO_AIRPORT"); + SQGSEventVehicleCrashed.DefSQConst(engine, ScriptEventVehicleCrashed::CRASH_FLOODED, "CRASH_FLOODED"); + + SQGSEventVehicleCrashed.DefSQStaticMethod(engine, &ScriptEventVehicleCrashed::Convert, "Convert", 2, ".x"); + + SQGSEventVehicleCrashed.DefSQMethod(engine, &ScriptEventVehicleCrashed::GetVehicleID, "GetVehicleID", 1, "x"); + SQGSEventVehicleCrashed.DefSQMethod(engine, &ScriptEventVehicleCrashed::GetCrashSite, "GetCrashSite", 1, "x"); + SQGSEventVehicleCrashed.DefSQMethod(engine, &ScriptEventVehicleCrashed::GetCrashReason, "GetCrashReason", 1, "x"); + + SQGSEventVehicleCrashed.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventSubsidyOffer, ST_GS>() { return "GSEventSubsidyOffer"; } + +void SQGSEventSubsidyOffer_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventSubsidyOffer, ST_GS> SQGSEventSubsidyOffer("GSEventSubsidyOffer"); + SQGSEventSubsidyOffer.PreRegister(engine, "GSEvent"); + + SQGSEventSubsidyOffer.DefSQStaticMethod(engine, &ScriptEventSubsidyOffer::Convert, "Convert", 2, ".x"); + + SQGSEventSubsidyOffer.DefSQMethod(engine, &ScriptEventSubsidyOffer::GetSubsidyID, "GetSubsidyID", 1, "x"); + + SQGSEventSubsidyOffer.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventSubsidyOfferExpired, ST_GS>() { return "GSEventSubsidyOfferExpired"; } + +void SQGSEventSubsidyOfferExpired_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventSubsidyOfferExpired, ST_GS> SQGSEventSubsidyOfferExpired("GSEventSubsidyOfferExpired"); + SQGSEventSubsidyOfferExpired.PreRegister(engine, "GSEvent"); + + SQGSEventSubsidyOfferExpired.DefSQStaticMethod(engine, &ScriptEventSubsidyOfferExpired::Convert, "Convert", 2, ".x"); + + SQGSEventSubsidyOfferExpired.DefSQMethod(engine, &ScriptEventSubsidyOfferExpired::GetSubsidyID, "GetSubsidyID", 1, "x"); + + SQGSEventSubsidyOfferExpired.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventSubsidyAwarded, ST_GS>() { return "GSEventSubsidyAwarded"; } + +void SQGSEventSubsidyAwarded_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventSubsidyAwarded, ST_GS> SQGSEventSubsidyAwarded("GSEventSubsidyAwarded"); + SQGSEventSubsidyAwarded.PreRegister(engine, "GSEvent"); + + SQGSEventSubsidyAwarded.DefSQStaticMethod(engine, &ScriptEventSubsidyAwarded::Convert, "Convert", 2, ".x"); + + SQGSEventSubsidyAwarded.DefSQMethod(engine, &ScriptEventSubsidyAwarded::GetSubsidyID, "GetSubsidyID", 1, "x"); + + SQGSEventSubsidyAwarded.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventSubsidyExpired, ST_GS>() { return "GSEventSubsidyExpired"; } + +void SQGSEventSubsidyExpired_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventSubsidyExpired, ST_GS> SQGSEventSubsidyExpired("GSEventSubsidyExpired"); + SQGSEventSubsidyExpired.PreRegister(engine, "GSEvent"); + + SQGSEventSubsidyExpired.DefSQStaticMethod(engine, &ScriptEventSubsidyExpired::Convert, "Convert", 2, ".x"); + + SQGSEventSubsidyExpired.DefSQMethod(engine, &ScriptEventSubsidyExpired::GetSubsidyID, "GetSubsidyID", 1, "x"); + + SQGSEventSubsidyExpired.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventCompanyNew, ST_GS>() { return "GSEventCompanyNew"; } + +void SQGSEventCompanyNew_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventCompanyNew, ST_GS> SQGSEventCompanyNew("GSEventCompanyNew"); + SQGSEventCompanyNew.PreRegister(engine, "GSEvent"); + + SQGSEventCompanyNew.DefSQStaticMethod(engine, &ScriptEventCompanyNew::Convert, "Convert", 2, ".x"); + + SQGSEventCompanyNew.DefSQMethod(engine, &ScriptEventCompanyNew::GetCompanyID, "GetCompanyID", 1, "x"); + + SQGSEventCompanyNew.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventCompanyInTrouble, ST_GS>() { return "GSEventCompanyInTrouble"; } + +void SQGSEventCompanyInTrouble_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventCompanyInTrouble, ST_GS> SQGSEventCompanyInTrouble("GSEventCompanyInTrouble"); + SQGSEventCompanyInTrouble.PreRegister(engine, "GSEvent"); + + SQGSEventCompanyInTrouble.DefSQStaticMethod(engine, &ScriptEventCompanyInTrouble::Convert, "Convert", 2, ".x"); + + SQGSEventCompanyInTrouble.DefSQMethod(engine, &ScriptEventCompanyInTrouble::GetCompanyID, "GetCompanyID", 1, "x"); + + SQGSEventCompanyInTrouble.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventCompanyMerger, ST_GS>() { return "GSEventCompanyMerger"; } + +void SQGSEventCompanyMerger_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventCompanyMerger, ST_GS> SQGSEventCompanyMerger("GSEventCompanyMerger"); + SQGSEventCompanyMerger.PreRegister(engine, "GSEvent"); + + SQGSEventCompanyMerger.DefSQStaticMethod(engine, &ScriptEventCompanyMerger::Convert, "Convert", 2, ".x"); + + SQGSEventCompanyMerger.DefSQMethod(engine, &ScriptEventCompanyMerger::GetOldCompanyID, "GetOldCompanyID", 1, "x"); + SQGSEventCompanyMerger.DefSQMethod(engine, &ScriptEventCompanyMerger::GetNewCompanyID, "GetNewCompanyID", 1, "x"); + + SQGSEventCompanyMerger.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventCompanyBankrupt, ST_GS>() { return "GSEventCompanyBankrupt"; } + +void SQGSEventCompanyBankrupt_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventCompanyBankrupt, ST_GS> SQGSEventCompanyBankrupt("GSEventCompanyBankrupt"); + SQGSEventCompanyBankrupt.PreRegister(engine, "GSEvent"); + + SQGSEventCompanyBankrupt.DefSQStaticMethod(engine, &ScriptEventCompanyBankrupt::Convert, "Convert", 2, ".x"); + + SQGSEventCompanyBankrupt.DefSQMethod(engine, &ScriptEventCompanyBankrupt::GetCompanyID, "GetCompanyID", 1, "x"); + + SQGSEventCompanyBankrupt.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventIndustryOpen, ST_GS>() { return "GSEventIndustryOpen"; } + +void SQGSEventIndustryOpen_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventIndustryOpen, ST_GS> SQGSEventIndustryOpen("GSEventIndustryOpen"); + SQGSEventIndustryOpen.PreRegister(engine, "GSEvent"); + + SQGSEventIndustryOpen.DefSQStaticMethod(engine, &ScriptEventIndustryOpen::Convert, "Convert", 2, ".x"); + + SQGSEventIndustryOpen.DefSQMethod(engine, &ScriptEventIndustryOpen::GetIndustryID, "GetIndustryID", 1, "x"); + + SQGSEventIndustryOpen.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventIndustryClose, ST_GS>() { return "GSEventIndustryClose"; } + +void SQGSEventIndustryClose_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventIndustryClose, ST_GS> SQGSEventIndustryClose("GSEventIndustryClose"); + SQGSEventIndustryClose.PreRegister(engine, "GSEvent"); + + SQGSEventIndustryClose.DefSQStaticMethod(engine, &ScriptEventIndustryClose::Convert, "Convert", 2, ".x"); + + SQGSEventIndustryClose.DefSQMethod(engine, &ScriptEventIndustryClose::GetIndustryID, "GetIndustryID", 1, "x"); + + SQGSEventIndustryClose.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventStationFirstVehicle, ST_GS>() { return "GSEventStationFirstVehicle"; } + +void SQGSEventStationFirstVehicle_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventStationFirstVehicle, ST_GS> SQGSEventStationFirstVehicle("GSEventStationFirstVehicle"); + SQGSEventStationFirstVehicle.PreRegister(engine, "GSEvent"); + + SQGSEventStationFirstVehicle.DefSQStaticMethod(engine, &ScriptEventStationFirstVehicle::Convert, "Convert", 2, ".x"); + + SQGSEventStationFirstVehicle.DefSQMethod(engine, &ScriptEventStationFirstVehicle::GetStationID, "GetStationID", 1, "x"); + SQGSEventStationFirstVehicle.DefSQMethod(engine, &ScriptEventStationFirstVehicle::GetVehicleID, "GetVehicleID", 1, "x"); + + SQGSEventStationFirstVehicle.PostRegister(engine); +} + + +template <> const char *GetClassName<ScriptEventTownFounded, ST_GS>() { return "GSEventTownFounded"; } + +void SQGSEventTownFounded_Register(Squirrel *engine) +{ + DefSQClass<ScriptEventTownFounded, ST_GS> SQGSEventTownFounded("GSEventTownFounded"); + SQGSEventTownFounded.PreRegister(engine, "GSEvent"); + + SQGSEventTownFounded.DefSQStaticMethod(engine, &ScriptEventTownFounded::Convert, "Convert", 2, ".x"); + + SQGSEventTownFounded.DefSQMethod(engine, &ScriptEventTownFounded::GetTownID, "GetTownID", 1, "x"); + + SQGSEventTownFounded.PostRegister(engine); +} diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp index 472fc72a2..cffa4a797 100644 --- a/src/script/api/script_event_types.hpp +++ b/src/script/api/script_event_types.hpp @@ -18,7 +18,7 @@ /** * Event Vehicle Crash, indicating a vehicle of yours is crashed. * It contains the crash site, the crashed vehicle and the reason for the crash. - * @api ai + * @api ai game */ class ScriptEventVehicleCrashed : public ScriptEvent { public: @@ -79,7 +79,7 @@ private: /** * Event Subsidy Offered, indicating someone offered a subsidy. - * @api ai + * @api ai game */ class ScriptEventSubsidyOffer : public ScriptEvent { public: @@ -110,7 +110,7 @@ private: /** * Event Subsidy Offer Expired, indicating a subsidy will no longer be awarded. - * @api ai + * @api ai game */ class ScriptEventSubsidyOfferExpired : public ScriptEvent { public: @@ -141,7 +141,7 @@ private: /** * Event Subidy Awarded, indicating a subsidy is awarded to some company. - * @api ai + * @api ai game */ class ScriptEventSubsidyAwarded : public ScriptEvent { public: @@ -172,7 +172,7 @@ private: /** * Event Subsidy Expired, indicating a route that was once subsidized no longer is. - * @api ai + * @api ai game */ class ScriptEventSubsidyExpired : public ScriptEvent { public: @@ -294,7 +294,7 @@ private: /** * Event Company New, indicating a new company has been created. - * @api ai + * @api ai game */ class ScriptEventCompanyNew : public ScriptEvent { public: @@ -326,7 +326,7 @@ private: /** * Event Company In Trouble, indicating a company is in trouble and might go * bankrupt soon. - * @api ai + * @api ai game */ class ScriptEventCompanyInTrouble : public ScriptEvent { public: @@ -405,7 +405,7 @@ private: /** * Event Company Merger, indicating a company has been bought by another * company. - * @api ai + * @api ai game */ class ScriptEventCompanyMerger : public ScriptEvent { public: @@ -448,7 +448,7 @@ private: /** * Event Company Bankrupt, indicating a company has gone bankrupt. - * @api ai + * @api ai game */ class ScriptEventCompanyBankrupt : public ScriptEvent { public: @@ -572,7 +572,7 @@ private: /** * Event Industry Open, indicating a new industry has been created. - * @api ai + * @api ai game */ class ScriptEventIndustryOpen : public ScriptEvent { public: @@ -603,7 +603,7 @@ private: /** * Event Industry Close, indicating an industry is going to be closed. - * @api ai + * @api ai game */ class ScriptEventIndustryClose : public ScriptEvent { public: @@ -665,7 +665,7 @@ private: /** * Event Station First Vehicle, indicating a station has been visited by a vehicle for the first time. - * @api ai + * @api ai game */ class ScriptEventStationFirstVehicle : public ScriptEvent { public: @@ -767,7 +767,7 @@ private: /** * Event Town Founded, indicating a new town has been created. - * @api ai + * @api ai game */ class ScriptEventTownFounded : public ScriptEvent { public: diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 384011d40..6e4ee0694 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -23,6 +23,7 @@ #include "subsidy_func.h" #include "core/pool_func.hpp" #include "core/random_func.hpp" +#include "game/game.hpp" #include "table/strings.h" @@ -58,6 +59,7 @@ void Subsidy::AwardTo(CompanyID company) cn ); AI::BroadcastNewEvent(new ScriptEventSubsidyAwarded(this->index)); + Game::NewEvent(new ScriptEventSubsidyAwarded(this->index)); InvalidateWindowData(WC_SUBSIDIES_LIST, 0); } @@ -202,6 +204,7 @@ void CreateSubsidy(CargoID cid, SourceType src_type, SourceID src, SourceType ds SetPartOfSubsidyFlag(s->src_type, s->src, POS_SRC); SetPartOfSubsidyFlag(s->dst_type, s->dst, POS_DST); AI::BroadcastNewEvent(new ScriptEventSubsidyOffer(s->index)); + Game::NewEvent(new ScriptEventSubsidyOffer(s->index)); } @@ -375,12 +378,14 @@ void SubsidyMonthlyLoop() Pair reftype = SetupSubsidyDecodeParam(s, true); AddNewsItem(STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); AI::BroadcastNewEvent(new ScriptEventSubsidyOfferExpired(s->index)); + Game::NewEvent(new ScriptEventSubsidyOfferExpired(s->index)); } else { if (s->awarded == _local_company) { Pair reftype = SetupSubsidyDecodeParam(s, true); AddNewsItem(STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, (NewsReferenceType)reftype.a, s->src, (NewsReferenceType)reftype.b, s->dst); } AI::BroadcastNewEvent(new ScriptEventSubsidyExpired(s->index)); + Game::NewEvent(new ScriptEventSubsidyExpired(s->index)); } delete s; modified = true; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 3bcbda8e8..096468599 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -47,6 +47,7 @@ #include "object_map.h" #include "object_base.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "table/strings.h" #include "table/town_land.h" @@ -1698,6 +1699,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 AddNewsItem(STR_NEWS_NEW_TOWN, NS_INDUSTRY_OPEN, NR_TILE, tile, NR_NONE, UINT32_MAX, cn); AI::BroadcastNewEvent(new ScriptEventTownFounded(t->index)); + Game::NewEvent(new ScriptEventTownFounded(t->index)); } } return cost; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index f5a07f20e..44e8d9efe 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -27,6 +27,7 @@ #include "vehicle_func.h" #include "sound_func.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "newgrf_station.h" #include "effectvehicle_func.h" #include "gamelog.h" @@ -2714,6 +2715,7 @@ static void TrainEnterStation(Train *v, StationID station) st->index ); AI::NewEvent(v->owner, new ScriptEventStationFirstVehicle(st->index, v->index)); + Game::NewEvent(new ScriptEventStationFirstVehicle(st->index, v->index)); } v->force_proceed = TFP_NONE; @@ -2840,6 +2842,7 @@ static uint TrainCrashed(Train *v) if (!(v->vehstatus & VS_CRASHED)) { num = v->Crash(); AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN)); + Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN)); } /* Try to re-reserve track under already crashed train too. diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index a62ae7040..19d43de03 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -32,6 +32,7 @@ #include "tunnelbridge_map.h" #include "station_base.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "core/random_func.hpp" #include "core/backup_type.hpp" #include "date_func.h" @@ -910,6 +911,7 @@ static void FloodVehicle(Vehicle *v) uint pass = v->Crash(true); AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED)); + Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED)); SetDParam(0, pass); AddVehicleNewsItem(STR_NEWS_DISASTER_FLOOD_VEHICLE, NS_ACCIDENT, v->index); CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); |