summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.appveyor.yml4
-rw-r--r--README.md4
-rw-r--r--src/core/Range2D.cpp28
-rw-r--r--src/core/Range2D.h11
-rw-r--r--src/core/Range3D.cpp30
-rw-r--r--src/core/Range3D.h11
-rw-r--r--src/entities/Entity.h2
-rw-r--r--src/entities/Physical.cpp2
-rw-r--r--src/math/Quaternion.h1
-rw-r--r--src/math/math.cpp11
-rw-r--r--src/peds/Ped.cpp368
-rw-r--r--src/peds/Ped.h15
-rw-r--r--src/peds/PedChat.cpp140
-rw-r--r--src/peds/PedDebug.cpp310
-rw-r--r--src/vehicles/Automobile.cpp57
-rw-r--r--src/vehicles/Bike.cpp1089
-rw-r--r--src/vehicles/Bike.h21
-rw-r--r--src/vehicles/Vehicle.cpp2
-rw-r--r--src/vehicles/Vehicle.h8
19 files changed, 1696 insertions, 418 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index 611294a5..f4b28dd4 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -40,13 +40,13 @@ deploy:
api_key:
secure: xWnYDfNWM87iPoBFbz6L1XAduxijJRWSpQLhMDOjznmzbMCsORtdx2tmWmFLTwf6
subject: gtamodding
- repo: re3
+ repo: revc
package: "%configuration%_%platform%"
version: "%APPVEYOR_BUILD_VERSION%"
artifact: reVC
publish: true
on:
- branch: master
+ branch: miami
APPVEYOR_REPO_TAG: false
cache:
diff --git a/README.md b/README.md
index 3dcc9f58..e96afb58 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,8 @@
<a href="https://discord.gg/jYpXxTm"><img src="https://img.shields.io/badge/discord-join-7289DA.svg?logo=discord&longCache=true&style=flat" /></a>
| Platform | Debug | Release |
|------------------|-------------|-------------|
-| Windows Direct3D9 | [![Download](https://api.bintray.com/packages/gtamodding/re3/Debug_win-x86-librw_d3d9-mss/images/download.svg)](https://bintray.com/gtamodding/re3/Debug_win-x86-librw_d3d9-mss/_latestVersion) | [![Download](https://api.bintray.com/packages/gtamodding/re3/Release_win-x86-librw_d3d9-mss/images/download.svg)](https://bintray.com/gtamodding/re3/Release_win-x86-librw_d3d9-mss/_latestVersion) |
-| Windows OpenGL3.3 | [![Download](https://api.bintray.com/packages/gtamodding/re3/Debug_win-x86-librw_gl3_glfw-mss/images/download.svg)](https://bintray.com/gtamodding/re3/Debug_win-x86-librw_gl3_glfw-mss/_latestVersion) | [![Download](https://api.bintray.com/packages/gtamodding/re3/Release_win-x86-librw_gl3_glfw-mss/images/download.svg)](https://bintray.com/gtamodding/re3/Release_win-x86-librw_gl3_glfw-mss/_latestVersion) |
+| Windows Direct3D9 | [![Download](https://api.bintray.com/packages/gtamodding/revc/Debug_win-x86-librw_d3d9-mss/images/download.svg)](https://bintray.com/gtamodding/revc/Debug_win-x86-librw_d3d9-mss/_latestVersion) | [![Download](https://api.bintray.com/packages/gtamodding/revc/Release_win-x86-librw_d3d9-mss/images/download.svg)](https://bintray.com/gtamodding/revc/Release_win-x86-librw_d3d9-mss/_latestVersion) |
+| Windows OpenGL3.3 | [![Download](https://api.bintray.com/packages/gtamodding/revc/Debug_win-x86-librw_gl3_glfw-mss/images/download.svg)](https://bintray.com/gtamodding/revc/Debug_win-x86-librw_gl3_glfw-mss/_latestVersion) | [![Download](https://api.bintray.com/packages/gtamodding/revc/Release_win-x86-librw_gl3_glfw-mss/images/download.svg)](https://bintray.com/gtamodding/revc/Release_win-x86-librw_gl3_glfw-mss/_latestVersion) |
## Intro
diff --git a/src/core/Range2D.cpp b/src/core/Range2D.cpp
new file mode 100644
index 00000000..33eafd0e
--- /dev/null
+++ b/src/core/Range2D.cpp
@@ -0,0 +1,28 @@
+#include "common.h"
+#include "Range2D.h"
+#include "General.h"
+
+CRange2D::CRange2D(CVector2D _min, CVector2D _max) : min(_min), max(_max) {}
+
+bool
+CRange2D::IsInRange(CVector2D vec)
+{
+ return min.x < vec.x && max.x > vec.x && min.y < vec.y && max.y > vec.y;
+}
+
+void
+CRange2D::DebugShowRange(float, int)
+{
+}
+
+CVector2D
+CRange2D::GetRandomPointInRange()
+{
+ int distX = Abs(max.x - min.x);
+ int distY = Abs(max.y - min.y);
+
+ float outX = CGeneral::GetRandomNumber() % distX + min.x;
+ float outY = CGeneral::GetRandomNumber() % distY + min.y;
+
+ return CVector2D(outX, outY);
+}
diff --git a/src/core/Range2D.h b/src/core/Range2D.h
new file mode 100644
index 00000000..f239e7de
--- /dev/null
+++ b/src/core/Range2D.h
@@ -0,0 +1,11 @@
+#pragma once
+
+class CRange2D
+{
+ CVector2D min, max;
+public:
+ CRange2D(CVector2D _min, CVector2D _max);
+ bool IsInRange(CVector2D vec);
+ void DebugShowRange(float, int);
+ CVector2D GetRandomPointInRange();
+}; \ No newline at end of file
diff --git a/src/core/Range3D.cpp b/src/core/Range3D.cpp
new file mode 100644
index 00000000..7fa28d67
--- /dev/null
+++ b/src/core/Range3D.cpp
@@ -0,0 +1,30 @@
+#include "common.h"
+#include "Range3D.h"
+#include "General.h"
+
+CRange3D::CRange3D(CVector _min, CVector _max) : min(_min), max(_max) {}
+
+bool
+CRange3D::IsInRange(CVector vec)
+{
+ return min.x < vec.x && max.x > vec.x && min.y < vec.y && max.y > vec.y && min.z < vec.z && max.z > vec.z;
+}
+
+void
+CRange3D::DebugShowRange(float, int)
+{
+}
+
+CVector
+CRange3D::GetRandomPointInRange()
+{
+ int distX = Abs(max.x - min.x);
+ int distY = Abs(max.y - min.y);
+ int distZ = Abs(max.z - min.z);
+
+ float outX = CGeneral::GetRandomNumber() % distX + min.x;
+ float outY = CGeneral::GetRandomNumber() % distY + min.y;
+ float outZ = CGeneral::GetRandomNumber() % distZ + min.z;
+
+ return CVector(outX, outY, outZ);
+}
diff --git a/src/core/Range3D.h b/src/core/Range3D.h
new file mode 100644
index 00000000..f42b523b
--- /dev/null
+++ b/src/core/Range3D.h
@@ -0,0 +1,11 @@
+#pragma once
+
+class CRange3D
+{
+ CVector min, max;
+public:
+ CRange3D(CVector _min, CVector _max);
+ bool IsInRange(CVector vec);
+ void DebugShowRange(float, int);
+ CVector GetRandomPointInRange();
+}; \ No newline at end of file
diff --git a/src/entities/Entity.h b/src/entities/Entity.h
index f506017a..c3e4cc3b 100644
--- a/src/entities/Entity.h
+++ b/src/entities/Entity.h
@@ -30,7 +30,7 @@ enum eEntityStatus : uint8
STATUS_PLANE,
STATUS_PLAYER_REMOTE,
STATUS_PLAYER_DISABLED,
- STATUS_12, // TODO: what is this? used in CPhysical::ApplyAirResistance
+ STATUS_GHOST
};
class CEntity : public CPlaceable
diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp
index 1f62ef64..332d3d81 100644
--- a/src/entities/Physical.cpp
+++ b/src/entities/Physical.cpp
@@ -531,7 +531,7 @@ void
CPhysical::ApplyAirResistance(void)
{
if(m_fAirResistance > 0.1f){
- if(GetStatus() != STATUS_12){
+ if(GetStatus() != STATUS_GHOST){
float f = Pow(m_fAirResistance, CTimer::GetTimeStep());
m_vecMoveSpeed *= f;
m_vecTurnSpeed *= f;
diff --git a/src/math/Quaternion.h b/src/math/Quaternion.h
index 1d04bdff..dac49362 100644
--- a/src/math/Quaternion.h
+++ b/src/math/Quaternion.h
@@ -60,6 +60,7 @@ public:
}
void Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, float invSin, float t);
+ void Set(RwV3d *axis, float angle);
void Get(RwMatrix *matrix);
};
diff --git a/src/math/math.cpp b/src/math/math.cpp
index e8b459ae..0661dcac 100644
--- a/src/math/math.cpp
+++ b/src/math/math.cpp
@@ -171,6 +171,17 @@ CQuaternion::Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, fl
}
void
+CQuaternion::Set(RwV3d *axis, float angle)
+{
+ float halfCos = Cos(angle*0.5f);
+ float halfSin = Sin(angle*0.5f);
+ x = axis->x*halfSin;
+ y = axis->y*halfSin;
+ z = axis->z*halfSin;
+ w = halfCos;
+}
+
+void
CQuaternion::Get(RwMatrix *matrix)
{
float x2 = x+x;
diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp
index a48fc426..e404463e 100644
--- a/src/peds/Ped.cpp
+++ b/src/peds/Ped.cpp
@@ -57,6 +57,7 @@
#include "Timecycle.h"
#include "ParticleObject.h"
#include "Floater.h"
+#include "Range2D.h"
#include "Streaming.h"
#include "PedAttractor.h"
#include "Debug.h"
@@ -73,48 +74,6 @@ static CColPoint aTempPedColPts[MAX_COLLISION_POINTS];
// TODO(Miami)
#define AUDIO_NOT_READY
-// Corresponds to ped sounds (from SOUND_PED_DEATH to SOUND_PED_TAXI_CALL)
-PedAudioData CommentWaitTime[39] = {
- {500, 800, 500, 2},
- {500, 800, 500, 2},
- {500, 800, 500, 2},
- {500, 800, 500, 2},
- {100, 2, 100, 2},
- {700, 500, 1000, 500},
- {700, 500, 1000, 500},
- {5000, 2000, 15000, 3000},
- {5000, 2000, 15000, 3000},
- {5000, 2000, 15000, 3000},
- {6000, 6000, 6000, 6000},
- {1000, 1000, 2000, 2000},
- {1000, 500, 2000, 1500},
- {1000, 500, 2000, 1500},
- {800, 200, 1000, 500},
- {800, 200, 1000, 500},
- {800, 400, 2000, 1000},
- {800, 400, 2000, 1000},
- {400, 300, 2000, 1000},
- {2000, 1000, 2500, 1500},
- {200, 200, 200, 200},
- {6000, 3000, 5000, 6000},
- {6000, 3000, 9000, 5000},
- {6000, 3000, 9000, 5000},
- {6000, 3000, 9000, 5000},
- {400, 300, 4000, 1000},
- {400, 300, 4000, 1000},
- {400, 300, 4000, 1000},
- {1000, 500, 3000, 1000},
- {1000, 500, 1000, 1000},
- {3000, 2000, 3000, 2000},
- {1000, 500, 3000, 6000},
- {1000, 500, 2000, 4000},
- {1000, 500, 2000, 5000},
- {1000, 500, 3000, 2000},
- {1600, 1000, 2000, 2000},
- {3000, 2000, 5000, 3000},
- {1000, 1000, 1000, 1000},
- {1000, 1000, 5000, 5000},
-};
uint16 nPlayerInComboMove;
RpClump *flyingClumpTemp;
@@ -143,228 +102,11 @@ void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->N
void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); }
void CPed::operator delete(void *p, int handle) { CPools::GetPedPool()->Delete((CPed*)p); }
-static char ObjectiveText[][28] = {
- "No Obj",
- "Wait on Foot",
- "Flee on Foot Till Safe",
- "Guard Spot",
- "Guard Area",
- "Wait in Car",
- "Wait in Car then Getout",
- "Kill Char on Foot",
- "Kill Char Any Means",
- "Flee Char on Foot Till Safe",
- "Flee Char on Foot Always",
- "GoTo Char on Foot",
- "Follow Char in Formation",
- "Leave Car",
- "Enter Car as Passenger",
- "Enter Car as Driver",
- "Follow Car in Car",
- "Fire at Obj from Vehicle",
- "Destroy Obj",
- "Destroy Car",
- "GoTo Area Any Means",
- "GoTo Area on Foot",
- "Run to Area",
- "GoTo Area in Car",
- "Follow Car on Foot Woffset",
- "Guard Attack",
- "Set Leader",
- "Follow Route",
- "Solicit",
- "Take Taxi",
- "Catch Train",
- "Buy IceCream",
- "Steal Any Car",
- "Mug Char",
-#ifdef VC_PED_PORTS
- "Leave Car and Die"
-#endif
-};
-
-static char StateText[][18] = {
- "None",
- "Idle",
- "Look Entity",
- "Look Heading",
- "Wander Range",
- "Wander Path",
- "Seek Pos",
- "Seek Entity",
- "Flee Pos",
- "Flee Entity",
- "Pursue",
- "Follow Path",
- "Sniper Mode",
- "Rocket Mode",
- "Dummy",
- "Pause",
- "Attack",
- "Fight",
- "Face Phone",
- "Make Call",
- "Chat",
- "Mug",
- "AimGun",
- "AI Control",
- "Seek Car",
- "Seek InBoat",
- "Follow Route",
- "C.P.R.",
- "Solicit",
- "Buy IceCream",
- "Investigate",
- "Step away",
- "On Fire",
- "Unknown",
- "STATES_NO_AI",
- "Jump",
- "Fall",
- "GetUp",
- "Stagger",
- "Dive away",
- "STATES_NO_ST",
- "Enter Train",
- "Exit Train",
- "Arrest Plyr",
- "Driving",
- "Passenger",
- "Taxi Passngr",
- "Open Door",
- "Die",
- "Dead",
- "CarJack",
- "Drag fm Car",
- "Enter Car",
- "Steal Car",
- "Exit Car",
- "Hands Up",
- "Arrested",
-};
-
-static char PersonalityTypeText[][18] = {
- "Player",
- "Cop",
- "Medic",
- "Fireman",
- "Gang 1",
- "Gang 2",
- "Gang 3",
- "Gang 4",
- "Gang 5",
- "Gang 6",
- "Gang 7",
- "Street Guy",
- "Suit Guy",
- "Sensible Guy",
- "Geek Guy",
- "Old Guy",
- "Tough Guy",
- "Street Girl",
- "Suit Girl",
- "Sensible Girl",
- "Geek Girl",
- "Old Girl",
- "Tough Girl",
- "Tramp Male",
- "Tramp Female",
- "Tourist",
- "Prostitute",
- "Criminal",
- "Busker",
- "Taxi Driver",
- "Psycho",
- "Steward",
- "Sports Fan",
- "Shopper",
- "Old Shopper"
-};
-
-static char WaitStateText[][16] = {
- "No Wait",
- "Traffic Lights",
- "Pause CrossRoad",
- "Look CrossRoad",
- "Look Ped",
- "Look Shop",
- "Look Accident",
- "FaceOff Gang",
- "Double Back",
- "Hit Wall",
- "Turn 180deg",
- "Surprised",
- "Ped Stuck",
- "Look About",
- "Play Duck",
- "Play Cower",
- "Play Taxi",
- "Play HandsUp",
- "Play HandsCower",
- "Play Chat",
- "Finish Flee",
-};
-
#ifdef TOGGLEABLE_BETA_FEATURES
bool CPed::bPopHeadsOnHeadshot = false;
bool CPed::bMakePedsRunToPhonesToReportCrimes = false;
#endif
-#ifndef MASTER
-int nDisplayDebugInfo = 0;
-
-void
-CPed::SwitchDebugDisplay(void)
-{
- nDisplayDebugInfo = !nDisplayDebugInfo;
-}
-
-void
-CPed::DebugRenderOnePedText(void)
-{
- if ((GetPosition() - TheCamera.GetPosition()).MagnitudeSqr() < sq(30.0f)) {
- float width, height;
- RwV3d screenCoords;
- CVector bitAbove = GetPosition();
- bitAbove.z += 2.0f;
- if (CSprite::CalcScreenCoors(bitAbove, &screenCoords, &width, &height, true)) {
-
- float lineHeight = SCREEN_SCALE_Y(Min(height/100.0f, 0.7f) * 22.0f);
-
- DefinedState();
- CFont::SetPropOn();
- CFont::SetBackgroundOn();
-
- // Originally both of them were being divided by 60.0f.
- float xScale = Min(width / 240.0f, 0.7f);
- float yScale = Min(height / 80.0f, 0.7f);
-
- CFont::SetScale(SCREEN_SCALE_X(xScale), SCREEN_SCALE_Y(yScale));
- CFont::SetCentreOn();
- CFont::SetCentreSize(SCREEN_WIDTH);
- CFont::SetJustifyOff();
- CFont::SetColor(CRGBA(255, 255, 0, 255));
- CFont::SetBackGroundOnlyTextOn();
- CFont::SetFontStyle(0);
- AsciiToUnicode(StateText[m_nPedState], gUString);
- CFont::PrintString(screenCoords.x, screenCoords.y, gUString);
- AsciiToUnicode(ObjectiveText[m_objective], gUString);
- CFont::PrintString(screenCoords.x, screenCoords.y + lineHeight, gUString);
- AsciiToUnicode(PersonalityTypeText[m_pedStats->m_type], gUString);
- CFont::PrintString(screenCoords.x, screenCoords.y + 2 * lineHeight, gUString);
- AsciiToUnicode(WaitStateText[m_nWaitState], gUString);
- CFont::PrintString(screenCoords.x, screenCoords.y + 3 * lineHeight, gUString);
- if (m_nPedState == PED_SEEK_POS || m_nPedState == PED_SEEK_ENTITY) {
- sprintf(gString, "Safe distance to target: %.2f", m_distanceToCountSeekDone);
- AsciiToUnicode(gString, gUString);
- CFont::PrintString(screenCoords.x, screenCoords.y + 4 * lineHeight, gUString);
- }
- DefinedState();
- }
- }
-}
-#endif
-
CPed::~CPed(void)
{
CWorld::Remove(this);
@@ -2743,7 +2485,7 @@ CPed::SetupLighting(void)
#ifndef MASTER
// Originally this was being called through iteration of Sectors, but putting it here is better.
- if (nDisplayDebugInfo && !IsPlayer())
+ if (GetDebugDisplay() != 0 && !IsPlayer())
DebugRenderOnePedText();
#endif
@@ -6107,61 +5849,6 @@ CPed::PlayHitSound(CPed *hitTo)
DMAudio.PlayOneShot(m_audioEntityId, soundId, 0.0f);
}
-// --MIAMI: Done except ifdef
-void
-CPed::Say(uint16 audio)
-{
- uint16 audioToPlay = audio;
-
- if (3.0f + TheCamera.GetPosition().z < GetPosition().z)
- return;
-
- if (TheCamera.m_CameraAverageSpeed > 1.65f) {
- if (audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND)
- return;
-
- } else if (TheCamera.m_CameraAverageSpeed > 1.25f) {
- if (audio != SOUND_PED_DEATH &&
- audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND &&
- audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE)
- return;
-
- } else if (TheCamera.m_CameraAverageSpeed > 0.9f) {
- switch (audio) {
- case SOUND_PED_DEATH:
- case SOUND_PED_DAMAGE:
- case SOUND_PED_HIT:
- case SOUND_PED_LAND:
- case SOUND_PED_BURNING:
- case SOUND_PED_FLEE_SPRINT:
- case SOUND_PED_TAXI_WAIT:
- case SOUND_PED_EVADE:
- case SOUND_PED_CAR_COLLISION:
- case SOUND_PED_BOAT_COLLISION:
- case SOUND_PED_HORN_ACTIVE:
- break;
- default:
- return;
- }
- }
-
- if (audioToPlay < m_queuedSound) {
- if (audioToPlay != m_lastQueuedSound || audioToPlay == SOUND_PED_DEATH
-
- // See VC Ped Speech patch
-#ifdef FIX_BUGS
- || CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime
- + (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nMaxRandomDelayTime)
-#else
- || CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime
- + (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nMaxRandomDelayTime)
-#endif
- + m_lastSoundStart <= CTimer::GetTimeInMilliseconds()) {
- m_queuedSound = audioToPlay;
- }
- }
-}
-
void
CPed::CollideWithPed(CPed *collideWith)
{
@@ -11654,13 +11341,6 @@ CPed::SetJump(void)
}
// --MIAMI: Done
-bool
-CPed::ServiceTalkingWhenDead(void)
-{
- return m_queuedSound == SOUND_PED_DEATH;
-}
-
-// --MIAMI: Done
void
CPed::RemoveInCarAnims(void)
{
@@ -15607,17 +15287,9 @@ CPed::WanderRange(void)
bool arrived = Seek();
if (arrived) {
Idle();
- if (((m_randomSeed % 256) + 3 * CTimer::GetFrameCounter()) % 1000 > 997) {
-
- int xDiff = Abs(m_wanderRangeBounds[1].x - m_wanderRangeBounds[0].x);
- int yDiff = Abs(m_wanderRangeBounds[1].y - m_wanderRangeBounds[0].y);
-
- CVector newCoords(
- (CGeneral::GetRandomNumber() % xDiff) + m_wanderRangeBounds[0].x,
- (CGeneral::GetRandomNumber() % yDiff) + m_wanderRangeBounds[0].y,
- GetPosition().z);
-
- SetSeek(newCoords, 2.5f);
+ if ((m_randomSeed + 3 * CTimer::GetFrameCounter()) % 1000 > 997) {
+ CVector2D newCoords2D = m_wanderRangeBounds->GetRandomPointInRange();
+ SetSeek(CVector(newCoords2D.x, newCoords2D.y, GetPosition().z), 2.5f);
}
}
}
@@ -16944,36 +16616,6 @@ CPed::SeekCar(void)
}
}
-// --MIAMI: Done except ifdef
-void
-CPed::ServiceTalking(void)
-{
- if (!bBodyPartJustCameOff || m_bodyPartBleeding != PED_HEAD) {
- if (!CGame::germanGame && m_pFire)
- m_queuedSound = SOUND_PED_BURNING;
-
- if (m_queuedSound != SOUND_NO_SOUND) {
- if (m_queuedSound == SOUND_PED_DEATH)
- m_soundStart = CTimer::GetTimeInMilliseconds() - 1;
-
- if (CTimer::GetTimeInMilliseconds() > m_soundStart) {
- DMAudio.PlayOneShot(m_audioEntityId, m_queuedSound, 1.0f);
- m_lastSoundStart = CTimer::GetTimeInMilliseconds();
- m_soundStart =
- CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nFixedDelayTime
- + CTimer::GetTimeInMilliseconds()
- + CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideFixedDelayTime);
-
- if (m_queuedSound == SOUND_PED_PLAYER_BEFORESEX && IsPlayer())
- m_soundStart += 2000;
-
- m_lastQueuedSound = m_queuedSound;
- m_queuedSound = SOUND_NO_SOUND;
- }
- }
- }
-}
-
void
CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk)
{
diff --git a/src/peds/Ped.h b/src/peds/Ped.h
index 0ac6f930..0d7ff972 100644
--- a/src/peds/Ped.h
+++ b/src/peds/Ped.h
@@ -570,7 +570,7 @@ public:
CEntity *m_pCollidingEntity;
uint8 m_stateUnused;
uint32 m_timerUnused;
- CVector2D *m_wanderRangeBounds; // array with 2 CVector2D (actually unused CRange2D class) - unused
+ class CRange2D *m_wanderRangeBounds;
CWeapon m_weapons[TOTAL_WEAPON_SLOTS];
eWeaponType m_storedWeapon;
eWeaponType m_delayedWeapon;
@@ -1064,8 +1064,21 @@ public:
#ifndef MASTER
// Mobile things
+ void DebugDrawPedDestination(CPed *, int, int);
+ void DebugDrawPedDesiredHeading(CPed *, int, int);
+ void DebugDrawCollisionRadius(float, float, float, float, int);
+ void DebugDrawVisionRange(CVector, float);
+ void DebugDrawVisionSimple(CVector, float);
+ void DebugDrawLook();
+ void DebugDrawPedPsyche();
+ void DebugDrawDebugLines();
+
static void SwitchDebugDisplay(void);
+ static int GetDebugDisplay(void);
+
+ void DebugDrawLookAtPoints();
void DebugRenderOnePedText(void);
+ void DebugRenderClosePedText();
#endif
#ifdef COMPATIBLE_SAVES
diff --git a/src/peds/PedChat.cpp b/src/peds/PedChat.cpp
new file mode 100644
index 00000000..78302844
--- /dev/null
+++ b/src/peds/PedChat.cpp
@@ -0,0 +1,140 @@
+#include "common.h"
+#include "Camera.h"
+#include "DMAudio.h"
+#include "General.h"
+#include "Ped.h"
+
+// Corresponds to ped sounds (from SOUND_PED_DEATH to SOUND_PED_TAXI_CALL)
+PedAudioData CommentWaitTime[39] = {
+ {500, 800, 500, 2},
+ {500, 800, 500, 2},
+ {500, 800, 500, 2},
+ {500, 800, 500, 2},
+ {100, 2, 100, 2},
+ {700, 500, 1000, 500},
+ {700, 500, 1000, 500},
+ {5000, 2000, 15000, 3000},
+ {5000, 2000, 15000, 3000},
+ {5000, 2000, 15000, 3000},
+ {6000, 6000, 6000, 6000},
+ {1000, 1000, 2000, 2000},
+ {1000, 500, 2000, 1500},
+ {1000, 500, 2000, 1500},
+ {800, 200, 1000, 500},
+ {800, 200, 1000, 500},
+ {800, 400, 2000, 1000},
+ {800, 400, 2000, 1000},
+ {400, 300, 2000, 1000},
+ {2000, 1000, 2500, 1500},
+ {200, 200, 200, 200},
+ {6000, 3000, 5000, 6000},
+ {6000, 3000, 9000, 5000},
+ {6000, 3000, 9000, 5000},
+ {6000, 3000, 9000, 5000},
+ {400, 300, 4000, 1000},
+ {400, 300, 4000, 1000},
+ {400, 300, 4000, 1000},
+ {1000, 500, 3000, 1000},
+ {1000, 500, 1000, 1000},
+ {3000, 2000, 3000, 2000},
+ {1000, 500, 3000, 6000},
+ {1000, 500, 2000, 4000},
+ {1000, 500, 2000, 5000},
+ {1000, 500, 3000, 2000},
+ {1600, 1000, 2000, 2000},
+ {3000, 2000, 5000, 3000},
+ {1000, 1000, 1000, 1000},
+ {1000, 1000, 5000, 5000},
+};
+
+// --MIAMI: Done
+bool
+CPed::ServiceTalkingWhenDead(void)
+{
+ return m_queuedSound == SOUND_PED_DEATH;
+}
+
+// --MIAMI: Done except ifdef
+void
+CPed::ServiceTalking(void)
+{
+ if (!bBodyPartJustCameOff || m_bodyPartBleeding != PED_HEAD) {
+ if (!CGame::germanGame && m_pFire)
+ m_queuedSound = SOUND_PED_BURNING;
+
+ if (m_queuedSound != SOUND_NO_SOUND) {
+ if (m_queuedSound == SOUND_PED_DEATH)
+ m_soundStart = CTimer::GetTimeInMilliseconds() - 1;
+
+ if (CTimer::GetTimeInMilliseconds() > m_soundStart) {
+ DMAudio.PlayOneShot(m_audioEntityId, m_queuedSound, 1.0f);
+ m_lastSoundStart = CTimer::GetTimeInMilliseconds();
+ m_soundStart =
+ CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nFixedDelayTime
+ + CTimer::GetTimeInMilliseconds()
+ + CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideFixedDelayTime);
+
+ if (m_queuedSound == SOUND_PED_PLAYER_BEFORESEX && IsPlayer())
+ m_soundStart += 2000;
+
+ m_lastQueuedSound = m_queuedSound;
+ m_queuedSound = SOUND_NO_SOUND;
+ }
+ }
+ }
+}
+
+// --MIAMI: Done except ifdef
+void
+CPed::Say(uint16 audio)
+{
+ uint16 audioToPlay = audio;
+
+ if (3.0f + TheCamera.GetPosition().z < GetPosition().z)
+ return;
+
+ if (TheCamera.m_CameraAverageSpeed > 1.65f) {
+ if (audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND)
+ return;
+
+ } else if (TheCamera.m_CameraAverageSpeed > 1.25f) {
+ if (audio != SOUND_PED_DEATH &&
+ audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND &&
+ audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE)
+ return;
+
+ } else if (TheCamera.m_CameraAverageSpeed > 0.9f) {
+ switch (audio) {
+ case SOUND_PED_DEATH:
+ case SOUND_PED_DAMAGE:
+ case SOUND_PED_HIT:
+ case SOUND_PED_LAND:
+ case SOUND_PED_BURNING:
+ case SOUND_PED_FLEE_SPRINT:
+ case SOUND_PED_TAXI_WAIT:
+ case SOUND_PED_EVADE:
+ case SOUND_PED_CAR_COLLISION:
+ case SOUND_PED_BOAT_COLLISION:
+ case SOUND_PED_HORN_ACTIVE:
+ break;
+ default:
+ return;
+ }
+ }
+
+ if (audioToPlay < m_queuedSound) {
+ if (audioToPlay != m_lastQueuedSound || audioToPlay == SOUND_PED_DEATH
+
+ // See VC Ped Speech patch
+#ifdef FIX_BUGS
+ || CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime
+ + (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[audioToPlay - SOUND_PED_DEATH].m_nMaxRandomDelayTime)
+#else
+ || CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime
+ + (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nMaxRandomDelayTime)
+#endif
+ + m_lastSoundStart <= CTimer::GetTimeInMilliseconds()) {
+ m_queuedSound = audioToPlay;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/peds/PedDebug.cpp b/src/peds/PedDebug.cpp
new file mode 100644
index 00000000..1c22963e
--- /dev/null
+++ b/src/peds/PedDebug.cpp
@@ -0,0 +1,310 @@
+#include "common.h"
+#ifndef MASTER
+#include "main.h"
+#include "Camera.h"
+#include "Font.h"
+#include "Ped.h"
+#include "Sprite.h"
+#include "Text.h"
+
+
+static char ObjectiveText[][28] = {
+ "No Obj",
+ "Wait on Foot",
+ "Flee on Foot Till Safe",
+ "Guard Spot",
+ "Guard Area",
+ "Wait in Car",
+ "Wait in Car then Getout",
+ "Kill Char on Foot",
+ "Kill Char Any Means",
+ "Flee Char on Foot Till Safe",
+ "Flee Char on Foot Always",
+ "GoTo Char on Foot",
+ "Follow Char in Formation",
+ "Leave Car",
+ "Enter Car as Passenger",
+ "Enter Car as Driver",
+ "Follow Car in Car",
+ "Fire at Obj from Vehicle",
+ "Destroy Obj",
+ "Destroy Car",
+ "GoTo Area Any Means",
+ "GoTo Area on Foot",
+ "Run to Area",
+ "GoTo Area in Car",
+ "Follow Car on Foot Woffset",
+ "Guard Attack",
+ "Set Leader",
+ "Follow Route",
+ "Solicit",
+ "Take Taxi",
+ "Catch Train",
+ "Buy IceCream",
+ "Steal Any Car",
+ "Mug Char",
+#ifdef VC_PED_PORTS
+ "Leave Car and Die"
+#endif
+};
+
+static char StateText[][18] = {
+ "None",
+ "Idle",
+ "Look Entity",
+ "Look Heading",
+ "Wander Range",
+ "Wander Path",
+ "Seek Pos",
+ "Seek Entity",
+ "Flee Pos",
+ "Flee Entity",
+ "Pursue",
+ "Follow Path",
+ "Sniper Mode",
+ "Rocket Mode",
+ "Dummy",
+ "Pause",
+ "Attack",
+ "Fight",
+ "Face Phone",
+ "Make Call",
+ "Chat",
+ "Mug",
+ "AimGun",
+ "AI Control",
+ "Seek Car",
+ "Seek InBoat",
+ "Follow Route",
+ "C.P.R.",
+ "Solicit",
+ "Buy IceCream",
+ "Investigate",
+ "Step away",
+ "On Fire",
+ "Unknown",
+ "STATES_NO_AI",
+ "Jump",
+ "Fall",
+ "GetUp",
+ "Stagger",
+ "Dive away",
+ "STATES_NO_ST",
+ "Enter Train",
+ "Exit Train",
+ "Arrest Plyr",
+ "Driving",
+ "Passenger",
+ "Taxi Passngr",
+ "Open Door",
+ "Die",
+ "Dead",
+ "CarJack",
+ "Drag fm Car",
+ "Enter Car",
+ "Steal Car",
+ "Exit Car",
+ "Hands Up",
+ "Arrested",
+};
+
+static char PersonalityTypeText[][18] = {
+ "Player",
+ "Cop",
+ "Medic",
+ "Fireman",
+ "Gang 1",
+ "Gang 2",
+ "Gang 3",
+ "Gang 4",
+ "Gang 5",
+ "Gang 6",
+ "Gang 7",
+ "Street Guy",
+ "Suit Guy",
+ "Sensible Guy",
+ "Geek Guy",
+ "Old Guy",
+ "Tough Guy",
+ "Street Girl",
+ "Suit Girl",
+ "Sensible Girl",
+ "Geek Girl",
+ "Old Girl",
+ "Tough Girl",
+ "Tramp Male",
+ "Tramp Female",
+ "Tourist",
+ "Prostitute",
+ "Criminal",
+ "Busker",
+ "Taxi Driver",
+ "Psycho",
+ "Steward",
+ "Sports Fan",
+ "Shopper",
+ "Old Shopper"
+};
+
+static char WaitStateText[][16] = {
+ "No Wait",
+ "Traffic Lights",
+ "Pause CrossRoad",
+ "Look CrossRoad",
+ "Look Ped",
+ "Look Shop",
+ "Look Accident",
+ "FaceOff Gang",
+ "Double Back",
+ "Hit Wall",
+ "Turn 180deg",
+ "Surprised",
+ "Ped Stuck",
+ "Look About",
+ "Play Duck",
+ "Play Cower",
+ "Play Taxi",
+ "Play HandsUp",
+ "Play HandsCower",
+ "Play Chat",
+ "Finish Flee",
+};
+
+void
+CPed::DebugDrawPedDestination(CPed *, int, int)
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+void
+CPed::DebugDrawPedDesiredHeading(CPed *, int, int)
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+void
+CPed::DebugDrawCollisionRadius(float, float, float, float, int)
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+void
+CPed::DebugDrawVisionRange(CVector a1, float)
+{
+ for (int i = a1.x - 90; i < a1.x + 89; i += 30) {
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+ }
+}
+
+void
+CPed::DebugDrawVisionSimple(CVector, float)
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+void
+CPed::DebugDrawLook()
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+void
+CPed::DebugDrawPedPsyche()
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+void
+CPed::DebugDrawDebugLines()
+{
+#ifndef FINAL
+ // TODO: something was here
+#endif // !FINAL
+}
+
+int nDisplayDebugInfo = 0;
+
+void
+CPed::SwitchDebugDisplay(void)
+{
+ if (++nDisplayDebugInfo > 2)
+ nDisplayDebugInfo = 0;
+}
+
+int
+CPed::GetDebugDisplay(void)
+{
+ return nDisplayDebugInfo;
+}
+
+void
+CPed::DebugDrawLookAtPoints()
+{
+ // TODO: mobile code
+}
+
+void
+CPed::DebugRenderOnePedText(void)
+{
+ if ((GetPosition() - TheCamera.GetPosition()).MagnitudeSqr() < sq(30.0f)) {
+ float width, height;
+ RwV3d screenCoords;
+ CVector bitAbove = GetPosition();
+ bitAbove.z += 2.0f;
+ if (CSprite::CalcScreenCoors(bitAbove, &screenCoords, &width, &height, true)) {
+
+ float lineHeight = SCREEN_SCALE_Y(Min(height / 100.0f, 0.7f) * 22.0f);
+
+ DefinedState();
+ CFont::SetPropOn();
+ CFont::SetBackgroundOn();
+
+ // Originally both of them were being divided by 60.0f.
+ float xScale = Min(width / 240.0f, 0.7f);
+ float yScale = Min(height / 80.0f, 0.7f);
+
+ CFont::SetScale(SCREEN_SCALE_X(xScale), SCREEN_SCALE_Y(yScale));
+ CFont::SetCentreOn();
+ CFont::SetCentreSize(SCREEN_WIDTH);
+ CFont::SetJustifyOff();
+ CFont::SetColor(CRGBA(255, 255, 0, 255));
+ CFont::SetBackGroundOnlyTextOn();
+ CFont::SetFontStyle(0);
+ AsciiToUnicode(StateText[m_nPedState], gUString);
+ CFont::PrintString(screenCoords.x, screenCoords.y, gUString);
+ AsciiToUnicode(ObjectiveText[m_objective], gUString);
+ CFont::PrintString(screenCoords.x, screenCoords.y + lineHeight, gUString);
+ AsciiToUnicode(PersonalityTypeText[m_pedStats->m_type], gUString);
+ CFont::PrintString(screenCoords.x, screenCoords.y + 2 * lineHeight, gUString);
+ AsciiToUnicode(WaitStateText[m_nWaitState], gUString);
+ CFont::PrintString(screenCoords.x, screenCoords.y + 3 * lineHeight, gUString);
+ if (m_nPedState == PED_SEEK_POS || m_nPedState == PED_SEEK_ENTITY) {
+ sprintf(gString, "Safe distance to target: %.2f", m_distanceToCountSeekDone);
+ AsciiToUnicode(gString, gUString);
+ CFont::PrintString(screenCoords.x, screenCoords.y + 4 * lineHeight, gUString);
+ }
+ DefinedState();
+ }
+ }
+}
+
+void
+CPed::DebugRenderClosePedText()
+{
+ // TODO: mobile code
+}
+#endif \ No newline at end of file
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp
index 8bf2a414..a09e184e 100644
--- a/src/vehicles/Automobile.cpp
+++ b/src/vehicles/Automobile.cpp
@@ -255,6 +255,7 @@ void
CAutomobile::ProcessControl(void)
{
int i;
+ float wheelRot;
CColModel *colModel;
if(bUsingSpecialColModel)
@@ -422,7 +423,7 @@ CAutomobile::ProcessControl(void)
float slowdown;
CVector parallelSpeed = m_vecMoveSpeed - DotProduct(m_vecMoveSpeed, GetUp())*m_vecMoveSpeed;
float fSpeed = parallelSpeed.MagnitudeSqr();
- if(fSpeed > 0.09f){
+ if(fSpeed > SQR(0.3f)){
fSpeed = Sqrt(fSpeed);
parallelSpeed *= 0.3f / fSpeed;
slowdown = SAND_SLOWDOWN * Max(1.0f - 2.0f*fSpeed, 0.2f);
@@ -461,11 +462,9 @@ CAutomobile::ProcessControl(void)
pHandling->Transmission.CalculateGearForSimpleCar(AutoPilot.m_fMaxTrafficSpeed/50.0f, m_nCurrentGear);
- {
- float wheelRot = ProcessWheelRotation(WHEEL_STATE_NORMAL, GetForward(), m_vecMoveSpeed, 0.35f);
+ wheelRot = ProcessWheelRotation(WHEEL_STATE_NORMAL, GetForward(), m_vecMoveSpeed, 0.35f);
for(i = 0; i < 4; i++)
m_aWheelRotation[i] += wheelRot;
- }
PlayHornIfNecessary();
ReduceHornCounter();
@@ -500,7 +499,7 @@ CAutomobile::ProcessControl(void)
break;
case STATUS_ABANDONED:
- if(m_vecMoveSpeed.MagnitudeSqr() < 0.01f)
+ if(m_vecMoveSpeed.MagnitudeSqr() < SQR(0.1f))
m_fBrakePedal = 0.2f;
else
m_fBrakePedal = 0.0f;
@@ -529,7 +528,7 @@ CAutomobile::ProcessControl(void)
break;
case STATUS_PLAYER_DISABLED:
- if(m_vecMoveSpeed.MagnitudeSqr() < 0.01f ||
+ if(m_vecMoveSpeed.MagnitudeSqr() < SQR(0.1f) ||
(pDriver && pDriver->IsPlayer() &&
(pDriver->GetPedState() == PED_ARRESTED ||
pDriver->GetPedState() == PED_DRAG_FROM_CAR ||
@@ -770,7 +769,7 @@ CAutomobile::ProcessControl(void)
for(i = 0; i < 4; i++){
if(m_aSuspensionSpringRatio[i] < 1.0f){
float bias = pHandling->fSuspensionBias;
- if(i == 1 || i == 3) // rear
+ if(i == CARWHEEL_REAR_LEFT || i == CARWHEEL_REAR_RIGHT)
bias = 1.0f - bias;
ApplySpringCollisionAlt(pHandling->fSuspensionForceLevel,
@@ -823,7 +822,6 @@ CAutomobile::ProcessControl(void)
}
}
-
bool gripCheat = true;
fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward());
if(!strongGrip1 && !CVehicle::bCheat3)
@@ -1062,6 +1060,7 @@ CAutomobile::ProcessControl(void)
}else if(m_doingBurnout && !mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier)){
rearBrake = 0.0f;
rearTraction = 0.0f;
+ // BUG: missing timestep
ApplyTurnForce(contactPoints[CARWHEEL_REAR_LEFT], -0.001f*m_fTurnMass*m_fSteerAngle*GetRight());
}else if(m_fTireTemperature > 1.0f){
rearTraction *= m_fTireTemperature;
@@ -1155,7 +1154,7 @@ CAutomobile::ProcessControl(void)
}
if(m_doingBurnout && !mod_HandlingManager.HasFrontWheelDrive(pHandling->nIdentifier) &&
- (m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SPINNING || m_aWheelState[CARWHEEL_REAR_RIGHT])){
+ (m_aWheelState[CARWHEEL_REAR_LEFT] == WHEEL_STATE_SPINNING || m_aWheelState[CARWHEEL_REAR_RIGHT] == WHEEL_STATE_SPINNING)){
m_fTireTemperature += 0.001f*CTimer::GetTimeStep();
if(m_fTireTemperature > 3.0f)
m_fTireTemperature = 3.0f;
@@ -1375,14 +1374,14 @@ CAutomobile::ProcessControl(void)
// Flying
- bool foo = false;
+ bool playRotorSound = false;
if(GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE && GetStatus() != STATUS_PHYSICS){
if(IsRealHeli()){
bEngineOn = false;
m_aWheelSpeed[1] = Max(m_aWheelSpeed[1]-0.0005f, 0.0f);
if(GetModelIndex() != MI_RCRAIDER && GetModelIndex() != MI_RCGOBLIN)
if(m_aWheelSpeed[1] < 0.154f && m_aWheelSpeed[1] > 0.0044f)
- foo = true;
+ playRotorSound = true;
}
}else if((GetModelIndex() == MI_DODO || CVehicle::bAllDodosCheat) &&
m_vecMoveSpeed.Magnitude() > 0.0f && CTimer::GetTimeStep() > 0.0f){
@@ -1476,10 +1475,25 @@ CAutomobile::ProcessControl(void)
if(GetModelIndex() != MI_RCRAIDER && GetModelIndex() != MI_RCGOBLIN)
if(m_aWheelSpeed[1] < 0.154f && m_aWheelSpeed[1] > 0.0044f)
- foo = true;
+ playRotorSound = true;
}
-//TODO(MIAMI): propeller stuff
+ // Play rotor sound
+ if(playRotorSound && m_aCarNodes[CAR_BONNET]){
+ CVector camDist = TheCamera.GetPosition() - GetPosition();
+ float distSq = camDist.MagnitudeSqr();
+ if(distSq < SQR(20.0f) && Abs(m_fPropellerRotation - m_aWheelRotation[1]) > DEGTORAD(30.0f)){
+ CMatrix mat;
+ mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_BONNET]));
+ CVector blade = mat.GetRight();
+ blade = GetMatrix() * blade;
+ camDist /= Max(Sqrt(distSq), 0.01f);
+ if(Abs(DotProduct(camDist, blade)) > 0.95f){
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_31, 0.0f);
+ m_fPropellerRotation = m_aWheelRotation[1];
+ }
+ }
+ }
}
@@ -1559,8 +1573,10 @@ CAutomobile::ProcessControl(void)
for(i = 0; i < 4; i++){
float suspChange = m_aSuspensionSpringRatioPrev[i] - m_aSuspensionSpringRatio[i];
if(suspChange > 0.3f && !drivingInSand && speedsq > 0.04f){
-//TODO(MIAMI): depends on wheel status
- DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, suspChange);
+ if(Damage.GetWheelStatus(i) == WHEEL_STATUS_BURST)
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP_2, suspChange);
+ else
+ DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_JUMP, suspChange);
if(suspChange > suspShake)
suspShake = suspChange;
}
@@ -4192,12 +4208,12 @@ CAutomobile::VehicleDamage(float impulse, uint16 damagedPiece)
pDriver &&
m_pDamageEntity && m_pDamageEntity->IsVehicle() &&
(this != FindPlayerVehicle() || ((CVehicle*)m_pDamageEntity)->VehicleCreatedBy == MISSION_VEHICLE) &&
+// TODO(MIAMI): enum
((CVehicle*)m_pDamageEntity)->pDriver){
-// TODO(MIAMI)
-// if(GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR)
-// pDriver->Say(145);
-// else
-// pDriver->Say(144);
+ if(GetVehicleAppearance() == VEHICLE_APPEARANCE_CAR)
+ pDriver->Say(145);
+ else
+ pDriver->Say(144);
}
int oldHealth = m_fHealth;
@@ -4828,7 +4844,6 @@ CAutomobile::BurstTyre(uint8 wheel, bool applyForces)
case CAR_PIECE_WHEEL_LR: wheel = VEHWHEEL_REAR_LEFT; break;
case CAR_PIECE_WHEEL_RF: wheel = VEHWHEEL_FRONT_RIGHT; break;
case CAR_PIECE_WHEEL_RR: wheel = VEHWHEEL_REAR_RIGHT; break;
- default: assert(0 && "invalid wheel");
}
int status = Damage.GetWheelStatus(wheel);
diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp
index b4f6452e..0da3a470 100644
--- a/src/vehicles/Bike.cpp
+++ b/src/vehicles/Bike.cpp
@@ -4,11 +4,18 @@
#include "DMAudio.h"
#include "Camera.h"
#include "Darkel.h"
+#include "Rubbish.h"
#include "Explosion.h"
+#include "Particle.h"
#include "World.h"
+#include "SurfaceTable.h"
+#include "Record.h"
#include "CarCtrl.h"
+#include "CarAI.h"
#include "Stats.h"
+#include "Replay.h"
#include "AnimManager.h"
+#include "RpAnimBlend.h"
#include "AnimBlendAssociation.h"
#include "Ped.h"
#include "PlayerPed.h"
@@ -16,6 +23,7 @@
#include "Vehicle.h"
#include "Automobile.h"
#include "Bike.h"
+#include "Debug.h"
#define FAKESUSPENSION (99999.992f)
@@ -24,7 +32,7 @@ CBike::CBike(int32 id, uint8 CreatedBy)
{
int i;
CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(id);
- switch(GetModelIndex()){
+ switch(id){
case MI_ANGEL:
case MI_FREEWAY:
m_bikeAnimType = ASSOCGRP_BIKE_HARLEY;
@@ -39,6 +47,7 @@ CBike::CBike(int32 id, uint8 CreatedBy)
case MI_SANCHEZ:
m_bikeAnimType = ASSOCGRP_BIKE_DIRT;
break;
+ default: assert(0 && "invalid bike model ID");
}
m_vehType = VEHICLE_TYPE_BIKE;
@@ -71,7 +80,7 @@ CBike::CBike(int32 id, uint8 CreatedBy)
m_fBuoyancy = pHandling->fBuoyancy;
m_fSteerAngle = 0.0f;
- m_fBikeSteerAngle = 0.0f;
+ m_fWheelAngle = 0.0f;
m_fLeanLRAngle = 0.0f;
m_fLeanLRAngle2 = 0.0f;
m_fGasPedal = 0.0f;
@@ -83,9 +92,9 @@ CBike::CBike(int32 id, uint8 CreatedBy)
m_pBombRigger = nil;
m_fGasPedalAudio = 0.0f;
m_bike_flag02 = false;
- m_bike_flag04 = false;
+ bWaterTight = false;
m_bike_flag08 = false;
- m_bike_flag10 = false;
+ bIsStanding = false;
m_bike_flag20 = false;
m_bike_flag40 = false;
m_bike_flag80 = false;
@@ -152,9 +161,921 @@ CBike::SetModelIndex(uint32 id)
SetupModelNodes();
}
+#define SAND_SLOWDOWN (0.02f)
+CVector vecTestResistance(0.9995f, 0.9f, 0.95f);
+float fDAxisX = 1.0f;
+float fDAxisXExtra = 100.0f;
+float fDAxisY = 1000.0f;
+float fInAirXRes = 0.88f;
+float fFlySpeedMult = -0.6f;
+
void
CBike::ProcessControl(void)
{
+ int i;
+ float wheelRot;
+ float acceleration = 0.0f;
+ bool bCanStand = false;
+ bool bStuckInSand = false;
+ float brake = 0.0f;
+ CColModel *colModel = GetColModel();
+ float wheelScale = ((CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()))->m_wheelScale;
+ bWarnedPeds = false;
+ bLeanMatrixClean = false;
+ m_doingBurnout = 0;
+ m_bike_flag20 = false;
+ bRestingOnPhysical = false;
+
+ if(CReplay::IsPlayingBack())
+ return;
+
+ ProcessCarAlarm();
+
+ ActivateBombWhenEntered();
+
+ CRubbish::StirUp(this);
+
+ UpdateClumpAlpha();
+
+ AutoPilot.m_bSlowedDownBecauseOfCars = false;
+ AutoPilot.m_bSlowedDownBecauseOfPeds = false;
+
+ switch(GetStatus()){
+ case STATUS_PLAYER:
+ bCanStand = true;
+ m_bike_flag08 = false;
+ if(pDriver && pDriver->GetPedState() != PED_EXIT_CAR && pDriver->GetPedState() != PED_DRAG_FROM_CAR){
+ ProcessControlInputs(0);
+
+ if(m_fLeanInput < 0.0f){
+ m_vecCentreOfMass.y = pHandling->CentreOfMass.y + pBikeHandling->fLeanBakCOM*m_fLeanInput;
+ if(m_fBrakePedal == 0.0f && !bIsHandbrakeOn || m_nWheelsOnGround == 0){
+ if(GetModelIndex() == MI_SANCHEZ){
+ float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanBackForce*Min(m_vecMoveSpeed.MagnitudeSqr(), 0.1f);
+ force *= 0.7f*m_fGasPedal + 0.3f;
+ ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), m_vecCentreOfMass+GetForward());
+ }else{
+ float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanBackForce*Min(m_vecMoveSpeed.MagnitudeSqr(), 0.1f);
+ force *= 0.5f*m_fGasPedal + 0.5f;
+ ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), m_vecCentreOfMass+GetForward());
+ }
+ }
+ }else{
+ m_vecCentreOfMass.y = pHandling->CentreOfMass.y + pBikeHandling->fLeanFwdCOM*m_fLeanInput;
+ if(m_fBrakePedal < 0.0f || m_nWheelsOnGround == 0){
+ float force = m_fLeanInput*m_fTurnMass*pBikeHandling->fLeanFwdForce*Min(m_vecMoveSpeed.MagnitudeSqr(), 0.1f);
+ ApplyTurnForce(-force*CTimer::GetTimeStep()*GetUp(), m_vecCentreOfMass+GetForward());
+ }
+ }
+
+ PruneReferences();
+
+ if(GetStatus() == STATUS_PLAYER && !CRecordDataForChase::IsRecording())
+ DoDriveByShootings();
+
+ if(m_aSuspensionSpringRatio[0] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[0].surfaceB) == ADHESIVE_SAND ||
+ m_aSuspensionSpringRatio[1] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[1].surfaceB) == ADHESIVE_SAND ||
+ m_aSuspensionSpringRatio[2] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[2].surfaceB) == ADHESIVE_SAND ||
+ m_aSuspensionSpringRatio[3] < 1.0f && CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[3].surfaceB) == ADHESIVE_SAND){
+ CVector parallelSpeed = m_vecMoveSpeed - DotProduct(m_vecMoveSpeed, GetUp())*m_vecMoveSpeed;
+ if(m_fGasPedal > 0.3f){
+ if(parallelSpeed.MagnitudeSqr() < SQR(0.3f))
+ bStuckInSand = true;
+ parallelSpeed -= DotProduct(parallelSpeed, GetForward())*GetForward();
+ }
+ ApplyMoveForce(parallelSpeed * -CTimer::GetTimeStep()*SAND_SLOWDOWN*m_fMass);
+ }
+ }
+ if(CPad::GetPad(0)->WeaponJustDown())
+ ActivateBomb();
+ break;
+
+ case STATUS_PLAYER_PLAYBACKFROMBUFFER:
+ bCanStand = true;
+ break;
+
+ case STATUS_SIMPLE:
+ CCarAI::UpdateCarAI(this);
+ CPhysical::ProcessControl();
+ CCarCtrl::UpdateCarOnRails(this);
+
+ m_nWheelsOnGround = 2;
+ m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround;
+ m_nDriveWheelsOnGround = 2;
+
+ pHandling->Transmission.CalculateGearForSimpleCar(AutoPilot.m_fMaxTrafficSpeed/50.0f, m_nCurrentGear);
+
+ wheelRot = ProcessWheelRotation(WHEEL_STATE_NORMAL, GetForward(), m_vecMoveSpeed, 0.35f);
+ for(i = 0; i < 2; i++)
+ m_aWheelRotation[i] += wheelRot;
+
+ PlayHornIfNecessary();
+ ReduceHornCounter();
+ bVehicleColProcessed = false;
+ bAudioChangingGear = false;
+ m_bike_flag80 = false;
+ // that's all we do for simple vehicles
+ return;
+
+ case STATUS_PHYSICS:
+ CCarAI::UpdateCarAI(this);
+ CCarCtrl::SteerAICarWithPhysics(this);
+ PlayHornIfNecessary();
+
+ bCanStand = true;
+ m_bike_flag80 = false;
+
+ if(bIsBeingCarJacked){
+ m_fGasPedal = 0.0f;
+ m_fBrakePedal = 1.0f;
+ bIsHandbrakeOn = true;
+ }else
+ m_bike_flag08 = false;
+ break;
+
+ case STATUS_ABANDONED:
+ m_fBrakePedal = 0.0f;
+ if(m_vecMoveSpeed.MagnitudeSqr() < SQR(0.1f) || bIsStanding)
+ bIsHandbrakeOn = true;
+ else
+ bIsHandbrakeOn = false;
+
+ m_fGasPedal = 0.0f;
+#ifdef FIX_BUGS
+ if(!IsAlarmOn())
+#endif
+ m_nCarHornTimer = 0;
+
+ bCanStand = (pDriver || pPassengers[0] || bIsBeingCarJacked) && !bIsStanding;
+ field_478 = 0;
+ field_47C = 0;
+ m_bike_flag80 = false;
+
+ if(bIsBeingCarJacked){
+ m_fGasPedal = 0.0f;
+ m_fBrakePedal = 1.0f;
+ bIsHandbrakeOn = true;
+ }
+ break;
+
+ case STATUS_WRECKED:
+ m_fBrakePedal = 0.05f;
+ bIsHandbrakeOn = true;
+
+ m_fSteerAngle = 0.0f;
+ m_fGasPedal = 0.0f;
+#ifdef FIX_BUGS
+ if(!IsAlarmOn())
+#endif
+ m_nCarHornTimer = 0;
+
+ bCanStand = false;
+ m_bike_flag80 = false;
+ field_478 = 0;
+ field_47C = 0;
+ break;
+
+ case STATUS_PLAYER_DISABLED:
+ if(m_vecMoveSpeed.MagnitudeSqr() < SQR(0.1f)){
+ m_fBrakePedal = 1.0f;
+ bIsHandbrakeOn = true;
+ }else{
+ m_fBrakePedal = 0.0f;
+ bIsHandbrakeOn = false;
+ }
+
+ m_fSteerAngle = 0.0f;
+ m_fGasPedal = 0.0f;
+#ifdef FIX_BUGS
+ if(!IsAlarmOn())
+#endif
+ m_nCarHornTimer = 0;
+
+ bCanStand = true;
+ m_bike_flag80 = false;
+ break;
+ }
+
+ if(bIsStanding)
+ if(Abs(GetRight().z) > 0.35f || Abs(GetForward().z) > 0.5f)
+ bIsStanding = false;
+
+ if(bCanStand || m_bike_flag08 || bIsStanding){
+ float fDx = fDAxisX;
+ CVector res = vecTestResistance;
+ CVector localTurnSpeed = Multiply3x3(m_vecTurnSpeed, GetMatrix());
+
+ if(GetStatus() == STATUS_PLAYER){
+ if(m_aWheelTimer[BIKESUSP_F1] == 0.0f && m_aWheelTimer[BIKESUSP_F2] == 0.0f){
+ fDx = fDAxisXExtra;
+ if(!(m_aWheelTimer[BIKESUSP_R1] == 0.0f && m_aWheelTimer[BIKESUSP_R2] == 0.0f) &&
+ GetForward().z > 0.0f)
+ res.x -= Max(0.25f*Abs(pBikeHandling->fWheelieAng-GetForward().z), 0.07f);
+ else
+ res.x = fInAirXRes;
+ }else if(m_aWheelTimer[BIKESUSP_R1] == 0.0f && m_aWheelTimer[BIKESUSP_R2] == 0.0f){
+ fDx = fDAxisXExtra;
+ if(GetForward().z < 0.0f)
+ res.x *= Max(0.3f*Abs(pBikeHandling->fStoppieAng-GetForward().z), 0.1f) + 0.9f;
+ }
+ }
+
+ res.x *= 1.0f/(fDx*SQR(localTurnSpeed.x) + 1.0f);
+ res.y *= 1.0f/(fDAxisY*SQR(localTurnSpeed.y) + 1.0f);
+ res.x = Pow(res.x, CTimer::GetTimeStep());
+ res.y = Pow(res.y, CTimer::GetTimeStep());
+ float turnX = localTurnSpeed.x*res.x - localTurnSpeed.x;
+ float turnY = localTurnSpeed.y*res.y - localTurnSpeed.y;
+
+ res = -GetUp() * turnY * m_fTurnMass;
+ // BUG? matrix multiplication
+ ApplyTurnForce(res, GetRight() + Multiply3x3(GetMatrix(),m_vecCentreOfMass));
+
+ res = GetUp() * turnX * m_fTurnMass;
+ // BUG? matrix multiplication
+ ApplyTurnForce(res, GetForward() + Multiply3x3(GetMatrix(),m_vecCentreOfMass));
+
+ if(GetStatus() != STATUS_PLAYER)
+ m_vecCentreOfMass = pHandling->CentreOfMass;
+ }else{
+ m_vecCentreOfMass = pHandling->CentreOfMass;
+ m_vecCentreOfMass.z = pBikeHandling->fNoPlayerCOMz;
+ }
+
+ // Skip physics if object is found to have been static recently
+ bool skipPhysics = false;
+ if(!bIsStuck && (GetStatus() == STATUS_ABANDONED || GetStatus() == STATUS_WRECKED) && !m_bike_flag08){
+ bool makeStatic = false;
+ float moveSpeedLimit, turnSpeedLimit, distanceLimit;
+
+ if(!bVehicleColProcessed &&
+ m_vecMoveSpeed.IsZero() &&
+ // BUG? m_aSuspensionSpringRatioPrev[3] is checked twice in the game. also, why 3?
+ m_aSuspensionSpringRatioPrev[3] != 1.0f)
+ makeStatic = true;
+
+ if(GetStatus() == STATUS_WRECKED){
+ moveSpeedLimit = 0.006f;
+ turnSpeedLimit = 0.0015f;
+ distanceLimit = 0.015f;
+ }else{
+ moveSpeedLimit = 0.003f;
+ turnSpeedLimit = 0.0009f;
+ distanceLimit = 0.005f;
+ }
+
+ m_vecMoveSpeedAvg = (m_vecMoveSpeedAvg + m_vecMoveSpeed)/2.0f;
+ m_vecTurnSpeedAvg = (m_vecTurnSpeedAvg + m_vecTurnSpeed)/2.0f;
+
+ if(m_vecMoveSpeedAvg.MagnitudeSqr() <= sq(moveSpeedLimit*CTimer::GetTimeStep()) &&
+ m_vecTurnSpeedAvg.MagnitudeSqr() <= sq(turnSpeedLimit*CTimer::GetTimeStep()) &&
+ m_fDistanceTravelled < distanceLimit &&
+ makeStatic){
+ m_nStaticFrames++;
+
+ if(m_nStaticFrames > 10 || makeStatic)
+ if(!CCarCtrl::MapCouldMoveInThisArea(GetPosition().x, GetPosition().y)){
+ if(!makeStatic || m_nStaticFrames > 10)
+ m_nStaticFrames = 10;
+
+ skipPhysics = true;
+
+ m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
+ }
+ }else
+ m_nStaticFrames = 0;
+ }
+
+ // Postpone
+ for(i = 0; i < 4; i++)
+ if(m_aGroundPhysical[i]){
+ bRestingOnPhysical = true;
+ if(!CWorld::bForceProcessControl && m_aGroundPhysical[i]->bIsInSafePosition){
+ bWasPostponed = true;
+ return;
+ }
+ }
+
+ if(bRestingOnPhysical){
+ skipPhysics = false;
+ m_nStaticFrames = 0;
+ }
+
+ VehicleDamage();
+
+ if(skipPhysics){
+ bHasContacted = false;
+ bIsInSafePosition = false;
+ bWasPostponed = false;
+ bHasHitWall = false;
+ m_nCollisionRecords = 0;
+ bHasCollided = false;
+ bVehicleColProcessed = false;
+ bAudioChangingGear = false;
+ m_nDamagePieceType = 0;
+ m_fDamageImpulse = 0.0f;
+ m_pDamageEntity = nil;
+ m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f);
+ m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f);
+// missing. BUG?
+// m_fTireTemperature = 1.0f;
+
+ if(bIsStanding && m_fWheelAngle < DEGTORAD(20.0f))
+ m_fWheelAngle += DEGTORAD(1.0f)*CTimer::GetTimeStep();
+ if(bIsStanding){
+ float f = Pow(0.97f, CTimer::GetTimeStep());
+ m_fLeanLRAngle2 = m_fLeanLRAngle2*f + (Asin(clamp(GetRight().z,-1.0f,1.0f))+DEGTORAD(15.0f))*(1.0f-f);
+ m_fLeanLRAngle = m_fLeanLRAngle2;
+ }
+ }else{
+
+ // This has to be done if ProcessEntityCollision wasn't called
+ if(!bVehicleColProcessed){
+ CMatrix mat(GetMatrix());
+ bIsStuck = false;
+ bHasContacted = false;
+ bIsInSafePosition = false;
+ bWasPostponed = false;
+ bHasHitWall = false;
+ m_fDistanceTravelled = 0.0f;
+ m_bIsVehicleBeingShifted = false;
+ bSkipLineCol = false;
+ ApplyMoveSpeed();
+ ApplyTurnSpeed();
+ for(i = 0; CheckCollision() && i < 5; i++){
+ GetMatrix() = mat;
+ ApplyMoveSpeed();
+ ApplyTurnSpeed();
+ }
+ bIsInSafePosition = true;
+ bIsStuck = false;
+ }
+
+ if(!(bCanStand || m_bike_flag08 || bIsStanding)){
+ if(GetRight().z < 0.0f){
+ if(m_fSteerAngle > -DEGTORAD(25.0f))
+ m_fSteerAngle -= DEGTORAD(0.5f)*CTimer::GetTimeStep();
+ }else{
+ if(m_fSteerAngle < DEGTORAD(25.0f))
+ m_fSteerAngle += DEGTORAD(0.5f)*CTimer::GetTimeStep();
+ }
+ }
+
+// TODO: lean forward speed up
+ float savedAirResistance = m_fAirResistance;
+ // ...
+
+ CPhysical::ProcessControl();
+ m_fAirResistance = savedAirResistance;
+
+ ProcessBuoyancy();
+
+ // Rescale spring ratios, i.e. subtract wheel radius
+ for(i = 0; i < 4; i++){
+ // wheel radius in relation to suspension line
+ float wheelRadius = 1.0f - m_aSuspensionSpringLength[i]/m_aSuspensionLineLength[i];
+ // rescale such that 0.0 is fully compressed and 1.0 is fully extended
+ m_aSuspensionSpringRatio[i] = (m_aSuspensionSpringRatio[i]-wheelRadius)/(1.0f-wheelRadius);
+ }
+
+ int rnd = 0;
+ float fwdSpeed = Abs(DotProduct(m_vecMoveSpeed, GetForward()));
+ CVector contactPoints[4]; // relative to model
+ CVector contactSpeeds[4]; // speed at contact points
+ CVector springDirections[4]; // normalized, in model space
+
+ for(i = 0; i < 4; i++){
+ // Set spring under certain circumstances
+ if(m_wheelStatus[i/2] == WHEEL_STATUS_MISSING)
+ m_aSuspensionSpringRatio[i] = 1.0f;
+ else if(m_wheelStatus[i/2] == WHEEL_STATUS_BURST){
+ // wheel more bumpy the faster we are
+ if(i == BIKESUSP_F1 || BIKESUSP_R1)
+ rnd = CGeneral::GetRandomNumberInRange(0, (uint16)(40*fwdSpeed) + 98) < 100;
+ if(rnd){
+ m_aSuspensionSpringRatio[i] += 0.3f*(m_aSuspensionLineLength[i]-m_aSuspensionSpringLength[i])/m_aSuspensionSpringLength[i];
+ if(m_aSuspensionSpringRatio[i] > 1.0f)
+ m_aSuspensionSpringRatio[i] = 1.0f;
+ }
+ }
+
+ // get points and directions if spring is compressed
+ if(m_aSuspensionSpringRatio[i] < 1.0f){
+ contactPoints[i] = m_aWheelColPoints[i].point - GetPosition();
+ springDirections[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1 - colModel->lines[i].p0);
+ springDirections[i].Normalise();
+ }
+ }
+
+ m_aWheelSkidmarkType[0] = m_aWheelSkidmarkType[1] = SKIDMARK_NORMAL;
+ m_aWheelSkidmarkUnk[0] = m_aWheelSkidmarkUnk[1] = false;
+
+ // Make springs push up vehicle
+ for(i = 0; i < 4; i++){
+ if(m_aSuspensionSpringRatio[i] < 1.0f){
+ float bias = pHandling->fSuspensionBias;
+ if(i == BIKESUSP_R1 || i == BIKESUSP_R2)
+ bias = 1.0f - bias;
+
+ if(m_aWheelColPoints[i].normal.z > 0.35f)
+ ApplySpringCollisionAlt(pHandling->fSuspensionForceLevel,
+ springDirections[i], contactPoints[i],
+ m_aSuspensionSpringRatio[i], bias, m_aWheelColPoints[i].normal);
+ else
+ ApplySpringCollision(pHandling->fSuspensionForceLevel,
+ springDirections[i], contactPoints[i],
+ m_aSuspensionSpringRatio[i], bias);
+
+ if(m_aWheelColPoints[i].surfaceB == SURFACE_GRASS ||
+ m_aWheelColPoints[i].surfaceB == SURFACE_MUD_DRY){
+ if(i < 2)
+ m_aWheelSkidmarkType[0] = SKIDMARK_MUDDY;
+ else
+ m_aWheelSkidmarkType[1] = SKIDMARK_MUDDY;
+ }else if(m_aWheelColPoints[i].surfaceB == SURFACE_SAND ||
+ m_aWheelColPoints[i].surfaceB == SURFACE_SAND_BEACH){
+ if(i < 2){
+ m_aWheelSkidmarkType[0] = SKIDMARK_SANDY;
+ m_aWheelSkidmarkUnk[0] = true;
+ }else{
+ m_aWheelSkidmarkType[1] = SKIDMARK_SANDY;
+ m_aWheelSkidmarkUnk[1] = true;
+ }
+ }
+ }else{
+ contactPoints[i] = Multiply3x3(GetMatrix(), colModel->lines[i].p1);
+ }
+ }
+
+ // Get speed at contact points
+ for(i = 0; i < 4; i++){
+ contactSpeeds[i] = GetSpeed(contactPoints[i]);
+ if(m_aGroundPhysical[i]){
+ // subtract movement of physical we're standing on
+ contactSpeeds[i] -= m_aGroundPhysical[i]->GetSpeed(m_aGroundOffset[i]);
+#ifndef FIX_BUGS
+ // this shouldn't be reset because we still need it below
+ m_aGroundPhysical[i] = nil;
+#endif
+ }
+ }
+
+ CVector normal;
+ if(m_aSuspensionSpringRatio[0] < 1.0f || m_aSuspensionSpringRatio[1] < 1.0f){
+ normal = m_aSuspensionSpringRatio[0] < 1.0f ? m_aWheelColPoints[0].normal : m_aWheelColPoints[1].normal;
+ if(normal.z > 0.35f)
+ springDirections[0] = -normal;
+ normal = m_aSuspensionSpringRatio[1] < 1.0f ? m_aWheelColPoints[1].normal : m_aWheelColPoints[0].normal;
+ if(normal.z > 0.35f)
+ springDirections[1] = -normal;
+ }
+ if(m_aSuspensionSpringRatio[2] < 1.0f || m_aSuspensionSpringRatio[3] < 1.0f){
+ normal = m_aSuspensionSpringRatio[2] < 1.0f ? m_aWheelColPoints[2].normal : m_aWheelColPoints[3].normal;
+ if(normal.z > 0.35f)
+ springDirections[2] = -normal;
+ normal = m_aSuspensionSpringRatio[3] < 1.0f ? m_aWheelColPoints[3].normal : m_aWheelColPoints[2].normal;
+ if(normal.z > 0.35f)
+ springDirections[3] = -normal;
+ }
+
+ // game has dead code here if m_vecMoveSpeed.Magnitude() < 0.01f
+
+ // dampen springs
+ for(i = 0; i < 4; i++)
+ if(m_aSuspensionSpringRatio[i] < 1.0f)
+ ApplySpringDampening(pHandling->fSuspensionDampingLevel,
+ springDirections[i], contactPoints[i], contactSpeeds[i]);
+
+ // Get speed at contact points again
+ for(i = 0; i < 4; i++){
+ contactSpeeds[i] = GetSpeed(contactPoints[i]);
+ if(m_aGroundPhysical[i]){
+ // subtract movement of physical we're standing on
+ contactSpeeds[i] -= m_aGroundPhysical[i]->GetSpeed(m_aGroundOffset[i]);
+ m_aGroundPhysical[i] = nil;
+ }
+ }
+
+ bool gripCheat = true;
+ fwdSpeed = DotProduct(m_vecMoveSpeed, GetForward());
+ if(!CVehicle::bCheat3)
+ gripCheat = false;
+ float acceleration = pHandling->Transmission.CalculateDriveAcceleration(m_fGasPedal, m_nCurrentGear, m_fChangeGearTime, fwdSpeed, gripCheat);
+ acceleration /= m_fForceMultiplier;
+
+ brake = m_fBrakePedal * pHandling->fBrakeDeceleration * CTimer::GetTimeStep();
+ bool neutralHandling = GetStatus() != STATUS_PLAYER && GetStatus() != STATUS_PLAYER_REMOTE && (pHandling->Flags & HANDLING_NEUTRALHANDLING);
+ float brakeBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fBrakeBias;
+ float brakeBiasRear = neutralHandling ? 1.0f : 2.0f*(1.0f-pHandling->fBrakeBias);
+ float tractionBiasFront = neutralHandling ? 1.0f : 2.0f*pHandling->fTractionBias;
+ float tractionBiasRear = neutralHandling ? 1.0f : 2.0f-tractionBiasFront;
+
+ // Count how many wheels are touching the ground
+
+ m_nWheelsOnGround = 0;
+ m_nDriveWheelsOnGroundPrev = m_nDriveWheelsOnGround;
+ m_nDriveWheelsOnGround = 0;
+
+ for(i = 0; i < 4; i++){
+ if(m_aSuspensionSpringRatio[i] < 1.0f)
+ m_aWheelTimer[i] = 4.0f;
+ else
+ m_aWheelTimer[i] = Max(m_aWheelTimer[i]-CTimer::GetTimeStep(), 0.0f);
+
+ if(m_aWheelTimer[i] > 0.0f){
+ m_nWheelsOnGround++;
+ if(i == BIKESUSP_R1 || i == BIKESUSP_R2)
+ m_nDriveWheelsOnGround = 1;
+ if(m_nWheelsOnGround == 1)
+ m_vecAvgSurfaceNormal = m_aWheelColPoints[i].normal;
+ else
+ m_vecAvgSurfaceNormal += m_aWheelColPoints[i].normal;
+ }
+ }
+
+ if(m_nWheelsOnGround == 0)
+ m_vecAvgSurfaceNormal = CVector(0.0f, 0.0f, 1.0f);
+ else{
+ m_vecAvgSurfaceNormal /= m_nWheelsOnGround;
+ if(DotProduct(m_vecAvgSurfaceNormal, GetUp()) < -0.5f)
+ m_vecAvgSurfaceNormal *= -1.0f;
+ }
+
+ // Find contact points for wheel processing
+ i = m_aSuspensionSpringRatio[BIKESUSP_F1] < m_aSuspensionSpringRatio[BIKESUSP_F2] ?
+ BIKESUSP_F1 : BIKESUSP_F2;
+ int frontLine = i;
+ CVector frontContact(0.0f,
+ colModel->lines[BIKESUSP_F1].p0.y,
+ colModel->lines[BIKESUSP_F1].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionSpringLength[BIKESUSP_F1] - 0.5f*wheelScale);
+ frontContact = Multiply3x3(GetMatrix(), frontContact);
+
+ i = m_aSuspensionSpringRatio[BIKESUSP_R1] < m_aSuspensionSpringRatio[BIKESUSP_R2] ?
+ BIKESUSP_R1 : BIKESUSP_R2;
+ int rearLine = i;
+ CVector rearContact(0.0f,
+ colModel->lines[BIKESUSP_R1].p0.y,
+ colModel->lines[BIKESUSP_R1].p0.z - m_aSuspensionSpringRatio[i]*m_aSuspensionSpringLength[BIKESUSP_R1] - 0.5f*wheelScale);
+ rearContact = Multiply3x3(GetMatrix(), rearContact);
+
+ float traction = 0.004f * m_fTraction;
+ traction *= pHandling->fTractionMultiplier / 4.0f;
+
+ // TODO: what is this?
+ if(GetStatus() == STATUS_PLAYER || !bIsStanding || m_bike_flag08){
+ if(Abs(m_vecMoveSpeed.x) < 0.01f && Abs(m_vecMoveSpeed.y) < 0.01f && m_fSteerAngle == 0.0f){
+ m_fWheelAngle *= Pow(0.96f, CTimer::GetTimeStep());
+ }else{
+ float f;
+ if(fwdSpeed > 0.01f && m_aWheelTimer[BIKESUSP_F1] > 0.0f && m_aWheelTimer[BIKESUSP_F2] > 0.0f && GetStatus() == STATUS_PLAYER){
+ CColPoint point;
+ point.surfaceA = SURFACE_WHEELBASE;
+ point.surfaceB = SURFACE_TARMAC;
+ float foo = CSurfaceTable::GetAdhesiveLimit(point)*4.0f*pBikeHandling->fSpeedSteer*traction;
+ if(CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[rearLine].surfaceB) == ADHESIVE_LOOSE ||
+ CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[rearLine].surfaceB) == ADHESIVE_SAND)
+ foo *= pBikeHandling->fSlipSteer;
+ f = Asin(Min(foo/SQR(fwdSpeed), 1.0))/DEGTORAD(pHandling->fSteeringLock);
+ if(m_fSteerAngle < 0.0f && m_fLeanLRAngle < 0.0f &&
+ m_fSteerAngle > 0.0f && m_fLeanLRAngle > 0.0f)
+ f *= 2.0f;
+ f = Min(f, 1.0f);
+ }else{
+ f = 1.0f;
+ }
+ if(GetStatus() != STATUS_PLAYER)
+ f = 1.0f;
+ m_fWheelAngle = m_fSteerAngle*f;
+ }
+ }else if(m_fWheelAngle < DEGTORAD(20.0f))
+ m_fWheelAngle += DEGTORAD(1.5f)*CTimer::GetTimeStep();
+
+ static float fThrust;
+ static tWheelState WheelState[2];
+ CVector initialMoveSpeed = m_vecMoveSpeed;
+ bool rearWheelsFirst = !!(pHandling->Flags & HANDLING_REARWHEEL_1ST);
+
+ // Process front wheel - first try
+
+ if(!rearWheelsFirst){
+ if(m_aWheelTimer[BIKESUSP_F1] > 0.0f || m_aWheelTimer[BIKESUSP_F2] > 0.0f){
+ // Wheel on ground
+ eBikeWheelSpecial spec;
+ if(m_aWheelTimer[BIKESUSP_R1] > 0.0f || m_aWheelTimer[BIKESUSP_R2] > 0.0f)
+ spec = BIKE_WHEELSPEC_0;
+ else
+ spec = BIKE_WHEELSPEC_2;
+ CVector wheelFwd = Multiply3x3(GetMatrix(), CVector(-Sin(m_fWheelAngle), Cos(m_fWheelAngle), 0.0f));
+ wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[frontLine].normal)*m_aWheelColPoints[frontLine].normal;
+ wheelFwd.Normalise();
+ CVector wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[frontLine].normal);
+ wheelRight.Normalise();
+
+ fThrust = 0.0f;
+ m_aWheelColPoints[frontLine].surfaceA = SURFACE_WHEELBASE;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[frontLine])*traction;
+ float adhesion2 = 1.0f;
+ if(someAngle > 0.0f)
+ switch(CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[frontLine].surfaceB)){
+ case ADHESIVE_HARD:
+ case ADHESIVE_LOOSE:
+ adhesion2 = 0.9f;
+ break;
+ case ADHESIVE_ROAD:
+ adhesion2 = 0.7f;
+ break;
+ }
+ if(GetStatus() == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[frontLine].surfaceB);
+ if(m_wheelStatus[BIKEWHEEL_FRONT] == WHEEL_STATUS_BURST)
+ adhesion *= 0.4f;
+ WheelState[BIKEWHEEL_FRONT] = m_aWheelState[BIKEWHEEL_FRONT];
+ ProcessBikeWheel(wheelFwd, wheelRight,
+ GetSpeed(frontContact), frontContact,
+ 2, fThrust,
+ brake*brakeBiasFront,
+ adhesion*tractionBiasFront,
+ adhesion2,
+ BIKEWHEEL_FRONT,
+ &m_aWheelSpeed[BIKEWHEEL_FRONT],
+ &WheelState[BIKEWHEEL_FRONT],
+ spec,
+ m_wheelStatus[BIKEWHEEL_FRONT]);
+ if(bStuckInSand && (WheelState[BIKEWHEEL_FRONT] == WHEEL_STATE_SPINNING || WheelState[BIKEWHEEL_FRONT] == WHEEL_STATE_SKIDDING))
+ WheelState[BIKEWHEEL_FRONT] = WHEEL_STATE_NORMAL;
+ }else{
+ // Wheel in the air
+ m_aWheelSpeed[BIKEWHEEL_FRONT] *= 0.95f;
+ m_aWheelRotation[BIKEWHEEL_FRONT] += m_aWheelSpeed[BIKEWHEEL_FRONT];
+ }
+ }
+
+ // Process rear wheel
+
+ if(m_aWheelTimer[BIKESUSP_R1] > 0.0f || m_aWheelTimer[BIKESUSP_R2] > 0.0f){
+ // Wheel on ground
+ float rearBrake = brake;
+ float rearTraction = traction;
+
+ CVector wheelFwd = GetForward();
+ CVector wheelRight = GetRight();
+ wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[rearLine].normal)*m_aWheelColPoints[rearLine].normal;
+ wheelFwd.Normalise();
+ wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[rearLine].normal);
+ wheelRight.Normalise();
+
+ if(bIsHandbrakeOn){
+#ifdef FIX_BUGS
+ // Not sure if this is needed, but brake usually has timestep as a factor
+ rearBrake = 20000.0f * CTimer::GetTimeStepFix();
+#else
+ rearBrake = 20000.0f;
+#endif
+ m_fTireTemperature = 1.0f;
+ }else if(m_doingBurnout){
+ rearBrake = 0.0f;
+ rearTraction = 0.0f;
+ ApplyTurnForce(contactPoints[BIKESUSP_R1], -0.0007f*m_fTurnMass*m_fSteerAngle*GetRight()*CTimer::GetTimeStep());
+ }else if(m_fTireTemperature < 1.0f && m_fGasPedal > 0.75f){
+ rearTraction *= m_fTireTemperature;
+ ApplyTurnForce(contactPoints[BIKESUSP_R1], (1.0f-m_fTireTemperature)*-0.0007f*m_fTurnMass*m_fSteerAngle*GetRight()*CTimer::GetTimeStep());
+ }
+
+ if(fThrust > 0.0f && brake > 0.0f)
+ brake = 0.0f; // only affects next front wheel. is this intended?
+ fThrust = acceleration;
+ m_aWheelColPoints[rearLine].surfaceA = SURFACE_WHEELBASE;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[rearLine])*rearTraction;
+ float adhesion2 = 1.0f;
+ if(someAngle > 0.0f)
+ switch(CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[rearLine].surfaceB)){
+ case ADHESIVE_HARD:
+ case ADHESIVE_LOOSE:
+ adhesion2 = 0.9f;
+ break;
+ case ADHESIVE_ROAD:
+ adhesion2 = 0.7f;
+ break;
+ }
+ if(GetStatus() == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[rearLine].surfaceB);
+ if(m_wheelStatus[BIKEWHEEL_REAR] == WHEEL_STATUS_BURST)
+ adhesion *= 0.4f;
+ WheelState[BIKEWHEEL_REAR] = m_aWheelState[BIKEWHEEL_REAR];
+ ProcessBikeWheel(wheelFwd, wheelRight,
+ GetSpeed(rearContact), rearContact,
+ 2, fThrust,
+ rearBrake*brakeBiasFront,
+ adhesion*tractionBiasFront,
+ adhesion2,
+ BIKEWHEEL_REAR,
+ &m_aWheelSpeed[BIKEWHEEL_REAR],
+ &WheelState[BIKEWHEEL_REAR],
+ BIKE_WHEELSPEC_1,
+ m_wheelStatus[BIKEWHEEL_REAR]);
+ if(bStuckInSand && (WheelState[BIKEWHEEL_REAR] == WHEEL_STATE_SPINNING || WheelState[BIKEWHEEL_REAR] == WHEEL_STATE_SKIDDING))
+ WheelState[BIKEWHEEL_REAR] = WHEEL_STATE_NORMAL;
+ }else{
+ // Wheel in the air
+ if(bIsHandbrakeOn)
+ m_aWheelSpeed[BIKEWHEEL_REAR] = 0.0f;
+ else{
+ if(acceleration > 0.0f){
+ if(m_aWheelSpeed[BIKEWHEEL_REAR] < 2.0f)
+ m_aWheelSpeed[BIKEWHEEL_REAR] -= 0.2f;
+ }else{
+ if(m_aWheelSpeed[BIKEWHEEL_REAR] > -2.0f)
+ m_aWheelSpeed[BIKEWHEEL_REAR] += 0.1f;
+ }
+ }
+ m_aWheelRotation[BIKEWHEEL_REAR] += m_aWheelSpeed[BIKEWHEEL_REAR];
+ }
+
+ if(m_doingBurnout && m_aWheelState[BIKEWHEEL_REAR] == WHEEL_STATE_SPINNING){
+ m_fTireTemperature += 0.001f*CTimer::GetTimeStep();
+ if(m_fTireTemperature > 3.0f)
+ m_fTireTemperature = 3.0f;
+ }else if(m_fTireTemperature > 1.0f){
+ m_fTireTemperature = (m_fTireTemperature - 1.0f)*Pow(0.995f, CTimer::GetTimeStep()) + 1.0f;
+ }
+
+ // Process front wheel - second try
+
+ if(rearWheelsFirst){
+ if(m_aWheelTimer[BIKESUSP_F1] > 0.0f || m_aWheelTimer[BIKESUSP_F2] > 0.0f){
+ // Wheel on ground
+ eBikeWheelSpecial spec;
+ if(m_aWheelTimer[BIKESUSP_R1] > 0.0f || m_aWheelTimer[BIKESUSP_R2] > 0.0f)
+ spec = BIKE_WHEELSPEC_0;
+ else
+ spec = BIKE_WHEELSPEC_2;
+ CVector wheelFwd = GetMatrix() * CVector(-Sin(m_fWheelAngle), Cos(m_fWheelAngle), 0.0f);
+ wheelFwd -= DotProduct(wheelFwd, m_aWheelColPoints[frontLine].normal)*m_aWheelColPoints[frontLine].normal;
+ wheelFwd.Normalise();
+ CVector wheelRight = CrossProduct(wheelFwd, m_aWheelColPoints[frontLine].normal);
+ wheelRight.Normalise();
+
+ fThrust = 0.0f;
+ m_aWheelColPoints[frontLine].surfaceA = SURFACE_WHEELBASE;
+ float adhesion = CSurfaceTable::GetAdhesiveLimit(m_aWheelColPoints[frontLine])*traction;
+ float adhesion2 = 1.0f;
+ if(someAngle > 0.0f)
+ switch(CSurfaceTable::GetAdhesionGroup(m_aWheelColPoints[frontLine].surfaceB)){
+ case ADHESIVE_HARD:
+ case ADHESIVE_LOOSE:
+ adhesion2 = 0.9f;
+ break;
+ case ADHESIVE_ROAD:
+ adhesion2 = 0.7f;
+ break;
+ }
+ if(GetStatus() == STATUS_PLAYER)
+ adhesion *= CSurfaceTable::GetWetMultiplier(m_aWheelColPoints[frontLine].surfaceB);
+ if(m_wheelStatus[BIKEWHEEL_FRONT] == WHEEL_STATUS_BURST)
+ adhesion *= 0.4f;
+ WheelState[BIKEWHEEL_FRONT] = m_aWheelState[BIKEWHEEL_FRONT];
+ ProcessBikeWheel(wheelFwd, wheelRight,
+ GetSpeed(frontContact), frontContact,
+ 2, fThrust,
+ brake*brakeBiasFront,
+ adhesion*tractionBiasFront,
+ adhesion2,
+ BIKEWHEEL_FRONT,
+ &m_aWheelSpeed[BIKEWHEEL_FRONT],
+ &WheelState[BIKEWHEEL_FRONT],
+ spec,
+ m_wheelStatus[BIKEWHEEL_FRONT]);
+ if(bStuckInSand && (WheelState[BIKEWHEEL_FRONT] == WHEEL_STATE_SPINNING || WheelState[BIKEWHEEL_FRONT] == WHEEL_STATE_SKIDDING))
+ WheelState[BIKEWHEEL_FRONT] = WHEEL_STATE_NORMAL;
+ }else{
+ // Wheel in the air
+ m_aWheelSpeed[BIKEWHEEL_FRONT] *= 0.95f;
+ m_aWheelRotation[BIKEWHEEL_FRONT] += m_aWheelSpeed[BIKEWHEEL_FRONT];
+ }
+ }
+
+ // Process leaning
+ float idleAngle = 0.0f;
+ if(pDriver){
+ CAnimBlendAssociation *assoc = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_BIKE_STILL);
+ if(assoc)
+ idleAngle = DEGTORAD(10.0f) * assoc->blendAmount;
+ }
+ if(bCanStand || m_bike_flag08){
+ m_vecAvgSurfaceRight = CrossProduct(GetForward(), m_vecAvgSurfaceNormal);
+ m_vecAvgSurfaceRight.Normalise();
+ float lean;
+ if(m_nWheelsOnGround == 0){
+ lean = -m_fSteerAngle/DEGTORAD(pHandling->fSteeringLock)*0.5f*GRAVITY*CTimer::GetTimeStep();
+ }else
+ lean = DotProduct(m_vecMoveSpeed-initialMoveSpeed, m_vecAvgSurfaceRight);
+ lean /= GRAVITY*Max(CTimer::GetTimeStep(), 0.01f);
+ if(m_wheelStatus[BIKEWHEEL_FRONT] == WHEEL_STATUS_BURST)
+ lean = clamp(lean, -0.4f*pBikeHandling->fMaxLean, 0.4f*pBikeHandling->fMaxLean);
+ else
+ lean = clamp(lean, -pBikeHandling->fMaxLean, pBikeHandling->fMaxLean);
+ float f = Pow(pBikeHandling->fDesLean, CTimer::GetTimeStep());
+ m_fLeanLRAngle2 = (Asin(lean) - idleAngle)*(1.0f-f) + m_fLeanLRAngle2*f;
+ }else{
+ if(bIsStanding){
+ float f = Pow(0.97f, CTimer::GetTimeStep());
+ m_fLeanLRAngle2 = m_fLeanLRAngle2*f - (Asin(GetRight().z) + DEGTORAD(15.0f) + idleAngle)*(1.0f-f);
+ }else{
+ float f = Pow(0.95f, CTimer::GetTimeStep());
+ m_fLeanLRAngle2 = m_fLeanLRAngle2*f;
+ }
+ }
+ m_fLeanLRAngle = m_fLeanLRAngle2;
+
+ // TODO: what is this?
+ if((m_aSuspensionSpringRatio[BIKESUSP_F1] < 1.0f || m_aSuspensionSpringRatio[BIKESUSP_F2] < 1.0f) &&
+ m_fBrakePedal - m_fGasPedal > 0.9f &&
+ fwdSpeed > 0.02f &&
+ !bIsHandbrakeOn){
+ someAngle += CGeneral::GetRandomNumberInRange(0.5f, 1.0f)*0.2f*CTimer::GetTimeStep();
+ if(m_aSuspensionSpringRatio[BIKESUSP_R1] < 1.0f || m_aSuspensionSpringRatio[BIKESUSP_R2] < 1.0f){
+ // BUG: this clamp makes no sense and the arguments seem swapped too
+ ApplyTurnForce(contactPoints[BIKESUSP_R1],
+ m_fTurnMass*Sin(someAngle)*clamp(fwdSpeed, 0.5f, 0.2f)*0.013f*GetRight()*CTimer::GetTimeStep());
+ }else{
+ // BUG: this clamp makes no sense and the arguments seem swapped too
+ ApplyTurnForce(contactPoints[BIKESUSP_R1],
+ m_fTurnMass*Sin(someAngle)*clamp(fwdSpeed, 0.5f, 0.2f)*0.003f*GetRight()*CTimer::GetTimeStep());
+ }
+ }else
+ someAngle = 0.0f;
+
+ // Update wheel positions from suspension
+ float frontWheelPos = colModel->lines[frontLine].p0.z;
+ if(m_aSuspensionSpringRatio[frontLine] > 0.0f)
+ frontWheelPos -= m_aSuspensionSpringRatio[frontLine]*m_aSuspensionSpringLength[frontLine];
+ m_aWheelPosition[BIKEWHEEL_FRONT] += (frontWheelPos - m_aWheelPosition[BIKEWHEEL_FRONT])*0.75f;
+
+ float rearWheelPos = colModel->lines[rearLine].p0.z;
+ if(m_aSuspensionSpringRatio[rearLine] > 0.0f)
+ rearWheelPos -= m_aSuspensionSpringRatio[rearLine]*m_aSuspensionSpringLength[rearLine];
+ m_aWheelPosition[BIKEWHEEL_REAR] += (rearWheelPos - m_aWheelPosition[BIKEWHEEL_REAR])*0.75f;
+
+ for(i = 0; i < 2; i++)
+ m_aWheelState[i] = WheelState[i];
+ // never spin when moving backwards
+ if(m_fGasPedal < 0.0f && m_aWheelState[BIKEWHEEL_REAR] == WHEEL_STATE_SPINNING)
+ m_aWheelState[BIKEWHEEL_REAR] = WHEEL_STATE_NORMAL;
+
+ // Process horn
+
+ if(GetStatus() != STATUS_PLAYER){
+#ifdef FIX_BUGS
+ if(!IsAlarmOn())
+#endif
+ ReduceHornCounter();
+ }else{
+#ifdef FIX_BUGS
+ if(!IsAlarmOn())
+#endif
+ {
+ if(Pads[0].GetHorn())
+ m_nCarHornTimer = 1;
+ else
+ m_nCarHornTimer = 0;
+ }
+ }
+ }
+
+ // TODO: pad shaking
+ for(i = 0; i < 4; i++){
+ m_aSuspensionSpringRatioPrev[i] = m_aSuspensionSpringRatio[i];
+ m_aSuspensionSpringRatio[i] = 1.0f;
+ }
+
+ if(bInfiniteMass){
+ m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f);
+ m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f);
+ m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f);
+ }else if(!skipPhysics &&
+ (acceleration == 0.0f && brake == 0.0f || GetStatus() == STATUS_WRECKED)){
+ if(Abs(m_vecMoveSpeed.x) < 0.005f &&
+ Abs(m_vecMoveSpeed.y) < 0.005f &&
+ Abs(m_vecMoveSpeed.z) < 0.005f){
+ m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ m_vecTurnSpeed.z = 0.0f;
+ }
+ }
+
+ // Balance bike
+ if(bCanStand || m_bike_flag08 || bIsStanding){
+ float onSideness = clamp(DotProduct(GetRight(), m_vecAvgSurfaceNormal), -1.0f, 1.0f);
+ CVector worldCOM = Multiply3x3(GetMatrix(), m_vecCentreOfMass);
+ if(bCanStand){
+ ApplyTurnForce(-0.07f*onSideness*m_fTurnMass*GetUp()*CTimer::GetTimeStep(), worldCOM+GetRight());
+ bIsStanding = false;
+ }else{
+ ApplyTurnForce(-0.1f*onSideness*m_fTurnMass*GetUp()*CTimer::GetTimeStep(), worldCOM+GetRight());
+ }
+// TODO
+ }
}
void
@@ -175,6 +1096,125 @@ CBike::Teleport(CVector pos)
void
CBike::PreRender(void)
{
+// TODO: particles and lights and such
+
+ CMatrix mat;
+ CVector pos;
+ CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex());
+ CColModel *colModel = mi->GetColModel();
+
+ // Wheel rotation
+ CVector frontWheelFwd = Multiply3x3(GetMatrix(), CVector(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f));
+ CVector rearWheelFwd = GetForward();
+ if(m_aWheelTimer[BIKESUSP_F1] > 0.0f || m_aWheelTimer[BIKESUSP_F2] > 0.0f){
+ float springRatio = Min(m_aSuspensionSpringRatioPrev[BIKESUSP_F1], m_aSuspensionSpringRatioPrev[BIKESUSP_F2]);
+ CVector contactPoint(0.0f,
+ (colModel->lines[BIKESUSP_F1].p0.y - colModel->lines[BIKESUSP_F2].p0.y)/2.0f,
+ colModel->lines[BIKESUSP_F1].p0.z - m_aSuspensionSpringLength[BIKESUSP_F1]*springRatio - 0.5f*mi->m_wheelScale);
+ CVector contactSpeed = GetSpeed(contactPoint);
+ // Why is wheel state always normal?
+ m_aWheelSpeed[BIKEWHEEL_FRONT] = ProcessWheelRotation(WHEEL_STATE_NORMAL, frontWheelFwd, contactSpeed, 0.5f*mi->m_wheelScale);
+ m_aWheelRotation[BIKEWHEEL_FRONT] += m_aWheelSpeed[BIKEWHEEL_FRONT];
+ }
+ if(m_aWheelTimer[BIKESUSP_R1] > 0.0f || m_aWheelTimer[BIKESUSP_R2] > 0.0f){
+ float springRatio = Min(m_aSuspensionSpringRatioPrev[BIKESUSP_R1], m_aSuspensionSpringRatioPrev[BIKESUSP_R2]);
+ CVector contactPoint(0.0f,
+ (colModel->lines[BIKESUSP_R1].p0.y - colModel->lines[BIKESUSP_R2].p0.y)/2.0f,
+ colModel->lines[BIKESUSP_R1].p0.z - m_aSuspensionSpringLength[BIKESUSP_R1]*springRatio - 0.5f*mi->m_wheelScale);
+ CVector contactSpeed = GetSpeed(contactPoint);
+ m_aWheelSpeed[BIKEWHEEL_REAR] = ProcessWheelRotation(m_aWheelState[BIKEWHEEL_REAR], rearWheelFwd, contactSpeed, 0.5f*mi->m_wheelScale);
+ m_aWheelRotation[BIKEWHEEL_REAR] += m_aWheelSpeed[BIKEWHEEL_REAR];
+ }
+
+ // Rear fork
+ if(m_aBikeNodes[BIKE_FORKS_FRONT]){
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_FORKS_FRONT]));
+ pos = mat.GetPosition();
+
+ RwMatrix rwrot;
+ // TODO: this looks like some weird ctor we don't have
+ CMatrix rot;
+ rot.m_attachment = &rwrot;
+ rot.SetUnity();
+ rot.UpdateRW();
+
+ // Make rotation matrix with front fork as axis
+ CVector forkAxis(0.0f, Sin(DEGTORAD(mi->m_bikeSteerAngle)), -Cos(DEGTORAD(mi->m_bikeSteerAngle)));
+ forkAxis.Normalise(); // as if that's not already the case
+ CQuaternion quat;
+ quat.Set((RwV3d*)&forkAxis, -m_fWheelAngle);
+ quat.Get(rot.m_attachment);
+ rot.Update();
+
+ // Transform fork
+ mat.SetUnity();
+ mat = mat * rot;
+ mat.Translate(pos);
+ mat.UpdateRW();
+
+ if(m_aBikeNodes[BIKE_HANDLEBARS]){
+ // Transform handle
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_HANDLEBARS]));
+ pos = mat.GetPosition();
+ if(GetStatus() == STATUS_ABANDONED || GetStatus() == STATUS_WRECKED){
+ mat.SetUnity();
+ mat = mat * rot;
+ mat.Translate(pos);
+ }else
+ mat.SetTranslate(mat.GetPosition());
+ mat.UpdateRW();
+ }
+ }
+
+ // Front fork
+ if(m_aBikeNodes[BIKE_FORKS_REAR]){
+ float sine = (m_aWheelPosition[BIKEWHEEL_REAR] - m_aWheelBasePosition[BIKEWHEEL_REAR])/m_fRearForkLength;
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_FORKS_REAR]));
+ pos = mat.GetPosition();
+ mat.SetRotate(-Asin(sine), 0.0f, 0.0f);
+ mat.Translate(pos);
+ mat.UpdateRW();
+ }
+
+ // Front wheel
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_WHEEL_FRONT]));
+ pos.x = mat.GetPosition().x;
+ pos.z = m_aWheelPosition[BIKEWHEEL_FRONT] - m_fFrontForkZ;
+ float y = (colModel->lines[BIKESUSP_F1].p0.y+colModel->lines[BIKESUSP_F2].p0.y)/2.0f - m_fFrontForkY;
+ pos.y = y - (m_aWheelPosition[BIKEWHEEL_FRONT] - m_aWheelBasePosition[BIKEWHEEL_FRONT])*m_fFrontForkSlope;
+ if(m_wheelStatus[BIKEWHEEL_FRONT] == WHEEL_STATUS_BURST)
+ mat.SetRotate(m_aWheelRotation[BIKEWHEEL_FRONT], 0.0f, 0.05f*Sin(m_aWheelRotation[BIKEWHEEL_FRONT]));
+ else
+ mat.SetRotateX(m_aWheelRotation[BIKEWHEEL_FRONT]);
+ mat.Translate(pos);
+ mat.UpdateRW();
+ // and mudguard
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_MUDGUARD]));
+ mat.SetTranslateOnly(pos);
+ mat.UpdateRW();
+
+ // Rear wheel
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_WHEEL_REAR]));
+ pos = mat.GetPosition();
+ if(m_wheelStatus[BIKEWHEEL_REAR] == WHEEL_STATUS_BURST)
+ mat.SetRotate(m_aWheelRotation[BIKEWHEEL_REAR], 0.0f, 0.07f*Sin(m_aWheelRotation[BIKEWHEEL_REAR]));
+ else
+ mat.SetRotateX(m_aWheelRotation[BIKEWHEEL_REAR]);
+ mat.Translate(pos);
+ mat.UpdateRW();
+
+ // Chassis
+ if(m_aBikeNodes[BIKE_CHASSIS]){
+ mat.Attach(RwFrameGetMatrix(m_aBikeNodes[BIKE_CHASSIS]));
+ pos = mat.GetPosition();
+ pos.z = (1.0f - Cos(m_fLeanLRAngle)) * (0.9*colModel->boundingBox.min.z);
+ mat.SetRotateX(-0.05f*Abs(m_fLeanLRAngle));
+ mat.RotateY(m_fLeanLRAngle);
+ mat.Translate(pos);
+ mat.UpdateRW();
+ }
+
+// TODO: exhaust
}
void
@@ -216,7 +1256,7 @@ CBike::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
// In ProcessControl these will be re-normalized to ignore the tyre radius.
if(colModel->numLines){
- for(i = 0; i < 4; i++)
+ for(i = 0; i < 4; i++){
if(m_aSuspensionSpringRatio[i] < 1.0f && m_aSuspensionSpringRatio[i] < prevRatios[i]){
numWheelCollisions++;
@@ -233,6 +1273,7 @@ CBike::ProcessEntityCollision(CEntity *ent, CColPoint *colpoints)
if(ent->IsBuilding())
m_pCurGroundEntity = ent;
}
+ }
}else
colModel->numLines = 4;
@@ -383,6 +1424,24 @@ CBike::ProcessControlInputs(uint8 pad)
}
void
+CBike::ProcessBuoyancy(void)
+{
+ // TODO
+}
+
+void
+CBike::DoDriveByShootings(void)
+{
+ // TODO
+}
+
+void
+CBike::VehicleDamage(void)
+{
+ // TODO
+}
+
+void
CBike::GetComponentWorldPosition(int32 component, CVector &pos)
{
if(m_aBikeNodes[component] == nil){
@@ -451,6 +1510,8 @@ CBike::BlowUpCar(CEntity *culprit)
if(!bCanBeDamaged)
return;
+// TODO: property damage stuff in FIX_BUGS
+
// explosion pushes vehicle up
m_vecMoveSpeed.z += 0.13f;
SetStatus(STATUS_WRECKED);
@@ -487,7 +1548,6 @@ CBike::BurstTyre(uint8 wheel, bool applyForces)
switch(wheel){
case CAR_PIECE_WHEEL_LF: wheel = BIKEWHEEL_FRONT; break;
case CAR_PIECE_WHEEL_LR: wheel = BIKEWHEEL_REAR; break;
- default: assert(0 && "invalid wheel");
}
if(m_wheelStatus[wheel] == WHEEL_STATUS_OK){
@@ -652,19 +1712,19 @@ CBike::SetupSuspensionLines(void)
posn.z = m_aWheelBasePosition[1];
}else{
switch(i){
- case BIKESUSP_FRONT_1:
+ case BIKESUSP_F1:
node = m_aBikeNodes[BIKE_WHEEL_FRONT];
suspOffset = 0.25f*mi->m_wheelScale;
break;
- case BIKESUSP_FRONT_2:
+ case BIKESUSP_F2:
node = m_aBikeNodes[BIKE_WHEEL_FRONT];
suspOffset = -0.25f*mi->m_wheelScale;
break;
- case BIKESUSP_REAR_1:
+ case BIKESUSP_R1:
node = m_aBikeNodes[BIKE_WHEEL_REAR];
suspOffset = 0.25f*mi->m_wheelScale;
break;
- case BIKESUSP_REAR_2:
+ case BIKESUSP_R2:
node = m_aBikeNodes[BIKE_WHEEL_REAR];
suspOffset = -0.25f*mi->m_wheelScale;
break;
@@ -672,15 +1732,16 @@ CBike::SetupSuspensionLines(void)
GetRelativeMatrix(mat, node, node);
posn = *RwMatrixGetPos(mat);
- if(i == BIKESUSP_FRONT_1)
+ if(i == BIKESUSP_F1)
m_aWheelBasePosition[BIKEWHEEL_FRONT] = posn.z;
- else if(i == BIKESUSP_REAR_1){
+ else if(i == BIKESUSP_R1){
m_aWheelBasePosition[BIKEWHEEL_REAR] = posn.z;
- GetRelativeMatrix(mat, node, m_aBikeNodes[BIKE_FORKS_REAR]);
+ GetRelativeMatrix(mat, m_aBikeNodes[BIKE_FORKS_REAR], m_aBikeNodes[BIKE_FORKS_REAR]);
float dz = posn.z - RwMatrixGetPos(mat)->z;
float dy = posn.y - RwMatrixGetPos(mat)->y;
m_fRearForkLength = Sqrt(SQR(dy) + SQR(dz));
+ assert(m_fRearForkLength != 0.0f); // we want to divide by this
}
posn.y += suspOffset;
}
@@ -701,7 +1762,7 @@ CBike::SetupSuspensionLines(void)
}
if(!initialized){
- GetRelativeMatrix(mat, m_aBikeNodes[BIKE_FORKS_REAR], m_aBikeNodes[BIKE_FORKS_REAR]);
+ GetRelativeMatrix(mat, m_aBikeNodes[BIKE_FORKS_FRONT], m_aBikeNodes[BIKE_FORKS_FRONT]);
m_fFrontForkY = RwMatrixGetPos(mat)->y;
m_fFrontForkZ = RwMatrixGetPos(mat)->z;
}
diff --git a/src/vehicles/Bike.h b/src/vehicles/Bike.h
index c524a89c..6c8db44a 100644
--- a/src/vehicles/Bike.h
+++ b/src/vehicles/Bike.h
@@ -21,10 +21,10 @@ enum {
};
enum {
- BIKESUSP_FRONT_1,
- BIKESUSP_FRONT_2,
- BIKESUSP_REAR_1,
- BIKESUSP_REAR_2,
+ BIKESUSP_F1,
+ BIKESUSP_F2,
+ BIKESUSP_R1,
+ BIKESUSP_R2,
};
class CBike : public CVehicle
@@ -33,8 +33,8 @@ public:
RwFrame *m_aBikeNodes[BIKE_NUM_NODES];
bool bLeanMatrixClean;
CMatrix m_leanMatrix;
- CVector wheelieNormal;
- CVector wheelieRight;
+ CVector m_vecAvgSurfaceNormal;
+ CVector m_vecAvgSurfaceRight;
tBikeHandlingData *pBikeHandling;
AssocGroupId m_bikeAnimType;
uint8 m_wheelStatus[2];
@@ -58,7 +58,7 @@ public:
float m_fFrontForkY;
float m_fFrontForkZ;
float m_fFrontForkSlope;
- float m_fBikeSteerAngle;
+ float m_fWheelAngle;
float m_fLeanLRAngle;
float m_fLeanLRAngle2;
float m_fLeanInput;
@@ -68,9 +68,9 @@ public:
uint8 unused[3]; // looks like padding..but for what?
uint8 m_bike_flag01 : 1;
uint8 m_bike_flag02 : 1;
- uint8 m_bike_flag04 : 1;
+ uint8 bWaterTight : 1;
uint8 m_bike_flag08 : 1;
- uint8 m_bike_flag10 : 1;
+ uint8 bIsStanding : 1;
uint8 m_bike_flag20 : 1;
uint8 m_bike_flag40 : 1;
uint8 m_bike_flag80 : 1;
@@ -117,6 +117,9 @@ public:
float GetHeightAboveRoad(void);
void PlayCarHorn(void);
+ void VehicleDamage(void);
+ void ProcessBuoyancy(void);
+ void DoDriveByShootings(void);
void PlayHornIfNecessary(void);
void ResetSuspension(void);
void SetupSuspensionLines(void);
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index 7a4aad50..764e49cc 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -926,7 +926,7 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee
if(bAlreadySkidding)
adhesion *= pHandling->fTractionLoss;
- if(special == BIKE_WHEEL_2 || special == BIKE_WHEEL_3)
+ if(special == BIKE_WHEELSPEC_2 || special == BIKE_WHEELSPEC_3)
contactSpeedRight = 0.0f;
else
contactSpeedRight = DotProduct(wheelContactSpeed, wheelRight);
diff --git a/src/vehicles/Vehicle.h b/src/vehicles/Vehicle.h
index 319f27c8..b3a36c6d 100644
--- a/src/vehicles/Vehicle.h
+++ b/src/vehicles/Vehicle.h
@@ -128,11 +128,13 @@ enum eVehicleAppearance
VEHICLE_APPEARANCE_PLANE,
};
-// TODO
+// TODO: what is this even?
enum eBikeWheelSpecial
{
- BIKE_WHEEL_2 = 2,
- BIKE_WHEEL_3,
+ BIKE_WHEELSPEC_0, // both wheels on ground
+ BIKE_WHEELSPEC_1, // rear wheel on ground
+ BIKE_WHEELSPEC_2, // only front wheel on ground
+ BIKE_WHEELSPEC_3, // can't happen
};
enum