a bit more CBike

This commit is contained in:
aap 2020-06-05 15:09:45 +02:00
parent 83e4023dc0
commit 1bfb01d5f5
5 changed files with 69 additions and 24 deletions

View file

@ -1546,10 +1546,8 @@ CAutomobile::ProcessControl(void)
// Blow up car after 5 seconds // Blow up car after 5 seconds
m_fFireBlowUpTimer += CTimer::GetTimeStepInMilliseconds(); m_fFireBlowUpTimer += CTimer::GetTimeStepInMilliseconds();
if(m_fFireBlowUpTimer > 5000.0f){ if(m_fFireBlowUpTimer > 5000.0f)
CWorld::Players[CWorld::PlayerInFocus].AwardMoneyForExplosion(this);
BlowUpCar(m_pSetOnFireEntity); BlowUpCar(m_pSetOnFireEntity);
}
}else }else
m_fFireBlowUpTimer = 0.0f; m_fFireBlowUpTimer = 0.0f;

View file

@ -96,7 +96,7 @@ CBike::CBike(int32 id, uint8 CreatedBy)
m_bike_flag08 = false; m_bike_flag08 = false;
bIsStanding = false; bIsStanding = false;
bExtraSpeed = false; bExtraSpeed = false;
m_bike_flag40 = false; bIsOnFire = false;
m_bike_flag80 = false; m_bike_flag80 = false;
m_fTireTemperature = 0.0f; m_fTireTemperature = 0.0f;
@ -209,22 +209,35 @@ CBike::ProcessControl(void)
if(m_fLeanInput < 0.0f){ if(m_fLeanInput < 0.0f){
m_vecCentreOfMass.y = pHandling->CentreOfMass.y + pBikeHandling->fLeanBakCOM*m_fLeanInput; m_vecCentreOfMass.y = pHandling->CentreOfMass.y + pBikeHandling->fLeanBakCOM*m_fLeanInput;
CVector com = m_vecCentreOfMass;
#ifdef FIX_BUGS
// center of mass has to have world space orientation. unfortunately we can't do wheelies
// at high speed then, flipping y here is like riding south without this fix where wheelies work
com.y = -com.y;
com = Multiply3x3(GetMatrix(), com);
#endif
if(m_fBrakePedal == 0.0f && !bIsHandbrakeOn || m_nWheelsOnGround == 0){ if(m_fBrakePedal == 0.0f && !bIsHandbrakeOn || m_nWheelsOnGround == 0){
if(GetModelIndex() == MI_SANCHEZ){ if(GetModelIndex() == MI_SANCHEZ){
float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanBackForce*Min(m_vecMoveSpeed.Magnitude(), 0.1f); float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanBackForce*Min(m_vecMoveSpeed.Magnitude(), 0.1f);
force *= 0.7f*m_fGasPedal + 0.3f; force *= 0.7f*m_fGasPedal + 0.3f;
ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), m_vecCentreOfMass+GetForward()); ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), com+GetForward());
}else{ }else{
float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanBackForce*Min(m_vecMoveSpeed.Magnitude(), 0.1f); float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanBackForce*Min(m_vecMoveSpeed.Magnitude(), 0.1f);
force *= 0.5f*m_fGasPedal + 0.5f; force *= 0.5f*m_fGasPedal + 0.5f;
ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), m_vecCentreOfMass+GetForward()); ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), com+GetForward());
} }
} }
}else{ }else{
m_vecCentreOfMass.y = pHandling->CentreOfMass.y + pBikeHandling->fLeanFwdCOM*m_fLeanInput; m_vecCentreOfMass.y = pHandling->CentreOfMass.y + pBikeHandling->fLeanFwdCOM*m_fLeanInput;
CVector com = m_vecCentreOfMass;
#ifdef FIX_BUGS
// see above
com.y = -com.y;
com = Multiply3x3(GetMatrix(), com);
#endif
if(m_fBrakePedal < 0.0f || m_nWheelsOnGround == 0){ if(m_fBrakePedal < 0.0f || m_nWheelsOnGround == 0){
float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanFwdForce*Min(m_vecMoveSpeed.Magnitude(), 0.1f); float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanFwdForce*Min(m_vecMoveSpeed.Magnitude(), 0.1f);
ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), m_vecCentreOfMass+GetForward()); ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), com+GetForward());
} }
} }
@ -388,12 +401,10 @@ CBike::ProcessControl(void)
float turnY = localTurnSpeed.y*(res.y - 1.0f); float turnY = localTurnSpeed.y*(res.y - 1.0f);
res = -GetUp() * turnY * m_fTurnMass; res = -GetUp() * turnY * m_fTurnMass;
// BUG? matrix multiplication ApplyTurnForce(res, GetRight() + Multiply3x3(GetMatrix(), m_vecCentreOfMass));
ApplyTurnForce(res, GetRight() + Multiply3x3(GetMatrix(),m_vecCentreOfMass));
res = GetUp() * turnX * m_fTurnMass; res = GetUp() * turnX * m_fTurnMass;
// BUG? matrix multiplication ApplyTurnForce(res, GetForward() + Multiply3x3(GetMatrix(), m_vecCentreOfMass));
ApplyTurnForce(res, GetForward() + Multiply3x3(GetMatrix(),m_vecCentreOfMass));
if(GetStatus() != STATUS_PLAYER) if(GetStatus() != STATUS_PLAYER)
m_vecCentreOfMass = pHandling->CentreOfMass; m_vecCentreOfMass = pHandling->CentreOfMass;
@ -1050,6 +1061,41 @@ CBike::ProcessControl(void)
} }
} }
if(m_fHealth < 250.0f && GetStatus() != STATUS_WRECKED){
// Car is on fire
CVector damagePos, fireDir;
// move fire forward if in first person
if(this == FindPlayerVehicle() && TheCamera.GetLookingForwardFirstPerson()){
damagePos = CVector(0.0f, 1.2f, -0.4f);
fireDir = CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.01125f, 0.09f));
}else{
damagePos = ((CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()))->m_positions[CAR_POS_BACKSEAT];
damagePos.z -= 0.3f;
fireDir = CGeneral::GetRandomNumberInRange(0.02025f, 0.09f) * GetRight();
fireDir -= CGeneral::GetRandomNumberInRange(0.02025f, 0.18f) * GetForward();
fireDir.z = CGeneral::GetRandomNumberInRange(0.00225f, 0.018f);
}
damagePos = GetMatrix()*damagePos;
CParticle::AddParticle(PARTICLE_CARFLAME, damagePos, fireDir,
nil, 0.9f);
CParticle::AddParticle(PARTICLE_ENGINE_SMOKE2, damagePos, CVector(0.0f, 0.0f, 0.0f), nil, 0.5f);
damagePos.x += CGeneral::GetRandomNumberInRange(-0.5625f, 0.5625f),
damagePos.y += CGeneral::GetRandomNumberInRange(-0.5625f, 0.5625f),
damagePos.z += CGeneral::GetRandomNumberInRange(0.5625f, 2.25f);
CParticle::AddParticle(PARTICLE_CARFLAME_SMOKE, damagePos, CVector(0.0f, 0.0f, 0.0f));
// Blow up car after 5 seconds
m_fFireBlowUpTimer += CTimer::GetTimeStepInMilliseconds();
if(m_fFireBlowUpTimer > 5000.0f)
BlowUpCar(m_pSetOnFireEntity);
}else
m_fFireBlowUpTimer = 0.0f;
ProcessDelayedExplosion(); ProcessDelayedExplosion();
// Find out how much to shake the pad depending on suspension and ground surface // Find out how much to shake the pad depending on suspension and ground surface
@ -1915,7 +1961,7 @@ void
CBike::Fix(void) CBike::Fix(void)
{ {
bIsDamaged = false; bIsDamaged = false;
m_bike_flag40 = false; bIsOnFire = false;
m_wheelStatus[0] = WHEEL_STATUS_OK; m_wheelStatus[0] = WHEEL_STATUS_OK;
m_wheelStatus[1] = WHEEL_STATUS_OK; m_wheelStatus[1] = WHEEL_STATUS_OK;
} }

View file

@ -72,7 +72,7 @@ public:
uint8 m_bike_flag08 : 1; uint8 m_bike_flag08 : 1;
uint8 bIsStanding : 1; uint8 bIsStanding : 1;
uint8 bExtraSpeed : 1; // leaning forward uint8 bExtraSpeed : 1; // leaning forward
uint8 m_bike_flag40 : 1; uint8 bIsOnFire : 1;
uint8 m_bike_flag80 : 1; uint8 m_bike_flag80 : 1;
int16 m_doingBurnout; int16 m_doingBurnout;
float m_fTireTemperature; float m_fTireTemperature;

View file

@ -5,6 +5,8 @@
#include "Timer.h" #include "Timer.h"
#include "Pad.h" #include "Pad.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "Bike.h"
#include "Automobile.h"
#include "Pools.h" #include "Pools.h"
#include "HandlingMgr.h" #include "HandlingMgr.h"
#include "CarCtrl.h" #include "CarCtrl.h"
@ -893,7 +895,7 @@ float fTweakBikeWheelTurnForce = 2.0f;
void void
CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint, CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
int32 wheelsOnGround, float thrust, float brake, float adhesion, float unk, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, eBikeWheelSpecial special, uint16 wheelStatus) int32 wheelsOnGround, float thrust, float brake, float adhesion, float destabTraction, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, eBikeWheelSpecial special, uint16 wheelStatus)
{ {
// BUG: using statics here is probably a bad idea // BUG: using statics here is probably a bad idea
static bool bAlreadySkidding = false; // this is never reset static bool bAlreadySkidding = false; // this is never reset
@ -1010,14 +1012,14 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee
right *= adhesion * tractionLoss / l; right *= adhesion * tractionLoss / l;
fwd *= adhesion * tractionLoss / l; fwd *= adhesion * tractionLoss / l;
if(unk < 1.0f) if(destabTraction < 1.0f)
right *= unk; right *= destabTraction;
}else if(unk < 1.0f){ }else if(destabTraction < 1.0f){
if(!bAlreadySkidding) if(!bAlreadySkidding)
unk *= pHandling->fTractionLoss; destabTraction *= pHandling->fTractionLoss;
if(sq(adhesion*unk) < speedSq){ if(sq(adhesion*destabTraction) < speedSq){
float l = Sqrt(speedSq); float l = Sqrt(speedSq);
right *= adhesion * unk / l; right *= adhesion * destabTraction / l;
} }
} }
@ -1030,15 +1032,14 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee
float impulse = speed*m_fMass; float impulse = speed*m_fMass;
float turnImpulse = speed*GetMass(wheelContactPoint, direction); float turnImpulse = speed*GetMass(wheelContactPoint, direction);
CVector vTurnImpulse = turnImpulse * direction; CVector vTurnImpulse = turnImpulse * direction;
float turnRight = DotProduct(vTurnImpulse, GetRight());
ApplyMoveForce(impulse * direction); ApplyMoveForce(impulse * direction);
float turnRight = DotProduct(vTurnImpulse, GetRight());
float contactRight = DotProduct(wheelContactPoint, GetRight()); float contactRight = DotProduct(wheelContactPoint, GetRight());
float contactFwd = DotProduct(wheelContactPoint, GetForward()); float contactFwd = DotProduct(wheelContactPoint, GetForward());
if(wheelId != CARWHEEL_REAR_LEFT || if(wheelId != BIKEWHEEL_REAR || !bBraking && !bReversing)
!bBraking && !bReversing)
ApplyTurnForce((vTurnImpulse - turnRight*GetRight()) * fTweakBikeWheelTurnForce, ApplyTurnForce((vTurnImpulse - turnRight*GetRight()) * fTweakBikeWheelTurnForce,
wheelContactPoint - contactRight*GetRight()); wheelContactPoint - contactRight*GetRight());

View file

@ -306,7 +306,7 @@ public:
void ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint, 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); int32 wheelsOnGround, float thrust, float brake, float adhesion, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, uint16 wheelStatus);
void ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint, void ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelContactSpeed, CVector &wheelContactPoint,
int32 wheelsOnGround, float thrust, float brake, float adhesion, float unk, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, eBikeWheelSpecial special, uint16 wheelStatus); int32 wheelsOnGround, float thrust, float brake, float adhesion, float destabTraction, int8 wheelId, float *wheelSpeed, tWheelState *wheelState, eBikeWheelSpecial special, uint16 wheelStatus);
void ExtinguishCarFire(void); void ExtinguishCarFire(void);
void ProcessDelayedExplosion(void); void ProcessDelayedExplosion(void);
float ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVector &speed, float radius); float ProcessWheelRotation(tWheelState state, const CVector &fwd, const CVector &speed, float radius);