Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New effect: Cars will explode on fire #319

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/gtasa/effects/custom/vehicle/CarsExplodeOnFireEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "util/EffectBase.h"

class CarsExplodeOnFireEffect : public EffectBase
{
// give some space for GhostRider to reset to 0
static inline const float BURN_TIMER = 4900.0f;

public:
void
OnTick (EffectInstance *inst) override
{
for (auto *vehicle : CPools::ms_pVehiclePool)
{
if (vehicle->m_fHealth < 250.0f)
{
SetBurnTimer (vehicle, BURN_TIMER);
}
}
}

void
SetBurnTimer (CVehicle *vehicle, float value)
{
if (!vehicle || !CPools::ms_pVehiclePool->IsObjectValid (vehicle))
{
return;
}

auto *model = CModelInfo::ms_modelInfoPtrs[vehicle->m_nModelIndex];
if (!model) return;

auto *vehicleModelInfo = reinterpret_cast<CVehicleModelInfo *> (model);
if (!vehicleModelInfo) return;

switch (vehicleModelInfo->m_nVehicleType)
{
case VEHICLE_BIKE:
{
CBike *bike = (CBike *) vehicle;
if (IsValidTime (bike->m_fBurningTimer))
{
bike->m_fBurningTimer = value;
}
break;
}
case VEHICLE_AUTOMOBILE:
case VEHICLE_MTRUCK:
case VEHICLE_QUAD:
case VEHICLE_TRAILER:
{
CAutomobile *automobile = (CAutomobile *) vehicle;
if (IsValidTime (automobile->m_fBurningTimer))
{
automobile->m_fBurningTimer = value;
}
break;
}
case VEHICLE_BOAT:
{
CBoat *boat = (CBoat *) vehicle;
if (IsValidTime (boat->m_fBurningTimer))
{
boat->m_fBurningTimer = value;
}
break;
}
}

if (vehicle->m_pTrailer && IsVehiclePointerValid (vehicle->m_pTrailer))
{
SetBurnTimer (vehicle->m_pTrailer, value);
}
}

static bool
IsValidTime (float time)
{
return time >= 0.0f && time < BURN_TIMER;
}
};

DEFINE_EFFECT (CarsExplodeOnFireEffect, "effect_cars_explode_on_fire", 0);