some vehicle cleanup

This commit is contained in:
aap 2020-06-02 23:34:53 +02:00
parent 575c5466df
commit 04a91761df
10 changed files with 88 additions and 100 deletions

View file

@ -5,6 +5,7 @@
#include "World.h" #include "World.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "Automobile.h" #include "Automobile.h"
#include "Boat.h"
#include "Ped.h" #include "Ped.h"
#include "PlayerPed.h" #include "PlayerPed.h"
#include "CopPed.h" #include "CopPed.h"
@ -2732,7 +2733,7 @@ CCam::Process_1stPerson(const CVector &CameraTarget, float TargetOrientation, fl
}else{ }else{
assert(CamTargetEntity->IsVehicle()); assert(CamTargetEntity->IsVehicle());
CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(CamTargetEntity->GetModelIndex()); CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(CamTargetEntity->GetModelIndex());
CVector CamPos = mi->m_vehicleType == VEHICLE_TYPE_BOAT ? mi->m_positions[BOAT_POS_FRONTSEAT] : mi->m_positions[CAR_POS_FRONTSEAT]; CVector CamPos = mi->GetFrontSeatPosn();
CamPos.x = 0.0f; CamPos.x = 0.0f;
CamPos.y += -0.08f; CamPos.y += -0.08f;
CamPos.z += 0.62f; CamPos.z += 0.62f;

View file

@ -16,6 +16,7 @@
#include "Train.h" #include "Train.h"
#include "Plane.h" #include "Plane.h"
#include "Heli.h" #include "Heli.h"
#include "Bike.h"
#include "ModelIndices.h" #include "ModelIndices.h"
#include "ModelInfo.h" #include "ModelInfo.h"
@ -120,16 +121,16 @@ RwObjectNameIdAssocation planeIds[] = {
}; };
RwObjectNameIdAssocation bikeIds[] = { RwObjectNameIdAssocation bikeIds[] = {
{ "chassis_dummy", 1, 0 }, { "chassis_dummy", BIKE_CHASSIS, 0 },
{ "forks_front", 2, 0 }, { "forks_front", BIKE_FORKS_FRONT, 0 },
{ "forks_rear", 3, 0 }, { "forks_rear", BIKE_FORKS_REAR, 0 },
{ "wheel_front", 4, 0 }, { "wheel_front", BIKE_WHEEL_FRONT, 0 },
{ "wheel_rear", 5, 0 }, { "wheel_rear", BIKE_WHEEL_REAR, 0 },
{ "mudguard", 6, 0 }, { "mudguard", BIKE_MUDGUARD, 0 },
{ "ped_frontseat", 2, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID }, { "ped_frontseat", CAR_POS_FRONTSEAT, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
{ "headlights", 0, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID }, { "headlights", CAR_POS_HEADLIGHTS, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
{ "taillights", 1, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID }, { "taillights", CAR_POS_TAILLIGHTS, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
{ "exhaust", 9, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID }, { "exhaust", CAR_POS_EXHAUST, VEHICLE_FLAG_POS | CLUMP_FLAG_NO_HIERID },
{ "extra1", 0, VEHICLE_FLAG_DRAWLAST | VEHICLE_FLAG_COMP | CLUMP_FLAG_NO_HIERID }, { "extra1", 0, VEHICLE_FLAG_DRAWLAST | VEHICLE_FLAG_COMP | CLUMP_FLAG_NO_HIERID },
{ "extra2", 0, VEHICLE_FLAG_DRAWLAST | VEHICLE_FLAG_COMP | CLUMP_FLAG_NO_HIERID }, { "extra2", 0, VEHICLE_FLAG_DRAWLAST | VEHICLE_FLAG_COMP | CLUMP_FLAG_NO_HIERID },
{ "extra3", 0, VEHICLE_FLAG_DRAWLAST | VEHICLE_FLAG_COMP | CLUMP_FLAG_NO_HIERID }, { "extra3", 0, VEHICLE_FLAG_DRAWLAST | VEHICLE_FLAG_COMP | CLUMP_FLAG_NO_HIERID },

View file

@ -35,6 +35,43 @@ enum eVehicleType {
NUM_VEHICLE_TYPES NUM_VEHICLE_TYPES
}; };
enum eCarPositions
{
CAR_POS_HEADLIGHTS,
CAR_POS_TAILLIGHTS,
CAR_POS_FRONTSEAT,
CAR_POS_BACKSEAT,
// these are unused so we don't know the actual values
CAR_POS_REVERSELIGHTS,
CAR_POS_BRAKELIGHTS,
CAR_POS_INDICATORS_FRONT,
CAR_POS_INDICATORS_BACK,
CAR_POS_STEERWHEEL,
//
CAR_POS_EXHAUST
};
enum eBoatPositions
{
BOAT_POS_FRONTSEAT
};
enum eTrainPositions
{
TRAIN_POS_LIGHT_FRONT,
TRAIN_POS_LIGHT_REAR,
TRAIN_POS_LEFT_ENTRY,
TRAIN_POS_MID_ENTRY,
TRAIN_POS_RIGHT_ENTRY
};
enum ePlanePositions
{
PLANE_POS_LIGHT_LEFT,
PLANE_POS_LIGHT_RIGHT,
PLANE_POS_LIGHT_TAIL,
};
enum { enum {
NUM_VEHICLE_POSITIONS = 10 NUM_VEHICLE_POSITIONS = 10
}; };
@ -100,6 +137,7 @@ public:
void SetVehicleComponentFlags(RwFrame *frame, uint32 flags); void SetVehicleComponentFlags(RwFrame *frame, uint32 flags);
void PreprocessHierarchy(void); void PreprocessHierarchy(void);
void GetWheelPosn(int32 n, CVector &pos); void GetWheelPosn(int32 n, CVector &pos);
CVector &GetFrontSeatPosn(void) { return m_positions[m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; };
int32 ChooseComponent(void); int32 ChooseComponent(void);
int32 ChooseSecondComponent(void); int32 ChooseSecondComponent(void);

View file

@ -1682,11 +1682,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float seatP
switch (component) { switch (component) {
case CAR_DOOR_RF: case CAR_DOOR_RF:
if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) vehDoorPos = vehModel->GetFrontSeatPosn();
vehDoorPos = vehModel->m_positions[BOAT_POS_FRONTSEAT];
else
vehDoorPos = vehModel->m_positions[CAR_POS_FRONTSEAT];
vehDoorPos.x += seatOffset; vehDoorPos.x += seatOffset;
vehDoorOffset.x = -vehDoorOffset.x; vehDoorOffset.x = -vehDoorOffset.x;
break; break;
@ -1698,11 +1694,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float seatP
break; break;
case CAR_DOOR_LF: case CAR_DOOR_LF:
if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) vehDoorPos = vehModel->GetFrontSeatPosn();
vehDoorPos = vehModel->m_positions[BOAT_POS_FRONTSEAT];
else
vehDoorPos = vehModel->m_positions[CAR_POS_FRONTSEAT];
vehDoorPos.x = -(vehDoorPos.x + seatOffset); vehDoorPos.x = -(vehDoorPos.x + seatOffset);
break; break;
@ -1712,11 +1704,7 @@ CPed::GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float seatP
break; break;
default: default:
if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) vehDoorPos = vehModel->GetFrontSeatPosn();
vehDoorPos = vehModel->m_positions[BOAT_POS_FRONTSEAT];
else
vehDoorPos = vehModel->m_positions[CAR_POS_FRONTSEAT];
vehDoorOffset = CVector(0.0f, 0.0f, 0.0f); vehDoorOffset = CVector(0.0f, 0.0f, 0.0f);
} }
return vehDoorPos - vehDoorOffset; return vehDoorPos - vehDoorOffset;
@ -15031,11 +15019,7 @@ CPed::SeekBoatPosition(void)
CVehicleModelInfo *boatModel = m_carInObjective->GetModelInfo(); CVehicleModelInfo *boatModel = m_carInObjective->GetModelInfo();
CVector enterOffset; CVector enterOffset;
if (boatModel->m_vehicleType == VEHICLE_TYPE_BOAT) enterOffset = boatModel->GetFrontSeatPosn();
enterOffset = boatModel->m_positions[BOAT_POS_FRONTSEAT];
else
enterOffset = boatModel->m_positions[CAR_POS_FRONTSEAT];
enterOffset.x = 0.0f; enterOffset.x = 0.0f;
CMatrix boatMat(m_carInObjective->GetMatrix()); CMatrix boatMat(m_carInObjective->GetMatrix());
SetMoveState(PEDMOVE_WALK); SetMoveState(PEDMOVE_WALK);
@ -16817,29 +16801,20 @@ CPed::SetPedPositionInCar(void)
CMatrix newMat(m_pMyVehicle->GetMatrix()); CMatrix newMat(m_pMyVehicle->GetMatrix());
CVector seatPos; CVector seatPos;
if (m_pMyVehicle->pDriver == this) { if (m_pMyVehicle->pDriver == this) {
if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) seatPos = vehModel->GetFrontSeatPosn();
seatPos = vehModel->m_positions[BOAT_POS_FRONTSEAT];
else
seatPos = vehModel->m_positions[CAR_POS_FRONTSEAT];
if (!m_pMyVehicle->IsBoat() && m_pMyVehicle->m_vehType != VEHICLE_TYPE_BIKE) if (!m_pMyVehicle->IsBoat() && m_pMyVehicle->m_vehType != VEHICLE_TYPE_BIKE)
seatPos.x = -seatPos.x; seatPos.x = -seatPos.x;
} else if (m_pMyVehicle->pPassengers[0] == this) { } else if (m_pMyVehicle->pPassengers[0] == this) {
if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) seatPos = vehModel->GetFrontSeatPosn();
seatPos = vehModel->m_positions[BOAT_POS_FRONTSEAT];
else
seatPos = vehModel->m_positions[CAR_POS_FRONTSEAT];
} else if (m_pMyVehicle->pPassengers[1] == this) { } else if (m_pMyVehicle->pPassengers[1] == this) {
seatPos = vehModel->m_positions[CAR_POS_BACKSEAT]; seatPos = vehModel->m_positions[CAR_POS_BACKSEAT];
seatPos.x = -seatPos.x; seatPos.x = -seatPos.x;
} else { } else {
if (m_pMyVehicle->pPassengers[2] == this) { if (m_pMyVehicle->pPassengers[2] == this) {
seatPos = vehModel->m_positions[CAR_POS_BACKSEAT]; seatPos = vehModel->m_positions[CAR_POS_BACKSEAT];
} else if (vehModel->m_vehicleType == VEHICLE_TYPE_BOAT) {
seatPos = vehModel->m_positions[BOAT_POS_FRONTSEAT];
} else { } else {
seatPos = vehModel->m_positions[CAR_POS_FRONTSEAT]; seatPos = vehModel->GetFrontSeatPosn();
} }
} }
newMat.GetPosition() += Multiply3x3(newMat, seatPos); newMat.GetPosition() += Multiply3x3(newMat, seatPos);

View file

@ -145,8 +145,7 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
for(i = 0; i < 4; i++){ for(i = 0; i < 4; i++){
m_aGroundPhysical[i] = nil; m_aGroundPhysical[i] = nil;
m_aGroundOffset[i] = CVector(0.0f, 0.0f, 0.0f); m_aGroundOffset[i] = CVector(0.0f, 0.0f, 0.0f);
m_aSuspensionSpringRatio[i] = 1.0f; m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i] = 1.0f;
m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i];
m_aWheelTimer[i] = 0.0f; m_aWheelTimer[i] = 0.0f;
m_aWheelRotation[i] = 0.0f; m_aWheelRotation[i] = 0.0f;
m_aWheelSpeed[i] = 0.0f; m_aWheelSpeed[i] = 0.0f;
@ -2314,6 +2313,17 @@ CAutomobile::ProcessControlInputs(uint8 pad)
m_fSteerAngle = DEGTORAD(pHandling->fSteeringLock) * fValue; m_fSteerAngle = DEGTORAD(pHandling->fSteeringLock) * fValue;
if(bComedyControls){ if(bComedyControls){
#if 0 // old comedy controls from PS2 - same as bike's
if(((CTimer::GetTimeInMilliseconds() >> 10) & 0xF) < 12)
m_fGasPedal = 1.0f;
if((((CTimer::GetTimeInMilliseconds() >> 10)+6) & 0xF) < 12)
m_fBrakePedal = 0.0f;
bIsHandbrakeOn = false;
if(CTimer::GetTimeInMilliseconds() & 0x800)
m_fSteerAngle += 0.08f;
else
m_fSteerAngle -= 0.03f;
#else
int rnd = CGeneral::GetRandomNumber() % 10; int rnd = CGeneral::GetRandomNumber() % 10;
switch(m_comedyControlState){ switch(m_comedyControlState){
case 0: case 0:
@ -2333,8 +2343,10 @@ CAutomobile::ProcessControlInputs(uint8 pad)
m_comedyControlState = 0; m_comedyControlState = 0;
break; break;
} }
}else }else{
m_comedyControlState = 0; m_comedyControlState = 0;
#endif
}
// Brake if player isn't in control // Brake if player isn't in control
// BUG: game always uses pad 0 here // BUG: game always uses pad 0 here
@ -3948,8 +3960,8 @@ CAutomobile::BurstTyre(uint8 wheel)
CCarCtrl::SwitchVehicleToRealPhysics(this); CCarCtrl::SwitchVehicleToRealPhysics(this);
} }
ApplyMoveForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f)); ApplyMoveForce(GetRight() * m_fMass * CGeneral::GetRandomNumberInRange(-0.03f, 0.03f));
ApplyTurnForce(GetRight() * CGeneral::GetRandomNumberInRange(-0.3f, 0.3f), GetForward()); ApplyTurnForce(GetRight() * m_fTurnMass * CGeneral::GetRandomNumberInRange(-0.03f, 0.03f), GetForward());
} }
} }
@ -3964,10 +3976,10 @@ CAutomobile::IsRoomForPedToLeaveCar(uint32 component, CVector *doorOffset)
CVector seatPos; CVector seatPos;
switch(component){ switch(component){
case CAR_DOOR_RF: case CAR_DOOR_RF:
seatPos = mi->m_positions[mi->m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; seatPos = mi->GetFrontSeatPosn();
break; break;
case CAR_DOOR_LF: case CAR_DOOR_LF:
seatPos = mi->m_positions[mi->m_vehicleType == VEHICLE_TYPE_BOAT ? BOAT_POS_FRONTSEAT : CAR_POS_FRONTSEAT]; seatPos = mi->GetFrontSeatPosn();
seatPos.x = -seatPos.x; seatPos.x = -seatPos.x;
break; break;
case CAR_DOOR_RR: case CAR_DOOR_RR:
@ -4558,7 +4570,7 @@ CAutomobile::SetupModelNodes(void)
int i; int i;
for(i = 0; i < NUM_CAR_NODES; i++) for(i = 0; i < NUM_CAR_NODES; i++)
m_aCarNodes[i] = nil; m_aCarNodes[i] = nil;
CClumpModelInfo::FillFrameArray((RpClump*)m_rwObject, m_aCarNodes); CClumpModelInfo::FillFrameArray(GetClump(), m_aCarNodes);
} }
void void

View file

@ -30,22 +30,6 @@ enum eCarNodes
NUM_CAR_NODES, NUM_CAR_NODES,
}; };
enum eCarPositions
{
CAR_POS_HEADLIGHTS,
CAR_POS_TAILLIGHTS,
CAR_POS_FRONTSEAT,
CAR_POS_BACKSEAT,
// these are unused so we don't know the actual values
CAR_POS_REVERSELIGHTS,
CAR_POS_BRAKELIGHTS,
CAR_POS_INDICATORS_FRONT,
CAR_POS_INDICATORS_BACK,
CAR_POS_STEERWHEEL,
//
CAR_POS_EXHAUST
};
// These are used for all the wheel arrays // These are used for all the wheel arrays
// DON'T confuse with VEHWHEEL, which are vehicle components // DON'T confuse with VEHWHEEL, which are vehicle components
enum { enum {

View file

@ -9,13 +9,6 @@ enum ePlaneNodes
NUM_PLANE_NODES NUM_PLANE_NODES
}; };
enum ePlanePositions
{
PLANE_POS_LIGHT_LEFT,
PLANE_POS_LIGHT_RIGHT,
PLANE_POS_LIGHT_TAIL,
};
struct CPlaneNode struct CPlaneNode
{ {
CVector p; // position CVector p; // position

View file

@ -24,15 +24,6 @@ enum eTrainNodes
NUM_TRAIN_NODES NUM_TRAIN_NODES
}; };
enum eTrainPositions
{
TRAIN_POS_LIGHT_FRONT,
TRAIN_POS_LIGHT_REAR,
TRAIN_POS_LEFT_ENTRY,
TRAIN_POS_MID_ENTRY,
TRAIN_POS_RIGHT_ENTRY
};
struct CTrainNode struct CTrainNode
{ {
CVector p; // position CVector p; // position

View file

@ -28,12 +28,6 @@ enum eCarLock {
CARLOCK_SKIP_SHUT_DOORS CARLOCK_SKIP_SHUT_DOORS
}; };
enum
{
BOAT_POS_FRONTSEAT
};
enum eDoors enum eDoors
{ {
DOOR_BONNET = 0, DOOR_BONNET = 0,

View file

@ -25,7 +25,8 @@
#include "Stats.h" #include "Stats.h"
#include "TempColModels.h" #include "TempColModels.h"
#include "Timer.h" #include "Timer.h"
#include "Vehicle.h" #include "Automobile.h"
#include "Boat.h"
#include "WaterLevel.h" #include "WaterLevel.h"
#include "WeaponInfo.h" #include "WeaponInfo.h"
#include "World.h" #include "World.h"
@ -1631,31 +1632,29 @@ CWeapon::FireInstantHitFromCar(CAutomobile *shooter, bool left)
CVehicleModelInfo *modelInfo = shooter->GetModelInfo(); CVehicleModelInfo *modelInfo = shooter->GetModelInfo();
#define FRONTSEATPOS() (&(shooter->IsBoat() ? modelInfo->m_positions[BOAT_POS_FRONTSEAT] : modelInfo->m_positions[CAR_POS_FRONTSEAT]))
CVector source, target; CVector source, target;
if ( left ) if ( left )
{ {
source = shooter->GetMatrix() * CVector(-shooter->GetColModel()->boundingBox.max.x + -0.2f, source = shooter->GetMatrix() * CVector(-shooter->GetColModel()->boundingBox.max.x + -0.2f,
float(CGeneral::GetRandomNumber() & 255) * 0.001f + FRONTSEATPOS()->y, float(CGeneral::GetRandomNumber() & 255) * 0.001f + modelInfo->GetFrontSeatPosn().y,
FRONTSEATPOS()->z + 0.5f); modelInfo->GetFrontSeatPosn().z + 0.5f);
source += CTimer::GetTimeStep() * shooter->m_vecMoveSpeed; source += CTimer::GetTimeStep() * shooter->m_vecMoveSpeed;
target = shooter->GetMatrix() * CVector(-info->m_fRange, target = shooter->GetMatrix() * CVector(-info->m_fRange,
FRONTSEATPOS()->y, modelInfo->GetFrontSeatPosn().y,
FRONTSEATPOS()->z + 0.5f); modelInfo->GetFrontSeatPosn().z + 0.5f);
} }
else else
{ {
source = shooter->GetMatrix() * CVector(shooter->GetColModel()->boundingBox.max.x + 0.2f, source = shooter->GetMatrix() * CVector(shooter->GetColModel()->boundingBox.max.x + 0.2f,
float(CGeneral::GetRandomNumber() & 255) * 0.001f + FRONTSEATPOS()->y, float(CGeneral::GetRandomNumber() & 255) * 0.001f + modelInfo->GetFrontSeatPosn().y,
FRONTSEATPOS()->z + 0.5f); modelInfo->GetFrontSeatPosn().z + 0.5f);
source += CTimer::GetTimeStep() * shooter->m_vecMoveSpeed; source += CTimer::GetTimeStep() * shooter->m_vecMoveSpeed;
target = shooter->GetMatrix() * CVector(info->m_fRange, target = shooter->GetMatrix() * CVector(info->m_fRange,
FRONTSEATPOS()->y, modelInfo->GetFrontSeatPosn().y,
FRONTSEATPOS()->z + 0.5f); modelInfo->GetFrontSeatPosn().z + 0.5f);
} }
#undef FRONTSEATPOS #undef FRONTSEATPOS