CPhysical almost done

This commit is contained in:
aap 2021-08-02 20:04:15 +02:00
parent a481b900b9
commit 0338d4c393
5 changed files with 224 additions and 135 deletions

View file

@ -29,7 +29,7 @@ enum
{ {
ENTITYLIST_BUILDINGS, ENTITYLIST_BUILDINGS,
ENTITYLIST_BUILDINGS_OVERLAP, ENTITYLIST_BUILDINGS_OVERLAP,
ENTITYLIST_UNKNOWN, ENTITYLIST_MULTIPLAYER,
ENTITYLIST_OBJECTS, ENTITYLIST_OBJECTS,
ENTITYLIST_OBJECTS_OVERLAP, ENTITYLIST_OBJECTS_OVERLAP,
ENTITYLIST_VEHICLES, ENTITYLIST_VEHICLES,

View file

@ -14,6 +14,7 @@ enum eEntityType
ENTITY_TYPE_PED, ENTITY_TYPE_PED,
ENTITY_TYPE_OBJECT, ENTITY_TYPE_OBJECT,
ENTITY_TYPE_DUMMY, ENTITY_TYPE_DUMMY,
ENTITY_TYPE_MULTIPLAYER
}; };
enum eEntityStatus enum eEntityStatus
@ -153,6 +154,7 @@ public:
bool IsPed(void) { return m_type == ENTITY_TYPE_PED; } bool IsPed(void) { return m_type == ENTITY_TYPE_PED; }
bool IsObject(void) { return m_type == ENTITY_TYPE_OBJECT; } bool IsObject(void) { return m_type == ENTITY_TYPE_OBJECT; }
bool IsDummy(void) { return m_type == ENTITY_TYPE_DUMMY; } bool IsDummy(void) { return m_type == ENTITY_TYPE_DUMMY; }
bool IsMultiplayer(void) { return m_type == ENTITY_TYPE_MULTIPLAYER; }
RpAtomic *GetAtomic(void) { RpAtomic *GetAtomic(void) {
assert(RwObjectGetType(m_rwObject) == rpATOMIC); assert(RwObjectGetType(m_rwObject) == rpATOMIC);

View file

@ -21,6 +21,8 @@
#include "Pickups.h" #include "Pickups.h"
#include "Physical.h" #include "Physical.h"
//--LCS: mostly done
bool gGravityCheat; bool gGravityCheat;
@ -80,6 +82,9 @@ CPhysical::CPhysical(void)
bIsFrozen = false; bIsFrozen = false;
bDontLoadCollision = false; bDontLoadCollision = false;
phys_lcs_unk1 = true;
phys_lcs_unk2 = 0;
} }
CPhysical::~CPhysical(void) CPhysical::~CPhysical(void)
@ -120,6 +125,9 @@ CPhysical::Add(void)
case ENTITY_TYPE_OBJECT: case ENTITY_TYPE_OBJECT:
list = &s->m_lists[ENTITYLIST_OBJECTS]; list = &s->m_lists[ENTITYLIST_OBJECTS];
break; break;
case ENTITY_TYPE_MULTIPLAYER:
list = &s->m_lists[ENTITYLIST_MULTIPLAYER];
break;
default: default:
assert(0); assert(0);
}else switch(m_type){ }else switch(m_type){
@ -132,6 +140,9 @@ CPhysical::Add(void)
case ENTITY_TYPE_OBJECT: case ENTITY_TYPE_OBJECT:
list = &s->m_lists[ENTITYLIST_OBJECTS_OVERLAP]; list = &s->m_lists[ENTITYLIST_OBJECTS_OVERLAP];
break; break;
case ENTITY_TYPE_MULTIPLAYER:
list = &s->m_lists[ENTITYLIST_MULTIPLAYER];
break;
default: default:
assert(0); assert(0);
} }
@ -172,6 +183,8 @@ CPhysical::RemoveAndAdd(void)
assert(ystart >= 0); assert(ystart >= 0);
assert(yend < NUMSECTORS_Y); assert(yend < NUMSECTORS_Y);
// TODO(LCS): there's a bunch of weird code in this function
// we'll try to recycle nodes from here // we'll try to recycle nodes from here
CEntryInfoNode *next = m_entryInfoList.first; CEntryInfoNode *next = m_entryInfoList.first;
@ -188,6 +201,9 @@ CPhysical::RemoveAndAdd(void)
case ENTITY_TYPE_OBJECT: case ENTITY_TYPE_OBJECT:
list = &s->m_lists[ENTITYLIST_OBJECTS]; list = &s->m_lists[ENTITYLIST_OBJECTS];
break; break;
case ENTITY_TYPE_MULTIPLAYER:
list = &s->m_lists[ENTITYLIST_MULTIPLAYER];
break;
}else switch(m_type){ }else switch(m_type){
case ENTITY_TYPE_VEHICLE: case ENTITY_TYPE_VEHICLE:
list = &s->m_lists[ENTITYLIST_VEHICLES_OVERLAP]; list = &s->m_lists[ENTITYLIST_VEHICLES_OVERLAP];
@ -198,6 +214,9 @@ CPhysical::RemoveAndAdd(void)
case ENTITY_TYPE_OBJECT: case ENTITY_TYPE_OBJECT:
list = &s->m_lists[ENTITYLIST_OBJECTS_OVERLAP]; list = &s->m_lists[ENTITYLIST_OBJECTS_OVERLAP];
break; break;
case ENTITY_TYPE_MULTIPLAYER:
list = &s->m_lists[ENTITYLIST_MULTIPLAYER];
break;
} }
if(next){ if(next){
// If we still have old nodes, use them // If we still have old nodes, use them
@ -224,22 +243,20 @@ CPhysical::RemoveAndAdd(void)
CRect CRect
CPhysical::GetBoundRect(void) CPhysical::GetBoundRect(void)
{ {
CVUVECTOR center; CVector center;
float radius; float radius;
GetBoundCentre(center); center = GetBoundCentre();
radius = GetBoundRadius(); radius = GetBoundRadius();
return CRect(center.x-radius, center.y-radius, center.x+radius, center.y+radius); return CRect(center.x-radius, center.y-radius, center.x+radius, center.y+radius);
} }
// --MIAMI: Proof-read once
void void
CPhysical::AddToMovingList(void) CPhysical::AddToMovingList(void)
{ {
if (!bIsStaticWaitingForCollision) if (m_movingListNode == nil && !bIsStaticWaitingForCollision)
m_movingListNode = CWorld::GetMovingEntityList().InsertItem(this); m_movingListNode = CWorld::GetMovingEntityList().InsertItem(this);
} }
// --MIAMI: Proof-read once
void void
CPhysical::RemoveFromMovingList(void) CPhysical::RemoveFromMovingList(void)
{ {
@ -259,7 +276,6 @@ CPhysical::SetDamagedPieceRecord(uint16 piece, float impulse, CEntity *entity, C
m_vecDamageNormal = dir; m_vecDamageNormal = dir;
} }
// --MIAMI: Proof-read once
void void
CPhysical::AddCollisionRecord(CEntity *ent) CPhysical::AddCollisionRecord(CEntity *ent)
{ {
@ -283,7 +299,6 @@ CPhysical::AddCollisionRecord(CEntity *ent)
} }
} }
// --MIAMI: Proof-read once
void void
CPhysical::AddCollisionRecord_Treadable(CEntity *ent) CPhysical::AddCollisionRecord_Treadable(CEntity *ent)
{ {
@ -291,7 +306,6 @@ CPhysical::AddCollisionRecord_Treadable(CEntity *ent)
} }
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::GetHasCollidedWith(CEntity *ent) CPhysical::GetHasCollidedWith(CEntity *ent)
{ {
@ -303,7 +317,6 @@ CPhysical::GetHasCollidedWith(CEntity *ent)
return false; return false;
} }
// --MIAMI: Proof-read once
void void
CPhysical::RemoveRefsToEntity(CEntity *ent) CPhysical::RemoveRefsToEntity(CEntity *ent)
{ {
@ -319,7 +332,6 @@ CPhysical::RemoveRefsToEntity(CEntity *ent)
} }
} }
// --MIAMI: Proof-read once
void void
CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phys, CVector localPos) CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phys, CVector localPos)
{ {
@ -336,10 +348,11 @@ CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phy
CWorld::Add(phys); CWorld::Add(phys);
} }
// --MIAMI: Proof-read once
int32 int32
CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints) CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
{ {
if(!GetIsTouching(ent))
return 0;
int32 numSpheres = CCollision::ProcessColModels( int32 numSpheres = CCollision::ProcessColModels(
GetMatrix(), *GetColModel(), GetMatrix(), *GetColModel(),
ent->GetMatrix(), *ent->GetColModel(), ent->GetMatrix(), *ent->GetColModel(),
@ -355,7 +368,6 @@ CPhysical::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
return numSpheres; return numSpheres;
} }
//--LCS: done
void void
CPhysical::ProcessControl(void) CPhysical::ProcessControl(void)
{ {
@ -423,7 +435,6 @@ CPhysical::GetSpeed(const CVector &r)
return m_vecMoveSpeed + m_vecMoveFriction + CrossProduct(m_vecTurnFriction + m_vecTurnSpeed, r); return m_vecMoveSpeed + m_vecMoveFriction + CrossProduct(m_vecTurnFriction + m_vecTurnSpeed, r);
} }
//--LCS: done
void void
CPhysical::ApplyMoveSpeed(void) CPhysical::ApplyMoveSpeed(void)
{ {
@ -433,7 +444,6 @@ CPhysical::ApplyMoveSpeed(void)
GetMatrix().Translate(m_vecMoveSpeed * CTimer::GetTimeStep()); GetMatrix().Translate(m_vecMoveSpeed * CTimer::GetTimeStep());
} }
//--LCS: done
void void
CPhysical::ApplyTurnSpeed(void) CPhysical::ApplyTurnSpeed(void)
{ {
@ -449,7 +459,6 @@ CPhysical::ApplyTurnSpeed(void)
} }
} }
//--LCS: done
void void
CPhysical::ApplyMoveForce(float jx, float jy, float jz) CPhysical::ApplyMoveForce(float jx, float jy, float jz)
{ {
@ -459,7 +468,6 @@ CPhysical::ApplyMoveForce(float jx, float jy, float jz)
m_vecTurnSpeed.z = Clamp(m_vecTurnSpeed.z, -4.0f, 4.0f); m_vecTurnSpeed.z = Clamp(m_vecTurnSpeed.z, -4.0f, 4.0f);
} }
//--LCS: done
void void
CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz) CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz)
{ {
@ -471,14 +479,26 @@ CPhysical::ApplyTurnForce(float jx, float jy, float jz, float px, float py, floa
m_vecTurnSpeed.z = Clamp(m_vecTurnSpeed.z, -4.0f, 4.0f); m_vecTurnSpeed.z = Clamp(m_vecTurnSpeed.z, -4.0f, 4.0f);
} }
//--LCS: done void
CPhysical::ApplyTurnForceMultiplayer(const CVector &j, const CVector &p)
{
CVector com = Multiply3x3(GetMatrix(), m_vecCentreOfMass);
CVector turnimpulse = CrossProduct(p-com, j);
turnimpulse *= (1.0f/m_fTurnMass);
m_vecTurnSpeed.x += Clamp(turnimpulse.x, -0.1f, 0.1f);
m_vecTurnSpeed.y += Clamp(turnimpulse.y, -0.1f, 0.1f);
m_vecTurnSpeed.z += Clamp(turnimpulse.z, -0.1f, 0.1f);
m_vecTurnSpeed.x = Clamp(m_vecTurnSpeed.x, -1.0f, 1.0f);
m_vecTurnSpeed.y = Clamp(m_vecTurnSpeed.y, -1.0f, 1.0f);
m_vecTurnSpeed.z = Clamp(m_vecTurnSpeed.z, -1.0f, 1.0f);
}
void void
CPhysical::ApplyFrictionMoveForce(float jx, float jy, float jz) CPhysical::ApplyFrictionMoveForce(float jx, float jy, float jz)
{ {
m_vecMoveFriction += CVector(jx, jy, jz)*(1.0f/m_fMass); m_vecMoveFriction += CVector(jx, jy, jz)*(1.0f/m_fMass);
} }
//--LCS: done
void void
CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float py, float pz) CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float py, float pz)
{ {
@ -487,7 +507,6 @@ CPhysical::ApplyFrictionTurnForce(float jx, float jy, float jz, float px, float
m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass); m_vecTurnFriction += turnimpulse*(1.0f/m_fTurnMass);
} }
//--LCS: done
bool bool
CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &point, float springRatio, float bias) CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &point, float springRatio, float bias)
{ {
@ -501,7 +520,6 @@ CPhysical::ApplySpringCollision(float springConst, CVector &springDir, CVector &
return true; return true;
} }
//--LCS: done
bool bool
CPhysical::ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir, float &impulse) CPhysical::ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir, float &impulse)
{ {
@ -522,7 +540,6 @@ CPhysical::ApplySpringCollisionAlt(float springConst, CVector &springDir, CVecto
float DAMPING_LIMIT_OF_SPRING_FORCE = 0.999f; float DAMPING_LIMIT_OF_SPRING_FORCE = 0.999f;
float DAMPING_LIMIT_IN_FRAME= 0.25f; float DAMPING_LIMIT_IN_FRAME= 0.25f;
//--LCS: done
// What exactly is speed? // What exactly is speed?
bool bool
CPhysical::ApplySpringDampening(float damping, float dampingLimit, CVector &springDir, CVector &point, CVector &speed) CPhysical::ApplySpringDampening(float damping, float dampingLimit, CVector &springDir, CVector &point, CVector &speed)
@ -564,7 +581,6 @@ CPhysical::ApplySpringDampening(float damping, float dampingLimit, CVector &spri
return true; return true;
} }
//--LCS: done
void void
CPhysical::ApplyGravity(void) CPhysical::ApplyGravity(void)
{ {
@ -591,7 +607,6 @@ CPhysical::ApplyGravity(void)
m_vecMoveSpeed.z -= GRAVITY * CTimer::GetTimeStep(); m_vecMoveSpeed.z -= GRAVITY * CTimer::GetTimeStep();
} }
//--LCS: done
void void
CPhysical::ApplyFriction(void) CPhysical::ApplyFriction(void)
{ {
@ -601,7 +616,6 @@ CPhysical::ApplyFriction(void)
m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f);
} }
//--LCS: done
void void
CPhysical::ApplyAirResistance(void) CPhysical::ApplyAirResistance(void)
{ {
@ -653,6 +667,14 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
foo = true; foo = true;
} }
CVector comA, comB;
comA = Multiply3x3(A->GetMatrix(), A->m_vecCentreOfMass);
comB = Multiply3x3(B->GetMatrix(), B->m_vecCentreOfMass);
if(A->IsVehicle() && B->IsObject() && ((CObject*)B)->bIsStreetLight ||
B->IsVehicle() && A->IsObject() && ((CObject*)A)->bIsStreetLight)
colpoint.normal.z = 0.0f;
float speedA, speedB; float speedA, speedB;
if(B->GetIsStatic() && !foo){ if(B->GetIsStatic() && !foo){
if(A->bPedPhysics){ if(A->bPedPhysics){
@ -673,6 +695,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
if(IsGlass(B->GetModelIndex())) if(IsGlass(B->GetModelIndex()))
CGlass::WindowRespondsToSoftCollision(B, impulseA); CGlass::WindowRespondsToSoftCollision(B, impulseA);
if(!A->bInfiniteMass) if(!A->bInfiniteMass)
//TODO(LCS): inline without clamp
A->ApplyMoveForce(colpoint.GetNormal() * (1.0f + A->m_fElasticity) * impulseA); A->ApplyMoveForce(colpoint.GetNormal() * (1.0f + A->m_fElasticity) * impulseA);
return true; return true;
} }
@ -683,6 +706,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
impulseA = -speedA * A->m_fMass; impulseA = -speedA * A->m_fMass;
impulseB = 0.0f; impulseB = 0.0f;
if(!A->bInfiniteMass) if(!A->bInfiniteMass)
//TODO(LCS): inline without clamp
A->ApplyMoveForce(colpoint.normal*(1.0f + A->m_fElasticity)*impulseA); A->ApplyMoveForce(colpoint.normal*(1.0f + A->m_fElasticity)*impulseA);
return true; return true;
} }
@ -696,7 +720,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
eA = -1.0f; eA = -1.0f;
else else
eA = -(1.0f + A->m_fElasticity); eA = -(1.0f + A->m_fElasticity);
impulseA = eA * speedA * A->GetMass(pointposA, colpoint.normal); impulseA = eA * speedA * A->GetMass(pointposA-comA, colpoint.normal);
impulseB = impulseA; impulseB = impulseA;
if(Bobj->m_nCollisionDamageEffect && impulseA > 20.0f){ if(Bobj->m_nCollisionDamageEffect && impulseA > 20.0f){
@ -721,7 +745,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
CParticleObject::AddObject(POBJECT_FIRE_HYDRANT, B->GetPosition() - CVector(0.0f, 0.0f, 0.5f), true); CParticleObject::AddObject(POBJECT_FIRE_HYDRANT, B->GetPosition() - CVector(0.0f, 0.0f, 0.5f), true);
CParticleObject::AddObject(POBJECT_FIRE_HYDRANT_STEAM, B->GetPosition() - CVector(0.0f, 0.0f, 0.5f), true); CParticleObject::AddObject(POBJECT_FIRE_HYDRANT_STEAM, B->GetPosition() - CVector(0.0f, 0.0f, 0.5f), true);
Bobj->bHasBeenDamaged = true; Bobj->bHasBeenDamaged = true;
}else if(model == MI_PARKINGMETER || model == MI_PARKINGMETER2){ }else if((model == MI_PARKINGMETER || model == MI_PARKINGMETER2) && !Bobj->bHasBeenDamaged){
CPickups::CreateSomeMoney(GetPosition(), CGeneral::GetRandomNumber()%100); CPickups::CreateSomeMoney(GetPosition(), CGeneral::GetRandomNumber()%100);
Bobj->bHasBeenDamaged = true; Bobj->bHasBeenDamaged = true;
}else if(B->IsObject() && !IsExplosiveThingModel(model)) }else if(B->IsObject() && !IsExplosiveThingModel(model))
@ -739,14 +763,17 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
} }
return true; return true;
} }
}else if(!B->bInfiniteMass) }else if(!B->bInfiniteMass){
B->SetIsStatic(false); B->SetIsStatic(false);
CWorld::Players[CWorld::PlayerInFocus].m_nHavocLevel += 2;
CStats::PropertyDestroyed += CGeneral::GetRandomNumberInRange(30, 60);
}
} }
} }
if(B->GetIsStatic()) if(B->GetIsStatic())
return false; return false;
if(!B->bInfiniteMass && !B->m_phy_flagA08) if(!B->bInfiniteMass && !B->bIsStaticWaitingForCollision)
B->AddToMovingList(); B->AddToMovingList();
} }
@ -756,13 +783,13 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
// negative if A is moving towards B // negative if A is moving towards B
speedA = DotProduct(A->m_vecMoveSpeed, colpoint.normal); speedA = DotProduct(A->m_vecMoveSpeed, colpoint.normal);
// positive if B is moving towards A // positive if B is moving towards A
float speedB = DotProduct(B->m_vecMoveSpeed, colpoint.normal); speedB = DotProduct(B->m_vecMoveSpeed, colpoint.normal);
bool affectB = false; bool affectB = false;
float mA = A->m_fMass;; float mA = A->m_fMass;
float mB = B->m_fMass;; float mB = B->m_fMass;
float speedSum; float speedSum;
if(((CPed*)A)->GetPedState() == PED_FOLLOW_PATH){ if(A->IsPed() && ((CPed*)A)->GetPedState() == PED_FOLLOW_PATH){
affectB = true; affectB = true;
speedSum = (2.0f*mA*speedA + mB*speedB)/(2.0f*mA + mB); speedSum = (2.0f*mA*speedA + mB*speedB)/(2.0f*mA + mB);
}else{ }else{
@ -794,7 +821,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
speedB = DotProduct(B->GetSpeed(pointposB), colpoint.normal); speedB = DotProduct(B->GetSpeed(pointposB), colpoint.normal);
float mA = A->m_fMass*massFactorA; float mA = A->m_fMass*massFactorA;
float mB = B->GetMassTweak(pointposB, colpoint.normal, massFactorB); float mB = B->GetMassTweak(pointposB-comB, colpoint.normal, massFactorB);
float speedSum; float speedSum;
if(foo) if(foo)
speedSum = speedB; speedSum = speedB;
@ -832,7 +859,7 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
speedA = DotProduct(A->GetSpeed(pointposA), colpoint.normal); speedA = DotProduct(A->GetSpeed(pointposA), colpoint.normal);
speedB = DotProduct(B->m_vecMoveSpeed, colpoint.normal); speedB = DotProduct(B->m_vecMoveSpeed, colpoint.normal);
float mA = A->GetMassTweak(pointposA, colpoint.normal, massFactorA); float mA = A->GetMassTweak(pointposA-comA, colpoint.normal, massFactorA);
float mB = B->m_fMass*massFactorB; float mB = B->m_fMass*massFactorB;
float speedSum = (mB*speedB + mA*speedA)/(mA + mB); float speedSum = (mB*speedB + mA*speedA)/(mA + mB);
if(speedA < speedSum){ if(speedA < speedSum){
@ -872,8 +899,8 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
CVector pointposB = colpoint.point - B->GetPosition(); CVector pointposB = colpoint.point - B->GetPosition();
speedA = DotProduct(A->GetSpeed(pointposA), colpoint.normal); speedA = DotProduct(A->GetSpeed(pointposA), colpoint.normal);
speedB = DotProduct(B->GetSpeed(pointposB), colpoint.normal); speedB = DotProduct(B->GetSpeed(pointposB), colpoint.normal);
float mA = A->GetMassTweak(pointposA, colpoint.normal, massFactorA); float mA = A->GetMassTweak(pointposA-comA, colpoint.normal, massFactorA);
float mB = B->GetMassTweak(pointposB, colpoint.normal, massFactorB); float mB = B->GetMassTweak(pointposB-comB, colpoint.normal, massFactorB);
float speedSum = (mB*speedB + mA*speedA)/(mA + mB); float speedSum = (mB*speedB + mA*speedA)/(mA + mB);
if(speedA < speedSum){ if(speedA < speedSum){
if(A->bHasHitWall) if(A->bHasHitWall)
@ -889,8 +916,8 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
CVector fA = colpoint.normal*(impulseA/massFactorA); CVector fA = colpoint.normal*(impulseA/massFactorA);
CVector fB = colpoint.normal*(-impulseB/massFactorB); CVector fB = colpoint.normal*(-impulseB/massFactorB);
if(A->IsVehicle() && !A->bHasHitWall){ if(A->IsVehicle() && !A->bHasHitWall){
fA.x *= 1.4f; // fA.x *= 1.4f;
fA.y *= 1.4f; // fA.y *= 1.4f;
if(colpoint.normal.z < 0.7f) if(colpoint.normal.z < 0.7f)
fA.z *= 0.3f; fA.z *= 0.3f;
if(A->GetStatus() == STATUS_PLAYER) if(A->GetStatus() == STATUS_PLAYER)
@ -901,8 +928,8 @@ CPhysical::ApplyCollision(CPhysical *B, CColPoint &colpoint, float &impulseA, fl
} }
} }
if(B->IsVehicle() && !B->bHasHitWall){ if(B->IsVehicle() && !B->bHasHitWall){
fB.x *= 1.4f; // fB.x *= 1.4f;
fB.y *= 1.4f; // fB.y *= 1.4f;
if(-colpoint.normal.z < 0.7f) if(-colpoint.normal.z < 0.7f)
fB.z *= 0.3f; fB.z *= 0.3f;
if(B->GetStatus() == STATUS_PLAYER) if(B->GetStatus() == STATUS_PLAYER)
@ -953,8 +980,8 @@ CPhysical::ApplyCollision(CColPoint &colpoint, float &impulse)
impulse = -(m_fElasticity + 1.0f) * speed * mass; impulse = -(m_fElasticity + 1.0f) * speed * mass;
CVector f = colpoint.normal*impulse; CVector f = colpoint.normal*impulse;
if(IsVehicle()){ if(IsVehicle()){
f.x *= 1.4f; // f.x *= 1.4f;
f.y *= 1.4f; // f.y *= 1.4f;
if(colpoint.normal.z < 0.7f) if(colpoint.normal.z < 0.7f)
f.z *= 0.3f; f.z *= 0.3f;
} }
@ -1032,7 +1059,7 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV
Abs(m_vecMoveSpeed.z) < minspeed*2.0f) Abs(m_vecMoveSpeed.z) < minspeed*2.0f)
impulse = -0.8f * normalSpeed * mass; impulse = -0.8f * normalSpeed * mass;
else if(IsVehicle() && ((CVehicle*)this)->IsBoat() && else if(IsVehicle() && ((CVehicle*)this)->IsBoat() &&
colpoint.surfaceB == SURFACE_WOOD_SOLID && colpoint.normal.z < 0.5f) (colpoint.surfaceB == SURFACE_WOOD_SOLID || colpoint.normal.z < 0.5f))
impulse = -(2.0f * m_fElasticity + 1.0f) * normalSpeed * mass; impulse = -(2.0f * m_fElasticity + 1.0f) * normalSpeed * mass;
else else
impulse = -(m_fElasticity + 1.0f) * normalSpeed * mass; impulse = -(m_fElasticity + 1.0f) * normalSpeed * mass;
@ -1060,7 +1087,7 @@ CPhysical::ApplyCollisionAlt(CEntity *B, CColPoint &colpoint, float &impulse, CV
return false; return false;
} }
// --MIAMI: Proof-read once //LCS: the div by 0 is fixed differently. probably should use their fix?
bool bool
CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint) CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
{ {
@ -1210,7 +1237,6 @@ CPhysical::ApplyFriction(CPhysical *B, float adhesiveLimit, CColPoint &colpoint)
return false; return false;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint) CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
{ {
@ -1276,7 +1302,6 @@ CPhysical::ApplyFriction(float adhesiveLimit, CColPoint &colpoint)
return false; return false;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ProcessShiftSectorList(CPtrList *lists) CPhysical::ProcessShiftSectorList(CPtrList *lists)
{ {
@ -1302,6 +1327,10 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
A->GetBoundCentre(center); A->GetBoundCentre(center);
radius = A->GetBoundRadius(); radius = A->GetBoundRadius();
if(A->IsMultiplayer())
return false;
for(i = 0; i <= ENTITYLIST_PEDS_OVERLAP; i++){ for(i = 0; i <= ENTITYLIST_PEDS_OVERLAP; i++){
list = &lists[i]; list = &lists[i];
for(node = list->first; node; node = node->next){ for(node = list->first; node; node = node->next){
@ -1309,12 +1338,13 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
Bobj = (CObject*)B; Bobj = (CObject*)B;
skipShift = false; skipShift = false;
if(B->IsBuilding() || if(B->IsMultiplayer() || B->IsBuilding() ||
B->IsObject() && B->bInfiniteMass) B->IsObject() && B->bInfiniteMass ||
A->IsPed() && B->IsObject() && B->GetIsStatic() && !Bobj->bHasBeenDamaged)
canshift = true; canshift = true;
else else
canshift = A->IsPed() && canshift = false;
B->IsObject() && B->GetIsStatic() && !Bobj->bHasBeenDamaged;
if(B == A || if(B == A ||
B->m_scanCode == CWorld::GetCurrentScanCode() || B->m_scanCode == CWorld::GetCurrentScanCode() ||
!B->bUsesCollision || !B->bUsesCollision ||
@ -1343,7 +1373,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
Aobj->m_pCollidingEntity = nil; Aobj->m_pCollidingEntity = nil;
}else if(Aobj->m_pCollidingEntity != B){ }else if(Aobj->m_pCollidingEntity != B){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(A->GetModelIndex())->boundingBox.GetSize();
size = A->GetMatrix() * size; size = A->GetMatrix() * size;
if(size.z < B->GetPosition().z || if(size.z < B->GetPosition().z ||
(Invert(B->GetMatrix(), inv) * size).z < 0.0f){ (Invert(B->GetMatrix(), inv) * size).z < 0.0f){
@ -1361,7 +1391,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
Bobj->m_pCollidingEntity = nil; Bobj->m_pCollidingEntity = nil;
}else if(Bobj->m_pCollidingEntity != A){ }else if(Bobj->m_pCollidingEntity != A){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(B->GetModelIndex())->boundingBox.GetSize();
size = B->GetMatrix() * size; size = B->GetMatrix() * size;
if(size.z < A->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f) (Invert(A->GetMatrix(), inv) * size).z < 0.0f)
@ -1373,10 +1403,11 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
else if(A->IsPed() && IsBodyPart(B->GetModelIndex())) else if(A->IsPed() && IsBodyPart(B->GetModelIndex()))
skipShift = true; skipShift = true;
else if(A->IsPed() && ((CPed*)A)->m_pCollidingEntity == B || else if(A->IsPed() && ((CPed*)A)->m_pCollidingEntity == B ||
B->IsPed() && ((CPed*)B)->m_pCollidingEntity == A || B->IsPed() && ((CPed*)B)->m_pCollidingEntity == A)
A->GetModelIndex() == MI_RCBANDIT && B->IsVehicle() ||
B->GetModelIndex() == MI_RCBANDIT && (A->IsPed() || A->IsVehicle()))
skipShift = true; skipShift = true;
// else if(A->GetModelIndex() == MI_RCBANDIT && B->IsVehicle() ||
// B->GetModelIndex() == MI_RCBANDIT && (A->IsPed() || A->IsVehicle()))
// skipShift = true;
if(skipShift) if(skipShift)
continue; continue;
@ -1418,6 +1449,7 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
dir.Normalise(); dir.Normalise();
B->GetMatrix().Translate(dir * colpoints[mostColliding].GetDepth() / (1.0f - f)); B->GetMatrix().Translate(dir * colpoints[mostColliding].GetDepth() / (1.0f - f));
// BUG? how can that ever happen? A is a Ped // BUG? how can that ever happen? A is a Ped
// LCS: gone or just optimized away?
if(B->IsVehicle()) if(B->IsVehicle())
B->ProcessEntityCollision(A, colpoints); B->ProcessEntityCollision(A, colpoints);
}else{ }else{
@ -1439,7 +1471,6 @@ CPhysical::ProcessShiftSectorList(CPtrList *lists)
return true; return true;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists) CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists)
{ {
@ -1481,6 +1512,10 @@ CPhysical::ProcessCollisionSectorList_SimpleCar(CPtrList *lists)
B->bUsesCollision && B->bUsesCollision &&
B->GetIsTouching(center, radius)){ B->GetIsTouching(center, radius)){
B->m_scanCode = CWorld::GetCurrentScanCode(); B->m_scanCode = CWorld::GetCurrentScanCode();
#ifndef FIX_BUGS
// surely they didn't mean to call this twice?
numCollisions = A->ProcessEntityCollision(B, aColPoints);
#endif
numCollisions = A->ProcessEntityCollision(B, aColPoints); numCollisions = A->ProcessEntityCollision(B, aColPoints);
if(numCollisions > 0) if(numCollisions > 0)
goto collision; goto collision;
@ -1606,7 +1641,6 @@ collision:
return true; return true;
} }
// --MIAMI: Proof-read once
bool bool
CPhysical::ProcessCollisionSectorList(CPtrList *lists) CPhysical::ProcessCollisionSectorList(CPtrList *lists)
{ {
@ -1632,7 +1666,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
radius = A->GetBoundRadius(); radius = A->GetBoundRadius();
A->GetBoundCentre(center); A->GetBoundCentre(center);
for(j = 0; j <= ENTITYLIST_PEDS_OVERLAP; j++){ for(j = A->IsMultiplayer() ? 1 : 0; j <= ENTITYLIST_PEDS_OVERLAP; j++){
list = &lists[j]; list = &lists[j];
CPtrNode *listnode; CPtrNode *listnode;
@ -1641,12 +1675,11 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
Bobj = (CObject*)B; Bobj = (CObject*)B;
Bped = (CPed*)B; Bped = (CPed*)B;
bool isTouching = true;
if(!B->bUsesCollision || if(!B->bUsesCollision ||
B->m_scanCode == CWorld::GetCurrentScanCode() || B->m_scanCode == CWorld::GetCurrentScanCode() ||
B == A || B == A)
!(isTouching = B->GetIsTouching(center, radius))){ continue;
if(!isTouching){ if(!B->GetIsTouching(center, radius)){
if(A->IsObject() && Aobj->m_pCollidingEntity == B) if(A->IsObject() && Aobj->m_pCollidingEntity == B)
Aobj->m_pCollidingEntity = nil; Aobj->m_pCollidingEntity = nil;
else if(B->IsObject() && Bobj->m_pCollidingEntity == A) else if(B->IsObject() && Bobj->m_pCollidingEntity == A)
@ -1655,7 +1688,6 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
Aped->m_pCollidingEntity = nil; Aped->m_pCollidingEntity = nil;
else if(B->IsPed() && Bped->m_pCollidingEntity == A) else if(B->IsPed() && Bped->m_pCollidingEntity == A)
Bped->m_pCollidingEntity = nil; Bped->m_pCollidingEntity = nil;
}
continue; continue;
} }
@ -1677,6 +1709,18 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
skipCollision = true; skipCollision = true;
A->bSkipLineCol = true; A->bSkipLineCol = true;
Bobj->m_pCollidingEntity = A; Bobj->m_pCollidingEntity = A;
}else if(A->IsObject() && Aobj->m_nSpecialCollisionResponseCases == COLLRESPONSE_FENCEPART &&
B->IsObject() && Bobj->m_nSpecialCollisionResponseCases == COLLRESPONSE_FENCEPART){
skipCollision = true;
A->bSkipLineCol = true;
}else if(A->IsObject() && Aobj->bIsStreetLight && !B->IsBuilding() && IsLCSTrafficLight(A->GetModelIndex())){
skipCollision = true;
A->bSkipLineCol = true;
Aobj->m_pCollidingEntity = B;
}else if(B->IsObject() && Bobj->bIsStreetLight && !A->IsBuilding() && IsLCSTrafficLight(B->GetModelIndex())){
skipCollision = true;
B->bSkipLineCol = true;
Bobj->m_pCollidingEntity = A;
}else if(A->IsObject() && B->IsVehicle()){ }else if(A->IsObject() && B->IsVehicle()){
if(A->GetModelIndex() == MI_CAR_BUMPER) if(A->GetModelIndex() == MI_CAR_BUMPER)
skipCollision = true; skipCollision = true;
@ -1687,7 +1731,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
skipCollision = true; skipCollision = true;
else if(Aobj->m_nCollisionDamageEffect < DAMAGE_EFFECT_SMASH_COMPLETELY){ else if(Aobj->m_nCollisionDamageEffect < DAMAGE_EFFECT_SMASH_COMPLETELY){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(A->GetModelIndex())->boundingBox.GetSize();
size = A->GetMatrix() * size; size = A->GetMatrix() * size;
if(size.z < B->GetPosition().z || if(size.z < B->GetPosition().z ||
(Invert(B->GetMatrix(), inv) * size).z < 0.0f){ (Invert(B->GetMatrix(), inv) * size).z < 0.0f){
@ -1706,7 +1750,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
skipCollision = true; skipCollision = true;
else if(Bobj->m_nCollisionDamageEffect < DAMAGE_EFFECT_SMASH_COMPLETELY){ else if(Bobj->m_nCollisionDamageEffect < DAMAGE_EFFECT_SMASH_COMPLETELY){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(B->GetModelIndex())->boundingBox.GetSize();
size = B->GetMatrix() * size; size = B->GetMatrix() * size;
if(size.z < A->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f){ (Invert(A->GetMatrix(), inv) * size).z < 0.0f){
@ -1721,20 +1765,39 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
B->GetPosition().z < A->GetPosition().z){ B->GetPosition().z < A->GetPosition().z){
skipCollision = true; skipCollision = true;
A->bSkipLineCol = true; A->bSkipLineCol = true;
}else if(A->IsPed() && Aped->m_pCollidingEntity == B){ }else if(A->IsPed() && (Aped->m_pCollidingEntity == B || !A->phys_lcs_unk1)){
skipCollision = true; skipCollision = true;
if(!Aped->bKnockedUpIntoAir || Aped->bKnockedOffBike) if(!Aped->bKnockedUpIntoAir || Aped->bKnockedOffBike)
A->bSkipLineCol = true; A->bSkipLineCol = true;
}else if(B->IsPed() && Bped->m_pCollidingEntity == A){ }else if(B->IsPed() && (Bped->m_pCollidingEntity == A || !B->phys_lcs_unk1)){
skipCollision = true;
A->bSkipLineCol = true;
}else if(A->GetModelIndex() == MI_RCBANDIT && (B->IsPed() || B->IsVehicle()) ||
B->GetModelIndex() == MI_RCBANDIT && (A->IsPed() || A->IsVehicle())){
skipCollision = true; skipCollision = true;
A->bSkipLineCol = true; A->bSkipLineCol = true;
// }else if(A->GetModelIndex() == MI_RCBANDIT && (B->IsPed() || B->IsVehicle()) ||
// B->GetModelIndex() == MI_RCBANDIT && (A->IsPed() || A->IsVehicle())){
// skipCollision = true;
// A->bSkipLineCol = true;
}else if(A->IsPed() && B->IsObject() && Bobj->m_fUprootLimit > 0.0f) }else if(A->IsPed() && B->IsObject() && Bobj->m_fUprootLimit > 0.0f)
altcollision = true; altcollision = true;
if(A->IsObject() && !B->IsBuilding()){
if(!A->phys_lcs_unk1){
A->bSkipLineCol = true;
skipCollision = true;
#ifdef FIX_BUGS
// looks correct below
Aobj->m_pCollidingEntity = B;
#else
Aobj->m_pCollidingEntity = A;
#endif
}
}
if(B->IsObject() && !A->IsBuilding()){
if(!B->phys_lcs_unk1){
B->bSkipLineCol = true;
skipCollision = true;
Bobj->m_pCollidingEntity = A;
}
}
if(!A->bUsesCollision || skipCollision){ if(!A->bUsesCollision || skipCollision){
B->m_scanCode = CWorld::GetCurrentScanCode(); B->m_scanCode = CWorld::GetCurrentScanCode();
@ -1764,6 +1827,8 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
if(impulseA > maxImpulseA) maxImpulseA = impulseA; if(impulseA > maxImpulseA) maxImpulseA = impulseA;
if(A->IsVehicle()){ if(A->IsVehicle()){
if(B->IsMultiplayer())
A->SendMuliVehicleCollision(B, &aColPoints[i], impulseA);
if(!(((CVehicle*)A)->IsBoat() && aColPoints[i].surfaceB == SURFACE_WOOD_SOLID) && if(!(((CVehicle*)A)->IsBoat() && aColPoints[i].surfaceB == SURFACE_WOOD_SOLID) &&
impulseA > A->m_fDamageImpulse) impulseA > A->m_fDamageImpulse)
A->SetDamagedPieceRecord(aColPoints[i].pieceA, impulseA, B, aColPoints[i].normal); A->SetDamagedPieceRecord(aColPoints[i].pieceA, impulseA, B, aColPoints[i].normal);
@ -1801,6 +1866,8 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
float adhesion = CSurfaceTable::GetAdhesiveLimit(aColPoints[i]) / numCollisions; float adhesion = CSurfaceTable::GetAdhesiveLimit(aColPoints[i]) / numCollisions;
if(A->IsVehicle()){ if(A->IsVehicle()){
if(B->IsMultiplayer())
A->SendMuliVehicleCollision(B, &aColPoints[i], impulseA);
if(((CVehicle*)A)->IsBoat() && aColPoints[i].surfaceB == SURFACE_WOOD_SOLID) if(((CVehicle*)A)->IsBoat() && aColPoints[i].surfaceB == SURFACE_WOOD_SOLID)
adhesion = 0.0f; adhesion = 0.0f;
else if(impulseA > A->m_fDamageImpulse) else if(impulseA > A->m_fDamageImpulse)
@ -1856,7 +1923,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
if(!CWorld::bNoMoreCollisionTorque && if(!CWorld::bNoMoreCollisionTorque &&
A->GetStatus() == STATUS_PLAYER && A->IsVehicle() && A->GetStatus() == STATUS_PLAYER && A->IsVehicle() &&
Abs(A->m_vecMoveSpeed.x) > 0.2f && Abs(A->m_vecMoveSpeed.x) > 0.2f &&
Abs(A->m_vecMoveSpeed.y) > 0.2f){ Abs(A->m_vecMoveSpeed.y) > 0.2f && !A->bIsInWater){
A->m_vecMoveFriction.x += moveSpeed.x * -0.3f / numCollisions; A->m_vecMoveFriction.x += moveSpeed.x * -0.3f / numCollisions;
A->m_vecMoveFriction.y += moveSpeed.y * -0.3f / numCollisions; A->m_vecMoveFriction.y += moveSpeed.y * -0.3f / numCollisions;
A->m_vecTurnFriction += turnSpeed * -0.3f / numCollisions; A->m_vecTurnFriction += turnSpeed * -0.3f / numCollisions;
@ -2009,7 +2076,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
Bobj->ObjectDamage(maxImpulseB); Bobj->ObjectDamage(maxImpulseB);
else if(Bobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){ else if(Bobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(B->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(B->GetModelIndex())->boundingBox.GetSize();
size = B->GetMatrix() * size; size = B->GetMatrix() * size;
if(size.z < A->GetPosition().z || if(size.z < A->GetPosition().z ||
(Invert(A->GetMatrix(), inv) * size).z < 0.0f) (Invert(A->GetMatrix(), inv) * size).z < 0.0f)
@ -2024,7 +2091,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
else if(Bobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){ else if(Bobj->m_nCollisionDamageEffect >= DAMAGE_EFFECT_SMASH_COMPLETELY){
#endif #endif
CMatrix inv; CMatrix inv;
CVector size = CModelInfo::GetModelInfo(A->GetModelIndex())->GetColModel()->boundingBox.GetSize(); CVector size = CModelInfo::GetColModel(A->GetModelIndex())->boundingBox.GetSize();
size = A->GetMatrix() * size; size = A->GetMatrix() * size;
if(size.z < B->GetPosition().z || if(size.z < B->GetPosition().z ||
(Invert(B->GetMatrix(), inv) * size).z < 0.0f) (Invert(B->GetMatrix(), inv) * size).z < 0.0f)
@ -2077,7 +2144,6 @@ CPhysical::CheckCollision_SimpleCar(void)
float PHYSICAL_SHIFT_SPEED_DAMP = 0.707f; float PHYSICAL_SHIFT_SPEED_DAMP = 0.707f;
// --MIAMI: Proof-read once
void void
CPhysical::ProcessShift(void) CPhysical::ProcessShift(void)
{ {
@ -2133,7 +2199,7 @@ CPhysical::ProcessShift(void)
} }
// x is the number of units (m) we would like to step // x is the number of units (m) we would like to step
#define NUMSTEPS(x) ceil(Sqrt(distSq) * (1.0f/(x))) #define NUMSTEPS(x) Ceil(Sqrt(distSq) * (1.0f/(x)))
float HIGHSPEED_ELASTICITY_MULT_PED = 2.0f; float HIGHSPEED_ELASTICITY_MULT_PED = 2.0f;
float HIGHSPEED_ELASTICITY_MULT_COPCAR = 2.0f; float HIGHSPEED_ELASTICITY_MULT_COPCAR = 2.0f;
@ -2148,7 +2214,7 @@ CPhysical::ProcessCollision(void)
m_bIsVehicleBeingShifted = false; m_bIsVehicleBeingShifted = false;
bSkipLineCol = false; bSkipLineCol = false;
if(!bUsesCollision){ if(!bUsesCollision || IsMultiplayer()){
bIsStuck = false; bIsStuck = false;
bIsInSafePosition = true; bIsInSafePosition = true;
RemoveAndAdd(); RemoveAndAdd();
@ -2178,28 +2244,32 @@ CPhysical::ProcessCollision(void)
float distSq = m_vecMoveSpeed.MagnitudeSqr() * sq(CTimer::GetTimeStep()); float distSq = m_vecMoveSpeed.MagnitudeSqr() * sq(CTimer::GetTimeStep());
if(IsPed() && (distSq >= sq(0.3f) || ped->IsPlayer())){ if(IsPed() && (distSq >= sq(0.3f) || ped->IsPlayer())){
if(ped->IsPlayer()){ if(ped->IsPlayer() && ped->m_pCurrentPhysSurface)
if(ped->m_pCurrentPhysSurface)
n = Max(NUMSTEPS(0.15f), 4.0f); n = Max(NUMSTEPS(0.15f), 4.0f);
else else
n = Max(NUMSTEPS(0.3f), 2.0f); n = Max(NUMSTEPS(0.3f), 2.0f);
}else if(ped->IsPlayer() && ped->bHasHitWall)
n = NUMSTEPS(0.45f); n *= 2;
step = savedTimeStep / n; step = savedTimeStep / n;
if(!ped->IsPlayer()) if(!ped->IsPlayer())
ped->m_fElasticity *= HIGHSPEED_ELASTICITY_MULT_PED; ped->m_fElasticity *= HIGHSPEED_ELASTICITY_MULT_PED;
}else if(IsVehicle() && distSq >= sq(0.4f)){ }else if(IsVehicle()){
if(GetStatus() == STATUS_PLAYER) if(GetStatus() == STATUS_PLAYER)
n = NUMSTEPS(0.2f); n = NUMSTEPS(0.3f);
else else
n = distSq > 0.32f ? NUMSTEPS(0.3f) : NUMSTEPS(0.4f); n = NUMSTEPS(0.4f);
if(n == 0)
n = 1;
step = savedTimeStep / n; step = savedTimeStep / n;
if(n > 2){
CVector bbox = GetColModel()->boundingBox.GetSize(); CVector bbox = GetColModel()->boundingBox.GetSize();
float relDistX = Abs(DotProduct(m_vecMoveSpeed, GetRight())) * CTimer::GetTimeStep() / bbox.x; float relDistX = Abs(DotProduct(m_vecMoveSpeed, GetRight())) * CTimer::GetTimeStep() / bbox.x;
float relDistY = Abs(DotProduct(m_vecMoveSpeed, GetForward())) * CTimer::GetTimeStep() / bbox.y; float relDistY = Abs(DotProduct(m_vecMoveSpeed, GetForward())) * CTimer::GetTimeStep() / bbox.y;
float relDistZ = Abs(DotProduct(m_vecMoveSpeed, GetUp())) * CTimer::GetTimeStep() / bbox.z; float relDistZ = Abs(DotProduct(m_vecMoveSpeed, GetUp())) * CTimer::GetTimeStep() / bbox.z;
if(Max(relDistX, Max(relDistY, relDistZ)) < 1.0f){ float relDist = Max(relDistX, Max(relDistY, relDistZ));
if(((CVehicle*)this)->GetVehicleAppearance() == VEHICLE_APPEARANCE_BIKE)
relDist *= 2.0f;
if(relDist < 1.0f){
// check if we can get away with simplified processing // check if we can get away with simplified processing
ApplyMoveSpeed(); ApplyMoveSpeed();
@ -2209,10 +2279,11 @@ CPhysical::ProcessCollision(void)
m_bIsVehicleBeingShifted = false; m_bIsVehicleBeingShifted = false;
bJustCheckCollision = true; bJustCheckCollision = true;
bool savedUsesCollision = bUsesCollision;
bUsesCollision = false; bUsesCollision = false;
if(!CheckCollision()){ if(!CheckCollision()){
bJustCheckCollision = false; bJustCheckCollision = false;
bUsesCollision = true; bUsesCollision = savedUsesCollision;
if(IsVehicle()) if(IsVehicle())
((CVehicle*)this)->bVehicleColProcessed = true; ((CVehicle*)this)->bVehicleColProcessed = true;
@ -2227,12 +2298,13 @@ CPhysical::ProcessCollision(void)
return; return;
} }
bJustCheckCollision = false; bJustCheckCollision = false;
bUsesCollision = true; bUsesCollision = savedUsesCollision;
GetMatrix() = savedMatrix; GetMatrix() = savedMatrix;
m_vecMoveSpeed = savedMoveSpeed; m_vecMoveSpeed = savedMoveSpeed;
if(IsVehicle() && ((CVehicle*)this)->bIsLawEnforcer) if(IsVehicle() && ((CVehicle*)this)->bIsLawEnforcer)
m_fElasticity *= HIGHSPEED_ELASTICITY_MULT_COPCAR; m_fElasticity *= HIGHSPEED_ELASTICITY_MULT_COPCAR;
} }
}
}else if(IsObject() && ((CObject*)this)->ObjectCreatedBy != TEMP_OBJECT){ }else if(IsObject() && ((CObject*)this)->ObjectCreatedBy != TEMP_OBJECT){
int responsecase = ((CObject*)this)->m_nSpecialCollisionResponseCases; int responsecase = ((CObject*)this)->m_nSpecialCollisionResponseCases;
if(responsecase == COLLRESPONSE_LAMPOST){ if(responsecase == COLLRESPONSE_LAMPOST){
@ -2314,7 +2386,7 @@ CPhysical::ProcessCollision(void)
bSkipLineCol = false; bSkipLineCol = false;
if(!m_vecMoveSpeed.IsZero() || if(!m_vecMoveSpeed.IsZero() ||
!m_vecTurnSpeed.IsZero() || !m_vecTurnSpeed.IsZero() ||
bHitByTrain || // bHitByTrain ||
GetStatus() == STATUS_PLAYER || GetStatus() == STATUS_PLAYER ||
IsVehicle() && ((CVehicle*)this)->bRestingOnPhysical || IsVehicle() && ((CVehicle*)this)->bRestingOnPhysical ||
IsPed() && ped->IsPlayer()){ IsPed() && ped->IsPlayer()){

View file

@ -15,8 +15,6 @@ class CTreadable;
class CPhysical : public CEntity class CPhysical : public CEntity
{ {
public: public:
// The not properly indented fields haven't been checked properly yet
int32 m_audioEntityId; int32 m_audioEntityId;
float m_phys_unused1; float m_phys_unused1;
uint32 m_nLastTimeCollided; uint32 m_nLastTimeCollided;
@ -63,9 +61,13 @@ public:
uint8 m_bIsVehicleBeingShifted : 1; // wrong name - also used on but never set for peds uint8 m_bIsVehicleBeingShifted : 1; // wrong name - also used on but never set for peds
uint8 bJustCheckCollision : 1; // just see if there is a collision uint8 bJustCheckCollision : 1; // just see if there is a collision
bool phys_lcs_unk1;
uint8 m_nSurfaceTouched; uint8 m_nSurfaceTouched;
int8 m_nZoneLevel; int8 m_nZoneLevel;
int8 phys_lcs_unk2;
CPhysical(void); CPhysical(void);
~CPhysical(void); ~CPhysical(void);
@ -77,6 +79,9 @@ public:
void ProcessShift(void); void ProcessShift(void);
void ProcessCollision(void); void ProcessCollision(void);
// these two are virtual in LCS...why?
virtual void ApplyMoveSpeed(void);
virtual void ApplyTurnSpeed(void);
virtual int32 ProcessEntityCollision(CEntity *ent, CColPoint *colpoints); virtual int32 ProcessEntityCollision(CEntity *ent, CColPoint *colpoints);
void RemoveAndAdd(void); void RemoveAndAdd(void);
@ -143,8 +148,6 @@ public:
m_vecCentreOfMass.z = z; m_vecCentreOfMass.z = z;
} }
void ApplyMoveSpeed(void);
void ApplyTurnSpeed(void);
// Force actually means Impulse here // Force actually means Impulse here
void ApplyMoveForce(float jx, float jy, float jz); void ApplyMoveForce(float jx, float jy, float jz);
void ApplyMoveForce(const CVector &j) { ApplyMoveForce(j.x, j.y, j.z); } void ApplyMoveForce(const CVector &j) { ApplyMoveForce(j.x, j.y, j.z); }
@ -152,6 +155,7 @@ public:
void ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz); void ApplyTurnForce(float jx, float jy, float jz, float px, float py, float pz);
// j is direction of force, p is point relative to model center where force is applied // j is direction of force, p is point relative to model center where force is applied
void ApplyTurnForce(const CVector &j, const CVector &p) { ApplyTurnForce(j.x, j.y, j.z, p.x, p.y, p.z); } void ApplyTurnForce(const CVector &j, const CVector &p) { ApplyTurnForce(j.x, j.y, j.z, p.x, p.y, p.z); }
void ApplyTurnForceMultiplayer(const CVector &j, const CVector &p);
void ApplyFrictionMoveForce(float jx, float jy, float jz); void ApplyFrictionMoveForce(float jx, float jy, float jz);
void ApplyFrictionMoveForce(const CVector &j) { ApplyFrictionMoveForce(j.x, j.y, j.z); } void ApplyFrictionMoveForce(const CVector &j) { ApplyFrictionMoveForce(j.x, j.y, j.z); }
void ApplyFrictionTurnForce(float jx, float jy, float jz, float rx, float ry, float rz); void ApplyFrictionTurnForce(float jx, float jy, float jz, float rx, float ry, float rz);
@ -175,6 +179,8 @@ public:
bool CheckCollision(void); bool CheckCollision(void);
bool CheckCollision_SimpleCar(void); bool CheckCollision_SimpleCar(void);
void SendMuliVehicleCollision(CEntity *,CColPoint *,float) {}
// TEMP // TEMP
bool ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir); bool ApplySpringCollisionAlt(float springConst, CVector &springDir, CVector &point, float springRatio, float bias, CVector &forceDir);
bool ApplySpringDampening(float damping, CVector &springDir, CVector &point, CVector &speed); bool ApplySpringDampening(float damping, CVector &springDir, CVector &point, CVector &speed);

View file

@ -1292,6 +1292,15 @@ IsLampPost(int16 id)
id == MI_TRAFFICLIGHTS_TWOVERTICAL; id == MI_TRAFFICLIGHTS_TWOVERTICAL;
} }
inline bool
IsLCSTrafficLight(int16 id)
{
return id == MI_TLIGHT_POST ||
id == MI_TLIGHT_WALK ||
id == MI_TLIGHT_BOX1 ||
id == MI_TLIGHT_BOX2;
}
inline bool inline bool
IsBodyPart(int16 id) IsBodyPart(int16 id)
{ {