diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index baee5c7663..e64a052037 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -2052,7 +2052,7 @@ static void AircraftHandleDestTooFar(Aircraft *v, bool too_far) if (!HasBit(v->flags, VAF_DEST_TOO_FAR)) { SetBit(v->flags, VAF_DEST_TOO_FAR); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); - AI::NewEvent(v->owner, new ScriptEventAircraftDestTooFar(v->index)); + ScriptTrigger::NewEvent(v->owner, v->index); if (v->owner == _local_company) { /* Post a news message. */ AddVehicleAdviceNewsItem(AdviceType::AircraftDestinationTooFar, GetEncodedString(STR_NEWS_AIRCRAFT_DEST_TOO_FAR, v->index), v->index); diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 668360f6e7..1225bfa1a0 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -20,7 +20,7 @@ #include "core/random_func.hpp" #include "vehiclelist.h" #include "road.h" -#include "ai/ai.hpp" +#include "script/script_trigger.hpp" #include "news_func.h" #include "strings_func.h" #include "autoreplace_cmd.h" @@ -481,7 +481,7 @@ static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlags flags, *single_unit = new_v; - AI::NewEvent(old_v->owner, new ScriptEventVehicleAutoReplaced(old_v->index, new_v->index)); + ScriptTrigger::NewEvent(old_v->owner, old_v->index, new_v->index); } /* Sell the old vehicle */ @@ -640,7 +640,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago /* Success ! */ if (flags.Test(DoCommandFlag::Execute) && new_head != old_head) { *chain = new_head; - AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index)); + ScriptTrigger::NewEvent(old_head->owner, old_head->index, new_head->index); } /* Transfer cargo of old vehicles and sell them */ @@ -709,7 +709,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago TransferCargo(old_head, new_head, true); *chain = new_head; - AI::NewEvent(old_head->owner, new ScriptEventVehicleAutoReplaced(old_head->index, new_head->index)); + ScriptTrigger::NewEvent(old_head->owner, old_head->index, new_head->index); } /* Sell the old vehicle */ diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index 93fca945bc..0b9f57c106 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -245,7 +245,7 @@ static bool DisasterTick_Zeppeliner(DisasterVehicle *v) v->age = CalendarTime::MIN_DATE; AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_ZEPPELIN, GetStationIndex(v->tile)), NewsType::Accident, v->tile); - AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCrashed(GetStationIndex(v->tile))); + ScriptTrigger::NewEvent(GetTileOwner(v->tile), GetStationIndex(v->tile)); } } @@ -263,7 +263,7 @@ static bool DisasterTick_Zeppeliner(DisasterVehicle *v) if (IsValidTile(v->tile) && IsAirportTile(v->tile)) { Station *st = Station::GetByTile(v->tile); st->airport.blocks.Reset(AirportBlock::RunwayIn); - AI::NewEvent(GetTileOwner(v->tile), new ScriptEventDisasterZeppelinerCleared(st->index)); + ScriptTrigger::NewEvent(GetTileOwner(v->tile), st->index); } v->UpdatePosition(v->x_pos, v->y_pos, GetAircraftFlightLevel(v)); diff --git a/src/engine.cpp b/src/engine.cpp index 102a284c63..0a571f987e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -21,6 +21,7 @@ #include "autoreplace_gui.h" #include "string_func.h" #include "ai/ai.hpp" +#include "game/game.hpp" #include "core/pool_func.hpp" #include "engine_gui.h" #include "engine_func.h" @@ -1127,6 +1128,9 @@ static void NewVehicleAvailable(Engine *e) /* Only broadcast event if AIs are able to build this vehicle type. */ if (!IsVehicleTypeDisabled(e->type, true)) AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index)); + /* Only send the event to Game Script if engine can be built. */ + if (!IsVehicleTypeDisabled(e->type, false)) Game::NewEvent(new ScriptEventEngineAvailable(index)); + /* Only provide the "New Vehicle available" news paper entry, if engine can be built. */ if (!IsVehicleTypeDisabled(e->type, false) && !e->info.extra_flags.Test(ExtraEngineFlag::NoNews)) { AddNewsItem(GetEncodedString(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index e65c57f148..3f6806dfd8 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -28,6 +28,14 @@ * \li GSCargo::CC_POTABLE * \li GSCargo::CC_NON_POTABLE * \li GSGroup::GetOwner + * \li GSEventVehicleLost + * \li GSEventVehicleWaitingInDepot + * \li GSEventVehicleUnprofitable + * \li GSEventEngineAvailable + * \li GSEventDisasterZeppelinerCrashed + * \li GSEventDisasterZeppelinerCleared + * \li GSEventAircraftDestTooFar + * \li GSEventVehicleAutoReplaced * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp index 0b67ce9376..fdc548d591 100644 --- a/src/script/api/script_event_types.hpp +++ b/src/script/api/script_event_types.hpp @@ -568,7 +568,7 @@ private: /** * Event Vehicle Lost, indicating a vehicle can't find its way to its destination. - * @api ai + * @api ai game */ class ScriptEventVehicleLost : public ScriptEvent { public: @@ -601,7 +601,7 @@ private: /** * Event VehicleWaitingInDepot, indicating a vehicle has arrived a depot and is now waiting there. - * @api ai + * @api ai game */ class ScriptEventVehicleWaitingInDepot : public ScriptEvent { public: @@ -634,7 +634,7 @@ private: /** * Event Vehicle Unprofitable, indicating a vehicle lost money last year. - * @api ai + * @api ai game */ class ScriptEventVehicleUnprofitable : public ScriptEvent { public: @@ -733,7 +733,7 @@ private: /** * Event Engine Available, indicating a new engine is available. - * @api ai + * @api ai game */ class ScriptEventEngineAvailable : public ScriptEvent { public: @@ -808,7 +808,7 @@ private: /** * Event Disaster Zeppeliner Crashed, indicating a zeppeliner has crashed on an airport and is blocking the runway. - * @api ai + * @api ai game */ class ScriptEventDisasterZeppelinerCrashed : public ScriptEvent { public: @@ -841,7 +841,7 @@ private: /** * Event Disaster Zeppeliner Cleared, indicating a previously crashed zeppeliner has been removed, and the airport is operating again. - * @api ai + * @api ai game */ class ScriptEventDisasterZeppelinerCleared : public ScriptEvent { public: @@ -909,7 +909,7 @@ private: * Event AircraftDestTooFar, indicating the next destination of an aircraft is too far away. * This event can be triggered when the current order of an aircraft changes, usually either when * loading is done or when switched manually. - * @api ai + * @api ai game */ class ScriptEventAircraftDestTooFar : public ScriptEvent { public: @@ -1177,7 +1177,7 @@ public: /** * Event VehicleAutoReplaced, indicating a vehicle has been auto replaced. - * @api ai + * @api ai game */ class ScriptEventVehicleAutoReplaced : public ScriptEvent { public: diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 97e5b3a009..d781cb04df 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -29,7 +29,7 @@ #include "autoreplace_func.h" #include "autoreplace_gui.h" #include "station_base.h" -#include "ai/ai.hpp" +#include "script/script_trigger.hpp" #include "depot_func.h" #include "network/network.h" #include "core/pool_func.hpp" @@ -812,7 +812,7 @@ void Vehicle::HandlePathfindingResult(bool path_found) this->ResetDepotUnbunching(); /* Notify user about the event. */ - AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index)); + ScriptTrigger::NewEvent(this->owner, this->index); if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) { AddVehicleAdviceNewsItem(AdviceType::VehicleLost, GetEncodedString(STR_NEWS_VEHICLE_IS_LOST, this->index), this->index); } @@ -1657,7 +1657,7 @@ void VehicleEnterDepot(Vehicle *v) if (v->owner == _local_company) { AddVehicleAdviceNewsItem(AdviceType::VehicleWaiting, GetEncodedString(STR_NEWS_TRAIN_IS_WAITING + v->type, v->index), v->index); } - AI::NewEvent(v->owner, new ScriptEventVehicleWaitingInDepot(v->index)); + ScriptTrigger::NewEvent(v->owner, v->index); } /* If we've entered our unbunching depot, record the round trip duration. */ @@ -3020,7 +3020,7 @@ static IntervalTimer _economy_vehicles_yearly({TimerGameEconom GetEncodedString(TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_VEHICLE_UNPROFITABLE_PERIOD : STR_NEWS_VEHICLE_UNPROFITABLE_YEAR, v->index, profit), v->index); } - AI::NewEvent(v->owner, new ScriptEventVehicleUnprofitable(v->index)); + ScriptTrigger::NewEvent(v->owner, v->index); } v->profit_last_year = v->profit_this_year;