summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/animation/AnimBlendAssociation.h5
-rw-r--r--src/audio/DMAudio.h18
-rw-r--r--src/control/CarCtrl.cpp9
-rw-r--r--src/control/Darkel.cpp298
-rw-r--r--src/control/Darkel.h10
-rw-r--r--src/control/Garages.cpp3
-rw-r--r--src/control/Garages.h3
-rw-r--r--src/control/Pickups.cpp1058
-rw-r--r--src/control/Pickups.h168
-rw-r--r--src/control/Script.cpp8
-rw-r--r--src/core/Camera.cpp24
-rw-r--r--src/core/Camera.h23
-rw-r--r--src/core/CutsceneMgr.cpp417
-rw-r--r--src/core/CutsceneMgr.h29
-rw-r--r--src/core/Frontend.cpp2
-rw-r--r--src/core/General.h9
-rw-r--r--src/core/Pad.h1
-rw-r--r--src/core/PlayerInfo.cpp24
-rw-r--r--src/core/PlayerInfo.h1
-rw-r--r--src/core/PlayerSkin.cpp166
-rw-r--r--src/core/PlayerSkin.h16
-rw-r--r--src/core/Pools.cpp1
-rw-r--r--src/core/Pools.h1
-rw-r--r--src/core/Radar.cpp424
-rw-r--r--src/core/Radar.h38
-rw-r--r--src/core/Streaming.cpp17
-rw-r--r--src/core/TempColModels.cpp2
-rw-r--r--src/core/TempColModels.h2
-rw-r--r--src/core/World.h3
-rw-r--r--src/core/common.h4
-rw-r--r--src/core/config.h27
-rw-r--r--src/entities/Physical.cpp2
-rw-r--r--src/entities/Physical.h2
-rw-r--r--src/math/Matrix.h17
-rw-r--r--src/math/math.cpp6
-rw-r--r--src/modelinfo/ModelIndices.h2
-rw-r--r--src/objects/Object.cpp4
-rw-r--r--src/objects/Object.h6
-rw-r--r--src/peds/CivilianPed.cpp26
-rw-r--r--src/peds/CivilianPed.h1
-rw-r--r--src/peds/Ped.cpp4003
-rw-r--r--src/peds/Ped.h90
-rw-r--r--src/peds/PedRoutes.cpp3
-rw-r--r--src/peds/PedRoutes.h3
-rw-r--r--src/peds/PlayerPed.cpp2
-rw-r--r--src/peds/PlayerPed.h2
-rw-r--r--src/render/Coronas.cpp4
-rw-r--r--src/render/Font.cpp8
-rw-r--r--src/render/Hud.cpp310
-rw-r--r--src/render/Hud.h2
-rw-r--r--src/render/MoneyMessages.cpp86
-rw-r--r--src/render/MoneyMessages.h24
-rw-r--r--src/render/Sprite2d.cpp14
-rw-r--r--src/render/Sprite2d.h2
54 files changed, 6582 insertions, 848 deletions
diff --git a/src/animation/AnimBlendAssociation.h b/src/animation/AnimBlendAssociation.h
index cd61636f..01d862cc 100644
--- a/src/animation/AnimBlendAssociation.h
+++ b/src/animation/AnimBlendAssociation.h
@@ -13,12 +13,13 @@ enum {
ASSOC_PARTIAL = 0x10,
ASSOC_MOVEMENT = 0x20, // ???
ASSOC_HAS_TRANSLATION = 0x40,
- ASSOC_FLAG80 = 0x80, // walking and running have it
+ ASSOC_FLAG80 = 0x80, // used for footstep sound calculation
ASSOC_FLAG100 = 0x100,
ASSOC_FLAG200 = 0x200,
ASSOC_FLAG400 = 0x400, // not seen yet
- ASSOC_FLAG800 = 0x800,
+ ASSOC_FLAG800 = 0x800, // anims that we fall to front. 0x1000 in VC
ASSOC_HAS_X_TRANSLATION = 0x1000,
+ // 0x2000 is vehicle anims in VC
};
// Anim hierarchy associated with a clump
diff --git a/src/audio/DMAudio.h b/src/audio/DMAudio.h
index 42dd9ef4..fe120576 100644
--- a/src/audio/DMAudio.h
+++ b/src/audio/DMAudio.h
@@ -101,25 +101,25 @@ enum eSound : int16
SOUND_EVIDENCE_PICKUP = 94,
SOUND_UNLOAD_GOLD = 95,
SOUND_PAGER = 96,
- SOUND_PED_DEATH = 97,
- SOUND_PED_DAMAGE = 98,
- SOUND_PED_HIT = 99,
- SOUND_PED_LAND = 100,
+ SOUND_PED_DEATH = 97, // 103 in VC
+ SOUND_PED_DAMAGE = 98, // 104 in VC
+ SOUND_PED_HIT = 99, // 105 in VC
+ SOUND_PED_LAND = 100, // hopefully 106 in VC
SOUND_PED_BULLET_HIT = 101,
SOUND_PED_BOMBER = 102,
- SOUND_PED_BURNING = 103,
+ SOUND_PED_BURNING = 103, // 108 in VC
SOUND_PED_ARREST_FBI = 104,
SOUND_PED_ARREST_SWAT = 105,
SOUND_PED_ARREST_COP = 106,
SOUND_PED_HELI_PLAYER_FOUND = 107,
SOUND_PED_HANDS_UP = 108,
SOUND_PED_HANDS_COWER = 109,
- SOUND_PED_FLEE_SPRINT = 110,
+ SOUND_PED_FLEE_SPRINT = 110, // 120 in VC
SOUND_PED_CAR_JACKING = 111,
SOUND_PED_MUGGING = 112,
SOUND_PED_CAR_JACKED = 113,
SOUND_PED_ROBBED = 114,
- SOUND_PED_TAXI_WAIT = 115,
+ SOUND_PED_TAXI_WAIT = 115, // 137 in VC
SOUND_PED_ATTACK = 116,
SOUND_PED_DEFEND = 117,
SOUND_PED_PURSUIT_ARMY = 118,
@@ -129,9 +129,9 @@ enum eSound : int16
SOUND_PED_HEALING = 122,
SOUND_PED_7B = 123,
SOUND_PED_LEAVE_VEHICLE = 124,
- SOUND_PED_EVADE = 125,
+ SOUND_PED_EVADE = 125, // 142 in VC
SOUND_PED_FLEE_RUN = 126,
- SOUND_PED_CAR_COLLISION = 127,
+ SOUND_PED_CAR_COLLISION = 127, // 144-145-146 in VC
SOUND_PED_SOLICIT = 128,
SOUND_PED_EXTINGUISHING_FIRE = 129,
SOUND_PED_WAIT_DOUBLEBACK = 130,
diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp
index a6cbad5e..4775d595 100644
--- a/src/control/CarCtrl.cpp
+++ b/src/control/CarCtrl.cpp
@@ -696,7 +696,7 @@ CCarCtrl::PossiblyRemoveVehicle(CVehicle* pVehicle)
}
if (pVehicle->bExtendedRange)
threshold *= 1.5f;
- if (distanceToPlayer > threshold && !CGarages::IsPointWithinHideOutGarage(&pVehicle->GetPosition())){
+ if (distanceToPlayer > threshold && !CGarages::IsPointWithinHideOutGarage(pVehicle->GetPosition())){
if (pVehicle->GetIsOnScreen() && CRenderer::IsEntityCullZoneVisible(pVehicle)){
pVehicle->bFadeOut = true;
}else{
@@ -712,9 +712,10 @@ CCarCtrl::PossiblyRemoveVehicle(CVehicle* pVehicle)
(pVehicle->GetPosition() - vecPlayerPos).Magnitude2D() > 25.0f &&
!IsThisVehicleInteresting(pVehicle) &&
!pVehicle->bIsLocked &&
+ pVehicle->CanBeDeleted() &&
!CTrafficLights::ShouldCarStopForLight(pVehicle, true) &&
!CTrafficLights::ShouldCarStopForBridge(pVehicle) &&
- !CGarages::IsPointWithinHideOutGarage(&pVehicle->GetPosition())){
+ !CGarages::IsPointWithinHideOutGarage(pVehicle->GetPosition())){
CWorld::Remove(pVehicle);
delete pVehicle;
return;
@@ -724,7 +725,7 @@ CCarCtrl::PossiblyRemoveVehicle(CVehicle* pVehicle)
if (CTimer::GetTimeInMilliseconds() > pVehicle->m_nTimeOfDeath + 60000 &&
(!pVehicle->GetIsOnScreen() || !CRenderer::IsEntityCullZoneVisible(pVehicle))){
if ((pVehicle->GetPosition() - vecPlayerPos).MagnitudeSqr() > SQR(7.5f)){
- if (!CGarages::IsPointWithinHideOutGarage(&pVehicle->GetPosition())){
+ if (!CGarages::IsPointWithinHideOutGarage(pVehicle->GetPosition())){
CWorld::Remove(pVehicle);
delete pVehicle;
}
@@ -1322,7 +1323,7 @@ void CCarCtrl::WeaveThroughPedsSectorList(CPtrList& lst, CVehicle* pVehicle, CPh
continue;
if (pPed->GetPosition().y < y_inf || pPed->GetPosition().y > y_sup)
continue;
- if (Abs(pPed->GetPosition().z - pPed->GetPosition().z) >= PED_HEIGHT_DIFF_TO_CONSIDER_WEAVING)
+ if (Abs(pPed->GetPosition().z - pVehicle->GetPosition().z) >= PED_HEIGHT_DIFF_TO_CONSIDER_WEAVING)
continue;
if (pPed->m_pCurSurface != pVehicle)
WeaveForPed(pPed, pVehicle, pAngleToWeaveLeft, pAngleToWeaveRight);
diff --git a/src/control/Darkel.cpp b/src/control/Darkel.cpp
index 670c10fb..da28faa7 100644
--- a/src/control/Darkel.cpp
+++ b/src/control/Darkel.cpp
@@ -2,12 +2,12 @@
#include "patcher.h"
#include "main.h"
#include "Darkel.h"
+#include "PlayerPed.h"
#include "Timer.h"
#include "DMAudio.h"
#include "Population.h"
#include "Weapon.h"
#include "World.h"
-#include "PlayerPed.h"
#include "Stats.h"
#include "Font.h"
#include "Text.h"
@@ -19,105 +19,140 @@ int32 &CDarkel::WeaponType = *(int32*)0x9430F0;
int32 &CDarkel::AmmoInterruptedWeapon = *(int32*)0x8E29C8;
int32 &CDarkel::KillsNeeded = *(int32*)0x8F1AB8;
int8 &CDarkel::InterruptedWeapon = *(int8*)0x95CD60;
+
+/*
+ * bStandardSoundAndMessages is a completely beta thing,
+ * makes game handle sounds & messages instead of SCM (just like in GTA2)
+ * but it's never been used in the game. Has unused sliding text when frenzy completed etc.
+ */
int8 &CDarkel::bStandardSoundAndMessages = *(int8*)0x95CDB6;
int8 &CDarkel::bNeedHeadShot = *(int8*)0x95CDCA;
int8 &CDarkel::bProperKillFrenzy = *(int8*)0x95CD98;
eKillFrenzyStatus &CDarkel::Status = *(eKillFrenzyStatus*)0x95CCB4;
-int16 *CDarkel::RegisteredKills = (int16*)0x6EDBE0;
+uint16 (&CDarkel::RegisteredKills)[NUMDEFAULTMODELS] = *(uint16(*)[NUMDEFAULTMODELS]) * (uintptr*)0x6EDBE0;
int32 &CDarkel::ModelToKill = *(int32*)0x8F2C78;
int32 &CDarkel::ModelToKill2 = *(int32*)0x885B40;
int32 &CDarkel::ModelToKill3 = *(int32*)0x885B3C;
int32 &CDarkel::ModelToKill4 = *(int32*)0x885B34;
wchar *CDarkel::pStartMessage = (wchar*)0x8F2C08;
-int32 CDarkel::CalcFade(uint32 time, int32 start, uint32 end) {
+uint8
+CDarkel::CalcFade(uint32 time, uint32 start, uint32 end)
+{
if (time >= start && time <= end) {
if (time >= start + 500) {
if (time <= end - 500)
return 255;
else
return 255 * (end - time) / 500;
- }
- else
+ } else
return 255 * (time - start) / 500;
- }
- else
+ } else
return 0;
}
-// This function has been cleaned up from unused stuff.
-#if 0
-WRAPPER void CDarkel::DrawMessages(void) { EAXJMP(0x420920); }
-#else
-void CDarkel::DrawMessages()
+// Screen positions taken from VC
+void
+CDarkel::DrawMessages()
{
- bool DisplayTimers = false;
-
switch (Status) {
- case KILLFRENZY_ONGOING:
- assert(pStartMessage != nil);
- DisplayTimers = true;
- break;
- case KILLFRENZY_PASSED:
- case KILLFRENZY_FAILED:
- DisplayTimers = false;
- break;
- };
-
- if (DisplayTimers) {
- CFont::SetPropOn();
- CFont::SetBackgroundOff();
- CFont::SetBackGroundOnlyTextOn();
- CFont::SetAlignment(ALIGN_RIGHT);
- CFont::SetRightJustifyWrap(-SCREEN_WIDTH);
- CFont::SetFontStyle(FONT_HEADING);
- CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f));
-
- float AlignToHUD = SCREEN_SCALE_X(-10.0f);
- int32 a = (TimeLimit - (CTimer::GetTimeInMilliseconds() - TimeOfFrenzyStart));
- if (CTimer::GetFrameCounter() & 8 || a > 4000) {
- sprintf(gString, "%d:%02d", a / 60000, a % 60000 / 1000);
+ case KILLFRENZY_ONGOING:
+ {
+ CFont::SetJustifyOff();
+ CFont::SetBackgroundOff();
+ CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(30.0f));
+ CFont::SetCentreOn();
+ CFont::SetPropOn();
+ uint32 timePassedSinceStart = CTimer::GetTimeInMilliseconds() - CDarkel::TimeOfFrenzyStart;
+ if (CDarkel::bStandardSoundAndMessages) {
+ if (timePassedSinceStart >= 3000 && timePassedSinceStart < 11000) {
+ CFont::SetScale(SCREEN_SCALE_X(1.3f), SCREEN_SCALE_Y(1.3f));
+ CFont::SetJustifyOff();
+ CFont::SetColor(CRGBA(255, 255, 128, CalcFade(timePassedSinceStart, 3000, 11000)));
+ CFont::SetFontStyle(FONT_BANK);
+ if (pStartMessage) {
+ CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, pStartMessage);
+ }
+ }
+ } else {
+ if (timePassedSinceStart < 8000) {
+ CFont::SetScale(SCREEN_SCALE_X(1.3f), SCREEN_SCALE_Y(1.3f));
+ CFont::SetJustifyOff();
+ CFont::SetColor(CRGBA(255, 255, 128, CalcFade(timePassedSinceStart, 0, 8000)));
+ CFont::SetFontStyle(FONT_BANK);
+ if (pStartMessage) {
+ CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, pStartMessage);
+ }
+ }
+ }
+ CFont::SetScale(SCREEN_SCALE_X(0.75f), SCREEN_SCALE_Y(1.5f));
+ CFont::SetCentreOff();
+ CFont::SetRightJustifyOn();
+ CFont::SetFontStyle(FONT_HEADING);
+ if (CDarkel::TimeLimit >= 0) {
+ uint32 timeLeft = CDarkel::TimeLimit - (CTimer::GetTimeInMilliseconds() - CDarkel::TimeOfFrenzyStart);
+ sprintf(gString, "%d:%02d", timeLeft / 60000, timeLeft % 60000 / 1000);
+ AsciiToUnicode(gString, gUString);
+ if (timeLeft > 4000 || CTimer::GetFrameCounter() & 1) {
+ CFont::SetColor(CRGBA(0, 0, 0, 255));
+ CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(109.0f), gUString);
+ CFont::SetColor(CRGBA(150, 100, 255, 255));
+ CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(34.0f), SCREEN_SCALE_Y(108.0f), gUString);
+ }
+ }
+ sprintf(gString, "%d", (CDarkel::KillsNeeded >= 0 ? CDarkel::KillsNeeded : 0));
AsciiToUnicode(gString, gUString);
CFont::SetColor(CRGBA(0, 0, 0, 255));
- CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(25.0f) + AlignToHUD, SCREEN_SCALE_Y(112.0f), gUString);
-
- CFont::SetColor(CRGBA(150, 100, 255, 255));
- CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(27.0f) + AlignToHUD, SCREEN_SCALE_Y(110.0f), gUString);
+ CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(144.0f), gUString);
+ CFont::SetColor(CRGBA(255, 128, 128, 255));
+ CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(34.0f), SCREEN_SCALE_Y(143.0f), gUString);
+ break;
}
-
- if (KillsNeeded <= 0)
- KillsNeeded = 0;
-
- sprintf((char *)gString, "%d", KillsNeeded);
- AsciiToUnicode(gString, gUString);
-
- CFont::SetColor(CRGBA(0, 0, 0, 255));
- CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(25.0f) + AlignToHUD, SCREEN_SCALE_Y(134.0f), gUString);
-
- CFont::SetColor(CRGBA(255, 128, 128, 255));
- CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(27.0f) + AlignToHUD, SCREEN_SCALE_Y(132.0f), gUString);
+ case KILLFRENZY_PASSED:
+ {
+ if (CDarkel::bStandardSoundAndMessages) {
+ uint32 timePassedSinceStart = CTimer::GetTimeInMilliseconds() - CDarkel::TimeOfFrenzyStart;
+ if (CTimer::GetTimeInMilliseconds() - CDarkel::TimeOfFrenzyStart < 5000) {
+ CFont::SetBackgroundOff();
+ CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f));
+ CFont::SetCentreOn();
+ CFont::SetScale(SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.5f));
+ CFont::SetJustifyOff();
+ CFont::SetColor(CRGBA(128, 255, 128, CalcFade(timePassedSinceStart, 0, 5000)));
+ CFont::SetFontStyle(FONT_BANK);
+ int y = SCREEN_HEIGHT / 2 + SCREEN_SCALE_Y(25.0f - timePassedSinceStart * 0.01f);
+ CFont::PrintString(SCREEN_WIDTH / 2, y, TheText.Get("KF_3"));
+ }
+ }
+ break;
+ }
+ default:
+ break;
}
}
-#endif
-void CDarkel::Init()
+void
+CDarkel::Init()
{
Status = KILLFRENZY_NONE;
}
-int16 CDarkel::QueryModelsKilledByPlayer(int32 modelId)
+uint16
+CDarkel::QueryModelsKilledByPlayer(int32 modelId)
{
return RegisteredKills[modelId];
}
-bool CDarkel::FrenzyOnGoing()
+bool
+CDarkel::FrenzyOnGoing()
{
return Status == KILLFRENZY_ONGOING;
}
-eKillFrenzyStatus CDarkel::ReadStatus()
+uint16
+CDarkel::ReadStatus()
{
return Status;
}
@@ -141,21 +176,24 @@ void CDarkel::RegisterKillByPlayer(CPed *victim, eWeaponType weapontype, bool he
}
#endif
-void CDarkel::RegisterKillNotByPlayer(CPed* victim, eWeaponType weapontype)
+void
+CDarkel::RegisterKillNotByPlayer(CPed* victim, eWeaponType weapontype)
{
- ++CStats::NumberKillFrenziesPassed;
+ ++CStats::PeopleKilledByOthers;
}
-void CDarkel::ResetModelsKilledByPlayer()
+void
+CDarkel::ResetModelsKilledByPlayer()
{
- for (int i = 0; i < 200; i++)
+ for (int i = 0; i < NUMDEFAULTMODELS; i++)
RegisteredKills[i] = 0;
}
#if 0
WRAPPER void CDarkel::ResetOnPlayerDeath() { EAXJMP(0x420E70); }
#else
-void CDarkel::ResetOnPlayerDeath()
+void
+CDarkel::ResetOnPlayerDeath()
{
if (Status != KILLFRENZY_ONGOING)
return;
@@ -164,48 +202,37 @@ void CDarkel::ResetOnPlayerDeath()
Status = KILLFRENZY_FAILED;
TimeOfFrenzyStart = CTimer::GetTimeInMilliseconds();
+ eWeaponType fixedWeapon;
if (WeaponType == WEAPONTYPE_UZI_DRIVEBY)
- WeaponType = WEAPONTYPE_UZI;
-
- if (WeaponType < WEAPONTYPE_TOTALWEAPONS) {
- FindPlayerPed()->m_nSelectedWepSlot = InterruptedWeapon;
- CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal = AmmoInterruptedWeapon;
- }
-
- if (FindPlayerVehicle()) {
- FindPlayerPed()->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(FindPlayerPed()->GetWeapon()->m_eWeaponType)->m_nModelId);
- FindPlayerPed()->m_currentWeapon = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_eWeaponType;
- FindPlayerPed()->MakeChangesForNewWeapon(FindPlayerPed()->m_currentWeapon);
- }
-
-
- CPopulation::m_AllRandomPedsThisType = -1;
- Status = KILLFRENZY_FAILED;
- TimeOfFrenzyStart = CTimer::GetTimeInMilliseconds();
-
- if (WeaponType == WEAPONTYPE_UZI_DRIVEBY)
- WeaponType = WEAPONTYPE_UZI;
+ fixedWeapon = WEAPONTYPE_UZI;
+ else
+ fixedWeapon = (eWeaponType)WeaponType;
- if (WeaponType < WEAPONTYPE_TOTALWEAPONS) {
- FindPlayerPed()->m_nSelectedWepSlot = InterruptedWeapon;
- CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal = AmmoInterruptedWeapon;
+ CPlayerPed *player = FindPlayerPed();
+ if (fixedWeapon < WEAPONTYPE_TOTALWEAPONS) {
+ player->m_nSelectedWepSlot = InterruptedWeapon;
+ player->GetWeapon(player->GetWeaponSlot(fixedWeapon)).m_nAmmoTotal = CDarkel::AmmoInterruptedWeapon;
}
if (FindPlayerVehicle()) {
- FindPlayerPed()->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(FindPlayerPed()->GetWeapon()->m_eWeaponType)->m_nModelId);
- FindPlayerPed()->m_currentWeapon = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_eWeaponType;
- FindPlayerPed()->MakeChangesForNewWeapon(FindPlayerPed()->m_currentWeapon);
+ player->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(player->GetWeapon()->m_eWeaponType)->m_nModelId);
+ player->m_currentWeapon = player->m_nSelectedWepSlot;
+ player->MakeChangesForNewWeapon(player->m_currentWeapon);
}
}
#endif
#if 0
-WRAPPER void CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, int16 kill, int32 modelId0, wchar *text, int32 modelId2, int32 modelId3, int32 modelId4, bool standardSound, bool needHeadShot) { EAXJMP(0x4210E0); }
+WRAPPER void CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, uint16 kill, int32 modelId0, wchar *text, int32 modelId2, int32 modelId3, int32 modelId4, bool standardSound, bool needHeadShot) { EAXJMP(0x4210E0); }
#else
-void CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, int16 kill, int32 modelId0, wchar *text, int32 modelId2, int32 modelId3, int32 modelId4, bool standardSound, bool needHeadShot)
+void
+CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, uint16 kill, int32 modelId0, wchar *text, int32 modelId2, int32 modelId3, int32 modelId4, bool standardSound, bool needHeadShot)
{
+ eWeaponType fixedWeapon;
if (weaponType == WEAPONTYPE_UZI_DRIVEBY)
- weaponType = WEAPONTYPE_UZI;
+ fixedWeapon = WEAPONTYPE_UZI;
+ else
+ fixedWeapon = weaponType;
WeaponType = weaponType;
Status = KILLFRENZY_ONGOING;
@@ -219,8 +246,7 @@ void CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, int16 kill, int32
if (text == TheText.Get("PAGE_00")) {
CDarkel::bProperKillFrenzy = 1;
CDarkel::pStartMessage = 0;
- }
- else
+ } else
bProperKillFrenzy = 0;
bStandardSoundAndMessages = standardSound;
@@ -229,20 +255,19 @@ void CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, int16 kill, int32
TimeLimit = time;
PreviousTime = time / 1000;
- if (weaponType < WEAPONTYPE_TOTALWEAPONS) {
- InterruptedWeapon = FindPlayerPed()->m_currentWeapon;
- FindPlayerPed()->GiveWeapon(weaponType, 0);
- AmmoInterruptedWeapon = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal;
- FindPlayerPed()->GiveWeapon(weaponType, 30000);
- FindPlayerPed()->m_nSelectedWepSlot = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_eWeaponType;
- FindPlayerPed()->MakeChangesForNewWeapon(FindPlayerPed()->m_nSelectedWepSlot);
+ CPlayerPed *player = FindPlayerPed();
+ if (fixedWeapon < WEAPONTYPE_TOTALWEAPONS) {
+ InterruptedWeapon = player->m_currentWeapon;
+ player->GiveWeapon(fixedWeapon, 0);
+ AmmoInterruptedWeapon = player->GetWeapon(player->GetWeaponSlot(fixedWeapon)).m_nAmmoTotal;
+ player->GiveWeapon(fixedWeapon, 30000);
+ player->m_nSelectedWepSlot = player->GetWeaponSlot(fixedWeapon);
+ player->MakeChangesForNewWeapon(player->m_nSelectedWepSlot);
if (FindPlayerVehicle()) {
- FindPlayerPed()->m_currentWeapon = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_eWeaponType;
- if (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal <= CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoInClip)
- CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoInClip = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal;
-
- FindPlayerPed()->ClearWeaponTarget();
+ player->m_currentWeapon = player->m_nSelectedWepSlot;
+ player->GetWeapon()->m_nAmmoInClip = min(player->GetWeapon()->m_nAmmoTotal, CWeaponInfo::GetWeaponInfo(player->GetWeapon()->m_eWeaponType)->m_nAmountofAmmunition);
+ player->ClearWeaponTarget();
}
}
if (CDarkel::bStandardSoundAndMessages)
@@ -250,13 +275,15 @@ void CDarkel::StartFrenzy(eWeaponType weaponType, int32 time, int16 kill, int32
}
#endif
-void CDarkel::Update()
+void
+CDarkel::Update()
{
if (Status != KILLFRENZY_ONGOING)
return;
int32 FrameTime = TimeLimit - (CTimer::GetTimeInMilliseconds() - TimeOfFrenzyStart);
if ((TimeLimit - (CTimer::GetTimeInMilliseconds() - TimeOfFrenzyStart)) > 0 || TimeLimit < 0) {
+
DMAudio.PlayFrontEndSound(SOUND_RAMPAGE_ONGOING, FrameTime);
int32 PrevTime = FrameTime / 1000;
@@ -267,24 +294,27 @@ void CDarkel::Update()
PreviousTime = PrevTime;
}
- }
- else {
+ } else {
CPopulation::m_AllRandomPedsThisType = -1;
Status = KILLFRENZY_FAILED;
TimeOfFrenzyStart = CTimer::GetTimeInMilliseconds();
+ eWeaponType fixedWeapon;
if (WeaponType == WEAPONTYPE_UZI_DRIVEBY)
- WeaponType = WEAPONTYPE_UZI;
+ fixedWeapon = WEAPONTYPE_UZI;
+ else
+ fixedWeapon = (eWeaponType)WeaponType;
- if (WeaponType < WEAPONTYPE_TOTALWEAPONS) {
- FindPlayerPed()->m_nSelectedWepSlot = InterruptedWeapon;
- CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal = AmmoInterruptedWeapon;
+ CPlayerPed *player = FindPlayerPed();
+ if (fixedWeapon < WEAPONTYPE_TOTALWEAPONS) {
+ player->m_nSelectedWepSlot = InterruptedWeapon;
+ player->GetWeapon(player->GetWeaponSlot(fixedWeapon)).m_nAmmoTotal = CDarkel::AmmoInterruptedWeapon;
}
if (FindPlayerVehicle()) {
- FindPlayerPed()->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(FindPlayerPed()->GetWeapon()->m_eWeaponType)->m_nModelId);
- FindPlayerPed()->m_currentWeapon = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_eWeaponType;
- FindPlayerPed()->MakeChangesForNewWeapon(FindPlayerPed()->m_currentWeapon);
+ player->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(player->GetWeapon()->m_eWeaponType)->m_nModelId);
+ player->m_currentWeapon = player->m_nSelectedWepSlot;
+ player->MakeChangesForNewWeapon(player->m_currentWeapon);
}
if (bStandardSoundAndMessages)
@@ -302,18 +332,22 @@ void CDarkel::Update()
FindPlayerPed()->m_pWanted->SetWantedLevel(0);
+ eWeaponType fixedWeapon;
if (WeaponType == WEAPONTYPE_UZI_DRIVEBY)
- WeaponType = WEAPONTYPE_UZI;
+ fixedWeapon = WEAPONTYPE_UZI;
+ else
+ fixedWeapon = (eWeaponType)WeaponType;
- if (WeaponType < WEAPONTYPE_TOTALWEAPONS) {
- FindPlayerPed()->m_nSelectedWepSlot = InterruptedWeapon;
- CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_nAmmoTotal = AmmoInterruptedWeapon;
+ CPlayerPed* player = FindPlayerPed();
+ if (fixedWeapon < WEAPONTYPE_TOTALWEAPONS) {
+ player->m_nSelectedWepSlot = InterruptedWeapon;
+ player->GetWeapon(player->GetWeaponSlot(fixedWeapon)).m_nAmmoTotal = CDarkel::AmmoInterruptedWeapon;
}
if (FindPlayerVehicle()) {
- FindPlayerPed()->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(FindPlayerPed()->GetWeapon()->m_eWeaponType)->m_nModelId);
- FindPlayerPed()->m_currentWeapon = CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_weapons[CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_currentWeapon].m_eWeaponType;
- FindPlayerPed()->MakeChangesForNewWeapon(FindPlayerPed()->m_currentWeapon);
+ player->RemoveWeaponModel(CWeaponInfo::GetWeaponInfo(player->GetWeapon()->m_eWeaponType)->m_nModelId);
+ player->m_currentWeapon = player->m_nSelectedWepSlot;
+ player->MakeChangesForNewWeapon(player->m_currentWeapon);
}
if (bStandardSoundAndMessages)
@@ -322,17 +356,17 @@ void CDarkel::Update()
}
STARTPATCHES
- /*InjectHook(0x421380, CDarkel::CalcFade, PATCH_JUMP);
- InjectHook(0x420920, CDarkel::DrawMessages, PATCH_JUMP);
- InjectHook(0x420E60, CDarkel::FrenzyOnGoing, PATCH_JUMP);
+ InjectHook(0x421380, CDarkel::CalcFade, PATCH_JUMP);
InjectHook(0x420650, CDarkel::Init, PATCH_JUMP);
- InjectHook(0x421370, CDarkel::QueryModelsKilledByPlayer, PATCH_JUMP);
+ InjectHook(0x420660, CDarkel::Update, PATCH_JUMP);
+ InjectHook(0x420E60, CDarkel::FrenzyOnGoing, PATCH_JUMP);
InjectHook(0x420E50, CDarkel::ReadStatus, PATCH_JUMP);
- InjectHook(0x421070, CDarkel::RegisterCarBlownUpByPlayer, PATCH_JUMP);
- InjectHook(0x420F60, CDarkel::RegisterKillByPlayer, PATCH_JUMP);
- InjectHook(0x421060, CDarkel::RegisterKillNotByPlayer, PATCH_JUMP);
- InjectHook(0x421310, CDarkel::ResetModelsKilledByPlayer, PATCH_JUMP);
InjectHook(0x420E70, CDarkel::ResetOnPlayerDeath, PATCH_JUMP);
InjectHook(0x4210E0, CDarkel::StartFrenzy, PATCH_JUMP);
- InjectHook(0x420660, CDarkel::Update, PATCH_JUMP);*/
+ InjectHook(0x421370, CDarkel::QueryModelsKilledByPlayer, PATCH_JUMP);
+ InjectHook(0x421060, CDarkel::RegisterKillNotByPlayer, PATCH_JUMP);
+ InjectHook(0x421310, CDarkel::ResetModelsKilledByPlayer, PATCH_JUMP);
+ InjectHook(0x420920, CDarkel::DrawMessages, PATCH_JUMP);
+ //InjectHook(0x421070, CDarkel::RegisterCarBlownUpByPlayer, PATCH_JUMP);
+ //InjectHook(0x420F60, CDarkel::RegisterKillByPlayer, PATCH_JUMP);
ENDPATCHES \ No newline at end of file
diff --git a/src/control/Darkel.h b/src/control/Darkel.h
index 77a14bb8..0171cd2c 100644
--- a/src/control/Darkel.h
+++ b/src/control/Darkel.h
@@ -26,7 +26,7 @@ private:
static int8 &bNeedHeadShot;
static int8 &bProperKillFrenzy;
static eKillFrenzyStatus &Status;
- static int16 *RegisteredKills;
+ static uint16 (&RegisteredKills)[NUMDEFAULTMODELS];
static int32 &ModelToKill;
static int32 &ModelToKill2;
static int32 &ModelToKill3;
@@ -34,18 +34,18 @@ private:
static wchar *pStartMessage;
public:
- static int32 CalcFade(uint32 time, int32 min, uint32 max);
+ static uint8 CalcFade(uint32 time, uint32 min, uint32 max);
static void DrawMessages(void);
static bool FrenzyOnGoing();
static void Init();
- static int16 QueryModelsKilledByPlayer(int32 modelId);
- static eKillFrenzyStatus ReadStatus();
+ static uint16 QueryModelsKilledByPlayer(int32 modelId);
+ static uint16 ReadStatus();
static void RegisterCarBlownUpByPlayer(CVehicle *vehicle);
static void RegisterKillByPlayer(CPed *victim, eWeaponType weapontype, bool headshot = false);
static void RegisterKillNotByPlayer(CPed* victim, eWeaponType weapontype);
static void ResetModelsKilledByPlayer();
static void ResetOnPlayerDeath();
- static void StartFrenzy(eWeaponType weaponType, int32 time, int16 kill, int32 modelId0, wchar *text, int32 modelId2, int32 modelId3, int32 modelId4, bool standardSound, bool needHeadShot);
+ static void StartFrenzy(eWeaponType weaponType, int32 time, uint16 kill, int32 modelId0, wchar *text, int32 modelId2, int32 modelId3, int32 modelId4, bool standardSound, bool needHeadShot);
static void Update();
};
diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp
index 0e9592dc..560a9c0c 100644
--- a/src/control/Garages.cpp
+++ b/src/control/Garages.cpp
@@ -69,7 +69,8 @@ bool CGarages::HasCarBeenCrushed(int32 handle)
}
WRAPPER void CGarages::TriggerMessage(const char *text, int16, uint16 time, int16) { EAXJMP(0x426B20); }
-WRAPPER bool CGarages::IsPointWithinHideOutGarage(CVector*) { EAXJMP(0x428260); }
+WRAPPER bool CGarages::IsPointWithinHideOutGarage(CVector&) { EAXJMP(0x428260); }
+WRAPPER bool CGarages::IsPointWithinAnyGarage(CVector&) { EAXJMP(0x428320); }
#if 0
WRAPPER void CGarages::PrintMessages(void) { EAXJMP(0x426310); }
diff --git a/src/control/Garages.h b/src/control/Garages.h
index 4c35fad1..cc5fb62b 100644
--- a/src/control/Garages.h
+++ b/src/control/Garages.h
@@ -25,5 +25,6 @@ public:
static void TriggerMessage(const char *text, int16, uint16 time, int16);
static void PrintMessages(void);
static bool HasCarBeenCrushed(int32);
- static bool IsPointWithinHideOutGarage(CVector*);
+ static bool IsPointWithinHideOutGarage(CVector&);
+ static bool IsPointWithinAnyGarage(CVector&);
};
diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp
index 81642a85..8a67e248 100644
--- a/src/control/Pickups.cpp
+++ b/src/control/Pickups.cpp
@@ -1,20 +1,1038 @@
-#include "common.h"
-#include "patcher.h"
-#include "Pickups.h"
-
-CPickup(&CPickups::aPickUps)[NUMPICKUPS] = *(CPickup(*)[NUMPICKUPS])*(uintptr*)0x878C98;
-
-// 20 ?! Some Miami leftover? (Originally at 0x5ED8D4)
-uint16 AmmoForWeapon[20] = { 0, 1, 45, 125, 25, 150, 300, 25, 5, 250, 5, 5, 0, 500, 0, 100, 0, 0, 0, 0 };
-uint16 AmmoForWeapon_OnStreet[20] = { 0, 1, 9, 25, 5, 30, 60, 5, 1, 50, 1, 1, 0, 200, 0, 100, 0, 0, 0, 0 };
-
-WRAPPER void CPickups::RenderPickUpText(void) { EAXJMP(0x432440); }
-WRAPPER void CPickups::DoCollectableEffects(CEntity *ent) { EAXJMP(0x431C30); }
-WRAPPER void CPickups::DoMoneyEffects(CEntity *ent) { EAXJMP(0x431F40); }
-WRAPPER void CPickups::DoMineEffects(CEntity *ent) { EAXJMP(0x4321C0); }
-WRAPPER void CPickups::DoPickUpEffects(CEntity *ent) { EAXJMP(0x431520); }
-WRAPPER void CPickups::RemoveAllFloatingPickups() { EAXJMP(0x430800); }
-WRAPPER int32 CPickups::GenerateNewOne(CVector, uint32, uint8, uint32) { EAXJMP(0x4304B0); }
-WRAPPER int32 CPickups::GenerateNewOne_WeaponType(CVector, eWeaponType, uint8, uint32) { EAXJMP(0x430660); }
-
-WRAPPER void CPacManPickups::Render(void) { EAXJMP(0x432F60); }
+#include "common.h"
+#include "patcher.h"
+#include "main.h"
+#include "Pickups.h"
+#include "Camera.h"
+#include "Entity.h"
+#include "Timer.h"
+#include "Shadows.h"
+#include "Coronas.h"
+#include "World.h"
+#include "ModelIndices.h"
+#include "PlayerPed.h"
+#include "Object.h"
+#include "Pools.h"
+#include "Pad.h"
+#include "Script.h"
+#include "Darkel.h"
+#include "Garages.h"
+#include "Explosion.h"
+#include "WaterLevel.h"
+#include "MoneyMessages.h"
+#include "PointLights.h"
+#include "Sprite.h"
+#include "Font.h"
+
+CPickup(&CPickups::aPickUps)[NUMPICKUPS] = *(CPickup(*)[NUMPICKUPS])*(uintptr*)0x878C98;
+int16 CPickups::NumMessages;// = *(int16*)0x95CC98;
+int32 CPickups::aPickUpsCollected[NUMCOLLECTEDPICKUPS];// = *(int32(*)[NUMCOLLECTEDPICKUPS])*(uintptr*)0x87C538;
+int16 CPickups::CollectedPickUpIndex;// = *(int16*)0x95CC8A;
+
+// unused
+bool &CPickups::bPickUpcamActivated = *(bool*)0x95CD71;
+CVehicle *&CPickups::pPlayerVehicle = *(CVehicle**)0x8F29E8;
+CVector &CPickups::StaticCamCoors = *(CVector*)0x9404C8;
+uint32 &CPickups::StaticCamStartTime = *(uint32*)0x8E289C;
+
+tPickupMessage CPickups::aMessages[NUMPICKUPMESSAGES];
+
+// 20 ?! Some Miami leftover? (Originally at 0x5ED8D4)
+uint16 AmmoForWeapon[20] = { 0, 1, 45, 125, 25, 150, 300, 25, 5, 250, 5, 5, 0, 500, 0, 100, 0, 0, 0, 0 };
+uint16 AmmoForWeapon_OnStreet[20] = { 0, 1, 9, 25, 5, 30, 60, 5, 1, 50, 1, 1, 0, 200, 0, 100, 0, 0, 0, 0 };
+uint16 CostOfWeapon[20] = { 0, 10, 250, 800, 1500, 3000, 5000, 10000, 25000, 25000, 2000, 2000, 0, 50000, 0, 3000, 0, 0, 0, 0 };
+
+uint8 aWeaponReds[] = { 255, 0, 128, 255, 255, 0, 255, 0, 128, 128, 255, 0255, 128, 0, 255, 0 };
+uint8 aWeaponGreens[] = { 0, 255, 128, 255, 0, 255, 128, 255, 0, 255, 255, 0, 255, 0, 255, 0 };
+uint8 aWeaponBlues[] = { 0, 0, 255, 0, 255, 255, 0, 128, 255, 0, 255, 0, 128, 255, 0, 0 };
+float aWeaponScale[] = { 1.0f, 2.0f, 1.5f, 1.0f, 1.0f, 1.5f, 1.0f, 2.0f, 1.0f, 2.0f, 2.5f, 1.0f, 1.0f, 1.0f, 1.0f };
+
+WRAPPER void CPacManPickups::Render(void) { EAXJMP(0x432F60); }
+
+
+void
+CPickup::RemoveKeepType()
+{
+ CWorld::Remove(m_pObject);
+ delete m_pObject;
+
+ m_bRemoved = true;
+ m_pObject = nil;
+}
+
+void
+CPickup::Remove()
+{
+ RemoveKeepType();
+ m_eType = PICKUP_NONE;
+}
+
+CObject *
+CPickup::GiveUsAPickUpObject(int32 handle)
+{
+ CObject *object;
+
+ if (handle <= 0) object = new CObject(m_eModelIndex, false);
+ else {
+ CPools::MakeSureSlotInObjectPoolIsEmpty(handle);
+ object = new(handle) CObject(m_eModelIndex, false);
+ }
+
+ if (object == nil) return nil;
+ object->ObjectCreatedBy = MISSION_OBJECT;
+ object->GetPosition() = m_vecPos;
+ object->SetOrientation(0.0f, 0.0f, -HALFPI);
+ object->GetMatrix().UpdateRW();
+ object->UpdateRwFrame();
+
+ object->bAffectedByGravity = false;
+ object->bExplosionProof = true;
+ object->bUsesCollision = false;
+ object->bIsPickup = true;
+
+ object->field_172 = m_eModelIndex == MI_PICKUP_BONUS ? m_nQuantity : 0;
+
+ switch (m_eType)
+ {
+ case PICKUP_IN_SHOP:
+ object->m_obj_flag2 = true;
+ object->bOutOfStock = false;
+ break;
+ case PICKUP_ON_STREET:
+ case PICKUP_ONCE:
+ case PICKUP_ONCE_TIMEOUT:
+ case PICKUP_COLLECTABLE1:
+ case PICKUP_MONEY:
+ case PICKUP_MINE_INACTIVE:
+ case PICKUP_MINE_ARMED:
+ case PICKUP_NAUTICAL_MINE_INACTIVE:
+ case PICKUP_NAUTICAL_MINE_ARMED:
+ case PICKUP_FLOATINGPACKAGE:
+ case PICKUP_ON_STREET_SLOW:
+ object->m_obj_flag2 = false;
+ object->bOutOfStock = false;
+ break;
+ case PICKUP_IN_SHOP_OUT_OF_STOCK:
+ object->m_obj_flag2 = false;
+ object->bOutOfStock = true;
+ object->bRenderScorched = true;
+ break;
+ case PICKUP_FLOATINGPACKAGE_FLOATING:
+ default:
+ break;
+ }
+ return object;
+}
+
+bool
+CPickup::CanBePickedUp(CPlayerPed *player)
+{
+ assert(m_pObject != nil);
+ bool cannotBePickedUp =
+ (m_pObject->GetModelIndex() == MI_PICKUP_BODYARMOUR && player->m_fArmour > 99.5f)
+ || (m_pObject->GetModelIndex() == MI_PICKUP_HEALTH && player->m_fHealth > 99.5f)
+ || (m_pObject->GetModelIndex() == MI_PICKUP_BRIBE && player->m_pWanted->m_nWantedLevel == 0)
+ || (m_pObject->GetModelIndex() == MI_PICKUP_KILLFRENZY && (CTheScripts::IsPlayerOnAMission() || CDarkel::FrenzyOnGoing() || !CGame::nastyGame));
+ return !cannotBePickedUp;
+}
+
+bool
+CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId)
+{
+ float waterLevel;
+
+ if (m_bRemoved) {
+ if (CTimer::GetTimeInMilliseconds() > m_nTimer) {
+ // respawn pickup if we're far enough
+ float dist = (FindPlayerCoors().x - m_vecPos.x) * (FindPlayerCoors().x - m_vecPos.x) + (FindPlayerCoors().y - m_vecPos.y) * (FindPlayerCoors().y - m_vecPos.y);
+ if (dist > 100.0f || m_eType == PICKUP_IN_SHOP && dist > 2.4f) {
+ m_pObject = GiveUsAPickUpObject(-1);
+ if (m_pObject) {
+ CWorld::Add(m_pObject);
+ m_bRemoved = false;
+ }
+ }
+ }
+ return false;
+ }
+
+ if (!m_pObject) return false;
+
+ if (!IsMine()) {
+ // let's check if we touched the pickup
+ bool isPickupTouched = false;
+ if (m_pObject->GetModelIndex() == MI_PICKUP_BRIBE) {
+ if (vehicle != nil) {
+ if (vehicle->IsSphereTouchingVehicle(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z, 2.0f))
+ isPickupTouched = true;
+ }
+ else {
+ if (Abs(player->GetPosition().z - m_pObject->GetPosition().z) < 2.0f) {
+ if ((player->GetPosition().x - m_pObject->GetPosition().x) * (player->GetPosition().x - m_pObject->GetPosition().x) +
+ (player->GetPosition().y - m_pObject->GetPosition().y) * (player->GetPosition().y - m_pObject->GetPosition().y) < 1.8f)
+ isPickupTouched = true;
+ }
+ }
+ } else if (m_pObject->GetModelIndex() == MI_PICKUP_CAMERA) {
+ if (vehicle != nil && vehicle->IsSphereTouchingVehicle(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z, 2.0f)) {
+ isPickupTouched = true;
+ }
+ } else if (vehicle == nil) {
+ if (Abs(player->GetPosition().z - m_pObject->GetPosition().z) < 2.0f) {
+ if ((player->GetPosition().x - m_pObject->GetPosition().x) * (player->GetPosition().x - m_pObject->GetPosition().x) +
+ (player->GetPosition().y - m_pObject->GetPosition().y) * (player->GetPosition().y - m_pObject->GetPosition().y) < 1.8f)
+ isPickupTouched = true;
+ }
+ }
+
+ // if we didn't then we've got nothing to do
+ if (isPickupTouched && CanBePickedUp(player)) {
+ CPad::GetPad(0)->StartShake(120, 100);
+ switch (m_eType)
+ {
+ case PICKUP_IN_SHOP:
+ if (CWorld::Players[playerId].m_nMoney < CostOfWeapon[CPickups::WeaponForModel(m_pObject->GetModelIndex())]) {
+ CGarages::TriggerMessage("PU_MONY", -1, 6000, -1);
+ } else {
+ CWorld::Players[playerId].m_nMoney -= CostOfWeapon[CPickups::WeaponForModel(m_pObject->GetModelIndex())];
+ if (!CPickups::GivePlayerGoodiesWithPickUpMI(m_pObject->GetModelIndex(), playerId)) {
+ player->GiveWeapon(CPickups::WeaponForModel(m_pObject->GetModelIndex()), AmmoForWeapon[CPickups::WeaponForModel(m_pObject->GetModelIndex())]);
+ player->m_nSelectedWepSlot = player->GetWeaponSlot(CPickups::WeaponForModel(m_pObject->GetModelIndex()));
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_WEAPON_BOUGHT, m_pObject->GetModelIndex() - MI_GRENADE);
+ }
+ RemoveKeepType();
+ m_nTimer = CTimer::GetTimeInMilliseconds() + 5000;
+ return true;
+ }
+ break;
+ case PICKUP_ON_STREET:
+ case PICKUP_ON_STREET_SLOW:
+ if (!CPickups::GivePlayerGoodiesWithPickUpMI(m_pObject->GetModelIndex(), playerId)) {
+ if (CPickups::WeaponForModel(m_pObject->GetModelIndex())) {
+ player->GiveWeapon(CPickups::WeaponForModel(m_pObject->GetModelIndex()), m_nQuantity != 0 ? m_nQuantity : AmmoForWeapon_OnStreet[CPickups::WeaponForModel(m_pObject->GetModelIndex())]);
+ if (player->m_nSelectedWepSlot == player->GetWeaponSlot(WEAPONTYPE_UNARMED)) {
+ player->m_nSelectedWepSlot = player->GetWeaponSlot(CPickups::WeaponForModel(m_pObject->GetModelIndex()));
+ }
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_WEAPON, m_pObject->GetModelIndex() - MI_GRENADE);
+ } else if (m_pObject->GetModelIndex() == MI_PICKUP_CAMERA && vehicle != nil) {
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0);
+ CPickups::bPickUpcamActivated = true;
+ CPickups::pPlayerVehicle = FindPlayerVehicle();
+ CPickups::StaticCamCoors = m_pObject->GetPosition();
+ CPickups::StaticCamStartTime = CTimer::GetTimeInMilliseconds();
+ }
+ }
+ if (m_eType == PICKUP_ON_STREET) {
+ m_nTimer = CTimer::GetTimeInMilliseconds() + 30000;
+ } else if (m_eType == PICKUP_ON_STREET_SLOW) {
+ if (MI_PICKUP_BRIBE == m_pObject->m_modelIndex)
+ m_nTimer = CTimer::GetTimeInMilliseconds() + 300000;
+ else
+ m_nTimer = CTimer::GetTimeInMilliseconds() + 720000;
+ }
+
+ RemoveKeepType();
+ return true;
+ case PICKUP_ONCE:
+ case PICKUP_ONCE_TIMEOUT:
+ if (!CPickups::GivePlayerGoodiesWithPickUpMI(m_pObject->GetModelIndex(), playerId)) {
+ if (CPickups::WeaponForModel(m_pObject->GetModelIndex())) {
+ player->GiveWeapon(CPickups::WeaponForModel(m_pObject->GetModelIndex()), m_nQuantity != 0 ? m_nQuantity : AmmoForWeapon[CPickups::WeaponForModel(m_pObject->GetModelIndex())]);
+ if (player->m_nSelectedWepSlot == player->GetWeaponSlot(WEAPONTYPE_UNARMED))
+ player->m_nSelectedWepSlot = player->GetWeaponSlot(CPickups::WeaponForModel(m_pObject->GetModelIndex()));
+ }
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_WEAPON, m_pObject->GetModelIndex() - MI_GRENADE);
+ }
+ Remove();
+ return true;
+ case PICKUP_COLLECTABLE1:
+ CWorld::Players[playerId].m_nCollectedPackages++;
+ CWorld::Players[playerId].m_nMoney += 1000;
+
+ if (CWorld::Players[playerId].m_nCollectedPackages == CWorld::Players[playerId].m_nTotalPackages) {
+ printf("All collectables have been picked up\n");
+ CGarages::TriggerMessage("CO_ALL", -1, 5000, -1);
+ CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 1000000;
+ } else
+ CGarages::TriggerMessage("CO_ONE", CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages, 5000, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages);
+
+ Remove();
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_HIDDEN_PACKAGE, 0);
+ return true;
+ case PICKUP_MONEY:
+ CWorld::Players[playerId].m_nMoney += m_nQuantity;
+ sprintf(gString, "$%d", m_nQuantity);
+#ifdef MONEY_MESSAGES
+ CMoneyMessages::RegisterOne(m_vecPos + CVector(0.0f, 0.0f, 1.0f), gString, 0, 255, 0, 0.5f, 0.5f);
+#endif
+ Remove();
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_MONEY, 0);
+ return true;
+ //case PICKUP_IN_SHOP_OUT_OF_STOCK:
+ //case PICKUP_MINE_INACTIVE:
+ //case PICKUP_MINE_ARMED:
+ //case PICKUP_NAUTICAL_MINE_INACTIVE:
+ //case PICKUP_NAUTICAL_MINE_ARMED:
+ //case PICKUP_FLOATINGPACKAGE:
+ //case PICKUP_FLOATINGPACKAGE_FLOATING:
+ default:
+ break;
+ }
+ }
+ } else {
+ switch (m_eType)
+ {
+ case PICKUP_MINE_INACTIVE:
+ if (vehicle != nil && !vehicle->IsSphereTouchingVehicle(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z, 2.0f)) {
+ m_eType = PICKUP_MINE_ARMED;
+ m_nTimer = CTimer::GetTimeInMilliseconds() + 10000;
+ }
+ break;
+ case PICKUP_NAUTICAL_MINE_INACTIVE:
+ {
+ if (CWaterLevel::GetWaterLevel(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z + 5.0f, &waterLevel, false))
+ m_pObject->GetPosition().z = waterLevel + 0.6f;
+
+ m_pObject->GetMatrix().UpdateRW();
+ m_pObject->UpdateRwFrame();
+
+ bool touched = false;
+ for (int32 i = CPools::GetVehiclePool()->GetSize(); i > 0; i--) { // TODO: check if i > 0 is not a R* mistake
+ CVehicle *vehicle = CPools::GetVehiclePool()->GetSlot(i);
+ if (vehicle != nil && vehicle->IsSphereTouchingVehicle(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z, 1.5f)) {
+ touched = true;
+ break; // added break here
+ }
+ }
+
+ if (!touched) {
+ m_eType = PICKUP_NAUTICAL_MINE_ARMED;
+ m_nTimer = CTimer::GetTimeInMilliseconds() + 10000;
+ }
+ break;
+ }
+ case PICKUP_NAUTICAL_MINE_ARMED:
+ if (CWaterLevel::GetWaterLevel(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z + 5.0f, &waterLevel, false))
+ m_pObject->GetPosition().z = waterLevel + 0.6f;
+
+ m_pObject->GetMatrix().UpdateRW();
+ m_pObject->UpdateRwFrame();
+ // no break here
+ case PICKUP_MINE_ARMED:
+ {
+ bool explode = false;
+ if (CTimer::GetTimeInMilliseconds() > m_nTimer)
+ explode = true;
+ else {// added else here since vehicle lookup is useless
+ for (int32 i = CPools::GetVehiclePool()->GetSize(); i > 0; i--) { // TODO: check if i > 0 is not a R* mistake
+ CVehicle *vehicle = CPools::GetVehiclePool()->GetSlot(i);
+ if (vehicle != nil && vehicle->IsSphereTouchingVehicle(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z, 1.5f)) {
+ explode = true;
+ break; // added break here
+ }
+ }
+ }
+ if (explode) {
+ CExplosion::AddExplosion(nil, nil, EXPLOSION_MINE, m_pObject->GetPosition(), 0);
+ Remove();
+ }
+ break;
+ }
+ case PICKUP_FLOATINGPACKAGE:
+ m_pObject->m_vecMoveSpeed.z -= 0.01f * CTimer::GetTimeStep();
+ m_pObject->GetPosition() += m_pObject->GetMoveSpeed() * CTimer::GetTimeStep();
+
+ m_pObject->GetMatrix().UpdateRW();
+ m_pObject->UpdateRwFrame();
+ if (CWaterLevel::GetWaterLevel(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z + 5.0f, &waterLevel, 0) && waterLevel >= m_pObject->GetPosition().z)
+ m_eType = PICKUP_FLOATINGPACKAGE_FLOATING;
+ break;
+ case PICKUP_FLOATINGPACKAGE_FLOATING:
+ if (CWaterLevel::GetWaterLevel(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z + 5.0f, &waterLevel, 0))
+ m_pObject->GetPosition().z = waterLevel;
+
+ m_pObject->GetMatrix().UpdateRW();
+ m_pObject->UpdateRwFrame();
+ if (vehicle != nil && vehicle->IsSphereTouchingVehicle(m_pObject->GetPosition().x, m_pObject->GetPosition().y, m_pObject->GetPosition().z, 2.0f)) {
+ Remove();
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_FLOAT_PACKAGE, 0);
+ }
+ break;
+ }
+ }
+ if (!m_bRemoved && (m_eType == PICKUP_ONCE_TIMEOUT || m_eType == PICKUP_MONEY) && CTimer::GetTimeInMilliseconds() > m_nTimer)
+ Remove();
+ return false;
+}
+
+void
+CPickups::Init(void)
+{
+ NumMessages = 0;
+ for (int i = 0; i < NUMPICKUPS; i++) {
+ aPickUps[i].m_eType = PICKUP_NONE;
+ aPickUps[i].m_nIndex = 1;
+ aPickUps[i].m_pObject = nil;
+ }
+
+ for (int i = 0; i < NUMCOLLECTEDPICKUPS; i++)
+ aPickUpsCollected[i] = 0;
+
+ CollectedPickUpIndex = 0;
+}
+
+bool
+CPickups::IsPickUpPickedUp(int32 pickupId)
+{
+ for (int i = 0; i < NUMCOLLECTEDPICKUPS; i++) {
+ if (pickupId == aPickUpsCollected[i]) {
+ aPickUpsCollected[i] = 0;
+ return true;
+ }
+ }
+ return false;
+}
+
+void
+CPickups::PassTime(uint32 time)
+{
+ for (int i = 0; i < NUMPICKUPS; i++) {
+ if (aPickUps[i].m_eType != PICKUP_NONE) {
+ if (aPickUps[i].m_nTimer <= time)
+ aPickUps[i].m_nTimer = 0;
+ else
+ aPickUps[i].m_nTimer -= time;
+ }
+ }
+}
+
+int32
+CPickups::GetActualPickupIndex(int32 index)
+{
+ if (index == -1) return -1;
+
+ // doesn't look nice
+ if ((uint16)((index & 0xFFFF0000) >> 16) != aPickUps[(uint16)index].m_nIndex) return -1;
+ return (uint16)index;
+}
+
+bool
+CPickups::GivePlayerGoodiesWithPickUpMI(int16 modelIndex, int playerIndex)
+{
+ CPlayerPed *player;
+
+ if (playerIndex <= 0) player = CWorld::Players[CWorld::PlayerInFocus].m_pPed;
+ else player = CWorld::Players[playerIndex].m_pPed;
+
+ if (modelIndex == MI_PICKUP_ADRENALINE) {
+ player->m_bAdrenalineActive = true;
+ player->m_nAdrenalineTime = CTimer::GetTimeInMilliseconds() + 20000;
+ player->m_fCurrentStamina = player->m_fMaxStamina;
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_ADRENALINE, 0);
+ return true;
+ } else if (modelIndex == MI_PICKUP_BODYARMOUR) {
+ player->m_fArmour = 100.0f;
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_ARMOUR, 0);
+ return true;
+ } else if (modelIndex == MI_PICKUP_INFO) {
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0);
+ return true;
+ } else if (modelIndex == MI_PICKUP_HEALTH) {
+ player->m_fHealth = 100.0f;
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_HEALTH, 0);
+ return true;
+ } else if (modelIndex == MI_PICKUP_BONUS) {
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0);
+ return true;
+ } else if (modelIndex == MI_PICKUP_BRIBE) {
+ int32 level = FindPlayerPed()->m_pWanted->m_nWantedLevel - 1;
+ if (level < 0) level = 0;
+ player->SetWantedLevel(level);
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0);
+ return true;
+ } else if (modelIndex == MI_PICKUP_KILLFRENZY) {
+ DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0);
+ return true;
+ }
+ return false;
+}
+
+void
+CPickups::RemoveAllFloatingPickups()
+{
+ for (int i = 0; i < NUMPICKUPS; i++) {
+ if (aPickUps[i].m_eType == PICKUP_FLOATINGPACKAGE || aPickUps[i].m_eType == PICKUP_FLOATINGPACKAGE_FLOATING) {
+ if (aPickUps[i].m_pObject) {
+ CWorld::Remove(aPickUps[i].m_pObject);
+ delete aPickUps[i].m_pObject;
+ aPickUps[i].m_pObject = nil;
+ }
+ }
+ }
+}
+
+void
+CPickups::RemovePickUp(int32 pickupIndex)
+{
+ int32 index = CPickups::GetActualPickupIndex(pickupIndex);
+ if (index == -1) return;
+
+ if (aPickUps[index].m_pObject) {
+ CWorld::Remove(aPickUps[index].m_pObject);
+ delete aPickUps[index].m_pObject;
+ aPickUps[index].m_pObject = nil;
+ }
+ aPickUps[index].m_eType = PICKUP_NONE;
+ aPickUps[index].m_bRemoved = true;
+}
+
+int32
+CPickups::GenerateNewOne(CVector pos, uint32 modelIndex, uint8 type, uint32 quantity)
+{
+ bool bFreeFound = false;
+ int32 slot = 0;
+
+ if (type == PICKUP_FLOATINGPACKAGE || type == PICKUP_NAUTICAL_MINE_INACTIVE) {
+ for (slot = NUMPICKUPS; slot >= 0; slot--) {
+ if (aPickUps[slot].m_eType == PICKUP_NONE) {
+ bFreeFound = true;
+ break;
+ }
+ }
+ } else {
+ for (slot = 0; slot < NUMGENERALPICKUPS; slot++) {
+ if (aPickUps[slot].m_eType == PICKUP_NONE) {
+ bFreeFound = true;
+ break;
+ }
+ }
+ }
+
+ if (!bFreeFound)
+ {
+ for (slot = 0; slot < NUMGENERALPICKUPS; slot++) {
+ if (aPickUps[slot].m_eType == PICKUP_MONEY) break;
+ }
+
+ if (slot >= NUMGENERALPICKUPS)
+ {
+ for (slot = 0; slot < NUMGENERALPICKUPS; slot++) {
+ if (aPickUps[slot].m_eType == PICKUP_ONCE_TIMEOUT) break;
+ }
+
+ if (slot >= NUMGENERALPICKUPS) return -1;
+ }
+ }
+
+ if (slot >= NUMPICKUPS) return -1;
+
+ aPickUps[slot].m_eType = (ePickupType)type;
+ aPickUps[slot].m_bRemoved = false;
+ aPickUps[slot].m_nQuantity = quantity;
+ if (type == PICKUP_ONCE_TIMEOUT)
+ aPickUps[slot].m_nTimer = CTimer::GetTimeInMilliseconds() + 20000;
+ else if (type == PICKUP_MONEY)
+ aPickUps[slot].m_nTimer = CTimer::GetTimeInMilliseconds() + 30000;
+ else if (type == PICKUP_MINE_INACTIVE || type == PICKUP_MINE_ARMED) {
+ aPickUps[slot].m_eType = PICKUP_MINE_INACTIVE;
+ aPickUps[slot].m_nTimer = CTimer::GetTimeInMilliseconds() + 1500;
+ } else if (type == PICKUP_NAUTICAL_MINE_INACTIVE || type == PICKUP_NAUTICAL_MINE_ARMED) {
+ aPickUps[slot].m_eType = PICKUP_NAUTICAL_MINE_INACTIVE;
+ aPickUps[slot].m_nTimer = CTimer::GetTimeInMilliseconds() + 1500;
+ }
+ aPickUps[slot].m_eModelIndex = modelIndex;
+ aPickUps[slot].m_vecPos = pos;
+ aPickUps[slot].m_pObject = aPickUps[slot].GiveUsAPickUpObject(-1);
+ if (aPickUps[slot].m_pObject)
+ CWorld::Add(aPickUps[slot].m_pObject);
+ return GetNewUniquePickupIndex(slot);
+}
+
+int32
+CPickups::GenerateNewOne_WeaponType(CVector pos, eWeaponType weaponType, uint8 type, uint32 quantity)
+{
+ return GenerateNewOne(pos, ModelForWeapon(weaponType), type, quantity);
+}
+
+int32
+CPickups::GetNewUniquePickupIndex(int32 slot)
+{
+ if (aPickUps[slot].m_nIndex >= 0xFFFE)
+ aPickUps[slot].m_nIndex = 1;
+ else
+ aPickUps[slot].m_nIndex++;
+ return slot | (aPickUps[slot].m_nIndex << 16);
+}
+
+int32
+CPickups::ModelForWeapon(eWeaponType weaponType)
+{
+ switch (weaponType)
+ {
+ case WEAPONTYPE_BASEBALLBAT: return MI_BASEBALL_BAT;
+ case WEAPONTYPE_COLT45: return MI_COLT;
+ case WEAPONTYPE_UZI: return MI_UZI;
+ case WEAPONTYPE_SHOTGUN: return MI_SHOTGUN;
+ case WEAPONTYPE_AK47: return MI_AK47;
+ case WEAPONTYPE_M16: return MI_M16;
+ case WEAPONTYPE_SNIPERRIFLE: return MI_SNIPER;
+ case WEAPONTYPE_ROCKETLAUNCHER: return MI_ROCKETLAUNCHER;
+ case WEAPONTYPE_FLAMETHROWER: return MI_FLAMETHROWER;
+ case WEAPONTYPE_MOLOTOV: return MI_MOLOTOV;
+ case WEAPONTYPE_GRENADE: return MI_GRENADE;
+ }
+ return 0;
+}
+
+eWeaponType
+CPickups::WeaponForModel(int32 model)
+{
+ if (model == MI_PICKUP_BODYARMOUR) return WEAPONTYPE_ARMOUR;
+ switch (model)
+ {
+ case MI_GRENADE: return WEAPONTYPE_GRENADE;
+ case MI_AK47: return WEAPONTYPE_AK47;
+ case MI_BASEBALL_BAT: return WEAPONTYPE_BASEBALLBAT;
+ case MI_COLT: return WEAPONTYPE_COLT45;
+ case MI_MOLOTOV: return WEAPONTYPE_MOLOTOV;
+ case MI_ROCKETLAUNCHER: return WEAPONTYPE_ROCKETLAUNCHER;
+ case MI_SHOTGUN: return WEAPONTYPE_SHOTGUN;
+ case MI_SNIPER: return WEAPONTYPE_SNIPERRIFLE;
+ case MI_UZI: return WEAPONTYPE_UZI;
+ case MI_MISSILE: return WEAPONTYPE_UNARMED;
+ case MI_M16: return WEAPONTYPE_M16;
+ case MI_FLAMETHROWER: return WEAPONTYPE_FLAMETHROWER;
+ }
+ return WEAPONTYPE_UNARMED;
+}
+
+int32
+CPickups::FindColourIndexForWeaponMI(int32 model)
+{
+ return WeaponForModel(model) - 1;
+}
+
+void
+CPickups::AddToCollectedPickupsArray(int32 index)
+{
+ aPickUpsCollected[CollectedPickUpIndex++] = index | (aPickUps[index].m_nIndex << 16);
+ if (CollectedPickUpIndex >= NUMCOLLECTEDPICKUPS)
+ CollectedPickUpIndex = 0;
+}
+
+void
+CPickups::Update()
+{
+#ifndef FIX_BUGS
+ // BUG: this code can only reach 318 out of 320 pickups
+#define PICKUPS_FRAME_SPAN (6)
+#define PICKUPS_PER_FRAME (NUMGENERALPICKUPS/PICKUPS_FRAME_SPAN)
+
+ for (uint32 i = PICKUPS_PER_FRAME * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN); i < PICKUPS_PER_FRAME * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN + 1); i++) {
+ if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].Update(FindPlayerPed(), FindPlayerVehicle(), CWorld::PlayerInFocus)) {
+ AddToCollectedPickupsArray(i);
+ }
+ }
+
+ for (uint32 i = NUMGENERALPICKUPS; i < NUMPICKUPS; i++) {
+ if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].Update(FindPlayerPed(), FindPlayerVehicle(), CWorld::PlayerInFocus)) {
+ AddToCollectedPickupsArray(i);
+ }
+ }
+
+#undef PICKUPS_FRAME_SPAN
+#undef PICKUPS_PER_FRAME
+#else
+ for (uint32 i = 0; i < NUMPICKUPS; i++) {
+ if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].Update(FindPlayerPed(), FindPlayerVehicle(), CWorld::PlayerInFocus)) {
+ AddToCollectedPickupsArray(i);
+ }
+ }
+#endif
+}
+
+void
+CPickups::DoPickUpEffects(CEntity *entity)
+{
+ if (entity->GetModelIndex() == MI_PICKUP_KILLFRENZY)
+ entity->m_flagD80 = CTheScripts::IsPlayerOnAMission() || CDarkel::FrenzyOnGoing() || !CGame::nastyGame;
+
+ if (!entity->m_flagD80) {
+ float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800));
+ float modifiedSin = 0.3 * (s + 1.0f);
+
+
+ int16 colorId;
+
+ if (entity->GetModelIndex() == MI_PICKUP_ADRENALINE || entity->GetModelIndex() == MI_PICKUP_CAMERA)
+ colorId = 11;
+ else if (entity->GetModelIndex() == MI_PICKUP_BODYARMOUR || entity->GetModelIndex() == MI_PICKUP_BRIBE)
+ colorId = 12;
+ else if (entity->GetModelIndex() == MI_PICKUP_INFO || entity->GetModelIndex() == MI_PICKUP_KILLFRENZY)
+ colorId = 13;
+ else if (entity->GetModelIndex() == MI_PICKUP_HEALTH || entity->GetModelIndex() == MI_PICKUP_BONUS)
+ colorId = 14;
+ else
+ colorId = FindColourIndexForWeaponMI(entity->GetModelIndex());
+
+ assert(colorId >= 0);
+
+ CVector &pos = entity->GetPosition();
+
+ float colorModifier = ((double)(rand() & 0x1F) * 0.015f + 1.0f) * modifiedSin * 0.15f;
+ CShadows::StoreStaticShadow(
+ (uintptr)entity,
+ SHADOWTYPE_ADDITIVE,
+ gpShadowExplosionTex,
+ &pos,
+ 2.0f, 0.0f, 0.0f, -2.0f,
+ 255, // this is 0 on PC which results in no shadow
+ aWeaponReds[colorId] * colorModifier, aWeaponGreens[colorId] * colorModifier, aWeaponBlues[colorId] * colorModifier,
+ 4.0f, 1.0f, 40.0f, false, 0.0f);
+
+ float radius = (double)(rand() & 0xF) * 0.1 + 3.0;
+ CPointLights::AddLight(CPointLights::LIGHT_POINT, pos, CVector(0.0f, 0.0f, 0.0f), radius, aWeaponReds[colorId] * modifiedSin / 256.0f, aWeaponGreens[colorId] * modifiedSin / 256.0f, aWeaponBlues[colorId] * modifiedSin / 256.0f, CPointLights::FOG_NONE, true);
+ float size = (double)(rand() & 0xF) * 0.0005 + 0.6;
+ CCoronas::RegisterCorona( (uintptr)entity,
+ aWeaponReds[colorId] * modifiedSin / 2.0f, aWeaponGreens[colorId] * modifiedSin / 2.0f, aWeaponBlues[colorId] * modifiedSin / 2.0f,
+ 255,
+ pos,
+ size, 65.0f, CCoronas::TYPE_RING, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
+
+ CObject *object = (CObject*)entity;
+ if (object->m_obj_flag2 || object->bOutOfStock || object->field_172) {
+ float dist = (TheCamera.GetPosition() - pos).Magnitude();
+ const float MAXDIST = 12.0f;
+
+ if (dist < MAXDIST && NumMessages < NUMPICKUPMESSAGES) {
+ RwV3d vecOut;
+ float fDistX, fDistY;
+ if (CSprite::CalcScreenCoors(entity->GetPosition() + CVector(0.0f, 0.0f, 0.7f), &vecOut, &fDistX, &fDistY, true)) {
+ aMessages[NumMessages].m_pos.x = vecOut.x;
+ aMessages[NumMessages].m_pos.y = vecOut.y;
+ aMessages[NumMessages].m_dist.x = fDistX;
+ aMessages[NumMessages].m_dist.y = fDistY;
+ aMessages[NumMessages].m_weaponType = WeaponForModel(entity->GetModelIndex());
+ aMessages[NumMessages].m_color.red = aWeaponReds[colorId];
+ aMessages[NumMessages].m_color.green = aWeaponGreens[colorId];
+ aMessages[NumMessages].m_color.blue = aWeaponBlues[colorId];
+ aMessages[NumMessages].m_color.alpha = (1.0f - dist / MAXDIST) * 128.0f;
+ aMessages[NumMessages].m_bOutOfStock = object->bOutOfStock;
+ aMessages[NumMessages].m_quantity = object->field_172;
+ NumMessages++;
+ }
+ }
+ }
+
+ entity->GetMatrix().SetRotateZOnlyScaled((float)(CTimer::GetTimeInMilliseconds() & 0x7FF) * DEGTORAD(360.0f / 0x800), aWeaponScale[colorId]);
+ }
+}
+
+void
+CPickups::DoMineEffects(CEntity *entity)
+{
+ CVector &pos = entity->GetPosition();
+ float dist = (TheCamera.GetPosition() - pos).Magnitude();
+ const float MAXDIST = 20.0f;
+
+ if (dist < MAXDIST) {
+ float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x1FF) * DEGTORAD(360.0f / 0x200));
+
+ int32 red = (MAXDIST - dist) * (0.5f * s + 0.5f) / MAXDIST * 64.0f;
+ CShadows::StoreStaticShadow((uintptr)entity, SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &pos,
+ 2.0f, 0.0f, 0.0f, -2.0f,
+ 255, // this is 0 on PC which results in no shadow
+ red, 0, 0,
+ 4.0f, 1.0f, 40.0f, false, 0.0f);
+ CCoronas::RegisterCorona((uintptr)entity, red, 0, 0, 255, pos, 0.6f, 60.0f, CCoronas::TYPE_RING, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
+ }
+
+ entity->GetMatrix().SetRotateZOnly((float)(CTimer::GetTimeInMilliseconds() & 0x3FF) * DEGTORAD(360.0f / 0x400));
+}
+
+void
+CPickups::DoMoneyEffects(CEntity *entity)
+{
+ CVector &pos = entity->GetPosition();
+ float dist = (TheCamera.GetPosition() - pos).Magnitude();
+ const float MAXDIST = 20.0f;
+
+ if (dist < MAXDIST) {
+ float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x3FF) * DEGTORAD(360.0f / 0x400));
+
+ int32 green = (MAXDIST - dist) * (0.2f * s + 0.3f) / MAXDIST * 64.0f;
+ CShadows::StoreStaticShadow((uintptr)entity, SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &pos,
+ 2.0f, 0.0f, 0.0f, -2.0f,
+ 255, // this is 0 on PC which results in no shadow
+ 0, green, 0,
+ 4.0f, 1.0f, 40.0f, false, 0.0f);
+ CCoronas::RegisterCorona((uintptr)entity, 0, green, 0, 255, pos, 0.4f, 40.0f, CCoronas::TYPE_RING, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
+ }
+
+ entity->GetMatrix().SetRotateZOnly((float)(CTimer::GetTimeInMilliseconds() & 0x7FF) * DEGTORAD(360.0f / 0x800));
+}
+
+void
+CPickups::DoCollectableEffects(CEntity *entity)
+{
+ CVector &pos = entity->GetPosition();
+ float dist = (TheCamera.GetPosition() - pos).Magnitude();
+ const float MAXDIST = 14.0f;
+
+ if (dist < MAXDIST) {
+ float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800));
+
+ int32 color = (MAXDIST - dist) * (0.5f * s + 0.5f) / MAXDIST * 255.0f;
+ CShadows::StoreStaticShadow((uintptr)entity, SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, &pos,
+ 2.0f, 0.0f, 0.0f, -2.0f,
+ 255, // this is 0 on PC which results in no shadow
+ color, color, color,
+ 4.0f, 1.0f, 40.0f, false, 0.0f);
+ CCoronas::RegisterCorona((uintptr)entity, color, color, color, 255, pos, 0.6f, 40.0f, CCoronas::TYPE_RING, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f);
+ }
+
+ entity->GetMatrix().SetRotateZOnly((float)(CTimer::GetTimeInMilliseconds() & 0xFFF) * DEGTORAD(360.0f / 0x1000));
+}
+
+void
+CPickups::RenderPickUpText()
+{
+ wchar *strToPrint;
+ for (int32 i = 0; i < NumMessages; i++) {
+ if (aMessages[i].m_quantity <= 39) {
+ switch (aMessages[i].m_quantity) // could use some enum maybe
+ {
+ case 0:
+ if (aMessages[i].m_weaponType == WEAPONTYPE_TOTALWEAPONS) { // unreachable code?
+ // what is this??
+ sprintf(gString, "%d/%d", CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages, 2903);
+ } else {
+ if (aMessages[i].m_bOutOfStock)
+ strToPrint = TheText.Get("STOCK");
+ else {
+ sprintf(gString, "$%d", CostOfWeapon[aMessages[i].m_weaponType]);
+ AsciiToUnicode(gString, gUString);
+ strToPrint = gUString;
+ }
+ }
+ break;
+ case 1:
+ strToPrint = TheText.Get("SECURI");
+ break;
+ case 2:
+ strToPrint = TheText.Get("MOONBM");
+ break;
+ case 3:
+ strToPrint = TheText.Get("COACH");
+ break;
+ case 4:
+ strToPrint = TheText.Get("FLATBED");
+ break;
+ case 5:
+ strToPrint = TheText.Get("LINERUN");
+ break;
+ case 6:
+ strToPrint = TheText.Get("TRASHM");
+ break;
+ case 7:
+ strToPrint = TheText.Get("PATRIOT");
+ break;
+ case 8:
+ strToPrint = TheText.Get("WHOOPEE");
+ break;
+ case 9:
+ strToPrint = TheText.Get("BLISTA");
+ break;
+ case 10:
+ strToPrint = TheText.Get("MULE");
+ break;
+ case 11:
+ strToPrint = TheText.Get("YANKEE");
+ break;
+ case 12:
+ strToPrint = TheText.Get("BOBCAT");
+ break;
+ case 13:
+ strToPrint = TheText.Get("DODO");
+ break;
+ case 14:
+ strToPrint = TheText.Get("BUS");
+ break;
+ case 15:
+ strToPrint = TheText.Get("RUMPO");
+ break;
+ case 16:
+ strToPrint = TheText.Get("PONY");
+ break;
+ case 17:
+ strToPrint = TheText.Get("SENTINL");
+ break;
+ case 18:
+ strToPrint = TheText.Get("CHEETAH");
+ break;
+ case 19:
+ strToPrint = TheText.Get("BANSHEE");
+ break;
+ case 20:
+ strToPrint = TheText.Get("IDAHO");
+ break;
+ case 21:
+ strToPrint = TheText.Get("INFERNS");
+ break;
+ case 22:
+ strToPrint = TheText.Get("TAXI");
+ break;
+ case 23:
+ strToPrint = TheText.Get("KURUMA");
+ break;
+ case 24:
+ strToPrint = TheText.Get("STRETCH");
+ break;
+ case 25:
+ strToPrint = TheText.Get("PEREN");
+ break;
+ case 26:
+ strToPrint = TheText.Get("STINGER");
+ break;
+ case 27:
+ strToPrint = TheText.Get("MANANA");
+ break;
+ case 28:
+ strToPrint = TheText.Get("LANDSTK");
+ break;
+ case 29:
+ strToPrint = TheText.Get("STALION");
+ break;
+ case 30:
+ strToPrint = TheText.Get("BFINJC");
+ break;
+ case 31:
+ strToPrint = TheText.Get("CABBIE");
+ break;
+ case 32:
+ strToPrint = TheText.Get("ESPERAN");
+ break;
+ case 33:
+ strToPrint = TheText.Get("FIRETRK");
+ break;
+ case 34:
+ strToPrint = TheText.Get("AMBULAN");
+ break;
+ case 35:
+ strToPrint = TheText.Get("ENFORCR");
+ break;
+ case 36:
+ strToPrint = TheText.Get("FBICAR");
+ break;
+ case 37:
+ strToPrint = TheText.Get("RHINO");
+ break;
+ case 38:
+ strToPrint = TheText.Get("BARRCKS");
+ break;
+ case 39:
+ strToPrint = TheText.Get("POLICAR");
+ break;
+ default:
+ break;
+ }
+ }
+ CFont::SetPropOn();
+ CFont::SetBackgroundOff();
+
+ const float MAX_SCALE = 1.0f;
+
+ float fScaleY = aMessages[i].m_dist.y / 100.0f;
+ if (fScaleY > MAX_SCALE) fScaleY = MAX_SCALE;
+
+ float fScaleX = aMessages[i].m_dist.x / 100.0f;
+ if (fScaleX > MAX_SCALE) fScaleX = MAX_SCALE;
+
+ CFont::SetScale(fScaleX, fScaleY);
+ CFont::SetCentreOn();
+ CFont::SetCentreSize(SCREEN_WIDTH);
+ CFont::SetJustifyOff();
+
+ CFont::SetColor(CRGBA(aMessages[i].m_color.red, aMessages[i].m_color.green, aMessages[i].m_color.blue, aMessages[i].m_color.alpha));
+ CFont::SetBackGroundOnlyTextOff();
+ CFont::SetFontStyle(FONT_BANK);
+ CFont::PrintString(aMessages[i].m_pos.x, aMessages[i].m_pos.y, strToPrint);
+ }
+ NumMessages = 0;
+}
+
+void
+CPickups::Load(uint8 *buffer, uint32 size)
+{
+ for (int32 i = 0; i < NUMPICKUPS; i++) {
+ CPickup *buf_pickup = (CPickup*)buffer;
+ aPickUps[i] = *buf_pickup;
+
+ if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].m_pObject != nil)
+ aPickUps[i].m_pObject = CPools::GetObjectPool()->GetSlot((int32)aPickUps[i].m_pObject - 1);
+
+ buffer += sizeof(CPickup);
+ }
+
+ CollectedPickUpIndex = *(uint16*)buffer;
+ buffer += sizeof(uint16);
+ NumMessages = 0;
+ buffer += sizeof(uint16);
+
+ for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++) {
+ aPickUpsCollected[i] = *(int32*)buffer;
+ buffer += sizeof(int32);
+ }
+}
+
+void
+CPickups::Save(uint8 *buffer, uint32 *size)
+{
+ *size = sizeof(CPickup) * NUMPICKUPS;
+ *size += sizeof(uint32) * NUMCOLLECTEDPICKUPS + 4;
+
+ for (int32 i = 0; i < NUMPICKUPS; i++) {
+ CPickup *buf_pickup = (CPickup*)buffer;
+ *buf_pickup = aPickUps[i];
+ if (buf_pickup->m_eType != PICKUP_NONE && buf_pickup->m_pObject != nil)
+ buf_pickup->m_pObject = (CObject*)(CPools::GetObjectPool()->GetJustIndex(buf_pickup->m_pObject) + 1);
+
+ buffer += sizeof(CPickup);
+ }
+
+ *(uint16*)buffer = CollectedPickUpIndex;
+ buffer += sizeof(uint16);
+ *(uint16*)buffer = 0; // possibly was NumMessages
+ buffer += sizeof(uint16);
+
+ for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++) {
+ *(int32*)buffer = aPickUpsCollected[i];
+ buffer += sizeof(int32);
+ }
+}
+
+STARTPATCHES
+ InjectHook(0x430220, CPickups::Init, PATCH_JUMP);
+ InjectHook(0x4303D0, CPickups::Update, PATCH_JUMP);
+ InjectHook(0x432440, CPickups::RenderPickUpText, PATCH_JUMP);
+ InjectHook(0x431C30, CPickups::DoCollectableEffects, PATCH_JUMP);
+ InjectHook(0x431F40, CPickups::DoMoneyEffects, PATCH_JUMP);
+ InjectHook(0x4321C0, CPickups::DoMineEffects, PATCH_JUMP);
+ InjectHook(0x431520, CPickups::DoPickUpEffects, PATCH_JUMP);
+ InjectHook(0x4304B0, CPickups::GenerateNewOne, PATCH_JUMP);
+ InjectHook(0x430660, CPickups::GenerateNewOne_WeaponType, PATCH_JUMP);
+ InjectHook(0x4307A0, CPickups::RemovePickUp, PATCH_JUMP);
+ InjectHook(0x430800, CPickups::RemoveAllFloatingPickups, PATCH_JUMP);
+ InjectHook(0x433D60, CPickups::AddToCollectedPickupsArray, PATCH_JUMP);
+ InjectHook(0x430770, CPickups::IsPickUpPickedUp, PATCH_JUMP);
+ InjectHook(0x430690, CPickups::ModelForWeapon, PATCH_JUMP);
+ InjectHook(0x4306F0, CPickups::WeaponForModel, PATCH_JUMP);
+ InjectHook(0x431510, CPickups::FindColourIndexForWeaponMI, PATCH_JUMP);/**/
+ InjectHook(0x433DF0, CPickups::GetActualPickupIndex, PATCH_JUMP);
+ InjectHook(0x433DB0, CPickups::GetNewUniquePickupIndex, PATCH_JUMP);
+ InjectHook(0x433B60, CPickups::PassTime, PATCH_JUMP);
+ InjectHook(0x4339F0, CPickups::GivePlayerGoodiesWithPickUpMI, PATCH_JUMP);
+ InjectHook(0x433F60, CPickups::Load, PATCH_JUMP);
+ InjectHook(0x433E40, CPickups::Save, PATCH_JUMP);
+ InjectHook(0x433BA0, &CPickup::GiveUsAPickUpObject, PATCH_JUMP);
+ InjectHook(0x430860, &CPickup::Update, PATCH_JUMP);
+ENDPATCHES \ No newline at end of file
diff --git a/src/control/Pickups.h b/src/control/Pickups.h
index 8c2014d6..b49a5544 100644
--- a/src/control/Pickups.h
+++ b/src/control/Pickups.h
@@ -1,59 +1,109 @@
-#pragma once
-#include "Weapon.h"
-
-enum ePickupType
-{
- PICKUP_NONE = 0,
- PICKUP_IN_SHOP = 1,
- PICKUP_ON_STREET = 2,
- PICKUP_ONCE = 3,
- PICKUP_ONCE_TIMEOUT = 4,
- PICKUP_COLLECTABLE1 = 5,
- PICKUP_IN_SHOP_OUT_OF_STOCK = 6,
- PICKUP_MONEY = 7,
- PICKUP_MINE_INACTIVE = 8,
- PICKUP_MINE_ARMED = 9,
- PICKUP_NAUTICAL_MINE_INACTIVE = 10,
- PICKUP_NAUTICAL_MINE_ARMED = 11,
- PICKUP_FLOATINGPACKAGE = 12,
- PICKUP_FLOATINGPACKAGE_FLOATING = 13,
- PICKUP_ON_STREET_SLOW = 14,
-};
-
-class CEntity;
-class CObject;
-
-class CPickup
-{
- ePickupType m_eType;
- uint16 m_wQuantity;
- CObject *m_pObject;
- uint32 m_nTimer;
- int16 m_eModelIndex;
- int16 m_wIndex;
- CVector m_vecPos;
-};
-
-class CPickups
-{
-public:
- static void RenderPickUpText(void);
- static void DoCollectableEffects(CEntity *ent);
- static void DoMoneyEffects(CEntity *ent);
- static void DoMineEffects(CEntity *ent);
- static void DoPickUpEffects(CEntity *ent);
- static void RemoveAllFloatingPickups();
- static int32 GenerateNewOne(CVector, uint32, uint8, uint32);
- static int32 GenerateNewOne_WeaponType(CVector, eWeaponType, uint8, uint32);
-
- static CPickup (&aPickUps)[NUMPICKUPS];
-};
-
-extern uint16 AmmoForWeapon[20];
-extern uint16 AmmoForWeapon_OnStreet[20];
-
-class CPacManPickups
-{
-public:
- static void Render(void);
-};
+#pragma once
+#include "Weapon.h"
+
+enum ePickupType : uint8
+{
+ PICKUP_NONE = 0,
+ PICKUP_IN_SHOP,
+ PICKUP_ON_STREET,
+ PICKUP_ONCE,
+ PICKUP_ONCE_TIMEOUT,
+ PICKUP_COLLECTABLE1,
+ PICKUP_IN_SHOP_OUT_OF_STOCK,
+ PICKUP_MONEY,
+ PICKUP_MINE_INACTIVE,
+ PICKUP_MINE_ARMED,
+ PICKUP_NAUTICAL_MINE_INACTIVE,
+ PICKUP_NAUTICAL_MINE_ARMED,
+ PICKUP_FLOATINGPACKAGE,
+ PICKUP_FLOATINGPACKAGE_FLOATING,
+ PICKUP_ON_STREET_SLOW,
+ PICKUP_NUMOFTYPES
+};
+
+class CEntity;
+class CObject;
+class CVehicle;
+class CPlayerPed;
+
+class CPickup
+{
+public:
+ ePickupType m_eType;
+ bool m_bRemoved;
+ uint16 m_nQuantity;
+ CObject *m_pObject;
+ uint32 m_nTimer;
+ int16 m_eModelIndex;
+ uint16 m_nIndex;
+ CVector m_vecPos;
+
+ CObject *GiveUsAPickUpObject(int32 handle);
+ bool Update(CPlayerPed *player, CVehicle *vehicle, int playerId);
+private:
+ bool IsMine() { return m_eType >= PICKUP_MINE_INACTIVE && m_eType <= PICKUP_FLOATINGPACKAGE_FLOATING; }
+ inline bool CanBePickedUp(CPlayerPed *player);
+ void RemoveKeepType();
+ void Remove();
+};
+
+static_assert(sizeof(CPickup) == 0x1C, "CPickup: error");
+
+struct tPickupMessage
+{
+ CVector2D m_pos;
+ eWeaponType m_weaponType;
+ CVector2D m_dist;
+ CRGBA m_color;
+ uint8 m_bOutOfStock : 1;
+ uint8 m_quantity;
+};
+
+class CPickups
+{
+ static int32 aPickUpsCollected[NUMCOLLECTEDPICKUPS];
+ static int16 CollectedPickUpIndex;
+ static int16 NumMessages;
+ static tPickupMessage aMessages[NUMPICKUPMESSAGES];
+public:
+ static void Init();
+ static void Update();
+ static void RenderPickUpText();
+ static void DoCollectableEffects(CEntity *ent);
+ static void DoMoneyEffects(CEntity *ent);
+ static void DoMineEffects(CEntity *ent);
+ static void DoPickUpEffects(CEntity *ent);
+ static int32 GenerateNewOne(CVector pos, uint32 modelIndex, uint8 type, uint32 quantity);
+ static int32 GenerateNewOne_WeaponType(CVector pos, eWeaponType weaponType, uint8 type, uint32 quantity);
+ static void RemovePickUp(int32 pickupIndex);
+ static void RemoveAllFloatingPickups();
+ static void AddToCollectedPickupsArray(int32 index);
+ static bool IsPickUpPickedUp(int32 pickupId);
+ static int32 ModelForWeapon(eWeaponType weaponType);
+ static enum eWeaponType WeaponForModel(int32 model);
+ static int32 FindColourIndexForWeaponMI(int32 model);
+ static int32 GetActualPickupIndex(int32 index);
+ static int32 GetNewUniquePickupIndex(int32 slot);
+ static void PassTime(uint32 time);
+ static bool GivePlayerGoodiesWithPickUpMI(int16 modelIndex, int playerIndex);
+ static void Load(uint8 *buffer, uint32 size);
+ static void Save(uint8 *buffer, uint32 *size);
+
+ static CPickup(&aPickUps)[NUMPICKUPS];
+
+ // unused
+ static bool &bPickUpcamActivated;
+ static CVehicle *&pPlayerVehicle;
+ static CVector &StaticCamCoors;
+ static uint32 &StaticCamStartTime;
+};
+
+extern uint16 AmmoForWeapon[20];
+extern uint16 AmmoForWeapon_OnStreet[20];
+extern uint16 CostOfWeapon[20];
+
+class CPacManPickups
+{
+public:
+ static void Render(void);
+};
diff --git a/src/control/Script.cpp b/src/control/Script.cpp
index 885d1d47..db4ef82f 100644
--- a/src/control/Script.cpp
+++ b/src/control/Script.cpp
@@ -130,7 +130,7 @@ void CMissionCleanup::Process()
CCarCtrl::CarDensityMultiplier = 1.0;
FindPlayerPed()->m_pWanted->m_fCrimeSensitivity = 1.0f;
TheCamera.Restore();
- TheCamera.SetWidescreenOff();
+ TheCamera.SetWideScreenOff();
DMAudio.ClearMissionAudio();
CWeather::ReleaseWeather();
for (int i = 0; i < NUM_OF_SPECIAL_CHARS; i++)
@@ -1707,7 +1707,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command)
ped->SetOrientation(0.0f, 0.0f, 0.0f);
CTheScripts::ClearSpaceForMissionEntity(pos, ped);
CWorld::Add(ped);
- ped->m_level = CTheZones::GetLevelFromPosition(pos);
+ ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos);
CPopulation::ms_nTotalMissionPeds++;
ScriptParams[0] = CPools::GetPedPool()->GetIndex(ped);
StoreParameters(&m_nIp, 1);
@@ -1948,7 +1948,7 @@ int8 CRunningScript::ProcessCommandsFrom100To199(int32 command)
car->AutoPilot.m_nCruiseSpeed = car->AutoPilot.m_fMaxTrafficSpeed = 9.0f;
car->AutoPilot.m_nCurrentLane = car->AutoPilot.m_nNextLane = 0;
car->bEngineOn = false;
- car->m_level = CTheZones::GetLevelFromPosition(pos);
+ car->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos);
car->bHasBeenOwnedByPlayer = true;
CWorld::Add(car);
handle = CPools::GetVehiclePool()->GetIndex(car);
@@ -2748,7 +2748,7 @@ int8 CRunningScript::ProcessCommandsFrom200To299(int32 command)
AnimationId anim = pVehicle->bLowVehicle ? ANIM_CAR_LSIT : ANIM_CAR_SIT;
pPed->m_pVehicleAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, anim, 100.0f);
pPed->StopNonPartialAnims();
- pPed->m_level = CTheZones::GetLevelFromPosition(pPed->GetPosition());
+ pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition());
CWorld::Add(pPed);
ScriptParams[0] = CPools::GetPedPool()->GetIndex(pPed);
StoreParameters(&m_nIp, 1);
diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp
index cb16c3ad..775ab46a 100644
--- a/src/core/Camera.cpp
+++ b/src/core/Camera.cpp
@@ -22,7 +22,6 @@ WRAPPER void CCamera::CamShake(float strength, float x, float y, float z) { EAXJ
WRAPPER void CCamera::DrawBordersForWideScreen(void) { EAXJMP(0x46B430); }
WRAPPER void CCamera::CalculateDerivedValues(void) { EAXJMP(0x46EEA0); }
WRAPPER void CCamera::Restore(void) { EAXJMP(0x46F990); }
-WRAPPER void CCamera::SetWidescreenOff(void) { EAXJMP(0x46FF10); }
WRAPPER void CamShakeNoPos(CCamera*, float) { EAXJMP(0x46B100); }
WRAPPER void CCamera::TakeControl(CEntity*, int16, int16, int32) { EAXJMP(0x471500); }
WRAPPER void CCamera::TakeControlNoEntity(const CVector&, int16, int32) { EAXJMP(0x4715B0); }
@@ -30,6 +29,10 @@ WRAPPER void CCamera::SetCamPositionForFixedMode(const CVector&, const CVector&)
WRAPPER void CCamera::Init(void) { EAXJMP(0x46BAD0); }
WRAPPER void CCamera::SetRwCamera(RwCamera*) { EAXJMP(0x46FEC0); }
WRAPPER void CCamera::Process(void) { EAXJMP(0x46D3F0); }
+WRAPPER void CCamera::LoadPathSplines(int file) { EAXJMP(0x46D1D0); }
+WRAPPER uint32 CCamera::GetCutSceneFinishTime(void) { EAXJMP(0x46B920); }
+WRAPPER void CCamera::FinishCutscene(void) { EAXJMP(0x46B560); }
+WRAPPER void CCamera::RestoreWithJumpCut(void) { EAXJMP(0x46FAE0); };
bool
CCamera::GetFading()
@@ -1327,6 +1330,25 @@ CCamera::Find3rdPersonQuickAimPitch(void)
return -(DEGTORAD(((0.5f - m_f3rdPersonCHairMultY) * 1.8f * 0.5f * Cams[ActiveCam].FOV)) + rot);
}
+void
+CCamera::SetCamCutSceneOffSet(const CVector &pos)
+{
+ m_vecCutSceneOffset = pos;
+};
+
+void
+CCamera::TakeControlWithSpline(short nSwitch)
+{
+ m_iModeToGoTo = CCam::MODE_FLYBY;
+ m_bLookingAtPlayer = false;
+ m_bLookingAtVector = false;
+ m_bcutsceneFinished = false;
+ m_iTypeOfSwitch = nSwitch;
+ m_bStartInterScript = true;
+
+ //FindPlayerPed(); // unused
+};
+
STARTPATCHES
InjectHook(0x42C760, (bool (CCamera::*)(const CVector &center, float radius, const CMatrix *mat))&CCamera::IsSphereVisible, PATCH_JUMP);
InjectHook(0x46FD00, &CCamera::SetFadeColour, PATCH_JUMP);
diff --git a/src/core/Camera.h b/src/core/Camera.h
index 1f38963b..0fd372c3 100644
--- a/src/core/Camera.h
+++ b/src/core/Camera.h
@@ -380,11 +380,11 @@ uint32 unknown;
CVector m_RealPreviousCameraPosition;
CVector m_cvecAimingTargetCoors;
CVector m_vecFixedModeVector;
+ CVector m_vecFixedModeSource;
+ CVector m_vecFixedModeUpOffSet;
+ CVector m_vecCutSceneOffset;
- // one of those has to go
- CVector m_vecFixedModeSource;
- CVector m_vecFixedModeUpOffSet;
-// CVector m_vecCutSceneOffset;
+ // one of those has to go
CVector m_cvecStartingSourceForInterPol;
CVector m_cvecStartingTargetForInterPol;
CVector m_cvecStartingUpForInterPol;
@@ -394,7 +394,7 @@ uint32 unknown;
CVector m_vecSourceWhenInterPol;
CVector m_vecTargetWhenInterPol;
CVector m_vecUpWhenInterPol;
- CVector m_vecClearGeometryVec;
+ //CVector m_vecClearGeometryVec;
CVector m_vecGameCamPos;
CVector SourceDuringInter;
@@ -444,6 +444,7 @@ int m_iModeObbeCamIsInForCar;
bool Get_Just_Switched_Status() { return m_bJust_Switched; }
inline const CMatrix& GetCameraMatrix(void) { return m_cameraMatrix; }
CVector &GetGameCamPosition(void) { return m_vecGameCamPos; }
+ float GetPositionAlongSpline(void) { return m_fPositionAlongSpline; }
bool IsPointVisible(const CVector &center, const CMatrix *mat);
bool IsSphereVisible(const CVector &center, float radius, const CMatrix *mat);
bool IsSphereVisible(const CVector &center, float radius);
@@ -467,7 +468,8 @@ int m_iModeObbeCamIsInForCar;
void DrawBordersForWideScreen(void);
void Restore(void);
- void SetWidescreenOff(void);
+ void SetWideScreenOn(void) { m_WideScreenOn = true; }
+ void SetWideScreenOff(void) { m_WideScreenOn = false; }
float Find3rdPersonQuickAimPitch(void);
@@ -480,6 +482,14 @@ int m_iModeObbeCamIsInForCar;
void SetRwCamera(RwCamera*);
void Process();
+ void LoadPathSplines(int file);
+ uint32 GetCutSceneFinishTime(void);
+ void FinishCutscene(void);
+
+ void SetCamCutSceneOffSet(const CVector&);
+ void TakeControlWithSpline(short);
+ void RestoreWithJumpCut(void);
+
void dtor(void) { this->CCamera::~CCamera(); }
};
static_assert(offsetof(CCamera, m_WideScreenOn) == 0x70, "CCamera: error");
@@ -489,6 +499,7 @@ static_assert(offsetof(CCamera, m_uiTransitionState) == 0x89, "CCamera: error");
static_assert(offsetof(CCamera, m_uiTimeTransitionStart) == 0x94, "CCamera: error");
static_assert(offsetof(CCamera, m_BlurBlue) == 0x9C, "CCamera: error");
static_assert(offsetof(CCamera, Cams) == 0x1A4, "CCamera: error");
+static_assert(offsetof(CCamera, m_vecCutSceneOffset) == 0x6F8, "CCamera: error");
static_assert(sizeof(CCamera) == 0xE9D8, "CCamera: wrong size");
extern CCamera &TheCamera;
diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp
index a54e8ff6..1461c858 100644
--- a/src/core/CutsceneMgr.cpp
+++ b/src/core/CutsceneMgr.cpp
@@ -1,8 +1,425 @@
#include "common.h"
#include "patcher.h"
#include "CutsceneMgr.h"
+#include "Directory.h"
+#include "Camera.h"
+#include "Streaming.h"
+#include "FileMgr.h"
+#include "main.h"
+#include "AnimManager.h"
+#include "AnimBlendAssocGroup.h"
+#include "AnimBlendClumpData.h"
+#include "Pad.h"
+#include "DMAudio.h"
+#include "World.h"
+#include "PlayerPed.h"
+#include "CutsceneHead.h"
+#include "RpAnimBlend.h"
+#include "ModelIndices.h"
+#include "TempColModels.h"
+#include "MusicManager.h"
+
+const struct {
+ const char *szTrackName;
+ int iTrackId;
+} musicNameIdAssoc[] = {
+ { "JB", STREAMED_SOUND_NEWS_INTRO },
+ { "BET", STREAMED_SOUND_BANK_INTRO },
+ { "L1_LG", STREAMED_SOUND_CUTSCENE_LUIGI1_LG },
+ { "L2_DSB", STREAMED_SOUND_CUTSCENE_LUIGI2_DSB },
+ { "L3_DM", STREAMED_SOUND_CUTSCENE_LUIGI3_DM },
+ { "L4_PAP", STREAMED_SOUND_CUTSCENE_LUIGI4_PAP },
+ { "L5_TFB", STREAMED_SOUND_CUTSCENE_LUIGI5_TFB },
+ { "J0_DM2", STREAMED_SOUND_CUTSCENE_JOEY0_DM2 },
+ { "J1_LFL", STREAMED_SOUND_CUTSCENE_JOEY1_LFL },
+ { "J2_KCL", STREAMED_SOUND_CUTSCENE_JOEY2_KCL },
+ { "J3_VH", STREAMED_SOUND_CUTSCENE_JOEY3_VH },
+ { "J4_ETH", STREAMED_SOUND_CUTSCENE_JOEY4_ETH },
+ { "J5_DST", STREAMED_SOUND_CUTSCENE_JOEY5_DST },
+ { "J6_TBJ", STREAMED_SOUND_CUTSCENE_JOEY6_TBJ },
+ { "T1_TOL", STREAMED_SOUND_CUTSCENE_TONI1_TOL },
+ { "T2_TPU", STREAMED_SOUND_CUTSCENE_TONI2_TPU },
+ { "T3_MAS", STREAMED_SOUND_CUTSCENE_TONI3_MAS },
+ { "T4_TAT", STREAMED_SOUND_CUTSCENE_TONI4_TAT },
+ { "T5_BF", STREAMED_SOUND_CUTSCENE_TONI5_BF },
+ { "S0_MAS", STREAMED_SOUND_CUTSCENE_SAL0_MAS },
+ { "S1_PF", STREAMED_SOUND_CUTSCENE_SAL1_PF },
+ { "S2_CTG", STREAMED_SOUND_CUTSCENE_SAL2_CTG },
+ { "S3_RTC", STREAMED_SOUND_CUTSCENE_SAL3_RTC },
+ { "S5_LRQ", STREAMED_SOUND_CUTSCENE_SAL5_LRQ },
+ { "S4_BDBA", STREAMED_SOUND_CUTSCENE_SAL4_BDBA },
+ { "S4_BDBB", STREAMED_SOUND_CUTSCENE_SAL4_BDBB },
+ { "S2_CTG2", STREAMED_SOUND_CUTSCENE_SAL2_CTG2 },
+ { "S4_BDBD", STREAMED_SOUND_CUTSCENE_SAL4_BDBD },
+ { "S5_LRQB", STREAMED_SOUND_CUTSCENE_SAL5_LRQB },
+ { "S5_LRQC", STREAMED_SOUND_CUTSCENE_SAL5_LRQC },
+ { "A1_SS0", STREAMED_SOUND_CUTSCENE_ASUKA_1_SSO },
+ { "A2_PP", STREAMED_SOUND_CUTSCENE_ASUKA_2_PP },
+ { "A3_SS", STREAMED_SOUND_CUTSCENE_ASUKA_3_SS },
+ { "A4_PDR", STREAMED_SOUND_CUTSCENE_ASUKA_4_PDR },
+ { "A5_K2FT", STREAMED_SOUND_CUTSCENE_ASUKA_5_K2FT},
+ { "K1_KBO", STREAMED_SOUND_CUTSCENE_KENJI1_KBO },
+ { "K2_GIS", STREAMED_SOUND_CUTSCENE_KENJI2_GIS },
+ { "K3_DS", STREAMED_SOUND_CUTSCENE_KENJI3_DS },
+ { "K4_SHI", STREAMED_SOUND_CUTSCENE_KENJI4_SHI },
+ { "K5_SD", STREAMED_SOUND_CUTSCENE_KENJI5_SD },
+ { "R0_PDR2", STREAMED_SOUND_CUTSCENE_RAY0_PDR2 },
+ { "R1_SW", STREAMED_SOUND_CUTSCENE_RAY1_SW },
+ { "R2_AP", STREAMED_SOUND_CUTSCENE_RAY2_AP },
+ { "R3_ED", STREAMED_SOUND_CUTSCENE_RAY3_ED },
+ { "R4_GF", STREAMED_SOUND_CUTSCENE_RAY4_GF },
+ { "R5_PB", STREAMED_SOUND_CUTSCENE_RAY5_PB },
+ { "R6_MM", STREAMED_SOUND_CUTSCENE_RAY6_MM },
+ { "D1_STOG", STREAMED_SOUND_CUTSCENE_DONALD1_STOG },
+ { "D2_KK", STREAMED_SOUND_CUTSCENE_DONALD2_KK },
+ { "D3_ADO", STREAMED_SOUND_CUTSCENE_DONALD3_ADO },
+ { "D5_ES", STREAMED_SOUND_CUTSCENE_DONALD5_ES },
+ { "D7_MLD", STREAMED_SOUND_CUTSCENE_DONALD7_MLD },
+ { "D4_GTA", STREAMED_SOUND_CUTSCENE_DONALD4_GTA },
+ { "D4_GTA2", STREAMED_SOUND_CUTSCENE_DONALD4_GTA2 },
+ { "D6_STS", STREAMED_SOUND_CUTSCENE_DONALD6_STS },
+ { "A6_BAIT", STREAMED_SOUND_CUTSCENE_ASUKA6_BAIT },
+ { "A7_ETG", STREAMED_SOUND_CUTSCENE_ASUKA7_ETG },
+ { "A8_PS", STREAMED_SOUND_CUTSCENE_ASUKA8_PS },
+ { "A9_ASD", STREAMED_SOUND_CUTSCENE_ASUKA9_ASD },
+ { "K4_SHI2", STREAMED_SOUND_CUTSCENE_KENJI4_SHI2 },
+ { "C1_TEX", STREAMED_SOUND_CUTSCENE_CATALINA1_TEX },
+ { "EL_PH1", STREAMED_SOUND_CUTSCENE_ELBURRO1_PH1 },
+ { "EL_PH2", STREAMED_SOUND_CUTSCENE_ELBURRO2_PH2 },
+ { "EL_PH3", STREAMED_SOUND_CUTSCENE_ELBURRO3_PH3 },
+ { "EL_PH4", STREAMED_SOUND_CUTSCENE_ELBURRO4_PH4 },
+ { "YD_PH1", STREAMED_SOUND_CUTSCENE_YARDIE_PH1 },
+ { "YD_PH2", STREAMED_SOUND_CUTSCENE_YARDIE_PH2 },
+ { "YD_PH3", STREAMED_SOUND_CUTSCENE_YARDIE_PH3 },
+ { "YD_PH4", STREAMED_SOUND_CUTSCENE_YARDIE_PH4 },
+ { "HD_PH1", STREAMED_SOUND_CUTSCENE_HOODS_PH1 },
+ { "HD_PH2", STREAMED_SOUND_CUTSCENE_HOODS_PH2 },
+ { "HD_PH3", STREAMED_SOUND_CUTSCENE_HOODS_PH3 },
+ { "HD_PH4", STREAMED_SOUND_CUTSCENE_HOODS_PH4 },
+ { "HD_PH5", STREAMED_SOUND_CUTSCENE_HOODS_PH5 },
+ { "MT_PH1", STREAMED_SOUND_CUTSCENE_MARTY_PH1 },
+ { "MT_PH2", STREAMED_SOUND_CUTSCENE_MARTY_PH2 },
+ { "MT_PH3", STREAMED_SOUND_CUTSCENE_MARTY_PH3 },
+ { "MT_PH4", STREAMED_SOUND_CUTSCENE_MARTY_PH4 },
+ { NULL, NULL }
+};
+
+int
+FindCutsceneAudioTrackId(const char *szCutsceneName)
+{
+ for (int i = 0; musicNameIdAssoc[i].szTrackName; i++)
+ {
+ if (!strcmpi(musicNameIdAssoc[i].szTrackName, szCutsceneName))
+ return musicNameIdAssoc[i].iTrackId;
+ }
+ return -1;
+}
bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5;
bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F;
CDirectory *&CCutsceneMgr::ms_pCutsceneDir = *(CDirectory**)0x8F5F88;
CCutsceneObject *(&CCutsceneMgr::ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS] = *(CCutsceneObject*(*)[NUMCUTSCENEOBJECTS]) *(uintptr*) 0x862170;
+int32 &CCutsceneMgr::ms_numCutsceneObjs = *(int32*)0x942FA4;
+bool &CCutsceneMgr::ms_loaded = *(bool*)0x95CD95;
+bool &CCutsceneMgr::ms_animLoaded = *(bool*)0x95CDA0;
+bool &CCutsceneMgr::ms_useLodMultiplier = *(bool*)0x95CD74;
+char(&CCutsceneMgr::ms_cutsceneName)[CUTSCENENAMESIZE] = *(char(*)[CUTSCENENAMESIZE]) *(uintptr*)0x70D9D0;
+CAnimBlendAssocGroup &CCutsceneMgr::ms_cutsceneAssociations = *(CAnimBlendAssocGroup*)0x709C58;
+CVector &CCutsceneMgr::ms_cutsceneOffset = *(CVector*)0x8F2C0C;
+float &CCutsceneMgr::ms_cutsceneTimer = *(float*)0x941548;
+uint32 &CCutsceneMgr::ms_cutsceneLoadStatus = *(uint32*)0x95CB40;
+
+WRAPPER RpAtomic* CalculateBoundingSphereRadiusCB(RpAtomic * atomic, void *data) { EAXJMP(0x404B40); }
+
+void
+CCutsceneMgr::Initialise(void)
+{
+ ms_numCutsceneObjs = 0;
+ ms_loaded = false;
+ ms_running = false;
+ ms_animLoaded = false;
+ ms_cutsceneProcessing = false;
+ ms_useLodMultiplier = false;
+
+ ms_pCutsceneDir = new CDirectory(CUTSCENEDIRSIZE);
+ ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR");
+}
+
+void
+CCutsceneMgr::Shutdown(void)
+{
+ delete ms_pCutsceneDir;
+}
+
+void
+CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName)
+{
+ int file;
+ uint32 size;
+ uint32 offset;
+ CPlayerPed *pPlayerPed;
+
+ ms_cutsceneProcessing = true;
+ if (!strcmpi(szCutsceneName, "jb"))
+ ms_useLodMultiplier = true;
+ CTimer::Stop();
+
+ ms_pCutsceneDir->numEntries = 0;
+ ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR");
+
+ CStreaming::RemoveUnusedModelsInLoadedList();
+ CGame::DrasticTidyUpMemory();
+
+ strcpy(ms_cutsceneName, szCutsceneName);
+ file = CFileMgr::OpenFile("ANIM\\CUTS.IMG", "rb");
+
+ // Load animations
+ sprintf(gString, "%s.IFP", szCutsceneName);
+ if (ms_pCutsceneDir->FindItem(gString, offset, size)) {
+ CStreaming::MakeSpaceFor(size << 11);
+ CStreaming::ImGonnaUseStreamingMemory();
+ CFileMgr::Seek(file, offset << 11, SEEK_SET);
+ CAnimManager::LoadAnimFile(file, false);
+ ms_cutsceneAssociations.CreateAssociations(szCutsceneName);
+ CStreaming::IHaveUsedStreamingMemory();
+ ms_animLoaded = true;
+ } else {
+ ms_animLoaded = false;
+ }
+
+ // Load camera data
+ sprintf(gString, "%s.DAT", szCutsceneName);
+ if (ms_pCutsceneDir->FindItem(gString, offset, size)) {
+ CFileMgr::Seek(file, offset << 11, SEEK_SET);
+ TheCamera.LoadPathSplines(file);
+ }
+
+ CFileMgr::CloseFile(file);
+
+ if (strcmpi(ms_cutsceneName, "end")) {
+ DMAudio.ChangeMusicMode(2);
+ int trackId = FindCutsceneAudioTrackId(szCutsceneName);
+ if (trackId != -1) {
+ printf("Start preload audio %s\n", szCutsceneName);
+ DMAudio.PreloadCutSceneMusic(trackId);
+ printf("End preload audio %s\n", szCutsceneName);
+ }
+ }
+
+ ms_cutsceneTimer = 0.0f;
+ ms_loaded = true;
+ ms_cutsceneOffset = CVector(0.0f, 0.0f, 0.0f);
+
+ pPlayerPed = FindPlayerPed();
+ CTimer::Update();
+
+ pPlayerPed->m_pWanted->ClearQdCrimes();
+ pPlayerPed->bIsVisible = false;
+ pPlayerPed->m_fCurrentStamina = pPlayerPed->m_fMaxStamina;
+ CPad::GetPad(0)->DisablePlayerControls |= PLAYERCONTROL_DISABLED_80;
+ CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(true);
+}
+
+void
+CCutsceneMgr::SetHeadAnim(const char *animName, CObject *pObject)
+{
+ CCutsceneHead *pCutsceneHead = (CCutsceneHead*)pObject;
+ char szAnim[CUTSCENENAMESIZE * 2];
+
+ sprintf(szAnim, "%s_%s", ms_cutsceneName, animName);
+ pCutsceneHead->PlayAnimation(szAnim);
+}
+
+void
+CCutsceneMgr::FinishCutscene()
+{
+ CCutsceneMgr::ms_cutsceneTimer = TheCamera.GetCutSceneFinishTime() * 0.001f;
+ TheCamera.FinishCutscene();
+
+ FindPlayerPed()->bIsVisible = true;
+ CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false);
+}
+
+void
+CCutsceneMgr::SetupCutsceneToStart(void)
+{
+ TheCamera.SetCamCutSceneOffSet(ms_cutsceneOffset);
+ TheCamera.TakeControlWithSpline(2);
+ TheCamera.SetWideScreenOn();
+
+ ms_cutsceneOffset.z++;
+
+ for (int i = ms_numCutsceneObjs - 1; i >= 0; i--) {
+ assert(RwObjectGetType(ms_pCutsceneObjects[i]->m_rwObject) == rpCLUMP);
+ if (CAnimBlendAssociation *pAnimBlendAssoc = RpAnimBlendClumpGetFirstAssociation((RpClump*)ms_pCutsceneObjects[i]->m_rwObject)) {
+ assert(pAnimBlendAssoc->hierarchy->sequences[0].HasTranslation());
+ ms_pCutsceneObjects[i]->GetPosition() = ms_cutsceneOffset + ((KeyFrameTrans*)pAnimBlendAssoc->hierarchy->sequences[0].GetKeyFrame(0))->translation;
+ CWorld::Add(ms_pCutsceneObjects[i]);
+ pAnimBlendAssoc->SetRun();
+ } else {
+ ms_pCutsceneObjects[i]->GetPosition() = ms_cutsceneOffset;
+ }
+ }
+
+ CTimer::Update();
+ CTimer::Update();
+ ms_running = true;
+ ms_cutsceneTimer = 0.0f;
+}
+
+void
+CCutsceneMgr::SetCutsceneAnim(const char *animName, CObject *pObject)
+{
+ CAnimBlendAssociation *pNewAnim;
+ CAnimBlendClumpData *pAnimBlendClumpData;
+
+ assert(RwObjectGetType(pObject->m_rwObject) == rpCLUMP);
+ RpAnimBlendClumpRemoveAllAssociations((RpClump*)pObject->m_rwObject);
+
+ pNewAnim = ms_cutsceneAssociations.CopyAnimation(animName);
+ pNewAnim->SetCurrentTime(0.0f);
+ pNewAnim->flags |= ASSOC_HAS_TRANSLATION;
+ pNewAnim->flags &= ~ASSOC_RUNNING;
+
+ pAnimBlendClumpData = *RPANIMBLENDCLUMPDATA(pObject->m_rwObject);
+ pAnimBlendClumpData->link.Prepend(&pNewAnim->link);
+}
+
+CCutsceneHead *
+CCutsceneMgr::AddCutsceneHead(CObject *pObject, int modelId)
+{
+ CCutsceneHead *pHead = new CCutsceneHead(pObject);
+ pHead->SetModelIndex(modelId);
+ CWorld::Add(pHead);
+ ms_pCutsceneObjects[ms_numCutsceneObjs++] = pHead;
+ return pHead;
+}
+
+CCutsceneObject *
+CCutsceneMgr::CreateCutsceneObject(int modelId)
+{
+ CBaseModelInfo *pModelInfo;
+ CColModel *pColModel;
+ float radius;
+ RpClump *clump;
+ CCutsceneObject *pCutsceneObject;
+
+ if (modelId >= MI_CUTOBJ01 && modelId <= MI_CUTOBJ05) {
+ pModelInfo = CModelInfo::GetModelInfo(modelId);
+ pColModel = &CTempColModels::ms_colModelCutObj[modelId - MI_CUTOBJ01];
+ radius = 0.0f;
+
+ pModelInfo->SetColModel(pColModel);
+ clump = (RpClump*)pModelInfo->GetRwObject();
+ assert(RwObjectGetType(clump) == rpCLUMP);
+ RpClumpForAllAtomics(clump, (RpAtomicCallBack)CalculateBoundingSphereRadiusCB, &radius);
+
+ pColModel->boundingSphere.radius = radius;
+ pColModel->boundingBox.min = CVector(-radius, -radius, -radius);
+ pColModel->boundingBox.max = CVector(radius, radius, radius);
+ }
+
+ pCutsceneObject = new CCutsceneObject();
+ pCutsceneObject->SetModelIndex(modelId);
+ ms_pCutsceneObjects[ms_numCutsceneObjs++] = pCutsceneObject;
+ return pCutsceneObject;
+}
+
+void
+CCutsceneMgr::DeleteCutsceneData(void)
+{
+ if (!ms_loaded) return;
+
+ ms_cutsceneProcessing = false;
+ ms_useLodMultiplier = false;
+
+ for (--ms_numCutsceneObjs; ms_numCutsceneObjs >= 0; ms_numCutsceneObjs--) {
+ CWorld::Remove(ms_pCutsceneObjects[ms_numCutsceneObjs]);
+ ms_pCutsceneObjects[ms_numCutsceneObjs]->DeleteRwObject();
+ delete ms_pCutsceneObjects[ms_numCutsceneObjs];
+ }
+ ms_numCutsceneObjs = 0;
+
+ if (ms_animLoaded)
+ CAnimManager::RemoveLastAnimFile();
+
+ ms_animLoaded = false;
+ TheCamera.RestoreWithJumpCut();
+ TheCamera.SetWideScreenOff();
+ ms_running = false;
+ ms_loaded = false;
+
+ FindPlayerPed()->bIsVisible = true;
+ CPad::GetPad(0)->DisablePlayerControls &= ~PLAYERCONTROL_DISABLED_80;
+ CWorld::Players[CWorld::PlayerInFocus].MakePlayerSafe(false);
+
+ if (strcmpi(ms_cutsceneName, "end")) {
+ DMAudio.StopCutSceneMusic();
+ if (strcmpi(ms_cutsceneName, "bet"))
+ DMAudio.ChangeMusicMode(1);
+ }
+ CTimer::Stop();
+ //TheCamera.GetScreenFadeStatus() == 2; // what for??
+ CGame::DrasticTidyUpMemory();
+ CTimer::Update();
+}
+
+void
+CCutsceneMgr::Update(void)
+{
+ enum {
+ CUTSCENE_LOADING_0 = 0,
+ CUTSCENE_LOADING_AUDIO,
+ CUTSCENE_LOADING_2,
+ CUTSCENE_LOADING_3,
+ CUTSCENE_LOADING_4
+ };
+
+ switch (ms_cutsceneLoadStatus) {
+ case CUTSCENE_LOADING_AUDIO:
+ SetupCutsceneToStart();
+ if (strcmpi(ms_cutsceneName, "end"))
+ DMAudio.PlayPreloadedCutSceneMusic();
+ ms_cutsceneLoadStatus++;
+ break;
+ case CUTSCENE_LOADING_2:
+ case CUTSCENE_LOADING_3:
+ ms_cutsceneLoadStatus++;
+ break;
+ case CUTSCENE_LOADING_4:
+ ms_cutsceneLoadStatus = CUTSCENE_LOADING_0;
+ break;
+ default:
+ break;
+ }
+
+ if (!ms_running) return;
+
+ ms_cutsceneTimer += CTimer::GetTimeStepNonClipped() * 0.02f;
+ if (strcmpi(ms_cutsceneName, "end") && TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_FLYBY && ms_cutsceneLoadStatus == CUTSCENE_LOADING_0) {
+ if (CPad::GetPad(0)->GetCrossJustDown()
+ || (CGame::playingIntro && CPad::GetPad(0)->GetStartJustDown())
+ || CPad::GetPad(0)->GetLeftMouseJustDown()
+ || CPad::GetPad(0)->GetPadEnterJustDown() || CPad::GetPad(0)->GetEnterJustDown() // NOTE: In original code it's a single CPad method
+ || CPad::GetPad(0)->GetCharJustDown(VK_SPACE))
+ FinishCutscene();
+ }
+}
+
+bool CCutsceneMgr::HasCutsceneFinished(void) { return TheCamera.GetPositionAlongSpline() == 1.0f; }
+
+STARTPATCHES
+InjectHook(0x4045D0, &CCutsceneMgr::Initialise, PATCH_JUMP);
+InjectHook(0x404630, &CCutsceneMgr::Shutdown, PATCH_JUMP);
+InjectHook(0x404650, &CCutsceneMgr::LoadCutsceneData, PATCH_JUMP);
+InjectHook(0x405140, &CCutsceneMgr::FinishCutscene, PATCH_JUMP);
+InjectHook(0x404D80, &CCutsceneMgr::SetHeadAnim, PATCH_JUMP);
+InjectHook(0x404DC0, &CCutsceneMgr::SetupCutsceneToStart, PATCH_JUMP);
+InjectHook(0x404D20, &CCutsceneMgr::SetCutsceneAnim, PATCH_JUMP);
+InjectHook(0x404CD0, &CCutsceneMgr::AddCutsceneHead, PATCH_JUMP);
+InjectHook(0x404BE0, &CCutsceneMgr::CreateCutsceneObject, PATCH_JUMP);
+InjectHook(0x4048E0, &CCutsceneMgr::DeleteCutsceneData, PATCH_JUMP);
+InjectHook(0x404EE0, &CCutsceneMgr::Update, PATCH_JUMP);
+InjectHook(0x4051B0, &CCutsceneMgr::GetCutsceneTimeInMilleseconds, PATCH_JUMP);
+InjectHook(0x4051F0, &CCutsceneMgr::HasCutsceneFinished, PATCH_JUMP);
+ENDPATCHES \ No newline at end of file
diff --git a/src/core/CutsceneMgr.h b/src/core/CutsceneMgr.h
index aa5a2eb2..9b942030 100644
--- a/src/core/CutsceneMgr.h
+++ b/src/core/CutsceneMgr.h
@@ -1,7 +1,11 @@
#pragma once
#include "CutsceneObject.h"
+#define CUTSCENENAMESIZE 8
+
class CDirectory;
+class CAnimBlendAssocGroup;
+class CCutsceneHead;
class CCutsceneMgr
{
@@ -9,10 +13,35 @@ class CCutsceneMgr
static bool &ms_cutsceneProcessing;
static CCutsceneObject *(&ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS];
+ static int32 &ms_numCutsceneObjs;
+ static bool &ms_loaded;
+ static bool &ms_animLoaded;
+ static bool &ms_useLodMultiplier;
+
+ static char(&ms_cutsceneName)[CUTSCENENAMESIZE];
+ static CAnimBlendAssocGroup &ms_cutsceneAssociations;
+ static CVector &ms_cutsceneOffset;
+ static float &ms_cutsceneTimer;
public:
static CDirectory *&ms_pCutsceneDir;
+ static uint32 &ms_cutsceneLoadStatus;
static bool IsRunning(void) { return ms_running; }
static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; }
static CCutsceneObject* GetCutsceneObject(int id) { return ms_pCutsceneObjects[id]; }
+ static int GetCutsceneTimeInMilleseconds(void) { return 1000.0f * ms_cutsceneTimer; }
+ static char *GetCutsceneName(void) { return ms_cutsceneName; }
+ static bool HasCutsceneFinished(void);
+
+ static void Initialise(void);
+ static void Shutdown(void);
+ static void LoadCutsceneData(const char *szCutsceneName);
+ static void FinishCutscene(void);
+ static void SetHeadAnim(const char *animName, CObject *pObject);
+ static void SetupCutsceneToStart(void);
+ static void SetCutsceneAnim(const char *animName, CObject *pObject);
+ static CCutsceneHead *AddCutsceneHead(CObject *pObject, int modelId);
+ static CCutsceneObject *CreateCutsceneObject(int modelId);
+ static void DeleteCutsceneData(void);
+ static void Update(void);
};
diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp
index effcb0b4..30b80634 100644
--- a/src/core/Frontend.cpp
+++ b/src/core/Frontend.cpp
@@ -2383,7 +2383,7 @@ void CMenuManager::SwitchToNewScreen(int32 screen)
// Set player skin.
if (m_nCurrScreen == MENUPAGE_SKIN_SELECT) {
- CPlayerSkin::BeginFrontEndSkinEdit();
+ CPlayerSkin::BeginFrontendSkinEdit();
m_bSkinsFound = false;
}
diff --git a/src/core/General.h b/src/core/General.h
index 366c571c..d73cf36f 100644
--- a/src/core/General.h
+++ b/src/core/General.h
@@ -54,14 +54,7 @@ public:
static float LimitRadianAngle(float angle)
{
- float result;
-
- if (angle < -25.0f)
- result = -25.0f;
- else if (angle > 25.0f)
- result = 25.0f;
- else
- result = angle;
+ float result = clamp(angle, -25.0f, 25.0f);
while (result >= PI) {
result -= 2 * PI;
diff --git a/src/core/Pad.h b/src/core/Pad.h
index 4f129e85..eca334ee 100644
--- a/src/core/Pad.h
+++ b/src/core/Pad.h
@@ -368,6 +368,7 @@ public:
bool GetLeftShoulder2JustDown() { return !!(NewState.LeftShoulder2 && !OldState.LeftShoulder2); }
bool GetRightShoulder1JustDown() { return !!(NewState.RightShoulder1 && !OldState.RightShoulder1); }
bool GetRightShoulder2JustDown() { return !!(NewState.RightShoulder2 && !OldState.RightShoulder2); }
+ bool GetStartJustDown() { return !!(NewState.Start && !OldState.Start); }
/*
int32 GetLeftShoulder1(void) { return NewState.LeftShoulder1; }
diff --git a/src/core/PlayerInfo.cpp b/src/core/PlayerInfo.cpp
index 8c505eb4..dc72848d 100644
--- a/src/core/PlayerInfo.cpp
+++ b/src/core/PlayerInfo.cpp
@@ -4,9 +4,9 @@
#include "PlayerInfo.h"
#include "Frontend.h"
#include "Vehicle.h"
+#include "PlayerSkin.h"
WRAPPER void CPlayerInfo::MakePlayerSafe(bool) { EAXJMP(0x4A1400); }
-WRAPPER void CPlayerInfo::LoadPlayerSkin() { EAXJMP(0x4A1700); }
WRAPPER void CPlayerInfo::AwardMoneyForExplosion(CVehicle *vehicle) { EAXJMP(0x4A15F0); }
WRAPPER void CPlayerInfo::Process(void) { EAXJMP(0x49FD30); }
@@ -22,3 +22,25 @@ CVector& CPlayerInfo::GetPos()
return m_pPed->m_pMyVehicle->GetPosition();
return m_pPed->GetPosition();
}
+
+void CPlayerInfo::LoadPlayerSkin()
+{
+ DeletePlayerSkin();
+
+ m_pSkinTexture = CPlayerSkin::GetSkinTexture(m_aSkinName);
+ if (!m_pSkinTexture)
+ m_pSkinTexture = CPlayerSkin::GetSkinTexture(DEFAULT_SKIN_NAME);
+}
+
+void CPlayerInfo::DeletePlayerSkin()
+{
+ if (m_pSkinTexture) {
+ RwTextureDestroy(m_pSkinTexture);
+ m_pSkinTexture = NULL;
+ }
+}
+
+STARTPATCHES
+InjectHook(0x4A1700, &CPlayerInfo::LoadPlayerSkin, PATCH_JUMP);
+InjectHook(0x4A1750, &CPlayerInfo::DeletePlayerSkin, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/core/PlayerInfo.h b/src/core/PlayerInfo.h
index 29290f6e..f0b879ee 100644
--- a/src/core/PlayerInfo.h
+++ b/src/core/PlayerInfo.h
@@ -68,6 +68,7 @@ public:
void MakePlayerSafe(bool);
void LoadPlayerSkin();
+ void DeletePlayerSkin();
void AwardMoneyForExplosion(CVehicle *vehicle);
void SetPlayerSkin(char* skin);
CVector& GetPos();
diff --git a/src/core/PlayerSkin.cpp b/src/core/PlayerSkin.cpp
index 1c9ca2c6..111333ec 100644
--- a/src/core/PlayerSkin.cpp
+++ b/src/core/PlayerSkin.cpp
@@ -1,5 +1,169 @@
#include "common.h"
#include "patcher.h"
+#include "main.h"
#include "PlayerSkin.h"
+#include "TxdStore.h"
+#include "rtbmp.h"
+#include "ClumpModelInfo.h"
+#include "VisibilityPlugins.h"
+#include "World.h"
+#include "PlayerInfo.h"
+#include "CdStream.h"
+#include "FileMgr.h"
+#include "Directory.h"
+#include "RwHelper.h"
+#include "Timer.h"
+#include "Lights.h"
-WRAPPER void CPlayerSkin::BeginFrontEndSkinEdit() { EAXJMP(0x59BC70); }
+int CPlayerSkin::m_txdSlot;
+
+void
+FindPlayerDff(uint32 &offset, uint32 &size)
+{
+ int file;
+ CDirectory::DirectoryInfo info;
+
+ file = CFileMgr::OpenFile("models\\gta3.dir", "rb");
+
+ do {
+ if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo)))
+ return;
+ } while (strcmpi("player.dff", info.name));
+
+ offset = info.offset;
+ size = info.size;
+}
+
+void
+LoadPlayerDff(void)
+{
+ RwStream *stream;
+ RwMemory mem;
+ uint32 offset, size;
+ uint8 *buffer;
+ bool streamWasAdded = false;
+
+ if (CdStreamGetNumImages() == 0) {
+ CdStreamAddImage("models\\gta3.img");
+ streamWasAdded = true;
+ }
+
+ FindPlayerDff(offset, size);
+ buffer = (uint8*)RwMallocAlign(size << 11, 2048);
+ CdStreamRead(0, buffer, offset, size);
+ CdStreamSync(0);
+
+ mem.start = buffer;
+ mem.length = size << 11;
+ stream = RwStreamOpen(rwSTREAMMEMORY, rwSTREAMREAD, &mem);
+
+ if (RwStreamFindChunk(stream, rwID_CLUMP, nil, nil))
+ gpPlayerClump = RpClumpStreamRead(stream);
+
+ RwStreamClose(stream, &mem);
+ RwFreeAlign(buffer);
+
+ if (streamWasAdded)
+ CdStreamRemoveImages();
+}
+
+void
+CPlayerSkin::Initialise(void)
+{
+ m_txdSlot = CTxdStore::AddTxdSlot("skin");
+ CTxdStore::Create(m_txdSlot);
+ CTxdStore::AddRef(m_txdSlot);
+}
+
+void
+CPlayerSkin::Shutdown(void)
+{
+ CTxdStore::RemoveTxdSlot(m_txdSlot);
+}
+
+RwTexture *
+CPlayerSkin::GetSkinTexture(const char *texName)
+{
+ RwTexture *tex;
+ RwRaster *raster;
+ int32 width, height, depth, format;
+
+ CTxdStore::PushCurrentTxd();
+ CTxdStore::SetCurrentTxd(m_txdSlot);
+ tex = RwTextureRead(texName, NULL);
+ CTxdStore::PopCurrentTxd();
+ if (tex) return tex;
+
+ if (!strcmp(DEFAULT_SKIN_NAME, texName))
+ sprintf(gString, "models\\generic\\player.bmp");
+ else
+ sprintf(gString, "skins\\%s.bmp", texName);
+
+ if (RwImage *image = RtBMPImageRead(gString)) {
+ RwImageFindRasterFormat(image, rwRASTERTYPETEXTURE, &width, &height, &depth, &format);
+ raster = RwRasterCreate(width, height, depth, format);
+ RwRasterSetFromImage(raster, image);
+
+ tex = RwTextureCreate(raster);
+ RwTextureSetName(tex, texName);
+ RwTextureSetFilterMode(tex, rwFILTERLINEAR); // filtering bugfix from VC
+ RwTexDictionaryAddTexture(CTxdStore::GetSlot(m_txdSlot)->texDict, tex);
+
+ RwImageDestroy(image);
+ }
+ return tex;
+}
+
+void
+CPlayerSkin::BeginFrontendSkinEdit(void)
+{
+ LoadPlayerDff();
+ RpClumpForAllAtomics(gpPlayerClump, CClumpModelInfo::SetAtomicRendererCB, CVisibilityPlugins::RenderPlayerCB);
+ CWorld::Players[0].LoadPlayerSkin();
+ gOldFov = CDraw::GetFOV();
+ CDraw::SetFOV(30.0f);
+}
+
+void
+CPlayerSkin::EndFrontendSkinEdit(void)
+{
+ RpClumpDestroy(gpPlayerClump);
+ gpPlayerClump = NULL;
+ CDraw::SetFOV(gOldFov);
+}
+
+void
+CPlayerSkin::RenderFrontendSkinEdit(void)
+{
+ static float rotation = 0.0f;
+ RwRGBAReal AmbientColor = { 0.65f, 0.65f, 0.65f, 1.0f };
+ const RwV3d pos = { 1.35f, 0.35f, 7.725f };
+ const RwV3d axis1 = { 1.0f, 0.0f, 0.0f };
+ const RwV3d axis2 = { 0.0f, 0.0f, 1.0f };
+ static uint32 LastFlash = 0;
+
+ RwFrame *frame = RpClumpGetFrame(gpPlayerClump);
+
+ if (CTimer::GetTimeInMillisecondsPauseMode() - LastFlash > 7) {
+ rotation += 2.0f;
+ if (rotation > 360.0f)
+ rotation -= 360.0f;
+ LastFlash = CTimer::GetTimeInMillisecondsPauseMode();
+ }
+ RwFrameTransform(frame, RwFrameGetMatrix(RwCameraGetFrame(Scene.camera)), rwCOMBINEREPLACE);
+ RwFrameTranslate(frame, &pos, rwCOMBINEPRECONCAT);
+ RwFrameRotate(frame, &axis1, -90.0f, rwCOMBINEPRECONCAT);
+ RwFrameRotate(frame, &axis2, rotation, rwCOMBINEPRECONCAT);
+ RwFrameUpdateObjects(frame);
+ SetAmbientColours(&AmbientColor);
+ RpClumpRender(gpPlayerClump);
+}
+
+STARTPATCHES
+InjectHook(0x59B9B0, &CPlayerSkin::Initialise, PATCH_JUMP);
+InjectHook(0x59B9E0, &CPlayerSkin::Shutdown, PATCH_JUMP);
+InjectHook(0x59B9F0, &CPlayerSkin::GetSkinTexture, PATCH_JUMP);
+InjectHook(0x59BC70, &CPlayerSkin::BeginFrontendSkinEdit, PATCH_JUMP);
+InjectHook(0x59BCB0, &CPlayerSkin::EndFrontendSkinEdit, PATCH_JUMP);
+InjectHook(0x59BCE0, &CPlayerSkin::RenderFrontendSkinEdit, PATCH_JUMP);
+ENDPATCHES \ No newline at end of file
diff --git a/src/core/PlayerSkin.h b/src/core/PlayerSkin.h
index 61e09cdf..2d82ec12 100644
--- a/src/core/PlayerSkin.h
+++ b/src/core/PlayerSkin.h
@@ -1,7 +1,21 @@
#pragma once
+#define DEFAULT_SKIN_NAME "$$\"\""
+
+static RpClump *gpPlayerClump;// = *(RpClump**)0x660FF8;
+static float gOldFov;// = *(float*)0x660FFC;
+
+void LoadPlayerDff(void);
+void FindPlayerDff(uint32 &offset, uint32 &size);
+
class CPlayerSkin
{
+ static int m_txdSlot;
public:
- static void BeginFrontEndSkinEdit();
+ static void Initialise();
+ static void Shutdown();
+ static RwTexture *GetSkinTexture(const char *texName);
+ static void BeginFrontendSkinEdit();
+ static void EndFrontendSkinEdit();
+ static void RenderFrontendSkinEdit();
}; \ No newline at end of file
diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp
index a76bbb6d..847fa753 100644
--- a/src/core/Pools.cpp
+++ b/src/core/Pools.cpp
@@ -13,6 +13,7 @@ CDummyPool *&CPools::ms_pDummyPool = *(CDummyPool**)0x8F2C18;
CAudioScriptObjectPool *&CPools::ms_pAudioScriptObjectPool = *(CAudioScriptObjectPool**)0x8F1B6C;
WRAPPER void CPools::Initialise(void) { EAXJMP(0x4A1770); }
+WRAPPER void CPools::MakeSureSlotInObjectPoolIsEmpty(int32 handle) { EAXJMP(0x4A2DB0); }
#if 0
void
diff --git a/src/core/Pools.h b/src/core/Pools.h
index bdf668c2..4e6bd547 100644
--- a/src/core/Pools.h
+++ b/src/core/Pools.h
@@ -49,4 +49,5 @@ public:
static CVehicle *GetVehicle(int32 handle);
static int32 GetObjectRef(CObject *object);
static CObject *GetObject(int32 handle);
+ static void MakeSureSlotInObjectPoolIsEmpty(int32 handle);
};
diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp
index f04e14d1..0d6cbc82 100644
--- a/src/core/Radar.cpp
+++ b/src/core/Radar.cpp
@@ -16,8 +16,7 @@
#include "Streaming.h"
float &CRadar::m_RadarRange = *(float*)0x8E281C;
-CBlip *CRadar::ms_RadarTrace = (CBlip*)0x6ED5E0;
-
+CBlip (&CRadar::ms_RadarTrace)[NUMRADARBLIPS] = *(CBlip(*)[NUMRADARBLIPS]) * (uintptr*)0x6ED5E0;
CVector2D &vec2DRadarOrigin = *(CVector2D*)0x6299B8;
int *gRadarTxdIds = (int*)0x6299C0;
@@ -78,13 +77,13 @@ static_assert(RADAR_TILE_SIZE == (WORLD_SIZE_Y / RADAR_NUM_TILES), "CRadar: not
#if 0
WRAPPER void CRadar::CalculateBlipAlpha(float) { EAXJMP(0x4A4F90); }
#else
-int CRadar::CalculateBlipAlpha(float dist)
+uint8 CRadar::CalculateBlipAlpha(float dist)
{
if (dist <= 1.0f)
return 255;
if (dist <= 5.0f)
- return (((1.0f - ((dist * 0.25f) - 0.25f)) * 255.0f) + (((dist * 0.25f) - 0.25f) * 128.0f));
+ return (128.0f * ((dist - 1.0f) / 4.0f)) + ((1.0f - (dist - 1.0f) / 4.0f) * 255.0f);
return 128;
}
@@ -109,18 +108,18 @@ void CRadar::ChangeBlipColour(int32 i, int32)
#endif
#if 1
-WRAPPER void CRadar::ChangeBlipDisplay(int32, int16) { EAXJMP(0x4A5810); }
+WRAPPER void CRadar::ChangeBlipDisplay(int32, eBlipDisplay) { EAXJMP(0x4A5810); }
#else
-void CRadar::ChangeBlipDisplay(int32 i, int16 flag)
+void CRadar::ChangeBlipDisplay(int32 i, eBlipDisplay display)
{
}
#endif
#if 1
-WRAPPER void CRadar::ChangeBlipScale(int32, int16) { EAXJMP(0x4A57E0); }
+WRAPPER void CRadar::ChangeBlipScale(int32, int32) { EAXJMP(0x4A57E0); }
#else
-void CRadar::ChangeBlipScale(int32 i, int16 scale)
+void CRadar::ChangeBlipScale(int32 i, int32 scale)
{
}
@@ -136,17 +135,17 @@ void CRadar::ClearBlip(int32 i)
#endif
#if 0
-WRAPPER void CRadar::ClearBlipForEntity(int16, int32) { EAXJMP(0x4A56C0); }
+WRAPPER void CRadar::ClearBlipForEntity(eBlipType, int32) { EAXJMP(0x4A56C0); }
#else
-void CRadar::ClearBlipForEntity(int16 type, int32 id)
+void CRadar::ClearBlipForEntity(eBlipType type, int32 id)
{
for (int i = 0; i < NUMRADARBLIPS; i++) {
if (type == ms_RadarTrace[i].m_eBlipType && id == ms_RadarTrace[i].m_nEntityHandle) {
- SetRadarMarkerState(i, 0);
- ms_RadarTrace[i].m_bInUse = 0;
- ms_RadarTrace[i].m_eBlipType = 0;
- ms_RadarTrace[i].m_eBlipDisplay = 0;
- ms_RadarTrace[i].m_IconID = 0;
+ SetRadarMarkerState(i, false);
+ ms_RadarTrace[i].m_bInUse = false;
+ ms_RadarTrace[i].m_eBlipType = BLIP_NONE;
+ ms_RadarTrace[i].m_eBlipDisplay = BLIP_DISPLAY_NEITHER;
+ ms_RadarTrace[i].m_IconID = RADAR_SPRITE_NONE;
}
};
}
@@ -278,6 +277,10 @@ void CRadar::DrawBlips()
float angle;
if (TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN1)
angle = PI + FindPlayerHeading();
+#ifdef FIX_BUGS
+ else if (TheCamera.GetLookDirection() != LOOKING_FORWARD)
+ angle = FindPlayerHeading() - (PI + (TheCamera.Cams[TheCamera.ActiveCam].CamTargetEntity->GetPosition() - TheCamera.Cams[TheCamera.ActiveCam].SourceBeforeLookBehind).Heading());
+#endif
else
angle = FindPlayerHeading() - (PI + TheCamera.GetForward().Heading());
@@ -291,82 +294,224 @@ void CRadar::DrawBlips()
TransformRadarPointToScreenSpace(out, in);
DrawRadarSprite(RADAR_SPRITE_NORTH, out.x, out.y, 255);
- /*
- DrawEntityBlip
- */
- for (int i = 0; i < NUMRADARBLIPS; i++) {
- if (ms_RadarTrace[i].m_bInUse) {
- if (ms_RadarTrace[i].m_eBlipType <= BLIP_OBJECT) {
- CEntity *e = nil;
- switch (ms_RadarTrace[i].m_eBlipType) {
- case BLIP_CAR:
- e = CPools::GetVehiclePool()->GetAt(ms_RadarTrace[i].m_nEntityHandle);
- break;
- case BLIP_CHAR:
- e = CPools::GetPedPool()->GetAt(ms_RadarTrace[i].m_nEntityHandle);
- break;
- case BLIP_OBJECT:
- e = CPools::GetObjectPool()->GetAt(ms_RadarTrace[i].m_nEntityHandle);
- break;
- };
-
- if (e) {
- if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
+ CEntity *blipEntity = nil;
+ for(int blipId = 0; blipId < NUMRADARBLIPS; blipId++) {
+ if (!ms_RadarTrace[blipId].m_bInUse)
+ continue;
+
+ switch (ms_RadarTrace[blipId].m_eBlipType) {
+ case BLIP_CAR:
+ case BLIP_CHAR:
+ case BLIP_OBJECT:
+ if (ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_BOMB || ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_SAVE
+ || ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_SPRAY || ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_WEAPON) {
+
+ switch (ms_RadarTrace[blipId].m_eBlipType) {
+ case BLIP_CAR:
+ blipEntity = CPools::GetVehiclePool()->GetAt(ms_RadarTrace[blipId].m_nEntityHandle);
+ break;
+ case BLIP_CHAR:
+ blipEntity = CPools::GetPedPool()->GetAt(ms_RadarTrace[blipId].m_nEntityHandle);
+ if (blipEntity && ((CPed*)blipEntity)->bInVehicle && ((CPed*)blipEntity)->m_pMyVehicle) {
+ blipEntity = ((CPed*)blipEntity)->m_pMyVehicle;
+ }
+ break;
+ case BLIP_OBJECT:
+ blipEntity = CPools::GetObjectPool()->GetAt(ms_RadarTrace[blipId].m_nEntityHandle);
+ break;
+ default:
+ break;
+ }
+ if (blipEntity) {
+ uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
+ if (CTheScripts::DbgFlag) {
+ ShowRadarMarker(blipEntity->GetPosition(), color, ms_RadarTrace[blipId].m_Radius);
+ ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
+ if (ms_RadarTrace[blipId].m_Radius < 1.0f)
+ ms_RadarTrace[blipId].m_Radius = 5.0f;
+ }
+ }
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
+ TransformRealWorldPointToRadarSpace(in, blipEntity->GetPosition());
+ float dist = LimitRadarPoint(in);
+ TransformRadarPointToScreenSpace(out, in);
+ if (ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_NONE) {
+ DrawRadarSprite(ms_RadarTrace[blipId].m_IconID, out.x, out.y, CalculateBlipAlpha(dist));
+ } else {
+#ifdef TRIANGULAR_BLIPS
+ CVector &pos = FindPlayerCentreOfWorld_NoSniperShift();
+ CVector &blipPos = blipEntity->GetPosition();
+ uint8 mode = BLIP_MODE_TRIANGULAR_UP;
+ if (blipPos.z - pos.z <= 2.0f) {
+ if (blipPos.z - pos.z < -4.0f) mode = BLIP_MODE_TRIANGULAR_DOWN;
+ else mode = BLIP_MODE_SQUARE;
+ }
+ ShowRadarTraceWithHeight(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255, mode);
+#else
+ ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255);
+#endif
+ }
+ }
+ }
+ }
+ break;
+ case BLIP_COORD:
+ case BLIP_CONTACT_POINT:
+ if ((ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_BOMB || ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_SAVE
+ || ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_SPRAY || ms_RadarTrace[blipId].m_IconID == RADAR_SPRITE_WEAPON)
+ && (ms_RadarTrace[blipId].m_eBlipType != BLIP_CONTACT_POINT || !CTheScripts::IsPlayerOnAMission())) {
+
+ uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) {
- ShowRadarMarker(e->GetPosition(), GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim), ms_RadarTrace->m_Radius);
-
- ms_RadarTrace[i].m_Radius = ms_RadarTrace[i].m_Radius - 0.1f;
- if (ms_RadarTrace[i].m_Radius >= 1.0f)
- ms_RadarTrace[i].m_Radius = 5.0;
+ ShowRadarMarker(ms_RadarTrace[blipId].m_vecPos, color, ms_RadarTrace[blipId].m_Radius);
+ ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
+ if (ms_RadarTrace[blipId].m_Radius < 1.0f)
+ ms_RadarTrace[blipId].m_Radius = 5.0f;
}
}
- if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
- vec2d = e->GetPosition();
- TransformRealWorldPointToRadarSpace(in, vec2d);
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
+ TransformRealWorldPointToRadarSpace(in, ms_RadarTrace[blipId].m_vec2DPos);
float dist = LimitRadarPoint(in);
- int a = CalculateBlipAlpha(dist);
TransformRadarPointToScreenSpace(out, in);
-
- int32 col = GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim);
-
- if (ms_RadarTrace[i].m_IconID)
- DrawRadarSprite(ms_RadarTrace[i].m_IconID, out.x, out.y, a);
- else
- ShowRadarTrace(out.x, out.y, ms_RadarTrace[i].m_wScale, ((col >> 24)), ((col >> 16) & 0xFF), ((col >> 8)), 255);
+ if (ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_NONE) {
+ DrawRadarSprite(ms_RadarTrace[blipId].m_IconID, out.x, out.y, CalculateBlipAlpha(dist));
+ } else {
+#ifdef TRIANGULAR_BLIPS
+ CVector &pos = FindPlayerCentreOfWorld_NoSniperShift();
+ CVector &blipPos = ms_RadarTrace[blipId].m_vecPos;
+ uint8 mode = BLIP_MODE_TRIANGULAR_UP;
+ if (blipPos.z - pos.z <= 2.0f) {
+ if (blipPos.z - pos.z < -4.0f) mode = BLIP_MODE_TRIANGULAR_DOWN;
+ else mode = BLIP_MODE_SQUARE;
+ }
+ ShowRadarTraceWithHeight(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255, mode);
+#else
+ ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255);
+#endif
+ }
}
}
- }
+ break;
+ default:
+ break;
+ }
+ }
+ for(int blipId = 0; blipId < NUMRADARBLIPS; blipId++) {
+ if (!ms_RadarTrace[blipId].m_bInUse)
+ continue;
+
+ switch (ms_RadarTrace[blipId].m_eBlipType) {
+ case BLIP_CAR:
+ case BLIP_CHAR:
+ case BLIP_OBJECT:
+ if (ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_BOMB && ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_SAVE
+ && ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_SPRAY && ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_WEAPON) {
+
+ switch (ms_RadarTrace[blipId].m_eBlipType) {
+ case BLIP_CAR:
+ blipEntity = CPools::GetVehiclePool()->GetAt(ms_RadarTrace[blipId].m_nEntityHandle);
+ break;
+ case BLIP_CHAR:
+ blipEntity = CPools::GetPedPool()->GetAt(ms_RadarTrace[blipId].m_nEntityHandle);
+ if (blipEntity && ((CPed*)blipEntity)->bInVehicle && ((CPed*)blipEntity)->m_pMyVehicle) {
+ blipEntity = ((CPed*)blipEntity)->m_pMyVehicle;
+ }
+ break;
+ case BLIP_OBJECT:
+ blipEntity = CPools::GetObjectPool()->GetAt(ms_RadarTrace[blipId].m_nEntityHandle);
+ break;
+ default:
+ break;
+ }
- /*
- DrawCoordBlip
- */
- if (ms_RadarTrace[i].m_eBlipType >= BLIP_COORD) {
- if (ms_RadarTrace[i].m_eBlipType != BLIP_CONTACT_POINT || ms_RadarTrace[i].m_eBlipType == BLIP_CONTACT_POINT && DisplayThisBlip(i) || !CTheScripts::IsPlayerOnAMission()) {
- if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
+ if (blipEntity) {
+ uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
+ if (CTheScripts::DbgFlag) {
+ ShowRadarMarker(blipEntity->GetPosition(), color, ms_RadarTrace[blipId].m_Radius);
+ ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
+ if (ms_RadarTrace[blipId].m_Radius < 1.0f)
+ ms_RadarTrace[blipId].m_Radius = 5.0f;
+ }
+ }
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
+ TransformRealWorldPointToRadarSpace(in, blipEntity->GetPosition());
+ float dist = LimitRadarPoint(in);
+ TransformRadarPointToScreenSpace(out, in);
+ if (ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_NONE)
+ DrawRadarSprite(ms_RadarTrace[blipId].m_IconID, out.x, out.y, CalculateBlipAlpha(dist));
+ else
+#ifdef TRIANGULAR_BLIPS
+ {
+ CVector &pos = FindPlayerCentreOfWorld_NoSniperShift();
+ CVector &blipPos = blipEntity->GetPosition();
+ uint8 mode = BLIP_MODE_TRIANGULAR_UP;
+ if (blipPos.z - pos.z <= 2.0f) {
+ if (blipPos.z - pos.z < -4.0f) mode = BLIP_MODE_TRIANGULAR_DOWN;
+ else mode = BLIP_MODE_SQUARE;
+ }
+ ShowRadarTraceWithHeight(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255, mode);
+ }
+#else
+ ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255);
+#endif
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ for (int blipId = 0; blipId < NUMRADARBLIPS; blipId++) {
+ if (!ms_RadarTrace[blipId].m_bInUse)
+ continue;
+
+ switch (ms_RadarTrace[blipId].m_eBlipType) {
+ case BLIP_COORD:
+ case BLIP_CONTACT_POINT:
+ if (ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_BOMB && ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_SAVE
+ && ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_SPRAY && ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_WEAPON
+ && (ms_RadarTrace[blipId].m_eBlipType != BLIP_CONTACT_POINT || !CTheScripts::IsPlayerOnAMission())) {
+
+ uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) {
- ShowRadarMarker(ms_RadarTrace[i].m_vecPos, GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim), ms_RadarTrace->m_Radius);
- ms_RadarTrace[i].m_Radius = ms_RadarTrace[i].m_Radius - 0.1f;
- if (ms_RadarTrace[i].m_Radius >= 1.0f)
- ms_RadarTrace[i].m_Radius = 5.0f;
+ ShowRadarMarker(ms_RadarTrace[blipId].m_vecPos, color, ms_RadarTrace[blipId].m_Radius);
+ ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
+ if (ms_RadarTrace[blipId].m_Radius < 1.0f)
+ ms_RadarTrace[blipId].m_Radius = 5.0f;
}
}
-
- if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
- TransformRealWorldPointToRadarSpace(in, ms_RadarTrace[i].m_vec2DPos);
+ if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) {
+ TransformRealWorldPointToRadarSpace(in, ms_RadarTrace[blipId].m_vec2DPos);
float dist = LimitRadarPoint(in);
- int a = CalculateBlipAlpha(dist);
TransformRadarPointToScreenSpace(out, in);
-
- int32 col = GetRadarTraceColour(ms_RadarTrace[i].m_nColor, ms_RadarTrace[i].m_bDim);
-
- if (ms_RadarTrace[i].m_IconID)
- DrawRadarSprite(ms_RadarTrace[i].m_IconID, out.x, out.y, a);
+ if (ms_RadarTrace[blipId].m_IconID != RADAR_SPRITE_NONE)
+ DrawRadarSprite(ms_RadarTrace[blipId].m_IconID, out.x, out.y, CalculateBlipAlpha(dist));
else
- ShowRadarTrace(out.x, out.y, ms_RadarTrace[i].m_wScale, ((col >> 24)), ((col >> 16) & 0xFF), ((col >> 8)), 255);
+#ifdef TRIANGULAR_BLIPS
+ {
+ CVector &pos = FindPlayerCentreOfWorld_NoSniperShift();
+ CVector &blipPos = ms_RadarTrace[blipId].m_vecPos;
+ uint8 mode = BLIP_MODE_TRIANGULAR_UP;
+ if (blipPos.z - pos.z <= 2.0f) {
+ if (blipPos.z - pos.z < -4.0f) mode = BLIP_MODE_TRIANGULAR_DOWN;
+ else mode = BLIP_MODE_SQUARE;
+ }
+ ShowRadarTraceWithHeight(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255, mode);
+ }
+#else
+ ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255);
+#endif
}
}
- }
- };
+ break;
+ default:
+ break;
+ }
}
}
}
@@ -531,9 +676,9 @@ void CRadar::DrawRadarSection(int32 x, int32 y)
#endif
#if 0
-WRAPPER void CRadar::DrawRadarSprite(int32 sprite, float x, float y, int32 alpha) { EAXJMP(0x4A5EF0); }
+WRAPPER void CRadar::DrawRadarSprite(uint16 sprite, float x, float y, uint8 alpha) { EAXJMP(0x4A5EF0); }
#else
-void CRadar::DrawRadarSprite(int32 sprite, float x, float y, int32 alpha)
+void CRadar::DrawRadarSprite(uint16 sprite, float x, float y, uint8 alpha)
{
RadarSprites[sprite]->Draw(CRect(x - SCREEN_SCALE_X(8.0f), y - SCREEN_SCALE_Y(8.0f), x + SCREEN_SCALE_X(8.0f), y + SCREEN_SCALE_Y(8.0f)), CRGBA(255, 255, 255, alpha));
}
@@ -570,12 +715,17 @@ void CRadar::DrawRotatingRadarSprite(CSprite2d* sprite, float x, float y, float
}
#endif
-#if 1
+#if 0
WRAPPER int32 CRadar::GetActualBlipArrayIndex(int32) { EAXJMP(0x4A41C0); }
#else
int32 CRadar::GetActualBlipArrayIndex(int32 i)
{
- return int32();
+ if (i == -1)
+ return -1;
+ else if ((i & 0xFFFF0000) >> 16 != ms_RadarTrace[(uint16)i].m_BlipIndex)
+ return -1;
+ else
+ return (uint16)i;
}
#endif
@@ -589,9 +739,9 @@ int32 CRadar::GetNewUniqueBlipIndex(int32 i)
#endif
#if 0
-WRAPPER int32 CRadar::GetRadarTraceColour(int32 color, bool bright) { EAXJMP(0x4A5BB0); }
+WRAPPER uint32 CRadar::GetRadarTraceColour(uint32 color, bool bright) { EAXJMP(0x4A5BB0); }
#else
-int32 CRadar::GetRadarTraceColour(int32 color, bool bright)
+uint32 CRadar::GetRadarTraceColour(uint32 color, bool bright)
{
int32 c;
switch (color) {
@@ -605,13 +755,13 @@ int32 CRadar::GetRadarTraceColour(int32 color, bool bright)
if (bright)
c = 0x5FA06AFF;
else
- c = 0x7F00FF;
+ c = 0x007F00FF;
break;
case 2:
if (bright)
c = 0x80A7F3FF;
else
- c = 0x007FFF;
+ c = 0x00007FFF;
break;
case 3:
if (bright)
@@ -633,9 +783,9 @@ int32 CRadar::GetRadarTraceColour(int32 color, bool bright)
break;
case 6:
if (bright)
- c = 0xFFFFFF;
+ c = 0x00FFFFFF;
else
- c = 0x7F7FFF;
+ c = 0x007F7FFF;
break;
default:
c = color;
@@ -727,37 +877,70 @@ void CRadar::SaveAllRadarBlips(int32)
}
#endif
-#if 1
+#if 0
WRAPPER void CRadar::SetBlipSprite(int32, int32) { EAXJMP(0x4A5840); }
#else
void CRadar::SetBlipSprite(int32 i, int32 icon)
{
-
+ int index = CRadar::GetActualBlipArrayIndex(i);
+ if (index != -1) {
+ ms_RadarTrace[index].m_IconID = icon;
+ }
}
#endif
-#if 1
-WRAPPER int32 CRadar::SetCoordBlip(eBlipType, CVector, int32, eBlipDisplay) { EAXJMP(0x4A5590); }
+#if 0
+WRAPPER int32 CRadar::SetCoordBlip(eBlipType, CVector, int32, eBlipDisplay display) { EAXJMP(0x4A5590); }
#else
-int CRadar::SetCoordBlip(eBlipType type, CVector pos, int32 flag, eBlipDisplay)
+int CRadar::SetCoordBlip(eBlipType type, CVector pos, int32 color, eBlipDisplay display)
{
- return 0;
+ int nextBlip;
+ for (nextBlip = 0; nextBlip < NUMRADARBLIPS; nextBlip++) {
+ if (!ms_RadarTrace[nextBlip].m_bInUse)
+ break;
+ }
+ ms_RadarTrace[nextBlip].m_eBlipType = type;
+ ms_RadarTrace[nextBlip].m_nColor = color;
+ ms_RadarTrace[nextBlip].m_bDim = 1;
+ ms_RadarTrace[nextBlip].m_bInUse = 1;
+ ms_RadarTrace[nextBlip].m_Radius = 1.0f;
+ ms_RadarTrace[nextBlip].m_vec2DPos = pos;
+ ms_RadarTrace[nextBlip].m_vecPos = pos;
+ ms_RadarTrace[nextBlip].m_nEntityHandle = 0;
+ ms_RadarTrace[nextBlip].m_wScale = 1;
+ ms_RadarTrace[nextBlip].m_eBlipDisplay = display;
+ ms_RadarTrace[nextBlip].m_IconID = RADAR_SPRITE_NONE;
+ return CRadar::GetNewUniqueBlipIndex(nextBlip);
}
#endif
-#if 1
+#if 0
WRAPPER int CRadar::SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay) { EAXJMP(0x4A5640); }
#else
-int CRadar::SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay)
+int CRadar::SetEntityBlip(eBlipType type, int32 handle, int32 color, eBlipDisplay display)
{
- return 0;
+ int nextBlip;
+ for (nextBlip = 0; nextBlip < NUMRADARBLIPS; nextBlip++) {
+ if (!ms_RadarTrace[nextBlip].m_bInUse)
+ break;
+ }
+ ms_RadarTrace[nextBlip].m_eBlipType = type;
+ ms_RadarTrace[nextBlip].m_nColor = color;
+ ms_RadarTrace[nextBlip].m_bDim = 1;
+ ms_RadarTrace[nextBlip].m_bInUse = 1;
+ ms_RadarTrace[nextBlip].m_Radius = 1.0f;
+ ms_RadarTrace[nextBlip].m_nEntityHandle = handle;
+ ms_RadarTrace[nextBlip].m_wScale = 1;
+ ms_RadarTrace[nextBlip].m_eBlipDisplay = display;
+ ms_RadarTrace[nextBlip].m_IconID = RADAR_SPRITE_NONE;
+ return CRadar::GetNewUniqueBlipIndex(nextBlip);
}
#endif
#if 0
-WRAPPER void CRadar::SetRadarMarkerState(int32, int32) { EAXJMP(0x4A5C60); }
+WRAPPER void CRadar::SetRadarMarkerState(int32, bool) { EAXJMP(0x4A5C60); }
#else
-void CRadar::SetRadarMarkerState(int32 counter, int32 flag)
+void CRadar::SetRadarMarkerState(int32 counter, bool flag)
{
CEntity *e;
switch (ms_RadarTrace[counter].m_eBlipType) {
@@ -780,11 +963,11 @@ void CRadar::SetRadarMarkerState(int32 counter, int32 flag)
#endif
#if 0
-WRAPPER void CRadar::ShowRadarMarker(CVector pos, int16 color, float radius) { EAXJMP(0x4A59C0); }
+WRAPPER void CRadar::ShowRadarMarker(CVector pos, uint32 color, float radius) { EAXJMP(0x4A59C0); }
#else
-void CRadar::ShowRadarMarker(CVector pos, int16 color, float radius) {
- float f1 = radius * 0.5f;
- float f2 = radius * 1.4f;
+void CRadar::ShowRadarMarker(CVector pos, uint32 color, float radius) {
+ float f1 = radius * 1.4f;
+ float f2 = radius * 0.5f;
CVector p1, p2;
p1 = pos + TheCamera.GetUp()*f1;
@@ -806,15 +989,42 @@ void CRadar::ShowRadarMarker(CVector pos, int16 color, float radius) {
#endif
#if 0
-WRAPPER void CRadar::ShowRadarTrace(float x, float y, uint32 size, uint32 red, uint32 green, uint32 blue, uint32 alpha) { EAXJMP(0x4A5870); }
+WRAPPER void CRadar::ShowRadarTrace(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha) { EAXJMP(0x4A5870); }
#else
-void CRadar::ShowRadarTrace(float x, float y, uint32 size, uint32 red, uint32 green, uint32 blue, uint32 alpha)
+void CRadar::ShowRadarTrace(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha)
{
+ if (!CHud::m_Wants_To_Draw_Hud || TheCamera.m_WideScreenOn)
+ return;
+
CSprite2d::DrawRect(CRect(x - SCREEN_SCALE_X(size + 1.0f), y - SCREEN_SCALE_Y(size + 1.0f), SCREEN_SCALE_X(size + 1.0f) + x, SCREEN_SCALE_Y(size + 1.0f) + y), CRGBA(0, 0, 0, alpha));
CSprite2d::DrawRect(CRect(x - SCREEN_SCALE_X(size), y - SCREEN_SCALE_Y(size), SCREEN_SCALE_X(size) + x, SCREEN_SCALE_Y(size) + y), CRGBA(red, green, blue, alpha));
}
#endif
+void CRadar::ShowRadarTraceWithHeight(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha, uint8 mode)
+{
+ if (!CHud::m_Wants_To_Draw_Hud || TheCamera.m_WideScreenOn)
+ return;
+
+ switch (mode)
+ {
+ case BLIP_MODE_TRIANGULAR_UP:
+ // size++; // VC does size + 1 for triangles
+ CSprite2d::Draw2DPolygon(x + SCREEN_SCALE_X(size + 3.0f), y + SCREEN_SCALE_Y(size + 2.0f), x - (SCREEN_SCALE_X(size + 3.0f)), y + SCREEN_SCALE_Y(size + 2.0f), x, y - (SCREEN_SCALE_Y(size + 3.0f)), x, y - (SCREEN_SCALE_Y(size + 3.0f)), CRGBA(0, 0, 0, alpha));
+ CSprite2d::Draw2DPolygon(x + SCREEN_SCALE_X(size + 1.0f), y + SCREEN_SCALE_Y(size + 1.0f), x - (SCREEN_SCALE_X(size + 1.0f)), y + SCREEN_SCALE_Y(size + 1.0f), x, y - (SCREEN_SCALE_Y(size + 1.0f)), x, y - (SCREEN_SCALE_Y(size + 1.0f)), CRGBA(red, green, blue, alpha));
+ break;
+ case BLIP_MODE_TRIANGULAR_DOWN:
+ // size++; // VC does size + 1 for triangles
+ CSprite2d::Draw2DPolygon(x, y + SCREEN_SCALE_Y(size + 2.0f), x, y + SCREEN_SCALE_Y(size + 3.0f), x + SCREEN_SCALE_X(size + 3.0f), y - (SCREEN_SCALE_Y(size + 2.0f)), x - (SCREEN_SCALE_X(size + 3.0f)), y - (SCREEN_SCALE_Y(size + 2.0f)), CRGBA(0, 0, 0, alpha));
+ CSprite2d::Draw2DPolygon(x, y + SCREEN_SCALE_Y(size + 1.0f), x, y + SCREEN_SCALE_Y(size + 1.0f), x + SCREEN_SCALE_X(size + 1.0f), y - (SCREEN_SCALE_Y(size + 1.0f)), x - (SCREEN_SCALE_X(size + 1.0f)), y - (SCREEN_SCALE_Y(size + 1.0f)), CRGBA(red, green, blue, alpha));
+ break;
+ case BLIP_MODE_SQUARE:
+ CSprite2d::DrawRect(CRect(x - SCREEN_SCALE_X(size + 1.0f), y - SCREEN_SCALE_Y(size + 1.0f), SCREEN_SCALE_X(size + 1.0f) + x, SCREEN_SCALE_Y(size + 1.0f) + y), CRGBA(0, 0, 0, alpha));
+ CSprite2d::DrawRect(CRect(x - SCREEN_SCALE_X(size), y - SCREEN_SCALE_Y(size), SCREEN_SCALE_X(size) + x, SCREEN_SCALE_Y(size) + y), CRGBA(red, green, blue, alpha));
+ break;
+ }
+}
+
#if 1
WRAPPER void CRadar::Shutdown() { EAXJMP(0x4A3F60); }
#else
@@ -1076,7 +1286,7 @@ STARTPATCHES
// InjectHook(0x4A3F60, CRadar::Shutdown, PATCH_JUMP);
// InjectHook(0x4A4030, CRadar::LoadTextures, PATCH_JUMP);
// InjectHook(0x4A4180, CRadar::GetNewUniqueBlipIndex, PATCH_JUMP);
-// InjectHook(0x4A41C0, CRadar::GetActualBlipArrayIndex, PATCH_JUMP);
+ InjectHook(0x4A41C0, CRadar::GetActualBlipArrayIndex, PATCH_JUMP);
InjectHook(0x4A4200, CRadar::DrawMap, PATCH_JUMP);
InjectHook(0x4A42F0, CRadar::DrawBlips, PATCH_JUMP);
// InjectHook(0x4A4C70, CRadar::Draw3dMarkers, PATCH_JUMP);
@@ -1086,18 +1296,18 @@ STARTPATCHES
InjectHook(0x4A50D0, CRadar::TransformRealWorldPointToRadarSpace, PATCH_JUMP);
InjectHook(0x4A5300, CRadar::TransformRadarPointToRealWorldSpace, PATCH_JUMP);
InjectHook(0x4A5530, CRadar::TransformRealWorldToTexCoordSpace, PATCH_JUMP);
-// InjectHook(0x4A5590, CRadar::SetCoordBlip, PATCH_JUMP);
-// InjectHook(0x4A5640, CRadar::SetEntityBlip, PATCH_JUMP);
+ InjectHook(0x4A5590, CRadar::SetCoordBlip, PATCH_JUMP);
+ InjectHook(0x4A5640, CRadar::SetEntityBlip, PATCH_JUMP);
InjectHook(0x4A56C0, CRadar::ClearBlipForEntity, PATCH_JUMP);
// InjectHook(0x4A5720, CRadar::ClearBlip, PATCH_JUMP);
// InjectHook(0x4A5770, CRadar::ChangeBlipColour, PATCH_JUMP);
// InjectHook(0x4A57A0, CRadar::ChangeBlipBrightness, PATCH_JUMP);
// InjectHook(0x4A57E0, CRadar::ChangeBlipScale, PATCH_JUMP);
// InjectHook(0x4A5810, CRadar::ChangeBlipDisplay, PATCH_JUMP);
-// InjectHook(0x4A5840, CRadar::SetBlipSprite, PATCH_JUMP);
+ InjectHook(0x4A5840, CRadar::SetBlipSprite, PATCH_JUMP);
InjectHook(0x4A5870, CRadar::ShowRadarTrace, PATCH_JUMP);
InjectHook(0x4A59C0, CRadar::ShowRadarMarker, PATCH_JUMP);
- //InjectHook(0x4A5BB0, CRadar::GetRadarTraceColour, PATCH_JUMP);
+ InjectHook(0x4A5BB0, CRadar::GetRadarTraceColour, PATCH_JUMP);
InjectHook(0x4A5C60, CRadar::SetRadarMarkerState, PATCH_JUMP);
InjectHook(0x4A5D10, CRadar::DrawRotatingRadarSprite, PATCH_JUMP);
InjectHook(0x4A5EF0, CRadar::DrawRadarSprite, PATCH_JUMP);
diff --git a/src/core/Radar.h b/src/core/Radar.h
index 1ec28070..d6b249db 100644
--- a/src/core/Radar.h
+++ b/src/core/Radar.h
@@ -45,10 +45,17 @@ enum eRadarSprite
RADAR_SPRITE_COUNT = 21,
};
+enum
+{
+ BLIP_MODE_TRIANGULAR_UP = 0,
+ BLIP_MODE_TRIANGULAR_DOWN,
+ BLIP_MODE_SQUARE,
+};
+
struct CBlip
{
- int32 m_nColor;
- int16 m_eBlipType; // eBlipType
+ uint32 m_nColor;
+ uint16 m_eBlipType; // eBlipType
int32 m_nEntityHandle;
CVector2D m_vec2DPos;
CVector m_vecPos;
@@ -57,8 +64,8 @@ struct CBlip
bool m_bInUse;
float m_Radius;
int16 m_wScale;
- int16 m_eBlipDisplay; // eBlipDisplay
- int16 m_IconID; // eRadarSprite
+ uint16 m_eBlipDisplay; // eBlipDisplay
+ uint16 m_IconID; // eRadarSprite
};
static_assert(sizeof(CBlip) == 0x30, "CBlip: error");
@@ -72,7 +79,7 @@ class CRadar
{
public:
static float &m_RadarRange;
- static CBlip *ms_RadarTrace; //[NUMRADARBLIPS]
+ static CBlip (&ms_RadarTrace)[NUMRADARBLIPS];
static CSprite2d *AsukaSprite;
static CSprite2d *BombSprite;
static CSprite2d *CatSprite;
@@ -96,13 +103,13 @@ public:
static CSprite2d *RadarSprites[21];
public:
- static int CalculateBlipAlpha(float dist);
+ static uint8 CalculateBlipAlpha(float dist);
static void ChangeBlipBrightness(int32 i, int32 bright);
static void ChangeBlipColour(int32 i, int32);
- static void ChangeBlipDisplay(int32 i, int16 flag);
- static void ChangeBlipScale(int32 i, int16 scale);
+ static void ChangeBlipDisplay(int32 i, eBlipDisplay display);
+ static void ChangeBlipScale(int32 i, int32 scale);
static void ClearBlip(int32 i);
- static void ClearBlipForEntity(int16 type, int32 id);
+ static void ClearBlipForEntity(eBlipType type, int32 id);
static int ClipRadarPoly(CVector2D *out, const CVector2D *in);
static bool DisplayThisBlip(int32 i);
static void Draw3dMarkers();
@@ -111,11 +118,11 @@ public:
static void DrawRadarMap();
static void DrawRadarMask();
static void DrawRadarSection(int32 x, int32 y);
- static void DrawRadarSprite(int32 sprite, float x, float y, int32 alpha);
+ static void DrawRadarSprite(uint16 sprite, float x, float y, uint8 alpha);
static void DrawRotatingRadarSprite(CSprite2d* sprite, float x, float y, float angle, int32 alpha);
static int32 GetActualBlipArrayIndex(int32 i);
static int32 GetNewUniqueBlipIndex(int32 i);
- static int32 GetRadarTraceColour(int32 color, bool bright);
+ static uint32 GetRadarTraceColour(uint32 color, bool bright);
static void Initialise();
static float LimitRadarPoint(CVector2D &point);
static void LoadAllRadarBlips(int32);
@@ -125,11 +132,12 @@ public:
static void RequestMapSection(int32 x, int32 y);
static void SaveAllRadarBlips(int32);
static void SetBlipSprite(int32 i, int32 icon);
- static int32 SetCoordBlip(eBlipType type, CVector pos, int32, eBlipDisplay flag);
+ static int32 SetCoordBlip(eBlipType type, CVector pos, int32, eBlipDisplay);
static int32 SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay);
- static void SetRadarMarkerState(int32 i, int32 flag);
- static void ShowRadarMarker(CVector pos, int16 color, float radius);
- static void ShowRadarTrace(float x, float y, uint32 size, uint32 red, uint32 green, uint32 blue, uint32 alpha);
+ static void SetRadarMarkerState(int32 i, bool flag);
+ static void ShowRadarMarker(CVector pos, uint32 color, float radius);
+ static void ShowRadarTrace(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha);
+ static void ShowRadarTraceWithHeight(float x, float y, uint32 size, uint8 red, uint8 green, uint8 blue, uint8 alpha, uint8 mode);
static void Shutdown();
static void StreamRadarSections(const CVector &posn);
static void StreamRadarSections(int32 x, int32 y);
diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp
index a7bde91e..227a4a9f 100644
--- a/src/core/Streaming.cpp
+++ b/src/core/Streaming.cpp
@@ -1021,7 +1021,7 @@ CStreaming::RemoveAllUnusedModels(void)
for(i = 0; i < MAXVEHICLESLOADED; i++)
RemoveLoadedVehicle();
- for(i = NUM_DEFAULT_MODELS; i < MODELINFOSIZE; i++){
+ for(i = NUMDEFAULTMODELS; i < MODELINFOSIZE; i++){
if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED &&
ms_aInfoForModel[i].m_flags & STREAMFLAGS_DONT_REMOVE &&
CModelInfo::GetModelInfo(i)->m_refCount == 0){
@@ -1719,8 +1719,10 @@ CStreaming::RetryLoadFile(int32 ch)
}
switch(ms_channel[ch].state){
+ case CHANNELSTATE_ERROR:
+ ms_channel[ch].numTries++;
+ if (CdStreamGetStatus(ch) == STREAM_READING || CdStreamGetStatus(ch) == STREAM_WAITING) break;
case CHANNELSTATE_IDLE:
-streamread:
CdStreamRead(ch, ms_pStreamingBuffer[ch], ms_channel[ch].position, ms_channel[ch].size);
ms_channel[ch].state = CHANNELSTATE_READING;
ms_channel[ch].field24 = -600;
@@ -1731,11 +1733,6 @@ streamread:
CTimer::SetCodePause(false);
}
break;
- case CHANNELSTATE_ERROR:
- ms_channel[ch].numTries++;
- if(CdStreamGetStatus(ch) != STREAM_READING && CdStreamGetStatus(ch) != STREAM_WAITING)
- goto streamread;
- break;
}
}
@@ -2408,8 +2405,8 @@ CStreaming::MemoryCardSave(uint8 *buffer, uint32 *length)
{
int i;
- *length = NUM_DEFAULT_MODELS;
- for(i = 0; i < NUM_DEFAULT_MODELS; i++)
+ *length = NUMDEFAULTMODELS;
+ for(i = 0; i < NUMDEFAULTMODELS; i++)
if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED)
buffer[i] = ms_aInfoForModel[i].m_flags;
else
@@ -2421,7 +2418,7 @@ CStreaming::MemoryCardLoad(uint8 *buffer, uint32 length)
{
uint32 i;
- assert(length == NUM_DEFAULT_MODELS);
+ assert(length == NUMDEFAULTMODELS);
for(i = 0; i < length; i++)
if(ms_aInfoForModel[i].m_loadState == STREAMSTATE_LOADED)
if(buffer[i] != 0xFF)
diff --git a/src/core/TempColModels.cpp b/src/core/TempColModels.cpp
index 07ac7989..d2d3f5fb 100644
--- a/src/core/TempColModels.cpp
+++ b/src/core/TempColModels.cpp
@@ -10,7 +10,7 @@ CColModel &CTempColModels::ms_colModelWheel1 = *(CColModel*)0x878C40;
CColModel &CTempColModels::ms_colModelPanel1 = *(CColModel*)0x87BDD8;
CColModel &CTempColModels::ms_colModelBodyPart2 = *(CColModel*)0x87BE30;
CColModel &CTempColModels::ms_colModelBodyPart1 = *(CColModel*)0x87BE88;
-CColModel &CTempColModels::ms_colModelCutObj = *(CColModel*)0x87C960;
+CColModel (&CTempColModels::ms_colModelCutObj)[5] = *(CColModel(*)[5]) *(uintptr*)0x87C960;
CColModel &CTempColModels::ms_colModelPedGroundHit = *(CColModel*)0x880480;
CColModel &CTempColModels::ms_colModelBoot1 = *(CColModel*)0x880670;
CColModel &CTempColModels::ms_colModelDoor1 = *(CColModel*)0x880850;
diff --git a/src/core/TempColModels.h b/src/core/TempColModels.h
index f91ac77e..263904d3 100644
--- a/src/core/TempColModels.h
+++ b/src/core/TempColModels.h
@@ -13,7 +13,7 @@ public:
static CColModel &ms_colModelPanel1;
static CColModel &ms_colModelBodyPart2;
static CColModel &ms_colModelBodyPart1;
- static CColModel &ms_colModelCutObj;
+ static CColModel (&ms_colModelCutObj)[5];
static CColModel &ms_colModelPedGroundHit;
static CColModel &ms_colModelBoot1;
static CColModel &ms_colModelDoor1;
diff --git a/src/core/World.h b/src/core/World.h
index b24e66f0..523585e7 100644
--- a/src/core/World.h
+++ b/src/core/World.h
@@ -56,9 +56,10 @@ class CWorld
static CPtrList &ms_listMovingEntityPtrs;
static CSector (*ms_aSectors)[NUMSECTORS_X]; // [NUMSECTORS_Y][NUMSECTORS_X];
static uint16 &ms_nCurrentScanCode;
- static CColPoint &ms_testSpherePoint;
public:
+ static CColPoint& ms_testSpherePoint;
+
static uint8 &PlayerInFocus;
static CPlayerInfo *Players;
static CEntity *&pIgnoreEntity;
diff --git a/src/core/common.h b/src/core/common.h
index b3a271c6..caa305d6 100644
--- a/src/core/common.h
+++ b/src/core/common.h
@@ -92,9 +92,11 @@ extern void **rwengine;
#define SCREEN_SCALE_FROM_BOTTOM(a) (SCREEN_HEIGHT - SCREEN_SCALE_Y(a))
#ifdef ASPECT_RATIO_SCALE
-#define SCREEN_SCALE_AR(a) ((a) * (4.0f / 3.0f) / SCREEN_ASPECT_RATIO)
+#define SCREEN_SCALE_AR(a) ((a) * DEFAULT_ASPECT_RATIO / SCREEN_ASPECT_RATIO)
+#define SCREEN_SCALE_AR2(a) ((a) / (DEFAULT_ASPECT_RATIO / SCREEN_ASPECT_RATIO))
#else
#define SCREEN_SCALE_AR(a) (a)
+#define SCREEN_SCALE_AR2(a) (a)
#endif
#include "maths.h"
diff --git a/src/core/config.h b/src/core/config.h
index 81e2f2fb..cfad6d85 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -8,6 +8,7 @@ enum Config {
MODELINFOSIZE = 5500,
TXDSTORESIZE = 850,
EXTRADIRSIZE = 128,
+ CUTSCENEDIRSIZE = 512,
SIMPLEMODELSIZE = 5000,
TIMEMODELSIZE = 30,
@@ -31,6 +32,7 @@ enum Config {
NUMDUMMIES = 2802, // 2368 on PS2
NUMAUDIOSCRIPTOBJECTS = 256,
NUMCUTSCENEOBJECTS = 50,
+ NUMDEFAULTMODELS = 200,
NUMTEMPOBJECTS = 30,
@@ -66,10 +68,15 @@ enum Config {
NUMANTENNAS = 8,
NUMCORONAS = 56,
NUMPOINTLIGHTS = 32,
+ NUMMONEYMESSAGES = 16,
+ NUMPICKUPMESSAGES = 16,
NUMONSCREENTIMERENTRIES = 1,
NUMRADARBLIPS = 32,
- NUMPICKUPS = 336,
+ NUMGENERALPICKUPS = 320,
+ NUMSCRIPTEDPICKUPS = 16,
+ NUMPICKUPS = NUMGENERALPICKUPS + NUMSCRIPTEDPICKUPS,
+ NUMCOLLECTEDPICKUPS = 20,
NUMEVENTS = 64,
NUM_CARGENS = 160,
@@ -132,10 +139,26 @@ enum Config {
#endif
#define FIX_BUGS // fix bugs in the game, TODO: use this more
+
+// Pad
#define KANGAROO_CHEAT
+
+// Hud & radar
#define ASPECT_RATIO_SCALE
+#define TRIANGULAR_BLIPS
+
+// Script
#define USE_DEBUG_SCRIPT_LOADER
+
+// Vehicles
#define EXPLODING_AIRTRAIN // can blow up jumbo jet with rocket launcher
+//#define REMOVE_TREADABLE_PATHFIND
+
+// Pickups
+//#define MONEY_MESSAGES
+
+// Peds
#define ANIMATE_PED_COL_MODEL
+#define VC_PED_PORTS
+#define NEW_WALK_AROUND_ALGORITHM
#define CANCELLABLE_CAR_ENTER
-//#define REMOVE_TREADABLE_PATHFIND
diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp
index fef5ec7f..fbd1322d 100644
--- a/src/entities/Physical.cpp
+++ b/src/entities/Physical.cpp
@@ -1459,7 +1459,7 @@ CPhysical::ProcessCollisionSectorList(CPtrList *lists)
A->m_phy_flagA80 = true;
}else if(A->IsPed() && Aped->m_pCollidingEntity == B){
skipCollision = true;
- if(!Aped->bKnockedUpIntoAir)
+ if(!Aped->m_ped_flagH1)
A->m_phy_flagA80 = true;
}else if(B->IsPed() && Bped->m_pCollidingEntity == A){
skipCollision = true;
diff --git a/src/entities/Physical.h b/src/entities/Physical.h
index 2786a7de..1b9f0e02 100644
--- a/src/entities/Physical.h
+++ b/src/entities/Physical.h
@@ -61,7 +61,7 @@ public:
uint8 m_phy_flagA80 : 1;
uint8 m_nSurfaceTouched;
- uint8 m_nZoneLevel;
+ int8 m_nZoneLevel;
CPhysical(void);
~CPhysical(void);
diff --git a/src/math/Matrix.h b/src/math/Matrix.h
index 7d8c02ab..5145f0ac 100644
--- a/src/math/Matrix.h
+++ b/src/math/Matrix.h
@@ -204,6 +204,22 @@ public:
m_matrix.at.y = 0.0f;
m_matrix.at.z = 1.0f;
}
+ void SetRotateZOnlyScaled(float angle, float scale) {
+ float c = Cos(angle);
+ float s = Sin(angle);
+
+ m_matrix.right.x = c * scale;
+ m_matrix.right.y = s * scale;
+ m_matrix.right.z = 0.0f;
+
+ m_matrix.up.x = -s * scale;
+ m_matrix.up.y = c * scale;
+ m_matrix.up.z = 0.0f;
+
+ m_matrix.at.x = 0.0f;
+ m_matrix.at.y = 0.0f;
+ m_matrix.at.z = scale;
+ }
void SetRotateZ(float angle){
SetRotateZOnly(angle);
m_matrix.pos.x = 0.0f;
@@ -213,6 +229,7 @@ public:
void SetRotate(float xAngle, float yAngle, float zAngle);
void Rotate(float x, float y, float z);
void RotateX(float x);
+ void RotateZ(float z);
void Reorthogonalise(void);
void CopyOnlyMatrix(CMatrix *other){
diff --git a/src/math/math.cpp b/src/math/math.cpp
index 66260709..0707e3d2 100644
--- a/src/math/math.cpp
+++ b/src/math/math.cpp
@@ -47,6 +47,12 @@ CMatrix::RotateX(float x)
}
void
+CMatrix::RotateZ(float z)
+{
+ Rotate(0.0f, 0.0f, z);
+}
+
+void
CMatrix::Reorthogonalise(void)
{
CVector &r = GetRight();
diff --git a/src/modelinfo/ModelIndices.h b/src/modelinfo/ModelIndices.h
index a0d3f70c..8f6d0e48 100644
--- a/src/modelinfo/ModelIndices.h
+++ b/src/modelinfo/ModelIndices.h
@@ -352,8 +352,6 @@ enum
MI_AIRTRAIN_VLO = 198,
MI_LOPOLYGUY,
-
- NUM_DEFAULT_MODELS,
};
enum{
diff --git a/src/objects/Object.cpp b/src/objects/Object.cpp
index bba4d7d9..9d531c9c 100644
--- a/src/objects/Object.cpp
+++ b/src/objects/Object.cpp
@@ -14,7 +14,9 @@ int16 &CObject::nNoTempObjects = *(int16*)0x95CCA2;
int16 &CObject::nBodyCastHealth = *(int16*)0x5F7D4C; // 1000
void *CObject::operator new(size_t sz) { return CPools::GetObjectPool()->New(); }
+void *CObject::operator new(size_t sz, int handle) { return CPools::GetObjectPool()->New(handle);};
void CObject::operator delete(void *p, size_t sz) { CPools::GetObjectPool()->Delete((CObject*)p); }
+void CObject::operator delete(void *p, int handle) { CPools::GetObjectPool()->Delete((CObject*)p); }
CObject::CObject(void)
{
@@ -32,7 +34,7 @@ CObject::CObject(void)
field_172 = 0;
bIsPickup = false;
m_obj_flag2 = false;
- m_obj_flag4 = false;
+ bOutOfStock = false;
m_obj_flag8 = false;
m_obj_flag10 = false;
bHasBeenDamaged = false;
diff --git a/src/objects/Object.h b/src/objects/Object.h
index 21348b52..47af4fbf 100644
--- a/src/objects/Object.h
+++ b/src/objects/Object.h
@@ -34,13 +34,13 @@ public:
int8 ObjectCreatedBy;
int8 bIsPickup : 1;
int8 m_obj_flag2 : 1;
- int8 m_obj_flag4 : 1;
+ int8 bOutOfStock : 1;
int8 m_obj_flag8 : 1;
int8 m_obj_flag10 : 1;
int8 bHasBeenDamaged : 1;
int8 bUseVehicleColours : 1;
int8 m_obj_flag80 : 1;
- int8 field_172;
+ int8 field_172; // car for a bonus pickup?
int8 field_173;
float m_fCollisionDamageMultiplier;
uint8 m_nCollisionDamageEffect;
@@ -63,7 +63,9 @@ public:
static int16 &nBodyCastHealth;
static void *operator new(size_t);
+ static void *operator new(size_t, int);
static void operator delete(void*, size_t);
+ static void operator delete(void*, int);
CObject(void);
CObject(int32, bool);
diff --git a/src/peds/CivilianPed.cpp b/src/peds/CivilianPed.cpp
index f28a1134..93cdcb3d 100644
--- a/src/peds/CivilianPed.cpp
+++ b/src/peds/CivilianPed.cpp
@@ -8,34 +8,11 @@ WRAPPER void CCivilianPed::ProcessControl(void) { EAXJMP(0x4BFFE0); }
CCivilianPed::CCivilianPed(int pedtype, int mi) : CPed(pedtype)
{
SetModelIndex(mi);
- for (int i = 0; i < 10; i++)
- {
+ for (int i = 0; i < 10; i++) {
m_nearPeds[i] = nil;
}
}
-bool
-CCivilianPed::ProcessNearestFreePhone(int unused)
-{
- if (m_nPedState == PED_SEEK_POS)
- return false;
-
- int phoneId = gPhoneInfo.FindNearestFreePhone(&GetPosition());
-
- if (phoneId == -1)
- return false;
-
- if (gPhoneInfo.m_aPhones[phoneId].m_nState != PHONE_STATE_FREE)
- return false;
-
- bRunningToPhone = true;
- SetMoveState(PEDMOVE_RUN);
- SetSeek(gPhoneInfo.m_aPhones[phoneId].m_vecPos, 0.3f);
- m_phoneId = phoneId;
- m_lookingForPhone = unused;
- return true;
-}
-
class CCivilianPed_ : public CCivilianPed
{
public:
@@ -46,5 +23,4 @@ public:
STARTPATCHES
InjectHook(0x4BFF30, &CCivilianPed_::ctor, PATCH_JUMP);
InjectHook(0x4BFFC0, &CCivilianPed_::dtor, PATCH_JUMP);
- InjectHook(0x4C10C0, &CCivilianPed::ProcessNearestFreePhone, PATCH_JUMP);
ENDPATCHES
diff --git a/src/peds/CivilianPed.h b/src/peds/CivilianPed.h
index e5e63682..14859a5c 100644
--- a/src/peds/CivilianPed.h
+++ b/src/peds/CivilianPed.h
@@ -9,6 +9,5 @@ public:
~CCivilianPed(void) { }
void ProcessControl(void);
- bool ProcessNearestFreePhone(int);
};
static_assert(sizeof(CCivilianPed) == 0x53C, "CCivilianPed: error");
diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp
index 68b7579a..cbd32cea 100644
--- a/src/peds/Ped.cpp
+++ b/src/peds/Ped.cpp
@@ -40,30 +40,34 @@
#include "CopPed.h"
#include "Script.h"
#include "CarCtrl.h"
+#include "Garages.h"
+#include "WaterLevel.h"
+#include "CarAI.h"
+#include "Zones.h"
WRAPPER void CPed::SpawnFlyingComponent(int, int8) { EAXJMP(0x4EB060); }
WRAPPER void CPed::SetPedPositionInCar(void) { EAXJMP(0x4D4970); }
WRAPPER void CPed::PreRender(void) { EAXJMP(0x4CFDD0); }
-WRAPPER void CPed::Render(void) { EAXJMP(0x4D03F0); }
-WRAPPER int32 CPed::ProcessEntityCollision(CEntity*, CColPoint*) { EAXJMP(0x4CBB30); }
WRAPPER void CPed::SetMoveAnim(void) { EAXJMP(0x4C5A40); }
WRAPPER void CPed::SetFollowRoute(int16, int16) { EAXJMP(0x4DD690); }
WRAPPER void CPed::SetDuck(uint32) { EAXJMP(0x4E4920); }
-WRAPPER void CPed::RegisterThreatWithGangPeds(CEntity*) { EAXJMP(0x4E3870); }
WRAPPER void CPed::SetFollowPath(CVector) { EAXJMP(0x4D2EA0); }
WRAPPER void CPed::StartFightDefend(uint8, uint8, uint8) { EAXJMP(0x4E7780); }
-WRAPPER void CPed::SetDirectionToWalkAroundObject(CEntity*) { EAXJMP(0x4CCEB0); }
WRAPPER void CPed::SetRadioStation(void) { EAXJMP(0x4D7BC0); }
-WRAPPER void CPed::ProcessObjective(void) { EAXJMP(0x4D94E0); }
WRAPPER void CPed::ProcessBuoyancy(void) { EAXJMP(0x4C7FF0); }
WRAPPER void CPed::ServiceTalking(void) { EAXJMP(0x4E5870); }
WRAPPER void CPed::UpdatePosition(void) { EAXJMP(0x4C7A00); }
WRAPPER void CPed::WanderRange(void) { EAXJMP(0x4D26C0); }
WRAPPER void CPed::WanderPath(void) { EAXJMP(0x4D28D0); }
-WRAPPER void CPed::ReactToPointGun(CEntity*) { EAXJMP(0x4DD980); }
WRAPPER void CPed::SeekCar(void) { EAXJMP(0x4D3F90); }
WRAPPER void CPed::SeekBoatPosition(void) { EAXJMP(0x4E4C70); }
-WRAPPER bool CPed::PositionPedOutOfCollision(void) { EAXJMP(0x4E4F30); }
+WRAPPER void CPed::UpdateFromLeader(void) { EAXJMP(0x4D8F30); }
+WRAPPER int CPed::ScanForThreats(void) { EAXJMP(0x4C5FE0); }
+WRAPPER void CPed::SetEnterCar(CVehicle*, uint32) { EAXJMP(0x4E0920); }
+WRAPPER bool CPed::WarpPedToNearEntityOffScreen(CEntity*) { EAXJMP(0x4E5570); }
+WRAPPER void CPed::SetExitCar(CVehicle*, uint32) { EAXJMP(0x4E1010); }
+
+#define FEET_OFFSET 1.04f
CPed *gapTempPedList[50];
uint16 gnNumTempPedList;
@@ -82,22 +86,23 @@ uint16 nPlayerInComboMove;
FightMove (&tFightMoves)[24] = * (FightMove(*)[24]) * (uintptr*)0x5F9844;
uint16 &CPed::nThreatReactionRangeMultiplier = *(uint16*)0x5F8C98;
+uint16 &CPed::nEnterCarRangeMultiplier = *(uint16*)0x5F8C94;
CVector vecPedCarDoorAnimOffset;
CVector vecPedCarDoorLoAnimOffset;
CVector vecPedVanRearDoorAnimOffset;
-CVector &vecPedQuickDraggedOutCarAnimOffset = *(CVector*)0x62E06C;
-CVector &vecPedDraggedOutCarAnimOffset = *(CVector*)0x62E060;
-CVector &vecPedTrainDoorAnimOffset = *(CVector*)0x62E054;
+CVector vecPedQuickDraggedOutCarAnimOffset;
+CVector vecPedDraggedOutCarAnimOffset;
+CVector vecPedTrainDoorAnimOffset;
-CVector2D CPed::ms_vec2DFleePosition; // = *(CVector2D*)0x6EDF70;
+CVector2D CPed::ms_vec2DFleePosition;
void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); }
void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->New(handle); }
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[34][28] = {
+static char ObjectiveText[][28] = {
"No Obj",
"Wait on Foot",
"Flee on Foot Till Safe",
@@ -132,9 +137,12 @@ static char ObjectiveText[34][28] = {
"Buy IceCream",
"Steal Any Car",
"Mug Char",
+#ifdef VC_PED_PORTS
+ "Leave Car and Die"
+#endif
};
-static char StateText[57][18] = {
+static char StateText[][18] = {
"None",
"Idle",
"Look Entity",
@@ -194,7 +202,7 @@ static char StateText[57][18] = {
"Arrested",
};
-static char PersonalityTypeText[32][18] = {
+static char PersonalityTypeText[][18] = {
"Player",
"Cop",
"Medic",
@@ -229,7 +237,7 @@ static char PersonalityTypeText[32][18] = {
"Sports Fan",
};
-static char WaitStateText[21][16] = {
+static char WaitStateText[][16] = {
"No Wait",
"Traffic Lights",
"Pause CrossRoad",
@@ -298,6 +306,11 @@ CPed::DebugRenderOnePedText(void)
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();
}
}
@@ -414,7 +427,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
m_fleeFromPosY = 0;
m_fleeTimer = 0;
m_vecSeekPosEx = CVector(0.0f, 0.0f, 0.0f);
- m_seekExAngle = 0.0f;
+ m_distanceToCountSeekDoneEx = 0.0f;
m_nWaitState = WAITSTATE_FALSE;
m_nWaitTimer = 0;
m_pCollidingEntity = nil;
@@ -473,11 +486,11 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
bHasACamera = false;
m_ped_flagD2 = false;
- m_ped_flagD4 = false;
- m_ped_flagD8 = false;
+ bPedIsBleeding = false;
+ bStopAndShoot = false;
bIsPedDieAnimPlaying = false;
bUsePedNodeSeek = false;
- m_ped_flagD40 = false;
+ bObjectiveCompleted = false;
bScriptObjectiveCompleted = false;
bKindaStayInSamePlace = false;
@@ -495,25 +508,25 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
m_ped_flagF8 = false;
bWillBeQuickJacked = false;
bCancelEnteringCar = false;
- m_ped_flagF40 = false;
+ bObstacleShowedUpDuringKillObjective = false;
bDuckAndCover = false;
- m_ped_flagG1 = false;
+ bStillOnValidPoly = false;
m_ped_flagG2 = true;
m_ped_flagG4 = false;
bStartWanderPathOnFoot = false;
- m_ped_flagG10 = false;
+ bOnBoat = false;
bBusJacked = false;
bGonnaKillTheCarJacker = false;
bFadeOut = false;
- bKnockedUpIntoAir = false;
- m_ped_flagH2 = false;
+ m_ped_flagH1 = false;
+ bHitSteepSlope = false;
m_ped_flagH4 = false;
bClearObjective = false;
m_ped_flagH10 = false;
bCollidedWithMyVehicle = false;
- m_ped_flagH40 = false;
+ bRichFromMugging = false;
m_ped_flagH80 = false;
bShakeFist = false;
@@ -524,6 +537,9 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
#ifdef KANGAROO_CHEAT
m_ped_flagI80 = false;
#endif
+#ifdef VC_PED_PORTS
+ bKnockedUpIntoAir = false;
+#endif
if ((CGeneral::GetRandomNumber() & 3) == 0)
bHasACamera = true;
@@ -537,8 +553,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
m_fAngleToEvent = 0.0f;
m_numNearPeds = 0;
- for (int i = 0; i < 10; i++)
- {
+ for (int i = 0; i < 10; i++) {
m_nearPeds[i] = nil;
if (i < 8) {
m_pPathNodesStates[i] = nil;
@@ -548,8 +563,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
m_currentWeapon = WEAPONTYPE_UNARMED;
m_storedWeapon = WEAPONTYPE_UNIDENTIFIED;
- for(int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; i++)
- {
+ for(int i = 0; i < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; i++) {
CWeapon &weapon = GetWeapon(i);
weapon.m_eWeaponType = WEAPONTYPE_UNARMED;
weapon.m_eWeaponState = WEAPONSTATE_READY;
@@ -789,7 +803,7 @@ CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer)
if (!IsPlayer() || evenOnPlayer) {
++CStats::HeadsPopped;
- // BUG: This condition will always return true.
+ // BUG: This condition will always return true. Even fixing it won't work, because these states are unused.
if (m_nPedState != PED_PASSENGER || m_nPedState != PED_TAXI_PASSENGER) {
CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f);
}
@@ -817,6 +831,22 @@ CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer)
}
}
+static RwObject*
+SetPedAtomicVisibilityCB(RwObject* object, void* data)
+{
+ if (data == nil)
+ RpAtomicSetFlags(object, 0);
+ return object;
+}
+
+static RwFrame*
+RecurseFrameChildrenVisibilityCB(RwFrame* frame, void* data)
+{
+ RwFrameForAllObjects(frame, SetPedAtomicVisibilityCB, data);
+ RwFrameForAllChildren(frame, RecurseFrameChildrenVisibilityCB, nil);
+ return frame;
+}
+
void
CPed::RemoveBodyPart(PedNode nodeId, int8 direction)
{
@@ -834,13 +864,13 @@ CPed::RemoveBodyPart(PedNode nodeId, int8 direction)
pos.y = 0.0f;
pos.z = 0.0f;
- for (frame = RwFrameGetParent(frame); frame; frame = RwFrameGetParent(frame))
+ for (; frame; frame = RwFrameGetParent(frame))
RwV3dTransformPoints(&pos, &pos, 1, RwFrameGetMatrix(frame));
if (CEntity::GetIsOnScreen()) {
CParticle::AddParticle(PARTICLE_TEST, pos,
CVector(0.0f, 0.0f, 0.0f),
- nil, 0.2f, 0, 0, 0, 0);
+ nil, 0.1f, 0, 0, 0, 0);
for (int i = 0; i < 16; i++) {
CParticle::AddParticle(PARTICLE_BLOOD_SMALL,
@@ -857,22 +887,6 @@ CPed::RemoveBodyPart(PedNode nodeId, int8 direction)
}
}
-RwObject*
-CPed::SetPedAtomicVisibilityCB(RwObject *object, void *data)
-{
- if (data == nil)
- RpAtomicSetFlags(object, 0);
- return object;
-}
-
-RwFrame*
-CPed::RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data)
-{
- RwFrameForAllObjects(frame, SetPedAtomicVisibilityCB, data);
- RwFrameForAllChildren(frame, RecurseFrameChildrenVisibilityCB, nil);
- return frame;
-}
-
void
CPed::SetLookFlag(CEntity *target, bool keepTryingToLook)
{
@@ -1248,6 +1262,19 @@ CPed::Attack(void)
GetWeapon()->AddGunshell(this, gunshellPos, gunshellRot, 0.025f);
}
}
+#ifdef VC_PED_PORTS
+ if (IsPlayer()) {
+ if (CPad::GetPad(0)->GetSprint()) {
+ // animBreakout is a member of WeaponInfo in VC, so it's me that added the below line.
+ float animBreakOut = ((ourWeaponType == WEAPONTYPE_FLAMETHROWER || ourWeaponType == WEAPONTYPE_UZI || ourWeaponType == WEAPONTYPE_SHOTGUN) ? 25 / 30.0f : 99 / 30.0f);
+ if (!attackShouldContinue && weaponAnimAssoc->currentTime > animBreakOut) {
+ weaponAnimAssoc->blendDelta = -4.0f;
+ FinishedAttackCB(nil, this);
+ return;
+ }
+ }
+ }
+#endif
animLoopEnd = ourWeapon->m_fAnimLoopEnd;
if (ourWeaponFire == WEAPON_FIRE_MELEE && weaponAnimAssoc->animId == ourWeapon->m_Anim2ToPlay)
animLoopEnd = 3.4f/6.0f;
@@ -1274,6 +1301,12 @@ CPed::Attack(void)
else
CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ourWeapon->m_Anim2ToPlay, 8.0f);
}
+#ifdef VC_PED_PORTS
+ } else if (IsPlayer() && m_pPointGunAt && bIsAimingGun && GetWeapon()->m_eWeaponState != WEAPONSTATE_RELOADING) {
+ weaponAnimAssoc->SetCurrentTime(ourWeapon->m_fAnimLoopEnd);
+ weaponAnimAssoc->flags &= ~ASSOC_RUNNING;
+ SetPointGunAt(m_pPointGunAt);
+#endif
} else {
ClearAimFlag();
@@ -1455,6 +1488,13 @@ CPed::BeingDraggedFromCar(void)
}
LineUpPedWithCar(lineUpType);
+#ifdef VC_PED_PORTS
+ if (m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) {
+ if (m_pMyVehicle) {
+ m_pMyVehicle->ProcessOpenDoor(m_vehEnterType, NUM_ANIMS, m_pVehicleAnim->currentTime);
+ }
+ }
+#endif
}
void
@@ -1474,7 +1514,6 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg)
CAnimBlendAssociation *quickJackedAssoc;
CVehicle *vehicle;
CPed *ped = (CPed*)arg;
- eWeaponType weaponType = ped->GetWeapon()->m_eWeaponType;
quickJackedAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), ANIM_CAR_QJACKED);
if (ped->m_nPedState != PED_ARRESTED) {
@@ -1487,19 +1526,20 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg)
ped->m_pSeekTarget = nil;
vehicle = ped->m_pMyVehicle;
- vehicle->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType);
+ if (vehicle) {
+ vehicle->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType);
- if (vehicle->pDriver == ped) {
- vehicle->RemoveDriver();
- if (vehicle->m_nDoorLock == CARLOCK_LOCKED_INITIALLY)
- vehicle->m_nDoorLock = CARLOCK_UNLOCKED;
+ if (vehicle->pDriver == ped) {
+ vehicle->RemoveDriver();
+ if (vehicle->m_nDoorLock == CARLOCK_LOCKED_INITIALLY)
+ vehicle->m_nDoorLock = CARLOCK_UNLOCKED;
- if (ped->m_nPedType == PEDTYPE_COP && vehicle->IsLawEnforcementVehicle())
- vehicle->ChangeLawEnforcerState(false);
- } else {
- vehicle->RemovePassenger(ped);
+ if (ped->m_nPedType == PEDTYPE_COP && vehicle->IsLawEnforcementVehicle())
+ vehicle->ChangeLawEnforcerState(false);
+ } else {
+ vehicle->RemovePassenger(ped);
+ }
}
-
ped->bInVehicle = false;
if (ped->IsPlayer())
AudioManager.PlayerJustLeftCar();
@@ -1512,15 +1552,8 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg)
CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_GETUP1, 1000.0f);
}
- // Only uzi can be used on cars, so previous weapon was stored
- if (ped->IsPlayer() && weaponType == WEAPONTYPE_UZI) {
- if (ped->m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) {
- ped->SetCurrentWeapon(ped->m_storedWeapon);
- ped->m_storedWeapon = WEAPONTYPE_UNIDENTIFIED;
- }
- } else {
- ped->AddWeaponModel(CWeaponInfo::GetWeaponInfo(weaponType)->m_nModelId);
- }
+ ped->ReplaceWeaponWhenExitingVehicle();
+
ped->m_nStoredMoveState = PEDMOVE_NONE;
ped->m_ped_flagI4 = false;
}
@@ -1665,7 +1698,6 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase)
CVehicle *veh = m_pMyVehicle;
// Not quite right, IsUpsideDown func. checks for <= -0.9f.
- // Since that function is also used in this file, doesn't this variable indicate upsidedownness?!
if (veh->GetUp().z <= -0.8f)
vehIsUpsideDown = true;
@@ -1700,6 +1732,11 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase)
if (!bInVehicle)
seatPosMult = 1.0f;
+#ifdef VC_PED_PORTS
+ bool multExtractedFromAnim = false;
+ bool multExtractedFromAnimBus = false;
+ float zBlend;
+#endif
if (m_pVehicleAnim) {
vehAnim = m_pVehicleAnim->animId;
@@ -1708,23 +1745,42 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase)
case ANIM_CAR_LJACKED_RHS:
case ANIM_CAR_JACKED_LHS:
case ANIM_CAR_LJACKED_LHS:
+ case ANIM_VAN_GETIN_L:
+ case ANIM_VAN_GETIN:
+#ifdef VC_PED_PORTS
+ multExtractedFromAnim = true;
+ zBlend = max(m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength - 0.3f, 0.0f) / (1.0f - 0.3f);
+ // fall through
+#endif
case ANIM_CAR_QJACKED:
case ANIM_CAR_GETOUT_LHS:
case ANIM_CAR_GETOUT_LOW_LHS:
case ANIM_CAR_GETOUT_RHS:
case ANIM_CAR_GETOUT_LOW_RHS:
+#ifdef VC_PED_PORTS
+ if (!multExtractedFromAnim) {
+ multExtractedFromAnim = true;
+ zBlend = max(m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength - 0.5f, 0.0f) / (1.0f - 0.5f);
+ }
+ // fall through
+#endif
case ANIM_CAR_CRAWLOUT_RHS:
case ANIM_CAR_CRAWLOUT_RHS2:
- case ANIM_VAN_GETIN_L:
case ANIM_VAN_GETOUT_L:
- case ANIM_VAN_GETIN:
case ANIM_VAN_GETOUT:
seatPosMult = m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength;
break;
- case ANIM_CAR_QJACK:
+ case ANIM_CAR_GETIN_RHS:
case ANIM_CAR_GETIN_LHS:
+#ifdef VC_PED_PORTS
+ if (veh && veh->IsCar() && veh->bIsBus) {
+ multExtractedFromAnimBus = true;
+ zBlend = min(m_pVehicleAnim->currentTime / m_pVehicleAnim->hierarchy->totalLength, 0.5f) / 0.5f;
+ }
+ // fall through
+#endif
+ case ANIM_CAR_QJACK:
case ANIM_CAR_GETIN_LOW_LHS:
- case ANIM_CAR_GETIN_RHS:
case ANIM_CAR_GETIN_LOW_RHS:
case ANIM_DRIVE_BOAT:
seatPosMult = m_pVehicleAnim->GetTimeLeft() / m_pVehicleAnim->hierarchy->totalLength;
@@ -1789,40 +1845,55 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase)
}
if (autoZPos.z > neededPos.z) {
- currentZ = GetPosition().z;
- if (m_pVehicleAnim && vehAnim != ANIM_VAN_GETIN_L && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE && vehAnim != ANIM_VAN_GETIN) {
- neededPos.z = autoZPos.z;
- m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
- } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) {
- adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f);
+#ifdef VC_PED_PORTS
+ if (multExtractedFromAnim) {
+ neededPos.z += (autoZPos.z - neededPos.z) * zBlend;
+ } else {
+#endif
+ currentZ = GetPosition().z;
+ if (m_pVehicleAnim && vehAnim != ANIM_VAN_GETIN_L && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE && vehAnim != ANIM_VAN_GETIN) {
+ neededPos.z = autoZPos.z;
+ m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ } else if (neededPos.z <= currentZ && m_pVehicleAnim && vehAnim != ANIM_VAN_CLOSE_L && vehAnim != ANIM_VAN_CLOSE) {
+ adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f);
- // Smoothly change ped position
- neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep);
+ // Smoothly change ped position
+ neededPos.z = currentZ - (currentZ - neededPos.z) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep);
+ }
+#ifdef VC_PED_PORTS
}
+#endif
} else {
// We may need to raise up the ped
if (phase == LINE_UP_TO_CAR_START) {
currentZ = GetPosition().z;
if (neededPos.z > currentZ) {
-
- if (m_pVehicleAnim &&
- (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS
- || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) {
- adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f);
-
- // Smoothly change ped position
- neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ;
- } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) {
- neededPos.z = max(currentZ, autoZPos.z);
+#ifdef VC_PED_PORTS
+ if (multExtractedFromAnimBus) {
+ neededPos.z = (neededPos.z - currentZ) * zBlend + currentZ;
+ } else {
+#endif
+ if (m_pVehicleAnim &&
+ (vehAnim == ANIM_CAR_GETIN_RHS || vehAnim == ANIM_CAR_GETIN_LOW_RHS || vehAnim == ANIM_CAR_GETIN_LHS || vehAnim == ANIM_CAR_GETIN_LOW_LHS
+ || vehAnim == ANIM_CAR_QJACK || vehAnim == ANIM_VAN_GETIN_L || vehAnim == ANIM_VAN_GETIN)) {
+ adjustedTimeStep = min(m_pVehicleAnim->timeStep, 0.1f);
+
+ // Smoothly change ped position
+ neededPos.z = (neededPos.z - currentZ) / (m_pVehicleAnim->GetTimeLeft() / adjustedTimeStep) + currentZ;
+ } else if (m_nPedState == PED_ENTER_CAR || m_nPedState == PED_CARJACK) {
+ neededPos.z = max(currentZ, autoZPos.z);
+ }
+#ifdef VC_PED_PORTS
}
+#endif
}
}
}
bool stillGettingInOut = false;
if (CTimer::GetTimeInMilliseconds() < m_nPedStateTimer)
- stillGettingInOut = veh->m_vehType != VEHICLE_TYPE_BOAT || m_ped_flagG10;
+ stillGettingInOut = veh->m_vehType != VEHICLE_TYPE_BOAT || bOnBoat;
if (!stillGettingInOut) {
m_fRotationCur = m_fRotationDest;
@@ -1849,13 +1920,11 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase)
if (seatPosMult > 0.2f || vehIsUpsideDown) {
GetPosition() = neededPos;
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
-
- // It will be all 0 after rotate.
- GetPosition() = neededPos;
+ SetHeading(m_fRotationCur);
} else {
CMatrix vehDoorMat(veh->GetMatrix());
vehDoorMat.GetPosition() += Multiply3x3(vehDoorMat, GetLocalPositionToOpenCarDoor(veh, m_vehEnterType, 0.0f));
+ // VC couch anims are inverted, so they're fixing it here.
GetMatrix() = vehDoorMat;
}
@@ -2023,7 +2092,7 @@ CPed::SortPeds(CPed **list, int min, int max)
int left = max;
int right;
for(right = min; right <= left; ){
- // Those 1.0s are to make sure loop always run for first time.
+ // Those 1.0s are my addition to make sure loop always run for first time.
for (float rightDist = middleDist-1.0f; middleDist > rightDist; right++) {
rightDiff = GetPosition() - list[right]->GetPosition();
rightDist = rightDiff.Magnitude();
@@ -2183,12 +2252,7 @@ CPed::CalculateNewOrientation(void)
if (CReplay::IsPlayingBack() || !IsPedInControl())
return;
- CVector pos = GetPosition();
-
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
-
- // Because SetRotate makes pos. all 0
- GetPosition() = pos;
+ SetHeading(m_fRotationCur);
}
float
@@ -2275,8 +2339,16 @@ CPed::CalculateNewVelocity(void)
CAnimBlendAssociation *idleAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_STANCE);
CAnimBlendAssociation *fightAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FIGHT_IDLE);
+#ifdef VC_PED_PORTS
+ if(!fightAssoc)
+ fightAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TIRED);
+
+ // There is one more anim in VC.
+ if ((!idleAssoc || idleAssoc->blendAmount < 0.5f) && !fightAssoc && !bIsDucking) {
+#else
if ((!idleAssoc || idleAssoc->blendAmount < 0.5f) && !fightAssoc) {
+#endif
LimbOrientation newUpperLegs;
newUpperLegs.phi = localWalkAngle;
@@ -2317,8 +2389,8 @@ CPed::CanPedDriveOff(void)
return false;
for (int i = 0; i < m_numNearPeds; i++) {
- CPed *ped = m_nearPeds[i];
- if (ped->m_nPedType == m_nPedType && ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && ped->m_carInObjective == m_carInObjective) {
+ CPed *nearPed = m_nearPeds[i];
+ if (nearPed->m_nPedType == m_nPedType && nearPed->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && nearPed->m_carInObjective == m_carInObjective) {
m_lookTimer = CTimer::GetTimeInMilliseconds() + 1000;
return false;
}
@@ -2326,8 +2398,39 @@ CPed::CanPedDriveOff(void)
return true;
}
+#ifdef VC_PED_PORTS
+bool
+CPed::CanPedJumpThis(CEntity *unused, CVector *damageNormal = nil)
+{
+ if (m_nSurfaceTouched == SURFACE_PUDDLE)
+ return true;
+
+ CVector pos = GetPosition();
+ CVector forwardOffset = GetForward();
+ if (damageNormal && damageNormal->z > 0.17f) {
+ if (damageNormal->z > 0.9f)
+ return false;
+
+ CColModel *ourCol = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel();
+ pos.z = ourCol->spheres->center.z - ourCol->spheres->radius * damageNormal->z + pos.z;
+ pos.z = pos.z + 0.05f;
+ float collPower = damageNormal->Magnitude2D();
+ if (damageNormal->z <= 0.5f) {
+ forwardOffset += collPower * ourCol->spheres->radius * forwardOffset;
+ } else {
+ CVector invDamageNormal(-damageNormal->x, -damageNormal->y, 0.0f);
+ invDamageNormal *= 1.0f / collPower;
+ CVector estimatedJumpDist = invDamageNormal + collPower * invDamageNormal * ourCol->spheres->radius;
+ forwardOffset = estimatedJumpDist * min(2.0f / collPower, 4.0f);
+ }
+ } else {
+ pos.z -= 0.15f;
+ }
-// TODO: Make this function actually work.
+ CVector forwardPos = pos + forwardOffset;
+ return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false);
+}
+#else
bool
CPed::CanPedJumpThis(CEntity *unused)
{
@@ -2337,8 +2440,10 @@ CPed::CanPedJumpThis(CEntity *unused)
forward.x + pos.x,
forward.y + pos.y,
pos.z);
+
return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false);
}
+#endif
bool
CPed::CanPedReturnToState(void)
@@ -2376,6 +2481,9 @@ bool
CPed::IsTemporaryObjective(eObjective objective)
{
return objective == OBJECTIVE_LEAVE_VEHICLE || objective == OBJECTIVE_SET_LEADER ||
+#ifdef VC_PED_PORTS
+ objective == OBJECTIVE_LEAVE_CAR_AND_DIE ||
+#endif
objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER;
}
@@ -2452,7 +2560,11 @@ CPed::RestorePreviousObjective(void)
if (m_objective == OBJECTIVE_NONE)
return;
- if (m_objective != OBJECTIVE_LEAVE_VEHICLE && m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER)
+ if (m_objective != OBJECTIVE_LEAVE_VEHICLE && m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER
+#ifdef VC_PED_PORTS
+ && m_nPedState != PED_CARJACK
+#endif
+ )
m_pedInObjective = nil;
if (m_objective == OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT) {
@@ -2464,7 +2576,7 @@ CPed::RestorePreviousObjective(void)
m_objective = m_prevObjective;
m_prevObjective = OBJECTIVE_NONE;
}
- m_ped_flagD40 = false;
+ bObjectiveCompleted = false;
}
void
@@ -2506,6 +2618,9 @@ CPed::SetObjective(eObjective newObj, void *entity)
break;
case OBJECTIVE_LEAVE_VEHICLE:
case OBJECTIVE_FLEE_CAR:
+#ifdef VC_PED_PORTS
+ case OBJECTIVE_LEAVE_CAR_AND_DIE:
+#endif
return;
case OBJECTIVE_ENTER_CAR_AS_PASSENGER:
case OBJECTIVE_ENTER_CAR_AS_DRIVER:
@@ -2525,11 +2640,15 @@ CPed::SetObjective(eObjective newObj, void *entity)
break;
}
} else {
- if (newObj == OBJECTIVE_LEAVE_VEHICLE && !bInVehicle)
+ if ((newObj == OBJECTIVE_LEAVE_VEHICLE
+#ifdef VC_PED_PORTS
+ || newObj == OBJECTIVE_LEAVE_CAR_AND_DIE
+#endif
+ ) && !bInVehicle)
return;
}
- m_ped_flagD40 = false;
+ bObjectiveCompleted = false;
if (!IsTemporaryObjective(m_objective) || IsTemporaryObjective(newObj)) {
if (m_objective != newObj) {
if (IsTemporaryObjective(newObj))
@@ -2573,6 +2692,9 @@ CPed::SetObjective(eObjective newObj, void *entity)
m_pedFormation = 1;
break;
case OBJECTIVE_LEAVE_VEHICLE:
+#ifdef VC_PED_PORTS
+ case OBJECTIVE_LEAVE_CAR_AND_DIE:
+#endif
case OBJECTIVE_FLEE_CAR:
m_carInObjective = (CVehicle*)entity;
m_carInObjective->RegisterReference((CEntity **)&m_carInObjective);
@@ -2642,8 +2764,14 @@ CPed::SetObjective(eObjective newObj)
return;
if (newObj == OBJECTIVE_NONE) {
- if ((m_objective == OBJECTIVE_LEAVE_VEHICLE || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER)
- && IsPedInControl()) {
+ if ((m_objective == OBJECTIVE_LEAVE_VEHICLE || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER
+#ifdef VC_PED_PORTS
+ || m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE)
+ && !IsPlayer()
+#else
+ )
+#endif
+ && !IsPedInControl()) {
bStartWanderPathOnFoot = true;
return;
@@ -2672,7 +2800,7 @@ CPed::SetObjective(eObjective newObj)
m_objective = newObj;
}
- m_ped_flagD40 = false;
+ bObjectiveCompleted = false;
switch (newObj) {
case OBJECTIVE_NONE:
@@ -2705,7 +2833,7 @@ CPed::SetObjective(eObjective newObj, int16 routePoint, int16 routeType)
if (m_objective == newObj && newObj == OBJECTIVE_FOLLOW_ROUTE && m_routeLastPoint == routePoint && m_routeType == routeType)
return;
- m_ped_flagD40 = false;
+ bObjectiveCompleted = false;
if (IsTemporaryObjective(m_objective)) {
m_prevObjective = newObj;
} else {
@@ -2799,15 +2927,8 @@ CPed::QuitEnteringCar(void)
bUsesCollision = true;
- if (IsPlayer() && GetWeapon()->m_eWeaponType == WEAPONTYPE_UZI) {
- if (IsPlayer() && m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) {
- SetCurrentWeapon(m_storedWeapon);
- m_storedWeapon = WEAPONTYPE_UNIDENTIFIED;
- }
- } else {
- CWeaponInfo *curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
- AddWeaponModel(curWeapon->m_nModelId);
- }
+ ReplaceWeaponWhenExitingVehicle();
+
if (DyingOrDead()) {
animAssoc = m_pVehicleAnim;
if (animAssoc) {
@@ -2837,6 +2958,21 @@ CPed::ReactToAttack(CEntity *attacker)
return;
}
+#ifdef VC_PED_PORTS
+ if (m_nPedState == PED_DRIVING && bInVehicle && m_pMyVehicle
+ && (m_pMyVehicle->pDriver == this || m_pMyVehicle->pDriver && m_pMyVehicle->pDriver->m_nPedState == PED_DRIVING)) {
+
+ if (m_pMyVehicle->VehicleCreatedBy == RANDOM_VEHICLE
+ && (m_pMyVehicle->m_status == STATUS_SIMPLE || m_pMyVehicle->m_status == STATUS_PHYSICS)
+ && m_pMyVehicle->AutoPilot.m_nCarMission == MISSION_CRUISE) {
+
+ CCarCtrl::SwitchVehicleToRealPhysics(m_pMyVehicle);
+ m_pMyVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 60.0f * m_pMyVehicle->pHandling->Transmission.fUnkMaxVelocity;
+ m_pMyVehicle->m_status = STATUS_PHYSICS;
+ }
+ } else
+#endif
if (IsPedInControl() && (CharCreatedBy != MISSION_CHAR || bRespondsToThreats)) {
CPed *ourLeader = m_leader;
if (ourLeader != attacker && (!ourLeader || FindPlayerPed() != ourLeader)
@@ -3177,7 +3313,7 @@ CPed::CheckIfInTheAir(void)
bool foundGround = CWorld::ProcessVerticalLine(pos, startZ, foundColPoint, foundEntity, true, true, false, true, false, false, nil);
if (!foundGround && m_nPedState != PED_JUMP)
{
- pos.z -= 1.04f;
+ pos.z -= FEET_OFFSET;
if (CWorld::TestSphereAgainstWorld(pos, 0.15f, this, true, false, false, false, false, false))
foundGround = true;
}
@@ -3203,7 +3339,7 @@ CPed::ClearAll(void)
ClearLookFlag();
bIsPointingGunAt = false;
bRenderPedInCar = true;
- bKnockedUpIntoAir = false;
+ m_ped_flagH1 = false;
m_pCollidingEntity = nil;
}
@@ -3419,7 +3555,56 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi
case WEAPONTYPE_BASEBALLBAT:
if (bMeleeProof)
return false;
-
+#ifdef VC_PED_PORTS
+ if (/*method != WEAPONTYPE_KATANA || */
+ damagedBy != FindPlayerPed()
+ || FindPlayerPed()->m_nPedState != PED_FIGHT
+ /*|| FindPlayerPed()->m_lastFightMove != 28 && FindPlayerPed()->m_lastFightMove != 29 */
+ || CGeneral::GetRandomNumber() & 3) {
+
+ if (m_nPedState == PED_FALL) {
+ if (IsPedHeadAbovePos(-0.3f)) {
+ dieAnim = NUM_ANIMS;
+ } else {
+ if (RpAnimBlendClumpGetFirstAssociation(GetClump(), ASSOC_FLAG800))
+ dieAnim = ANIM_FLOOR_HIT_F;
+ else
+ dieAnim = ANIM_FLOOR_HIT;
+ dieDelta = dieDelta * 2.0f;
+ dieSpeed = 0.5f;
+ }
+ } else if (damagedBy != FindPlayerPed()) { // || FindPlayerPed()->m_lastFightMove != 29)
+ //if (damagedBy != FindPlayerPed() || FindPlayerPed()->m_lastFightMove != 30) {
+ switch (direction) {
+ case 0:
+ dieAnim = ANIM_KO_SKID_FRONT;
+ break;
+ case 1:
+ dieAnim = ANIM_KO_SPIN_R;
+ break;
+ case 2:
+ dieAnim = ANIM_KO_SKID_BACK;
+ break;
+ case 3:
+ dieAnim = ANIM_KO_SPIN_L;
+ break;
+ default:
+ break;
+ }
+ //} else {
+ // dieAnim = ANIM_KO_SHOT_STOM;
+ //}
+ } else {
+ dieAnim = ANIM_KO_SHOT_FACE;
+ }
+ } else {
+ dieAnim = ANIM_KO_SHOT_FACE;
+ // SpawnFlyingComponent in VC
+ RemoveBodyPart(PED_HEAD, direction);
+ headShot = true;
+ willLinger = true;
+ }
+#else
if (m_nPedState == PED_FALL) {
if (IsPedHeadAbovePos(-0.3f)) {
dieAnim = NUM_ANIMS;
@@ -3449,6 +3634,7 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi
break;
}
}
+#endif
break;
case WEAPONTYPE_COLT45:
case WEAPONTYPE_UZI:
@@ -3463,8 +3649,7 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi
if (IsPlayer() || bNoCriticalHits)
dontRemoveLimb = true;
else {
- switch (method)
- {
+ switch (method) {
case WEAPONTYPE_SNIPERRIFLE:
dontRemoveLimb = false;
break;
@@ -3709,6 +3894,51 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi
if (bInVehicle) {
if (method != WEAPONTYPE_WATER) {
+#ifdef VC_PED_PORTS
+ if (m_pMyVehicle) {
+ if (m_pMyVehicle->IsCar() && m_pMyVehicle->pDriver == this) {
+ if (m_pMyVehicle->m_status == STATUS_SIMPLE) {
+ m_pMyVehicle->m_status = STATUS_PHYSICS;
+ CCarCtrl::SwitchVehicleToRealPhysics(m_pMyVehicle);
+ }
+ m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ m_pMyVehicle->AutoPilot.m_nTempAction = TEMPACT_HANDBRAKESTRAIGHT;
+ m_pMyVehicle->AutoPilot.m_nTimeTempAction = CTimer::GetTimeInMilliseconds() + 2000;
+ }
+ if (m_pMyVehicle->CanPedExitCar()) {
+ SetObjective(OBJECTIVE_LEAVE_CAR_AND_DIE, m_pMyVehicle);
+ } else {
+ m_fHealth = 0.0f;
+ if (m_pMyVehicle && m_pMyVehicle->pDriver == this) {
+ SetRadioStation();
+ m_pMyVehicle->m_status = STATUS_ABANDONED;
+ }
+ SetDie(dieAnim, dieDelta, dieSpeed);
+ /*
+ if (damagedBy == FindPlayerPed() && damagedBy != this) {
+ // PlayerInfo stuff
+ }
+ */
+ }
+ for (int i = 0; i < 8; i++) {
+ CPed* passenger = m_pMyVehicle->pPassengers[i];
+ if (passenger && passenger != this && damagedBy)
+ passenger->ReactToAttack(damagedBy);
+ }
+
+ CPed *driverOfVeh = m_pMyVehicle->pDriver;
+ if (driverOfVeh && driverOfVeh != this && damagedBy)
+ driverOfVeh->ReactToAttack(damagedBy);
+
+ if (damagedBy == FindPlayerPed() || damagedBy && damagedBy == FindPlayerVehicle()) {
+ CDarkel::RegisterKillByPlayer(this, method, headShot);
+ m_threatEntity = FindPlayerPed();
+ } else {
+ CDarkel::RegisterKillNotByPlayer(this, method);
+ }
+ }
+#endif
m_fHealth = 1.0f;
return false;
}
@@ -3723,6 +3953,8 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi
SetDie(dieAnim, dieDelta, dieSpeed);
if (damagedBy == player || damagedBy && damagedBy == FindPlayerVehicle()) {
+
+ // There are PlayerInfo stuff here in VC
CDarkel::RegisterKillByPlayer(this, method, headShot);
m_threatEntity = player;
} else {
@@ -3792,7 +4024,7 @@ CPed::SetGetUp(void)
}
bGetUpAnimStarted = true;
m_pCollidingEntity = nil;
- bKnockedUpIntoAir = false;
+ m_ped_flagH1 = false;
CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_SPRINT);
if (animAssoc) {
if (RpAnimBlendClumpGetAssociation(GetClump(), ANIM_RUN)) {
@@ -3875,9 +4107,16 @@ CPed::ClearObjective(void)
if (m_nPedState == PED_DRIVING && m_pMyVehicle) {
if (m_pMyVehicle->pDriver != this) {
- bWanderPathAfterExitingCar = true;
+#ifdef VC_PED_PORTS
+ if(!IsPlayer())
+#endif
+ bWanderPathAfterExitingCar = true;
+
SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
}
+#ifdef VC_PED_PORTS
+ m_nLastPedState = PED_NONE;
+#endif
} else {
SetIdle();
SetMoveState(PEDMOVE_STILL);
@@ -4382,8 +4621,8 @@ CPed::SetAttack(CEntity *victim)
if (curWeapon->m_bCanAim) {
CVector aimPos = GetRight() * 0.1f + GetForward() * 0.2f + GetPosition();
- CEntity *foundEntity = CWorld::TestSphereAgainstWorld(aimPos, 0.2f, nil, true, false, false, true, false, false);
- if (foundEntity)
+ CEntity *obstacle = CWorld::TestSphereAgainstWorld(aimPos, 0.2f, nil, true, false, false, true, false, false);
+ if (obstacle)
return;
m_pLookTarget = victim;
@@ -4631,7 +4870,7 @@ CPed::GetLocalDirection(const CVector2D &posOffset)
for (direction = (int)RADTODEG(direction) / 90; direction > 3; direction -= 4);
- // Should be 0-east, 1-north, 2-west, 3-south. Not sure about order.
+ // 0-forward, 1-left, 2-backward, 3-right.
return direction;
}
@@ -4787,7 +5026,7 @@ CPed::FightStrike(CVector &touchedNodePos)
CEventList::RegisterEvent(nearPed->m_nPedType == PEDTYPE_COP ? EVENT_ASSAULT_POLICE : EVENT_ASSAULT, EVENT_ENTITY_PED, nearPed, this, 2000);
}
- if (!m_fightState)
+ if (m_fightState == FIGHTSTATE_NO_MOVE)
m_fightState = FIGHTSTATE_1;
m_vecHitLastPos = *touchedNodePos;
@@ -4916,7 +5155,7 @@ CPed::SetWaitState(eWaitState state, void *time)
break;
case WAITSTATE_CROSS_ROAD:
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 1000;
- CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 3000.0f);
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f);
break;
case WAITSTATE_CROSS_ROAD_LOOK:
CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_ROAD_CROSS, 8.0f);
@@ -4935,7 +5174,7 @@ CPed::SetWaitState(eWaitState state, void *time)
case WAITSTATE_DOUBLEBACK:
m_headingRate = 0.0f;
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 3500;
- CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 3000.0f);
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f);
break;
case WAITSTATE_HITWALL:
m_headingRate = 2.0f;
@@ -4954,14 +5193,14 @@ CPed::SetWaitState(eWaitState state, void *time)
case WAITSTATE_TURN180:
m_headingRate = 0.0f;
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000;
- animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_TURN_180, 3000.0f);
+ animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_TURN_180, 4.0f);
animAssoc->SetFinishCallback(FinishedWaitCB, this);
animAssoc->SetDeleteCallback(RestoreHeadingRateCB, this);
break;
case WAITSTATE_SURPRISE:
m_headingRate = 0.0f;
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 2000;
- animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_HIT_WALL, 3000.0f);
+ animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_HIT_WALL, 4.0f);
animAssoc->SetFinishCallback(FinishedWaitCB, this);
break;
case WAITSTATE_STUCK:
@@ -4969,7 +5208,7 @@ CPed::SetWaitState(eWaitState state, void *time)
SetMoveAnim();
m_headingRate = 0.0f;
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000;
- CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 3000.0f);
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f);
if (m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER && CharCreatedBy == RANDOM_CHAR && m_nPedState == PED_SEEK_CAR) {
ClearObjective();
@@ -4982,7 +5221,7 @@ CPed::SetWaitState(eWaitState state, void *time)
SetMoveAnim();
m_headingRate = 0.0f;
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 5000;
- CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 3000.0f);
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_HBHB, 4.0f);
break;
case WAITSTATE_PLAYANIM_COWER:
waitAnim = ANIM_HANDSCOWER;
@@ -4998,7 +5237,7 @@ CPed::SetWaitState(eWaitState state, void *time)
else
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 3000;
- animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, waitAnim, 3000.0f);
+ animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, waitAnim, 4.0f);
animAssoc->SetDeleteCallback(FinishedWaitCB, this);
break;
case WAITSTATE_PLAYANIM_DUCK:
@@ -5014,7 +5253,7 @@ CPed::SetWaitState(eWaitState state, void *time)
else
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 3000;
- animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, waitAnim, 3000.0f);
+ animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, waitAnim, 4.0f);
animAssoc->flags &= ~ASSOC_FADEOUTWHENDONE;
animAssoc->flags |= ASSOC_DELETEFADEDOUT;
animAssoc->SetDeleteCallback(FinishedWaitCB, this);
@@ -5024,7 +5263,7 @@ CPed::SetWaitState(eWaitState state, void *time)
SetMoveAnim();
m_headingRate = 0.0f;
m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 2500;
- CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 3000.0f);
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TIRED, 4.0f);
break;
default:
m_nWaitState = WAITSTATE_FALSE;
@@ -5098,6 +5337,8 @@ CPed::Say(uint16 audio)
uint16 audioToPlay = audio;
if (IsPlayer()) {
+
+ // Ofc this part isn't in VC.
switch (audio) {
case SOUND_PED_DEATH:
audioToPlay = SOUND_PED_DAMAGE;
@@ -5119,14 +5360,27 @@ CPed::Say(uint16 audio)
return;
if (TheCamera.m_CameraAverageSpeed > 1.65f) {
- return;
+#ifdef VC_PED_PORTS
+ if (audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND)
+#endif
+ return;
+
} else if (TheCamera.m_CameraAverageSpeed > 1.25f) {
- if (audio != SOUND_PED_DEATH && audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE)
+ if (audio != SOUND_PED_DEATH &&
+#ifdef VC_PED_PORTS
+ audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND &&
+#endif
+ audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE)
return;
} else if (TheCamera.m_CameraAverageSpeed > 0.9f) {
switch (audio) {
case SOUND_PED_DEATH:
+#ifdef VC_PED_PORTS
+ case SOUND_PED_DAMAGE:
+ case SOUND_PED_HIT:
+ case SOUND_PED_LAND:
+#endif
case SOUND_PED_BURNING:
case SOUND_PED_FLEE_SPRINT:
case SOUND_PED_TAXI_WAIT:
@@ -5167,7 +5421,12 @@ CPed::CollideWithPed(CPed *collideWith)
if (m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL) {
if ((!IsPlayer() || ((CPlayerPed*)this)->m_fMoveSpeed <= 1.8f)
- && (IsPlayer() || heIsMissionChar && weAreMissionChar || m_nMoveState != PEDMOVE_RUN && m_nMoveState != PEDMOVE_SPRINT)) {
+ && (IsPlayer() || heIsMissionChar && weAreMissionChar || m_nMoveState != PEDMOVE_RUN && m_nMoveState != PEDMOVE_SPRINT
+#ifdef VC_PED_PORTS
+ || m_objective == OBJECTIVE_FOLLOW_PED_IN_FORMATION && m_pedInObjective == collideWith
+ || collideWith->m_objective == OBJECTIVE_FOLLOW_PED_IN_FORMATION && collideWith->m_pedInObjective == this
+#endif
+ )) {
if (m_objective != OBJECTIVE_FOLLOW_PED_IN_FORMATION && m_objective != OBJECTIVE_GOTO_CHAR_ON_FOOT) {
@@ -5175,7 +5434,7 @@ CPed::CollideWithPed(CPed *collideWith)
if (heIsMissionChar || !weAreMissionChar && collideWith->m_nMoveState != PEDMOVE_STILL) {
- if (weAreMissionChar && ((m_nPedState == PED_SEEK_POS) || m_nPedState == PED_SEEK_ENTITY)) {
+ if (weAreMissionChar && (m_nPedState == PED_SEEK_POS || m_nPedState == PED_SEEK_ENTITY)) {
if (collideWith->m_nMoveState != PEDMOVE_STILL
&& (!collideWith->IsPlayer() || collideWith->IsPlayer() && CPad::GetPad(0)->ArePlayerControlsDisabled())) {
@@ -5194,14 +5453,62 @@ CPed::CollideWithPed(CPed *collideWith)
} else if (collideWith->m_nMoveState == PEDMOVE_STILL) {
SetDirectionToWalkAroundObject(collideWith);
}
- } else if (weAreMissionChar || m_pedStats->m_fear <= 100 - collideWith->m_pedStats->m_temper
- || (collideWith->IsPlayer() || collideWith->m_nMoveState == PEDMOVE_NONE || collideWith->m_nMoveState == PEDMOVE_STILL) &&
- (!collideWith->IsPlayer() || ((CPlayerPed*)collideWith)->m_fMoveSpeed <= 1.0f)) {
- SetDirectionToWalkAroundObject(collideWith);
- if (!weAreMissionChar)
- Say(SOUND_PED_CHAT);
} else {
- SetEvasiveStep(collideWith, 2);
+#ifdef VC_PED_PORTS
+ if (FindPlayerPed() != m_pedInObjective
+ || m_objective != OBJECTIVE_KILL_CHAR_ANY_MEANS && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT
+ || collideWith == m_pedInObjective) {
+#endif
+ if (weAreMissionChar || m_pedStats->m_fear <= 100 - collideWith->m_pedStats->m_temper
+ || (collideWith->IsPlayer() || collideWith->m_nMoveState == PEDMOVE_NONE || collideWith->m_nMoveState == PEDMOVE_STILL) &&
+ (!collideWith->IsPlayer() || ((CPlayerPed*)collideWith)->m_fMoveSpeed <= 1.0f)) {
+ SetDirectionToWalkAroundObject(collideWith);
+ if (!weAreMissionChar)
+ Say(SOUND_PED_CHAT);
+ } else {
+ SetEvasiveStep(collideWith, 2);
+ }
+#ifdef VC_PED_PORTS
+ } else if (collideWith->m_nMoveState != PEDMOVE_STILL && GetWeapon()->IsTypeMelee()
+ && collideWith->m_pedInObjective == m_pedInObjective) {
+
+ int colliderIsAtPlayerSafePosID = -1;
+ int weAreAtPlayerSafePosID = -1;
+ for (int i = 0; i < 6; i++) {
+ CPed *pedAtSafePos = ((CPlayerPed*)m_pedInObjective)->m_pPedAtSafePos[i];
+ if (pedAtSafePos == this) {
+ weAreAtPlayerSafePosID = i;
+ } else if (pedAtSafePos == collideWith) {
+ colliderIsAtPlayerSafePosID = i;
+ }
+ }
+ bool weAreCloserToTargetThenCollider = false;
+ if ((GetPosition() - m_vecSeekPos).MagnitudeSqr2D() < (collideWith->GetPosition() - m_vecSeekPos).MagnitudeSqr2D())
+ weAreCloserToTargetThenCollider = true;
+
+ if (weAreAtPlayerSafePosID <= 0 || weAreCloserToTargetThenCollider) {
+ if (!weAreCloserToTargetThenCollider) {
+ int time = 300;
+ SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &time);
+ m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + time;
+ }
+ } else if (colliderIsAtPlayerSafePosID <= 0) {
+ if (collideWith->m_pedInObjective == FindPlayerPed()) {
+ // VC specific
+ // ((CPlayerPed*)m_pedInObjective)->RemovePedFromMeleeList(this);
+ int time = 500;
+ SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &time);
+ m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + time;
+ }
+ } else {
+ int time = 300;
+ SetWaitState(WAITSTATE_CROSS_ROAD_LOOK, &time);
+ m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + time;
+ }
+ } else {
+ SetDirectionToWalkAroundObject(collideWith);
+ }
+#endif
}
} else {
if (m_pedStats->m_temper <= m_pedStats->m_fear
@@ -5258,7 +5565,11 @@ CPed::CollideWithPed(CPed *collideWith)
}
}
}
- } else if (collideWith->m_pedStats->m_defendWeakness <= 1.5f || heIsMissionChar) {
+ } else if (collideWith->m_pedStats->m_defendWeakness <= 1.5f || heIsMissionChar
+#ifdef VC_PED_PORTS
+ || m_pedStats->m_defendWeakness <= collideWith->m_pedStats->m_defendWeakness
+#endif
+ ) {
// He looks us and we're not at his right side
if (heLooksToUs && DotProduct(posDiff,collideWith->GetRight()) > 0.0f) {
CVector moveForce = GetRight();
@@ -5382,6 +5693,7 @@ CPed::CreateDeadPedMoney(void)
int moneyPerPickup = money / pickupCount;
for(int i = 0; i < pickupCount; i++) {
+ // (CGeneral::GetRandomNumber() % 256) * PI / 128 gives a float up to something TWOPI-ish.
float pickupX = 1.5f * Sin((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().x;
float pickupY = 1.5f * Cos((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().y;
bool found = false;
@@ -5475,9 +5787,7 @@ CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack)
bChangedSeat = false;
bWillBeQuickJacked = quickJack;
- CVector pos = GetPosition();
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
- GetPosition() += pos;
+ SetHeading(m_fRotationCur);
Say(SOUND_PED_CAR_JACKED);
SetRadioStation();
@@ -5532,7 +5842,11 @@ CPed::SetChat(CEntity *chatWith, uint32 time)
void
CPed::SetDead(void)
{
- bUsesCollision = false;
+#ifdef VC_PED_PORTS
+ if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DROWN))
+#endif
+ bUsesCollision = false;
+
m_fHealth = 0.0f;
if (m_nPedState == PED_DRIVING)
bIsVisible = false;
@@ -5637,21 +5951,22 @@ uint8
CPed::DoesLOSBulletHitPed(CColPoint &colPoint)
{
RwMatrix mat;
+ uint8 retVal = 2;
CPedIK::GetWorldMatrix(GetNodeFrame(PED_HEAD), &mat);
float headZ = RwMatrixGetPos(&mat)->z;
if (m_nPedState == PED_FALL)
- return 1;
+ retVal = 1;
float colZ = colPoint.point.z;
if (colZ < headZ)
- return 1;
+ retVal = 1;
if (headZ + 0.2f <= colZ)
- return 0;
+ retVal = 0;
- return 2;
+ return retVal;
}
bool
@@ -5955,9 +6270,7 @@ CPed::LineUpPedWithTrain(void)
}
GetPosition() = lineUpPos;
-// CVector pedPos = GetPosition();
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
- GetPosition() += lineUpPos;
+ SetHeading(m_fRotationCur);
}
void
@@ -6494,17 +6807,21 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg)
CVector forward(0.15f * ped->GetForward() + ped->GetPosition());
forward.z += CModelInfo::GetModelInfo(ped->m_modelIndex)->GetColModel()->spheres->center.z + 0.25f;
- CEntity *foundEnt = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false);
- if (!foundEnt) {
+ CEntity *obstacle = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false);
+ if (!obstacle) {
// Forward of forward
forward += 0.15f * ped->GetForward();
forward.z += 0.15f;
- foundEnt = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false);
+ obstacle = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false);
}
- if (foundEnt) {
+ if (obstacle) {
animAssoc->flags |= ASSOC_DELETEFADEDOUT;
+#ifndef VC_PED_PORTS
CAnimBlendAssociation *handsCoverAssoc = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_HANDSCOWER, 8.0f);
+#else
+ CAnimBlendAssociation* handsCoverAssoc = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_HIT_WALL, 8.0f);
+#endif
handsCoverAssoc->flags &= ~ASSOC_FADEOUTWHENDONE;
handsCoverAssoc->SetFinishCallback(FinishHitHeadCB, ped);
ped->bIsLanding = true;
@@ -6523,12 +6840,20 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg)
}
}
- if (ped->IsPlayer())
+ if (ped->IsPlayer()
+#ifdef VC_PED_PORTS
+ || ped->m_pedInObjective && ped->m_pedInObjective->IsPlayer()
+#endif
+ )
ped->ApplyMoveForce(0.0f, 0.0f, 8.5f);
else
ped->ApplyMoveForce(0.0f, 0.0f, 4.5f);
- if (sq(velocityFromAnim) > ped->m_vecMoveSpeed.MagnitudeSqr2D()) {
+ if (sq(velocityFromAnim) > ped->m_vecMoveSpeed.MagnitudeSqr2D()
+#ifdef VC_PED_PORTS
+ || ped->m_pCurrentPhysSurface
+#endif
+ ) {
if (TheCamera.Cams[0].Using3rdPersonMouseCam()) {
float fpsAngle = ped->WorkOutHeadingForMovingFirstPerson(ped->m_fRotationCur);
@@ -6538,6 +6863,12 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg)
ped->m_vecMoveSpeed.x = -velocityFromAnim * Sin(ped->m_fRotationCur);
ped->m_vecMoveSpeed.y = velocityFromAnim * Cos(ped->m_fRotationCur);
}
+#ifdef VC_PED_PORTS
+ if (ped->m_pCurrentPhysSurface) {
+ ped->m_vecMoveSpeed.x += ((CPhysical*)ped->m_pCurrentPhysSurface)->m_vecMoveSpeed.x;
+ ped->m_vecMoveSpeed.y += ((CPhysical*)ped->m_pCurrentPhysSurface)->m_vecMoveSpeed.y;
+ }
+#endif
}
ped->bIsStanding = false;
@@ -6631,7 +6962,7 @@ CPed::Wait(void)
}
break;
- case WAITSTATE_LOOK_PED:
+ case WAITSTATE_CROSS_ROAD_LOOK:
if (CTimer::GetTimeInMilliseconds() > m_nWaitTimer) {
m_nWaitState = WAITSTATE_FALSE;
animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_ROAD_CROSS);
@@ -6788,7 +7119,9 @@ CPed::Wait(void)
if (m_pedStats->m_fear <= 100 - pedWeLook->m_pedStats->m_temper) {
if (GetWeapon()->IsTypeMelee()) {
-
+#ifdef VC_PED_PORTS
+ if(m_pedStats->m_flags & STAT_GUN_PANIC) {
+#endif
SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, m_pLookTarget);
if (m_nPedState == PED_FLEE_ENTITY || m_nPedState == PED_FLEE_POS) {
@@ -6802,6 +7135,12 @@ CPed::Wait(void)
ProcessObjective();
SetMoveState(PEDMOVE_WALK);
}
+#ifdef VC_PED_PORTS
+ } else {
+ SetObjective(OBJECTIVE_NONE);
+ SetWanderPath(CGeneral::GetRandomNumberInRange(0.0f, 8.0f));
+ }
+#endif
} else {
SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, m_pLookTarget);
SetObjectiveTimer(20000);
@@ -6848,6 +7187,19 @@ CPed::Wait(void)
}
m_nWaitState = WAITSTATE_FALSE;
}
+#ifdef VC_PED_PORTS
+ else if (m_nWaitState == WAITSTATE_PLAYANIM_TAXI) {
+ if (m_pedInObjective) {
+ if (m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT) {
+
+ // VC also calls CleanUpOldReference here for old LookTarget.
+ m_pLookTarget = m_pedInObjective;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+ TurnBody();
+ }
+ }
+ }
+#endif
break;
case WAITSTATE_FINISH_FLEE:
@@ -6886,14 +7238,14 @@ CPed::Seek(void)
if ((!m_pedInObjective || !m_pedInObjective->bInVehicle)
&& !((CTimer::GetFrameCounter() + (m_randomSeed % 256) + 17) & 7)) {
- CEntity *foundEnt = CWorld::TestSphereAgainstWorld(m_vecSeekPos, 0.4f, nil,
+ CEntity *obstacle = CWorld::TestSphereAgainstWorld(m_vecSeekPos, 0.4f, nil,
false, true, false, false, false, false);
- if (foundEnt) {
- if (!foundEnt->IsVehicle() || ((CVehicle*)foundEnt)->m_vehType == VEHICLE_TYPE_CAR) {
+ if (obstacle) {
+ if (!obstacle->IsVehicle() || ((CVehicle*)obstacle)->m_vehType == VEHICLE_TYPE_CAR) {
distanceToCountItDone = 2.5f;
} else {
- CVehicleModelInfo *vehModel = (CVehicleModelInfo*) CModelInfo::GetModelInfo(foundEnt->m_modelIndex);
+ CVehicleModelInfo *vehModel = (CVehicleModelInfo*) CModelInfo::GetModelInfo(obstacle->m_modelIndex);
float yLength = vehModel->GetColModel()->boundingBox.max.y
- vehModel->GetColModel()->boundingBox.min.y;
distanceToCountItDone = yLength * 0.55f;
@@ -7076,7 +7428,7 @@ CPed::Flee(void)
if (dirDiff > 2 && dirDiff < 6) {
realLastNode = nil;
m_pLastPathNode = m_pNextPathNode;
- m_pNextPathNode = 0;
+ m_pNextPathNode = nil;
}
}
@@ -7172,8 +7524,8 @@ CPed::Flee(void)
double angleToFleeDamagingThing = CGeneral::GetRadianAngleBetweenPoints(
m_vecDamageNormal.x,
m_vecDamageNormal.y,
- 0.0,
- 0.0);
+ 0.0f,
+ 0.0f);
angleToFleeDamagingThing = CGeneral::LimitRadianAngle(angleToFleeDamagingThing);
if (angleToFleeEntity - PI > angleToFleeDamagingThing)
@@ -7616,7 +7968,11 @@ CPed::InTheAir(void)
if (m_vecMoveSpeed.z < 0.0f && !bIsPedDieAnimPlaying) {
if (!DyingOrDead()) {
if (CWorld::ProcessLineOfSight(ourPos, bitBelow, foundCol, foundEnt, true, true, false, true, false, false, false)) {
- if (GetPosition().z - foundCol.point.z < 1.3f)
+ if (GetPosition().z - foundCol.point.z < 1.3f
+#ifdef VC_PED_PORTS
+ || bIsStanding
+#endif
+ )
SetLanding();
} else {
if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL)) {
@@ -7966,15 +8322,15 @@ CPed::IsRoomToBeCarJacked(void)
if (!m_pMyVehicle)
return false;
- CVector2D offset;
+ CVector offset;
if (m_pMyVehicle->bLowVehicle || m_nPedType == PEDTYPE_COP) {
offset = vecPedDraggedOutCarAnimOffset;
} else {
offset = vecPedQuickDraggedOutCarAnimOffset;
}
- CVector doorPos(offset.x, offset.y, 0.0f);
- if (m_pMyVehicle->IsRoomForPedToLeaveCar(CAR_DOOR_LF, &doorPos)) {
+ offset.z = 0.0f;
+ if (m_pMyVehicle->IsRoomForPedToLeaveCar(CAR_DOOR_LF, &offset)) {
return true;
}
@@ -8165,11 +8521,15 @@ CPed::KillPedWithCar(CVehicle *car, float impulse)
m_pCollidingEntity = car;
}
if (nodeToDamage == PED_MID)
- bKnockedUpIntoAir = true;
+ m_ped_flagH1 = true;
else
- bKnockedUpIntoAir = false;
+ m_ped_flagH1 = false;
distVec.Normalise();
+
+#ifdef VC_PED_PORTS
+ distVec *= min(car->m_fMass / 1400.0f, 1.0f);
+#endif
car->ApplyMoveForce(distVec * -100.0f);
Say(SOUND_PED_DEFEND);
@@ -8189,22 +8549,25 @@ CPed::KillPedWithCar(CVehicle *car, float impulse)
if ((m_nPedState == PED_FALL || m_nPedState == PED_DIE || m_nPedState == PED_DEAD)
&& !m_pCollidingEntity
- && (!IsPlayer() || m_ped_flagD2 || car->m_modelIndex == MI_TRAIN || m_vecDamageNormal.z < -0.8f)) {
+ && (!IsPlayer() || bHasHitWall || car->m_modelIndex == MI_TRAIN || m_vecDamageNormal.z < -0.8f)) {
m_pCollidingEntity = car;
}
- bKnockedUpIntoAir = false;
- if (car->m_modelIndex != MI_TRAIN && !m_ped_flagD2) {
+ m_ped_flagH1 = false;
+ if (car->m_modelIndex != MI_TRAIN && !bHasHitWall) {
m_vecMoveSpeed = car->m_vecMoveSpeed * 0.75f;
}
m_vecMoveSpeed.z = 0.0f;
distVec.Normalise();
+#ifdef VC_PED_PORTS
+ distVec *= min(car->m_fMass / 1400.0f, 1.0f);
+#endif
car->ApplyMoveForce(distVec * -60.0f);
Say(SOUND_PED_DEFEND);
}
-#ifdef FIX_BUGS
+#if defined FIX_BUGS || defined VC_PED_PORTS
// Killing gang members with car wasn't triggering a fight, until now... Taken from VC.
if (IsGangMember()) {
CPed *driver = car->pDriver;
@@ -8794,7 +9157,11 @@ CPed::ProcessControl(void)
if (m_nPedState != PED_ARRESTED) {
if (m_nPedState == PED_DEAD) {
DeadPedMakesTyresBloody();
+#ifndef VC_PED_PORTS
if (CGame::nastyGame) {
+#else
+ if (CGame::nastyGame && !bIsInWater) {
+#endif
uint32 remainingBloodyFpTime = CTimer::GetTimeInMilliseconds() - m_bloodyFootprintCount;
float timeDependentDist;
if (remainingBloodyFpTime >= 2000) {
@@ -8851,6 +9218,14 @@ CPed::ProcessControl(void)
}
if (ServiceTalkingWhenDead())
ServiceTalking();
+
+#ifdef VC_PED_PORTS
+ if (bIsInWater) {
+ bIsStanding = false;
+ m_ped_flagA2 = false;
+ CPhysical::ProcessControl();
+ }
+#endif
return;
}
@@ -8876,7 +9251,11 @@ CPed::ProcessControl(void)
bCollidedWithMyVehicle = false;
CEntity *collidingEnt = m_pDamageEntity;
+#ifndef VC_PED_PORTS
if (!bUsesCollision || m_fDamageImpulse <= 0.0f || m_nPedState == PED_DIE || !collidingEnt) {
+#else
+ if (!bUsesCollision || ((!collidingEnt || m_fDamageImpulse <= 0.0f) && (!IsPlayer() || !bIsStuck)) || m_nPedState == PED_DIE) {
+#endif
bHitSomethingLastFrame = false;
if (m_nPedStateTimer <= 500 && bIsInTheAir) {
if (m_nPedStateTimer)
@@ -8895,8 +9274,11 @@ CPed::ProcessControl(void)
}
*/
+#ifndef VC_PED_PORTS
} else {
-
+#else
+ } else if (collidingEnt) {
+#endif
switch (collidingEnt->m_type)
{
case ENTITY_TYPE_BUILDING:
@@ -8918,19 +9300,30 @@ CPed::ProcessControl(void)
break;
}
- float angleToFlee = CGeneral::GetRadianAngleBetweenPoints(
+ float angleToFaceWhenHit = CGeneral::GetRadianAngleBetweenPoints(
GetPosition().x,
GetPosition().y,
m_vecDamageNormal.x + GetPosition().x,
m_vecDamageNormal.y + GetPosition().y);
- float neededTurn = Abs(m_fRotationCur - angleToFlee);
+ float neededTurn = Abs(m_fRotationCur - angleToFaceWhenHit);
if (neededTurn > PI)
neededTurn = TWOPI - neededTurn;
float oldDestRot = CGeneral::LimitRadianAngle(m_fRotationDest);
+#ifdef VC_PED_PORTS
+ if (m_nPedState == PED_FOLLOW_PATH) {
+ if (DotProduct(m_vecDamageNormal, GetForward()) < -0.866f && CanPedJumpThis(collidingEnt, &m_vecDamageNormal)) {
+ SetJump();
+
+ // Moved break into here, for compatibility with III
+ break;
+ }
+ // break;
+ }
+#endif
if (m_pedInObjective &&
(m_objective == OBJECTIVE_GOTO_CHAR_ON_FOOT || m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT)) {
@@ -9097,13 +9490,178 @@ CPed::ProcessControl(void)
}
case ENTITY_TYPE_VEHICLE:
{
- CVehicle *collidingVeh = ((CVehicle*)collidingEnt);
+ CVehicle* collidingVeh = ((CVehicle*)collidingEnt);
float collidingVehSpeedSqr = collidingVeh->m_vecMoveSpeed.MagnitudeSqr();
if (collidingVeh == m_pMyVehicle)
bCollidedWithMyVehicle = true;
+#ifdef VC_PED_PORTS
+ float oldHealth = m_fHealth;
+ bool playerSufferSound = false;
if (collidingVehSpeedSqr <= 1.0f / 400.0f) {
+ if (IsPedInControl()
+ && (!IsPlayer()
+ || m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT
+ || m_objective == OBJECTIVE_RUN_TO_AREA
+ || m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER)) {
+
+ if (collidingVeh != m_pCurrentPhysSurface || IsPlayer()) {
+ if (!m_ped_flagB80) {
+ if (collidingVeh->m_status != STATUS_PLAYER || CharCreatedBy == MISSION_CHAR) {
+
+ // VC calls SetDirectionToWalkAroundVehicle instead if ped is in PED_SEEK_CAR.
+ SetDirectionToWalkAroundObject(collidingVeh);
+ CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer;
+ } else {
+ if (CTimer::GetTimeInMilliseconds() >= CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer
+ || m_nPedStateTimer >= CTimer::GetTimeInMilliseconds()) {
+
+ // VC calls SetDirectionToWalkAroundVehicle instead if ped is in PED_SEEK_CAR.
+ SetDirectionToWalkAroundObject(collidingVeh);
+ CWorld::Players[CWorld::PlayerInFocus].m_nLastBumpPlayerCarTimer = m_nPedStateTimer;
+
+ } else if (m_fleeFrom != collidingVeh) {
+ SetFlee(collidingVeh, 4000);
+ bUsePedNodeSeek = false;
+ SetMoveState(PEDMOVE_WALK);
+ }
+ }
+ }
+ } else {
+ float angleLeftToCompleteTurn = Abs(m_fRotationCur - m_fRotationDest);
+ if (angleLeftToCompleteTurn < 0.01f && CanPedJumpThis(collidingVeh)) {
+ SetJump();
+ }
+ }
+ } else if (IsPlayer() && !bIsInTheAir) {
+
+ if (IsPedInControl() && ((CPlayerPed*)this)->m_fMoveSpeed == 0.0f
+ && !bIsLooking && CTimer::GetTimeInMilliseconds() > m_lookTimer && collidingVeh->pDriver) {
+
+ ((CPlayerPed*)this)->AnnoyPlayerPed(false);
+ SetLookFlag(collidingVeh, true);
+ SetLookTimer(1300);
+
+ eWeaponType weaponType = GetWeapon()->m_eWeaponType;
+ if (weaponType == WEAPONTYPE_UNARMED
+ || weaponType == WEAPONTYPE_BASEBALLBAT
+ || weaponType == WEAPONTYPE_COLT45
+ || weaponType == WEAPONTYPE_UZI) {
+ bShakeFist = true;
+ }
+ } else {
+ SetLookFlag(collidingVeh, true);
+ SetLookTimer(500);
+ }
+ }
+ } else {
+ float adjustedImpulse = m_fDamageImpulse;
+ if (IsPlayer()) {
+ if (bIsStanding) {
+ float forwardVecAndDamageDirDotProd = DotProduct(m_vecAnimMoveDelta.y * GetForward(), m_vecDamageNormal);
+ if (forwardVecAndDamageDirDotProd < 0.0f) {
+ adjustedImpulse = forwardVecAndDamageDirDotProd * m_fMass + m_fDamageImpulse;
+ if (adjustedImpulse < 0.0f)
+ adjustedImpulse = 0.0f;
+ }
+ }
+ }
+ if (m_fMass / 20.0f < adjustedImpulse)
+ DMAudio.PlayOneShot(collidingVeh->m_audioEntityId, SOUND_CAR_PED_COLLISION, adjustedImpulse);
+
+ if (IsPlayer()) {
+ if (adjustedImpulse > 20.0f)
+ adjustedImpulse = 20.0f;
+
+ if (adjustedImpulse > 5.0f) {
+ if (adjustedImpulse <= 13.0f)
+ playerSufferSound = true;
+ else
+ Say(SOUND_PED_DAMAGE);
+ }
+
+ CColModel* collidingCol = CModelInfo::GetModelInfo(collidingVeh->m_modelIndex)->GetColModel();
+ CVector colMinVec = collidingCol->boundingBox.min;
+ CVector colMaxVec = collidingCol->boundingBox.max;
+
+ CVector vehColCenterDist = collidingVeh->GetMatrix() * ((colMinVec + colMaxVec) * 0.5f) - GetPosition();
+
+ // TLVC = To look vehicle center
+
+ float angleToVehFront = collidingVeh->GetForward().Heading();
+ float angleDiffFromLookingFrontTLVC = angleToVehFront - vehColCenterDist.Heading();
+ angleDiffFromLookingFrontTLVC = CGeneral::LimitRadianAngle(angleDiffFromLookingFrontTLVC);
+
+ // I don't know why do we use that
+ float vehTopRightHeading = Atan2(colMaxVec.x - colMinVec.x, colMaxVec.y - colMinVec.y);
+
+ CVector vehDist = GetPosition() - collidingVeh->GetPosition();
+ vehDist.Normalise();
+
+ float vehRightVecAndSpeedDotProd;
+
+ if (Abs(angleDiffFromLookingFrontTLVC) >= vehTopRightHeading && Abs(angleDiffFromLookingFrontTLVC) < PI - vehTopRightHeading) {
+ if (angleDiffFromLookingFrontTLVC <= 0.0f) {
+ vehRightVecAndSpeedDotProd = DotProduct(collidingVeh->GetRight(), collidingVeh->m_vecMoveSpeed);
+
+ // vehRightVecAndSpeedDotProd < 0.1f = Vehicle being overturned or spinning to it's right?
+ if (collidingVehSpeedSqr > 1.0f / 100.0f && vehRightVecAndSpeedDotProd < 0.1f) {
+
+ // Car's right faces towards us and isn't coming directly to us
+ if (DotProduct(collidingVeh->GetRight(), GetForward()) < 0.0f
+ && DotProduct(vehDist, collidingVeh->m_vecMoveSpeed) > 0.0f) {
+ SetEvasiveStep(collidingVeh, 1);
+ }
+ }
+ } else {
+ vehRightVecAndSpeedDotProd = DotProduct(-1.0f * collidingVeh->GetRight(), collidingVeh->m_vecMoveSpeed);
+
+ if (collidingVehSpeedSqr > 1.0f / 100.0f && vehRightVecAndSpeedDotProd < 0.1f) {
+ if (DotProduct(collidingVeh->GetRight(), GetForward()) > 0.0f
+ && DotProduct(vehDist, collidingVeh->m_vecMoveSpeed) > 0.0f) {
+ SetEvasiveStep(collidingVeh, 1);
+ }
+ }
+ }
+ } else {
+ vehRightVecAndSpeedDotProd = DotProduct(vehDist, collidingVeh->m_vecMoveSpeed);
+ }
+
+ if (vehRightVecAndSpeedDotProd <= 0.1f) {
+ if (m_nPedState != PED_FIGHT) {
+ SetLookFlag(collidingVeh, true);
+ SetLookTimer(700);
+ }
+ } else {
+ bIsStanding = false;
+ CVector2D collidingEntMoveDir = -collidingVeh->m_vecMoveSpeed;
+ int dir = GetLocalDirection(collidingEntMoveDir);
+ SetFall(1000, (AnimationId)(dir + 25), false);
+
+ float damage;
+ if (collidingVeh->m_modelIndex == MI_TRAIN) {
+ damage = 50.0f;
+ } else {
+ damage = 20.0f;
+ }
+
+ InflictDamage(collidingVeh, WEAPONTYPE_RAMMEDBYCAR, damage, PEDPIECE_TORSO, dir);
+ Say(SOUND_PED_DAMAGE);
+ }
+ } else {
+ KillPedWithCar(collidingVeh, m_fDamageImpulse);
+ }
+
+ /* VC specific
+ if (m_pCollidingEntity != collidingEnt)
+ bPushedAlongByCar = true;
+ */
+ }
+ if (m_fHealth < oldHealth && playerSufferSound)
+ Say(SOUND_PED_HIT);
+#else
+ if (collidingVehSpeedSqr <= 1.0f / 400.0f) {
if (!IsPedInControl()
|| IsPlayer()
&& m_objective != OBJECTIVE_GOTO_AREA_ON_FOOT
@@ -9134,9 +9692,8 @@ CPed::ProcessControl(void)
SetLookTimer(500);
}
}
- } else if (!m_ped_flagB80) {
- // I don't remember any condition that we were STATUS_PLAYER.
+ } else if (!m_ped_flagB80) {
if (collidingVeh->m_status != STATUS_PLAYER || CharCreatedBy == MISSION_CHAR) {
SetDirectionToWalkAroundObject(collidingVeh);
@@ -9154,7 +9711,7 @@ CPed::ProcessControl(void)
}
}
} else {
- DMAudio.PlayOneShot(collidingVeh->m_audioEntityId, 142, m_fDamageImpulse);
+ DMAudio.PlayOneShot(collidingVeh->m_audioEntityId, SOUND_CAR_PED_COLLISION, m_fDamageImpulse);
if (IsPlayer()) {
CColModel *collidingCol = CModelInfo::GetModelInfo(collidingVeh->m_modelIndex)->GetColModel();
CVector colMinVec = collidingCol->boundingBox.min;
@@ -9168,15 +9725,15 @@ CPed::ProcessControl(void)
float angleDiffFromLookingFrontTLVC = angleToVehFront - vehColCenterDist.Heading();
angleDiffFromLookingFrontTLVC = CGeneral::LimitRadianAngle(angleDiffFromLookingFrontTLVC);
- // Not sure about this one
- float minNeededTurnTLVC = Atan2(colMaxVec.x - colMinVec.x, colMaxVec.y - colMinVec.y);
+ // I don't know why do we use that
+ float vehTopRightHeading = Atan2(colMaxVec.x - colMinVec.x, colMaxVec.y - colMinVec.y);
CVector vehDist = GetPosition() - collidingVeh->GetPosition();
vehDist.Normalise();
float vehRightVecAndSpeedDotProd;
- if (Abs(angleDiffFromLookingFrontTLVC) >= minNeededTurnTLVC && Abs(angleDiffFromLookingFrontTLVC) < PI - minNeededTurnTLVC) {
+ if (Abs(angleDiffFromLookingFrontTLVC) >= vehTopRightHeading && Abs(angleDiffFromLookingFrontTLVC) < PI - vehTopRightHeading) {
if (angleDiffFromLookingFrontTLVC <= 0.0f) {
vehRightVecAndSpeedDotProd = DotProduct(collidingVeh->GetRight(), collidingVeh->m_vecMoveSpeed);
@@ -9231,6 +9788,7 @@ CPed::ProcessControl(void)
KillPedWithCar(collidingVeh, m_fDamageImpulse);
}
}
+#endif
break;
}
case ENTITY_TYPE_PED:
@@ -9265,7 +9823,12 @@ CPed::ProcessControl(void)
}
}
CVector forceDir;
- if (!bIsInTheAir && m_nPedState != PED_JUMP) {
+ if (!bIsInTheAir && m_nPedState != PED_JUMP
+#ifdef VC_PED_PORTS
+ && m_fDamageImpulse > 0.0f
+#endif
+ ) {
+
forceDir = m_vecDamageNormal;
forceDir.z = 0.0f;
if (!bIsStanding) {
@@ -9276,7 +9839,11 @@ CPed::ProcessControl(void)
ApplyMoveForce(forceDir);
}
- if (bIsInTheAir && !DyingOrDead()) {
+ if ((bIsInTheAir && !DyingOrDead())
+#ifdef VC_PED_PORTS
+ || (!bIsStanding && !m_ped_flagA2 && m_nPedState == PED_FALL)
+#endif
+ ) {
if (m_nPedStateTimer <= 1000 && m_nPedStateTimer) {
forceDir = GetPosition() - m_vecHitLastPos;
} else {
@@ -9297,29 +9864,54 @@ CPed::ProcessControl(void)
if (m_nCollisionRecords == 1 && m_aCollisionRecords[0] != nil && m_aCollisionRecords[0]->m_type == ENTITY_TYPE_BUILDING
&& m_nPedStateTimer > 50.0f / (2.0f * adjustedTs) && m_nPedStateTimer * 1.0f / 250.0f > Abs(forceDir.z)) {
offsetToCheck.x = -forceDir.y;
+#ifdef VC_PED_PORTS
+ offsetToCheck.z = 1.0f;
+#else
offsetToCheck.z = 0.0f;
+#endif
offsetToCheck.y = forceDir.x;
offsetToCheck.Normalise();
CVector posToCheck = GetPosition() + offsetToCheck;
- float lastCollidingColZ;
- if (CWorld::ProcessVerticalLine(posToCheck, -20.0f, foundCol, foundEnt, true, false, false, false, false, false, false)) {
- lastCollidingColZ = foundCol.point.z;
+ // These are either obstacle or ground to land, I don't know which one.
+ float obstacleForFlyingZ, obstacleForFlyingOtherDirZ;
+ CColPoint obstacleForFlying, obstacleForFlyingOtherDir;
+
+ // Check is there any room for being knocked up in reverse direction of force
+ if (CWorld::ProcessVerticalLine(posToCheck, -20.0f, obstacleForFlying, foundEnt, true, false, false, false, false, false, false)) {
+ obstacleForFlyingZ = obstacleForFlying.point.z;
} else {
- lastCollidingColZ = 500.0f;
+ obstacleForFlyingZ = 500.0f;
}
posToCheck = GetPosition() - offsetToCheck;
- float lastCollidingColInOtherDirZ;
- if (CWorld::ProcessVerticalLine(posToCheck, -20.0f, foundCol, foundEnt, true, false, false, false, false, false, false)) {
- lastCollidingColInOtherDirZ = foundCol.point.z;
+ // Now check for direction of force this time
+ if (CWorld::ProcessVerticalLine(posToCheck, -20.0f, obstacleForFlyingOtherDir, foundEnt, true, false, false, false, false, false, false)) {
+ obstacleForFlyingOtherDirZ = obstacleForFlyingOtherDir.point.z;
+ } else {
+ obstacleForFlyingOtherDirZ = 501.0f;
+ }
+#ifdef VC_PED_PORTS
+ uint8 flyDir = 0;
+ float feetZ = GetPosition().z - FEET_OFFSET;
+ if ((obstacleForFlyingZ <= feetZ || obstacleForFlyingOtherDirZ >= 500.0f) && (obstacleForFlyingZ <= feetZ || obstacleForFlyingOtherDirZ <= feetZ)) {
+ if (obstacleForFlyingOtherDirZ > feetZ && obstacleForFlyingZ < 499.0f)
+ flyDir = 2;
} else {
- lastCollidingColInOtherDirZ = 501.0f;
+ flyDir = 1;
}
- if (lastCollidingColZ < lastCollidingColInOtherDirZ) {
+ if (flyDir != 0 && !bKnockedUpIntoAir) {
+ GetPosition() = (flyDir == 2 ? obstacleForFlyingOtherDir.point : obstacleForFlying.point);
+ GetPosition().z += FEET_OFFSET;
+ GetMatrix().UpdateRW();
+ SetLanding();
+ bIsStanding = true;
+ }
+#endif
+ if (obstacleForFlyingZ < obstacleForFlyingOtherDirZ) {
offsetToCheck *= -1.0f;
}
offsetToCheck.z = 1.0f;
@@ -9332,19 +9924,36 @@ CPed::ProcessControl(void)
m_fRotationCur = CGeneral::GetRadianAngleBetweenPoints(offsetToCheck.x, offsetToCheck.y, 0.0f, 0.0f);
m_fRotationCur = CGeneral::LimitRadianAngle(m_fRotationCur);
m_fRotationDest = m_fRotationCur;
- CVector pos = GetPosition();
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
- GetPosition() += pos;
+ SetHeading(m_fRotationCur);
if (m_nPedState != PED_FALL && !bIsPedDieAnimPlaying) {
CPed::SetFall(1000, ANIM_KO_SKID_BACK, true);
}
bIsInTheAir = false;
} else if (m_vecDamageNormal.z > 0.4f) {
+#ifndef VC_PED_PORTS
forceDir = m_vecDamageNormal;
forceDir.z = 0.0f;
forceDir.Normalise();
ApplyMoveForce(2.0f * forceDir);
+#else
+ if (m_nPedState == PED_JUMP) {
+ if (m_nWaitTimer <= 2000) {
+ if (m_nWaitTimer < 1000)
+ m_nWaitTimer += CTimer::GetTimeStep() * 0.02f * 1000.0f;
+ } else {
+ m_nWaitTimer = 0;
+ }
+ }
+ forceDir = m_vecDamageNormal;
+ forceDir.z = 0.0f;
+ forceDir.Normalise();
+ if (m_nPedState != PED_JUMP || m_nWaitTimer >= 300) {
+ ApplyMoveForce(2.0f * forceDir);
+ } else {
+ ApplyMoveForce(-4.0f * forceDir);
+ }
+#endif
}
} else if ((CTimer::GetFrameCounter() + m_randomSeed % 256 + 3) & 7) {
if (IsPlayer() && m_nPedState != PED_JUMP && pad0->JumpJustDown()) {
@@ -9355,9 +9964,7 @@ CPed::ProcessControl(void)
m_fRotationDest -= TheCamera.Orientation;
m_fRotationDest = CGeneral::LimitRadianAngle(m_fRotationDest);
m_fRotationCur = m_fRotationDest;
- CVector pos = GetPosition();
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
- GetPosition() += pos;
+ SetHeading(m_fRotationCur);
}
SetJump();
m_nPedStateTimer = 0;
@@ -9369,13 +9976,11 @@ CPed::ProcessControl(void)
int16 padWalkX = pad0->GetPedWalkLeftRight();
int16 padWalkY = pad0->GetPedWalkUpDown();
if (Abs(padWalkX) > 0.0f || Abs(padWalkY) > 0.0f) {
- m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(0.0, 0.0, -padWalkX, padWalkY);
+ m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(0.0f, 0.0f, -padWalkX, padWalkY);
m_fRotationDest -= TheCamera.Orientation;
m_fRotationDest = CGeneral::LimitRadianAngle(m_fRotationDest);
m_fRotationCur = m_fRotationDest;
- CVector pos = GetPosition();
- GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur);
- GetPosition() += pos;
+ SetHeading(m_fRotationCur);
}
CAnimBlendAssociation *jumpAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_JUMP_GLIDE);
@@ -9403,9 +10008,18 @@ CPed::ProcessControl(void)
offsetToCheck = GetPosition();
offsetToCheck.z += 0.5f;
- if (CWorld::ProcessVerticalLine(offsetToCheck, GetPosition().z - 1.04f, foundCol, foundEnt, true, true, false, true, false, false, false)) {
- GetPosition().z = 1.04f + foundCol.point.z;
+ if (CWorld::ProcessVerticalLine(offsetToCheck, GetPosition().z - FEET_OFFSET, foundCol, foundEnt, true, true, false, true, false, false, false)) {
+#ifdef VC_PED_PORTS
+ if (!bKnockedUpIntoAir || FEET_OFFSET + foundCol.point.z < GetPosition().z) {
+ GetPosition().z = FEET_OFFSET + foundCol.point.z;
+ GetMatrix().UpdateRW();
+ if (bKnockedUpIntoAir)
+ bKnockedUpIntoAir = false;
+ }
+#else
+ GetPosition().z = FEET_OFFSET + foundCol.point.z;
GetMatrix().UpdateRW();
+#endif
SetLanding();
bIsStanding = true;
}
@@ -9434,8 +10048,31 @@ CPed::ProcessControl(void)
m_vecMoveSpeed *= airResistance;
}
+#ifdef VC_PED_PORTS
+ if (IsPlayer() || !bIsStanding || m_vecMoveSpeed.x != 0.0f || m_vecMoveSpeed.y != 0.0f || m_vecMoveSpeed.z != 0.0f
+ || (m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL)
+ || m_vecAnimMoveDelta.x != 0.0f || m_vecAnimMoveDelta.y != 0.0f
+ || m_nPedState == PED_JUMP
+ || bIsInTheAir
+ || m_pCurrentPhysSurface) {
+ CPhysical::ProcessControl();
+ } else {
+ bHasContacted = false;
+ bIsInSafePosition = false;
+ bWasPostponed = false;
+ bHasHitWall = false;
+ m_nCollisionRecords = 0;
+ bHasCollided = 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);
+ }
+#else
CPhysical::ProcessControl();
+#endif
if (m_nPedState != PED_DIE || bIsPedDieAnimPlaying) {
if (m_nPedState != PED_DEAD) {
CalculateNewVelocity();
@@ -9445,8 +10082,18 @@ CPed::ProcessControl(void)
PlayFootSteps();
if (IsPedInControl() && !bIsStanding && !m_pDamageEntity && CheckIfInTheAir()) {
SetInTheAir();
+#ifdef VC_PED_PORTS
+ bKnockedUpIntoAir = true;
+#endif
}
-
+#ifdef VC_PED_PORTS
+ if (bKnockedUpIntoAir) {
+ CVector posToCheck = GetPosition();
+ posToCheck.z += 0.9f;
+ if (!CWorld::TestSphereAgainstWorld(posToCheck, 0.2f, this, true, true, false, true, false, false))
+ bKnockedUpIntoAir = false;
+ }
+#endif
ProcessObjective();
if (!bIsAimingGun) {
if (bIsRestoringGun)
@@ -9747,7 +10394,7 @@ CPed::ProcessControl(void)
break;
}
SetMoveAnim();
- if (m_ped_flagD4) {
+ if (bPedIsBleeding) {
if (CGame::nastyGame) {
if (!(CTimer::GetFrameCounter() & 3)) {
CVector cameraDist = GetPosition() - TheCamera.GetPosition();
@@ -9858,7 +10505,11 @@ CPed::PedAnimDoorCloseCB(CAnimBlendAssociation *animAssoc, void *arg)
} else if (ped->m_vehEnterType == CAR_DOOR_RF
&& (veh->m_nGettingInFlags & CAR_DOOR_FLAG_LF ||
(veh->pDriver != nil &&
- (veh->pDriver->m_objective != OBJECTIVE_LEAVE_VEHICLE || !veh->IsRoomForPedToLeaveCar(CAR_DOOR_LF, nil))))) {
+ (veh->pDriver->m_objective != OBJECTIVE_LEAVE_VEHICLE
+#ifdef VC_PED_PORTS
+ && veh->pDriver->m_objective != OBJECTIVE_LEAVE_CAR_AND_DIE
+#endif
+ || !veh->IsRoomForPedToLeaveCar(CAR_DOOR_LF, nil))))) {
if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER)
veh->m_veh_flagC10 = false;
@@ -10091,7 +10742,11 @@ CPed::PedAnimDoorOpenCB(CAnimBlendAssociation* animAssoc, void* arg)
void
CPed::SetJump(void)
{
- if (!bInVehicle && (m_nSurfaceTouched != SURFACE_STONE || DotProduct(GetForward(), m_vecDamageNormal) >= 0.0f)) {
+ if (!bInVehicle &&
+#ifdef VC_PED_PORTS
+ m_nPedState != PED_JUMP && !RpAnimBlendClumpGetAssociation(GetClump(), ANIM_JUMP_LAUNCH) &&
+#endif
+ (m_nSurfaceTouched != SURFACE_STONE || DotProduct(GetForward(), m_vecDamageNormal) >= 0.0f)) {
SetStoredState();
m_nPedState = PED_JUMP;
CAnimBlendAssociation *jumpAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_JUMP_LAUNCH, 8.0f);
@@ -10375,17 +11030,27 @@ CPed::PedAnimStepOutCarCB(CAnimBlendAssociation* animAssoc, void* arg)
PedSetOutCarCB(nil, ped);
return;
}
+#ifdef VC_PED_PORTS
+ CVector posForZ = ped->GetPosition();
+ CPedPlacement::FindZCoorForPed(&posForZ);
+ if (ped->GetPosition().z - 0.5f > posForZ.z) {
+ PedSetOutCarCB(nil, ped);
+ return;
+ }
+#endif
veh->m_nStaticFrames = 0;
veh->m_vecMoveSpeed += CVector(0.001f, 0.001f, 0.001f);
veh->m_vecTurnSpeed += CVector(0.001f, 0.001f, 0.001f);
if (!veh->bIsBus)
veh->ProcessOpenDoor(ped->m_vehEnterType, ANIM_CAR_GETOUT_LHS, 1.0f);
- // Duplicate and pointless code
+ /*
+ // Duplicate and only in PC for some reason
if (!veh) {
PedSetOutCarCB(nil, ped);
return;
}
+ */
eDoors door;
switch (ped->m_vehEnterType) {
case CAR_DOOR_RF:
@@ -10447,6 +11112,11 @@ CPed::PedAnimStepOutCarCB(CAnimBlendAssociation* animAssoc, void* arg)
}
}
+#ifdef VC_PED_PORTS
+ if (ped->m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE)
+ closeDoor = false;
+#endif
+
if (!closeDoor) {
if (!veh->IsDoorMissing(door) && !veh->bIsBus) {
((CAutomobile*)veh)->Damage.SetDoorStatus(door, DOOR_STATUS_SWINGING);
@@ -10860,10 +11530,2861 @@ CPed::PedSetInTrainCB(CAnimBlendAssociation* animAssoc, void* arg)
veh->AddPassenger(ped);
}
-WRAPPER void CPed::PedStaggerCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8D0); }
-WRAPPER void CPed::PedSetOutCarCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4CE8F0); }
-WRAPPER void CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *dragAssoc, void *arg) { EAXJMP(0x4E2480); }
-WRAPPER void CPed::PedSetOutTrainCB(CAnimBlendAssociation *assoc, void *arg) { EAXJMP(0x4E36E0); }
+void
+CPed::PedStaggerCB(CAnimBlendAssociation* animAssoc, void* arg)
+{
+ /*
+ CPed *ped = (CPed*)arg;
+
+ if (ped->m_nPedState == PED_STAGGER)
+ // nothing
+ */
+}
+
+// It's "CPhoneInfo::ProcessNearestFreePhone" in PC IDB, but it's not true, someone made it up.
+// TO-DO: No peds run to phones to report crimes. Make this work.
+bool
+CPed::RunToReportCrime(eCrimeType crimeToReport)
+{
+ if (m_nPedState == PED_SEEK_POS)
+ return false;
+
+ CVector pos = GetPosition();
+ int phoneId = gPhoneInfo.FindNearestFreePhone(&pos);
+
+ if (phoneId == -1)
+ return false;
+
+ if (gPhoneInfo.m_aPhones[phoneId].m_nState != PHONE_STATE_FREE)
+ return false;
+
+ bRunningToPhone = true;
+ SetMoveState(PEDMOVE_RUN);
+ SetSeek(gPhoneInfo.m_aPhones[phoneId].m_vecPos, 0.3f);
+ m_phoneId = phoneId;
+ m_crimeToReportOnPhone = crimeToReport;
+ return true;
+}
+
+void
+CPed::RegisterThreatWithGangPeds(CEntity *attacker)
+{
+ CPed *attackerPed = nil;
+ if (attacker) {
+ if (m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT && m_objective != OBJECTIVE_KILL_CHAR_ANY_MEANS) {
+ if (attacker->IsPed()) {
+ attackerPed = (CPed*)attacker;
+ } else {
+ if (!attacker->IsVehicle())
+ return;
+
+ attackerPed = ((CVehicle*)attacker)->pDriver;
+ if (!attackerPed)
+ return;
+ }
+
+ if (attackerPed && (attackerPed->IsPlayer() || attackerPed->IsGangMember())) {
+ for (int i = 0; i < m_numNearPeds; ++i) {
+ CPed *nearPed = m_nearPeds[i];
+ if (nearPed->IsPointerValid()) {
+ if (nearPed != this && nearPed->m_nPedType == m_nPedType)
+ nearPed->m_fearFlags |= CPedType::GetFlag(attackerPed->m_nPedType);
+ }
+ }
+ }
+ }
+ }
+
+ if (attackerPed && attackerPed->IsPlayer() && (attackerPed->m_nPedState == PED_CARJACK || attackerPed->bInVehicle)) {
+ if (!attackerPed->m_pMyVehicle || attackerPed->m_pMyVehicle->m_modelIndex != MI_TOYZ) {
+ int16 lastVehicle;
+ CEntity *vehicles[8];
+ CWorld::FindObjectsInRange(GetPosition(), 30.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false);
+
+ if (lastVehicle > 8)
+ lastVehicle = 8;
+
+ for (int j = 0; j < lastVehicle; ++j) {
+ CVehicle *nearVeh = (CVehicle*) vehicles[j];
+
+ if (nearVeh->VehicleCreatedBy != MISSION_VEHICLE) {
+ CPed *nearVehDriver = nearVeh->pDriver;
+
+ if (nearVehDriver && nearVehDriver != this && nearVehDriver->m_nPedType == m_nPedType) {
+
+ if (nearVeh->IsVehicleNormal() && nearVeh->IsCar()) {
+ nearVeh->AutoPilot.m_nCruiseSpeed = 60.0f * nearVeh->pHandling->Transmission.fUnkMaxVelocity * 0.8f;
+ nearVeh->AutoPilot.m_nCarMission = MISSION_RAMPLAYER_FARAWAY;
+ nearVeh->m_status = STATUS_PHYSICS;
+ nearVeh->AutoPilot.m_nTempAction = TEMPACT_NONE;
+ nearVeh->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void
+CPed::ReactToPointGun(CEntity *entWithGun)
+{
+ CPed *pedWithGun = (CPed*)entWithGun;
+ int waitTime;
+
+ if (IsPlayer() || !IsPedInControl() || CharCreatedBy == MISSION_CHAR)
+ return;
+
+ if (m_leader == pedWithGun)
+ return;
+
+ if (m_nWaitState == WAITSTATE_PLAYANIM_HANDSUP || m_nWaitState == WAITSTATE_PLAYANIM_HANDSCOWER ||
+ (GetPosition() - pedWithGun->GetPosition()).MagnitudeSqr2D() > 225.0f)
+ return;
+
+ if (m_leader) {
+ if (FindPlayerPed() == m_leader)
+ return;
+
+ ClearLeader();
+ }
+ if (m_pedStats->m_flags & STAT_GUN_PANIC
+ && (m_nPedState != PED_ATTACK || GetWeapon()->IsTypeMelee())
+ && m_nPedState != PED_FLEE_ENTITY && m_nPedState != PED_AIM_GUN) {
+
+ waitTime = CGeneral::GetRandomNumberInRange(3000, 6000);
+ SetWaitState(WAITSTATE_PLAYANIM_HANDSCOWER, &waitTime);
+ Say(SOUND_PED_HANDS_COWER);
+ m_pLookTarget = pedWithGun;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+ SetMoveState(PEDMOVE_NONE);
+
+ } else if (m_nPedType != pedWithGun->m_nPedType) {
+ if (IsGangMember() || m_nPedType == PEDTYPE_EMERGENCY || m_nPedType == PEDTYPE_FIREMAN) {
+ RegisterThreatWithGangPeds(pedWithGun);
+ }
+
+ if (m_nPedType == PEDTYPE_COP) {
+ if (pedWithGun->IsPlayer()) {
+ ((CPlayerPed*)pedWithGun)->m_pWanted->SetWantedLevelNoDrop(2);
+ }
+ if (bCrouchWhenShooting || bKindaStayInSamePlace) {
+ SetDuck(CGeneral::GetRandomNumberInRange(1000, 3000));
+ }
+
+ } else if (m_nPedType != PEDTYPE_COP
+ && (m_nPedState != PED_ATTACK || GetWeapon()->IsTypeMelee())
+ && (m_nPedState != PED_FLEE_ENTITY || pedWithGun->IsPlayer() && m_fleeFrom != pedWithGun)
+ && m_nPedState != PED_AIM_GUN && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT) {
+
+ waitTime = CGeneral::GetRandomNumberInRange(3000, 6000);
+ SetWaitState(WAITSTATE_PLAYANIM_HANDSUP, &waitTime);
+ Say(SOUND_PED_HANDS_UP);
+ m_pLookTarget = pedWithGun;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+ SetMoveState(PEDMOVE_NONE);
+ if (m_nPedState == PED_FLEE_ENTITY) {
+ m_fleeFrom = pedWithGun;
+ m_fleeFrom->RegisterReference((CEntity **) &m_fleeFrom);
+ }
+
+ if (FindPlayerPed() == pedWithGun && bRichFromMugging) {
+ int money = CGeneral::GetRandomNumberInRange(100, 300);
+ int pickupCount = money / 40 + 1;
+ int moneyPerPickup = money / pickupCount;
+
+ for (int i = 0; i < pickupCount; i++) {
+ // (CGeneral::GetRandomNumber() % 256) * PI / 128 gives a float up to something TWOPI-ish.
+ float pickupX = 1.5f * Sin((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().x;
+ float pickupY = 1.5f * Cos((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().y;
+ bool found = false;
+ float groundZ = CWorld::FindGroundZFor3DCoord(pickupX, pickupY, GetPosition().z, &found) + 0.5f;
+ if (found) {
+ CPickups::GenerateNewOne(CVector(pickupX, pickupY, groundZ), MI_MONEY, PICKUP_MONEY, moneyPerPickup + (CGeneral::GetRandomNumber() & 7));
+ }
+ }
+ bRichFromMugging = false;
+ }
+ }
+ }
+}
+
+void
+CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg)
+{
+ CPed *ped = (CPed*)arg;
+
+ CVehicle *veh = ped->m_pMyVehicle;
+
+ bool startedToRun = false;
+ ped->bUsesCollision = true;
+ ped->m_actionX = 0.0f;
+ ped->m_actionY = 0.0f;
+ ped->m_ped_flagI4 = false;
+ if (veh && veh->IsBoat())
+ ped->ApplyMoveSpeed();
+
+ if (ped->m_objective == OBJECTIVE_LEAVE_VEHICLE)
+ ped->RestorePreviousObjective();
+#ifdef VC_PED_PORTS
+ else if (ped->m_objective == OBJECTIVE_LEAVE_CAR_AND_DIE) {
+ ped->m_fHealth = 0.0f;
+ ped->SetDie(ANIM_FLOOR_HIT, 4.0f, 0.5f);
+ }
+#endif
+
+ ped->bInVehicle = false;
+ if (veh && veh->IsCar() && !veh->IsRoomForPedToLeaveCar(ped->m_vehEnterType, nil)) {
+ ped->PositionPedOutOfCollision();
+ }
+
+ if (ped->m_nPedState == PED_EXIT_CAR) {
+ if (ped->m_nPedType == PEDTYPE_COP)
+ ped->SetIdle();
+ else
+ ped->RestorePreviousState();
+
+ veh = ped->m_pMyVehicle;
+ if (ped->bFleeAfterExitingCar && veh) {
+ ped->bFleeAfterExitingCar = false;
+ ped->SetFlee(veh->GetPosition(), 12000);
+ ped->bUsePedNodeSeek = true;
+ ped->m_pNextPathNode = nil;
+ if (CGeneral::GetRandomNumber() & 1 || ped->m_pedStats->m_fear > 70) {
+ ped->SetMoveState(PEDMOVE_SPRINT);
+ ped->Say(SOUND_PED_FLEE_SPRINT);
+ } else {
+ ped->SetMoveState(PEDMOVE_RUN);
+ ped->Say(SOUND_PED_FLEE_RUN);
+ }
+ startedToRun = true;
+
+ // This is not a good way to do this...
+ ped->m_nLastPedState = PED_WANDER_PATH;
+
+ } else if (ped->bWanderPathAfterExitingCar) {
+ ped->SetWanderPath(CGeneral::GetRandomNumberInRange(0.0f, 8.0f));
+ ped->bWanderPathAfterExitingCar = false;
+ if (ped->m_nPedType == PEDTYPE_PROSTITUTE)
+ ped->SetObjectiveTimer(30000);
+ ped->m_nLastPedState = PED_NONE;
+
+ } else if (ped->bGonnaKillTheCarJacker) {
+
+ // Kill objective is already given at this point.
+ ped->bGonnaKillTheCarJacker = false;
+ if (ped->m_pedInObjective) {
+ if (!(CGeneral::GetRandomNumber() & 1)
+ && ped->m_nPedType != PEDTYPE_COP
+ && (!ped->m_pedInObjective->IsPlayer() || !CTheScripts::IsPlayerOnAMission())) {
+ ped->ClearObjective();
+ ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
+ }
+ ped->m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 1500;
+ }
+ int waitTime = 1500;
+ ped->SetWaitState(WAITSTATE_PLAYANIM_COWER, &waitTime);
+ ped->SetMoveState(PEDMOVE_RUN);
+ startedToRun = true;
+ } else if (ped->m_objective == OBJECTIVE_NONE && ped->CharCreatedBy != MISSION_CHAR && ped->m_nPedState == PED_IDLE && !ped->IsPlayer()) {
+ ped->SetWanderPath(CGeneral::GetRandomNumberInRange(0.0f, 8.0f));
+ }
+ }
+#ifdef VC_PED_PORTS
+ else {
+ ped->m_nPedState = PED_IDLE;
+ }
+#endif
+
+ if (animAssoc)
+ animAssoc->blendDelta = -1000.0f;
+
+ ped->RestartNonPartialAnims();
+ ped->m_pVehicleAnim = nil;
+ CVector posFromZ = ped->GetPosition();
+ CPedPlacement::FindZCoorForPed(&posFromZ);
+ ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ ped->GetPosition() = posFromZ;
+ veh = ped->m_pMyVehicle;
+ if (veh) {
+ if (ped->m_nPedType == PEDTYPE_PROSTITUTE) {
+ if (veh->pDriver) {
+ if (veh->pDriver->IsPlayer() && ped->CharCreatedBy == RANDOM_CHAR) {
+ CWorld::Players[CWorld::PlayerInFocus].m_nNextSexMoneyUpdateTime = 0;
+ CWorld::Players[CWorld::PlayerInFocus].m_nNextSexFrequencyUpdateTime = 0;
+ CWorld::Players[CWorld::PlayerInFocus].m_pHooker = nil;
+ CWorld::Players[CWorld::PlayerInFocus].m_nMoney -= 100;
+ if (CWorld::Players[CWorld::PlayerInFocus].m_nMoney < 0)
+ CWorld::Players[CWorld::PlayerInFocus].m_nMoney = 0;
+ }
+ }
+ }
+ veh->m_nGettingOutFlags &= ~GetCarDoorFlag(ped->m_vehEnterType);
+ if (veh->pDriver == ped) {
+ veh->RemoveDriver();
+ veh->m_status = STATUS_ABANDONED;
+ if (veh->m_nDoorLock == CARLOCK_LOCKED_INITIALLY)
+ veh->m_nDoorLock = CARLOCK_UNLOCKED;
+ if (ped->m_nPedType == PEDTYPE_COP && veh->IsLawEnforcementVehicle())
+ veh->ChangeLawEnforcerState(false);
+ } else {
+ veh->RemovePassenger(ped);
+ }
+
+ if (veh->bIsBus && !veh->IsUpsideDown() && !veh->IsOnItsSide()) {
+ float angleAfterExit;
+ if (ped->m_vehEnterType == CAR_DOOR_LF) {
+ angleAfterExit = HALFPI + veh->GetForward().Heading();
+ } else {
+ angleAfterExit = veh->GetForward().Heading() - HALFPI;
+ }
+ ped->SetHeading(angleAfterExit);
+ ped->m_fRotationDest = angleAfterExit;
+ ped->m_fRotationCur = angleAfterExit;
+ if (!ped->bBusJacked)
+ ped->SetMoveState(PEDMOVE_WALK);
+ }
+ if (CGarages::IsPointWithinAnyGarage(ped->GetPosition()))
+ veh->bLightsOn = false;
+ }
+
+ if (ped->IsPlayer())
+ AudioManager.PlayerJustLeftCar();
+
+ ped->ReplaceWeaponWhenExitingVehicle();
+
+ ped->bOnBoat = false;
+ if (ped->bBusJacked) {
+ ped->SetFall(1500, ANIM_KO_SKID_BACK, false);
+ ped->bBusJacked = false;
+ }
+ ped->m_nStoredMoveState = PEDMOVE_NONE;
+ if (!ped->IsPlayer()) {
+ // It's a shame...
+#ifdef FIX_BUGS
+ int createdBy = ped->CharCreatedBy;
+#else
+ int createdBy = !ped->CharCreatedBy;
+#endif
+
+ if (createdBy == MISSION_CHAR && !startedToRun)
+ ped->SetMoveState(PEDMOVE_WALK);
+ }
+}
+
+// It was inlined in III but not in VC.
+inline void
+CPed::ReplaceWeaponWhenExitingVehicle(void)
+{
+ eWeaponType weaponType = GetWeapon()->m_eWeaponType;
+
+ // If it's Uzi, we may have stored weapon. Uzi is the only gun we can use in car.
+ if (IsPlayer() && weaponType == WEAPONTYPE_UZI) {
+ if (m_storedWeapon != WEAPONTYPE_UNIDENTIFIED) {
+ SetCurrentWeapon(m_storedWeapon);
+ m_storedWeapon = WEAPONTYPE_UNIDENTIFIED;
+ }
+ } else {
+ AddWeaponModel(CWeaponInfo::GetWeaponInfo(weaponType)->m_nModelId);
+ }
+}
+
+void
+CPed::PedSetOutTrainCB(CAnimBlendAssociation *animAssoc, void *arg)
+{
+ CPed *ped = (CPed*)arg;
+
+ CVehicle *veh = ped->m_pMyVehicle;
+
+ if (ped->m_pVehicleAnim)
+ ped->m_pVehicleAnim->blendDelta = -1000.0f;
+
+ ped->bUsesCollision = true;
+ ped->m_pVehicleAnim = nil;
+ ped->bInVehicle = false;
+ ped->m_nPedState = PED_IDLE;
+ ped->RestorePreviousObjective();
+ ped->SetMoveState(PEDMOVE_STILL);
+
+ CMatrix pedMat(ped->GetMatrix());
+ ped->m_fRotationCur = HALFPI + veh->GetForward().Heading();
+ ped->m_fRotationDest = ped->m_fRotationCur;
+ CVector posAfterExit = Multiply3x3(pedMat, vecPedTrainDoorAnimOffset);
+ posAfterExit += ped->GetPosition();
+ CPedPlacement::FindZCoorForPed(&posAfterExit);
+ ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ ped->GetPosition() = posAfterExit;
+ ped->SetHeading(ped->m_fRotationCur);
+ veh->RemovePassenger(ped);
+}
+
+bool
+CPed::PlacePedOnDryLand(void)
+{
+ float waterLevel = 0.0f;
+ CEntity *foundEnt = nil;
+ CColPoint foundCol;
+ float foundColZ;
+
+ CWaterLevel::GetWaterLevelNoWaves(GetPosition().x, GetPosition().y, GetPosition().z, &waterLevel);
+
+ CVector potentialGround = GetPosition();
+ potentialGround.z = waterLevel;
+
+ if (!CWorld::TestSphereAgainstWorld(potentialGround, 5.0f, nil, true, false, false, false, false, false))
+ return false;
+
+ CVector potentialGroundDist = CWorld::ms_testSpherePoint.point - GetPosition();
+ potentialGroundDist.z = 0.0f;
+ potentialGroundDist.Normalise();
+
+ CVector posToCheck = 0.5f * potentialGroundDist + CWorld::ms_testSpherePoint.point;
+ posToCheck.z = 3.0f + waterLevel;
+
+ if (CWorld::ProcessVerticalLine(posToCheck, waterLevel - 1.0f, foundCol, foundEnt, true, true, false, true, false, false, false)) {
+ foundColZ = foundCol.point.z;
+ if (foundColZ >= waterLevel) {
+ posToCheck.z = 0.8f + foundColZ;
+ GetPosition() = posToCheck;
+ bIsStanding = true;
+ m_ped_flagA2 = true;
+ return true;
+ }
+ }
+
+ posToCheck = 5.0f * potentialGroundDist + GetPosition();
+ posToCheck.z = 3.0f + waterLevel;
+
+ if (!CWorld::ProcessVerticalLine(posToCheck, waterLevel - 1.0f, foundCol, foundEnt, true, true, false, true, false, false, false))
+ return false;
+
+ foundColZ = foundCol.point.z;
+ if (foundColZ < waterLevel)
+ return false;
+
+ posToCheck.z = 0.8f + foundColZ;
+ GetPosition() = posToCheck;
+ bIsStanding = true;
+ m_ped_flagA2 = true;
+ return true;
+}
+
+void
+CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *animAssoc, void *arg)
+{
+ CPed *ped = (CPed*)arg;
+
+ CVehicle *veh = ped->m_pMyVehicle;
+
+ CVector finalPos;
+ CVector draggedOutOffset;
+ CVector finalLocalPos;
+
+ CMatrix pedMat(ped->GetMatrix());
+ ped->bUsesCollision = true;
+ ped->RestartNonPartialAnims();
+ draggedOutOffset = vecPedQuickDraggedOutCarAnimOffset;
+ if (ped->m_vehEnterType == CAR_DOOR_RF || ped->m_vehEnterType == CAR_DOOR_RR)
+ draggedOutOffset.x = -draggedOutOffset.x;
+
+ finalLocalPos = Multiply3x3(pedMat, draggedOutOffset);
+ finalPos = finalLocalPos + ped->GetPosition();
+ CPedPlacement::FindZCoorForPed(&finalPos);
+ ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
+ ped->GetPosition() = finalPos;
+
+ if (veh) {
+ ped->m_fRotationDest = veh->GetForward().Heading() - HALFPI;
+ ped->m_fRotationCur = ped->m_fRotationDest;
+ ped->CalculateNewOrientation();
+
+ if (!veh->IsRoomForPedToLeaveCar(ped->m_vehEnterType, &vecPedQuickDraggedOutCarAnimOffset))
+ ped->PositionPedOutOfCollision();
+ }
+
+ if (!ped->CanSetPedState())
+ return;
+
+ ped->SetIdle();
+ if (veh) {
+ if (ped->bFleeAfterExitingCar) {
+ ped->bFleeAfterExitingCar = false;
+ ped->SetFlee(veh->GetPosition(), 14000);
+
+ } else if (ped->bWanderPathAfterExitingCar) {
+ ped->SetWanderPath(CGeneral::GetRandomNumberInRange(0.0f, 8.0f));
+ ped->bWanderPathAfterExitingCar = false;
+
+ } else if (ped->bGonnaKillTheCarJacker) {
+ ped->bGonnaKillTheCarJacker = false;
+ if (ped->m_pedInObjective && CGeneral::GetRandomNumber() & 1) {
+ if (ped->m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT)
+ ped->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, ped->m_pedInObjective);
+
+ } else {
+ CPed *driver = veh->pDriver;
+ if (!driver || driver == ped || driver->IsPlayer() && CTheScripts::IsPlayerOnAMission()) {
+ ped->SetFlee(veh->GetPosition(), 14000);
+ } else {
+ ped->ClearObjective();
+ ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
+ }
+ ped->bUsePedNodeSeek = true;
+ ped->m_pNextPathNode = nil;
+ ped->Say(SOUND_PED_FLEE_RUN);
+ }
+ } else {
+ if (ped->m_pedStats->m_temper <= ped->m_pedStats->m_fear
+ || ped->CharCreatedBy == MISSION_CHAR || veh->VehicleCreatedBy == MISSION_VEHICLE
+ || !veh->pDriver || !veh->pDriver->IsPlayer()
+ || CTheScripts::IsPlayerOnAMission()) {
+
+ ped->SetFlee(veh->GetPosition(), 10000);
+ ped->bUsePedNodeSeek = true;
+ ped->m_pNextPathNode = nil;
+ if (CGeneral::GetRandomNumber() & 1 || ped->m_pedStats->m_fear > 70) {
+ ped->SetMoveState(PEDMOVE_SPRINT);
+ ped->Say(SOUND_PED_FLEE_SPRINT);
+ } else {
+ ped->Say(SOUND_PED_FLEE_RUN);
+ }
+ } else if (CGeneral::GetRandomNumber() < 0x3FFF) {
+ ped->SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, veh->pDriver);
+ } else
+ ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
+ }
+ }
+ if (ped->m_nLastPedState == PED_IDLE)
+ ped->m_nLastPedState = PED_WANDER_PATH;
+}
+
+bool
+CPed::PositionPedOutOfCollision(void)
+{
+ CVehicle *veh;
+ CVector posNearVeh;
+ CVector posSomewhereClose;
+ bool putNearVeh = false;
+ bool putSomewhereClose = false;
+ int smallestDistNearVeh = 999;
+ int smallestDistSomewhereClose = 999;
+
+ if (!m_pMyVehicle)
+ return false;
+
+ CVector vehPos = m_pMyVehicle->GetPosition();
+ CVector potentialPos;
+ potentialPos.y = GetPosition().y - 3.5f;
+ potentialPos.z = GetPosition().z;
+
+ for (int yTry = 0; yTry < 15; yTry++) {
+ potentialPos.x = GetPosition().x - 3.5f;
+
+ for (int xTry = 0; xTry < 15; xTry++) {
+ CPedPlacement::FindZCoorForPed(&potentialPos);
+ CVector distVec = potentialPos - vehPos;
+ float dist = distVec.Magnitude();
+
+ // Makes close distances bigger for some reason.
+ float mult = (0.6f + dist) / dist;
+ CVector adjustedPotentialPos = distVec * mult + vehPos;
+ if (CWorld::GetIsLineOfSightClear(vehPos, adjustedPotentialPos, true, false, false, true, false, false, false)
+ && !CWorld::TestSphereAgainstWorld(potentialPos, 0.6f, this, true, false, false, true, false, false)) {
+
+ float potentialChangeSqr = (potentialPos - GetPosition()).MagnitudeSqr();
+ veh = (CVehicle*)CWorld::TestSphereAgainstWorld(potentialPos, 0.6f, this, false, true, false, false, false, false);
+ if (veh) {
+ if (potentialChangeSqr < smallestDistNearVeh) {
+ posNearVeh = potentialPos;
+ putNearVeh = true;
+ smallestDistNearVeh = potentialChangeSqr;
+ }
+ } else if (potentialChangeSqr < smallestDistSomewhereClose) {
+ smallestDistSomewhereClose = potentialChangeSqr;
+ posSomewhereClose = potentialPos;
+ putSomewhereClose = true;
+ }
+ }
+ potentialPos.x += 0.5f;
+ }
+ potentialPos.y += 0.5f;
+ }
+
+ if (!putSomewhereClose && !putNearVeh)
+ return false;
+
+ // We refrain from using posNearVeh, probably because of it may be top of the vehicle.
+ if (putSomewhereClose) {
+ GetPosition() = posSomewhereClose;
+ } else {
+ CVector vehSize = veh->GetModelInfo()->GetColModel()->boundingBox.max;
+ GetPosition() = posNearVeh;
+ GetPosition().z += vehSize.z;
+ }
+ return true;
+}
+
+bool
+CPed::PossiblyFindBetterPosToSeekCar(CVector *pos, CVehicle *veh)
+{
+ bool foundIt = false;
+
+ CVector helperPos = GetPosition();
+ helperPos.z = pos->z - 0.5f;
+
+ CVector foundPos = *pos;
+ foundPos.z -= 0.5f;
+
+ // If there is another car between target car and us.
+ if (CWorld::TestSphereAgainstWorld((foundPos + helperPos) / 2.0f, 0.25f, veh, false, true, false, false, false, false)) {
+
+ CColModel *vehCol = veh->GetModelInfo()->GetColModel();
+ CVector *colMin = &vehCol->boundingBox.min;
+ CVector *colMax = &vehCol->boundingBox.max;
+
+ CVector leftRearPos = CVector(colMin->x - 0.5f, colMin->y - 0.5f, 0.0f);
+ CVector rightRearPos = CVector(0.5f + colMax->x, colMin->y - 0.5f, 0.0f);
+ CVector leftFrontPos = CVector(colMin->x - 0.5f, 0.5f + colMax->y, 0.0f);
+ CVector rightFrontPos = CVector(0.5f + colMax->x, 0.5f + colMax->y, 0.0f);
+
+ leftRearPos = veh->GetMatrix() * leftRearPos;
+ rightRearPos = veh->GetMatrix() * rightRearPos;
+ leftFrontPos = veh->GetMatrix() * leftFrontPos;
+ rightFrontPos = veh->GetMatrix() * rightFrontPos;
+
+ // Makes helperPos veh-ped distance vector.
+ helperPos -= veh->GetPosition();
+
+ // ?!? I think it's absurd to use this unless another function like SeekCar finds next pos. with it and we're trying to simulate it's behaviour.
+ // On every run it returns another pos. for ped, with same distance to the veh.
+ // Sequence of positions are not guarenteed, it depends on global pos. (So sometimes it returns positions to make ped draw circle, sometimes don't)
+ helperPos = veh->GetMatrix() * helperPos;
+
+ float vehForwardHeading = veh->GetForward().Heading();
+
+ // I'm absolutely not sure about these namings.
+ // NTVF = needed turn if we're looking to vehicle front and wanna look to...
+
+ float potentialLrHeading = Atan2(leftRearPos.x - helperPos.x, leftRearPos.y - helperPos.y);
+ float NTVF_LR = CGeneral::LimitRadianAngle(potentialLrHeading - vehForwardHeading);
+
+ float potentialRrHeading = Atan2(rightRearPos.x - helperPos.x, rightRearPos.y - helperPos.y);
+ float NTVF_RR = CGeneral::LimitRadianAngle(potentialRrHeading - vehForwardHeading);
+
+ float potentialLfHeading = Atan2(leftFrontPos.x - helperPos.x, leftFrontPos.y - helperPos.y);
+ float NTVF_LF = CGeneral::LimitRadianAngle(potentialLfHeading - vehForwardHeading);
+
+ float potentialRfHeading = Atan2(rightFrontPos.x - helperPos.x, rightFrontPos.y - helperPos.y);
+ float NTVF_RF = CGeneral::LimitRadianAngle(potentialRfHeading - vehForwardHeading);
+
+ bool canHeadToLr = NTVF_LR <= -PI || NTVF_LR >= -HALFPI;
+
+ bool canHeadToRr = NTVF_RR <= HALFPI || NTVF_RR >= PI;
+
+ bool canHeadToLf = NTVF_LF >= 0.0f || NTVF_LF <= -HALFPI;
+
+ bool canHeadToRf = NTVF_RF <= 0.0f || NTVF_RF >= HALFPI;
+
+ // Only order of conditions are different among enterTypes.
+ if (m_vehEnterType == CAR_DOOR_RR) {
+ if (canHeadToRr) {
+ foundPos = rightRearPos;
+ foundIt = true;
+ } else if (canHeadToRf) {
+ foundPos = rightFrontPos;
+ foundIt = true;
+ } else if (canHeadToLr) {
+ foundPos = leftRearPos;
+ foundIt = true;
+ } else if (canHeadToLf) {
+ foundPos = leftFrontPos;
+ foundIt = true;
+ }
+ } else if(m_vehEnterType == CAR_DOOR_RF) {
+ if (canHeadToRf) {
+ foundPos = rightFrontPos;
+ foundIt = true;
+ } else if (canHeadToRr) {
+ foundPos = rightRearPos;
+ foundIt = true;
+ } else if (canHeadToLf) {
+ foundPos = leftFrontPos;
+ foundIt = true;
+ } else if (canHeadToLr) {
+ foundPos = leftRearPos;
+ foundIt = true;
+ }
+ } else if (m_vehEnterType == CAR_DOOR_LF) {
+ if (canHeadToLf) {
+ foundPos = leftFrontPos;
+ foundIt = true;
+ } else if (canHeadToLr) {
+ foundPos = leftRearPos;
+ foundIt = true;
+ } else if (canHeadToRf) {
+ foundPos = rightFrontPos;
+ foundIt = true;
+ } else if (canHeadToRr) {
+ foundPos = rightRearPos;
+ foundIt = true;
+ }
+ } else if (m_vehEnterType == CAR_DOOR_LR) {
+ if (canHeadToLr) {
+ foundPos = leftRearPos;
+ foundIt = true;
+ } else if (canHeadToLf) {
+ foundPos = leftFrontPos;
+ foundIt = true;
+ } else if (canHeadToRr) {
+ foundPos = rightRearPos;
+ foundIt = true;
+ } else if (canHeadToRf) {
+ foundPos = rightFrontPos;
+ foundIt = true;
+ }
+ }
+ }
+ if (!foundIt)
+ return false;
+
+ helperPos = GetPosition() - foundPos;
+ helperPos.z = 0.0f;
+ if (helperPos.MagnitudeSqr() <= 0.25f)
+ return false;
+
+ pos->x = foundPos.x;
+ pos->y = foundPos.y;
+ return true;
+}
+
+void
+CPed::Render(void)
+{
+ if (!bInVehicle
+ || m_nPedState == PED_EXIT_CAR
+ || m_nPedState == PED_DRAG_FROM_CAR
+ || bRenderPedInCar &&
+ sq(25.0f * TheCamera.LODDistMultiplier) >= (TheCamera.GetPosition() - GetPosition()).MagnitudeSqr()) {
+ CEntity::Render();
+ }
+}
+
+void
+CPed::ProcessObjective(void)
+{
+ if (bClearObjective && (IsPedInControl() || m_nPedState == PED_DRIVING)) {
+ ClearObjective();
+ bClearObjective = false;
+ }
+ UpdateFromLeader();
+
+ CVector carOrOurPos;
+ CVector targetCarOrHisPos;
+ CVector distWithTarget;
+
+ if (m_objective != OBJECTIVE_NONE && (IsPedInControl() || m_nPedState == PED_DRIVING)) {
+ if (bInVehicle) {
+ if (!m_pMyVehicle) {
+ bInVehicle = false;
+ return;
+ }
+ carOrOurPos = m_pMyVehicle->GetPosition();
+ } else {
+ carOrOurPos = GetPosition();
+ }
+
+ if (m_pedInObjective) {
+ if (m_pedInObjective->bInVehicle && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR && m_pedInObjective->m_pMyVehicle) {
+ targetCarOrHisPos = m_pedInObjective->m_pMyVehicle->GetPosition();
+ } else {
+ targetCarOrHisPos = m_pedInObjective->GetPosition();
+ }
+ distWithTarget = targetCarOrHisPos - carOrOurPos;
+ } else if (m_carInObjective) {
+ targetCarOrHisPos = m_carInObjective->GetPosition();
+ distWithTarget = targetCarOrHisPos - carOrOurPos;
+ }
+
+ switch (m_objective) {
+ case OBJECTIVE_NONE:
+ case OBJECTIVE_GUARD_AREA:
+ case OBJECTIVE_FOLLOW_CAR_IN_CAR:
+ case OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE:
+ case OBJECTIVE_DESTROY_OBJ:
+ case OBJECTIVE_23:
+ case OBJECTIVE_24:
+ case OBJECTIVE_SET_LEADER:
+ break;
+ case OBJECTIVE_IDLE:
+ SetIdle();
+ m_objective = OBJECTIVE_NONE;
+ SetMoveState(PEDMOVE_STILL);
+ break;
+ case OBJECTIVE_FLEE_TILL_SAFE:
+ if (bInVehicle && m_pMyVehicle) {
+ SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
+ bFleeAfterExitingCar = true;
+ } else if (m_nPedState != PED_FLEE_POS) {
+ SetFlee(GetPosition(), 10000);
+ bUsePedNodeSeek = true;
+ m_pNextPathNode = nil;
+ }
+ break;
+ case OBJECTIVE_GUARD_SPOT:
+ {
+ distWithTarget = m_vecSeekPosEx - GetPosition();
+ if (m_pedInObjective) {
+ SetLookFlag(m_pedInObjective, true);
+ m_pLookTarget = m_pedInObjective;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+ TurnBody();
+ }
+ float distWithTargetSc = distWithTarget.Magnitude();
+ if (2.0f * m_distanceToCountSeekDoneEx >= distWithTargetSc) {
+ if (m_pedInObjective) {
+ if (distWithTargetSc <= m_distanceToCountSeekDoneEx)
+ SetIdle();
+ else
+ SetSeek(m_vecSeekPosEx, m_distanceToCountSeekDoneEx);
+ } else if (CTimer::GetTimeInMilliseconds() > m_lookTimer) {
+ int threatType = ScanForThreats();
+ SetLookTimer(CGeneral::GetRandomNumberInRange(500, 1500));
+
+ // Second condition is pointless and isn't there in Mobile.
+ if (threatType == 0x100000 || (threatType == 0x800000 && m_threatEntity) || m_threatEntity) {
+ if (m_threatEntity->IsPed())
+ SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, m_threatEntity);
+ }
+ }
+ } else {
+ SetSeek(m_vecSeekPosEx, m_distanceToCountSeekDoneEx);
+ }
+ break;
+ }
+ case OBJECTIVE_WAIT_IN_CAR:
+ m_nPedState = PED_DRIVING;
+ break;
+ case OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT:
+ m_nPedState = PED_DRIVING;
+ break;
+ case OBJECTIVE_KILL_CHAR_ANY_MEANS:
+ {
+ if (m_pedInObjective) {
+ if (m_pedInObjective->IsPlayer() && CharCreatedBy != MISSION_CHAR
+ && m_nPedType != PEDTYPE_COP && FindPlayerPed()->m_pWanted->m_CurrentCops
+ && !bKindaStayInSamePlace) {
+
+ SetObjective(OBJECTIVE_FLEE_TILL_SAFE);
+ break;
+ }
+ if (bInVehicle && m_pMyVehicle) {
+ if (distWithTarget.Magnitude() >= 20.0f
+ || m_pMyVehicle->m_vecMoveSpeed.MagnitudeSqr() >= 0.0004f) {
+ if (m_pMyVehicle->pDriver == this
+ && !m_pMyVehicle->m_nGettingInFlags) {
+ m_pMyVehicle->m_status = STATUS_PHYSICS;
+ m_pMyVehicle->AutoPilot.m_nPrevRouteNode = 0;
+ if (m_nPedType == PEDTYPE_COP) {
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = (CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->m_nWantedLevel * 0.1f + 0.6f) * (60.0f * m_pMyVehicle->pHandling->Transmission.fUnkMaxVelocity);
+ m_pMyVehicle->AutoPilot.m_nCarMission = CCarAI::FindPoliceCarMissionForWantedLevel();
+ } else {
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 60.0f * m_pMyVehicle->pHandling->Transmission.fUnkMaxVelocity * 0.8f;
+ m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_RAMPLAYER_FARAWAY;
+ }
+ m_pMyVehicle->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS;
+ }
+ } else {
+ bool targetHasVeh = m_pedInObjective->bInVehicle;
+ if (!targetHasVeh
+ || targetHasVeh && m_pedInObjective->m_pMyVehicle->CanPedExitCar()) {
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ m_pMyVehicle->AutoPilot.m_nCarMission = MISSION_NONE;
+ SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
+ }
+ }
+ break;
+ }
+ if (distWithTarget.Magnitude() > 30.0f && !bKindaStayInSamePlace) {
+ if (m_pMyVehicle) {
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
+ } else {
+ float closestVehDist = 60.0f;
+ int16 lastVehicle;
+ CEntity* vehicles[8];
+ CWorld::FindObjectsInRange(GetPosition(), 25.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false);
+ CVehicle *foundVeh = nil;
+ for(int i = 0; i < lastVehicle; i++) {
+ CVehicle *nearVeh = (CVehicle*)vehicles[i];
+ /*
+ Not used.
+ CVector vehSpeed = nearVeh->GetSpeed();
+ CVector ourSpeed = GetSpeed();
+ */
+ CVector vehDistVec = nearVeh->GetPosition() - GetPosition();
+ if (vehDistVec.Magnitude() < closestVehDist && m_pedInObjective->m_pMyVehicle != nearVeh
+ && nearVeh->CanPedOpenLocks(this)) {
+
+ foundVeh = nearVeh;
+ closestVehDist = vehDistVec.Magnitude();
+ }
+ }
+ m_pMyVehicle = foundVeh;
+ if (m_pMyVehicle) {
+ m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle);
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
+ } else if (!GetIsOnScreen()) {
+ CVector ourPos = GetPosition();
+ int closestNode = ThePaths.FindNodeClosestToCoors(ourPos, PATH_CAR, 20.0f);
+ if (closestNode >= 0) {
+ int16 colliding;
+ CWorld::FindObjectsKindaColliding(
+ ThePaths.m_pathNodes[closestNode].pos, 10.0f, true, &colliding, 2, nil, false, true, true, false, false);
+ if (!colliding) {
+ CZoneInfo zoneInfo;
+ int chosenCarClass;
+ CTheZones::GetZoneInfoForTimeOfDay(&ourPos, &zoneInfo);
+ int chosenModel = CCarCtrl::ChooseModel(&zoneInfo, &ourPos, &chosenCarClass);
+ CAutomobile *newVeh = new CAutomobile(chosenModel, RANDOM_VEHICLE);
+ if (newVeh) {
+ newVeh->GetPosition() = ThePaths.m_pathNodes[closestNode].pos;
+ newVeh->GetPosition().z += 4.0f;
+ newVeh->SetHeading(DEGTORAD(200.0f));
+ newVeh->m_status = STATUS_ABANDONED;
+ newVeh->m_nDoorLock = CARLOCK_UNLOCKED;
+ CWorld::Add(newVeh);
+ m_pMyVehicle = newVeh;
+ if (m_pMyVehicle) {
+ m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle);
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
+ }
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ } else {
+ ClearLookFlag();
+ bObjectiveCompleted = true;
+ }
+ }
+ case OBJECTIVE_KILL_CHAR_ON_FOOT:
+ {
+ bool killPlayerInNoPoliceZone = false;
+ if (m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT && bInVehicle && m_pMyVehicle) {
+ SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
+ break;
+ }
+
+ if (!m_pedInObjective || m_pedInObjective->DyingOrDead()) {
+ ClearLookFlag();
+ bObjectiveCompleted = true;
+ SetMoveAnim();
+ break;
+ }
+ if (m_pedInObjective->IsPlayer() && CCullZones::NoPolice())
+ killPlayerInNoPoliceZone = true;
+
+ if (!bNotAllowedToDuck || killPlayerInNoPoliceZone) {
+ if (m_nPedType == PEDTYPE_COP && !m_pedInObjective->GetWeapon()->IsTypeMelee() && !GetWeapon()->IsTypeMelee())
+ bNotAllowedToDuck = true;
+ } else {
+ if (!m_pedInObjective->bInVehicle) {
+ if (m_pedInObjective->GetWeapon()->IsTypeMelee() || GetWeapon()->IsTypeMelee()) {
+ bNotAllowedToDuck = false;
+ bCrouchWhenShooting = false;
+ } else if (DuckAndCover()) {
+ break;
+ }
+ } else {
+ bNotAllowedToDuck = false;
+ bCrouchWhenShooting = false;
+ }
+ }
+ if (m_leaveCarTimer > CTimer::GetTimeInMilliseconds() && !bKindaStayInSamePlace) {
+ SetMoveState(PEDMOVE_STILL);
+ break;
+ }
+ if (m_pedInObjective->IsPlayer()) {
+ CPlayerPed *player = FindPlayerPed();
+ if (m_nPedType == PEDTYPE_COP && player->m_pWanted->m_bIgnoredByCops
+ || player->m_pWanted->m_bIgnoredByEveryone
+ || m_pedInObjective->bIsInWater
+ || m_pedInObjective->m_nPedState == PED_ARRESTED) {
+
+ if (m_nPedState != PED_ARREST_PLAYER)
+ SetIdle();
+
+ break;
+ }
+ }
+ CWeaponInfo *wepInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
+ float wepRange = wepInfo->m_fRange;
+ float wepRangeAdjusted;
+ if (GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED) {
+ wepRangeAdjusted = wepRange / 3.0f;
+ } else {
+ if (m_nPedState == PED_FIGHT) {
+ if (!IsPlayer() && !(m_pedStats->m_flags & STAT_CAN_KICK))
+ wepRange = 2.0f;
+ } else {
+ wepRange = 1.3f;
+ }
+ wepRangeAdjusted = wepRange;
+ }
+ if (m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() && wepRangeAdjusted < 2.5f) {
+ wepRangeAdjusted = 2.5f;
+ }
+ if (m_pedInObjective->IsPlayer() && m_nPedType != PEDTYPE_COP
+ && CharCreatedBy != MISSION_CHAR && FindPlayerPed()->m_pWanted->m_CurrentCops) {
+ SetObjective(OBJECTIVE_FLEE_TILL_SAFE);
+ break;
+ }
+ if (m_pedInObjective->m_fHealth <= 0.0f) {
+ bObjectiveCompleted = true;
+ bScriptObjectiveCompleted = true;
+ SetMoveAnim();
+ break;
+ }
+ float distWithTargetSc = distWithTarget.Magnitude();
+ if (m_pedInObjective->bInVehicle && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) {
+ CVehicle *vehOfTarget = m_pedInObjective->m_pMyVehicle;
+ if (vehOfTarget->bIsInWater || vehOfTarget->m_status == STATUS_PLAYER_DISABLED
+ || m_pedInObjective->IsPlayer() && CPad::GetPad(0)->ArePlayerControlsDisabled()) {
+ SetIdle();
+ return;
+ }
+ SetLookFlag(vehOfTarget, false);
+ if (m_nPedState != PED_CARJACK) {
+ if (m_pedInObjective->m_nPedState != PED_ARRESTED) {
+ if (m_attackTimer < CTimer::GetTimeInMilliseconds() && wepInfo->m_eWeaponFire != WEAPON_FIRE_MELEE
+ && distWithTargetSc < wepRange && distWithTargetSc > 3.0f) {
+
+ // I hope so
+ CVector ourHead = GetMatrix() * CVector(0.5f, 0.0f, 0.6f);
+ CVector maxShotPos = vehOfTarget->GetPosition() - ourHead;
+ maxShotPos.Normalise();
+ maxShotPos = maxShotPos * wepInfo->m_fRange + ourHead;
+
+ CWorld::bIncludeDeadPeds = true;
+ CColPoint foundCol;
+ CEntity *foundEnt;
+ CWorld::ProcessLineOfSight(ourHead, maxShotPos, foundCol, foundEnt,
+ true, true, true, true, false, true, false);
+ CWorld::bIncludeDeadPeds = false;
+ if (foundEnt == vehOfTarget) {
+ SetAttack(vehOfTarget);
+ m_pPointGunAt = vehOfTarget;
+ if (vehOfTarget)
+ vehOfTarget->RegisterReference((CEntity **) &m_pPointGunAt);
+
+ SetShootTimer(CGeneral::GetRandomNumberInRange(500, 2000));
+ if (distWithTargetSc <= m_distanceToCountSeekDone) {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(200, 500));
+ SetMoveState(PEDMOVE_STILL);
+ } else {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(2000, 5000));
+ }
+ }
+ }
+ else if (m_nPedState != PED_ATTACK && !bKindaStayInSamePlace && !killPlayerInNoPoliceZone) {
+ if (vehOfTarget) {
+ if (m_nPedType == PEDTYPE_COP || vehOfTarget->bIsBus) {
+ GoToNearestDoor(vehOfTarget);
+ } else {
+ m_vehEnterType = 0;
+ if (m_pedInObjective == vehOfTarget->pDriver || vehOfTarget->bIsBus) {
+ m_vehEnterType = CAR_DOOR_LF;
+ } else if (m_pedInObjective == vehOfTarget->pPassengers[0]) {
+ m_vehEnterType = CAR_DOOR_RF;
+ } else if (m_pedInObjective == vehOfTarget->pPassengers[1]) {
+ m_vehEnterType = CAR_DOOR_LR;
+ } else if (m_pedInObjective == vehOfTarget->pPassengers[2]) {
+ m_vehEnterType = CAR_DOOR_RR;
+ }
+ // Unused
+ // GetPositionToOpenCarDoor(vehOfTarget, m_vehEnterType);
+ SetSeekCar(vehOfTarget, m_vehEnterType);
+ SetMoveState(PEDMOVE_RUN);
+ }
+ }
+ }
+ }
+ }
+ SetMoveAnim();
+ break;
+ }
+ if (m_nMoveState == PEDMOVE_STILL && IsPedInControl()) {
+ SetLookFlag(m_pedInObjective, false);
+ TurnBody();
+ }
+ if (m_nPedType == PEDTYPE_COP && distWithTargetSc < 1.5f && m_pedInObjective->IsPlayer()) {
+ if (m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds()
+ || m_pedInObjective->m_nPedState == PED_DRAG_FROM_CAR) {
+
+ ((CCopPed*)this)->SetArrestPlayer(m_pedInObjective);
+ return;
+ }
+ }
+ if (!bKindaStayInSamePlace && !bStopAndShoot && m_nPedState != PED_ATTACK && !killPlayerInNoPoliceZone) {
+ if (distWithTargetSc > wepRange
+ || m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds()
+ || m_pedInObjective->m_nPedState == PED_ARRESTED
+ || (m_pedInObjective->m_nPedState == PED_ENTER_CAR || m_pedInObjective->m_nPedState == PED_CARJACK) && distWithTargetSc < 3.0f
+ || distWithTargetSc > m_distanceToCountSeekDone && !CanSeeEntity(m_pedInObjective, DEGTORAD(60.0f))) {
+
+ if (m_pedInObjective->m_nPedState == PED_ENTER_CAR || m_pedInObjective->m_nPedState == PED_CARJACK)
+ wepRangeAdjusted = 2.0f;
+
+ if (bUsePedNodeSeek) {
+ CVector bestCoords(0.0f, 0.0f, 0.0f);
+ m_vecSeekPos = m_pedInObjective->GetPosition();
+
+ if (!m_pNextPathNode)
+ FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords);
+
+ if (m_pNextPathNode)
+ m_vecSeekPos = m_pNextPathNode->pos;
+
+ SetSeek(m_vecSeekPos, m_distanceToCountSeekDone);
+ } else {
+ SetSeek(m_pedInObjective, wepRangeAdjusted);
+ }
+ bCrouchWhenShooting = false;
+ if (m_pedInObjective->m_pCurrentPhysSurface && distWithTargetSc < 5.0f) {
+ if (wepRange <= 5.0f) {
+ if (m_pedInObjective->IsPlayer()
+ && FindPlayerPed()->m_bSpeedTimerFlag
+ && (IsGangMember() || m_nPedType == PEDTYPE_COP)
+ && GetWeapon()->m_eWeaponType == WEAPONTYPE_UNARMED) {
+ GiveWeapon(WEAPONTYPE_COLT45, 1000);
+ SetCurrentWeapon(WEAPONTYPE_COLT45);
+ }
+ } else {
+ bStopAndShoot = true;
+ }
+ SetMoveState(PEDMOVE_STILL);
+ SetMoveAnim();
+ break;
+ }
+ bStopAndShoot = false;
+ SetMoveAnim();
+ break;
+ }
+ }
+ if (m_attackTimer < CTimer::GetTimeInMilliseconds()
+ && distWithTargetSc < wepRange && m_pedInObjective->m_nPedState != PED_GETUP && m_pedInObjective->m_nPedState != PED_DRAG_FROM_CAR) {
+ if (bIsDucking) {
+ CAnimBlendAssociation *duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN);
+ if (duckAnim) {
+ duckAnim->blendDelta = -2.0f;
+ break;
+ }
+ bIsDucking = false;
+ } else if (wepRange <= 5.0f) {
+ SetMoveState(PEDMOVE_STILL);
+ SetAttack(m_pedInObjective);
+ m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(
+ m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y,
+ GetPosition().x, GetPosition().y);
+ SetShootTimer(CGeneral::GetRandomNumberInRange(0.0f, 500.0f));
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(0.0f, 1500.0f));
+ bObstacleShowedUpDuringKillObjective = false;
+
+ } else {
+ CVector target;
+ CVector ourHead = GetMatrix() * CVector(0.5f, 0.0f, 0.6f);
+ if (m_pedInObjective->IsPed())
+ m_pedInObjective->m_pedIK.GetComponentPosition((RwV3d*)&target, PED_MID);
+ else
+ target = m_pedInObjective->GetPosition();
+
+ target -= ourHead;
+ target.Normalise();
+ target = target * wepInfo->m_fRange + ourHead;
+
+ CWorld::bIncludeDeadPeds = true;
+ CEntity *foundEnt = nil;
+ CColPoint foundCol;
+
+ CWorld::ProcessLineOfSight(
+ ourHead, target, foundCol, foundEnt,
+ true, true, true, false, true, false);
+ CWorld::bIncludeDeadPeds = 0;
+ if (foundEnt == m_pedInObjective) {
+ SetAttack(m_pedInObjective);
+ m_pPointGunAt = m_pedInObjective;
+ if (m_pedInObjective)
+ m_pedInObjective->RegisterReference((CEntity **) &m_pPointGunAt);
+
+ SetShootTimer(CGeneral::GetRandomNumberInRange(500.0f, 2000.0f));
+
+ int time;
+ if (distWithTargetSc <= wepRangeAdjusted)
+ time = CGeneral::GetRandomNumberInRange(100.0f, 500.0f);
+ else
+ time = CGeneral::GetRandomNumberInRange(1500.0f, 3000.0f);
+
+ SetAttackTimer(time);
+ bObstacleShowedUpDuringKillObjective = false;
+
+ } else if (foundEnt) {
+ if (foundEnt->IsPed()) {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(500.0f, 1000.0f));
+ bObstacleShowedUpDuringKillObjective = false;
+ } else {
+ if (foundEnt->IsObject()) {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(200.0f, 400.0f));
+ bObstacleShowedUpDuringKillObjective = true;
+ } else if (foundEnt->IsVehicle()) {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(400.0f, 600.0f));
+ bObstacleShowedUpDuringKillObjective = true;
+ } else {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(700.0f, 1200.0f));
+ bObstacleShowedUpDuringKillObjective = true;
+ }
+ }
+
+ m_fleeFrom = foundEnt;
+ m_fleeFrom->RegisterReference((CEntity**) &m_fleeFrom);
+ SetPointGunAt(m_pedInObjective);
+ }
+ }
+ } else {
+ if (!m_pedInObjective->m_pCurrentPhysSurface)
+ bStopAndShoot = false;
+
+ if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT) {
+
+ // This is weird...
+ if (bNotAllowedToDuck && bKindaStayInSamePlace) {
+ if (!bIsDucking) {
+ CAnimBlendAssociation* duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN);
+ if (!duckAnim || duckAnim->blendDelta < 0.0f) {
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_DUCK_DOWN, 4.0f);
+ bIsDucking = true;
+ }
+ break;
+ } else {
+ CAnimBlendAssociation* duckAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_DUCK_DOWN);
+ if (!duckAnim || duckAnim->blendDelta < 0.0f) {
+ bIsDucking = false;
+ } else {
+ break;
+ }
+ }
+ }
+ if (bObstacleShowedUpDuringKillObjective) {
+ if (m_nPedType == PEDTYPE_COP) {
+ if (GetWeapon()->m_eWeaponType > WEAPONTYPE_COLT45
+ || m_fleeFrom && m_fleeFrom->IsObject()) {
+ wepRangeAdjusted = 6.0f;
+ } else if (m_fleeFrom && m_fleeFrom->IsVehicle()) {
+ wepRangeAdjusted = 4.0f;
+ } else {
+ wepRangeAdjusted = 2.0f;
+ }
+ } else {
+ wepRangeAdjusted = 2.0f;
+ }
+ }
+ if (distWithTargetSc <= wepRangeAdjusted) {
+ SetMoveState(PEDMOVE_STILL);
+ bIsPointingGunAt = true;
+ if (m_nPedState != PED_AIM_GUN && !bDuckAndCover) {
+ m_attackTimer = CTimer::GetTimeInMilliseconds();
+ SetIdle();
+ }
+ } else {
+ if (m_nPedState != PED_SEEK_ENTITY && m_nPedState != PED_SEEK_POS
+ && !bStopAndShoot && !killPlayerInNoPoliceZone && !bKindaStayInSamePlace) {
+ Say(SOUND_PED_ATTACK);
+ SetSeek(m_pedInObjective, wepRangeAdjusted);
+ bIsRunning = true;
+ }
+ }
+ }
+ }
+
+ if (distWithTargetSc < 2.5f && wepRange > 5.0f
+ && wepInfo->m_eWeaponFire != WEAPON_FIRE_MELEE) {
+
+ SetAttack(m_pedInObjective);
+ if (m_attackTimer < CTimer::GetTimeInMilliseconds()) {
+ int time = CGeneral::GetRandomNumberInRange(500.0f, 1000.0f);
+ SetAttackTimer(time);
+ SetShootTimer(time - 500);
+ }
+ SetMoveState(PEDMOVE_STILL);
+ }
+ if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer)
+ m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y, GetPosition().x, GetPosition().y);
+
+ SetMoveAnim();
+ break;
+ }
+ case OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE:
+ case OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS:
+ {
+ if (bInVehicle && m_pMyVehicle) {
+ if (m_nPedState == PED_DRIVING)
+ SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
+ } else if (m_nPedState != PED_FLEE_ENTITY) {
+ int time;
+ if (m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_ALWAYS)
+ time = 0;
+ else
+ time = 6000;
+
+ SetFlee(m_pedInObjective, time);
+ bUsePedNodeSeek = true;
+ m_pNextPathNode = nil;
+ }
+ break;
+ }
+ case OBJECTIVE_GOTO_CHAR_ON_FOOT:
+ {
+ if (m_pedInObjective) {
+ float safeDistance = 2.0f;
+ if (m_pedInObjective->bInVehicle)
+ safeDistance = 3.0f;
+
+ float distWithTargetSc = distWithTarget.Magnitude();
+ if (m_nPedStateTimer < CTimer::GetTimeInMilliseconds()) {
+ if (distWithTargetSc <= safeDistance) {
+ bScriptObjectiveCompleted = true;
+ if (m_nPedState != PED_ATTACK) {
+ SetIdle();
+ m_pLookTarget = m_pedInObjective;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+ TurnBody();
+ }
+ if (distWithTargetSc > 2.0f)
+ SetMoveState(m_pedInObjective->m_nMoveState);
+ else
+ SetMoveState(PEDMOVE_STILL);
+ } else {
+ SetSeek(m_pedInObjective, safeDistance);
+ if (distWithTargetSc >= 5.0f) {
+ if (m_leader && m_leader->m_nMoveState == PEDMOVE_SPRINT)
+ SetMoveState(PEDMOVE_SPRINT);
+ else
+ SetMoveState(PEDMOVE_RUN);
+ } else {
+ if (m_leader && m_leader->m_nMoveState != PEDMOVE_STILL
+ && m_leader->m_nMoveState != PEDMOVE_NONE) {
+ if (m_leader->IsPlayer()) {
+ if (distWithTargetSc >= 3.0f && FindPlayerPed()->m_fMoveSpeed >= 1.3f)
+ SetMoveState(PEDMOVE_RUN);
+ else
+ SetMoveState(PEDMOVE_WALK);
+ } else {
+ SetMoveState(m_leader->m_nMoveState);
+ }
+ } else if (distWithTargetSc <= 3.0f) {
+ SetMoveState(PEDMOVE_WALK);
+ } else {
+ SetMoveState(PEDMOVE_RUN);
+ }
+ }
+ }
+ }
+ } else {
+ SetObjective(OBJECTIVE_NONE);
+ }
+ break;
+ }
+ case OBJECTIVE_FOLLOW_PED_IN_FORMATION:
+ {
+ if (m_pedInObjective) {
+ CVector posToGo = GetFormationPosition();
+ distWithTarget = posToGo - carOrOurPos;
+ SetSeek(posToGo, 1.0f);
+ if (distWithTarget.Magnitude() <= 3.0f) {
+ SetSeek(posToGo, 1.0f);
+ if (m_pedInObjective->m_nMoveState != PEDMOVE_STILL)
+ SetMoveState(m_pedInObjective->m_nMoveState);
+ } else {
+ SetSeek(posToGo, 1.0f);
+ SetMoveState(PEDMOVE_RUN);
+ }
+ } else {
+ SetObjective(OBJECTIVE_NONE);
+ }
+ break;
+ }
+ case OBJECTIVE_ENTER_CAR_AS_PASSENGER:
+ {
+ if (m_carInObjective) {
+ if (!bInVehicle && m_carInObjective->m_nNumPassengers >= m_carInObjective->m_nNumMaxPassengers) {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ if (IsPedInControl())
+ m_pMyVehicle = nil;
+
+ break;
+ }
+
+ if (m_prevObjective == OBJECTIVE_HAIL_TAXI && !((CAutomobile*)m_carInObjective)->bTaxiLight) {
+ RestorePreviousObjective();
+ ClearObjective();
+ SetWanderPath(CGeneral::GetRandomNumber() & 7);
+ bIsRunning = false;
+ break;
+ }
+ if (m_objectiveTimer && m_objectiveTimer < CTimer::GetTimeInMilliseconds()) {
+ if (m_nPedState != PED_CARJACK && m_nPedState != PED_ENTER_CAR) {
+ bool foundSeat = false;
+ if (m_carInObjective->pPassengers[0] || m_carInObjective->m_nGettingInFlags & CAR_DOOR_FLAG_RF) {
+ if (m_carInObjective->pPassengers[1] || m_carInObjective->m_nGettingInFlags & CAR_DOOR_FLAG_LR) {
+ if (m_carInObjective->pPassengers[2] || m_carInObjective->m_nGettingInFlags & CAR_DOOR_FLAG_RR) {
+ foundSeat = false;
+ } else {
+ m_vehEnterType = CAR_DOOR_RR;
+ foundSeat = true;
+ }
+ } else {
+ m_vehEnterType = CAR_DOOR_LR;
+ foundSeat = true;
+ }
+ } else {
+ m_vehEnterType = CAR_DOOR_RF;
+ foundSeat = true;
+ }
+ for (int i = 2; i < m_carInObjective->m_nNumMaxPassengers; ++i) {
+ if (!m_carInObjective->pPassengers[i] && !(m_carInObjective->m_nGettingInFlags & CAR_DOOR_FLAG_RF)) {
+ m_vehEnterType = CAR_DOOR_RF;
+ foundSeat = true;
+ }
+ }
+ if (foundSeat) {
+ GetPosition() = GetPositionToOpenCarDoor(m_carInObjective, m_vehEnterType);
+ SetEnterCar(m_carInObjective, m_vehEnterType);
+ }
+ }
+ m_objectiveTimer = 0;
+ }
+ }
+ }
+ case OBJECTIVE_ENTER_CAR_AS_DRIVER:
+ {
+ if (!m_carInObjective || bInVehicle) {
+ bObjectiveCompleted = true;
+ bScriptObjectiveCompleted = true;
+ RestorePreviousState();
+ } else {
+ if (m_leaveCarTimer > CTimer::GetTimeInMilliseconds()) {
+ SetMoveState(PEDMOVE_STILL);
+ break;
+ }
+ if (IsPedInControl()) {
+ if (m_prevObjective == OBJECTIVE_KILL_CHAR_ANY_MEANS) {
+ if (distWithTarget.Magnitude() < 20.0f) {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ return;
+ }
+ if (m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) {
+ if (m_carInObjective->pDriver) {
+ if (m_carInObjective->pDriver->m_objective == OBJECTIVE_KILL_CHAR_ANY_MEANS && m_carInObjective->pDriver != m_pedInObjective) {
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_carInObjective);
+ m_carInObjective->m_veh_flagC10 = false;
+ }
+ }
+ }
+ } else if (m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER) {
+ if (m_carInObjective->pDriver) {
+ if (m_carInObjective->pDriver->m_nPedType == m_nPedType) {
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_carInObjective);
+ m_carInObjective->m_veh_flagC10 = false;
+ }
+ }
+ }
+ if (m_carInObjective->IsUpsideDown() && m_carInObjective->m_vehType != VEHICLE_TYPE_BIKE) {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ return;
+ }
+ if (!m_carInObjective->IsBoat() || m_nPedState == PED_SEEK_IN_BOAT) {
+ if (m_nPedState != PED_SEEK_CAR)
+ SetSeekCar(m_carInObjective, 0);
+ } else {
+ SetSeekBoatPosition(m_carInObjective);
+ }
+ if (m_nMoveState == PEDMOVE_STILL && !m_ped_flagB80)
+ SetMoveState(PEDMOVE_RUN);
+
+ if (m_carInObjective && m_carInObjective->m_fHealth > 0.0f) {
+ distWithTarget = m_carInObjective->GetPosition() - GetPosition();
+ if (!bInVehicle) {
+ if (nEnterCarRangeMultiplier * 30.0f < distWithTarget.Magnitude()) {
+ if (!m_carInObjective->pDriver && !m_carInObjective->GetIsOnScreen() && !GetIsOnScreen())
+ WarpPedToNearEntityOffScreen(m_carInObjective);
+
+ if (CharCreatedBy != MISSION_CHAR || m_prevObjective == OBJECTIVE_KILL_CHAR_ANY_MEANS) {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ if (IsPedInControl())
+ m_pMyVehicle = nil;
+ } else {
+ SetIdle();
+ SetMoveState(PEDMOVE_STILL);
+ }
+ }
+ }
+ } else if (!bInVehicle) {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ if (IsPedInControl())
+ m_pMyVehicle = nil;
+ }
+ }
+ }
+ break;
+ }
+ case OBJECTIVE_DESTROY_CAR:
+ {
+ if (!m_carInObjective) {
+ ClearLookFlag();
+ bObjectiveCompleted = true;
+ break;
+ }
+ float distWithTargetSc = distWithTarget.Magnitude();
+ CWeaponInfo *wepInfo = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType);
+ float wepRange = wepInfo->m_fRange;
+ m_pLookTarget = m_carInObjective;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+
+ m_pSeekTarget = m_carInObjective;
+ m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget);
+
+ TurnBody();
+ if (m_carInObjective->m_fHealth <= 0.0f) {
+ ClearLookFlag();
+ bScriptObjectiveCompleted = true;
+ break;
+ }
+
+ if (m_attackTimer < CTimer::GetTimeInMilliseconds() && wepInfo->m_eWeaponFire != WEAPON_FIRE_MELEE
+ && distWithTargetSc < wepRange) {
+
+ // I hope so
+ CVector ourHead = GetMatrix() * CVector(0.5f, 0.0f, 0.6f);
+ CVector maxShotPos = m_carInObjective->GetPosition() - ourHead;
+ maxShotPos.Normalise();
+ maxShotPos = maxShotPos * wepInfo->m_fRange + ourHead;
+
+ CWorld::bIncludeDeadPeds = true;
+ CColPoint foundCol;
+ CEntity *foundEnt;
+ CWorld::ProcessLineOfSight(ourHead, maxShotPos, foundCol, foundEnt,
+ true, true, true, true, false, true, false);
+ CWorld::bIncludeDeadPeds = false;
+ if (foundEnt == m_carInObjective) {
+ SetAttack(m_carInObjective);
+ m_pPointGunAt = m_carInObjective;
+ if (m_pPointGunAt)
+ m_pPointGunAt->RegisterReference((CEntity **) &m_pPointGunAt);
+
+ SetShootTimer(CGeneral::GetRandomNumberInRange(500, 2000));
+ if (distWithTargetSc > 10.0f && !bKindaStayInSamePlace) {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(2000, 5000));
+ } else {
+ SetAttackTimer(CGeneral::GetRandomNumberInRange(50, 300));
+ SetMoveState(PEDMOVE_STILL);
+ }
+ }
+ } else if (m_nPedState != PED_ATTACK && !bKindaStayInSamePlace) {
+
+ float safeDistance;
+ if (wepRange <= 5.0f)
+ safeDistance = 3.0f;
+ else
+ safeDistance = wepRange * 0.25f;
+
+ SetSeek(m_carInObjective, safeDistance);
+ SetMoveState(PEDMOVE_RUN);
+ }
+ SetLookFlag(m_carInObjective, false);
+ TurnBody();
+ break;
+ }
+ case OBJECTIVE_GOTO_AREA_ANY_MEANS:
+ {
+ distWithTarget = m_nextRoutePointPos - GetPosition();
+ distWithTarget.z = 0.0f;
+ if (bInVehicle && m_pMyVehicle) {
+ CCarAI::GetCarToGoToCoors(m_pMyVehicle, &m_nextRoutePointPos);
+ CCarCtrl::RegisterVehicleOfInterest(m_pMyVehicle);
+ if (distWithTarget.MagnitudeSqr() < 400.0f) {
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ CPed::ForceStoredObjective(OBJECTIVE_GOTO_AREA_ANY_MEANS);
+ SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
+ }
+ break;
+ }
+ if (distWithTarget.Magnitude() > 30.0f) {
+ if (m_pMyVehicle) {
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ } else {
+ float closestVehDist = 3600.0f;
+ int16 lastVehicle;
+ CEntity* vehicles[8];
+ CWorld::FindObjectsInRange(GetPosition(), 25.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false);
+ CVehicle* foundVeh = nil;
+ for (int i = 0; i < lastVehicle; i++) {
+ CVehicle* nearVeh = (CVehicle*)vehicles[i];
+ /*
+ Not used.
+ CVector vehSpeed = nearVeh->GetSpeed();
+ CVector ourSpeed = GetSpeed();
+ */
+ CVector vehDistVec = nearVeh->GetPosition() - GetPosition();
+ if (vehDistVec.Magnitude() < closestVehDist
+ && m_pedInObjective->m_pMyVehicle != nearVeh)
+ {
+ foundVeh = nearVeh;
+ closestVehDist = vehDistVec.Magnitude();
+ }
+ }
+ m_pMyVehicle = foundVeh;
+ if (m_pMyVehicle) {
+ m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle);
+ m_pMyVehicle->AutoPilot.m_nCruiseSpeed = 0;
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, m_pMyVehicle);
+ }
+ }
+ break;
+ }
+ // fall through
+ }
+ case OBJECTIVE_GOTO_AREA_ON_FOOT:
+ case OBJECTIVE_RUN_TO_AREA:
+ {
+ if ((m_objective == OBJECTIVE_GOTO_AREA_ON_FOOT || m_objective == OBJECTIVE_RUN_TO_AREA)
+ && bInVehicle && m_pMyVehicle) {
+ SetObjective(OBJECTIVE_LEAVE_VEHICLE, m_pMyVehicle);
+ } else {
+ distWithTarget = m_nextRoutePointPos - GetPosition();
+ distWithTarget.z = 0.0f;
+ if (sq(m_distanceToCountSeekDone) >= distWithTarget.MagnitudeSqr()) {
+ bObjectiveCompleted = true;
+ bScriptObjectiveCompleted = true;
+ SetMoveState(PEDMOVE_STILL);
+ } else if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer || m_nPedState != PED_SEEK_POS) {
+ if (bUsePedNodeSeek) {
+ CVector bestCoords(0.0f, 0.0f, 0.0f);
+ m_vecSeekPos = m_nextRoutePointPos;
+
+ if (!m_pNextPathNode)
+ FindBestCoordsFromNodes(m_vecSeekPos, &bestCoords);
+
+ if (m_pNextPathNode)
+ m_vecSeekPos = m_pNextPathNode->pos;
+ }
+ SetSeek(m_vecSeekPos, m_distanceToCountSeekDone);
+ }
+ }
+
+ break;
+ }
+ case OBJECTIVE_FIGHT_CHAR:
+ {
+ if (m_pedInObjective) {
+ SetLookFlag(m_pedInObjective, true);
+ m_pLookTarget = m_pedInObjective;
+ m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
+ m_lookTimer = m_attackTimer;
+ TurnBody();
+ float distWithTargetSc = distWithTarget.Magnitude();
+ if (distWithTargetSc >= 20.0f) {
+ RestorePreviousObjective();
+ } else if (m_attackTimer < CTimer::GetTimeInMilliseconds()) {
+ if (m_nPedState != PED_SEEK_ENTITY && distWithTargetSc >= 2.0f) {
+ SetSeek(m_pedInObjective, 1.0f);
+ } else {
+ SetAttack(m_pedInObjective);
+ SetShootTimer(CGeneral::GetRandomNumberInRange(500.0f, 1500.0f));
+ }
+ SetAttackTimer(1000);
+ }
+ } else {
+ RestorePreviousObjective();
+ }
+ break;
+ }
+ case OBJECTIVE_FOLLOW_ROUTE:
+ if (HaveReachedNextPointOnRoute(1.0f)) {
+ int nextPoint = GetNextPointOnRoute();
+ m_nextRoutePointPos = CRouteNode::GetPointPosition(nextPoint);
+ } else {
+ SetSeek(m_nextRoutePointPos, 0.8f);
+ }
+ break;
+ case OBJECTIVE_SOLICIT:
+ if (m_carInObjective) {
+ if (m_objectiveTimer <= CTimer::GetTimeInMilliseconds()) {
+ if (!bInVehicle) {
+ SetObjective(OBJECTIVE_NONE);
+ SetWanderPath(CGeneral::GetRandomNumber() & 7);
+ m_objectiveTimer = CTimer::GetTimeInMilliseconds() + 10000;
+ if (IsPedInControl())
+ m_pMyVehicle = nil;
+ }
+ } else {
+ if (m_nPedState != PED_FLEE_ENTITY && m_nPedState != PED_SOLICIT)
+ SetSeekCar(m_carInObjective, 0);
+ }
+ } else {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ if (IsPedInControl())
+ m_pMyVehicle = nil;
+ }
+ break;
+ case OBJECTIVE_HAIL_TAXI:
+ if (!RpAnimBlendClumpGetAssociation(GetClump(), ANIM_IDLE_TAXI) && CTimer::GetTimeInMilliseconds() > m_nWaitTimer) {
+ Say(SOUND_PED_TAXI_WAIT);
+ CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_IDLE_TAXI, 4.0f);
+ m_nWaitTimer = CTimer::GetTimeInMilliseconds() + 2000;
+ }
+ break;
+ case OBJECTIVE_CATCH_TRAIN:
+ {
+ if (m_carInObjective) {
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_carInObjective);
+ } else {
+ CVehicle* trainToEnter = nil;
+ float closestCarDist = 15.0f;
+ CVector pos = GetPosition();
+ int16 lastVehicle;
+ CEntity* vehicles[8];
+
+ CWorld::FindObjectsInRange(pos, 10.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false);
+ for (int i = 0; i < lastVehicle; i++) {
+ CVehicle* nearVeh = (CVehicle*)vehicles[i];
+ if (nearVeh->IsTrain()) {
+ CVector vehDistVec = GetPosition() - nearVeh->GetPosition();
+ float vehDist = vehDistVec.Magnitude();
+ if (vehDist < closestCarDist && m_pedInObjective->m_pMyVehicle != nearVeh)
+ {
+ trainToEnter = nearVeh;
+ closestCarDist = vehDist;
+ }
+ }
+ }
+ if (trainToEnter) {
+ m_carInObjective = trainToEnter;
+ m_carInObjective->RegisterReference((CEntity **) &m_carInObjective);
+ }
+ }
+ break;
+ }
+ case OBJECTIVE_BUY_ICE_CREAM:
+ if (m_carInObjective) {
+ if (m_nPedState != PED_FLEE_ENTITY && m_nPedState != PED_BUY_ICECREAM)
+ SetSeekCar(m_carInObjective, 0);
+ } else {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ if (IsPedInControl())
+ m_pMyVehicle = nil;
+ }
+ break;
+ case OBJECTIVE_STEAL_ANY_CAR:
+ {
+ if (bInVehicle) {
+ bScriptObjectiveCompleted = true;
+ RestorePreviousObjective();
+ } else if (m_hitRecoverTimer < CTimer::GetTimeInMilliseconds()) {
+ CVehicle *carToSteal = nil;
+ float closestCarDist = 30.0f;
+ CVector pos = GetPosition();
+ int16 lastVehicle;
+ CEntity *vehicles[8];
+
+ CWorld::FindObjectsInRange(pos, 15.0f, true, &lastVehicle, 6, vehicles, false, true, false, false, false);
+ for(int i = 0; i < lastVehicle; i++) {
+ CVehicle *nearVeh = (CVehicle*)vehicles[i];
+ if (nearVeh->VehicleCreatedBy != MISSION_VEHICLE) {
+ if (nearVeh->m_vecMoveSpeed.Magnitude() <= 0.1f) {
+ if (nearVeh->CanPedOpenLocks(this)) {
+ CVector vehDistVec = GetPosition() - nearVeh->GetPosition();
+ float vehDist = vehDistVec.Magnitude();
+ if (vehDist < closestCarDist) {
+ carToSteal = nearVeh;
+ closestCarDist = vehDist;
+ }
+ }
+ }
+ }
+ }
+ if (carToSteal) {
+ SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, carToSteal);
+ m_hitRecoverTimer = CTimer::GetTimeInMilliseconds() + 5000;
+ } else {
+ RestorePreviousObjective();
+ RestorePreviousState();
+ }
+ }
+ break;
+ }
+ case OBJECTIVE_MUG_CHAR:
+ {
+ if (m_pedInObjective) {
+ if (m_pedInObjective->IsPlayer() || m_pedInObjective->bInVehicle || m_pedInObjective->m_fHealth <= 0.0f) {
+ ClearObjective();
+ return;
+ }
+ if (m_pedInObjective->m_nMoveState > PEDMOVE_WALK) {
+ ClearObjective();
+ return;
+ }
+ if (m_pedInObjective->m_objective == OBJECTIVE_KILL_CHAR_ON_FOOT && m_pedInObjective->m_pedInObjective == this) {
+ SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, m_pedInObjective);
+ SetMoveState(PEDMOVE_SPRINT);
+ return;
+ }
+ if (m_pedInObjective->m_nPedState == PED_FLEE_ENTITY && m_fleeFrom == this
+ || m_pedInObjective->m_objective == OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE && m_pedInObjective->m_pedInObjective == this) {
+ ClearObjective();
+ SetFlee(m_pedInObjective, 15000);
+ bUsePedNodeSeek = true;
+ m_pNextPathNode = nil;
+ SetMoveState(PEDMOVE_WALK);
+ return;
+ }
+ float distWithTargetScSqr = distWithTarget.MagnitudeSqr();
+ if (distWithTargetScSqr <= 100.0f) {
+ if (distWithTargetScSqr <= 1.96f) {
+ CAnimBlendAssociation *reloadAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_AK_RELOAD);
+ m_fRotationDest = CGeneral::GetRadianAngleBetweenPoints(
+ m_pedInObjective->GetPosition().x, m_pedInObjective->GetPosition().y,
+ GetPosition().x, GetPosition().y);
+
+ if (reloadAssoc || !m_pedInObjective->IsPedShootable()) {
+ if (reloadAssoc &&
+ (!reloadAssoc->IsRunning() || reloadAssoc->currentTime / reloadAssoc->hierarchy->totalLength > 0.8f)) {
+ CAnimBlendAssociation *punchAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_FIGHT_PPUNCH, 8.0f);
+ punchAssoc->flags |= ASSOC_DELETEFADEDOUT;
+ punchAssoc->flags |= ASSOC_FADEOUTWHENDONE;
+ CVector2D offset(distWithTarget.x, distWithTarget.y);
+ int dir = m_pedInObjective->GetLocalDirection(offset);
+ m_pedInObjective->StartFightDefend(dir, 4, 5);
+ m_pedInObjective->ReactToAttack(this);
+ m_pedInObjective->Say(SOUND_PED_ROBBED);
+ Say(SOUND_PED_MUGGING);
+ bRichFromMugging = true;
+ ClearObjective();
+ if (m_pedInObjective->m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT
+ || m_pedInObjective->m_pedInObjective != this) {
+ SetFlee(m_pedInObjective, 15000);
+ bUsePedNodeSeek = true;
+ m_pNextPathNode = nil;
+ SetMoveState(PEDMOVE_WALK);
+ m_nLastPedState = PED_WANDER_PATH;
+ } else {
+ SetObjective(OBJECTIVE_FLEE_CHAR_ON_FOOT_TILL_SAFE, m_pedInObjective);
+ SetMoveState(PEDMOVE_SPRINT);
+ m_nLastPedState = PED_WANDER_PATH;
+ }
+ }
+ } else {
+ eWeaponType weaponType = GetWeapon()->m_eWeaponType;
+ if (weaponType != WEAPONTYPE_UNARMED && weaponType != WEAPONTYPE_BASEBALLBAT)
+ SetCurrentWeapon(WEAPONTYPE_UNARMED);
+
+ CAnimBlendAssociation *newReloadAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_AK_RELOAD, 8.0f);
+ newReloadAssoc->flags |= ASSOC_DELETEFADEDOUT;
+ newReloadAssoc->flags |= ASSOC_FADEOUTWHENDONE;
+ }
+ } else {
+ SetSeek(m_pedInObjective, 1.0f);
+ CAnimBlendAssociation *walkAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK);
+
+ if (walkAssoc)
+ walkAssoc->speed = 1.3f;
+ }
+ } else {
+ ClearObjective();
+ SetWanderPath(CGeneral::GetRandomNumber() & 7);
+ }
+ } else {
+ ClearObjective();
+ }
+ break;
+ }
+ case OBJECTIVE_FLEE_CAR:
+ if (!bInVehicle && m_nPedState != PED_FLEE_ENTITY && m_pMyVehicle) {
+ RestorePreviousObjective();
+ SetFlee(m_pMyVehicle, 6000);
+ break;
+ }
+ // fall through
+ case OBJECTIVE_LEAVE_VEHICLE:
+ if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer) {
+ if (bInVehicle && m_pMyVehicle) {
+ if (m_nPedState != PED_EXIT_CAR && m_nPedState != PED_DRAG_FROM_CAR && m_nPedState != PED_EXIT_TRAIN
+ && (m_nPedType != PEDTYPE_COP
+ || m_pMyVehicle->m_vecMoveSpeed.MagnitudeSqr2D() < 0.000025f)) {
+ if (m_pMyVehicle->IsTrain())
+ SetExitTrain(m_pMyVehicle);
+ else
+ SetExitCar(m_pMyVehicle, 0);
+ }
+ } else {
+ RestorePreviousObjective();
+ }
+ }
+ break;
+#ifdef VC_PED_PORTS
+ case OBJECTIVE_LEAVE_CAR_AND_DIE:
+ {
+ if (CTimer::GetTimeInMilliseconds() > m_leaveCarTimer) {
+ if (bInVehicle && m_pMyVehicle) {
+ if (m_nPedState != PED_EXIT_CAR && m_nPedState != PED_DRAG_FROM_CAR
+ && m_nPedState != PED_EXIT_TRAIN) {
+ // VC checks for boat instead of train
+ if (m_pMyVehicle->IsTrain())
+ SetExitTrain(m_pMyVehicle);
+ else if (m_pMyVehicle->bIsBus || m_pMyVehicle->IsBoat())
+ SetExitCar(m_pMyVehicle, 0);
+ else {
+ eCarNodes doorNode = CAR_DOOR_LF;
+ if (m_pMyVehicle->pDriver != this) {
+ if (m_pMyVehicle->pPassengers[0] == this) {
+ doorNode = CAR_DOOR_RF;
+ } else if (m_pMyVehicle->pPassengers[1] == this) {
+ doorNode = CAR_DOOR_LR;
+ } else if (m_pMyVehicle->pPassengers[2] == this) {
+ doorNode = CAR_DOOR_RR;
+ }
+ }
+ SetBeingDraggedFromCar(m_pMyVehicle, doorNode, false);
+ }
+ }
+ }
+ }
+ break;
+ }
+#endif
+ }
+ if (bObjectiveCompleted
+ || m_objectiveTimer != 0 && CTimer::GetTimeInMilliseconds() > m_objectiveTimer) {
+ RestorePreviousObjective();
+ if (m_objectiveTimer > CTimer::GetTimeInMilliseconds() || !m_objectiveTimer)
+ m_objectiveTimer = CTimer::GetTimeInMilliseconds() - 1;
+
+ if (CharCreatedBy != RANDOM_CHAR || bInVehicle) {
+ if (IsPedInControl())
+ RestorePreviousState();
+ } else {
+ SetWanderPath(CGeneral::GetRandomNumber() & 7);
+ }
+ ClearAimFlag();
+ ClearLookFlag();
+ }
+ }
+}
+
+void
+CPed::SetShootTimer(uint32 time)
+{
+ if (CTimer::GetTimeInMilliseconds() > m_shootTimer) {
+ m_shootTimer = CTimer::GetTimeInMilliseconds() + time;
+ }
+}
+
+void
+CPed::SetSeekCar(CVehicle *car, uint32 doorNode)
+{
+ if (m_nPedState == PED_SEEK_CAR)
+ return;
+
+ SetStoredState();
+ m_pSeekTarget = car;
+ m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget);
+ m_carInObjective = car;
+ m_carInObjective->RegisterReference((CEntity**) &m_carInObjective);
+ m_pMyVehicle = car;
+ m_pMyVehicle->RegisterReference((CEntity**) &m_pMyVehicle);
+ // m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget);
+ m_vehEnterType = doorNode;
+ m_distanceToCountSeekDone = 0.5f;
+ m_nPedState = PED_SEEK_CAR;
+
+}
+
+void
+CPed::SetSeekBoatPosition(CVehicle *boat)
+{
+ if (m_nPedState == PED_SEEK_IN_BOAT || boat->pDriver)
+ return;
+
+ SetStoredState();
+ m_carInObjective = boat;
+ m_carInObjective->RegisterReference((CEntity **) &m_carInObjective);
+ m_pMyVehicle = boat;
+ m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle);
+ m_distanceToCountSeekDone = 0.5f;
+ m_nPedState = PED_SEEK_IN_BOAT;
+
+}
+
+void
+CPed::SetExitTrain(CVehicle* train)
+{
+ if (m_nPedState != PED_EXIT_TRAIN && train->m_status == STATUS_TRAIN_NOT_MOVING && ((CTrain*)train)->Doors[0].IsFullyOpen()) {
+ /*
+ // Not used
+ CVector exitPos;
+ GetNearestTrainPedPosition(train, exitPos);
+ */
+ m_nPedState = PED_EXIT_TRAIN;
+ m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_TRAIN_GETOUT, 4.0f);
+ m_pVehicleAnim->SetFinishCallback(PedSetOutTrainCB, this);
+ bUsesCollision = false;
+ LineUpPedWithTrain();
+ }
+}
+
+#ifdef NEW_WALK_AROUND_ALGORITHM
+CVector
+LocalPosForWalkAround(CVector2D colMin, CVector2D colMax, int walkAround, uint32 enterDoorNode, bool itsVan) {
+ switch (walkAround) {
+ case 0:
+ if (enterDoorNode == CAR_DOOR_LF)
+ return CVector(colMin.x, colMax.y - 1.0f, 0.0f);
+ case 1:
+ return CVector(colMin.x, colMax.y, 0.0f);
+ case 2:
+ case 3:
+ if (walkAround == 3 && enterDoorNode == CAR_DOOR_RF)
+ return CVector(colMax.x, colMax.y - 1.0f, 0.0f);
+
+ return CVector(colMax.x, colMax.y, 0.0f);
+ case 4:
+ if (enterDoorNode == CAR_DOOR_RR && !itsVan)
+ return CVector(colMax.x, colMin.y + 1.0f, 0.0f);
+ case 5:
+ return CVector(colMax.x, colMin.y, 0.0f);
+ case 6:
+ case 7:
+ if (walkAround == 7 && enterDoorNode == CAR_DOOR_LR && !itsVan)
+ return CVector(colMin.x, colMin.y + 1.0f, 0.0f);
+
+ return CVector(colMin.x, colMin.y, 0.0f);
+ default:
+ return CVector(0.0f, 0.0f, 0.0f);
+ }
+}
+
+bool
+CanWeSeeTheCorner(CVector2D dist, CVector2D fwdOffset)
+{
+ // because if dist is more then 5 unit, fov isn't important, we want shortest way
+ if (dist.Magnitude() > 5.0f)
+ return true;
+
+ if (DotProduct2D(dist, fwdOffset) < 0.0f)
+ return false;
+
+ return true;
+}
+#endif
+
+// This function looks completely same on VC.
+void
+CPed::SetDirectionToWalkAroundObject(CEntity *obj)
+{
+ float distLimitForTimer = 8.0f;
+ CColModel *objCol = CModelInfo::GetModelInfo(obj->m_modelIndex)->GetColModel();
+ CVector objColMin = objCol->boundingBox.min;
+ CVector objColMax = objCol->boundingBox.max;
+ CVector objColCenter = (objColMin + objColMax) / 2.0f;
+ CMatrix objMat(obj->GetMatrix());
+ float dirToSet = obj->GetForward().Heading();
+ bool goingToEnterCarAndItsVan = false;
+ bool goingToEnterCar = false;
+ bool objUpsideDown = false;
+
+ float checkIntervalInDist = (objColMax.y - objColMin.y) * 0.1f;
+ float checkIntervalInTime;
+
+ if (m_nMoveState == PEDMOVE_NONE || m_nMoveState == PEDMOVE_STILL)
+ return;
+
+ if (CharCreatedBy != MISSION_CHAR && obj->m_modelIndex == MI_PHONEBOOTH1) {
+ bool isRunning = m_nMoveState == PEDMOVE_RUN || m_nMoveState == PEDMOVE_SPRINT;
+ SetFlee(obj, 5000);
+ bUsePedNodeSeek = true;
+ m_pNextPathNode = nil;
+ if (!isRunning)
+ SetMoveState(PEDMOVE_WALK);
+ return;
+ }
+ CVector2D adjustedColMin(objColMin.x - 0.35f, objColMin.y - 0.35f);
+ CVector2D adjustedColMax(objColMax.x + 0.35f, objColMax.y + 0.35f);
+
+ checkIntervalInDist = max(checkIntervalInDist, 0.5f);
+ checkIntervalInDist = min(checkIntervalInDist, (objColMax.z - objColMin.z) / 2.0f);
+ checkIntervalInDist = min(checkIntervalInDist, (adjustedColMax.x - adjustedColMin.x) / 2.0f);
+
+ if (objMat.GetUp().z < 0.0f)
+ objUpsideDown = true;
+
+ if (obj->m_modelIndex != MI_TRAFFICLIGHTS && obj->m_modelIndex != MI_SINGLESTREETLIGHTS1 && obj->m_modelIndex != MI_SINGLESTREETLIGHTS2) {
+ objColCenter = obj->GetMatrix() * objColCenter;
+ } else {
+ checkIntervalInDist = 0.4f;
+ if (objMat.GetUp().z <= 0.57f) {
+
+ // Specific calculations for traffic lights, didn't get a bit.
+ adjustedColMin.x = 1.2f * (adjustedColMin.x < adjustedColMin.y ? adjustedColMin.x : adjustedColMin.y);
+ adjustedColMax.x = 1.2f * (adjustedColMax.x > adjustedColMax.y ? adjustedColMax.x : adjustedColMax.y);
+ adjustedColMin.y = 1.2f * objColMin.z;
+ adjustedColMax.y = 1.2f * objColMax.z;
+ dirToSet = objMat.GetUp().Heading();
+ objMat.SetUnity();
+ objMat.RotateZ(dirToSet);
+ objMat.GetPosition() += obj->GetPosition();
+ objColCenter = obj->GetPosition();
+ } else {
+ objColCenter.x = adjustedColMax.x - 0.25f;
+ objColCenter = obj->GetMatrix() * objColCenter;
+ distLimitForTimer = 0.75f;
+ }
+ objUpsideDown = false;
+ }
+ float oldRotDest = m_fRotationDest;
+#ifndef NEW_WALK_AROUND_ALGORITHM
+ float angleToFaceObjCenter = (objColCenter - GetPosition()).Heading();
+ float angleDiffBtwObjCenterAndForward = CGeneral::LimitRadianAngle(dirToSet - angleToFaceObjCenter);
+ float objTopRightHeading = Atan2(adjustedColMax.x - adjustedColMin.x, adjustedColMax.y - adjustedColMin.y);
+#endif
+
+ if (IsPlayer()) {
+ if (FindPlayerPed()->m_fMoveSpeed <= 0.0f)
+ checkIntervalInTime = 0.0f;
+ else
+ checkIntervalInTime = 2.0f / FindPlayerPed()->m_fMoveSpeed;
+ } else {
+ switch (m_nMoveState) {
+ case PEDMOVE_WALK:
+ checkIntervalInTime = 2.0f;
+ break;
+ case PEDMOVE_RUN:
+ checkIntervalInTime = 0.5f;
+ break;
+ case PEDMOVE_SPRINT:
+ checkIntervalInTime = 0.5f;
+ break;
+ default:
+ checkIntervalInTime = 0.0f;
+ break;
+ }
+ }
+ if (m_pSeekTarget == obj && obj->IsVehicle()) {
+ if (m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER || m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER
+ || m_objective == OBJECTIVE_SOLICIT) {
+ goingToEnterCar = true;
+ if (IsPlayer())
+ checkIntervalInTime = 0.0f;
+
+ if (((CVehicle*)obj)->bIsVan)
+ goingToEnterCarAndItsVan = true;
+ }
+ }
+
+ int entityOnTopLeftOfObj = 0;
+ int entityOnBottomLeftOfObj = 0;
+ int entityOnTopRightOfObj = 0;
+ int entityOnBottomRightOfObj = 0;
+
+ if (CTimer::GetTimeInMilliseconds() > m_collidingThingTimer || m_collidingEntityWhileFleeing != obj) {
+ bool collidingThingChanged = true;
+ CEntity *obstacle;
+
+#ifndef NEW_WALK_AROUND_ALGORITHM
+ if (!obj->IsVehicle() || objUpsideDown) {
+ collidingThingChanged = false;
+ } else {
+#else
+ CVector cornerToGo = CVector(10.0f, 10.0f, 10.0f);
+ int dirToGo;
+ m_walkAroundType = 0;
+#endif
+ float adjustedCheckInterval = 0.7f * checkIntervalInDist;
+ CVector posToCheck;
+
+ // Top left of obj
+ posToCheck.x = adjustedColMin.x + adjustedCheckInterval;
+ posToCheck.y = adjustedColMax.y - adjustedCheckInterval;
+ posToCheck.z = 0.0f;
+ posToCheck = objMat * posToCheck;
+ posToCheck.z += 0.6f;
+ obstacle = CWorld::TestSphereAgainstWorld(posToCheck, checkIntervalInDist, obj,
+ true, true, false, true, false, false);
+ if (obstacle) {
+ if (obstacle->IsBuilding()) {
+ entityOnTopLeftOfObj = 1;
+ } else if (obstacle->IsVehicle()) {
+ entityOnTopLeftOfObj = 2;
+ } else {
+ entityOnTopLeftOfObj = 3;
+ }
+ }
+#ifdef NEW_WALK_AROUND_ALGORITHM
+ else {
+ CVector tl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMax.y, 0.0f) - GetPosition();
+ if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) {
+ cornerToGo = tl;
+ m_walkAroundType = 1;
+ } else if(CanWeSeeTheCorner(tl, GetForward())){
+ cornerToGo = tl;
+ dirToGo = GetLocalDirection(tl);
+ if (dirToGo == 1)
+ m_walkAroundType = 0; // ALL of the next turns will be right turn
+ else if (dirToGo == 3)
+ m_walkAroundType = 1; // ALL of the next turns will be left turn
+ }
+ }
+#endif
+
+ // Top right of obj
+ posToCheck.x = adjustedColMax.x - adjustedCheckInterval;
+ posToCheck.y = adjustedColMax.y - adjustedCheckInterval;
+ posToCheck.z = 0.0f;
+ posToCheck = objMat * posToCheck;
+ posToCheck.z += 0.6f;
+ obstacle = CWorld::TestSphereAgainstWorld(posToCheck, checkIntervalInDist, obj,
+ true, true, false, true, false, false);
+ if (obstacle) {
+ if (obstacle->IsBuilding()) {
+ entityOnTopRightOfObj = 1;
+ } else if (obstacle->IsVehicle()) {
+ entityOnTopRightOfObj = 2;
+ } else {
+ entityOnTopRightOfObj = 3;
+ }
+ }
+#ifdef NEW_WALK_AROUND_ALGORITHM
+ else {
+ CVector tr = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMax.y, 0.0f) - GetPosition();
+ if (tr.Magnitude2D() < cornerToGo.Magnitude2D()) {
+ if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) {
+ cornerToGo = tr;
+ m_walkAroundType = 2;
+ } else if (CanWeSeeTheCorner(tr, GetForward())) {
+ cornerToGo = tr;
+ dirToGo = GetLocalDirection(tr);
+ if (dirToGo == 1)
+ m_walkAroundType = 2; // ALL of the next turns will be right turn
+ else if (dirToGo == 3)
+ m_walkAroundType = 3; // ALL of the next turns will be left turn
+ }
+ }
+ }
+#endif
+
+ // Bottom right of obj
+ posToCheck.x = adjustedColMax.x - adjustedCheckInterval;
+ posToCheck.y = adjustedColMin.y + adjustedCheckInterval;
+ posToCheck.z = 0.0f;
+ posToCheck = objMat * posToCheck;
+ posToCheck.z += 0.6f;
+ obstacle = CWorld::TestSphereAgainstWorld(posToCheck, checkIntervalInDist, obj,
+ true, true, false, true, false, false);
+ if (obstacle) {
+ if (obstacle->IsBuilding()) {
+ entityOnBottomRightOfObj = 1;
+ } else if (obstacle->IsVehicle()) {
+ entityOnBottomRightOfObj = 2;
+ } else {
+ entityOnBottomRightOfObj = 3;
+ }
+ }
+#ifdef NEW_WALK_AROUND_ALGORITHM
+ else {
+ CVector br = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMin.y, 0.0f) - GetPosition();
+ if (br.Magnitude2D() < cornerToGo.Magnitude2D()) {
+ if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) {
+ cornerToGo = br;
+ m_walkAroundType = 5;
+ } else if (CanWeSeeTheCorner(br, GetForward())) {
+ cornerToGo = br;
+ dirToGo = GetLocalDirection(br);
+ if (dirToGo == 1)
+ m_walkAroundType = 4; // ALL of the next turns will be right turn
+ else if (dirToGo == 3)
+ m_walkAroundType = 5; // ALL of the next turns will be left turn
+ }
+ }
+ }
+#endif
+
+ // Bottom left of obj
+ posToCheck.x = adjustedColMin.x + adjustedCheckInterval;
+ posToCheck.y = adjustedColMin.y + adjustedCheckInterval;
+ posToCheck.z = 0.0f;
+ posToCheck = objMat * posToCheck;
+ posToCheck.z += 0.6f;
+ obstacle = CWorld::TestSphereAgainstWorld(posToCheck, checkIntervalInDist, obj,
+ true, true, false, true, false, false);
+ if (obstacle) {
+ if (obstacle->IsBuilding()) {
+ entityOnBottomLeftOfObj = 1;
+ } else if (obstacle->IsVehicle()) {
+ entityOnBottomLeftOfObj = 2;
+ } else {
+ entityOnBottomLeftOfObj = 3;
+ }
+ }
+#ifdef NEW_WALK_AROUND_ALGORITHM
+ else {
+ CVector bl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMin.y, 0.0f) - GetPosition();
+ if (bl.Magnitude2D() < cornerToGo.Magnitude2D()) {
+ if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) {
+ cornerToGo = bl;
+ m_walkAroundType = 6;
+ } else if (CanWeSeeTheCorner(bl, GetForward())) {
+ cornerToGo = bl;
+ dirToGo = GetLocalDirection(bl);
+ if (dirToGo == 1)
+ m_walkAroundType = 6; // ALL of the next turns will be right turn
+ else if (dirToGo == 3)
+ m_walkAroundType = 7; // ALL of the next turns will be left turn
+ }
+ }
+ }
+#else
+ }
+
+ if (entityOnTopLeftOfObj && entityOnTopRightOfObj && entityOnBottomRightOfObj && entityOnBottomLeftOfObj) {
+ collidingThingChanged = false;
+ entityOnTopLeftOfObj = 0;
+ entityOnBottomLeftOfObj = 0;
+ entityOnTopRightOfObj = 0;
+ entityOnBottomRightOfObj = 0;
+ }
+
+ if (!collidingThingChanged) {
+ m_walkAroundType = 0;
+ } else {
+ if (Abs(angleDiffBtwObjCenterAndForward) >= objTopRightHeading) {
+ if (PI - objTopRightHeading >= Abs(angleDiffBtwObjCenterAndForward)) {
+ if ((angleDiffBtwObjCenterAndForward <= 0.0f || objUpsideDown) && (angleDiffBtwObjCenterAndForward < 0.0f || !objUpsideDown)) {
+ if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) {
+ m_walkAroundType = 0;
+ } else {
+ if (CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) >= 0.0f) {
+ if (entityOnBottomRightOfObj == 1 || entityOnBottomRightOfObj && !entityOnTopLeftOfObj && !entityOnTopRightOfObj) {
+ m_walkAroundType = 1;
+ } else if (entityOnBottomLeftOfObj == 1 || entityOnBottomLeftOfObj && !entityOnTopLeftOfObj && !entityOnTopRightOfObj) {
+ m_walkAroundType = 1;
+ }
+ } else {
+ if (entityOnTopRightOfObj == 1 || entityOnTopRightOfObj && !entityOnBottomRightOfObj && !entityOnBottomLeftOfObj) {
+ m_walkAroundType = 4;
+ } else if (entityOnTopLeftOfObj == 1 || entityOnTopLeftOfObj && !entityOnBottomRightOfObj && !entityOnBottomLeftOfObj) {
+ m_walkAroundType = 4;
+ }
+ }
+ }
+ } else {
+ if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) {
+ m_walkAroundType = 0;
+ } else {
+ if (CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) <= 0.0f) {
+ if (entityOnBottomLeftOfObj == 1 || entityOnBottomLeftOfObj && !entityOnTopLeftOfObj && !entityOnTopRightOfObj) {
+ m_walkAroundType = 2;
+ } else if (entityOnBottomRightOfObj == 1 || entityOnBottomRightOfObj && !entityOnTopLeftOfObj && !entityOnTopRightOfObj) {
+ m_walkAroundType = 2;
+ }
+ } else {
+ if (entityOnTopLeftOfObj == 1 || entityOnTopLeftOfObj && !entityOnBottomRightOfObj && !entityOnBottomLeftOfObj) {
+ m_walkAroundType = 3;
+ } else if (entityOnTopRightOfObj == 1 || entityOnTopRightOfObj && !entityOnBottomRightOfObj && !entityOnBottomLeftOfObj) {
+ m_walkAroundType = 3;
+ }
+ }
+ }
+ }
+ } else if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)
+ || CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) < 0.0f) {
+ if (entityOnTopLeftOfObj == 1 || entityOnTopLeftOfObj && !entityOnTopRightOfObj && !entityOnBottomRightOfObj) {
+ m_walkAroundType = 3;
+ }
+ } else if (entityOnTopRightOfObj == 1 || entityOnTopRightOfObj && !entityOnTopLeftOfObj && !entityOnBottomLeftOfObj) {
+ m_walkAroundType = 4;
+ }
+ } else if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)
+ || CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) > 0.0f) {
+ if (entityOnBottomLeftOfObj == 1 || entityOnBottomLeftOfObj && !entityOnTopRightOfObj && !entityOnBottomRightOfObj) {
+ m_walkAroundType = 2;
+ }
+ } else if (entityOnBottomRightOfObj == 1 || entityOnBottomRightOfObj && !entityOnTopLeftOfObj && !entityOnBottomLeftOfObj) {
+ m_walkAroundType = 1;
+ } else {
+ m_walkAroundType = 0;
+ }
+ }
+#endif
+ }
+ m_collidingEntityWhileFleeing = obj;
+ m_collidingEntityWhileFleeing->RegisterReference((CEntity**) &m_collidingEntityWhileFleeing);
+
+ // TODO: This random may need to be changed.
+ m_collidingThingTimer = CTimer::GetTimeInMilliseconds() + 512 + CGeneral::GetRandomNumber();
+
+ CVector localPosToHead;
+
+#ifdef NEW_WALK_AROUND_ALGORITHM
+ int nextWalkAround = m_walkAroundType;
+ if (m_walkAroundType % 2 == 0) {
+ nextWalkAround += 2;
+ if (nextWalkAround > 6)
+ nextWalkAround = 0;
+ } else {
+ nextWalkAround -= 2;
+ if (nextWalkAround < 0)
+ nextWalkAround = 7;
+ }
+
+ CVector nextPosToHead = objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, nextWalkAround, goingToEnterCar ? m_vehEnterType : 0, goingToEnterCarAndItsVan);
+ bool nextRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), nextPosToHead, true, true, true, true, true, true, false);
+
+ if(nextRouteIsClear)
+ m_walkAroundType = nextWalkAround;
+ else {
+ CVector posToHead = objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType, goingToEnterCar ? m_vehEnterType : 0, goingToEnterCarAndItsVan);
+ bool currentRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), posToHead,
+ true, true, true, true, true, true, false);
+
+ /* Either;
+ * - Some obstacle came in and it's impossible to reach current destination
+ * - We reached to the destination, but since next route is not clear, we're turning around us
+ */
+ if (!currentRouteIsClear ||
+ ((posToHead - GetPosition()).Magnitude2D() < 0.8f &&
+ !CWorld::GetIsLineOfSightClear(GetPosition() + GetForward(), nextPosToHead,
+ true, true, true, true, true, true, false))) {
+
+ // Change both target and direction (involves changing even/oddness)
+ if (m_walkAroundType % 2 == 0) {
+ m_walkAroundType -= 2;
+ if (m_walkAroundType < 0)
+ m_walkAroundType = 7;
+ else
+ m_walkAroundType += 1;
+ } else {
+ m_walkAroundType += 2;
+ if (m_walkAroundType > 7)
+ m_walkAroundType = 0;
+ else
+ m_walkAroundType -= 1;
+ }
+ }
+ }
+
+ localPosToHead = LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType, goingToEnterCar ? m_vehEnterType : 0, goingToEnterCarAndItsVan);
+#else
+ if (Abs(angleDiffBtwObjCenterAndForward) < objTopRightHeading) {
+ if (goingToEnterCar) {
+ if (goingToEnterCarAndItsVan) {
+ if (m_vehEnterType == CAR_DOOR_LR || m_vehEnterType == CAR_DOOR_RR)
+ return;
+ }
+ if (m_vehEnterType != CAR_DOOR_LF && m_vehEnterType != CAR_DOOR_LR && (!entityOnBottomRightOfObj || entityOnBottomLeftOfObj)) {
+ m_fRotationDest = CGeneral::LimitRadianAngle(dirToSet - HALFPI);
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(HALFPI + dirToSet);
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ }
+ } else {
+ if (m_walkAroundType != 1 && m_walkAroundType != 4
+ && (m_walkAroundType || CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) <= 0.0f)) {
+
+ m_fRotationDest = CGeneral::LimitRadianAngle(dirToSet - HALFPI);
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(HALFPI + dirToSet);
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ }
+ }
+ } else {
+ if (PI - objTopRightHeading >= Abs(angleDiffBtwObjCenterAndForward)) {
+ if (angleDiffBtwObjCenterAndForward <= 0.0f) {
+ if (!goingToEnterCar || !goingToEnterCarAndItsVan || m_vehEnterType != CAR_DOOR_LR && m_vehEnterType != CAR_DOOR_RR) {
+ if (goingToEnterCar) {
+ if (m_vehEnterType == CAR_DOOR_RF || (m_vehEnterType == CAR_DOOR_RR && !goingToEnterCarAndItsVan))
+ return;
+ }
+ if (m_walkAroundType == 4 || m_walkAroundType == 3
+ || !m_walkAroundType && CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) > 0.0f) {
+
+ m_fRotationDest = CGeneral::LimitRadianAngle(PI + dirToSet);
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ } else {
+ m_fRotationDest = dirToSet;
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMax.y;
+ }
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(PI + dirToSet);
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ }
+ } else if (goingToEnterCar && goingToEnterCarAndItsVan && (m_vehEnterType == CAR_DOOR_LR || m_vehEnterType == CAR_DOOR_RR)) {
+ m_fRotationDest = CGeneral::LimitRadianAngle(PI + dirToSet);
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ } else {
+ if (goingToEnterCar) {
+ if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR && !goingToEnterCarAndItsVan)
+ return;
+ }
+ if (m_walkAroundType == 1 || m_walkAroundType == 2
+ || !m_walkAroundType && CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) > 0.0f) {
+
+ m_fRotationDest = dirToSet;
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMax.y;
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(PI + dirToSet);
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMin.y;
+ }
+ }
+ } else {
+ if (goingToEnterCar && (!goingToEnterCarAndItsVan || m_vehEnterType != CAR_DOOR_LR && m_vehEnterType != CAR_DOOR_RR)) {
+ if (m_vehEnterType != CAR_DOOR_LF && m_vehEnterType != CAR_DOOR_LR && (!entityOnTopRightOfObj || entityOnTopLeftOfObj)) {
+
+ m_fRotationDest = CGeneral::LimitRadianAngle(dirToSet - HALFPI);
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMax.y;
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(HALFPI + dirToSet);
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMax.y;
+ }
+ } else {
+ if (m_walkAroundType == 2 || m_walkAroundType == 3
+ || !m_walkAroundType && CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) > 0.0f) {
+
+ m_fRotationDest = CGeneral::LimitRadianAngle(dirToSet - HALFPI);
+ localPosToHead.x = adjustedColMax.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMax.y;
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(HALFPI + dirToSet);
+ localPosToHead.x = adjustedColMin.x;
+ localPosToHead.z = 0.0f;
+ localPosToHead.y = adjustedColMax.y;
+ }
+ }
+ }
+ }
+#endif
+ if (objUpsideDown)
+ localPosToHead.x = localPosToHead.x * -1.0f;
+
+ localPosToHead = objMat * localPosToHead;
+ m_actionX = localPosToHead.x;
+ m_actionY = localPosToHead.y;
+ localPosToHead -= GetPosition();
+ m_fRotationDest = CGeneral::LimitRadianAngle(localPosToHead.Heading());
+
+ if (m_fRotationDest != m_fRotationCur && bHitSomethingLastFrame) {
+ if (m_fRotationDest == oldRotDest) {
+ m_fRotationDest = oldRotDest;
+ } else {
+ m_fRotationDest = CGeneral::LimitRadianAngle(PI + dirToSet);
+ }
+ }
+
+ float dist = localPosToHead.Magnitude2D();
+ if (dist < 0.5f)
+ dist = 0.5f;
+
+ if (dist > distLimitForTimer)
+ dist = distLimitForTimer;
+ m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 280.0f * dist * checkIntervalInTime;
+}
+
+int32
+CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints)
+{
+ bool collidedWithBoat = false;
+ bool belowTorsoCollided = false;
+ float gravityEffect = -0.15f * CTimer::GetTimeStep();
+ CColPoint intersectionPoint;
+ CColLine ourLine;
+
+ CColModel *ourCol = CModelInfo::GetModelInfo(m_modelIndex)->GetColModel();
+ CColModel *hisCol = CModelInfo::GetModelInfo(collidingEnt->m_modelIndex)->GetColModel();
+
+ if (!bUsesCollision)
+ return false;
+
+ if (collidingEnt->IsVehicle() && ((CVehicle*)collidingEnt)->IsBoat())
+ collidedWithBoat = true;
+
+ if (!field_EF && !m_phy_flagA80
+#ifdef VC_PED_PORTS
+ && !collidingEnt->IsPed()
+#endif
+ ) {
+ if (!bCollisionProcessed) {
+#ifdef VC_PED_PORTS
+ m_pCurrentPhysSurface = nil;
+#endif
+ if (bIsStanding) {
+ bIsStanding = false;
+ m_ped_flagA2 = true;
+ }
+ bCollisionProcessed = true;
+ m_fCollisionSpeed += m_vecMoveSpeed.Magnitude2D() * CTimer::GetTimeStep();
+ bStillOnValidPoly = false;
+ if (IsPlayer() || m_fCollisionSpeed >= 1.0f
+ && (m_fCollisionSpeed >= 2.0f || m_nPedState != PED_WANDER_PATH)) {
+ m_collPoly.valid = false;
+ m_fCollisionSpeed = 0.0f;
+ bHitSteepSlope = false;
+ } else {
+ CVector pos = GetPosition();
+ float potentialGroundZ = GetPosition().z - FEET_OFFSET;
+ if (m_ped_flagA2) {
+ pos.z += -0.25f;
+ potentialGroundZ += gravityEffect;
+ }
+ if (CCollision::IsStoredPolyStillValidVerticalLine(pos, potentialGroundZ, intersectionPoint, &m_collPoly)) {
+ bStillOnValidPoly = true;
+#ifdef VC_PED_PORTS
+ if(!bKnockedUpIntoAir || FEET_OFFSET + intersectionPoint.point.z < GetPosition().z) {
+ GetPosition().z = FEET_OFFSET + intersectionPoint.point.z;
+ if (bKnockedUpIntoAir)
+ bKnockedUpIntoAir = false;
+ }
+#else
+ GetPosition().z = FEET_OFFSET + intersectionPoint.point.z;
+#endif
+
+ m_vecMoveSpeed.z = 0.0f;
+ bIsStanding = true;
+ } else {
+ m_collPoly.valid = false;
+ m_fCollisionSpeed = 0.0f;
+ bHitSteepSlope = false;
+ }
+ }
+ }
+
+ if (!bStillOnValidPoly) {
+ CVector potentialCenter = GetPosition();
+ potentialCenter.z = GetPosition().z - 0.52f;
+
+ // 0.52f should be a ped's approx. radius
+ float totalRadiusWhenCollided = collidingEnt->GetBoundRadius() + 0.52f - gravityEffect;
+ if (m_ped_flagA2) {
+ if (collidedWithBoat) {
+ potentialCenter.z += 2.0f * gravityEffect;
+ totalRadiusWhenCollided += Abs(gravityEffect);
+ } else {
+ potentialCenter.z += gravityEffect;
+ }
+ }
+ if (sq(totalRadiusWhenCollided) > (potentialCenter - collidingEnt->GetBoundCentre()).MagnitudeSqr()) {
+ ourLine.p0 = GetPosition();
+ ourLine.p1 = GetPosition();
+ ourLine.p1.z = GetPosition().z - FEET_OFFSET;
+ if (m_ped_flagA2) {
+ ourLine.p1.z = ourLine.p1.z + gravityEffect;
+ ourLine.p0.z = ourLine.p0.z + -0.25f;
+ }
+ float minDist = 1.0f;
+ belowTorsoCollided = CCollision::ProcessVerticalLine(ourLine, collidingEnt->GetMatrix(), *hisCol,
+ intersectionPoint, minDist, false, &m_collPoly);
+
+ if (collidedWithBoat && m_ped_flagA2 && !belowTorsoCollided) {
+ ourLine.p0.z = ourLine.p1.z;
+ ourLine.p1.z = ourLine.p1.z + gravityEffect;
+ belowTorsoCollided = CCollision::ProcessVerticalLine(ourLine, collidingEnt->GetMatrix(), *hisCol,
+ intersectionPoint, minDist, false, &m_collPoly);
+ }
+ if (belowTorsoCollided) {
+#ifndef VC_PED_PORTS
+ if (!collidingEnt->IsPed()) {
+#endif
+ if (!bIsStanding
+ || FEET_OFFSET + intersectionPoint.point.z > GetPosition().z
+ || collidedWithBoat && 3.12f + intersectionPoint.point.z > GetPosition().z) {
+
+ if (!collidingEnt->IsVehicle() && !collidingEnt->IsObject()) {
+ m_pCurSurface = collidingEnt;
+ collidingEnt->RegisterReference((CEntity**)&m_pCurSurface);
+ m_ped_flagH10 = false;
+ bOnBoat = false;
+ } else {
+ m_pCurrentPhysSurface = collidingEnt;
+ collidingEnt->RegisterReference((CEntity**)m_pCurrentPhysSurface);
+ m_vecOffsetFromPhysSurface = intersectionPoint.point - collidingEnt->GetPosition();
+ m_pCurSurface = collidingEnt;
+ collidingEnt->RegisterReference((CEntity**)&m_pCurSurface);
+ m_collPoly.valid = false;
+ if (collidingEnt->IsVehicle() && ((CVehicle*)collidingEnt)->IsBoat()) {
+ bOnBoat = true;
+ } else {
+ bOnBoat = false;
+ }
+ }
+#ifdef VC_PED_PORTS
+ if (!bKnockedUpIntoAir || FEET_OFFSET + intersectionPoint.point.z < GetPosition().z) {
+ GetPosition().z = FEET_OFFSET + intersectionPoint.point.z;
+ if (bKnockedUpIntoAir)
+ bKnockedUpIntoAir = false;
+ }
+#else
+ GetPosition().z = FEET_OFFSET + intersectionPoint.point.z;
+#endif
+ m_nSurfaceTouched = intersectionPoint.surfaceB;
+ if (m_nSurfaceTouched == SURFACE_STONE) {
+ bHitSteepSlope = true;
+ m_vecDamageNormal = intersectionPoint.normal;
+ }
+ }
+#ifdef VC_PED_PORTS
+ float upperSpeedLimit = 0.33f;
+ float lowerSpeedLimit = -0.25f;
+ float speed = m_vecMoveSpeed.Magnitude2D();
+ if (m_nPedState == PED_IDLE) {
+ upperSpeedLimit *= 2.0f;
+ lowerSpeedLimit *= 1.5f;
+ }
+ if (m_ped_flagA2
+ || (speed <= upperSpeedLimit /* || (bfFlagsL >> 5) & 1 */) && m_vecMoveSpeed.z >= lowerSpeedLimit
+ || m_pCollidingEntity == collidingEnt) {
+
+ if (!m_ped_flagA2 && RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL)
+ && -0.016f * CTimer::GetTimeStep() > m_vecMoveSpeed.z) {
+ InflictDamage(collidingEnt, WEAPONTYPE_FALL_DAMAGE, 15.0f, PEDPIECE_TORSO, 2);
+ }
+ } else {
+ float damage = 100.0f * max(speed - 0.25f, 0.0f);
+ float damage2 = damage;
+ if (m_vecMoveSpeed.z < -0.25f)
+ damage += (-0.25f - m_vecMoveSpeed.z) * 150.0f;
+
+ uint8 dir = 2; // from backward
+ if (m_vecMoveSpeed.x > 0.01f || m_vecMoveSpeed.x < -0.01f
+ || m_vecMoveSpeed.y > 0.01f || m_vecMoveSpeed.y < -0.01f) {
+ CVector2D offset = -m_vecMoveSpeed;
+ dir = GetLocalDirection(offset);
+ }
+ InflictDamage(collidingEnt, WEAPONTYPE_FALL_DAMAGE, damage, PEDPIECE_TORSO, dir);
+ if (IsPlayer() && damage2 > 5.0f)
+ Say(SOUND_PED_LAND);
+ }
+#else
+ float speedSqr = m_vecMoveSpeed.MagnitudeSqr();
+ if (m_ped_flagA2
+ || m_vecMoveSpeed.z >= -0.25f && speedSqr <= 0.25f) {
+ if (!m_ped_flagA2 && RpAnimBlendClumpGetAssociation(GetClump(), ANIM_FALL_FALL)
+ && -0.016f * CTimer::GetTimeStep() > m_vecMoveSpeed.z) {
+ InflictDamage(collidingEnt, WEAPONTYPE_FALL_DAMAGE, 15.0f, PEDPIECE_TORSO, 2);
+ }
+ } else {
+ if (speedSqr == 0.0f)
+ speedSqr = sq(m_vecMoveSpeed.z);
+
+ uint8 dir = 2; // from backward
+ if (m_vecMoveSpeed.x > 0.01f || m_vecMoveSpeed.x < -0.01f
+ || m_vecMoveSpeed.y > 0.01f || m_vecMoveSpeed.y < -0.01f) {
+ CVector2D offset = -m_vecMoveSpeed;
+ dir = GetLocalDirection(offset);
+ }
+ InflictDamage(collidingEnt, WEAPONTYPE_FALL_DAMAGE, 350.0f * sq(speedSqr), PEDPIECE_TORSO, dir);
+ }
+#endif
+ m_vecMoveSpeed.z = 0.0f;
+ bIsStanding = true;
+#ifndef VC_PED_PORTS
+ } else {
+ bOnBoat = false;
+ }
+#endif
+ } else {
+ bOnBoat = false;
+ }
+ }
+ }
+ }
+
+ int ourCollidedSpheres = CCollision::ProcessColModels(GetMatrix(), *ourCol, collidingEnt->GetMatrix(), *hisCol, collidingPoints, nil, nil);
+ if (ourCollidedSpheres > 0 || belowTorsoCollided) {
+ AddCollisionRecord(collidingEnt);
+ if (!collidingEnt->IsBuilding())
+ ((CPhysical*)collidingEnt)->AddCollisionRecord(this);
+
+ if (ourCollidedSpheres > 0 && (collidingEnt->IsBuilding() || collidingEnt->bIsStatic)) {
+ bHasHitWall = true;
+ }
+ }
+ if (collidingEnt->IsBuilding() || collidingEnt->bIsStatic) {
+
+ if (m_ped_flagA2) {
+ CVector sphereNormal;
+ float normalLength;
+ for(int sphere = 0; sphere < ourCollidedSpheres; sphere++) {
+ sphereNormal = collidingPoints[sphere].normal;
+#ifdef VC_PED_PORTS
+ if (sphereNormal.z >= -1.0f || !IsPlayer()) {
+#endif
+ normalLength = sphereNormal.Magnitude2D();
+ if (normalLength != 0.0f) {
+ sphereNormal.x = sphereNormal.x / normalLength;
+ sphereNormal.y = sphereNormal.y / normalLength;
+ }
+#ifdef VC_PED_PORTS
+ } else {
+ float speed = m_vecMoveSpeed.Magnitude2D();
+ sphereNormal.x = -m_vecMoveSpeed.x / max(0.001f, speed);
+ sphereNormal.y = -m_vecMoveSpeed.y / max(0.001f, speed);
+ GetPosition().z -= 0.05f;
+ bKnockedUpIntoAir = true;
+ }
+#endif
+ sphereNormal.Normalise();
+ collidingPoints[sphere].normal = sphereNormal;
+ if (collidingPoints[sphere].surfaceB == SURFACE_STONE)
+ bHitSteepSlope = true;
+ }
+ }
+ }
+ return ourCollidedSpheres;
+}
class CPed_ : public CPed
{
@@ -10877,6 +14398,8 @@ public:
void RemoveLighting_(bool reset) { CPed::RemoveLighting(reset); }
void Teleport_(CVector pos) { CPed::Teleport(pos); }
void ProcessControl_(void) { CPed::ProcessControl(); }
+ void Render_(void) { CPed::Render(); }
+ int32 ProcessEntityCollision_(CEntity *collidingEnt, CColPoint *collidingPoints) { return CPed::ProcessEntityCollision(collidingEnt, collidingPoints); }
};
STARTPATCHES
@@ -10888,6 +14411,8 @@ STARTPATCHES
InjectHook(0x4A7DC0, &CPed_::RemoveLighting_, PATCH_JUMP);
InjectHook(0x4D3E70, &CPed_::Teleport_, PATCH_JUMP);
InjectHook(0x4C8910, &CPed_::ProcessControl_, PATCH_JUMP);
+ InjectHook(0x4D03F0, &CPed_::Render_, PATCH_JUMP);
+ InjectHook(0x4CBB30, &CPed_::ProcessEntityCollision_, PATCH_JUMP);
InjectHook(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP);
InjectHook(0x4C6AA0, &CPed::AimGun, PATCH_JUMP);
@@ -10922,7 +14447,6 @@ STARTPATCHES
InjectHook(0x4C7EA0, &CPed::CalculateNewOrientation, PATCH_JUMP);
InjectHook(0x4C78F0, &CPed::WorkOutHeadingForMovingFirstPerson, PATCH_JUMP);
InjectHook(0x4C73F0, &CPed::CalculateNewVelocity, PATCH_JUMP);
- InjectHook(0x4D72F0, &CPed::CanPedJumpThis, PATCH_JUMP);
InjectHook(0x4DD820, &CPed::CanSeeEntity, PATCH_JUMP);
InjectHook(0x4D9460, &CPed::RestorePreviousObjective, PATCH_JUMP);
InjectHook(0x4D82C0, (void (CPed::*)(eObjective)) &CPed::SetObjective, PATCH_JUMP);
@@ -11054,4 +14578,15 @@ STARTPATCHES
InjectHook(0x4E2920, &CPed::PedSetDraggedOutCarPositionCB, PATCH_JUMP);
InjectHook(0x4CF220, &CPed::PedSetInCarCB, PATCH_JUMP);
InjectHook(0x4E3290, &CPed::PedSetInTrainCB, PATCH_JUMP);
+ InjectHook(0x4C10C0, &CPed::RunToReportCrime, PATCH_JUMP);
+ InjectHook(0x4E3870, &CPed::RegisterThreatWithGangPeds, PATCH_JUMP);
+ InjectHook(0x4DD980, &CPed::ReactToPointGun, PATCH_JUMP);
+ InjectHook(0x4CE8F0, &CPed::PedSetOutCarCB, PATCH_JUMP);
+ InjectHook(0x4E36E0, &CPed::PedSetOutTrainCB, PATCH_JUMP);
+ InjectHook(0x4EB6E0, &CPed::PlacePedOnDryLand, PATCH_JUMP);
+ InjectHook(0x4E2480, &CPed::PedSetQuickDraggedOutCarPositionCB, PATCH_JUMP);
+ InjectHook(0x4E4F30, &CPed::PositionPedOutOfCollision, PATCH_JUMP);
+ InjectHook(0x4D6A00, &CPed::PossiblyFindBetterPosToSeekCar, PATCH_JUMP);
+ InjectHook(0x4D94E0, &CPed::ProcessObjective, PATCH_JUMP);
+ InjectHook(0x4CCEB0, &CPed::SetDirectionToWalkAroundObject, PATCH_JUMP);
ENDPATCHES \ No newline at end of file
diff --git a/src/peds/Ped.h b/src/peds/Ped.h
index a14a8c4b..0b1b80d6 100644
--- a/src/peds/Ped.h
+++ b/src/peds/Ped.h
@@ -14,6 +14,7 @@
#include "EventList.h"
struct CPathNode;
+class CAccident;
struct CPedAudioData
{
@@ -57,6 +58,7 @@ struct FightMove
};
static_assert(sizeof(FightMove) == 0x18, "FightMove: error");
+// TO-DO: This is eFightState on mobile.
enum PedFightMoves
{
FIGHTMOVE_NULL,
@@ -127,7 +129,7 @@ enum eObjective : uint32 {
OBJECTIVE_IDLE,
OBJECTIVE_FLEE_TILL_SAFE,
OBJECTIVE_GUARD_SPOT,
- OBJECTIVE_GUARD_AREA,
+ OBJECTIVE_GUARD_AREA, // not implemented
OBJECTIVE_WAIT_IN_CAR,
OBJECTIVE_WAIT_IN_CAR_THEN_GETOUT,
OBJECTIVE_KILL_CHAR_ON_FOOT,
@@ -139,15 +141,15 @@ enum eObjective : uint32 {
OBJECTIVE_LEAVE_VEHICLE,
OBJECTIVE_ENTER_CAR_AS_PASSENGER,
OBJECTIVE_ENTER_CAR_AS_DRIVER,
- OBJECTIVE_FOLLOW_CAR_IN_CAR,
- OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE,
- OBJECTIVE_DESTROY_OBJ,
+ OBJECTIVE_FOLLOW_CAR_IN_CAR, // seems not implemented so far
+ OBJECTIVE_FIRE_AT_OBJ_FROM_VEHICLE, // not implemented
+ OBJECTIVE_DESTROY_OBJ, // not implemented
OBJECTIVE_DESTROY_CAR,
OBJECTIVE_GOTO_AREA_ANY_MEANS,
OBJECTIVE_GOTO_AREA_ON_FOOT,
OBJECTIVE_RUN_TO_AREA,
- OBJECTIVE_23,
- OBJECTIVE_24,
+ OBJECTIVE_23, // not implemented
+ OBJECTIVE_24, // not implemented
OBJECTIVE_FIGHT_CHAR,
OBJECTIVE_SET_LEADER,
OBJECTIVE_FOLLOW_ROUTE,
@@ -158,7 +160,9 @@ enum eObjective : uint32 {
OBJECTIVE_STEAL_ANY_CAR,
OBJECTIVE_MUG_CHAR,
OBJECTIVE_FLEE_CAR,
- OBJECTIVE_35
+#ifdef VC_PED_PORTS
+ OBJECTIVE_LEAVE_CAR_AND_DIE
+#endif
};
enum {
@@ -169,7 +173,7 @@ enum {
enum PedLineUpPhase {
LINE_UP_TO_CAR_START,
LINE_UP_TO_CAR_END,
- LINE_UP_TO_CAR_2
+ LINE_UP_TO_CAR_2 // Buggy. Used for cops arresting you from passenger door
};
enum PedOnGroundState {
@@ -262,7 +266,7 @@ public:
// cf. https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CPed.h from R*
uint8 bIsStanding : 1;
- uint8 m_ped_flagA2 : 1;
+ uint8 m_ped_flagA2 : 1; // bWasStanding?
uint8 bIsAttacking : 1; // doesn't reset after fist fight
uint8 bIsPointingGunAt : 1;
uint8 bIsLooking : 1;
@@ -277,9 +281,9 @@ public:
uint8 bIsLanding : 1;
uint8 bIsRunning : 1; // on some conditions
uint8 bHitSomethingLastFrame : 1;
- uint8 m_ped_flagB80 : 1; // bIsNearCar? something related with reaction to colliding vehicle
+ uint8 m_ped_flagB80 : 1; // bIsNearCar? it's sure that it's related with cars and used for deciding whether we should move
- uint8 m_ped_flagC1 : 1;
+ uint8 m_ped_flagC1 : 1; // bCanPedEnterSeekedCar?
uint8 bRespondsToThreats : 1;
uint8 bRenderPedInCar : 1;
uint8 bChangedSeat : 1;
@@ -290,15 +294,15 @@ public:
uint8 bHasACamera : 1; // does ped possess a camera to document accidents involves fire/explosion
uint8 m_ped_flagD2 : 1; // set when ped witnessed an event
- uint8 m_ped_flagD4 : 1; // bPedIsBleeding? so far only creates blood pool in hands up state
- uint8 m_ped_flagD8 : 1;
+ uint8 bPedIsBleeding : 1;
+ uint8 bStopAndShoot : 1; // Ped cannot reach target to attack with fist, need to use gun
uint8 bIsPedDieAnimPlaying : 1;
uint8 bUsePedNodeSeek : 1;
- uint8 m_ped_flagD40 : 1; // reset when objective changes
+ uint8 bObjectiveCompleted : 1;
uint8 bScriptObjectiveCompleted : 1;
uint8 bKindaStayInSamePlace : 1;
- uint8 m_ped_flagE2 : 1;
+ uint8 m_ped_flagE2 : 1; // bBeingChasedByPolice?
uint8 bNotAllowedToDuck : 1;
uint8 bCrouchWhenShooting : 1;
uint8 bIsDucking : 1;
@@ -312,33 +316,37 @@ public:
uint8 m_ped_flagF8 : 1;
uint8 bWillBeQuickJacked : 1;
uint8 bCancelEnteringCar : 1; // after door is opened or couldn't be opened due to it's locked
- uint8 m_ped_flagF40 : 1;
+ uint8 bObstacleShowedUpDuringKillObjective : 1;
uint8 bDuckAndCover : 1;
- uint8 m_ped_flagG1 : 1;
+ uint8 bStillOnValidPoly : 1;
uint8 m_ped_flagG2 : 1;
- uint8 m_ped_flagG4 : 1; // bStillOnValidPoly?
+ uint8 m_ped_flagG4 : 1; // bResetWalkAnims?
uint8 bStartWanderPathOnFoot : 1; // exits the car if he's in it, reset after path found
- uint8 m_ped_flagG10 : 1; // bOnBoat? (but not in the sense of driving)
+ uint8 bOnBoat : 1; // not just driver, may be just standing
uint8 bBusJacked : 1;
uint8 bGonnaKillTheCarJacker : 1; // only set when car is jacked from right door
uint8 bFadeOut : 1;
- uint8 bKnockedUpIntoAir : 1; // has ped been knocked up into the air by a car collision
- uint8 m_ped_flagH2 : 1;
+ uint8 m_ped_flagH1 : 1;
+ uint8 bHitSteepSlope : 1; // has ped collided/is standing on a steep slope (surface type)
uint8 m_ped_flagH4 : 1;
uint8 bClearObjective : 1;
- uint8 m_ped_flagH10 : 1;
+ uint8 m_ped_flagH10 : 1; // bTryingToReachDryLand? reset when we landed on something not vehicle and object
uint8 bCollidedWithMyVehicle : 1;
- uint8 m_ped_flagH40 : 1;
+ uint8 bRichFromMugging : 1; // ped has lots of cash from mugging people - will drop money if someone points gun to him
uint8 m_ped_flagH80 : 1;
uint8 bShakeFist : 1; // test shake hand at look entity
uint8 bNoCriticalHits : 1; // if set, limbs won't came off
- uint8 m_ped_flagI4 : 1;
+ uint8 m_ped_flagI4 : 1; // seems like related with cars
uint8 bHasAlreadyBeenRecorded : 1;
uint8 bFallenDown : 1;
+#ifdef VC_PED_PORTS
+ uint8 bKnockedUpIntoAir : 1; // has ped been knocked up into the air by a car collision
+#else
uint8 m_ped_flagI20 : 1;
+#endif
uint8 m_ped_flagI40 : 1;
uint8 m_ped_flagI80 : 1;
@@ -398,7 +406,7 @@ public:
float m_fRotationDest;
float m_headingRate;
uint16 m_vehEnterType; // TODO: this is more like a door, not a type
- uint16 m_walkAroundType;
+ int16 m_walkAroundType;
CEntity *m_pCurrentPhysSurface;
CVector m_vecOffsetFromPhysSurface;
CEntity *m_pCurSurface;
@@ -411,9 +419,9 @@ public:
bool bRunningToPhone;
uint8 field_31D;
int16 m_phoneId;
- uint32 m_lookingForPhone; // unused
+ eCrimeType m_crimeToReportOnPhone;
uint32 m_phoneTalkTimer;
- void *m_lastAccident;
+ CAccident *m_lastAccident;
int32 m_nPedType;
CPedStats *m_pedStats;
float m_fleeFromPosX;
@@ -467,8 +475,8 @@ public:
uint32 m_soundStart;
uint16 m_lastQueuedSound;
uint16 m_queuedSound;
- CVector m_vecSeekPosEx;
- float m_seekExAngle;
+ CVector m_vecSeekPosEx; // used in objectives
+ float m_distanceToCountSeekDoneEx; // used in objectives
static void *operator new(size_t);
static void *operator new(size_t, int);
@@ -526,7 +534,6 @@ public:
void CalculateNewOrientation(void);
float WorkOutHeadingForMovingFirstPerson(float);
void CalculateNewVelocity(void);
- bool CanPedJumpThis(CEntity*);
bool CanSeeEntity(CEntity*, float);
void RestorePreviousObjective(void);
void SetIdle(void);
@@ -646,6 +653,14 @@ public:
void SeekCar(void);
void SeekBoatPosition(void);
bool PositionPedOutOfCollision(void);
+ bool RunToReportCrime(eCrimeType);
+ bool PlacePedOnDryLand(void);
+ bool PossiblyFindBetterPosToSeekCar(CVector*, CVehicle*);
+ void UpdateFromLeader(void);
+ int ScanForThreats(void);
+ void SetEnterCar(CVehicle*, uint32);
+ bool WarpPedToNearEntityOffScreen(CEntity*);
+ void SetExitCar(CVehicle*, uint32);
// Static methods
static CVector GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float offset);
@@ -656,8 +671,6 @@ public:
static void LoadFightData(void);
// Callbacks
- static RwObject *SetPedAtomicVisibilityCB(RwObject *object, void *data);
- static RwFrame *RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data);
static void PedGetupCB(CAnimBlendAssociation *assoc, void *arg);
static void PedStaggerCB(CAnimBlendAssociation *assoc, void *arg);
static void PedEvadeCB(CAnimBlendAssociation *assoc, void *arg);
@@ -716,6 +729,15 @@ public:
void PointGunAt(void);
bool ServiceTalkingWhenDead(void);
void SetPedPositionInTrain(void);
+ void SetShootTimer(uint32);
+ void SetSeekCar(CVehicle*, uint32);
+ void SetSeekBoatPosition(CVehicle*);
+ void SetExitTrain(CVehicle*);
+#ifdef VC_PED_PORTS
+ bool CanPedJumpThis(CEntity*, CVector*);
+#else
+ bool CanPedJumpThis(CEntity*);
+#endif
bool HasWeapon(uint8 weaponType) { return m_weapons[weaponType].m_eWeaponType == weaponType; }
CWeapon &GetWeapon(uint8 weaponType) { return m_weapons[weaponType]; }
@@ -724,10 +746,14 @@ public:
PedState GetPedState(void) { return m_nPedState; }
void SetPedState(PedState state) { m_nPedState = state; }
bool DyingOrDead(void) { return m_nPedState == PED_DIE || m_nPedState == PED_DEAD; }
+ void ReplaceWeaponWhenExitingVehicle(void);
// set by 0482:set_threat_reaction_range_multiplier opcode
static uint16 &nThreatReactionRangeMultiplier;
+ // set by 0481:set_enter_car_range_multiplier opcode
+ static uint16 &nEnterCarRangeMultiplier;
+
static bool &bNastyLimbsCheat;
static bool &bPedCheat2;
static bool &bPedCheat3;
diff --git a/src/peds/PedRoutes.cpp b/src/peds/PedRoutes.cpp
index c572d8be..f1f73988 100644
--- a/src/peds/PedRoutes.cpp
+++ b/src/peds/PedRoutes.cpp
@@ -3,4 +3,5 @@
#include "main.h"
#include "PedRoutes.h"
-WRAPPER int16 CRouteNode::GetRouteThisPointIsOn(int16) { EAXJMP(0x4EE7A0); } \ No newline at end of file
+WRAPPER int16 CRouteNode::GetRouteThisPointIsOn(int16) { EAXJMP(0x4EE7A0); }
+WRAPPER CVector CRouteNode::GetPointPosition(int16) { EAXJMP(0x4EE780); } \ No newline at end of file
diff --git a/src/peds/PedRoutes.h b/src/peds/PedRoutes.h
index 2530ebe6..c9a175a8 100644
--- a/src/peds/PedRoutes.h
+++ b/src/peds/PedRoutes.h
@@ -3,5 +3,6 @@
class CRouteNode
{
public:
- static int16 GetRouteThisPointIsOn(int16 point);
+ static int16 GetRouteThisPointIsOn(int16);
+ static CVector GetPointPosition(int16);
}; \ No newline at end of file
diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp
index ceee0bd2..668a6011 100644
--- a/src/peds/PlayerPed.cpp
+++ b/src/peds/PlayerPed.cpp
@@ -51,7 +51,7 @@ CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1)
field_1413 = 0;
for (int i = 0; i < 6; i++) {
m_vecSafePos[i] = CVector(0.0f, 0.0f, 0.0f);
- field_1488[i] = 0;
+ m_pPedAtSafePos[i] = nil;
}
}
diff --git a/src/peds/PlayerPed.h b/src/peds/PlayerPed.h
index 16fc65ee..136fcc48 100644
--- a/src/peds/PlayerPed.h
+++ b/src/peds/PlayerPed.h
@@ -35,7 +35,7 @@ public:
int8 field_1414;
int8 field_1415;
CVector m_vecSafePos[6]; // safe places from the player, for example behind a tree
- int32 field_1488[6]; // m_pPedAtSafePos?
+ CPed *m_pPedAtSafePos[6];
float m_fWalkAngle;
float m_fFPSMoveHeading;
diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp
index 1a6cfea3..89a85e92 100644
--- a/src/render/Coronas.cpp
+++ b/src/render/Coronas.cpp
@@ -324,7 +324,7 @@ CCoronas::Render(void)
CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z,
spritew * aCoronas[i].size * wscale,
- spriteh * aCoronas[i].size * fogscale * hscale,
+ spriteh * SCREEN_SCALE_AR2(aCoronas[i].size * fogscale * hscale),
CCoronas::aCoronas[i].red / fogscale,
CCoronas::aCoronas[i].green / fogscale,
CCoronas::aCoronas[i].blue / fogscale,
@@ -335,7 +335,7 @@ CCoronas::Render(void)
CSprite::RenderOneXLUSprite_Rotate_Aspect(
spriteCoors.x, spriteCoors.y, spriteCoors.z,
spritew * aCoronas[i].size * fogscale,
- spriteh * aCoronas[i].size * fogscale,
+ spriteh * SCREEN_SCALE_AR2(aCoronas[i].size * fogscale),
CCoronas::aCoronas[i].red / fogscale,
CCoronas::aCoronas[i].green / fogscale,
CCoronas::aCoronas[i].blue / fogscale,
diff --git a/src/render/Font.cpp b/src/render/Font.cpp
index 59023960..54243069 100644
--- a/src/render/Font.cpp
+++ b/src/render/Font.cpp
@@ -134,10 +134,10 @@ CFont::PrintChar(float x, float y, uint16 c)
if(Details.style == 0 || Details.style == 2){
if(Details.dropShadowPosition != 0){
CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
- CRect(x + Details.dropShadowPosition,
- y + Details.dropShadowPosition,
- x + Details.dropShadowPosition + 32.0f * Details.scaleX * 1.0f,
- y + Details.dropShadowPosition + 40.0f * Details.scaleY * 0.5f),
+ CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition),
+ y + SCREEN_SCALE_Y(Details.dropShadowPosition),
+ x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f,
+ y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f),
Details.dropColor,
xoff/16.0f, yoff/12.8f,
(xoff+1.0f)/16.0f - 0.001f, yoff/12.8f,
diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp
index 2dae7551..d98ec1ea 100644
--- a/src/render/Hud.cpp
+++ b/src/render/Hud.cpp
@@ -46,7 +46,7 @@ wchar *CHud::m_Message = (wchar*)0x72E318;
wchar *CHud::m_PagerMessage = (wchar*)0x878840;
bool &CHud::m_Wants_To_Draw_Hud = *(bool*)0x95CD89;
bool &CHud::m_Wants_To_Draw_3dMarkers = *(bool*)0x95CD62;
-wchar(*CHud::m_BigMessage)[128] = (wchar(*)[128])0x664CE0;
+wchar(&CHud::m_BigMessage)[6][128] = *(wchar(*)[6][128])*(uintptr*)0x664CE0;
int16 &CHud::m_ItemToFlash = *(int16*)0x95CC82;
// These aren't really in CHud
@@ -68,53 +68,35 @@ int16 &CHud::PagerTimer = *(int16*)0x95CC3A;
int16 &CHud::PagerOn = *(int16*)0x95CCA0;
CSprite2d *CHud::Sprites = (CSprite2d*)0x95CB9C;
-char *WeaponFilenames[] = {
- "fist",
- "fistm",
- "bat",
- "batm",
- "pistol",
- "pistolm",
- "uzi",
- "uzim",
- "shotgun",
- "shotgunm",
- "ak47",
- "ak47m",
- "m16",
- "m16m",
- "sniper",
- "sniperm",
- "rocket",
- "rocketm",
- "flame",
- "flamem",
- "molotov",
- "molotovm",
- "grenade",
- "grenadem",
- "detonator",
- "detonator_mask",
- "",
- "",
- "",
- "",
- "radardisc",
- "radardiscm",
- "pager",
- "pagerm",
- "",
- "",
- "",
- "",
- "bleeder",
- "",
- "sitesniper",
- "sitesniperm",
- "siteM16",
- "siteM16m",
- "siterocket",
- "siterocketm"
+
+struct
+{
+ const char *name;
+ const char *mask;
+} WeaponFilenames[] = {
+ {"fist", "fistm"},
+ {"bat", "batm"},
+ {"pistol", "pistolm" },
+ {"uzi", "uzim"},
+ {"shotgun", "shotgunm"},
+ {"ak47", "ak47m"},
+ {"m16", "m16m"},
+ {"sniper", "sniperm"},
+ {"rocket", "rocketm"},
+ {"flame", "flamem"},
+ {"molotov", "molotovm"},
+ {"grenade", "grenadem"},
+ {"detonator", "detonator_mask"},
+ {"", ""},
+ {"", ""},
+ {"radardisc", "radardiscm"},
+ {"pager", "pagerm"},
+ {"", ""},
+ {"", ""},
+ {"bleeder", ""},
+ {"sitesniper", "sitesniperm"},
+ {"siteM16", "siteM16m"},
+ {"siterocket", "siterocketm"}
};
RwTexture *&gpSniperSightTex = *(RwTexture**)0x8F5834;
@@ -336,23 +318,6 @@ void CHud::Draw()
AsciiToUnicode(sTemp, sPrint);
- CFont::SetBackgroundOff();
- CFont::SetScale(SCREEN_SCALE_X(0.4f), SCREEN_SCALE_Y(0.6f));
- CFont::SetJustifyOff();
- CFont::SetCentreOn();
- CFont::SetCentreSize(SCREEN_SCALE_X(640.0f));
- CFont::SetPropOn();
- CFont::SetFontStyle(FONT_BANK);
-
- if (!CDarkel::FrenzyOnGoing()) {
- if (WeaponType) {
- if (WeaponType != WEAPONTYPE_BASEBALLBAT) {
- CFont::SetColor(CRGBA(0, 0, 0, 255));
- CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(66.0f), SCREEN_SCALE_Y(73.0f), sPrint);
- }
- }
- }
-
/*
DrawWeaponIcon
*/
@@ -368,6 +333,19 @@ void CHud::Draw()
1.0f,
1.0f);
+ CFont::SetBackgroundOff();
+ CFont::SetScale(SCREEN_SCALE_X(0.4f), SCREEN_SCALE_Y(0.6f));
+ CFont::SetJustifyOff();
+ CFont::SetCentreOn();
+ CFont::SetCentreSize(SCREEN_SCALE_X(640.0f));
+ CFont::SetPropOn();
+ CFont::SetFontStyle(FONT_BANK);
+
+ if (!CDarkel::FrenzyOnGoing() && WeaponType != WEAPONTYPE_UNARMED && WeaponType != WEAPONTYPE_BASEBALLBAT) {
+ CFont::SetColor(CRGBA(0, 0, 0, 255));
+ CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(66.0f), SCREEN_SCALE_Y(73.0f), sPrint);
+ }
+
/*
DrawHealth
*/
@@ -896,15 +874,17 @@ void CHud::Draw()
CFont::SetPropOn();
CFont::SetFontStyle(FONT_BANK);
- if (TheCamera.m_WideScreenOn)
- CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(120.0f));
- else
- CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(280.0f));
+ float offsetX = SCREEN_SCALE_X(40.0f) + SCREEN_SCALE_X(8.0f);
+ float center = SCREEN_SCALE_FROM_RIGHT(50.0f) - SCREEN_SCALE_X(8.0f) - offsetX;
+ CFont::SetCentreSize(center);
- CFont::SetDropShadowPosition(1);
+ const int16 shadow = 1;
+ CFont::SetDropShadowPosition(shadow);
CFont::SetDropColor(CRGBA(0, 0, 0, 255));
CFont::SetColor(CRGBA(235, 235, 235, 255));
- CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_SCALE_FROM_BOTTOM(64.0f), m_Message);
+
+ // I'm not sure shadow substaction was intentional here, might be a leftover if CFont::PrintString was used for a shadow draw call
+ CFont::PrintString(center / 2.0f + offsetX - SCREEN_SCALE_X(shadow), SCREEN_SCALE_Y(4.0f) + SCREEN_SCALE_FROM_BOTTOM(68.0f) - SCREEN_SCALE_Y(shadow), m_Message);
CFont::SetDropShadowPosition(0);
}
@@ -924,11 +904,11 @@ void CHud::Draw()
CFont::SetFontStyle(FONT_HEADING);
if (BigMessageX[0] >= (SCREEN_WIDTH - 20)) {
- BigMessageInUse[0] += (CTimer::GetTimeStepInSeconds() * 120.0f);
+ BigMessageInUse[0] += CTimer::GetTimeStep();
if (BigMessageInUse[0] >= 120.0f) {
BigMessageInUse[0] = 120.0;
- BigMessageAlpha[0] += (CTimer::GetTimeStepInSeconds() * -255.0f);
+ BigMessageAlpha[0] -= (CTimer::GetTimeStepInMilliseconds() * 0.3f);
}
if (BigMessageAlpha[0] <= 0.0f) {
@@ -937,18 +917,22 @@ void CHud::Draw()
}
}
else {
- BigMessageX[0] += (CTimer::GetTimeStepInSeconds() * 255.0f);
- BigMessageAlpha[0] += (CTimer::GetTimeStepInSeconds() * 255.0f);
+ BigMessageX[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
+ BigMessageAlpha[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
if (BigMessageAlpha[0] >= 255.0f)
BigMessageAlpha[0] = 255.0f;
}
CFont::SetColor(CRGBA(0, 0, 0, BigMessageAlpha[0]));
- CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f - 2.0f), m_BigMessage[0]);
+#ifdef FIX_BUGS
+ CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(18.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[0]);
+#else
+ CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[0]);
+#endif
CFont::SetColor(CRGBA(85, 119, 133, BigMessageAlpha[0]));
- CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f), m_BigMessage[0]);
+ CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(18.0f), m_BigMessage[0]);
}
else {
BigMessageAlpha[0] = 0.0f;
@@ -1103,7 +1087,7 @@ void CHud::DrawAfterFade()
DrawBigMessage2
*/
// Oddjob
- if (m_BigMessage[4][0]) {
+ if (m_BigMessage[3][0]) {
CFont::SetJustifyOff();
CFont::SetBackgroundOff();
CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f));
@@ -1113,70 +1097,90 @@ void CHud::DrawAfterFade()
CFont::SetFontStyle(FONT_BANK);
CFont::SetColor(CRGBA(0, 0, 0, 255));
- CFont::PrintString(SCREEN_SCALE_X(2.0f) + (SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[4]);
+ CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[3]);
CFont::SetColor(CRGBA(89, 115, 150, 255));
- CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[4]);
+ CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[3]);
+ }
+
+ if (!m_BigMessage[1][0] && m_BigMessage[4][0]) {
+ CFont::SetJustifyOff();
+ CFont::SetBackgroundOff();
+ CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f));
+ CFont::SetCentreOn();
+ CFont::SetPropOn();
+ CFont::SetCentreSize(SCREEN_SCALE_X(620.0f));
+ CFont::SetColor(CRGBA(0, 0, 0, 255));
+ CFont::SetFontStyle(FONT_BANK);
+
+ CFont::PrintString((SCREEN_WIDTH / 2) - SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) - SCREEN_SCALE_Y(2.0f), m_BigMessage[3]);
+
+ CFont::SetColor(CRGBA(89, 115, 150, 255));
+ CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f), m_BigMessage[3]);
}
// Oddjob result
if (OddJob2OffTimer > 0)
- OddJob2OffTimer = OddJob2OffTimer - CTimer::GetTimeStepInMilliseconds();
+ OddJob2OffTimer -= CTimer::GetTimeStepInMilliseconds();
static float fStep;
- if (!m_BigMessage[1][0] && m_BigMessage[4][0] && m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) {
- switch (OddJob2On) {
- case 0:
- OddJob2On = 1;
- OddJob2XOffset = 380.0f;
- break;
- case 1:
- if (OddJob2XOffset <= 2.0f) {
- OddJob2Timer = 0;
- OddJob2On = 2;
- }
- else {
- fStep = 40.0f;
- if ((OddJob2XOffset * 0.16667f) <= 40.0f)
- fStep = OddJob2XOffset * 0.16667f;
- OddJob2XOffset = OddJob2XOffset - fStep;
- }
- break;
- case 2:
- OddJob2Timer += (20.0f * CTimer::GetTimeStep());
- if (OddJob2Timer > 1500) {
- OddJob2On = 3;
- }
- break;
- case 3:
- fStep = 30.0f;
- if ((OddJob2XOffset * 0.2f) >= 30.0f)
- fStep = OddJob2XOffset * 0.2f;
+ if (m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) {
+ if (OddJob2On <= 3) {
+ switch (OddJob2On) {
+ case 0:
+ OddJob2On = 1;
+ OddJob2XOffset = 380.0f;
+ break;
+ case 1:
+ if (OddJob2XOffset <= 2.0f) {
+ OddJob2Timer = 0;
+ OddJob2On = 2;
+ }
+ else {
+ fStep = 40.0f;
+ if ((OddJob2XOffset / 6.0f) <= 40.0f)
+ fStep = OddJob2XOffset / 6.0f;
+ OddJob2XOffset = OddJob2XOffset - fStep;
+ }
+ break;
+ case 2:
+ OddJob2Timer += (20.0f * CTimer::GetTimeStep());
+ if (OddJob2Timer > 1500) {
+ OddJob2On = 3;
+ }
+ break;
+ case 3:
+ fStep = 30.0f;
+ if ((OddJob2XOffset / 5.0f) >= 30.0f)
+ fStep = OddJob2XOffset / 5.0f;
- OddJob2XOffset = OddJob2XOffset - fStep;
+ OddJob2XOffset = OddJob2XOffset - fStep;
- if (OddJob2XOffset < -380.0f) {
- OddJob2OffTimer = 5000.0f;
- OddJob2On = 0;
+ if (OddJob2XOffset < -380.0f) {
+ OddJob2OffTimer = 5000.0f;
+ OddJob2On = 0;
+ }
+ break;
+ default:
+ break;
}
- break;
- default:
- break;
}
- CFont::SetJustifyOff();
- CFont::SetBackgroundOff();
- CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.2f));
- CFont::SetCentreOn();
- CFont::SetPropOn();
- CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f));
- CFont::SetFontStyle(FONT_BANK);
+ if (!m_BigMessage[1][0]) {
+ CFont::SetJustifyOff();
+ CFont::SetBackgroundOff();
+ CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.2f));
+ CFont::SetCentreOn();
+ CFont::SetPropOn();
+ CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f));
+ CFont::SetColor(CRGBA(0, 0, 0, 255));
+ CFont::SetFontStyle(FONT_BANK);
- CFont::SetColor(CRGBA(0, 0, 0, 255));
- CFont::PrintString(SCREEN_SCALE_X(2.0f) + (SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f + 2.0f), m_BigMessage[5]);
+ CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), SCREEN_HEIGHT / 2 - SCREEN_SCALE_Y(20.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[5]);
- CFont::SetColor(CRGBA(156, 91, 40, 255));
- CFont::PrintString((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(20.0f + 2.0f), m_BigMessage[5]);
+ CFont::SetColor(CRGBA(156, 91, 40, 255));
+ CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - SCREEN_SCALE_Y(20.0f), m_BigMessage[5]);
+ }
}
/*
@@ -1193,15 +1197,15 @@ void CHud::DrawAfterFade()
CFont::SetScale(SCREEN_SCALE_X(1.04f), SCREEN_SCALE_Y(1.6f));
CFont::SetPropOn();
- CFont::SetRightJustifyWrap(-500);
+ CFont::SetRightJustifyWrap(-500.0f);
CFont::SetRightJustifyOn();
CFont::SetFontStyle(FONT_HEADING);
if (BigMessageX[1] >= (SCREEN_WIDTH - 20)) {
- BigMessageInUse[1] += (CTimer::GetTimeStepInSeconds() * 120.0f);
+ BigMessageInUse[1] += CTimer::GetTimeStep();
if (BigMessageInUse[1] >= 120.0f) {
BigMessageInUse[1] = 120.0;
- BigMessageAlpha[1] += (CTimer::GetTimeStepInSeconds() * -255.0f);
+ BigMessageAlpha[1] -= (CTimer::GetTimeStepInMilliseconds() * 0.3f);
}
if (BigMessageAlpha[1] <= 0) {
m_BigMessage[1][0] = 0;
@@ -1209,15 +1213,15 @@ void CHud::DrawAfterFade()
}
}
else {
- BigMessageX[1] += (CTimer::GetTimeStepInSeconds() * 255.0f);
- BigMessageAlpha[1] += (CTimer::GetTimeStepInSeconds() * 255.0f);
+ BigMessageX[1] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
+ BigMessageAlpha[1] += (CTimer::GetTimeStepInMilliseconds() * 0.3f);
if (BigMessageAlpha[1] >= 255.0f)
BigMessageAlpha[1] = 255.0f;
}
CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[1]));
- CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f - 2.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f), m_BigMessage[1]);
+ CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[1]);
CFont::SetColor(CRGBA(220, 172, 2, BigMessageAlpha[1]));
CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f), m_BigMessage[1]);
@@ -1276,9 +1280,8 @@ void CHud::GetRidOfAllHudMessages()
void CHud::Initialise()
{
- debug("Init CHud");
-
- ReInitialise();
+ m_Wants_To_Draw_Hud = true;
+ m_Wants_To_Draw_3dMarkers = true;
int HudTXD = CTxdStore::AddTxdSlot("hud");
CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD");
@@ -1286,12 +1289,31 @@ void CHud::Initialise()
CTxdStore::PopCurrentTxd();
CTxdStore::SetCurrentTxd(HudTXD);
- for (int i = 0; i < ARRAY_SIZE(WeaponFilenames) / 2; i++) {
- Sprites[i].SetTexture(WeaponFilenames[i * 2]);
+ for (int i = 0; i < ARRAY_SIZE(WeaponFilenames); i++) {
+ Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask);
}
- gpSniperSightTex = RwTextureRead("sitesniper", nil);
- gpRocketSightTex = RwTextureRead("siterocket", nil);
+ GetRidOfAllHudMessages();
+
+ if (gpSniperSightTex == nil)
+ gpSniperSightTex = RwTextureRead("sitesniper", nil);
+ if (gpRocketSightTex == nil)
+ gpRocketSightTex = RwTextureRead("siterocket", nil);
+
+ CounterOnLastFrame = 0;
+ m_ItemToFlash = ITEM_NONE;
+ OddJob2Timer = 0;
+ OddJob2OffTimer = 0.0f;
+ OddJob2On = 0;
+ OddJob2XOffset = 0.0f;
+ CounterFlashTimer = 0;
+ TimerOnLastFrame = 0;
+ TimerFlashTimer = 0;
+ SpriteBrightness = 0;
+ PagerOn = 0;
+ PagerTimer = 0;
+ PagerSoundPlayed = 0;
+ PagerXOffset = 150.0f;
CTxdStore::PopCurrentTxd();
}
@@ -1328,7 +1350,7 @@ WRAPPER void CHud::SetBigMessage(wchar *message, int16 style) { EAXJMP(0x50A250)
#else
void CHud::SetBigMessage(wchar *message, int16 style)
{
- int i;
+ int i = 0;
if (style == 5) {
for (i = 0; i < 128; i++) {
@@ -1379,7 +1401,7 @@ WRAPPER void CHud::SetMessage(wchar *message) { EAXJMP(0x50A210); }
#else
void CHud::SetMessage(wchar *message)
{
- int i;
+ int i = 0;
for (i = 0; i < 256; i++) {
if (message[i] == 0)
break;
@@ -1395,7 +1417,7 @@ WRAPPER void CHud::SetPagerMessage(wchar *message) { EAXJMP(0x50A320); }
#else
void CHud::SetPagerMessage(wchar *message)
{
- int i;
+ int i = 0;
for (i = 0; i < 256; i++) {
if (message[i] == 0)
break;
@@ -1428,7 +1450,7 @@ void CHud::Shutdown()
{
debug("Shutdown CHud");
- for (int i = 0; i < ARRAY_SIZE(WeaponFilenames) / 2; ++i) {
+ for (int i = 0; i < ARRAY_SIZE(WeaponFilenames); ++i) {
Sprites[i].Delete();
}
diff --git a/src/render/Hud.h b/src/render/Hud.h
index 1567abdc..d3482ae6 100644
--- a/src/render/Hud.h
+++ b/src/render/Hud.h
@@ -61,7 +61,7 @@ public:
static wchar *m_PagerMessage;
static bool &m_Wants_To_Draw_Hud;
static bool &m_Wants_To_Draw_3dMarkers;
- static wchar(*m_BigMessage)[128];
+ static wchar(&m_BigMessage)[6][128];
static int16 &m_ItemToFlash;
// These aren't really in CHud
diff --git a/src/render/MoneyMessages.cpp b/src/render/MoneyMessages.cpp
new file mode 100644
index 00000000..53d6db58
--- /dev/null
+++ b/src/render/MoneyMessages.cpp
@@ -0,0 +1,86 @@
+#include "common.h"
+#include "patcher.h"
+#include "MoneyMessages.h"
+#include "Timer.h"
+#include "Sprite.h"
+#include "Font.h"
+#include "Text.h"
+
+#define MONEY_MESSAGE_LIFETIME_MS 2000
+
+CMoneyMessage CMoneyMessages::aMoneyMessages[NUMMONEYMESSAGES];
+
+void
+CMoneyMessage::Render()
+{
+ const float MAX_SCALE = 4.0f;
+ uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered;
+ if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0;
+ else {
+ float fLifeTime = (float)nLifeTime / MONEY_MESSAGE_LIFETIME_MS;
+ RwV3d vecOut;
+ float fDistX, fDistY;
+ if (CSprite::CalcScreenCoors(m_vecPosition + CVector(0.0f, 0.0f, fLifeTime), &vecOut, &fDistX, &fDistY, true)) {
+ fDistX *= (0.7 * fLifeTime + 2.0) * m_fSize;
+ fDistY *= (0.7 * fLifeTime + 2.0) * m_fSize;
+ CFont::SetPropOn();
+ CFont::SetBackgroundOff();
+
+ float fScaleY = fDistY / 100.0f;
+ if (fScaleY > MAX_SCALE) fScaleY = MAX_SCALE;
+
+ float fScaleX = fDistX / 100.0f;
+ if (fScaleX > MAX_SCALE) fScaleX = MAX_SCALE;
+
+ CFont::SetScale(fScaleX, fScaleY); // maybe use SCREEN_SCALE_X and SCREEN_SCALE_Y here?
+ CFont::SetCentreOn();
+ CFont::SetCentreSize(SCREEN_WIDTH);
+ CFont::SetJustifyOff();
+ CFont::SetColor(CRGBA(m_Colour.r, m_Colour.g, m_Colour.b, (255.0f - 255.0f * fLifeTime) * m_fOpacity));
+ CFont::SetBackGroundOnlyTextOff();
+ CFont::SetFontStyle(FONT_BANK);
+ CFont::PrintString(vecOut.x, vecOut.y, m_aText);
+ }
+ }
+}
+
+void
+CMoneyMessages::Init()
+{
+ for (int32 i = 0; i < NUMMONEYMESSAGES; i++)
+ aMoneyMessages[i].m_nTimeRegistered = 0;
+}
+
+void
+CMoneyMessages::Render()
+{
+ for (int32 i = 0; i < NUMMONEYMESSAGES; i++) {
+ if (aMoneyMessages[i].m_nTimeRegistered != 0)
+ aMoneyMessages[i].Render();
+ }
+}
+
+void
+CMoneyMessages::RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity)
+{
+ uint32 nIndex = 0;
+ while (aMoneyMessages[nIndex].m_nTimeRegistered != 0) {
+ if (++nIndex >= NUMMONEYMESSAGES) return;
+ }
+
+ // Add data of this money message to the array
+ AsciiToUnicode(pText, aMoneyMessages[nIndex].m_aText);
+
+ aMoneyMessages[nIndex].m_nTimeRegistered = CTimer::GetTimeInMilliseconds();
+ aMoneyMessages[nIndex].m_vecPosition = vecPos;
+ aMoneyMessages[nIndex].m_Colour.red = bRed;
+ aMoneyMessages[nIndex].m_Colour.green = bGreen;
+ aMoneyMessages[nIndex].m_Colour.blue = bBlue;
+ aMoneyMessages[nIndex].m_fSize = fSize;
+ aMoneyMessages[nIndex].m_fOpacity = fOpacity;
+}
+
+STARTPATCHES
+ InjectHook(0x51AF70, CMoneyMessages::Init, PATCH_JUMP);
+ InjectHook(0x51B030, CMoneyMessages::Render, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/render/MoneyMessages.h b/src/render/MoneyMessages.h
new file mode 100644
index 00000000..f0a48a84
--- /dev/null
+++ b/src/render/MoneyMessages.h
@@ -0,0 +1,24 @@
+#pragma once
+
+class CMoneyMessage
+{
+ friend class CMoneyMessages;
+
+ uint32 m_nTimeRegistered;
+ CVector m_vecPosition;
+ wchar m_aText[16];
+ CRGBA m_Colour;
+ float m_fSize;
+ float m_fOpacity;
+public:
+ void Render();
+};
+
+class CMoneyMessages
+{
+ static CMoneyMessage aMoneyMessages[NUMMONEYMESSAGES];
+public:
+ static void Init();
+ static void Render();
+ static void RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity);
+}; \ No newline at end of file
diff --git a/src/render/Sprite2d.cpp b/src/render/Sprite2d.cpp
index 4ed27fa1..c4dbcdaa 100644
--- a/src/render/Sprite2d.cpp
+++ b/src/render/Sprite2d.cpp
@@ -457,6 +457,20 @@ CSprite2d::DrawRectXLU(const CRect &r, const CRGBA &c0, const CRGBA &c1, const C
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
}
+void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color)
+{
+ SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, color, color, color, color);
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0);
+ RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEFLAT);
+ RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(color.a != 255));
+ RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4);
+ RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);
+ RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD);
+}
+
STARTPATCHES
#define C4 const CRGBA&, const CRGBA&, const CRGBA&, const CRGBA&
#define F8 float, float, float, float, float, float, float, float
diff --git a/src/render/Sprite2d.h b/src/render/Sprite2d.h
index e0f19ef1..268c7d2b 100644
--- a/src/render/Sprite2d.h
+++ b/src/render/Sprite2d.h
@@ -47,5 +47,7 @@ public:
static void DrawRect(const CRect &r, const CRGBA &col);
static void DrawRectXLU(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3);
+ static void Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color);
+
static RwIm2DVertex* GetVertices() { return maVertices; };
};