From edf5ac2626ce17b74037281aa3c9730902b4b1d4 Mon Sep 17 00:00:00 2001 From: aap Date: Mon, 8 Jul 2019 17:07:34 +0200 Subject: [PATCH] little changes; one more function of CAutomobile --- src/control/Replay.cpp | 56 ++++++++++++++++++------------------- src/core/Placeable.h | 8 +++--- src/entities/Entity.cpp | 14 +++++----- src/entities/Physical.cpp | 4 +-- src/math/Matrix.h | 46 +++++++++++++++--------------- src/peds/Ped.cpp | 28 +++++++++---------- src/peds/Ped.h | 23 +-------------- src/vehicles/Automobile.cpp | 39 ++++++++++++++++++++++++-- src/vehicles/Vehicle.h | 23 +++++++++++++++ 9 files changed, 138 insertions(+), 103 deletions(-) diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index d0264415..9041a003 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -469,7 +469,7 @@ void CReplay::ProcessPedUpdate(CPed *ped, float interpolation, CAddressInReplayB CMatrix ped_matrix; pp->matrix.DecompressIntoFullMatrix(ped_matrix); ped->GetMatrix() = ped->GetMatrix() * CMatrix(1.0f - interpolation); - *ped->GetMatrix().GetPosition() *= (1.0f - interpolation); + ped->GetMatrix().GetPosition() *= (1.0f - interpolation); ped->GetMatrix() += CMatrix(interpolation) * ped_matrix; if (pp->vehicle_index) { ped->m_pMyVehicle = CPools::GetVehiclePool()->GetSlot(pp->vehicle_index - 1); @@ -666,7 +666,7 @@ void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressI CMatrix vehicle_matrix; vp->matrix.DecompressIntoFullMatrix(vehicle_matrix); vehicle->GetMatrix() = vehicle->GetMatrix() * CMatrix(1.0f - interpolation); - *vehicle->GetMatrix().GetPosition() *= (1.0f - interpolation); + vehicle->GetMatrix().GetPosition() *= (1.0f - interpolation); vehicle->GetMatrix() += CMatrix(interpolation) * vehicle_matrix; vehicle->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); vehicle->m_fHealth = 4 * vp->health; @@ -847,7 +847,7 @@ bool CReplay::PlayBackThisFrameInterpolation(CAddressInReplayBuffer *buffer, flo { tGeneralPacket* pg = (tGeneralPacket*)&ptr[offset]; TheCamera.GetMatrix() = TheCamera.GetMatrix() * CMatrix(split); - *TheCamera.GetMatrix().GetPosition() *= split; + TheCamera.GetMatrix().GetPosition() *= split; TheCamera.GetMatrix() += CMatrix(interpolation) * pg->camera_pos; RwMatrix* pm = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); pm->pos = *(RwV3d*)TheCamera.GetMatrix().GetPosition(); @@ -979,34 +979,34 @@ void CReplay::ProcessReplayCamera(void) switch (CameraMode) { case REPLAYCAMMODE_TOPDOWN: { - *TheCamera.GetMatrix().GetPosition() = CVector(CameraFocusX, CameraFocusY, CameraFocusZ + 15.0f); - *TheCamera.GetMatrix().GetForward() = CVector(0.0f, 0.0f, -1.0f); - *TheCamera.GetMatrix().GetUp() = CVector(0.0f, 1.0f, 0.0f); - *TheCamera.GetMatrix().GetRight() = CVector(1.0f, 0.0f, 0.0f); + TheCamera.GetMatrix().GetPosition() = CVector(CameraFocusX, CameraFocusY, CameraFocusZ + 15.0f); + TheCamera.GetMatrix().GetForward() = CVector(0.0f, 0.0f, -1.0f); + TheCamera.GetMatrix().GetUp() = CVector(0.0f, 1.0f, 0.0f); + TheCamera.GetMatrix().GetRight() = CVector(1.0f, 0.0f, 0.0f); RwMatrix* pm = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); - pm->pos = *(RwV3d*)TheCamera.GetMatrix().GetPosition(); - pm->at = *(RwV3d*)TheCamera.GetMatrix().GetForward(); - pm->up = *(RwV3d*)TheCamera.GetMatrix().GetUp(); - pm->right = *(RwV3d*)TheCamera.GetMatrix().GetRight(); + pm->pos = *(RwV3d*)&TheCamera.GetMatrix().GetPosition(); + pm->at = *(RwV3d*)&TheCamera.GetMatrix().GetForward(); + pm->up = *(RwV3d*)&TheCamera.GetMatrix().GetUp(); + pm->right = *(RwV3d*)&TheCamera.GetMatrix().GetRight(); break; } case REPLAYCAMMODE_FIXED: { - *TheCamera.GetMatrix().GetPosition() = CVector(CameraFixedX, CameraFixedY, CameraFixedZ); + TheCamera.GetMatrix().GetPosition() = CVector(CameraFixedX, CameraFixedY, CameraFixedZ); CVector forward(CameraFocusX - CameraFixedX, CameraFocusY - CameraFixedY, CameraFocusZ - CameraFixedZ); forward.Normalise(); CVector right = CrossProduct(CVector(0.0f, 0.0f, 1.0f), forward); right.Normalise(); CVector up = CrossProduct(forward, right); up.Normalise(); - *TheCamera.GetMatrix().GetForward() = forward; - *TheCamera.GetMatrix().GetUp() = up; - *TheCamera.GetMatrix().GetRight() = right; + TheCamera.GetMatrix().GetForward() = forward; + TheCamera.GetMatrix().GetUp() = up; + TheCamera.GetMatrix().GetRight() = right; RwMatrix* pm = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); - pm->pos = *(RwV3d*)TheCamera.GetMatrix().GetPosition(); - pm->at = *(RwV3d*)TheCamera.GetMatrix().GetForward(); - pm->up = *(RwV3d*)TheCamera.GetMatrix().GetUp(); - pm->right = *(RwV3d*)TheCamera.GetMatrix().GetRight(); + pm->pos = *(RwV3d*)&TheCamera.GetMatrix().GetPosition(); + pm->at = *(RwV3d*)&TheCamera.GetMatrix().GetForward(); + pm->up = *(RwV3d*)&TheCamera.GetMatrix().GetUp(); + pm->right = *(RwV3d*)&TheCamera.GetMatrix().GetRight(); break; } default: @@ -1189,7 +1189,7 @@ void CReplay::RestoreStuffFromMem(void) CMatrix tmp1; tmp1.Attach(RwFrameGetMatrix(dodo->m_aCarNodes[CAR_WHEEL_RF]), false); CMatrix tmp2(RwFrameGetMatrix(dodo->m_aCarNodes[CAR_WHEEL_LF]), false); - *tmp1.GetPosition() += CVector(tmp2.GetPosition()->x + 0.1f, 0.0f, tmp2.GetPosition()->z); + tmp1.GetPosition() += CVector(tmp2.GetPosition().x + 0.1f, 0.0f, tmp2.GetPosition().z); tmp1.UpdateRW(); } if (vehicle->IsCar()){ @@ -1525,15 +1525,15 @@ void CReplay::ProcessLookAroundCam(void) right.Normalise(); CVector up = CrossProduct(forward, right); up.Normalise(); - *TheCamera.GetMatrix().GetForward() = forward; - *TheCamera.GetMatrix().GetUp() = up; - *TheCamera.GetMatrix().GetRight() = right; - *TheCamera.GetMatrix().GetPosition() = camera_pt; + TheCamera.GetMatrix().GetForward() = forward; + TheCamera.GetMatrix().GetUp() = up; + TheCamera.GetMatrix().GetRight() = right; + TheCamera.GetMatrix().GetPosition() = camera_pt; RwMatrix* pm = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); - pm->pos = *(RwV3d*)TheCamera.GetMatrix().GetPosition(); - pm->at = *(RwV3d*)TheCamera.GetMatrix().GetForward(); - pm->up = *(RwV3d*)TheCamera.GetMatrix().GetUp(); - pm->right = *(RwV3d*)TheCamera.GetMatrix().GetRight(); + pm->pos = *(RwV3d*)&TheCamera.GetMatrix().GetPosition(); + pm->at = *(RwV3d*)&TheCamera.GetMatrix().GetForward(); + pm->up = *(RwV3d*)&TheCamera.GetMatrix().GetUp(); + pm->right = *(RwV3d*)&TheCamera.GetMatrix().GetRight(); TheCamera.CalculateDerivedValues(); RwMatrixUpdate(RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera))); RwFrameUpdateObjects(RwCameraGetFrame(TheCamera.m_pRwCamera)); diff --git a/src/core/Placeable.h b/src/core/Placeable.h index bd1d50ab..1dfece69 100644 --- a/src/core/Placeable.h +++ b/src/core/Placeable.h @@ -10,10 +10,10 @@ public: CPlaceable(void); virtual ~CPlaceable(void); - CVector &GetPosition(void) { return *m_matrix.GetPosition(); } - CVector &GetRight(void) { return *m_matrix.GetRight(); } - CVector &GetForward(void) { return *m_matrix.GetForward(); } - CVector &GetUp(void) { return *m_matrix.GetUp(); } + CVector &GetPosition(void) { return m_matrix.GetPosition(); } + CVector &GetRight(void) { return m_matrix.GetRight(); } + CVector &GetForward(void) { return m_matrix.GetForward(); } + CVector &GetUp(void) { return m_matrix.GetUp(); } CMatrix &GetMatrix(void) { return m_matrix; } void SetTransform(RwMatrix *m) { m_matrix = CMatrix(m, false); } void SetHeading(float angle); diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 105f14c3..d562ced5 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -632,7 +632,7 @@ CEntity::ProcessLightsForEntity(void) lightOn = true; else lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>1 ^ m_randomSeed) & 3) + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed) & 3) lightOn = true; break; case LIGHT_FLICKER_NIGHT: @@ -641,7 +641,7 @@ CEntity::ProcessLightsForEntity(void) lightOn = true; else lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>1 ^ m_randomSeed) & 3) + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed) & 3) lightOn = true; } break; @@ -680,7 +680,7 @@ CEntity::ProcessLightsForEntity(void) lightOn = true; else lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>1 ^ m_randomSeed*8) & 3) + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed*8) & 3) lightOn = true; } break; @@ -693,7 +693,7 @@ CEntity::ProcessLightsForEntity(void) lightOn = true; else lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>1 ^ m_randomSeed*8) & 3) + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed*8) & 3) lightOn = true; } } @@ -815,8 +815,8 @@ CEntity::ModifyMatrixForTreeInWind(void) strength = 0.005f; } - mat.GetUp()->x = strength * flutter; - mat.GetUp()->y = mat.GetUp()->x; + mat.GetUp().x = strength * flutter; + mat.GetUp().y = mat.GetUp().x; mat.UpdateRW(); UpdateRwFrame(); @@ -847,7 +847,7 @@ CEntity::ModifyMatrixForBannerInWind(void) else strength = 0.66f; - t = ((int)(GetMatrix().GetPosition()->x + GetMatrix().GetPosition()->y) << 10) + 16*CTimer::GetTimeInMilliseconds(); + t = ((int)(GetMatrix().GetPosition().x + GetMatrix().GetPosition().y) << 10) + 16*CTimer::GetTimeInMilliseconds(); f = (t & 0x7FF)/(float)0x800; flutter = f * BannerWindTabel[(t>>11)+1 & 0x1F] + (1.0f - f) * BannerWindTabel[(t>>11) & 0x1F]; diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index 3d45bf52..b2512ec2 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -1883,7 +1883,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && m_vecMoveSpeed.z == 0.0f && !ped->m_ped_flagA2 && ped->bIsStanding) - savedMatrix.GetPosition()->z = GetPosition().z; + savedMatrix.GetPosition().z = GetPosition().z; GetMatrix() = savedMatrix; CTimer::SetTimeStep(savedTimeStep); return; @@ -1891,7 +1891,7 @@ CPhysical::ProcessCollision(void) if(IsPed() && m_vecMoveSpeed.z == 0.0f && !ped->m_ped_flagA2 && ped->bIsStanding) - savedMatrix.GetPosition()->z = GetPosition().z; + savedMatrix.GetPosition().z = GetPosition().z; GetMatrix() = savedMatrix; CTimer::SetTimeStep(savedTimeStep); if(IsVehicle()){ diff --git a/src/math/Matrix.h b/src/math/Matrix.h index 5cc7d12f..eda75e4a 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -78,10 +78,10 @@ public: return *this; } - CVector *GetPosition(void){ return (CVector*)&m_matrix.pos; } - CVector *GetRight(void) { return (CVector*)&m_matrix.right; } - CVector *GetForward(void) { return (CVector*)&m_matrix.up; } - CVector *GetUp(void) { return (CVector*)&m_matrix.at; } + CVector &GetPosition(void){ return *(CVector*)&m_matrix.pos; } + CVector &GetRight(void) { return *(CVector*)&m_matrix.right; } + CVector &GetForward(void) { return *(CVector*)&m_matrix.up; } + CVector &GetUp(void) { return *(CVector*)&m_matrix.at; } void SetScale(float s){ m_matrix.right.x = s; m_matrix.right.y = 0.0f; @@ -190,9 +190,9 @@ public: m_matrix.pos.z = 0.0f; } void Reorthogonalise(void){ - CVector &r = *GetRight(); - CVector &f = *GetForward(); - CVector &u = *GetUp(); + CVector &r = GetRight(); + CVector &f = GetForward(); + CVector &u = GetUp(); u = CrossProduct(r, f); u.Normalise(); r = CrossProduct(f, u); @@ -327,24 +327,24 @@ class CCompressedMatrixNotAligned public: void CompressFromFullMatrix(CMatrix &other) { - m_rightX = 127.0f * other.GetRight()->x; - m_rightY = 127.0f * other.GetRight()->y; - m_rightZ = 127.0f * other.GetRight()->z; - m_upX = 127.0f * other.GetForward()->x; - m_upY = 127.0f * other.GetForward()->y; - m_upZ = 127.0f * other.GetForward()->z; - m_vecPos = *other.GetPosition(); + m_rightX = 127.0f * other.GetRight().x; + m_rightY = 127.0f * other.GetRight().y; + m_rightZ = 127.0f * other.GetRight().z; + m_upX = 127.0f * other.GetForward().x; + m_upY = 127.0f * other.GetForward().y; + m_upZ = 127.0f * other.GetForward().z; + m_vecPos = other.GetPosition(); } void DecompressIntoFullMatrix(CMatrix &other) { - other.GetRight()->x = m_rightX / 127.0f; - other.GetRight()->y = m_rightY / 127.0f; - other.GetRight()->z = m_rightZ / 127.0f; - other.GetForward()->x = m_upX / 127.0f; - other.GetForward()->y = m_upY / 127.0f; - other.GetForward()->z = m_upZ / 127.0f; - *other.GetUp() = CrossProduct(*other.GetRight(), *other.GetForward()); - *other.GetPosition() = m_vecPos; + other.GetRight().x = m_rightX / 127.0f; + other.GetRight().y = m_rightY / 127.0f; + other.GetRight().z = m_rightZ / 127.0f; + other.GetForward().x = m_upX / 127.0f; + other.GetForward().y = m_upY / 127.0f; + other.GetForward().z = m_upZ / 127.0f; + other.GetUp() = CrossProduct(other.GetRight(), other.GetForward()); + other.GetPosition() = m_vecPos; other.Reorthogonalise(); } -}; \ No newline at end of file +}; diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 20f26688..692fc4f2 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -63,7 +63,7 @@ CPed::~CPed(void) CWorld::Remove(this); CRadar::ClearBlipForEntity(BLIP_CHAR, CPools::GetPedPool()->GetIndex(this)); if (bInVehicle && m_pMyVehicle){ - uint8 door_flag = GetVehEnterExitFlag(m_vehEnterType); + uint8 door_flag = GetVehDoorFlag(m_vehEnterType); if (m_pMyVehicle->pDriver == this) m_pMyVehicle->pDriver = nil; else { @@ -309,7 +309,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) m_fRotationCur = 0.0f; m_headingRate = 15.0f; m_fRotationDest = 0.0f; - m_vehEnterType = VEHICLE_ENTER_FRONT_LEFT; + m_vehEnterType = CAR_DOOR_LF; m_walkAroundType = 0; m_pCurrentPhysSurface = nil; m_vecOffsetFromPhysSurface = CVector(0.0f, 0.0f, 0.0f); @@ -1334,7 +1334,7 @@ CPed::BeingDraggedFromCar(void) if (animAssoc) animAssoc->blendDelta = -1000.0f; - if (m_vehEnterType == VEHICLE_ENTER_FRONT_LEFT || m_vehEnterType == VEHICLE_ENTER_REAR_LEFT) { + if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR) { if (m_ped_flagF10) { enterAnim = ANIM_CAR_QJACKED; } else if (m_pMyVehicle->bLowVehicle) { @@ -1342,7 +1342,7 @@ CPed::BeingDraggedFromCar(void) } else { enterAnim = ANIM_CAR_JACKED_LHS; } - } else if (m_vehEnterType == VEHICLE_ENTER_FRONT_RIGHT || m_vehEnterType == VEHICLE_ENTER_REAR_RIGHT) { + } else if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) { if (m_pMyVehicle->bLowVehicle) enterAnim = ANIM_CAR_LJACKED_RHS; else @@ -1396,7 +1396,7 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg) ped->m_pSeekTarget = nil; vehicle = ped->m_pMyVehicle; - vehicle->m_nGettingOutFlags &= ~GetVehEnterExitFlag(ped->m_vehEnterType); + vehicle->m_nGettingOutFlags &= ~GetVehDoorFlag(ped->m_vehEnterType); if (vehicle->pDriver == ped) { vehicle->RemoveDriver(); @@ -1448,7 +1448,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enter float seatOffset; vehModel = (CVehicleModelInfo*) CModelInfo::GetModelInfo(veh->m_modelIndex); - if (veh->bIsVan && (enterType == VEHICLE_ENTER_REAR_LEFT || enterType == VEHICLE_ENTER_REAR_RIGHT)) { + if (veh->bIsVan && (enterType == CAR_DOOR_LR || enterType == CAR_DOOR_RR)) { seatOffset = 0.0f; vehDoorOffset = offsetToOpenVanDoor; } else { @@ -1461,7 +1461,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enter } switch (enterType) { - case VEHICLE_ENTER_FRONT_RIGHT: + case CAR_DOOR_RF: if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_BOAT_RUDDER]; else @@ -1471,13 +1471,13 @@ CPed::GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enter vehDoorOffset.x = -vehDoorOffset.x; break; - case VEHICLE_ENTER_REAR_RIGHT: + case CAR_DOOR_RR: vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_REAR_SEATS]; vehDoorPos.x += seatOffset; vehDoorOffset.x = -vehDoorOffset.x; break; - case VEHICLE_ENTER_FRONT_LEFT: + case CAR_DOOR_LF: if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_BOAT_RUDDER]; else @@ -1486,7 +1486,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVector *output, CVehicle *veh, uint32 enter vehDoorPos.x = -(vehDoorPos.x + seatOffset); break; - case VEHICLE_ENTER_REAR_LEFT: + case CAR_DOOR_LR: vehDoorPos = vehModel->m_positions[VEHICLE_DUMMY_REAR_SEATS]; vehDoorPos.x = -(vehDoorPos.x + seatOffset); break; @@ -1584,7 +1584,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) if (veh->GetUp().z <= -0.8f) vehIsUpsideDown = true; - if (m_vehEnterType == VEHICLE_ENTER_FRONT_RIGHT || m_vehEnterType == VEHICLE_ENTER_REAR_RIGHT) { + if (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR) { if (vehIsUpsideDown) { m_fRotationDest = -PI + veh->GetForward().Heading(); } else if (veh->bIsBus) { @@ -1592,7 +1592,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) } else { m_fRotationDest = veh->GetForward().Heading(); } - } else if (m_vehEnterType == VEHICLE_ENTER_FRONT_LEFT || m_vehEnterType == VEHICLE_ENTER_REAR_LEFT) { + } else if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR) { if (vehIsUpsideDown) { m_fRotationDest = veh->GetForward().Heading(); } else if (veh->bIsBus) { @@ -1763,7 +1763,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) CMatrix vehDoorMat(veh->GetMatrix()); GetLocalPositionToOpenCarDoor(&output, veh, m_vehEnterType, 0.0f); - *vehDoorMat.GetPosition() += Multiply3x3(vehDoorMat, output); + vehDoorMat.GetPosition() += Multiply3x3(vehDoorMat, output); GetMatrix() = vehDoorMat; } @@ -2696,7 +2696,7 @@ CPed::QuitEnteringCar(void) if (veh->m_nNumGettingIn != 0) veh->m_nNumGettingIn--; - veh->m_nGettingInFlags = GetVehEnterExitFlag(m_vehEnterType); + veh->m_nGettingInFlags = GetVehDoorFlag(m_vehEnterType); } bUsesCollision = true; diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 6b04404b..2390d1d4 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -76,13 +76,6 @@ enum eObjective : uint32 { OBJECTIVE_35 }; -enum eVehEnter : uint16 { - VEHICLE_ENTER_FRONT_RIGHT = 11, - VEHICLE_ENTER_REAR_RIGHT = 12, - VEHICLE_ENTER_FRONT_LEFT = 15, - VEHICLE_ENTER_REAR_LEFT = 16, -}; - enum { RANDOM_CHAR = 1, MISSION_CHAR, @@ -321,7 +314,7 @@ public: float m_fRotationCur; float m_fRotationDest; float m_headingRate; - eVehEnter m_vehEnterType; + uint16 m_vehEnterType; uint16 m_walkAroundType; CEntity *m_pCurrentPhysSurface; CVector m_vecOffsetFromPhysSurface; @@ -526,20 +519,6 @@ public: CWeapon &GetWeapon(uint8 weaponType) { return m_weapons[weaponType]; } CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } RwFrame *GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; } - static uint8 GetVehEnterExitFlag(eVehEnter vehEnter) { - switch (vehEnter) { - case VEHICLE_ENTER_FRONT_RIGHT: - return 4; - case VEHICLE_ENTER_REAR_RIGHT: - return 8; - case VEHICLE_ENTER_FRONT_LEFT: - return 1; - case VEHICLE_ENTER_REAR_LEFT: - return 2; - default: - return 0; - } - } PedState GetPedState(void) { return m_nPedState; } void SetPedState(PedState state) { m_nPedState = state; } diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 23fa8ba0..c06c958c 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -1,6 +1,7 @@ #include "common.h" #include "patcher.h" #include "VisibilityPlugins.h" +#include "SurfaceTable.h" #include "HandlingMgr.h" #include "Automobile.h" @@ -55,7 +56,7 @@ CAutomobile::SetComponentRotation(int32 component, CVector rotation) mat.SetRotateX(DEGTORAD(rotation.x)); mat.SetRotateY(DEGTORAD(rotation.y)); mat.SetRotateZ(DEGTORAD(rotation.z)); - *mat.GetPosition() += pos; + mat.GetPosition() += pos; mat.UpdateRW(); } @@ -106,7 +107,38 @@ CAutomobile::RemoveRefsToVehicle(CEntity *ent) } WRAPPER void CAutomobile::BlowUpCar(CEntity *ent) { EAXJMP(0x53BC60); } -WRAPPER bool CAutomobile::SetUpWheelColModel(CColModel *colModel) { EAXJMP(0x53BF70); } + +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; +} + WRAPPER void CAutomobile::BurstTyre(uint8 tyre) { EAXJMP(0x53C0E0); } WRAPPER bool CAutomobile::IsRoomForPedToLeaveCar(uint32, CVector *) { EAXJMP(0x53C5B0); } @@ -285,7 +317,7 @@ public: 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) { CAutomobile::SetUpWheelColModel(colModel); } + 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(); } @@ -303,6 +335,7 @@ STARTPATCHES InjectHook(0x52EFD0, &CAutomobile_::IsDoorClosed_, PATCH_JUMP); InjectHook(0x52F000, &CAutomobile_::IsDoorMissing_, PATCH_JUMP); InjectHook(0x53BF40, &CAutomobile_::RemoveRefsToVehicle_, PATCH_JUMP); + InjectHook(0x53BF70, &CAutomobile_::SetUpWheelColModel_, PATCH_JUMP); InjectHook(0x437690, &CAutomobile_::GetHeightAboveRoad_, PATCH_JUMP); InjectHook(0x5301A0, &CAutomobile::SetPanelDamage, PATCH_JUMP); InjectHook(0x530120, &CAutomobile::SetBumperDamage, PATCH_JUMP); diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h index 0f9003db..1e70d171 100644 --- a/src/vehicles/Vehicle.h +++ b/src/vehicles/Vehicle.h @@ -88,6 +88,14 @@ enum eLights VEHLIGHT_REAR_RIGHT, }; +enum +{ + CAR_PIECE_WHEEL_LF = 13, + CAR_PIECE_WHEEL_LR, + CAR_PIECE_WHEEL_RF, + CAR_PIECE_WHEEL_RR, +}; + class CVehicle : public CPhysical { public: @@ -250,3 +258,18 @@ static_assert(sizeof(CVehicle) == 0x288, "CVehicle: error"); static_assert(offsetof(CVehicle, m_pCurSurface) == 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; + } +}