summaryrefslogtreecommitdiffstats
path: root/src/vehicles/Vehicle.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/vehicles/Vehicle.cpp195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index 6ea0e61e..c541bae5 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -1,7 +1,9 @@
#include "common.h"
#include "main.h"
#include "patcher.h"
+#include "General.h"
#include "Timer.h"
+#include "Pad.h"
#include "Vehicle.h"
#include "Pools.h"
#include "HandlingMgr.h"
@@ -13,6 +15,7 @@
#include "PointLights.h"
#include "Renderer.h"
#include "DMAudio.h"
+#include "MusicManager.h"
#include "Radar.h"
bool &CVehicle::bWheelsOnlyCheat = *(bool *)0x95CD78;
@@ -27,6 +30,79 @@ void *CVehicle::operator new(size_t sz, int handle) { return CPools::GetVehicleP
void CVehicle::operator delete(void *p, size_t sz) { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
void CVehicle::operator delete(void *p, int handle) { CPools::GetVehiclePool()->Delete((CVehicle*)p); }
+CVehicle::CVehicle(uint8 CreatedBy)
+{
+ int i;
+
+ m_nCurrentGear = 0;
+ field_208 = 0;
+ m_fSteerRatio = 0.0f;
+ m_type = ENTITY_TYPE_VEHICLE;
+ VehicleCreatedBy = CreatedBy;
+ bIsLocked = false;
+ bIsLawEnforcer = false;
+ bIsAmbulanceOnDuty = false;
+ bIsFireTruckOnDuty = false;
+ CCarCtrl::UpdateCarCount(this, false);
+ m_fHealth = 1000.0f;
+ bEngineOn = true;
+ bFreebies = true;
+ pDriver = nil;
+ m_nNumPassengers = 0;
+ m_nNumGettingIn = 0;
+ m_nGettingInFlags = 0;
+ m_nGettingOutFlags = 0;
+ m_nNumMaxPassengers = 8;
+ for(i = 0; i < m_nNumMaxPassengers; i++)
+ pPassengers[i] = nil;
+ m_nBombTimer = 0;
+ m_pWhoSetMeOnFire = nil;
+ field_1FB = 0;
+ m_veh_flagB10 = false;
+ m_veh_flagB40 = false;
+ m_veh_flagB80 = false;
+ m_veh_flagC1 = false;
+ bIsDamaged = false;
+ m_veh_flagC8 = false;
+ m_veh_flagC10 = false;
+ m_veh_flagC4 = false;
+ m_veh_flagC20 = false;
+ bCanBeDamaged = true;
+ m_veh_flagC80 = false;
+ m_veh_flagD1 = false;
+ m_veh_flagD2 = false;
+ m_nGunFiringTime = 0;
+ field_214 = 0;
+ bLightsOn = false;
+ bVehicleColProcessed = false;
+ field_1F9 = 0;
+ bIsCarParkVehicle = false;
+ bHasAlreadyBeenRecorded = false;
+ m_bSirenOrAlarm = 0;
+ m_nCarHornTimer = 0;
+ field_22D = 0;
+ m_nAlarmState = 0;
+ m_nDoorLock = CARLOCK_UNLOCKED;
+ m_nLastWeaponDamage = -1;
+ field_220 = 0.0;
+ field_21C = field_220;
+ m_audioEntityId = DMAudio.CreateEntity(0, this);
+ if(m_audioEntityId)
+ DMAudio.SetEntityStatus(m_audioEntityId, true);
+ m_nRadioStation = CGeneral::GetRandomNumber() % USERTRACK;
+ m_pCurGroundEntity = nil;
+ field_22A = 0;
+ field_22B = 0;
+ field_22F = 0;
+ m_aCollPolys[0].valid = false;
+ m_aCollPolys[1].valid = false;
+ m_autoPilot.m_nCarMission = MISSION_NONE;
+ m_autoPilot.m_nAnimationId = TEMPACT_NONE;
+ m_autoPilot.m_nTimeToStartMission = CTimer::GetTimeInMilliseconds();
+ m_autoPilot.m_flag4 = false;
+ m_autoPilot.m_flag10 = false;
+}
+
CVehicle::~CVehicle()
{
m_nAlarmState = 0;
@@ -55,6 +131,67 @@ CVehicle::~CVehicle()
}
void
+CVehicle::FlyingControl(eFlightModel flightModel)
+{
+ switch(flightModel){
+ case FLIGHT_MODEL_DODO:
+ {
+ // This seems pretty magic
+
+ // Move Left/Right
+ float moveSpeed = m_vecMoveSpeed.Magnitude();
+ float sideSpeed = DotProduct(m_vecMoveSpeed, GetRight());
+ float sideImpulse = -1.0f * sideSpeed / moveSpeed;
+ float fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward());
+ float magic = m_vecMoveSpeed.MagnitudeSqr() * sq(fwdSpeed);
+ float turnImpulse = (sideImpulse*0.003f + m_fSteerAngle*0.001f) *
+ magic*m_fTurnMass*CTimer::GetTimeStep();
+ ApplyTurnForce(turnImpulse*GetRight(), -4.0f*GetForward());
+
+ float impulse = sideImpulse*0.2f *
+ magic*m_fMass*CTimer::GetTimeStep();
+ ApplyMoveForce(impulse*GetRight());
+ ApplyTurnForce(impulse*GetRight(), 2.0f*GetUp());
+
+
+ // Move Up/Down
+ moveSpeed = m_vecMoveSpeed.Magnitude();
+ float upSpeed = DotProduct(m_vecMoveSpeed, GetUp());
+ float upImpulse = -1.0f * upSpeed / moveSpeed;
+ turnImpulse = (upImpulse*0.002f + -CPad::GetPad(0)->GetSteeringUpDown()/128.0f*0.001f) *
+ magic*m_fTurnMass*CTimer::GetTimeStep();
+ ApplyTurnForce(turnImpulse*GetUp(), -4.0f*GetForward());
+
+ impulse = (upImpulse*3.5f + 0.5f)*0.05f *
+ magic*m_fMass*CTimer::GetTimeStep();
+ if(GRAVITY*m_fMass*CTimer::GetTimeStep() < impulse &&
+ GetPosition().z > 100.0f)
+ impulse = 0.9f*GRAVITY*m_fMass*CTimer::GetTimeStep();
+ CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass);
+ ApplyMoveForce(impulse*GetUp());
+ ApplyTurnForce(impulse*GetUp(), 2.0f*GetUp() + com);
+
+
+ m_vecTurnSpeed.y *= powf(0.9f, CTimer::GetTimeStep());
+ moveSpeed = m_vecMoveSpeed.MagnitudeSqr();
+ if(moveSpeed > 2.25f)
+ m_vecMoveSpeed *= 1.5f/sqrt(moveSpeed);
+
+ float turnSpeed = m_vecTurnSpeed.MagnitudeSqr();
+ if(turnSpeed > 0.04f)
+ m_vecTurnSpeed *= 0.2f/sqrt(turnSpeed);
+ }
+ break;
+
+ case FLIGHT_MODEL_RCPLANE:
+ case FLIGHT_MODEL_SEAPLANE:
+ assert(0 && "Plane flight model not implemented");
+ case FLIGHT_MODEL_HELI:
+ assert(0 && "Heli flight model not implemented");
+ }
+}
+
+void
CVehicle::SetModelIndex(uint32 id)
{
CEntity::SetModelIndex(id);
@@ -96,6 +233,60 @@ CVehicle::GetHeightAboveRoad(void)
}
+void
+CVehicle::ExtinguishCarFire(void)
+{
+ m_fHealth = max(m_fHealth, 300.0f);
+ if(m_pCarFire)
+ m_pCarFire->Extinguish();
+ if(IsCar()){
+ CAutomobile *car = (CAutomobile*)this;
+ if(car->Damage.GetEngineStatus() >= 225)
+ car->Damage.SetEngineStatus(215);
+ car->field_530 = 0.0f;
+ }
+}
+
+void
+CVehicle::ProcessDelayedExplosion(void)
+{
+ if(m_nBombTimer == 0)
+ return;
+
+ if(m_nBombTimer == 0){
+ int tick = CTimer::GetTimeStep()/60.0f*1000.0f;
+ if(tick > m_nBombTimer)
+ m_nBombTimer = 0;
+ else
+ m_nBombTimer -= tick;
+
+ if(IsCar() && ((CAutomobile*)this)->m_auto_flagA7 == 4 && (m_nBombTimer & 0xFE00) != 0xFE00)
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_BOMB_TICK, 0.0f);
+
+ if(FindPlayerVehicle() != this && m_pWhoSetMeOnFire == FindPlayerPed())
+ CWorld::Players[CWorld::PlayerInFocus].AwardMoneyForExplosion(this);
+ BlowUpCar(m_pWhoSetMeOnFire);
+ }
+}
+
+float
+CVehicle::ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVector &speed, float radius)
+{
+ float angularVelocity;
+ switch(state){
+ case WHEEL_STATE_1:
+ angularVelocity = -1.1f; // constant speed forward
+ break;
+ case WHEEL_STATE_3:
+ angularVelocity = 0.0f; // not moving
+ break;
+ default:
+ angularVelocity = -DotProduct(fwd, speed) / radius; // forward speed
+ break;
+ }
+ return angularVelocity * CTimer::GetTimeStep();
+}
+
bool
CVehicle::IsLawEnforcementVehicle(void)
{
@@ -477,6 +668,10 @@ STARTPATCHES
InjectHook(0x4A7E60, &CVehicle_::RemoveLighting_, PATCH_JUMP);
InjectHook(0x417E60, &CVehicle_::GetHeightAboveRoad_, PATCH_JUMP);
+ InjectHook(0x552BB0, &CVehicle::FlyingControl, PATCH_JUMP);
+ InjectHook(0x552AF0, &CVehicle::ExtinguishCarFire, PATCH_JUMP);
+ InjectHook(0x551C90, &CVehicle::ProcessDelayedExplosion, PATCH_JUMP);
+ InjectHook(0x551280, &CVehicle::ProcessWheelRotation, PATCH_JUMP);
InjectHook(0x552880, &CVehicle::IsLawEnforcementVehicle, PATCH_JUMP);
InjectHook(0x552820, &CVehicle::ChangeLawEnforcerState, PATCH_JUMP);
InjectHook(0x552200, &CVehicle::UsesSiren, PATCH_JUMP);