mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Add: [Script] Include number of victims in ScriptEventVehicleCrashed (#12861)
This commit is contained in:
parent
eeed824329
commit
d67963e616
@ -1322,10 +1322,10 @@ void Aircraft::MarkDirty()
|
||||
|
||||
uint Aircraft::Crash(bool flooded)
|
||||
{
|
||||
uint pass = Vehicle::Crash(flooded) + 2; // pilots
|
||||
uint victims = Vehicle::Crash(flooded) + 2; // pilots
|
||||
this->crashed_counter = flooded ? 9000 : 0; // max 10000, disappear pretty fast when flooded
|
||||
|
||||
return pass;
|
||||
return victims;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1336,8 +1336,8 @@ static void CrashAirplane(Aircraft *v)
|
||||
{
|
||||
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
||||
|
||||
uint pass = v->Crash();
|
||||
SetDParam(0, pass);
|
||||
uint victims = v->Crash();
|
||||
SetDParam(0, victims);
|
||||
|
||||
v->cargo.Truncate();
|
||||
v->Next()->cargo.Truncate();
|
||||
@ -1351,8 +1351,8 @@ static void CrashAirplane(Aircraft *v)
|
||||
newsitem = STR_NEWS_AIRCRAFT_CRASH;
|
||||
}
|
||||
|
||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
|
||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING));
|
||||
AI::NewEvent(v->owner, 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));
|
||||
|
||||
NewsType newstype = NT_ACCIDENT;
|
||||
if (v->owner != _local_company) {
|
||||
|
@ -384,13 +384,13 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
|
||||
if (z <= u->z_pos && (u->vehstatus & VS_HIDDEN) == 0) {
|
||||
v->age++;
|
||||
if (u->crashed_ctr == 0) {
|
||||
u->Crash();
|
||||
uint victims = u->Crash();
|
||||
u->disaster_vehicle = INVALID_VEHICLE;
|
||||
|
||||
AddTileNewsItem(STR_NEWS_DISASTER_SMALL_UFO, NT_ACCIDENT, u->tile);
|
||||
|
||||
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));
|
||||
AI::NewEvent(u->owner, new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO, victims));
|
||||
Game::NewEvent(new ScriptEventVehicleCrashed(u->index, u->tile, ScriptEventVehicleCrashed::CRASH_RV_UFO, victims));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,9 +528,9 @@ static Vehicle *EnumCheckRoadVehCrashTrain(Vehicle *v, void *data)
|
||||
|
||||
uint RoadVehicle::Crash(bool flooded)
|
||||
{
|
||||
uint pass = this->GroundVehicleBase::Crash(flooded);
|
||||
uint victims = this->GroundVehicleBase::Crash(flooded);
|
||||
if (this->IsFrontEngine()) {
|
||||
pass += 1; // driver
|
||||
victims += 1; // driver
|
||||
|
||||
/* If we're in a drive through road stop we ought to leave it */
|
||||
if (IsInsideMM(this->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) {
|
||||
@ -538,18 +538,18 @@ uint RoadVehicle::Crash(bool flooded)
|
||||
}
|
||||
}
|
||||
this->crashed_ctr = flooded ? 2000 : 1; // max 2220, disappear pretty fast when flooded
|
||||
return pass;
|
||||
return victims;
|
||||
}
|
||||
|
||||
static void RoadVehCrash(RoadVehicle *v)
|
||||
{
|
||||
uint pass = v->Crash();
|
||||
uint victims = 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));
|
||||
AI::NewEvent(v->owner, 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));
|
||||
|
||||
SetDParam(0, pass);
|
||||
StringID newsitem = (pass == 1) ? STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER : STR_NEWS_ROAD_VEHICLE_CRASH;
|
||||
SetDParam(0, victims);
|
||||
StringID newsitem = (victims == 1) ? STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER : STR_NEWS_ROAD_VEHICLE_CRASH;
|
||||
NewsType newstype = NT_ACCIDENT;
|
||||
|
||||
if (v->owner != _local_company) {
|
||||
|
@ -17,6 +17,9 @@
|
||||
*
|
||||
* This version is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li AIEventVehicleCrashed::GetVictims
|
||||
*
|
||||
* \b 14.0
|
||||
*
|
||||
* API additions:
|
||||
|
@ -17,6 +17,9 @@
|
||||
*
|
||||
* This version is not yet released. The following changes are not set in stone yet.
|
||||
*
|
||||
* API additions:
|
||||
* \li GSEventVehicleCrashed::GetVictims
|
||||
*
|
||||
* \b 14.0
|
||||
*
|
||||
* API additions:
|
||||
|
@ -38,12 +38,14 @@ public:
|
||||
* @param vehicle The vehicle that crashed.
|
||||
* @param crash_site Where the vehicle crashed.
|
||||
* @param crash_reason The reason why the vehicle crashed.
|
||||
* @param victims The number of victims caused by the crash.
|
||||
*/
|
||||
ScriptEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason) :
|
||||
ScriptEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason, uint victims) :
|
||||
ScriptEvent(ET_VEHICLE_CRASHED),
|
||||
crash_site(crash_site),
|
||||
vehicle(vehicle),
|
||||
crash_reason(crash_reason)
|
||||
crash_reason(crash_reason),
|
||||
victims(victims)
|
||||
{}
|
||||
#endif /* DOXYGEN_API */
|
||||
|
||||
@ -72,10 +74,17 @@ public:
|
||||
*/
|
||||
CrashReason GetCrashReason() { return this->crash_reason; }
|
||||
|
||||
/**
|
||||
* Get the number of victims
|
||||
* @return The number of victims
|
||||
*/
|
||||
SQInteger GetVictims() { return this->victims; }
|
||||
|
||||
private:
|
||||
TileIndex crash_site; ///< The location of the crash.
|
||||
VehicleID vehicle; ///< The crashed vehicle.
|
||||
CrashReason crash_reason; ///< The reason for crashing.
|
||||
uint victims; ///< The number of victims.
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3086,9 +3086,9 @@ void Train::ReserveTrackUnderConsist() const
|
||||
*/
|
||||
uint Train::Crash(bool flooded)
|
||||
{
|
||||
uint pass = 0;
|
||||
uint victims = 0;
|
||||
if (this->IsFrontEngine()) {
|
||||
pass += 2; // driver
|
||||
victims += 2; // driver
|
||||
|
||||
/* Remove the reserved path in front of the train if it is not stuck.
|
||||
* Also clear all reserved tracks the train is currently on. */
|
||||
@ -3111,10 +3111,10 @@ uint Train::Crash(bool flooded)
|
||||
HideFillingPercent(&this->fill_percent_te_id);
|
||||
}
|
||||
|
||||
pass += this->GroundVehicleBase::Crash(flooded);
|
||||
victims += this->GroundVehicleBase::Crash(flooded);
|
||||
|
||||
this->crash_anim_pos = flooded ? 4000 : 1; // max 4440, disappear pretty fast when flooded
|
||||
return pass;
|
||||
return victims;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3125,20 +3125,20 @@ uint Train::Crash(bool flooded)
|
||||
*/
|
||||
static uint TrainCrashed(Train *v)
|
||||
{
|
||||
uint num = 0;
|
||||
uint victims = 0;
|
||||
|
||||
/* do not crash train twice */
|
||||
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));
|
||||
victims = v->Crash();
|
||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims));
|
||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_TRAIN, victims));
|
||||
}
|
||||
|
||||
/* Try to re-reserve track under already crashed train too.
|
||||
* Crash() clears the reservation! */
|
||||
v->ReserveTrackUnderConsist();
|
||||
|
||||
return num;
|
||||
return victims;
|
||||
}
|
||||
|
||||
/** Temporary data storage for testing collisions. */
|
||||
|
@ -990,11 +990,11 @@ static void GetTileDesc_Water(TileIndex tile, TileDesc *td)
|
||||
*/
|
||||
static void FloodVehicle(Vehicle *v)
|
||||
{
|
||||
uint pass = v->Crash(true);
|
||||
uint victims = 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);
|
||||
AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims));
|
||||
Game::NewEvent(new ScriptEventVehicleCrashed(v->index, v->tile, ScriptEventVehicleCrashed::CRASH_FLOODED, victims));
|
||||
SetDParam(0, victims);
|
||||
AddTileNewsItem(STR_NEWS_DISASTER_FLOOD_VEHICLE, NT_ACCIDENT, v->tile);
|
||||
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
|
||||
if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
|
||||
|
Loading…
Reference in New Issue
Block a user