mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Add vehicle owner to crash event (#13878)
Co-authored-by: Björn Wärmedal <bjorn.warmedal@lumera.com>pull/13896/head
parent
fb008436b8
commit
d009bfc47b
|
@ -1345,8 +1345,8 @@ static void CrashAirplane(Aircraft *v)
|
||||||
headline = GetEncodedString(STR_NEWS_AIRCRAFT_CRASH, victims, st->index);
|
headline = GetEncodedString(STR_NEWS_AIRCRAFT_CRASH, victims, st->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
|
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims, v->owner));
|
||||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims));
|
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims, v->owner));
|
||||||
|
|
||||||
NewsType newstype = NewsType::Accident;
|
NewsType newstype = NewsType::Accident;
|
||||||
if (v->owner != _local_company) {
|
if (v->owner != _local_company) {
|
||||||
|
|
|
@ -388,8 +388,8 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
|
||||||
|
|
||||||
AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_SMALL_UFO), NewsType::Accident, u->tile);
|
AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_SMALL_UFO), NewsType::Accident, u->tile);
|
||||||
|
|
||||||
AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO, victims));
|
AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO, victims, u->owner));
|
||||||
Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO, victims));
|
Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO, victims, u->owner));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -544,8 +544,8 @@ static void RoadVehCrash(RoadVehicle *v)
|
||||||
{
|
{
|
||||||
uint victims = v->Crash();
|
uint victims = v->Crash();
|
||||||
|
|
||||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, victims));
|
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, victims, v->owner));
|
||||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, victims));
|
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, victims, v->owner));
|
||||||
|
|
||||||
EncodedString headline = (victims == 1)
|
EncodedString headline = (victims == 1)
|
||||||
? GetEncodedString(STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER)
|
? GetEncodedString(STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*
|
*
|
||||||
* API additions:
|
* API additions:
|
||||||
* \li AIEventVehicleCrashed::GetVictims
|
* \li AIEventVehicleCrashed::GetVictims
|
||||||
|
* \li AIEventVehicleCrashed::GetVehicleOwner
|
||||||
* \li AIEventCompanyRenamed
|
* \li AIEventCompanyRenamed
|
||||||
* \li AIEventPresidentRenamed
|
* \li AIEventPresidentRenamed
|
||||||
* \li AICargo::CC_OVERSIZED
|
* \li AICargo::CC_OVERSIZED
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*
|
*
|
||||||
* API additions:
|
* API additions:
|
||||||
* \li GSEventVehicleCrashed::GetVictims
|
* \li GSEventVehicleCrashed::GetVictims
|
||||||
|
* \li GSEventVehicleCrashed::GetVehicleOwner
|
||||||
* \li GSEventCompanyRenamed
|
* \li GSEventCompanyRenamed
|
||||||
* \li GSEventPresidentRenamed
|
* \li GSEventPresidentRenamed
|
||||||
* \li GSCargo::CC_OVERSIZED
|
* \li GSCargo::CC_OVERSIZED
|
||||||
|
|
|
@ -45,13 +45,15 @@ public:
|
||||||
* @param crash_site Where the vehicle crashed.
|
* @param crash_site Where the vehicle crashed.
|
||||||
* @param crash_reason The reason why the vehicle crashed.
|
* @param crash_reason The reason why the vehicle crashed.
|
||||||
* @param victims The number of victims caused by the crash.
|
* @param victims The number of victims caused by the crash.
|
||||||
|
* @param the ID of the company owning the crashed vehicle.
|
||||||
*/
|
*/
|
||||||
ScriptEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason, uint victims) :
|
ScriptEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason, uint victims, ::CompanyID company) :
|
||||||
ScriptEvent(ET_VEHICLE_CRASHED),
|
ScriptEvent(ET_VEHICLE_CRASHED),
|
||||||
crash_site(crash_site),
|
crash_site(crash_site),
|
||||||
vehicle(vehicle),
|
vehicle(vehicle),
|
||||||
crash_reason(crash_reason),
|
crash_reason(crash_reason),
|
||||||
victims(victims)
|
victims(victims),
|
||||||
|
company(ScriptCompany::ToScriptCompanyID(company))
|
||||||
{}
|
{}
|
||||||
#endif /* DOXYGEN_API */
|
#endif /* DOXYGEN_API */
|
||||||
|
|
||||||
|
@ -86,11 +88,18 @@ public:
|
||||||
*/
|
*/
|
||||||
SQInteger GetVictims() { return this->victims; }
|
SQInteger GetVictims() { return this->victims; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the CompanyID of the company owning the vehicle
|
||||||
|
* @return The company owning the vehicle
|
||||||
|
*/
|
||||||
|
ScriptCompany::CompanyID GetVehicleOwner() { return this->company; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TileIndex crash_site; ///< The location of the crash.
|
TileIndex crash_site; ///< The location of the crash.
|
||||||
VehicleID vehicle; ///< The crashed vehicle.
|
VehicleID vehicle; ///< The crashed vehicle.
|
||||||
CrashReason crash_reason; ///< The reason for crashing.
|
CrashReason crash_reason; ///< The reason for crashing.
|
||||||
uint victims; ///< The number of victims.
|
uint victims; ///< The number of victims.
|
||||||
|
ScriptCompany::CompanyID company; ///< The company owning the vehicle.
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3152,8 +3152,8 @@ static uint TrainCrashed(Train *v)
|
||||||
/* do not crash train twice */
|
/* do not crash train twice */
|
||||||
if (!v->vehstatus.Test(VehState::Crashed)) {
|
if (!v->vehstatus.Test(VehState::Crashed)) {
|
||||||
victims = v->Crash();
|
victims = v->Crash();
|
||||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims));
|
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims, v->owner));
|
||||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims));
|
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims, v->owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to re-reserve track under already crashed train too.
|
/* Try to re-reserve track under already crashed train too.
|
||||||
|
|
|
@ -1005,8 +1005,8 @@ static void FloodVehicle(Vehicle *v)
|
||||||
{
|
{
|
||||||
uint victims = v->Crash(true);
|
uint victims = v->Crash(true);
|
||||||
|
|
||||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims));
|
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims, v->owner));
|
||||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims));
|
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims, v->owner));
|
||||||
AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_FLOOD_VEHICLE, victims), NewsType::Accident, v->tile);
|
AddTileNewsItem(GetEncodedString(STR_NEWS_DISASTER_FLOOD_VEHICLE, victims), NewsType::Accident, v->tile);
|
||||||
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
||||||
if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
||||||
|
|
Loading…
Reference in New Issue