CVehicle fixes

This commit is contained in:
aap 2020-05-24 15:14:56 +02:00
parent e95de89c9a
commit 3fdd352ca2
4 changed files with 55 additions and 53 deletions

View file

@ -175,7 +175,7 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
m_nNumPassengers = 0; m_nNumPassengers = 0;
m_bombType = CARBOMB_NONE; m_bombType = CARBOMB_NONE;
bHadDriver = false; bDriverLastFrame = false;
m_pBombRigger = nil; m_pBombRigger = nil;
if(m_nDoorLock == CARLOCK_UNLOCKED && if(m_nDoorLock == CARLOCK_UNLOCKED &&
@ -276,7 +276,7 @@ CAutomobile::ProcessControl(void)
// Process driver // Process driver
if(pDriver){ if(pDriver){
if(!bHadDriver && m_bombType == CARBOMB_ONIGNITIONACTIVE){ if(!bDriverLastFrame && m_bombType == CARBOMB_ONIGNITIONACTIVE){
// If someone enters the car and there is a bomb, detonate // If someone enters the car and there is a bomb, detonate
m_nBombTimer = 1000; m_nBombTimer = 1000;
m_pBlowUpEntity = m_pBombRigger; m_pBlowUpEntity = m_pBombRigger;
@ -284,7 +284,7 @@ CAutomobile::ProcessControl(void)
m_pBlowUpEntity->RegisterReference((CEntity**)&m_pBlowUpEntity); m_pBlowUpEntity->RegisterReference((CEntity**)&m_pBlowUpEntity);
DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TICK, 1.0f); DMAudio.PlayOneShot(m_audioEntityId, SOUND_BOMB_TICK, 1.0f);
} }
bHadDriver = true; bDriverLastFrame = true;
if(IsUpsideDown() && CanPedEnterCar()){ if(IsUpsideDown() && CanPedEnterCar()){
if(!pDriver->IsPlayer() && if(!pDriver->IsPlayer() &&
@ -293,7 +293,7 @@ CAutomobile::ProcessControl(void)
pDriver->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this); pDriver->SetObjective(OBJECTIVE_LEAVE_VEHICLE, this);
} }
}else }else
bHadDriver = false; bDriverLastFrame = false;
// Process passengers // Process passengers
if(m_nNumPassengers != 0 && IsUpsideDown() && CanPedEnterCar()){ if(m_nNumPassengers != 0 && IsUpsideDown() && CanPedEnterCar()){
@ -3928,7 +3928,7 @@ CAutomobile::SetUpWheelColModel(CColModel *colModel)
if(m_aCarNodes[CAR_WHEEL_LM] != nil && m_aCarNodes[CAR_WHEEL_RM] != nil){ if(m_aCarNodes[CAR_WHEEL_LM] != nil && m_aCarNodes[CAR_WHEEL_RM] != nil){
mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM])); mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LM]));
colModel->spheres[4].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RF); colModel->spheres[4].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_LR);
mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM])); mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RM]));
colModel->spheres[5].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR); colModel->spheres[5].Set(mi->m_wheelScale, mat.GetPosition(), SURFACE_TIRE, CAR_PIECE_WHEEL_RR);
colModel->numSpheres = 6; colModel->numSpheres = 6;

View file

@ -86,7 +86,7 @@ public:
uint8 field_4D8; uint8 field_4D8;
uint8 m_bombType : 3; uint8 m_bombType : 3;
uint8 bTaxiLight : 1; uint8 bTaxiLight : 1;
uint8 bHadDriver : 1; // for bombs uint8 bDriverLastFrame : 1; // for bombs
uint8 bFixedColour : 1; uint8 bFixedColour : 1;
uint8 bBigWheels : 1; uint8 bBigWheels : 1;
uint8 bWaterTight : 1; // no damage for non-player peds uint8 bWaterTight : 1; // no damage for non-player peds

View file

@ -50,8 +50,8 @@ CVehicle::CVehicle(uint8 CreatedBy)
{ {
int i; int i;
m_nCurrentGear = 0; m_nCurrentGear = 1;
m_fChangeGearTime = 0; m_fChangeGearTime = 0.0f;
m_fSteerRatio = 0.0f; m_fSteerRatio = 0.0f;
m_type = ENTITY_TYPE_VEHICLE; m_type = ENTITY_TYPE_VEHICLE;
VehicleCreatedBy = CreatedBy; VehicleCreatedBy = CreatedBy;
@ -280,8 +280,8 @@ CVehicle::FlyingControl(eFlightModel flightModel)
float turnSpeed = m_vecTurnSpeed.MagnitudeSqr(); float turnSpeed = m_vecTurnSpeed.MagnitudeSqr();
if(turnSpeed > SQR(0.2f)) if(turnSpeed > SQR(0.2f))
m_vecTurnSpeed *= 0.2f/Sqrt(turnSpeed); m_vecTurnSpeed *= 0.2f/Sqrt(turnSpeed);
}
break; break;
}
case FLIGHT_MODEL_RCPLANE: case FLIGHT_MODEL_RCPLANE:
case FLIGHT_MODEL_SEAPLANE: case FLIGHT_MODEL_SEAPLANE:
@ -294,76 +294,77 @@ CVehicle::FlyingControl(eFlightModel flightModel)
fThrust += 1.0f; fThrust += 1.0f;
else if (fForwSpeed > 0.0f && fThrust < 0.0f) else if (fForwSpeed > 0.0f && fThrust < 0.0f)
fThrust = 0.0f; fThrust = 0.0f;
float fThrustImpulse; float fThrustAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
fThrustImpulse = (fThrust - fRCPropFallOff * fForwSpeed) * fRCAeroThrust; fThrustAccel = (fThrust - fRCPropFallOff * fForwSpeed) * fRCAeroThrust;
else else
fThrustImpulse = (fThrust - fSeaPropFallOff * fForwSpeed) * fSeaThrust; fThrustAccel = (fThrust - fSeaPropFallOff * fForwSpeed) * fSeaThrust;
ApplyMoveForce(fThrustImpulse * GetForward() * m_fMass * CTimer::GetTimeStep()); ApplyMoveForce(fThrustAccel * GetForward() * m_fMass * CTimer::GetTimeStep());
// left/right // left/right
float fSideSpeed = -DotProduct(GetMoveSpeed(), GetRight()); float fSideSpeed = -DotProduct(GetMoveSpeed(), GetRight());
float fSteerLR = CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f; float fSteerLR = CPad::GetPad(0)->GetSteeringLeftRight() / 128.0f;
float fSideSlipImpulse; float fSideSlipAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
fSideSlipImpulse = Abs(fSideSpeed) * fSideSpeed * fRCSideSlipMult; fSideSlipAccel = Abs(fSideSpeed) * fSideSpeed * fRCSideSlipMult;
else else
fSideSlipImpulse = Abs(fSideSpeed) * fSideSpeed * fSeaSideSlipMult; fSideSlipAccel = Abs(fSideSpeed) * fSideSpeed * fSeaSideSlipMult;
ApplyMoveForce(m_fMass * GetRight() * fSideSlipImpulse * CTimer::GetTimeStep()); ApplyMoveForce(m_fMass * GetRight() * fSideSlipAccel * CTimer::GetTimeStep());
float fYaw = -DotProduct(CrossProduct(m_vecTurnSpeed + m_vecTurnFriction, vecWidthForward) + m_vecMoveSpeed + m_vecMoveFriction, GetRight()); float fYaw = -DotProduct(GetSpeed(vecWidthForward), GetRight());
float fYawImpulse; float fYawAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
fYawImpulse = fRCRudderMult * fYaw * Abs(fYaw) + fRCYawMult * fSteerLR * fForwSpeed; fYawAccel = fRCRudderMult * fYaw * Abs(fYaw) + fRCYawMult * fSteerLR * fForwSpeed;
else else
fYawImpulse = fSeaRudderMult * fYaw * Abs(fYaw) + fSeaYawMult * fSteerLR * fForwSpeed; fYawAccel = fSeaRudderMult * fYaw * Abs(fYaw) + fSeaYawMult * fSteerLR * fForwSpeed;
ApplyTurnForce(fYawImpulse * GetRight() * m_fTurnMass * CTimer::GetTimeStep(), vecWidthForward); ApplyTurnForce(fYawAccel * GetRight() * m_fTurnMass * CTimer::GetTimeStep(), vecWidthForward);
float fRollImpulse; float fRollAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) { if (flightModel == FLIGHT_MODEL_RCPLANE) {
float fDirectionMultiplier = CPad::GetPad(0)->GetLookRight(); float fDirectionMultiplier = CPad::GetPad(0)->GetLookRight();
if (CPad::GetPad(0)->GetLookLeft()) if (CPad::GetPad(0)->GetLookLeft())
fDirectionMultiplier = -1; fDirectionMultiplier = -1;
fRollImpulse = (0.5f * fDirectionMultiplier + fSteerLR) * fRCRollMult; fRollAccel = (0.5f * fDirectionMultiplier + fSteerLR) * fRCRollMult;
} }
else else
fRollImpulse = fSteerLR * fSeaRollMult; fRollAccel = fSteerLR * fSeaRollMult;
ApplyTurnForce(GetRight() * fRollImpulse * fForwSpeed * m_fTurnMass * CTimer::GetTimeStep(), GetUp()); ApplyTurnForce(GetRight() * fRollAccel * fForwSpeed * m_fTurnMass * CTimer::GetTimeStep(), GetUp());
CVector vecFRight = CrossProduct(GetForward(), CVector(0.0f, 0.0f, 1.0f)); CVector vecFRight = CrossProduct(GetForward(), CVector(0.0f, 0.0f, 1.0f));
CVector vecStabilise = (GetUp().z > 0.0f) ? vecFRight : -vecFRight; CVector vecStabilise = (GetUp().z > 0.0f) ? vecFRight : -vecFRight;
float fStabiliseDirection = (GetRight().z > 0.0f) ? -1.0f : 1.0f; float fStabiliseDirection = (GetRight().z > 0.0f) ? -1.0f : 1.0f;
float fStabiliseImpulse; float fStabiliseSpeed;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
fStabiliseImpulse = fRCRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z)); fStabiliseSpeed = fRCRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z));
else else
fStabiliseImpulse = fSeaRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z)); fStabiliseSpeed = fSeaRollStabilise * fStabiliseDirection * (1.0f - DotProduct(GetRight(), vecStabilise)) * (1.0f - Abs(GetForward().z));
ApplyTurnForce(fStabiliseImpulse * m_fTurnMass * GetRight(), GetUp()); // no CTimer::GetTimeStep(), is it right? VC doesn't have it too ApplyTurnForce(fStabiliseSpeed * m_fTurnMass * GetRight(), GetUp()); // no CTimer::GetTimeStep(), is it right? VC doesn't have it too
// up/down // up/down
float fTail = -DotProduct(CrossProduct(m_vecTurnSpeed + m_vecTurnFriction, vecWidthForward) + m_vecMoveSpeed + m_vecMoveFriction, GetUp()); float fTail = -DotProduct(GetSpeed(vecWidthForward), GetUp());
float fSteerUD = -CPad::GetPad(0)->GetSteeringUpDown() / 128.0f; float fSteerUD = -CPad::GetPad(0)->GetSteeringUpDown() / 128.0f;
float fPitchImpulse; float fPitchAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
fPitchImpulse = fRCTailMult * fTail * Abs(fTail) + fRCPitchMult * fSteerUD * fForwSpeed; fPitchAccel = fRCTailMult * fTail * Abs(fTail) + fRCPitchMult * fSteerUD * fForwSpeed;
else else
fPitchImpulse = fSeaTailMult * fTail * Abs(fTail) + fSeaPitchMult * fSteerUD * fForwSpeed; fPitchAccel = fSeaTailMult * fTail * Abs(fTail) + fSeaPitchMult * fSteerUD * fForwSpeed;
ApplyTurnForce(fPitchImpulse * m_fTurnMass * GetUp() * CTimer::GetTimeStep(), vecWidthForward); ApplyTurnForce(fPitchAccel * m_fTurnMass * GetUp() * CTimer::GetTimeStep(), vecWidthForward);
float fLift = -DotProduct(GetMoveSpeed(), GetUp()) / Max(0.01f, GetMoveSpeed().Magnitude()); float fLift = -DotProduct(GetMoveSpeed(), GetUp()) / Max(0.01f, GetMoveSpeed().Magnitude());
float fLiftImpluse; float fLiftAccel;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
fLiftImpluse = (fRCAttackLiftMult * fLift + fRCFormLiftMult) * fForwSpeed * fForwSpeed; fLiftAccel = (fRCAttackLiftMult * fLift + fRCFormLiftMult) * fForwSpeed * fForwSpeed;
else else
fLiftImpluse = (fSeaAttackLiftMult * fLift + fSeaFormLiftMult) * fForwSpeed * fForwSpeed; fLiftAccel = (fSeaAttackLiftMult * fLift + fSeaFormLiftMult) * fForwSpeed * fForwSpeed;
float fLiftForce = fLiftImpluse * m_fMass * CTimer::GetTimeStep(); float fLiftImpulse = fLiftAccel * m_fMass * CTimer::GetTimeStep();
if (GRAVITY * CTimer::GetTimeStep() * m_fMass < fLiftImpluse) { if (GRAVITY * CTimer::GetTimeStep() * m_fMass < fLiftImpulse) {
if (flightModel == FLIGHT_MODEL_RCPLANE && GetPosition().z > 50.0f) if (flightModel == FLIGHT_MODEL_RCPLANE && GetPosition().z > 50.0f)
fLiftForce = CTimer::GetTimeStep() * 0.0072 * m_fMass; fLiftImpulse = CTimer::GetTimeStep() * 0.9f*GRAVITY * m_fMass;
else if (flightModel == FLIGHT_MODEL_SEAPLANE && GetPosition().z > 80.0f) else if (flightModel == FLIGHT_MODEL_SEAPLANE && GetPosition().z > 80.0f)
fLiftForce = CTimer::GetTimeStep() * 0.0072 * m_fMass; fLiftImpulse = CTimer::GetTimeStep() * 0.9f*GRAVITY * m_fMass;
} }
ApplyMoveForce(fLiftForce * GetUp()); ApplyMoveForce(fLiftImpulse * GetUp());
CVector vecResistance; CVector vecResistance;
if (flightModel == FLIGHT_MODEL_RCPLANE) if (flightModel == FLIGHT_MODEL_RCPLANE)
vecResistance = vecRCAeroResistance; vecResistance = vecRCAeroResistance;
@ -425,10 +426,9 @@ CVehicle::FlyingControl(eFlightModel flightModel)
} }
if (CPad::GetPad(0)->GetHorn()) { if (CPad::GetPad(0)->GetHorn()) {
fYaw = 0.0f; fYaw = 0.0f;
fPitch = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetUp()), -200.0f, 1.3f); fPitch = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetForward()), -200.0f, 1.3f);
fRoll = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetRight()), -200.0f, 1.3f); fRoll = clamp(10.0f * DotProduct(m_vecMoveSpeed, GetRight()), -200.0f, 1.3f);
} }
debug("fPitch: %f\n", fPitch);
ApplyTurnForce(fPitch * GetUp() * fPitchVar * m_fTurnMass * CTimer::GetTimeStep(), GetForward()); ApplyTurnForce(fPitch * GetUp() * fPitchVar * m_fTurnMass * CTimer::GetTimeStep(), GetForward());
ApplyTurnForce(fRoll * GetUp() * fRollVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight()); ApplyTurnForce(fRoll * GetUp() * fRollVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight());
ApplyTurnForce(fYaw * GetForward() * fYawVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight()); ApplyTurnForce(fYaw * GetForward() * fYawVar * m_fTurnMass * CTimer::GetTimeStep(), GetRight());
@ -442,11 +442,11 @@ CVehicle::FlyingControl(eFlightModel flightModel)
float rY = Pow(vecResistance.y, CTimer::GetTimeStep()); float rY = Pow(vecResistance.y, CTimer::GetTimeStep());
float rZ = Pow(vecResistance.z, CTimer::GetTimeStep()); float rZ = Pow(vecResistance.z, CTimer::GetTimeStep());
CVector vecTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix()); CVector vecTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix());
float fResistanceMultiplier = Pow(1.0f / (fSpinSpeedRes * SQR(vecTurnSpeed.z) + 1.0f), CTimer::GetTimeStep()); float fResistanceMultiplier = Pow(1.0f / (fSpinSpeedRes * SQR(vecTurnSpeed.z) + 1.0f) * rZ, CTimer::GetTimeStep());
float fResistance = vecTurnSpeed.z * fResistanceMultiplier - vecTurnSpeed.z; float fResistance = vecTurnSpeed.z * fResistanceMultiplier - vecTurnSpeed.z;
vecTurnSpeed.x *= rX; vecTurnSpeed.x *= rX;
vecTurnSpeed.y *= rY; vecTurnSpeed.y *= rY;
vecTurnSpeed.z *= rZ; vecTurnSpeed.z *= fResistanceMultiplier;
m_vecTurnSpeed = Multiply3x3(GetMatrix(), vecTurnSpeed); m_vecTurnSpeed = Multiply3x3(GetMatrix(), vecTurnSpeed);
ApplyTurnForce(-GetRight() * fResistance * m_fTurnMass, GetForward() + Multiply3x3(GetMatrix(), m_vecCentreOfMass)); ApplyTurnForce(-GetRight() * fResistance * m_fTurnMass, GetForward() + Multiply3x3(GetMatrix(), m_vecCentreOfMass));
break; break;
@ -454,6 +454,9 @@ CVehicle::FlyingControl(eFlightModel flightModel)
} }
} }
float fBurstSpeedMax = 0.3f;
float fBurstTyreMod = 0.1f;
void void
CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint, 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) int32 wheelsOnGround, float thrust, float brake, float adhesion, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, uint16 wheelStatus)
@ -494,8 +497,8 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon
#endif #endif
if(wheelStatus == WHEEL_STATUS_BURST){ if(wheelStatus == WHEEL_STATUS_BURST){
float fwdspeed = Min(contactSpeedFwd, 0.3f); float fwdspeed = Min(contactSpeedFwd, fBurstSpeedMax);
right += fwdspeed * CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); right += fwdspeed * CGeneral::GetRandomNumberInRange(-fBurstTyreMod, fBurstTyreMod);
} }
} }
@ -671,7 +674,7 @@ CVehicle::InflictDamage(CEntity* damagedBy, eWeaponType weaponType, float damage
break; break;
} }
} }
if (oldHealth > DAMAGE_HEALTH_TO_CATCH_FIRE && m_fHealth < DAMAGE_HEALTH_TO_CATCH_FIRE) { if (oldHealth >= DAMAGE_HEALTH_TO_CATCH_FIRE && m_fHealth < DAMAGE_HEALTH_TO_CATCH_FIRE) {
if (IsCar()) { if (IsCar()) {
CAutomobile* pThisCar = (CAutomobile*)this; CAutomobile* pThisCar = (CAutomobile*)this;
pThisCar->Damage.SetEngineStatus(ENGINE_STATUS_ON_FIRE); pThisCar->Damage.SetEngineStatus(ENGINE_STATUS_ON_FIRE);
@ -990,9 +993,8 @@ CVehicle::CanPedOpenLocks(CPed *ped)
bool bool
CVehicle::CanPedEnterCar(void) CVehicle::CanPedEnterCar(void)
{ {
CVector up = GetUp();
// can't enter when car is on side // can't enter when car is on side
if(up.z > 0.1f || up.z < -0.1f){ if(GetUp().z > 0.1f || GetUp().z < -0.1f){
// also when car is moving too fast // also when car is moving too fast
if(m_vecMoveSpeed.MagnitudeSqr() > sq(0.2f)) if(m_vecMoveSpeed.MagnitudeSqr() > sq(0.2f))
return false; return false;

View file

@ -86,8 +86,8 @@ enum
CAR_PIECE_WING_LR, CAR_PIECE_WING_LR,
CAR_PIECE_WING_RR, CAR_PIECE_WING_RR,
CAR_PIECE_WHEEL_LF, CAR_PIECE_WHEEL_LF,
CAR_PIECE_WHEEL_LR,
CAR_PIECE_WHEEL_RF, CAR_PIECE_WHEEL_RF,
CAR_PIECE_WHEEL_LR,
CAR_PIECE_WHEEL_RR, CAR_PIECE_WHEEL_RR,
CAR_PIECE_WINDSCREEN, CAR_PIECE_WINDSCREEN,
}; };