summaryrefslogtreecommitdiffstats
path: root/src/vehicles
diff options
context:
space:
mode:
authorFire_Head <Fire-Head@users.noreply.github.com>2019-07-11 02:48:36 +0200
committerGitHub <noreply@github.com>2019-07-11 02:48:36 +0200
commitaa449b6fe162d8960351c5fe164a9120b8572652 (patch)
treefa82496d356ac2b77ffa1ab00684b0150907f009 /src/vehicles
parentfixfixfix (diff)
parentMerge pull request #129 from erorcun/erorcun (diff)
downloadre3-aa449b6fe162d8960351c5fe164a9120b8572652.tar
re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.gz
re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.bz2
re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.lz
re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.xz
re3-aa449b6fe162d8960351c5fe164a9120b8572652.tar.zst
re3-aa449b6fe162d8960351c5fe164a9120b8572652.zip
Diffstat (limited to 'src/vehicles')
-rw-r--r--src/vehicles/Automobile.cpp1150
-rw-r--r--src/vehicles/Automobile.h94
-rw-r--r--src/vehicles/Boat.cpp10
-rw-r--r--src/vehicles/Boat.h1
-rw-r--r--src/vehicles/DamageManager.cpp1
-rw-r--r--src/vehicles/DamageManager.h40
-rw-r--r--src/vehicles/Door.cpp126
-rw-r--r--src/vehicles/Door.h36
-rw-r--r--src/vehicles/HandlingMgr.h2
-rw-r--r--src/vehicles/Heli.cpp8
-rw-r--r--src/vehicles/Heli.h1
-rw-r--r--src/vehicles/Plane.cpp10
-rw-r--r--src/vehicles/Plane.h1
-rw-r--r--src/vehicles/Train.cpp10
-rw-r--r--src/vehicles/Train.h1
-rw-r--r--src/vehicles/Vehicle.cpp336
-rw-r--r--src/vehicles/Vehicle.h107
17 files changed, 1844 insertions, 90 deletions
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp
index 54eed17a..7d3f8ee3 100644
--- a/src/vehicles/Automobile.cpp
+++ b/src/vehicles/Automobile.cpp
@@ -1,18 +1,1152 @@
#include "common.h"
#include "patcher.h"
+#include "General.h"
+#include "ModelIndices.h"
+#include "VisibilityPlugins.h"
+#include "DMAudio.h"
+#include "Camera.h"
+#include "Darkel.h"
+#include "Fire.h"
+#include "Explosion.h"
+#include "World.h"
+#include "SurfaceTable.h"
+#include "HandlingMgr.h"
+#include "CarCtrl.h"
+#include "PathFind.h"
+#include "Ped.h"
+#include "PlayerPed.h"
+#include "Object.h"
#include "Automobile.h"
-CAutomobile::CAutomobile(int mi, uint8 owner)
+RwObject *GetCurrentAtomicObjectCB(RwObject *object, void *data);
+
+bool &CAutomobile::m_sAllTaxiLights = *(bool*)0x95CD21;
+
+WRAPPER CAutomobile* CAutomobile::ctor(int, uint8) { EAXJMP(0x52C6B0); }
+
+CAutomobile::CAutomobile(int mi, uint8 CreatedBy)
{
- ctor(mi, owner);
+ ctor(mi, CreatedBy);
}
-WRAPPER CAutomobile* CAutomobile::ctor(int, uint8) { EAXJMP(0x52C6B0); }
-WRAPPER void CAutomobile::SetDoorDamage(int32, uint32, bool) { EAXJMP(0x530200); }
-WRAPPER void CAutomobile::SetPanelDamage(int32, uint32, bool) { EAXJMP(0x5301A0); }
-WRAPPER void CAutomobile::SetBumperDamage(int32, uint32, bool) { EAXJMP(0x530120); }
+void
+CAutomobile::SetModelIndex(uint32 id)
+{
+ CVehicle::SetModelIndex(id);
+ SetupModelNodes();
+}
+
+WRAPPER void CAutomobile::ProcessControl(void) { EAXJMP(0x531470); }
+
+void
+CAutomobile::Teleport(CVector pos)
+{
+ CWorld::Remove(this);
+
+ GetPosition() = pos;
+ SetOrientation(0.0f, 0.0f, 0.0f);
+ SetMoveSpeed(0.0f, 0.0f, 0.0f);
+ SetTurnSpeed(0.0f, 0.0f, 0.0f);
+
+ ResetSuspension();
+
+ CWorld::Add(this);
+}
+
+WRAPPER void CAutomobile::PreRender(void) { EAXJMP(0x535B40); }
+WRAPPER void CAutomobile::Render(void) { EAXJMP(0x539EA0); }
+
+
+int32
+CAutomobile::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
+{
+ int i;
+ CColModel *colModel;
+
+ if(m_status != STATUS_SIMPLE)
+ bVehicleColProcessed = true;
+
+ if(m_veh_flagC80)
+ colModel = &CWorld::Players[CWorld::PlayerInFocus].m_ColModel;
+ else
+ colModel = GetColModel();
+
+ int numWheelCollisions = 0;
+ float prevRatios[4] = { 0.0f, 0.0f, 0.0f, 0.0f};
+ for(i = 0; i < 4; i++)
+ prevRatios[i] = m_aSuspensionSpringRatio[i];
+
+ int numCollisions = CCollision::ProcessColModels(GetMatrix(), *colModel,
+ ent->GetMatrix(), *ent->GetColModel(),
+ colpoints,
+ m_aWheelColPoints, m_aSuspensionSpringRatio);
+
+ // m_aSuspensionSpringRatio are now set to the point where the tyre touches ground.
+ // In ProcessControl these will be re-normalized to ignore the tyre radius.
+
+ if(field_EF || m_phy_flagA80 ||
+ GetModelIndex() == MI_DODO && (ent->m_status == STATUS_PHYSICS || ent->m_status == STATUS_SIMPLE)){
+ // don't do line collision
+ for(i = 0; i < 4; i++)
+ m_aSuspensionSpringRatio[i] = prevRatios[i];
+ }else{
+ for(i = 0; i < 4; i++)
+ if(m_aSuspensionSpringRatio[i] < 1.0f && m_aSuspensionSpringRatio[i] < prevRatios[i]){
+ numWheelCollisions++;
+
+ // wheel is touching a physical
+ if(ent->IsVehicle() || ent->IsObject()){
+ CPhysical *phys = (CPhysical*)ent;
+
+ m_aGroundPhysical[i] = phys;
+ phys->RegisterReference((CEntity**)&m_aGroundPhysical[i]);
+ m_aGroundOffset[i] = m_aWheelColPoints[i].point - phys->GetPosition();
+
+ if(phys->GetModelIndex() == MI_BODYCAST && m_status == STATUS_PLAYER){
+ // damage body cast
+ float speed = m_vecMoveSpeed.MagnitudeSqr();
+ if(speed > 0.1f){
+ CObject::nBodyCastHealth -= 0.1f*m_fMass*speed;
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_PED_BODYCAST_HIT, 0.0f);
+ }
+
+ // move body cast
+ if(phys->bIsStatic){
+ phys->bIsStatic = false;
+ phys->m_nStaticFrames = 0;
+ phys->ApplyMoveForce(m_vecMoveSpeed / speed);
+ phys->AddToMovingList();
+ }
+ }
+ }
+
+ m_nSurfaceTouched = m_aWheelColPoints[i].surfaceB;
+ if(ent->IsBuilding())
+ m_pCurGroundEntity = ent;
+ }
+ }
+
+ if(numCollisions > 0 || numWheelCollisions > 0){
+ AddCollisionRecord(ent);
+ if(!ent->IsBuilding())
+ ((CPhysical*)ent)->AddCollisionRecord(this);
+
+ if(numCollisions > 0)
+ if(ent->IsBuilding() ||
+ ent->IsObject() && ((CPhysical*)ent)->bInfiniteMass)
+ bHasHitWall = true;
+ }
+
+ return numCollisions;
+}
+
+
+WRAPPER void CAutomobile::ProcessControlInputs(uint8) { EAXJMP(0x53B660); }
+
+void
+CAutomobile::GetComponentWorldPosition(int32 component, CVector &pos)
+{
+ if(m_aCarNodes[component] == nil){
+ printf("CarNode missing: %d %d\n", GetModelIndex(), component);
+ return;
+ }
+ RwMatrix *ltm = RwFrameGetLTM(m_aCarNodes[component]);
+ pos = *RwMatrixGetPos(ltm);
+}
+
+bool
+CAutomobile::IsComponentPresent(int32 comp)
+{
+ return m_aCarNodes[comp] != nil;
+}
+
+void
+CAutomobile::SetComponentRotation(int32 component, CVector rotation)
+{
+ CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component]));
+ CVector pos = mat.GetPosition();
+ // BUG: all these set the whole matrix
+ mat.SetRotateX(DEGTORAD(rotation.x));
+ mat.SetRotateY(DEGTORAD(rotation.y));
+ mat.SetRotateZ(DEGTORAD(rotation.z));
+ mat.Translate(pos);
+ mat.UpdateRW();
+}
+
+void
+CAutomobile::OpenDoor(int32 component, eDoors door, float openRatio)
+{
+ CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component]));
+ CVector pos = mat.GetPosition();
+ float axes[3] = { 0.0f, 0.0f, 0.0f };
+ float wasClosed = false;
+
+ if(Doors[door].IsClosed()){
+ // enable angle cull for closed doors
+ RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::ClearAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL);
+ wasClosed = true;
+ }
+
+ Doors[door].Open(openRatio);
+
+ if(wasClosed && Doors[door].RetAngleWhenClosed() != Doors[door].m_fAngle){
+ // door opened
+ HideAllComps();
+ // turn off angle cull for swinging door
+ RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::SetAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL);
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_DOOR_OPEN_BONNET + door, 0.0f);
+ }
+
+ if(!wasClosed && openRatio == 0.0f){
+ // door closed
+ if(Damage.GetDoorStatus(door) == DOOR_STATUS_SWINGING)
+ Damage.SetDoorStatus(door, DOOR_STATUS_OK); // huh?
+ ShowAllComps();
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_DOOR_CLOSE_BONNET + door, 0.0f);
+ }
+
+ axes[Doors[door].m_nAxis] = Doors[door].m_fAngle;
+ mat.SetRotate(axes[0], axes[1], axes[2]);
+ mat.Translate(pos);
+ mat.UpdateRW();
+}
+
+inline void ProcessDoorOpenAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float end)
+{
+ if(time > start && time < end){
+ float ratio = (time - start)/(end - start);
+ if(car->Doors[door].GetAngleOpenRatio() < ratio)
+ car->OpenDoor(component, door, ratio);
+ }else if(time > end){
+ car->OpenDoor(component, door, 1.0f);
+ }
+}
+
+inline void ProcessDoorCloseAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float end)
+{
+ if(time > start && time < end){
+ float ratio = 1.0f - (time - start)/(end - start);
+ if(car->Doors[door].GetAngleOpenRatio() > ratio)
+ car->OpenDoor(component, door, ratio);
+ }else if(time > end){
+ car->OpenDoor(component, door, 0.0f);
+ }
+}
+
+inline void ProcessDoorOpenCloseAnimation(CAutomobile *car, uint32 component, eDoors door, float time, float start, float mid, float end)
+{
+ if(time > start && time < mid){
+ // open
+ float ratio = (time - start)/(mid - start);
+ if(car->Doors[door].GetAngleOpenRatio() < ratio)
+ car->OpenDoor(component, door, ratio);
+ }else if(time > mid && time < end){
+ // close
+ float ratio = 1.0f - (time - mid)/(end - mid);
+ if(car->Doors[door].GetAngleOpenRatio() > ratio)
+ car->OpenDoor(component, door, ratio);
+ }else if(time > end){
+ car->OpenDoor(component, door, 0.0f);
+ }
+}
+void
+CAutomobile::ProcessOpenDoor(uint32 component, uint32 anim, float time)
+{
+ eDoors door;
+
+ switch(component){
+ case CAR_DOOR_RF: door = DOOR_FRONT_RIGHT; break;
+ case CAR_DOOR_RR: door = DOOR_REAR_RIGHT; break;
+ case CAR_DOOR_LF: door = DOOR_FRONT_LEFT; break;
+ case CAR_DOOR_LR: door = DOOR_REAR_LEFT; break;
+ default: assert(0);
+ }
+
+ if(IsDoorMissing(door))
+ return;
+
+ switch(anim){
+ case ANIM_CAR_QJACK:
+ case ANIM_CAR_OPEN_LHS:
+ case ANIM_CAR_OPEN_RHS:
+ ProcessDoorOpenAnimation(this, component, door, time, 0.66f, 0.8f);
+ break;
+ case ANIM_CAR_CLOSEDOOR_LHS:
+ case ANIM_CAR_CLOSEDOOR_LOW_LHS:
+ case ANIM_CAR_CLOSEDOOR_RHS:
+ case ANIM_CAR_CLOSEDOOR_LOW_RHS:
+ ProcessDoorCloseAnimation(this, component, door, time, 0.2f, 0.63f);
+ break;
+ case ANIM_CAR_ROLLDOOR:
+ case ANIM_CAR_ROLLDOOR_LOW:
+ ProcessDoorOpenCloseAnimation(this, component, door, time, 0.1f, 0.6f, 0.95f);
+ break;
+ break;
+ case ANIM_CAR_GETOUT_LHS:
+ case ANIM_CAR_GETOUT_LOW_LHS:
+ case ANIM_CAR_GETOUT_RHS:
+ case ANIM_CAR_GETOUT_LOW_RHS:
+ ProcessDoorOpenAnimation(this, component, door, time, 0.06f, 0.43f);
+ break;
+ case ANIM_CAR_CLOSE_LHS:
+ case ANIM_CAR_CLOSE_RHS:
+ ProcessDoorCloseAnimation(this, component, door, time, 0.1f, 0.23f);
+ break;
+ case ANIM_CAR_PULLOUT_RHS:
+ case ANIM_CAR_PULLOUT_LOW_RHS:
+ OpenDoor(component, door, 1.0f);
+ case ANIM_COACH_OPEN_L:
+ case ANIM_COACH_OPEN_R:
+ ProcessDoorOpenAnimation(this, component, door, time, 0.66f, 0.8f);
+ break;
+ case ANIM_COACH_OUT_L:
+ ProcessDoorOpenAnimation(this, component, door, time, 0.0f, 0.3f);
+ break;
+ case ANIM_VAN_OPEN_L:
+ case ANIM_VAN_OPEN:
+ ProcessDoorOpenAnimation(this, component, door, time, 0.37f, 0.55f);
+ break;
+ case ANIM_VAN_CLOSE_L:
+ case ANIM_VAN_CLOSE:
+ ProcessDoorCloseAnimation(this, component, door, time, 0.5f, 0.8f);
+ break;
+ case ANIM_VAN_GETOUT_L:
+ case ANIM_VAN_GETOUT:
+ ProcessDoorOpenAnimation(this, component, door, time, 0.5f, 0.6f);
+ break;
+ case NUM_ANIMS:
+ OpenDoor(component, door, time);
+ break;
+ }
+}
+
+bool
+CAutomobile::IsDoorReady(eDoors door)
+{
+ if(Doors[door].IsClosed() || IsDoorMissing(door))
+ return true;
+ int doorflag = 0;
+ // TODO: enum?
+ switch(door){
+ case DOOR_FRONT_LEFT: doorflag = 1; break;
+ case DOOR_FRONT_RIGHT: doorflag = 4; break;
+ case DOOR_REAR_LEFT: doorflag = 2; break;
+ case DOOR_REAR_RIGHT: doorflag = 8; break;
+ }
+ return (doorflag & m_nGettingInFlags) == 0;
+}
+
+bool
+CAutomobile::IsDoorFullyOpen(eDoors door)
+{
+ return Doors[door].IsFullyOpen() || IsDoorMissing(door);
+}
+
+bool
+CAutomobile::IsDoorClosed(eDoors door)
+{
+ return !!Doors[door].IsClosed();
+}
+
+bool
+CAutomobile::IsDoorMissing(eDoors door)
+{
+ return Damage.GetDoorStatus(door) == DOOR_STATUS_MISSING;
+}
+
+void
+CAutomobile::RemoveRefsToVehicle(CEntity *ent)
+{
+ int i;
+ for(i = 0; i < 4; i++)
+ if(m_aGroundPhysical[i] == ent)
+ m_aGroundPhysical[i] = nil;
+}
+
+void
+CAutomobile::BlowUpCar(CEntity *culprit)
+{
+ int i;
+ RpAtomic *atomic;
+
+ if(!bCanBeDamaged)
+ return;
+
+ // explosion pushes vehicle up
+ m_vecMoveSpeed.z += 0.13f;
+ m_status = STATUS_WRECKED;
+ bRenderScorched = true;
+ m_nTimeOfDeath = CTimer::GetTimeInMilliseconds();
+ Damage.FuckCarCompletely();
+
+ if(GetModelIndex() != MI_RCBANDIT){
+ SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT);
+ SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR);
+ SetDoorDamage(CAR_BONNET, DOOR_BONNET);
+ SetDoorDamage(CAR_BOOT, DOOR_BOOT);
+ SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT);
+ SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT);
+ SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT);
+ SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT);
+ SpawnFlyingComponent(CAR_WHEEL_LF, COMPGROUP_WHEEL);
+ RwFrameForAllObjects(m_aCarNodes[CAR_WHEEL_LF], GetCurrentAtomicObjectCB, &atomic);
+ if(atomic)
+ RpAtomicSetFlags(atomic, 0);
+ }
+
+ m_fHealth = 0.0f;
+ m_nBombTimer = 0;
+ m_auto_flagA7 = 0;
+
+ TheCamera.CamShake(0.7f, GetPosition().x, GetPosition().y, GetPosition().z);
+
+ // kill driver and passengers
+ if(pDriver){
+ CDarkel::RegisterKillByPlayer(pDriver, WEAPONTYPE_EXPLOSION);
+ if(pDriver->GetPedState() == PED_DRIVING){
+ pDriver->SetDead();
+ if(!pDriver->IsPlayer())
+ pDriver->FlagToDestroyWhenNextProcessed();
+ }else
+ pDriver->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f);
+ }
+ for(i = 0; i < m_nNumMaxPassengers; i++){
+ if(pPassengers[i]){
+ CDarkel::RegisterKillByPlayer(pPassengers[i], WEAPONTYPE_EXPLOSION);
+ if(pPassengers[i]->GetPedState() == PED_DRIVING){
+ pPassengers[i]->SetDead();
+ if(!pPassengers[i]->IsPlayer())
+ pPassengers[i]->FlagToDestroyWhenNextProcessed();
+ }else
+ pPassengers[i]->SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f);
+ }
+ }
+
+ bEngineOn = false;
+ bLightsOn = false;
+ m_bSirenOrAlarm = false;
+ bTaxiLight = false;
+ if(bIsAmbulanceOnDuty){
+ bIsAmbulanceOnDuty = false;
+ CCarCtrl::NumAmbulancesOnDuty--;
+ }
+ if(bIsFireTruckOnDuty){
+ bIsFireTruckOnDuty = false;
+ CCarCtrl::NumFiretrucksOnDuty--;
+ }
+ ChangeLawEnforcerState(false);
+
+ gFireManager.StartFire(this, culprit, 0.8f, 1); // TODO
+ CDarkel::RegisterCarBlownUpByPlayer(this);
+ if(GetModelIndex() == MI_RCBANDIT)
+ CExplosion::AddExplosion(this, culprit, EXPLOSION_4, GetPosition(), 0); // TODO
+ else
+ CExplosion::AddExplosion(this, culprit, EXPLOSION_3, GetPosition(), 0); // TODO
+}
+
+bool
+CAutomobile::SetUpWheelColModel(CColModel *colModel)
+{
+ CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex());
+ CColModel *vehColModel = mi->GetColModel();
+
+ colModel->boundingSphere = vehColModel->boundingSphere;
+ colModel->boundingBox = vehColModel->boundingBox;
+
+ CMatrix mat;
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF]));
+ colModel->spheres[0].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LF);
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB]));
+ colModel->spheres[1].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LR);
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF]));
+ colModel->spheres[2].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF);
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB]));
+ colModel->spheres[3].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR);
+
+ if(m_aCarNodes[CAR_WHEEL_LM] != nil && m_aCarNodes[CAR_WHEEL_RM] != nil){
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM]));
+ colModel->spheres[4].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF);
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM]));
+ colModel->spheres[5].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR);
+ colModel->numSpheres = 6;
+ }else
+ colModel->numSpheres = 4;
+
+ return true;
+}
+
+// this probably isn't used in III yet
+void
+CAutomobile::BurstTyre(uint8 wheel)
+{
+ switch(wheel){
+ case CAR_PIECE_WHEEL_LF: wheel = VEHWHEEL_FRONT_LEFT; break;
+ case CAR_PIECE_WHEEL_LR: wheel = VEHWHEEL_REAR_LEFT; break;
+ case CAR_PIECE_WHEEL_RF: wheel = VEHWHEEL_FRONT_RIGHT; break;
+ case CAR_PIECE_WHEEL_RR: wheel = VEHWHEEL_REAR_RIGHT; break;
+ }
+
+ int status = Damage.GetWheelStatus(wheel);
+ if(status == WHEEL_STATUS_OK){
+ Damage.SetWheelStatus(wheel, WHEEL_STATUS_BURST);
+
+ if(m_status == STATUS_SIMPLE){
+ m_status = STATUS_PHYSICS;
+ CCarCtrl::SwitchVehicleToRealPhysics(this);
+ }
+
+ ApplyMoveForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f));
+ ApplyTurnForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f), GetForward());
+ }
+}
+
+WRAPPER bool CAutomobile::IsRoomForPedToLeaveCar(uint32, CVector *) { EAXJMP(0x53C5B0); }
+
+float
+CAutomobile::GetHeightAboveRoad(void)
+{
+ return m_fHeightAboveRoad;
+}
+
+void
+CAutomobile::PlayCarHorn(void)
+{
+ int r;
+
+ if(m_nCarHornTimer != 0)
+ return;
+
+ r = CGeneral::GetRandomNumber() & 7;
+ if(r < 2){
+ m_nCarHornTimer = 45;
+ }else if(r < 4){
+ if(pDriver)
+ pDriver->Say(SOUND_PED_CAR_COLLISION);
+ m_nCarHornTimer = 45;
+ }else{
+ if(pDriver)
+ pDriver->Say(SOUND_PED_CAR_COLLISION);
+ }
+}
+
+void
+CAutomobile::PlayHornIfNecessary(void)
+{
+ if(m_autoPilot.m_flag2 ||
+ m_autoPilot.m_flag1)
+ if(!HasCarStoppedBecauseOfLight())
+ PlayCarHorn();
+}
+
+
+void
+CAutomobile::ResetSuspension(void)
+{
+ int i;
+ for(i = 0; i < 4; i++){
+ m_aSuspensionSpringRatio[i] = 1.0f;
+ m_aWheelSkidThing[i] = 0.0f;
+ m_aWheelRotation[i] = 0.0f;
+ m_aWheelState[i] = 0; // TODO: enum?
+ }
+}
+
+void
+CAutomobile::SetupSuspensionLines(void)
+{
+ int i;
+ CVector posn;
+ CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex());
+ CColModel *colModel = mi->GetColModel();
+
+ // Each suspension line starts at the uppermost wheel position
+ // and extends down to the lowermost point on the tyre
+ for(i = 0; i < 4; i++){
+ mi->GetWheelPosn(i, posn);
+ m_aWheelPosition[i] = posn.z;
+
+ // uppermost wheel position
+ posn.z += m_handling->fSuspensionUpperLimit;
+ colModel->lines[i].p0 = posn;
+
+ // lowermost wheel position
+ posn.z += m_handling->fSuspensionLowerLimit - m_handling->fSuspensionUpperLimit;
+ // lowest point on tyre
+ posn.z -= mi->m_wheelScale*0.5f;
+ colModel->lines[i].p1 = posn;
+
+ // this is length of the spring at rest
+ m_aSuspensionSpringLength[i] = m_handling->fSuspensionUpperLimit - m_handling->fSuspensionLowerLimit;
+ m_aSuspensionLineLength[i] = colModel->lines[i].p0.z - colModel->lines[i].p1.z;
+ }
+
+ // Compress spring somewhat to get normal height on road
+ m_fHeightAboveRoad = -(colModel->lines[0].p0.z + (colModel->lines[0].p1.z - colModel->lines[0].p0.z)*
+ (1.0f - 1.0f/(8.0f*m_handling->fSuspensionForceLevel)));
+ for(i = 0; i < 4; i++)
+ m_aWheelPosition[i] = mi->m_wheelScale*0.5f - m_fHeightAboveRoad;
+
+ // adjust col model to include suspension lines
+ if(colModel->boundingBox.min.z > colModel->lines[0].p1.z)
+ colModel->boundingBox.min.z = colModel->lines[0].p1.z;
+ float radius = max(colModel->boundingBox.min.Magnitude(), colModel->boundingBox.max.Magnitude());
+ if(colModel->boundingSphere.radius < radius)
+ colModel->boundingSphere.radius = radius;
+
+ if(GetModelIndex() == MI_RCBANDIT){
+ colModel->boundingSphere.radius = 2.0f;
+ for(i = 0; i < colModel->numSpheres; i++)
+ colModel->spheres[i].radius = 0.3f;
+ }
+}
+
+// called on police cars
+void
+CAutomobile::ScanForCrimes(void)
+{
+ if(FindPlayerVehicle() && FindPlayerVehicle()->IsCar())
+ if(FindPlayerVehicle()->m_nAlarmState != -1)
+ // if player's alarm is on, increase wanted level
+ if((FindPlayerVehicle()->GetPosition() - GetPosition()).MagnitudeSqr() < sq(20.0f))
+ CWorld::Players[CWorld::PlayerInFocus].m_pPed->SetWantedLevelNoDrop(1);
+}
+
+void
+CAutomobile::BlowUpCarsInPath(void)
+{
+ int i;
+
+ if(m_vecMoveSpeed.Magnitude() > 0.1f)
+ for(i = 0; i < m_nCollisionRecords; i++)
+ if(m_aCollisionRecords[i] &&
+ m_aCollisionRecords[i]->IsVehicle() &&
+ m_aCollisionRecords[i]->GetModelIndex() != MI_RHINO &&
+ !m_aCollisionRecords[i]->bRenderScorched)
+ ((CVehicle*)m_aCollisionRecords[i])->BlowUpCar(this);
+}
+
+bool
+CAutomobile::HasCarStoppedBecauseOfLight(void)
+{
+ int i;
+
+ if(m_status != STATUS_SIMPLE && m_status != STATUS_PHYSICS)
+ return false;
+
+ if(m_autoPilot.m_nCurrentRouteNode && m_autoPilot.m_nNextRouteNode){
+ CPathNode *curnode = &ThePaths.m_pathNodes[m_autoPilot.m_nCurrentRouteNode];
+ for(i = 0; i < curnode->numLinks; i++)
+ if(ThePaths.m_connections[curnode->firstLink + i] == m_autoPilot.m_nNextRouteNode)
+ break;
+ if(i < curnode->numLinks &&
+ ThePaths.m_carPathLinks[ThePaths.m_carPathConnections[curnode->firstLink + i]].trafficLightType & 3) // TODO
+ return true;
+ }
+
+ if(m_autoPilot.m_nCurrentRouteNode && m_autoPilot.m_nPrevRouteNode){
+ CPathNode *curnode = &ThePaths.m_pathNodes[m_autoPilot.m_nCurrentRouteNode];
+ for(i = 0; i < curnode->numLinks; i++)
+ if(ThePaths.m_connections[curnode->firstLink + i] == m_autoPilot.m_nPrevRouteNode)
+ break;
+ if(i < curnode->numLinks &&
+ ThePaths.m_carPathLinks[ThePaths.m_carPathConnections[curnode->firstLink + i]].trafficLightType & 3) // TODO
+ return true;
+ }
+
+ return false;
+}
+
+void
+CAutomobile::SetBusDoorTimer(uint32 timer, uint8 type)
+{
+ if(timer < 1000)
+ timer = 1000;
+ if(type == 0)
+ // open and close
+ m_nBusDoorTimerStart = CTimer::GetTimeInMilliseconds();
+ else
+ // only close
+ m_nBusDoorTimerStart = CTimer::GetTimeInMilliseconds() - 500;
+ m_nBusDoorTimerEnd = m_nBusDoorTimerStart + timer;
+}
+
+void
+CAutomobile::ProcessAutoBusDoors(void)
+{
+ if(CTimer::GetTimeInMilliseconds() < m_nBusDoorTimerEnd){
+ if(m_nBusDoorTimerEnd != 0 && CTimer::GetTimeInMilliseconds() > m_nBusDoorTimerEnd-500){
+ // close door
+ if(!IsDoorMissing(DOOR_FRONT_LEFT) && (m_nGettingInFlags & 1) == 0){
+ if(IsDoorClosed(DOOR_FRONT_LEFT)){
+ m_nBusDoorTimerEnd = CTimer::GetTimeInMilliseconds();
+ OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, 0.0f);
+ }else{
+ OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT,
+ 1.0f - (CTimer::GetTimeInMilliseconds() - (m_nBusDoorTimerEnd-500))/500.0f);
+ }
+ }
+
+ if(!IsDoorMissing(DOOR_FRONT_RIGHT) && (m_nGettingInFlags & 4) == 0){
+ if(IsDoorClosed(DOOR_FRONT_RIGHT)){
+ m_nBusDoorTimerEnd = CTimer::GetTimeInMilliseconds();
+ OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, 0.0f);
+ }else{
+ OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT,
+ 1.0f - (CTimer::GetTimeInMilliseconds() - (m_nBusDoorTimerEnd-500))/500.0f);
+ }
+ }
+ }
+ }else{
+ // ended
+ if(m_nBusDoorTimerStart){
+ if(!IsDoorMissing(DOOR_FRONT_LEFT) && (m_nGettingInFlags & 1) == 0)
+ OpenDoor(CAR_DOOR_LF, DOOR_FRONT_LEFT, 0.0f);
+ if(!IsDoorMissing(DOOR_FRONT_RIGHT) && (m_nGettingInFlags & 4) == 0)
+ OpenDoor(CAR_DOOR_RF, DOOR_FRONT_RIGHT, 0.0f);
+ m_nBusDoorTimerStart = 0;
+ m_nBusDoorTimerEnd = 0;
+ }
+ }
+}
+
+void
+CAutomobile::ProcessSwingingDoor(int32 component, eDoors door)
+{
+ if(Damage.GetDoorStatus(door) != DOOR_STATUS_SWINGING)
+ return;
+
+ CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component]));
+ CVector pos = mat.GetPosition();
+ float axes[3] = { 0.0f, 0.0f, 0.0f };
+
+ Doors[door].Process(this);
+ axes[Doors[door].m_nAxis] = Doors[door].m_fAngle;
+ mat.SetRotate(axes[0], axes[1], axes[2]);
+ mat.Translate(pos);
+ mat.UpdateRW();
+}
+
+void
+CAutomobile::Fix(void)
+{
+ int component;
+
+ Damage.ResetDamageStatus();
+
+ if(m_handling->Flags & HANDLING_NO_DOORS){
+ Damage.SetDoorStatus(DOOR_FRONT_LEFT, DOOR_STATUS_MISSING);
+ Damage.SetDoorStatus(DOOR_FRONT_RIGHT, DOOR_STATUS_MISSING);
+ Damage.SetDoorStatus(DOOR_REAR_LEFT, DOOR_STATUS_MISSING);
+ Damage.SetDoorStatus(DOOR_REAR_RIGHT, DOOR_STATUS_MISSING);
+ }
+
+ bIsDamaged = false;
+ RpClumpForAllAtomics((RpClump*)m_rwObject, CVehicleModelInfo::HideAllComponentsAtomicCB, (void*)ATOMIC_FLAG_DAM);
+
+ for(component = CAR_BUMP_FRONT; component < NUM_CAR_NODES; component++){
+ if(m_aCarNodes[component]){
+ CMatrix mat(RwFrameGetMatrix(m_aCarNodes[component]));
+ mat.SetTranslate(mat.GetPosition());
+ mat.UpdateRW();
+ }
+ }
+}
+
+void
+CAutomobile::SetupDamageAfterLoad(void)
+{
+ if(m_aCarNodes[CAR_BUMP_FRONT])
+ SetBumperDamage(CAR_BUMP_FRONT, VEHBUMPER_FRONT);
+ if(m_aCarNodes[CAR_BONNET])
+ SetDoorDamage(CAR_BONNET, DOOR_BONNET);
+ if(m_aCarNodes[CAR_BUMP_REAR])
+ SetBumperDamage(CAR_BUMP_REAR, VEHBUMPER_REAR);
+ if(m_aCarNodes[CAR_BOOT])
+ SetDoorDamage(CAR_BOOT, DOOR_BOOT);
+ if(m_aCarNodes[CAR_DOOR_LF])
+ SetDoorDamage(CAR_DOOR_LF, DOOR_FRONT_LEFT);
+ if(m_aCarNodes[CAR_DOOR_RF])
+ SetDoorDamage(CAR_DOOR_RF, DOOR_FRONT_RIGHT);
+ if(m_aCarNodes[CAR_DOOR_LR])
+ SetDoorDamage(CAR_DOOR_LR, DOOR_REAR_LEFT);
+ if(m_aCarNodes[CAR_DOOR_RR])
+ SetDoorDamage(CAR_DOOR_RR, DOOR_REAR_RIGHT);
+ if(m_aCarNodes[CAR_WING_LF])
+ SetPanelDamage(CAR_WING_LF, VEHPANEL_FRONT_LEFT);
+ if(m_aCarNodes[CAR_WING_RF])
+ SetPanelDamage(CAR_WING_RF, VEHPANEL_FRONT_RIGHT);
+ if(m_aCarNodes[CAR_WING_LR])
+ SetPanelDamage(CAR_WING_LR, VEHPANEL_REAR_LEFT);
+ if(m_aCarNodes[CAR_WING_RR])
+ SetPanelDamage(CAR_WING_RR, VEHPANEL_REAR_RIGHT);
+}
+
+RwObject*
+GetCurrentAtomicObjectCB(RwObject *object, void *data)
+{
+ RpAtomic *atomic = (RpAtomic*)object;
+ assert(RwObjectGetType(object) == rpATOMIC);
+ if(RpAtomicGetFlags(atomic) & rpATOMICRENDER)
+ *(RpAtomic**)data = atomic;
+ return object;
+}
+
+CColPoint aTempPedColPts[32]; // this name doesn't make any sense
+
+CObject*
+CAutomobile::SpawnFlyingComponent(int32 component, uint32 type)
+{
+ RpAtomic *atomic;
+ RwFrame *frame;
+ RwMatrix *matrix;
+ CObject *obj;
+
+ if(CObject::nNoTempObjects >= NUMTEMPOBJECTS)
+ return nil;
+
+ atomic = nil;
+ RwFrameForAllObjects(m_aCarNodes[component], GetCurrentAtomicObjectCB, &atomic);
+ if(atomic == nil)
+ return nil;
+
+ obj = new CObject;
+ if(obj == nil)
+ return nil;
+
+ if(component == CAR_WINDSCREEN){
+ obj->SetModelIndexNoCreate(MI_CAR_BONNET);
+ }else switch(type){
+ case COMPGROUP_BUMPER:
+ obj->SetModelIndexNoCreate(MI_CAR_BUMPER);
+ break;
+ case COMPGROUP_WHEEL:
+ obj->SetModelIndexNoCreate(MI_CAR_WHEEL);
+ break;
+ case COMPGROUP_DOOR:
+ obj->SetModelIndexNoCreate(MI_CAR_DOOR);
+ obj->SetCenterOfMass(0.0f, -0.5f, 0.0f);
+ break;
+ case COMPGROUP_BONNET:
+ obj->SetModelIndexNoCreate(MI_CAR_BONNET);
+ obj->SetCenterOfMass(0.0f, 0.4f, 0.0f);
+ break;
+ case COMPGROUP_BOOT:
+ obj->SetModelIndexNoCreate(MI_CAR_BOOT);
+ obj->SetCenterOfMass(0.0f, -0.3f, 0.0f);
+ break;
+ case COMPGROUP_PANEL:
+ default:
+ obj->SetModelIndexNoCreate(MI_CAR_PANEL);
+ break;
+ }
+
+ // object needs base model
+ obj->RefModelInfo(GetModelIndex());
+
+ // create new atomic
+ matrix = RwFrameGetLTM(m_aCarNodes[component]);
+ frame = RwFrameCreate();
+ atomic = RpAtomicClone(atomic);
+ *RwFrameGetMatrix(frame) = *matrix;
+ RpAtomicSetFrame(atomic, frame);
+ CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil);
+ obj->AttachToRwObject((RwObject*)atomic);
+
+ // init object
+ obj->m_fMass = 10.0f;
+ obj->m_fTurnMass = 25.0f;
+ obj->m_fAirResistance = 0.97f;
+ obj->m_fElasticity = 0.1f;
+ obj->m_fBuoyancy = obj->m_fMass*GRAVITY/0.75f;
+ obj->ObjectCreatedBy = TEMP_OBJECT;
+ obj->bIsStatic = true;
+ obj->bIsPickup = false;
+ obj->bUseVehicleColours = true;
+ obj->m_colour1 = m_currentColour1;
+ obj->m_colour2 = m_currentColour2;
+
+ // life time - the more objects the are, the shorter this one will live
+ CObject::nNoTempObjects++;
+ if(CObject::nNoTempObjects > 20)
+ obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000/5.0f;
+ else if(CObject::nNoTempObjects > 10)
+ obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000/2.0f;
+ else
+ obj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 20000;
+
+ obj->m_vecMoveSpeed = m_vecMoveSpeed;
+ if(obj->m_vecMoveSpeed.z > 0.0f){
+ obj->m_vecMoveSpeed.z *= 1.5f;
+ }else if(GetUp().z > 0.0f &&
+ (component == COMPGROUP_BONNET || component == COMPGROUP_BOOT || component == CAR_WINDSCREEN)){
+ obj->m_vecMoveSpeed.z *= -1.5f;
+ obj->m_vecMoveSpeed.z += 0.04f;
+ }else{
+ obj->m_vecMoveSpeed.z *= 0.25f;
+ }
+ obj->m_vecMoveSpeed.x *= 0.75f;
+ obj->m_vecMoveSpeed.y *= 0.75f;
+
+ obj->m_vecTurnSpeed = m_vecTurnSpeed*2.0f;
+
+ // push component away from car
+ CVector dist = obj->GetPosition() - GetPosition();
+ dist.Normalise();
+ if(component == COMPGROUP_BONNET || component == COMPGROUP_BOOT || component == CAR_WINDSCREEN){
+ // push these up some
+ dist += GetUp();
+ if(GetUp().z > 0.0f){
+ // simulate fast upward movement if going fast
+ float speed = CVector2D(m_vecMoveSpeed).MagnitudeSqr();
+ obj->GetPosition() += GetUp()*speed;
+ }
+ }
+ obj->ApplyMoveForce(dist);
+
+ if(type == COMPGROUP_WHEEL){
+ obj->m_fTurnMass = 5.0f;
+ obj->m_vecTurnSpeed.x = 0.5f;
+ obj->m_fAirResistance = 0.99f;
+ }
+
+ if(CCollision::ProcessColModels(obj->GetMatrix(), *obj->GetColModel(),
+ this->GetMatrix(), *this->GetColModel(),
+ aTempPedColPts, nil, nil) > 0)
+ obj->m_pCollidingEntity = this;
+
+ if(bRenderScorched)
+ obj->bRenderScorched = true;
+
+ CWorld::Add(obj);
+
+ return obj;
+}
+
+CObject*
+CAutomobile::RemoveBonnetInPedCollision(void)
+{
+ CObject *obj;
+
+ if(Damage.GetDoorStatus(DOOR_BONNET) != DOOR_STATUS_SWINGING &&
+ Doors[DOOR_BONNET].RetAngleWhenOpen()*0.4f < Doors[DOOR_BONNET].m_fAngle){
+ // BUG? why not COMPGROUP_BONNET?
+ obj = SpawnFlyingComponent(CAR_BONNET, COMPGROUP_DOOR);
+ // make both doors invisible on car
+ SetComponentVisibility(m_aCarNodes[CAR_BONNET], ATOMIC_FLAG_NONE);
+ Damage.SetDoorStatus(DOOR_BONNET, DOOR_STATUS_MISSING);
+ return obj;
+ }
+ return nil;
+}
+
+void
+CAutomobile::SetPanelDamage(int32 component, ePanels panel, bool noFlyingComponents)
+{
+ int status = Damage.GetPanelStatus(panel);
+ if(m_aCarNodes[component] == nil)
+ return;
+ if(status == PANEL_STATUS_SMASHED1){
+ // show damaged part
+ SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM);
+ }else if(status == PANEL_STATUS_MISSING){
+ if(!noFlyingComponents)
+ SpawnFlyingComponent(component, COMPGROUP_PANEL);
+ // hide both
+ SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE);
+ }
+}
+
+void
+CAutomobile::SetBumperDamage(int32 component, ePanels panel, bool noFlyingComponents)
+{
+ int status = Damage.GetPanelStatus(panel);
+ if(m_aCarNodes[component] == nil){
+ printf("Trying to damage component %d of %s\n",
+ component, CModelInfo::GetModelInfo(GetModelIndex())->GetName());
+ return;
+ }
+ if(status == PANEL_STATUS_SMASHED1){
+ // show damaged part
+ SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM);
+ }else if(status == PANEL_STATUS_MISSING){
+ if(!noFlyingComponents)
+ SpawnFlyingComponent(component, COMPGROUP_BUMPER);
+ // hide both
+ SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE);
+ }
+}
+
+void
+CAutomobile::SetDoorDamage(int32 component, eDoors door, bool noFlyingComponents)
+{
+ int status = Damage.GetDoorStatus(door);
+ if(m_aCarNodes[component] == nil){
+ printf("Trying to damage component %d of %s\n",
+ component, CModelInfo::GetModelInfo(GetModelIndex())->GetName());
+ return;
+ }
+
+ if(door == DOOR_BOOT && status == DOOR_STATUS_SWINGING && m_handling->Flags & HANDLING_NOSWING_BOOT){
+ Damage.SetDoorStatus(DOOR_BOOT, DOOR_STATUS_MISSING);
+ status = DOOR_STATUS_MISSING;
+ }
+
+ if(status == DOOR_STATUS_SMASHED){
+ // show damaged part
+ SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_DAM);
+ }else if(status == DOOR_STATUS_SWINGING){
+ // turn off angle cull for swinging doors
+ RwFrameForAllObjects(m_aCarNodes[component], CVehicleModelInfo::SetAtomicFlagCB, (void*)ATOMIC_FLAG_NOCULL);
+ }else if(status == DOOR_STATUS_MISSING){
+ if(!noFlyingComponents){
+ if(door == DOOR_BONNET)
+ SpawnFlyingComponent(component, COMPGROUP_BONNET);
+ else if(door == DOOR_BOOT)
+ SpawnFlyingComponent(component, COMPGROUP_BOOT);
+ else
+ SpawnFlyingComponent(component, COMPGROUP_DOOR);
+ }
+ // hide both
+ SetComponentVisibility(m_aCarNodes[component], ATOMIC_FLAG_NONE);
+ }
+}
+
+
+static RwObject*
+SetVehicleAtomicVisibilityCB(RwObject *object, void *data)
+{
+ uint32 flags = (uint32)(uintptr)data;
+ RpAtomic *atomic = (RpAtomic*)object;
+ if((CVisibilityPlugins::GetAtomicId(atomic) & (ATOMIC_FLAG_OK|ATOMIC_FLAG_DAM)) == flags)
+ RpAtomicSetFlags(atomic, rpATOMICRENDER);
+ else
+ RpAtomicSetFlags(atomic, 0);
+ return object;
+}
+
+void
+CAutomobile::SetComponentVisibility(RwFrame *frame, uint32 flags)
+{
+ HideAllComps();
+ bIsDamaged = true;
+ RwFrameForAllObjects(frame, SetVehicleAtomicVisibilityCB, (void*)flags);
+}
+
+void
+CAutomobile::SetupModelNodes(void)
+{
+ int i;
+ for(i = 0; i < NUM_CAR_NODES; i++)
+ m_aCarNodes[i] = nil;
+ CClumpModelInfo::FillFrameArray((RpClump*)m_rwObject, m_aCarNodes);
+}
+
+void
+CAutomobile::SetTaxiLight(bool light)
+{
+ bTaxiLight = light;
+}
+
+bool
+CAutomobile::GetAllWheelsOffGround(void)
+{
+ return m_nWheelsOnGround == 0;
+}
+
+void
+CAutomobile::HideAllComps(void)
+{
+ // empty
+}
+
+void
+CAutomobile::ShowAllComps(void)
+{
+ // empty
+}
+
+void
+CAutomobile::ReduceHornCounter(void)
+{
+ if(m_nCarHornTimer != 0)
+ m_nCarHornTimer--;
+}
+
+void
+CAutomobile::SetAllTaxiLights(bool set)
+{
+ m_sAllTaxiLights = set;
+}
+
+class CAutomobile_ : public CAutomobile
+{
+public:
+ void dtor() { CAutomobile::~CAutomobile(); }
+ void SetModelIndex_(uint32 id) { CAutomobile::SetModelIndex(id); }
+ void ProcessControl_(void) { CAutomobile::ProcessControl(); }
+ void Teleport_(CVector v) { CAutomobile::Teleport(v); }
+ void PreRender_(void) { CAutomobile::PreRender(); }
+ void Render_(void) { CAutomobile::Render(); }
+
+ int32 ProcessEntityCollision_(CEntity *ent, CColPoint *colpoints){ return CAutomobile::ProcessEntityCollision(ent, colpoints); }
+
+ void ProcessControlInputs_(uint8 x) { CAutomobile::ProcessControlInputs(x); }
+ void GetComponentWorldPosition_(int32 component, CVector &pos) { CAutomobile::GetComponentWorldPosition(component, pos); }
+ bool IsComponentPresent_(int32 component) { return CAutomobile::IsComponentPresent(component); }
+ void SetComponentRotation_(int32 component, CVector rotation) { CAutomobile::SetComponentRotation(component, rotation); }
+ void OpenDoor_(int32 component, eDoors door, float ratio) { CAutomobile::OpenDoor(component, door, ratio); }
+ void ProcessOpenDoor_(uint32 component, uint32 anim, float time) { CAutomobile::ProcessOpenDoor(component, anim, time); }
+ bool IsDoorReady_(eDoors door) { return CAutomobile::IsDoorReady(door); }
+ bool IsDoorFullyOpen_(eDoors door) { return CAutomobile::IsDoorFullyOpen(door); }
+ bool IsDoorClosed_(eDoors door) { return CAutomobile::IsDoorClosed(door); }
+ bool IsDoorMissing_(eDoors door) { return CAutomobile::IsDoorMissing(door); }
+ void RemoveRefsToVehicle_(CEntity *ent) { CAutomobile::RemoveRefsToVehicle(ent); }
+ void BlowUpCar_(CEntity *ent) { CAutomobile::BlowUpCar(ent); }
+ bool SetUpWheelColModel_(CColModel *colModel) { return CAutomobile::SetUpWheelColModel(colModel); }
+ void BurstTyre_(uint8 tyre) { CAutomobile::BurstTyre(tyre); }
+ bool IsRoomForPedToLeaveCar_(uint32 door, CVector *pos) { return CAutomobile::IsRoomForPedToLeaveCar(door, pos); }
+ float GetHeightAboveRoad_(void) { return CAutomobile::GetHeightAboveRoad(); }
+ void PlayCarHorn_(void) { CAutomobile::PlayCarHorn(); }
+};
STARTPATCHES
-InjectHook(0x52D170, &CAutomobile::dtor, PATCH_JUMP);
-ENDPATCHES \ No newline at end of file
+ InjectHook(0x52D170, &CAutomobile_::dtor, PATCH_JUMP);
+ InjectHook(0x52D190, &CAutomobile_::SetModelIndex_, PATCH_JUMP);
+ InjectHook(0x535180, &CAutomobile_::Teleport_, PATCH_JUMP);
+ InjectHook(0x53B270, &CAutomobile_::ProcessEntityCollision_, PATCH_JUMP);
+ InjectHook(0x52E5F0, &CAutomobile_::GetComponentWorldPosition_, PATCH_JUMP);
+ InjectHook(0x52E660, &CAutomobile_::IsComponentPresent_, PATCH_JUMP);
+ InjectHook(0x52E680, &CAutomobile_::SetComponentRotation_, PATCH_JUMP);
+ InjectHook(0x52E750, &CAutomobile_::OpenDoor_, PATCH_JUMP);
+ InjectHook(0x52EF10, &CAutomobile_::IsDoorReady_, PATCH_JUMP);
+ InjectHook(0x52EF90, &CAutomobile_::IsDoorFullyOpen_, PATCH_JUMP);
+ InjectHook(0x52EFD0, &CAutomobile_::IsDoorClosed_, PATCH_JUMP);
+ InjectHook(0x52F000, &CAutomobile_::IsDoorMissing_, PATCH_JUMP);
+ InjectHook(0x53BF40, &CAutomobile_::RemoveRefsToVehicle_, PATCH_JUMP);
+ InjectHook(0x53BC60, &CAutomobile_::BlowUpCar_, PATCH_JUMP);
+ InjectHook(0x53BF70, &CAutomobile_::SetUpWheelColModel_, PATCH_JUMP);
+ InjectHook(0x53C0E0, &CAutomobile_::BurstTyre_, PATCH_JUMP);
+ InjectHook(0x437690, &CAutomobile_::GetHeightAboveRoad_, PATCH_JUMP);
+ InjectHook(0x53C450, &CAutomobile_::PlayCarHorn_, PATCH_JUMP);
+ InjectHook(0x5353A0, &CAutomobile::ResetSuspension, PATCH_JUMP);
+ InjectHook(0x52D210, &CAutomobile::SetupSuspensionLines, PATCH_JUMP);
+ InjectHook(0x53E000, &CAutomobile::BlowUpCarsInPath, PATCH_JUMP);
+ InjectHook(0x42E220, &CAutomobile::HasCarStoppedBecauseOfLight, PATCH_JUMP);
+ InjectHook(0x53D320, &CAutomobile::SetBusDoorTimer, PATCH_JUMP);
+ InjectHook(0x53D370, &CAutomobile::ProcessAutoBusDoors, PATCH_JUMP);
+ InjectHook(0x535250, &CAutomobile::ProcessSwingingDoor, PATCH_JUMP);
+ InjectHook(0x53C240, &CAutomobile::Fix, PATCH_JUMP);
+ InjectHook(0x53C310, &CAutomobile::SetupDamageAfterLoad, PATCH_JUMP);
+ InjectHook(0x530300, &CAutomobile::SpawnFlyingComponent, PATCH_JUMP);
+ InjectHook(0x535320, &CAutomobile::RemoveBonnetInPedCollision, PATCH_JUMP);
+ InjectHook(0x5301A0, &CAutomobile::SetPanelDamage, PATCH_JUMP);
+ InjectHook(0x530120, &CAutomobile::SetBumperDamage, PATCH_JUMP);
+ InjectHook(0x530200, &CAutomobile::SetDoorDamage, PATCH_JUMP);
+ InjectHook(0x5300E0, &CAutomobile::SetComponentVisibility, PATCH_JUMP);
+ InjectHook(0x52D1B0, &CAutomobile::SetupModelNodes, PATCH_JUMP);
+ InjectHook(0x53C420, &CAutomobile::SetTaxiLight, PATCH_JUMP);
+ InjectHook(0x53BC40, &CAutomobile::GetAllWheelsOffGround, PATCH_JUMP);
+ InjectHook(0x5308C0, &CAutomobile::ReduceHornCounter, PATCH_JUMP);
+ InjectHook(0x53C440, &CAutomobile::SetAllTaxiLights, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/vehicles/Automobile.h b/src/vehicles/Automobile.h
index 630635c7..60e08d0a 100644
--- a/src/vehicles/Automobile.h
+++ b/src/vehicles/Automobile.h
@@ -1,21 +1,10 @@
#pragma once
-#include "DamageManager.h"
#include "Vehicle.h"
+#include "DamageManager.h"
+#include "Door.h"
-struct CDoor
-{
- float m_fAngleWhenOpened;
- float m_fAngleWhenClosed;
- char field_8;
- char field_9;
- char field_10;
- char field_11;
- float m_fAngle;
- float m_fPreviousAngle;
- float m_fAngularVelocity;
- CVector m_vecVelocity;
-};
+class CObject;
class CAutomobile : public CVehicle
{
@@ -28,20 +17,28 @@ public:
float m_aSuspensionSpringRatio[4];
float m_aSuspensionSpringRatioPrev[4];
float m_aWheelSkidThing[4];
- int field_49C;
+ float field_49C;
bool m_aWheelSkidmarkMuddy[4];
bool m_aWheelSkidmarkBloody[4];
float m_aWheelRotation[4];
float m_aWheelPosition[4];
float m_aWheelSpeed[4];
- uint8 stuff3[12];
+ uint8 field_4D8;
+ uint8 m_auto_flagA7 : 1;
+ uint8 bTaxiLight : 1;
+ uint8 m_auto_flagA10 : 1;
+ uint8 m_auto_flagA20 : 1;
+ uint8 m_auto_flagA40 : 1;
+ uint8 m_auto_flagA80 : 1;
+ uint8 field_4DA[10];
uint32 m_nBusDoorTimerEnd;
uint32 m_nBusDoorTimerStart;
float m_aSuspensionSpringLength[4];
float m_aSuspensionLineLength[4];
float m_fHeightAboveRoad;
float m_fImprovedHandling;
- uint8 stuff6[32];
+ uint8 stuff6[28];
+ float field_530;
CPhysical *m_aGroundPhysical[4]; // physicals touching wheels
CVector m_aGroundOffset[4]; // from ground object to colpoint
CEntity *m_pBlowUpEntity;
@@ -57,11 +54,66 @@ public:
uint8 stuff5[5];
int32 m_aWheelState[4];
+ static bool &m_sAllTaxiLights;
+
CAutomobile(int, uint8);
+
+ // from CEntity
+ void SetModelIndex(uint32 id);
+ void ProcessControl(void);
+ void Teleport(CVector v);
+ void PreRender(void);
+ void Render(void);
+
+ // from CPhysical
+ int32 ProcessEntityCollision(CEntity *ent, CColPoint *colpoints);
+
+ // from CVehicle
+ void ProcessControlInputs(uint8);
+ void GetComponentWorldPosition(int32 component, CVector &pos);
+ bool IsComponentPresent(int32 component);
+ void SetComponentRotation(int32 component, CVector rotation);
+ void OpenDoor(int32 component, eDoors door, float openRatio);
+ void ProcessOpenDoor(uint32, uint32, float);
+ bool IsDoorReady(eDoors door);
+ bool IsDoorFullyOpen(eDoors door);
+ bool IsDoorClosed(eDoors door);
+ bool IsDoorMissing(eDoors door);
+ void RemoveRefsToVehicle(CEntity *ent);
+ void BlowUpCar(CEntity *ent);
+ bool SetUpWheelColModel(CColModel *colModel);
+ void BurstTyre(uint8 tyre);
+ bool IsRoomForPedToLeaveCar(uint32, CVector *);
+ float GetHeightAboveRoad(void);
+ void PlayCarHorn(void);
+
+ void PlayHornIfNecessary(void);
+ void ResetSuspension(void);
+ void SetupSuspensionLines(void);
+ void ScanForCrimes(void);
+ void BlowUpCarsInPath(void);
+ bool HasCarStoppedBecauseOfLight(void);
+ void SetBusDoorTimer(uint32 timer, uint8 type);
+ void ProcessAutoBusDoors(void);
+ void ProcessSwingingDoor(int32 component, eDoors door);
+ void SetupDamageAfterLoad(void);
+ CObject *SpawnFlyingComponent(int32 component, uint32 type);
+ CObject *RemoveBonnetInPedCollision(void);
+ void SetPanelDamage(int32 component, ePanels panel, bool noFlyingComponents = false);
+ void SetBumperDamage(int32 component, ePanels panel, bool noFlyingComponents = false);
+ void SetDoorDamage(int32 component, eDoors door, bool noFlyingComponents = false);
+
+ void Fix(void);
+ void SetComponentVisibility(RwFrame *frame, uint32 flags);
+ void SetupModelNodes(void);
+ void SetTaxiLight(bool light);
+ bool GetAllWheelsOffGround(void);
+ void HideAllComps(void);
+ void ShowAllComps(void);
+ void ReduceHornCounter(void);
+
+ static void SetAllTaxiLights(bool set);
+
CAutomobile* ctor(int, uint8);
- void SetDoorDamage(int32, uint32, bool); /* TODO: eDoors */
- void SetPanelDamage(int32, uint32, bool); /* TODO: ePanels */
- void SetBumperDamage(int32, uint32, bool); /* TODO: ePanels */
- void dtor() { this->CAutomobile::~CAutomobile(); }
};
static_assert(sizeof(CAutomobile) == 0x5A8, "CAutomobile: error");
diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp
index 9b462971..53a912b3 100644
--- a/src/vehicles/Boat.cpp
+++ b/src/vehicles/Boat.cpp
@@ -20,7 +20,6 @@ CBoat::CBoat(int mi, uint8 owner)
WRAPPER CBoat* CBoat::ctor(int, uint8) { EAXJMP(0x53E3E0); }
-
bool CBoat::IsSectorAffectedByWake(CVector2D sector, float fSize, CBoat **apBoats)
{
uint8 numVerts = 0;
@@ -71,7 +70,12 @@ float CBoat::IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat)
WRAPPER void CBoat::FillBoatList(void) { EAXJMP(0x542250); }
+class CBoat_ : public CBoat
+{
+public:
+ void dtor() { CBoat::~CBoat(); };
+};
STARTPATCHES
-InjectHook(0x53E790, &CBoat::dtor, PATCH_JUMP);
-ENDPATCHES \ No newline at end of file
+ InjectHook(0x53E790, &CBoat_::dtor, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/vehicles/Boat.h b/src/vehicles/Boat.h
index 41fed2ff..52f3530c 100644
--- a/src/vehicles/Boat.h
+++ b/src/vehicles/Boat.h
@@ -49,6 +49,7 @@ public:
static bool IsSectorAffectedByWake(CVector2D sector, float fSize, CBoat **apBoats);
static float IsVertexAffectedByWake(CVector vecVertex, CBoat *pBoat);
static void FillBoatList(void);
+
};
static_assert(sizeof(CBoat) == 0x484, "CBoat: error");
diff --git a/src/vehicles/DamageManager.cpp b/src/vehicles/DamageManager.cpp
index 1a7f25ed..380537f2 100644
--- a/src/vehicles/DamageManager.cpp
+++ b/src/vehicles/DamageManager.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include "patcher.h"
#include "General.h"
+#include "Vehicle.h"
#include "DamageManager.h"
diff --git a/src/vehicles/DamageManager.h b/src/vehicles/DamageManager.h
index 1fdbc6b1..b815f724 100644
--- a/src/vehicles/DamageManager.h
+++ b/src/vehicles/DamageManager.h
@@ -4,6 +4,28 @@
// TODO: move some of this into Vehicle.h
+enum eDoorStatus
+{
+ DOOR_STATUS_OK,
+ DOOR_STATUS_SMASHED,
+ DOOR_STATUS_SWINGING,
+ DOOR_STATUS_MISSING
+};
+
+enum ePanelStatus
+{
+ PANEL_STATUS_OK,
+ PANEL_STATUS_SMASHED1,
+ PANEL_STATUS_SMASHED2,
+ PANEL_STATUS_MISSING,
+};
+
+enum eWheelStatus
+{
+ WHEEL_STATUS_OK,
+ WHEEL_STATUS_BURST
+};
+
enum tComponent
{
COMPONENT_DEFAULT,
@@ -37,23 +59,7 @@ enum tComponentGroup
COMPGROUP_DEFAULT,
};
-enum eLights
-{
- VEHLIGHT_FRONT_LEFT,
- VEHLIGHT_FRONT_RIGHT,
- VEHLIGHT_REAR_LEFT,
- VEHLIGHT_REAR_RIGHT,
-};
-
-enum {
- VEHPANEL_FRONT_LEFT,
- VEHPANEL_FRONT_RIGHT,
- VEHPANEL_REAR_LEFT,
- VEHPANEL_REAR_RIGHT,
- VEHPANEL_WINDSCREEN,
- VEHBUMPER_FRONT,
- VEHBUMPER_REAR,
-};
+enum eLights;
class CDamageManager
{
diff --git a/src/vehicles/Door.cpp b/src/vehicles/Door.cpp
new file mode 100644
index 00000000..25e87504
--- /dev/null
+++ b/src/vehicles/Door.cpp
@@ -0,0 +1,126 @@
+#include "common.h"
+#include "patcher.h"
+#include "Vehicle.h"
+#include "Door.h"
+
+CDoor::CDoor(void)
+{
+ memset(this, 0, sizeof(*this));
+}
+
+void
+CDoor::Open(float ratio)
+{
+ float open;
+
+ m_fPrevAngle = m_fAngle;
+ open = RetAngleWhenOpen();
+ if(ratio < 1.0f){
+ m_fAngle = open*ratio;
+ if(m_fAngle == 0.0f)
+ m_fAngVel = 0.0f;
+ }else{
+ m_nDoorState = DOORST_OPEN;
+ m_fAngle = open;
+ }
+}
+
+void
+CDoor::Process(CVehicle *vehicle)
+{
+ static CVector vecOffset(1.0f, 0.0f, 0.0f);
+ CVector speed = vehicle->GetSpeed(vecOffset);
+ CVector vecSpeedDiff = speed - m_vecSpeed;
+ vecSpeedDiff = Multiply3x3(vecSpeedDiff, vehicle->GetMatrix());
+
+ // air resistance
+ float fSpeedDiff = 0.0f; // uninitialized in game
+ switch(m_nAxis){
+ case 0: // x-axis
+ if(m_nDirn)
+ fSpeedDiff = vecSpeedDiff.y + vecSpeedDiff.z;
+ else
+ fSpeedDiff = -(vecSpeedDiff.y + vecSpeedDiff.z);
+ break;
+
+ // we don't support y axis apparently?
+
+ case 2: // z-axis
+ if(m_nDirn)
+ fSpeedDiff = -(vecSpeedDiff.x + vecSpeedDiff.y);
+ else
+ fSpeedDiff = vecSpeedDiff.x + vecSpeedDiff.y;
+ break;
+ }
+ fSpeedDiff = clamp(fSpeedDiff, -0.2f, 0.2f);
+ if(Abs(fSpeedDiff) > 0.002f)
+ m_fAngVel += fSpeedDiff;
+ m_fAngVel *= 0.945f;
+ m_fAngVel = clamp(m_fAngVel, -0.3f, 0.3f);
+
+ m_fAngle += m_fAngVel;
+ m_nDoorState = DOORST_SWINGING;
+ if(m_fAngle > m_fMaxAngle){
+ m_fAngle = m_fMaxAngle;
+ m_fAngVel *= -0.8f;
+ m_nDoorState = DOORST_OPEN;
+ }
+ if(m_fAngle < m_fMinAngle){
+ m_fAngle = m_fMinAngle;
+ m_fAngVel *= -0.8f;
+ m_nDoorState = DOORST_CLOSED;
+ }
+ m_vecSpeed = speed;
+}
+
+float
+CDoor::RetAngleWhenClosed(void)
+{
+ if(Abs(m_fMaxAngle) < Abs(m_fMinAngle))
+ return m_fMaxAngle;
+ else
+ return m_fMinAngle;
+}
+
+float
+CDoor::RetAngleWhenOpen(void)
+{
+ if(Abs(m_fMaxAngle) < Abs(m_fMinAngle))
+ return m_fMinAngle;
+ else
+ return m_fMaxAngle;
+}
+
+float
+CDoor::GetAngleOpenRatio(void)
+{
+ float open = RetAngleWhenOpen();
+ if(open == 0.0f)
+ return 0.0f;
+ return m_fAngle/open;
+}
+
+bool
+CDoor::IsFullyOpen(void)
+{
+ // why -0.5? that's around 28 deg less than fully open
+ if(Abs(m_fAngle) < Abs(RetAngleWhenOpen()) - 0.5f)
+ return false;
+ return true;
+}
+
+bool
+CDoor::IsClosed(void)
+{
+ return m_fAngle == RetAngleWhenClosed();
+}
+
+STARTPATCHES
+ InjectHook(0x545EF0, &CDoor::Open, PATCH_JUMP);
+ InjectHook(0x545BD0, &CDoor::Process, PATCH_JUMP);
+ InjectHook(0x545FE0, &CDoor::RetAngleWhenClosed, PATCH_JUMP);
+ InjectHook(0x546020, &CDoor::RetAngleWhenOpen, PATCH_JUMP);
+ InjectHook(0x545F80, &CDoor::GetAngleOpenRatio, PATCH_JUMP);
+ InjectHook(0x546090, &CDoor::IsFullyOpen, PATCH_JUMP);
+ InjectHook(0x546060, &CDoor::IsClosed, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/vehicles/Door.h b/src/vehicles/Door.h
new file mode 100644
index 00000000..fc771a40
--- /dev/null
+++ b/src/vehicles/Door.h
@@ -0,0 +1,36 @@
+#pragma once
+
+class CVehicle;
+
+enum eDoorState
+{
+ DOORST_SWINGING,
+ // actually wrong though,
+ // OPEN is really MAX_ANGLE and CLOSED is MIN_ANGLE
+ DOORST_OPEN,
+ DOORST_CLOSED
+};
+
+struct CDoor
+{
+ float m_fMaxAngle;
+ float m_fMinAngle;
+ // direction of rotation for air resistance
+ int8 m_nDirn;
+ // axis in which this door rotates
+ int8 m_nAxis;
+ int8 m_nDoorState;
+ float m_fAngle;
+ float m_fPrevAngle;
+ float m_fAngVel;
+ CVector m_vecSpeed;
+
+ CDoor(void);
+ void Open(float ratio);
+ void Process(CVehicle *veh);
+ float RetAngleWhenClosed(void);
+ float RetAngleWhenOpen(void);
+ float GetAngleOpenRatio(void);
+ bool IsFullyOpen(void);
+ bool IsClosed(void);
+};
diff --git a/src/vehicles/HandlingMgr.h b/src/vehicles/HandlingMgr.h
index 958e2351..2627fbae 100644
--- a/src/vehicles/HandlingMgr.h
+++ b/src/vehicles/HandlingMgr.h
@@ -119,7 +119,9 @@ VALIDATE_SIZE(tHandlingData, 0xD8);
class cHandlingDataMgr
{
float field_0; // unused it seems
+public:
float field_4; // wheel related
+private:
float field_8; //
float field_C; // unused it seems
float field_10; //
diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp
index 01ee5375..d43e8c19 100644
--- a/src/vehicles/Heli.cpp
+++ b/src/vehicles/Heli.cpp
@@ -10,6 +10,12 @@ CHeli::CHeli(int mi, uint8 owner)
WRAPPER CHeli* CHeli::ctor(int, uint8) { EAXJMP(0x547220); }
WRAPPER void CHeli::SpecialHeliPreRender(void) { EAXJMP(0x54AE10); }
+class CHeli_ : public CHeli
+{
+public:
+ void dtor(void) { CHeli::~CHeli(); }
+};
+
STARTPATCHES
-InjectHook(0x5474A0, &CHeli::dtor, PATCH_JUMP);
+ InjectHook(0x5474A0, &CHeli_::dtor, PATCH_JUMP);
ENDPATCHES
diff --git a/src/vehicles/Heli.h b/src/vehicles/Heli.h
index da7bb171..db873ae2 100644
--- a/src/vehicles/Heli.h
+++ b/src/vehicles/Heli.h
@@ -10,7 +10,6 @@ public:
CHeli(int, uint8);
CHeli* ctor(int, uint8);
- void dtor(void) { this->CHeli::~CHeli(); }
static void SpecialHeliPreRender(void);
};
diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp
index 6e30bced..3bad1e07 100644
--- a/src/vehicles/Plane.cpp
+++ b/src/vehicles/Plane.cpp
@@ -14,6 +14,12 @@ CPlane::~CPlane()
DeleteRwObject();
}
+class CPlane_ : public CPlane
+{
+public:
+ void dtor(void) { CPlane::~CPlane(); }
+};
+
STARTPATCHES
-InjectHook(0x54B270, &CPlane::dtor, PATCH_JUMP);
-ENDPATCHES \ No newline at end of file
+ InjectHook(0x54B270, &CPlane_::dtor, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/vehicles/Plane.h b/src/vehicles/Plane.h
index e26008f6..1f54e529 100644
--- a/src/vehicles/Plane.h
+++ b/src/vehicles/Plane.h
@@ -12,7 +12,6 @@ public:
CPlane(int, uint8);
~CPlane(void);
CPlane* ctor(int, uint8);
- void dtor(void) { this->CPlane::~CPlane(); }
void FlagToDestroyWhenNextProcessed() { bRemoveFromWorld = true; }
};
static_assert(sizeof(CPlane) == 0x29C, "CPlane: error");
diff --git a/src/vehicles/Train.cpp b/src/vehicles/Train.cpp
index 62fd53ec..b7fd6ca1 100644
--- a/src/vehicles/Train.cpp
+++ b/src/vehicles/Train.cpp
@@ -9,6 +9,12 @@ CTrain::CTrain(int mi, uint8 owner)
WRAPPER CTrain* CTrain::ctor(int, uint8) { EAXJMP(0x54E2A0); }
+class CTrain_ : public CTrain
+{
+public:
+ void dtor(void) { CTrain::~CTrain(); }
+};
+
STARTPATCHES
-InjectHook(0x54E450, &CTrain::dtor, PATCH_JUMP);
-ENDPATCHES \ No newline at end of file
+ InjectHook(0x54E450, &CTrain_::dtor, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/vehicles/Train.h b/src/vehicles/Train.h
index 84b6faf5..5e1e2e35 100644
--- a/src/vehicles/Train.h
+++ b/src/vehicles/Train.h
@@ -21,6 +21,5 @@ public:
CTrain(int, uint8);
CTrain* ctor(int, uint8);
- void dtor(void) { this->CTrain::~CTrain(); }
};
static_assert(sizeof(CTrain) == 0x2E4, "CTrain: error");
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index dccd9195..d8ed1a15 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;
@@ -92,9 +168,227 @@ CVehicle::RemoveLighting(bool reset)
float
CVehicle::GetHeightAboveRoad(void)
{
- return -1.0f * CModelInfo::GetModelInfo(GetModelIndex())->GetColModel()->boundingBox.min.z;
+ return -1.0f * GetColModel()->boundingBox.min.z;
+}
+
+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 *= Pow(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::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
+ int32 wheelsOnGround, float thrust, float brake, float adhesion, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, uint16 wheelStatus)
+{
+ // BUG: using statics here is probably a bad idea
+ static bool bAlreadySkidding = false; // this is never reset
+ static bool bBraking;
+ static bool bDriving;
+
+ // how much force we want to apply in these axes
+ float fwd = 0.0f;
+ float right = 0.0f;
+
+ bBraking = brake != 0.0f;
+ if(bBraking)
+ thrust = 0.0f;
+ bDriving = thrust != 0.0f;
+
+ float contactSpeedFwd = DotProduct(wheelContactSpeed, wheelFwd);
+ float contactSpeedRight = DotProduct(wheelContactSpeed, wheelRight);
+
+ if(*wheelState != WHEEL_STATE_0)
+ bAlreadySkidding = true;
+ *wheelState = WHEEL_STATE_0;
+
+ adhesion *= CTimer::GetTimeStep();
+ if(bAlreadySkidding)
+ adhesion *= m_handling->fTractionLoss;
+
+ // moving sideways
+ if(contactSpeedRight != 0.0f){
+ // exert opposing force
+ right = -contactSpeedRight/wheelsOnGround;
+
+ if(wheelStatus == WHEEL_STATUS_BURST){
+ float fwdspeed = min(contactSpeedFwd, 0.3f);
+ right += fwdspeed * CGeneral::GetRandomNumberInRange(-0.1f, 0.1f);
+ }
+ }
+
+ if(bDriving){
+ fwd = thrust;
+
+ // limit sideways force (why?)
+ if(right > 0.0f){
+ if(right > adhesion)
+ right = adhesion;
+ }else{
+ if(right < -adhesion)
+ right = -adhesion;
+ }
+ }else if(contactSpeedFwd != 0.0f){
+ fwd = -contactSpeedFwd/wheelsOnGround;
+
+ if(!bBraking){
+ if(m_fGasPedal < 0.01f){
+ if(GetModelIndex() == MI_RCBANDIT)
+ brake = 0.2f * mod_HandlingManager.field_4 / m_fMass;
+ else
+ brake = mod_HandlingManager.field_4 / m_fMass;
+ }
+ }
+
+ if(brake > adhesion){
+ if(Abs(contactSpeedFwd) > 0.005f)
+ *wheelState = WHEEL_STATE_STATIC;
+ }else {
+ if(fwd > 0.0f){
+ if(fwd > brake)
+ fwd = brake;
+ }else{
+ if(fwd < -brake)
+ fwd = -brake;
+ }
+ }
+ }
+
+ if(sq(adhesion) < sq(right) + sq(fwd)){
+ if(*wheelState != WHEEL_STATE_STATIC){
+ if(bDriving && contactSpeedFwd < 0.2f)
+ *wheelState = WHEEL_STATE_1;
+ else
+ *wheelState = WHEEL_STATE_2;
+ }
+
+ float l = Sqrt(sq(right) + sq(fwd));
+ float tractionLoss = bAlreadySkidding ? 1.0f : m_handling->fTractionLoss;
+ right *= adhesion * tractionLoss / l;
+ fwd *= adhesion * tractionLoss / l;
+ }
+
+ if(fwd != 0.0f || right != 0.0f){
+ CVector direction = fwd*wheelFwd + right*wheelRight;
+ float speed = direction.Magnitude();
+ direction.Normalise();
+
+ float impulse = speed*m_fMass;
+ float turnImpulse = speed*GetMass(wheelContactPoint, direction);
+
+ ApplyMoveForce(impulse * direction);
+ ApplyTurnForce(turnImpulse * direction, wheelContactPoint);
+ }
+}
+
+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_STATIC:
+ angularVelocity = 0.0f; // not moving
+ break;
+ default:
+ angularVelocity = -DotProduct(fwd, speed) / radius; // forward speed
+ break;
+ }
+ return angularVelocity * CTimer::GetTimeStep();
}
+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);
+ }
+}
bool
CVehicle::IsLawEnforcementVehicle(void)
@@ -258,9 +552,9 @@ CVehicle::CanPedExitCar(void)
if(m_vecMoveSpeed.MagnitudeSqr() > 0.005f)
return false;
// if car is slow enough, check turn speed
- if(fabs(m_vecTurnSpeed.x) > 0.01f ||
- fabs(m_vecTurnSpeed.y) > 0.01f ||
- fabs(m_vecTurnSpeed.z) > 0.01f)
+ if(Abs(m_vecTurnSpeed.x) > 0.01f ||
+ Abs(m_vecTurnSpeed.y) > 0.01f ||
+ Abs(m_vecTurnSpeed.z) > 0.01f)
return false;
return true;
}else{
@@ -270,9 +564,9 @@ CVehicle::CanPedExitCar(void)
if(m_vecMoveSpeed.MagnitudeSqr() >= 0.005f)
return false;
// if car is slow enough, check turn speed
- if(fabs(m_vecTurnSpeed.x) >= 0.01f ||
- fabs(m_vecTurnSpeed.y) >= 0.01f ||
- fabs(m_vecTurnSpeed.z) >= 0.01f)
+ if(Abs(m_vecTurnSpeed.x) >= 0.01f ||
+ Abs(m_vecTurnSpeed.y) >= 0.01f ||
+ Abs(m_vecTurnSpeed.z) >= 0.01f)
return false;
return true;
}
@@ -442,7 +736,7 @@ CVehicle::IsSphereTouchingVehicle(float sx, float sy, float sz, float radius)
float x, y, z;
// sphere relative to vehicle
CVector sph = CVector(sx, sy, sz) - GetPosition();
- CColModel *colmodel = CModelInfo::GetModelInfo(GetModelIndex())->GetColModel();
+ CColModel *colmodel = GetColModel();
x = DotProduct(sph, GetRight());
if(colmodel->boundingBox.min.x - radius > x ||
@@ -460,12 +754,28 @@ CVehicle::IsSphereTouchingVehicle(float sx, float sy, float sz, float radius)
return true;
}
-STARTPATCHES
- InjectHook(0x551170, &CVehicle::SetModelIndex_, PATCH_JUMP);
- InjectHook(0x4A7DD0, &CVehicle::SetupLighting_, PATCH_JUMP);
- InjectHook(0x4A7E60, &CVehicle::RemoveLighting_, PATCH_JUMP);
- InjectHook(0x417E60, &CVehicle::GetHeightAboveRoad_, PATCH_JUMP);
+class CVehicle_ : public CVehicle
+{
+public:
+ void dtor(void) { CVehicle::~CVehicle(); }
+ void SetModelIndex_(uint32 id) { CVehicle::SetModelIndex(id); }
+ bool SetupLighting_(void) { return CVehicle::SetupLighting(); }
+ void RemoveLighting_(bool reset) { CVehicle::RemoveLighting(reset); }
+ float GetHeightAboveRoad_(void) { return CVehicle::GetHeightAboveRoad(); }
+};
+
+STARTPATCHES
+ InjectHook(0x551170, &CVehicle_::SetModelIndex_, PATCH_JUMP);
+ InjectHook(0x4A7DD0, &CVehicle_::SetupLighting_, PATCH_JUMP);
+ InjectHook(0x4A7E60, &CVehicle_::RemoveLighting_, PATCH_JUMP);
+ InjectHook(0x417E60, &CVehicle_::GetHeightAboveRoad_, PATCH_JUMP);
+
+ InjectHook(0x552BB0, &CVehicle::FlyingControl, PATCH_JUMP);
+ InjectHook(0x5512E0, &CVehicle::ProcessWheel, PATCH_JUMP);
+ InjectHook(0x551280, &CVehicle::ProcessWheelRotation, PATCH_JUMP);
+ InjectHook(0x552AF0, &CVehicle::ExtinguishCarFire, PATCH_JUMP);
+ InjectHook(0x551C90, &CVehicle::ProcessDelayedExplosion, PATCH_JUMP);
InjectHook(0x552880, &CVehicle::IsLawEnforcementVehicle, PATCH_JUMP);
InjectHook(0x552820, &CVehicle::ChangeLawEnforcerState, PATCH_JUMP);
InjectHook(0x552200, &CVehicle::UsesSiren, PATCH_JUMP);
diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h
index 39a56fe0..c293b8a6 100644
--- a/src/vehicles/Vehicle.h
+++ b/src/vehicles/Vehicle.h
@@ -69,6 +69,58 @@ enum eDoors
DOOR_REAR_RIGHT
};
+enum ePanels
+{
+ VEHPANEL_FRONT_LEFT,
+ VEHPANEL_FRONT_RIGHT,
+ VEHPANEL_REAR_LEFT,
+ VEHPANEL_REAR_RIGHT,
+ VEHPANEL_WINDSCREEN,
+ VEHBUMPER_FRONT,
+ VEHBUMPER_REAR,
+};
+
+enum eLights
+{
+ VEHLIGHT_FRONT_LEFT,
+ VEHLIGHT_FRONT_RIGHT,
+ VEHLIGHT_REAR_LEFT,
+ VEHLIGHT_REAR_RIGHT,
+};
+
+enum eWheels
+{
+ VEHWHEEL_FRONT_LEFT,
+ VEHWHEEL_FRONT_RIGHT,
+ VEHWHEEL_REAR_LEFT,
+ VEHWHEEL_REAR_RIGHT,
+};
+
+enum
+{
+ CAR_PIECE_WHEEL_LF = 13,
+ CAR_PIECE_WHEEL_LR,
+ CAR_PIECE_WHEEL_RF,
+ CAR_PIECE_WHEEL_RR,
+};
+
+enum tWheelState
+{
+ WHEEL_STATE_0 = 0,
+ WHEEL_STATE_1 = 1, // constant velocity
+ WHEEL_STATE_2 = 2, // normal
+ WHEEL_STATE_STATIC = 3, // not moving
+};
+
+enum eFlightModel
+{
+ FLIGHT_MODEL_DODO,
+ // not used in III
+ FLIGHT_MODEL_RCPLANE,
+ FLIGHT_MODEL_HELI,
+ FLIGHT_MODEL_SEAPLANE
+};
+
class CVehicle : public CPhysical
{
public:
@@ -88,7 +140,7 @@ public:
int8 m_nGettingOutFlags;
uint8 m_nNumMaxPassengers;
char field_1CD[19];
- CEntity *m_pCurSurface;
+ CEntity *m_pCurGroundEntity;
CFire *m_pCarFire;
float m_fSteerAngle;
float m_fGasPedal;
@@ -115,19 +167,19 @@ public:
uint8 m_veh_flagB80 : 1;
uint8 m_veh_flagC1 : 1;
- uint8 m_veh_flagC2 : 1;
+ uint8 bIsDamaged : 1; // This vehicle has been damaged and is displaying all its components
uint8 m_veh_flagC4 : 1;
uint8 m_veh_flagC8 : 1;
uint8 m_veh_flagC10 : 1;
uint8 m_veh_flagC20 : 1;
- uint8 m_veh_flagC40 : 1;
+ uint8 bCanBeDamaged : 1; // Set to FALSE during cut scenes to avoid explosions
uint8 m_veh_flagC80 : 1;
uint8 m_veh_flagD1 : 1;
uint8 m_veh_flagD2 : 1;
- uint8 m_veh_flagD4 : 1;
- uint8 m_veh_flagD8 : 1;
- uint8 bRecordedForReplay : 1;
+ uint8 bVehicleColProcessed : 1;// Has ProcessEntityCollision been processed for this car?
+ uint8 bIsCarParkVehicle : 1; // Car has been created using the special CAR_PARK script command
+ uint8 bHasAlreadyBeenRecorded : 1; // Used for replays
uint8 m_veh_flagD20 : 1;
uint8 m_veh_flagD40 : 1;
uint8 m_veh_flagD80 : 1;
@@ -144,7 +196,7 @@ public:
uint32 m_nTimeOfDeath;
int16 field_214;
int16 m_nBombTimer; // goes down with each frame
- CPed *m_pWhoDetonatedMe;
+ CPed *m_pWhoSetMeOnFire;
float field_21C;
float field_220;
eCarLock m_nDoorLock;
@@ -154,11 +206,9 @@ public:
int8 field_22B;
uint8 m_nCarHornTimer;
int8 field_22D;
- uint8 m_nSirenOrAlarm;
+ bool m_bSirenOrAlarm;
int8 field_22F;
- // TODO: this is an array
- CStoredCollPoly m_frontCollPoly; // poly which is under front part of car
- CStoredCollPoly m_rearCollPoly; // poly which is under rear part of car
+ CStoredCollPoly m_aCollPolys[2]; // poly which is under front/rear part of car
float m_fSteerRatio;
eVehicleType m_vehType;
@@ -167,9 +217,11 @@ public:
static void operator delete(void*, size_t);
static void operator delete(void*, int);
+ CVehicle(void) {} // FAKE
+ CVehicle(uint8 CreatedBy);
~CVehicle(void);
// from CEntity
- void SetModelIndex(uint32 i);
+ void SetModelIndex(uint32 id);
bool SetupLighting(void);
void RemoveLighting(bool);
void FlagToDestroyWhenNextProcessed(void) {}
@@ -197,6 +249,13 @@ public:
bool IsTrain(void) { return m_vehType == VEHICLE_TYPE_TRAIN; }
bool IsHeli(void) { return m_vehType == VEHICLE_TYPE_HELI; }
bool IsPlane(void) { return m_vehType == VEHICLE_TYPE_PLANE; }
+
+ void FlyingControl(eFlightModel flightModel);
+ void ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
+ int32 wheelsOnGround, float thrust, float brake, float adhesion, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, uint16 wheelStatus);
+ void ExtinguishCarFire(void);
+ void ProcessDelayedExplosion(void);
+ float ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVector &speed, float radius);
bool IsLawEnforcementVehicle(void);
void ChangeLawEnforcerState(uint8 enable);
bool UsesSiren(uint32 id);
@@ -225,16 +284,24 @@ public:
static bool &bCheat4;
static bool &bCheat5;
static bool &m_bDisableMouseSteering;
-
-
- void dtor(void) { CVehicle::~CVehicle(); }
- void SetModelIndex_(uint32 id) { CVehicle::SetModelIndex(id); }
- bool SetupLighting_(void) { return CVehicle::SetupLighting(); }
- void RemoveLighting_(bool reset) { CVehicle::RemoveLighting(reset); }
- float GetHeightAboveRoad_(void) { return CVehicle::GetHeightAboveRoad(); }
};
static_assert(sizeof(CVehicle) == 0x288, "CVehicle: error");
-static_assert(offsetof(CVehicle, m_pCurSurface) == 0x1E0, "CVehicle: error");
+static_assert(offsetof(CVehicle, m_pCurGroundEntity) == 0x1E0, "CVehicle: error");
static_assert(offsetof(CVehicle, m_nAlarmState) == 0x1A0, "CVehicle: error");
static_assert(offsetof(CVehicle, m_nLastWeaponDamage) == 0x228, "CVehicle: error");
+
+inline uint8 GetVehDoorFlag(int32 carnode) {
+ switch (carnode) {
+ case CAR_DOOR_LF:
+ return 1;
+ case CAR_DOOR_LR:
+ return 2;
+ case CAR_DOOR_RF:
+ return 4;
+ case CAR_DOOR_RR:
+ return 8;
+ default:
+ return 0;
+ }
+}