From 0f9178568b3470d35ffc1d5e21a230d8cc11eef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 16 Sep 2019 20:32:58 +0300 Subject: [PATCH 01/32] Peds, a fix and a tad of VC --- src/control/CarCtrl.cpp | 7 +- src/control/Garages.cpp | 3 +- src/control/Garages.h | 3 +- src/core/General.h | 9 +- src/core/World.h | 3 +- src/peds/CivilianPed.cpp | 26 +- src/peds/CivilianPed.h | 1 - src/peds/Ped.cpp | 885 +++++++++++++++++++++++++++++++++++---- src/peds/Ped.h | 13 +- 9 files changed, 827 insertions(+), 123 deletions(-) diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index cae010d2..0be8a0a0 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; } 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/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/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/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..50385dc1 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -40,6 +40,8 @@ #include "CopPed.h" #include "Script.h" #include "CarCtrl.h" +#include "Garages.h" +#include "WaterLevel.h" WRAPPER void CPed::SpawnFlyingComponent(int, int8) { EAXJMP(0x4EB060); } WRAPPER void CPed::SetPedPositionInCar(void) { EAXJMP(0x4D4970); } @@ -49,7 +51,6 @@ WRAPPER int32 CPed::ProcessEntityCollision(CEntity*, CColPoint*) { EAXJMP(0x4CBB 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); } @@ -60,11 +61,12 @@ 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); } +#define VC_PED_PORTS + CPed *gapTempPedList[50]; uint16 gnNumTempPedList; @@ -86,11 +88,11 @@ uint16 &CPed::nThreatReactionRangeMultiplier = *(uint16*)0x5F8C98; 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); } @@ -298,6 +300,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, "Will stop when %.2f left to target", m_distanceToCountSeekDone); + AsciiToUnicode(gString, gUString); + CFont::PrintString(screenCoords.x, screenCoords.y + 4 * lineHeight, gUString); + } DefinedState(); } } @@ -513,7 +520,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) bClearObjective = false; m_ped_flagH10 = false; bCollidedWithMyVehicle = false; - m_ped_flagH40 = false; + bRichFromMugging = false; m_ped_flagH80 = false; bShakeFist = false; @@ -537,8 +544,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 +554,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 +794,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); } @@ -1474,7 +1479,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) { @@ -1512,15 +1516,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->GiveWeaponBackAfterExitingCar(); + ped->m_nStoredMoveState = PEDMOVE_NONE; ped->m_ped_flagI4 = false; } @@ -1849,10 +1846,7 @@ 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)); @@ -2023,7 +2017,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 +2177,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 @@ -2317,8 +2306,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,17 +2315,27 @@ CPed::CanPedDriveOff(void) return true; } - -// TODO: Make this function actually work. bool CPed::CanPedJumpThis(CEntity *unused) { +#ifndef VC_PED_PORTS CVector2D forward(-Sin(m_fRotationCur), Cos(m_fRotationCur)); CVector pos = GetPosition(); CVector forwardPos( forward.x + pos.x, forward.y + pos.y, pos.z); +#else + if (m_nSurfaceTouched == SURFACE_PUDDLE) + return true; + + // VC makes some other calculations if the function called with CVector. + + CVector pos = GetPosition(); + pos.z -= 0.15f; + + CVector forwardPos = pos + GetForward(); +#endif return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); } @@ -2799,15 +2798,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); - } + GiveWeaponBackAfterExitingCar(); + if (DyingOrDead()) { animAssoc = m_pVehicleAnim; if (animAssoc) { @@ -4382,8 +4374,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 *thereIsSomethingBetween = CWorld::TestSphereAgainstWorld(aimPos, 0.2f, nil, true, false, false, true, false, false); + if (thereIsSomethingBetween) return; m_pLookTarget = victim; @@ -4787,7 +4779,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; @@ -5175,7 +5167,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())) { @@ -5382,6 +5374,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 +5468,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(); @@ -5955,9 +5946,7 @@ CPed::LineUpPedWithTrain(void) } GetPosition() = lineUpPos; -// CVector pedPos = GetPosition(); - GetMatrix().SetRotate(0.0f, 0.0f, m_fRotationCur); - GetPosition() += lineUpPos; + SetHeading(m_fRotationCur); } void @@ -7966,15 +7955,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; } @@ -8170,6 +8159,10 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) bKnockedUpIntoAir = 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); @@ -8200,6 +8193,9 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) } 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); } @@ -9097,12 +9093,179 @@ 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()) { + /* VC specific + if (adjustedImpulse > 20.0f) + adjustedImpulse = 20.0f; + + if (adjustedImpulse > 5.0f) { + if (adjustedImpulse <= 13.0f) + playerSufferSound = true; + else + Say(104); + } + */ + 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); + + // Not sure about this one + float minNeededTurnTLVC = 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 (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 + bPushedAlongByCar = true; + */ + } + /* VC specific + if (m_fHealth < oldHealth && playerSufferSound) + Say(105); + */ +#else if (collidingVehSpeedSqr <= 1.0f / 400.0f) { if (!IsPedInControl() || IsPlayer() @@ -9134,9 +9297,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 +9316,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; @@ -9231,6 +9393,7 @@ CPed::ProcessControl(void) KillPedWithCar(collidingVeh, m_fDamageImpulse); } } +#endif break; } case ENTITY_TYPE_PED: @@ -9265,7 +9428,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 +9444,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 { @@ -9332,19 +9504,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 +9544,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; @@ -9373,9 +9560,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); } CAnimBlendAssociation *jumpAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_JUMP_GLIDE); @@ -9434,8 +9619,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(); @@ -10381,11 +10589,13 @@ CPed::PedAnimStepOutCarCB(CAnimBlendAssociation* animAssoc, void* arg) 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: @@ -10860,10 +11070,520 @@ 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->IsCar()) + ped->ApplyMoveSpeed(); + + if (ped->m_objective == OBJECTIVE_LEAVE_VEHICLE) + ped->RestorePreviousObjective(); + + 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)); + } + } + 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->GiveWeaponBackAfterExitingCar(); + + ped->m_ped_flagG10 = 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); + } +} + +inline void +CPed::GiveWeaponBackAfterExitingCar(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; +} class CPed_ : public CPed { @@ -11054,4 +11774,11 @@ 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); ENDPATCHES \ No newline at end of file diff --git a/src/peds/Ped.h b/src/peds/Ped.h index a14a8c4b..177f934d 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, @@ -169,7 +171,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 { @@ -330,7 +332,7 @@ public: uint8 bClearObjective : 1; uint8 m_ped_flagH10 : 1; 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 @@ -411,9 +413,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; @@ -646,6 +648,8 @@ public: void SeekCar(void); void SeekBoatPosition(void); bool PositionPedOutOfCollision(void); + bool RunToReportCrime(eCrimeType); + bool PlacePedOnDryLand(void); // Static methods static CVector GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float offset); @@ -724,6 +728,7 @@ 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 GiveWeaponBackAfterExitingCar(void); // set by 0482:set_threat_reaction_range_multiplier opcode static uint16 &nThreatReactionRangeMultiplier; From 3cb0a62ee6ed473765bab7655a0a6820913e0128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 20 Sep 2019 22:40:33 +0300 Subject: [PATCH 02/32] Peds --- src/animation/AnimBlendAssociation.h | 5 +- src/peds/Ped.cpp | 327 ++++++++++++++++++++++++--- src/peds/Ped.h | 3 +- 3 files changed, 301 insertions(+), 34 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/peds/Ped.cpp b/src/peds/Ped.cpp index 50385dc1..d4452006 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -46,7 +46,6 @@ 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); } @@ -63,7 +62,6 @@ WRAPPER void CPed::WanderRange(void) { EAXJMP(0x4D26C0); } WRAPPER void CPed::WanderPath(void) { EAXJMP(0x4D28D0); } WRAPPER void CPed::SeekCar(void) { EAXJMP(0x4D3F90); } WRAPPER void CPed::SeekBoatPosition(void) { EAXJMP(0x4E4C70); } -WRAPPER bool CPed::PositionPedOutOfCollision(void) { EAXJMP(0x4E4F30); } #define VC_PED_PORTS @@ -1253,6 +1251,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; @@ -1279,6 +1290,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(); @@ -1491,19 +1508,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(); @@ -1516,7 +1534,7 @@ CPed::PedSetDraggedOutCarCB(CAnimBlendAssociation *dragAssoc, void *arg) CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_GETUP1, 1000.0f); } - ped->GiveWeaponBackAfterExitingCar(); + ped->ReplaceWeaponWhenExitingVehicle(); ped->m_nStoredMoveState = PEDMOVE_NONE; ped->m_ped_flagI4 = false; @@ -2264,8 +2282,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; @@ -2329,7 +2355,7 @@ CPed::CanPedJumpThis(CEntity *unused) if (m_nSurfaceTouched == SURFACE_PUDDLE) return true; - // VC makes some other calculations if the function called with CVector. + // VC makes some other calculations if there is a CVector passed with function, which isn't possible here. CVector pos = GetPosition(); pos.z -= 0.15f; @@ -2798,7 +2824,7 @@ CPed::QuitEnteringCar(void) bUsesCollision = true; - GiveWeaponBackAfterExitingCar(); + ReplaceWeaponWhenExitingVehicle(); if (DyingOrDead()) { animAssoc = m_pVehicleAnim; @@ -4374,8 +4400,8 @@ CPed::SetAttack(CEntity *victim) if (curWeapon->m_bCanAim) { CVector aimPos = GetRight() * 0.1f + GetForward() * 0.2f + GetPosition(); - CEntity *thereIsSomethingBetween = CWorld::TestSphereAgainstWorld(aimPos, 0.2f, nil, true, false, false, true, false, false); - if (thereIsSomethingBetween) + CEntity *obstacle = CWorld::TestSphereAgainstWorld(aimPos, 0.2f, nil, true, false, false, true, false, false); + if (obstacle) return; m_pLookTarget = victim; @@ -5523,7 +5549,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; @@ -6483,15 +6513,15 @@ 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; CAnimBlendAssociation *handsCoverAssoc = CAnimManager::BlendAnimation(ped->GetClump(), ASSOCGRP_STD, ANIM_HANDSCOWER, 8.0f); handsCoverAssoc->flags &= ~ASSOC_FADEOUTWHENDONE; @@ -6875,14 +6905,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; @@ -8182,13 +8212,13 @@ 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) { + if (car->m_modelIndex != MI_TRAIN && !bHasHitWall) { m_vecMoveSpeed = car->m_vecMoveSpeed * 0.75f; } m_vecMoveSpeed.z = 0.0f; @@ -8790,7 +8820,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) { @@ -8847,6 +8881,14 @@ CPed::ProcessControl(void) } if (ServiceTalkingWhenDead()) ServiceTalking(); + +#ifdef VC_PED_PORTS + if (bIsInWater) { + bIsStanding = false; + m_ped_flagA2 = false; + CPhysical::ProcessControl(); + } +#endif return; } @@ -8872,7 +8914,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) @@ -8891,8 +8937,11 @@ CPed::ProcessControl(void) } */ +#ifndef VC_PED_PORTS } else { - +#else + } else if (collidingEnt) { +#endif switch (collidingEnt->m_type) { case ENTITY_TYPE_BUILDING: @@ -11379,7 +11428,7 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (ped->IsPlayer()) AudioManager.PlayerJustLeftCar(); - ped->GiveWeaponBackAfterExitingCar(); + ped->ReplaceWeaponWhenExitingVehicle(); ped->m_ped_flagG10 = false; if (ped->bBusJacked) { @@ -11400,8 +11449,9 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) } } +// It was inlined in III but not in VC. inline void -CPed::GiveWeaponBackAfterExitingCar(void) +CPed::ReplaceWeaponWhenExitingVehicle(void) { eWeaponType weaponType = GetWeapon()->m_eWeaponType; @@ -11585,6 +11635,217 @@ CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *animAssoc, void 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(); + } +} + class CPed_ : public CPed { public: @@ -11597,6 +11858,7 @@ 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(); } }; STARTPATCHES @@ -11608,6 +11870,7 @@ 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(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP); InjectHook(0x4C6AA0, &CPed::AimGun, PATCH_JUMP); @@ -11781,4 +12044,6 @@ STARTPATCHES 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); ENDPATCHES \ No newline at end of file diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 177f934d..30dceb51 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -650,6 +650,7 @@ public: bool PositionPedOutOfCollision(void); bool RunToReportCrime(eCrimeType); bool PlacePedOnDryLand(void); + bool PossiblyFindBetterPosToSeekCar(CVector*, CVehicle*); // Static methods static CVector GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float offset); @@ -728,7 +729,7 @@ 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 GiveWeaponBackAfterExitingCar(void); + void ReplaceWeaponWhenExitingVehicle(void); // set by 0482:set_threat_reaction_range_multiplier opcode static uint16 &nThreatReactionRangeMultiplier; From 0c385195d8ac10ac677d1b470af7845615ce742a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 27 Sep 2019 00:01:50 +0300 Subject: [PATCH 03/32] Peds, ProcessObjective and fixes --- src/control/CarAI.cpp | 1 + src/control/CarAI.h | 1 + src/core/config.h | 3 +- src/peds/Ped.cpp | 1620 ++++++++++++++++++++++++++++++++++++++-- src/peds/Ped.h | 32 +- src/peds/PedRoutes.cpp | 3 +- src/peds/PedRoutes.h | 3 +- 7 files changed, 1593 insertions(+), 70 deletions(-) diff --git a/src/control/CarAI.cpp b/src/control/CarAI.cpp index 097d69c6..45edb555 100644 --- a/src/control/CarAI.cpp +++ b/src/control/CarAI.cpp @@ -14,6 +14,7 @@ WRAPPER void CCarAI::AddPoliceOccupants(CVehicle*) { EAXJMP(0x415C60); } WRAPPER void CCarAI::AddAmbulanceOccupants(CVehicle*) { EAXJMP(0x415CE0); } WRAPPER void CCarAI::AddFiretruckOccupants(CVehicle*) { EAXJMP(0x415D00); } WRAPPER void CCarAI::TellOccupantsToLeaveCar(CVehicle*) { EAXJMP(0x415D20); } +WRAPPER float CCarAI::GetCarToGoToCoors(CVehicle*, CVector*) { EAXJMP(0x415B10); } void CCarAI::CarHasReasonToStop(CVehicle* pVehicle) { diff --git a/src/control/CarAI.h b/src/control/CarAI.h index 03bcd260..21294be3 100644 --- a/src/control/CarAI.h +++ b/src/control/CarAI.h @@ -16,4 +16,5 @@ public: static void AddFiretruckOccupants(CVehicle*); static void CarHasReasonToStop(CVehicle*); static void TellOccupantsToLeaveCar(CVehicle*); + static float GetCarToGoToCoors(CVehicle*, CVector*); }; diff --git a/src/core/config.h b/src/core/config.h index 81e2f2fb..161cf898 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -137,5 +137,6 @@ enum Config { #define USE_DEBUG_SCRIPT_LOADER #define EXPLODING_AIRTRAIN // can blow up jumbo jet with rocket launcher #define ANIMATE_PED_COL_MODEL -#define CANCELLABLE_CAR_ENTER //#define REMOVE_TREADABLE_PATHFIND +#define CANCELLABLE_CAR_ENTER +#define VC_PED_PORTS diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index d4452006..94b45cd6 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -42,6 +42,8 @@ #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); } @@ -54,7 +56,6 @@ 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); } @@ -62,8 +63,11 @@ WRAPPER void CPed::WanderRange(void) { EAXJMP(0x4D26C0); } WRAPPER void CPed::WanderPath(void) { EAXJMP(0x4D28D0); } WRAPPER void CPed::SeekCar(void) { EAXJMP(0x4D3F90); } WRAPPER void CPed::SeekBoatPosition(void) { EAXJMP(0x4E4C70); } - -#define VC_PED_PORTS +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); } CPed *gapTempPedList[50]; uint16 gnNumTempPedList; @@ -82,6 +86,7 @@ uint16 nPlayerInComboMove; FightMove (&tFightMoves)[24] = * (FightMove(*)[24]) * (uintptr*)0x5F9844; uint16 &CPed::nThreatReactionRangeMultiplier = *(uint16*)0x5F8C98; +uint16 &CPed::nEnterCarRangeMultiplier = *(uint16*)0x5F8C94; CVector vecPedCarDoorAnimOffset; CVector vecPedCarDoorLoAnimOffset; @@ -97,7 +102,7 @@ void *CPed::operator new(size_t sz, int handle) { return CPools::GetPedPool()->N void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } void CPed::operator delete(void *p, int handle) { CPools::GetPedPool()->Delete((CPed*)p); } -static char ObjectiveText[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", @@ -299,7 +307,7 @@ CPed::DebugRenderOnePedText(void) 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, "Will stop when %.2f left to target", m_distanceToCountSeekDone); + sprintf(gString, "Safe distance to target: %.2f", m_distanceToCountSeekDone); AsciiToUnicode(gString, gUString); CFont::PrintString(screenCoords.x, screenCoords.y + 4 * lineHeight, gUString); } @@ -419,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; @@ -1477,6 +1485,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 @@ -1715,6 +1730,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; @@ -1723,23 +1743,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_LHS: - case ANIM_CAR_GETIN_LOW_LHS: 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_LOW_RHS: case ANIM_DRIVE_BOAT: seatPosMult = m_pVehicleAnim->GetTimeLeft() / m_pVehicleAnim->hierarchy->totalLength; @@ -1804,33 +1843,48 @@ 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) { +#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); - 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); + // 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 } } } @@ -1868,6 +1922,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) } 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; } @@ -2401,6 +2456,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; } @@ -2477,7 +2535,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) { @@ -2531,6 +2593,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: @@ -2550,7 +2615,11 @@ 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; } @@ -2598,6 +2667,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); @@ -2667,8 +2739,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; @@ -2855,6 +2933,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) @@ -3727,6 +3820,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; } @@ -3741,6 +3879,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 { @@ -3893,9 +4033,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); @@ -4934,7 +5081,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); @@ -4953,7 +5100,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; @@ -4972,14 +5119,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: @@ -4987,7 +5134,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(); @@ -5000,7 +5147,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; @@ -5016,7 +5163,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: @@ -5032,7 +5179,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); @@ -5042,7 +5189,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; @@ -5658,21 +5805,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 @@ -6523,7 +6671,11 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg) 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; @@ -6542,12 +6694,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); @@ -6557,6 +6717,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; @@ -6650,7 +6816,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); @@ -6807,7 +6973,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) { @@ -6821,6 +6989,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); @@ -6867,6 +7041,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: @@ -7095,7 +7282,7 @@ CPed::Flee(void) if (dirDiff > 2 && dirDiff < 6) { realLastNode = nil; m_pLastPathNode = m_pNextPathNode; - m_pNextPathNode = 0; + m_pNextPathNode = nil; } } @@ -8230,7 +8417,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) 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; @@ -10115,7 +10302,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; @@ -10348,7 +10539,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); @@ -10632,6 +10827,14 @@ 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); @@ -10706,6 +10909,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); @@ -11310,11 +11518,17 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) ped->m_actionX = 0.0f; ped->m_actionY = 0.0f; ped->m_ped_flagI4 = false; - if (veh && veh->IsCar()) + 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)) { @@ -11373,6 +11587,12 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) 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; @@ -11846,6 +12066,1289 @@ CPed::Render(void) } } +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(); + m_ped_flagD40 = 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(); + m_ped_flagD40 = 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) { + m_ped_flagD40 = 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 && !m_ped_flagD8 && 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 { + m_ped_flagD8 = true; + } + SetMoveState(PEDMOVE_STILL); + SetMoveAnim(); + break; + } + m_ped_flagD8 = 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)); + m_ped_flagF40 = 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); + m_ped_flagF40 = false; + + } else if (foundEnt) { + if (foundEnt->IsPed()) { + SetAttackTimer(CGeneral::GetRandomNumberInRange(500.0f, 1000.0f)); + m_ped_flagF40 = false; + } else { + if (foundEnt->IsObject()) { + SetAttackTimer(CGeneral::GetRandomNumberInRange(200.0f, 400.0f)); + m_ped_flagF40 = true; + } else if (foundEnt->IsVehicle()) { + SetAttackTimer(CGeneral::GetRandomNumberInRange(400.0f, 600.0f)); + m_ped_flagF40 = true; + } else { + SetAttackTimer(CGeneral::GetRandomNumberInRange(700.0f, 1200.0f)); + m_ped_flagF40 = true; + } + } + + m_fleeFrom = foundEnt; + m_fleeFrom->RegisterReference((CEntity**) &m_fleeFrom); + SetPointGunAt(m_pedInObjective); + } + } + } else { + if (!m_pedInObjective->m_pCurrentPhysSurface) + m_ped_flagD8 = 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 (m_ped_flagF40) { + 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 + && !m_ped_flagD8 && !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) { + m_ped_flagD40 = 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(); + m_ped_flagD40 = 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()) { + m_ped_flagD40 = 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 (m_ped_flagD40 + || 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(); + } +} + class CPed_ : public CPed { public: @@ -12046,4 +13549,5 @@ STARTPATCHES InjectHook(0x4E2480, &CPed::PedSetQuickDraggedOutCarPositionCB, PATCH_JUMP); InjectHook(0x4E4F30, &CPed::PositionPedOutOfCollision, PATCH_JUMP); InjectHook(0x4D6A00, &CPed::PossiblyFindBetterPosToSeekCar, PATCH_JUMP); + InjectHook(0x4D94E0, &CPed::ProcessObjective, PATCH_JUMP); ENDPATCHES \ No newline at end of file diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 30dceb51..29916bf4 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -129,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, @@ -141,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, @@ -160,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 { @@ -469,8 +471,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); @@ -651,6 +653,11 @@ public: 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); @@ -721,6 +728,10 @@ public: void PointGunAt(void); bool ServiceTalkingWhenDead(void); void SetPedPositionInTrain(void); + void SetShootTimer(uint32); + void SetSeekCar(CVehicle*, uint32); + void SetSeekBoatPosition(CVehicle*); + void SetExitTrain(CVehicle*); bool HasWeapon(uint8 weaponType) { return m_weapons[weaponType].m_eWeaponType == weaponType; } CWeapon &GetWeapon(uint8 weaponType) { return m_weapons[weaponType]; } @@ -734,6 +745,9 @@ public: // 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 From 6362ceeff305b47063622b2ce19152b699963a66 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Sep 2019 17:03:00 +0300 Subject: [PATCH 04/32] Full CCutsceneMgr --- src/core/Camera.cpp | 6 + src/core/Camera.h | 11 + src/core/CutsceneMgr.cpp | 419 +++++++++++++++++++++++++++++++++++++ src/core/CutsceneMgr.h | 27 +++ src/core/Pad.h | 1 + src/core/TempColModels.cpp | 2 +- src/core/TempColModels.h | 2 +- 7 files changed, 466 insertions(+), 2 deletions(-) diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index cb16c3ad..93680dc1 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -30,6 +30,12 @@ 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::SetCamCutSceneOffSet(const CVector&) { EAXJMP(0x46FC30); }; +WRAPPER void CCamera::TakeControlWithSpline(short) { EAXJMP(0x471620); }; +WRAPPER void CCamera::RestoreWithJumpCut(void) { EAXJMP(0x46FAE0); }; bool CCamera::GetFading() diff --git a/src/core/Camera.h b/src/core/Camera.h index 1f38963b..de725b19 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -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 ¢er, const CMatrix *mat); bool IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat); bool IsSphereVisible(const CVector ¢er, float radius); @@ -480,6 +481,16 @@ 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 SetWideScreenOn(void) { m_WideScreenOn = true; } + void SetWideScreenOff(void) { m_WideScreenOn = false; } + void RestoreWithJumpCut(void); + void dtor(void) { this->CCamera::~CCamera(); } }; static_assert(offsetof(CCamera, m_WideScreenOn) == 0x70, "CCamera: error"); diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp index a54e8ff6..40ae0d2e 100644 --- a/src/core/CutsceneMgr.cpp +++ b/src/core/CutsceneMgr.cpp @@ -1,8 +1,427 @@ #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)[8] = *(char(*)[8]) *(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(512); + ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR"); +} + +void +CCutsceneMgr::Shutdown(void) +{ + if (ms_pCutsceneDir) + 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[16]; + + sprintf(szAnim, "%s_%s", ms_cutsceneName, animName); + pCutsceneHead->PlayAnimation(szAnim); +} + +void +CCutsceneMgr::FinishCutscene() +{ + CCutsceneMgr::ms_cutsceneTimer = TheCamera.GetCutSceneFinishTime() * 0.001; + 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) { + 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(); + if (ms_pCutsceneObjects[ms_numCutsceneObjs]) + 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) { + ms_cutsceneTimer += CTimer::GetTimeStepNonClipped() * 0.02; + 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() { return TheCamera.GetPositionAlongSpline() == 1.0; } + +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..4f62d7c8 100644 --- a/src/core/CutsceneMgr.h +++ b/src/core/CutsceneMgr.h @@ -2,6 +2,8 @@ #include "CutsceneObject.h" class CDirectory; +class CAnimBlendAssocGroup; +class CCutsceneHead; class CCutsceneMgr { @@ -9,10 +11,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)[8]; + 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() { 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/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/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; From 45ead4d0bf00aea9c94f8606d2c49736309621b3 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Sep 2019 17:31:14 +0300 Subject: [PATCH 05/32] Refactoring --- src/core/CutsceneMgr.cpp | 86 ++++++++++++++++++++-------------------- src/core/CutsceneMgr.h | 2 +- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp index 40ae0d2e..b3737c4d 100644 --- a/src/core/CutsceneMgr.cpp +++ b/src/core/CutsceneMgr.cpp @@ -329,41 +329,41 @@ CCutsceneMgr::CreateCutsceneObject(int modelId) void CCutsceneMgr::DeleteCutsceneData(void) { - if (ms_loaded) { - ms_cutsceneProcessing = false; - ms_useLodMultiplier = false; + if (!ms_loaded) return; - for (--ms_numCutsceneObjs; ms_numCutsceneObjs >= 0; ms_numCutsceneObjs--) { - CWorld::Remove(ms_pCutsceneObjects[ms_numCutsceneObjs]); - ms_pCutsceneObjects[ms_numCutsceneObjs]->DeleteRwObject(); - if (ms_pCutsceneObjects[ms_numCutsceneObjs]) - delete ms_pCutsceneObjects[ms_numCutsceneObjs]; - } - ms_numCutsceneObjs = 0; + ms_cutsceneProcessing = false; + ms_useLodMultiplier = false; - 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(); + for (--ms_numCutsceneObjs; ms_numCutsceneObjs >= 0; ms_numCutsceneObjs--) { + CWorld::Remove(ms_pCutsceneObjects[ms_numCutsceneObjs]); + ms_pCutsceneObjects[ms_numCutsceneObjs]->DeleteRwObject(); + if (ms_pCutsceneObjects[ms_numCutsceneObjs]) + 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 @@ -395,20 +395,20 @@ CCutsceneMgr::Update(void) break; } - if (ms_running) { - ms_cutsceneTimer += CTimer::GetTimeStepNonClipped() * 0.02; - 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(); - } + if (!ms_running) return; + + ms_cutsceneTimer += CTimer::GetTimeStepNonClipped() * 0.02; + 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() { return TheCamera.GetPositionAlongSpline() == 1.0; } +bool CCutsceneMgr::HasCutsceneFinished(void) { return TheCamera.GetPositionAlongSpline() == 1.0; } STARTPATCHES InjectHook(0x4045D0, &CCutsceneMgr::Initialise, PATCH_JUMP); diff --git a/src/core/CutsceneMgr.h b/src/core/CutsceneMgr.h index 4f62d7c8..69ce58a6 100644 --- a/src/core/CutsceneMgr.h +++ b/src/core/CutsceneMgr.h @@ -27,7 +27,7 @@ public: 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() { return 1000.0f * ms_cutsceneTimer; } + static int GetCutsceneTimeInMilleseconds(void) { return 1000.0f * ms_cutsceneTimer; } static char *GetCutsceneName(void) { return ms_cutsceneName; } static bool HasCutsceneFinished(void); From ef65ad81ceda9ae04d4ddfd1e79fe5377ae7d07f Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Sep 2019 18:01:05 +0300 Subject: [PATCH 06/32] Added f for floats, removed checks for delete --- src/core/CutsceneMgr.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp index b3737c4d..ccb0bf64 100644 --- a/src/core/CutsceneMgr.cpp +++ b/src/core/CutsceneMgr.cpp @@ -148,8 +148,7 @@ CCutsceneMgr::Initialise(void) void CCutsceneMgr::Shutdown(void) { - if (ms_pCutsceneDir) - delete ms_pCutsceneDir; + delete ms_pCutsceneDir; } void @@ -234,7 +233,7 @@ CCutsceneMgr::SetHeadAnim(const char *animName, CObject *pObject) void CCutsceneMgr::FinishCutscene() { - CCutsceneMgr::ms_cutsceneTimer = TheCamera.GetCutSceneFinishTime() * 0.001; + CCutsceneMgr::ms_cutsceneTimer = TheCamera.GetCutSceneFinishTime() * 0.001f; TheCamera.FinishCutscene(); FindPlayerPed()->bIsVisible = true; @@ -337,8 +336,7 @@ CCutsceneMgr::DeleteCutsceneData(void) for (--ms_numCutsceneObjs; ms_numCutsceneObjs >= 0; ms_numCutsceneObjs--) { CWorld::Remove(ms_pCutsceneObjects[ms_numCutsceneObjs]); ms_pCutsceneObjects[ms_numCutsceneObjs]->DeleteRwObject(); - if (ms_pCutsceneObjects[ms_numCutsceneObjs]) - delete ms_pCutsceneObjects[ms_numCutsceneObjs]; + delete ms_pCutsceneObjects[ms_numCutsceneObjs]; } ms_numCutsceneObjs = 0; @@ -397,7 +395,7 @@ CCutsceneMgr::Update(void) if (!ms_running) return; - ms_cutsceneTimer += CTimer::GetTimeStepNonClipped() * 0.02; + 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()) @@ -408,7 +406,7 @@ CCutsceneMgr::Update(void) } } -bool CCutsceneMgr::HasCutsceneFinished(void) { return TheCamera.GetPositionAlongSpline() == 1.0; } +bool CCutsceneMgr::HasCutsceneFinished(void) { return TheCamera.GetPositionAlongSpline() == 1.0f; } STARTPATCHES InjectHook(0x4045D0, &CCutsceneMgr::Initialise, PATCH_JUMP); From b13c4de6a4f73177af63a527ca505e76fba3abab Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Sep 2019 18:16:52 +0300 Subject: [PATCH 07/32] Added CUTSCENEDIRSIZE to Config enum and CUTSCENENAMESIZE macro --- src/core/CutsceneMgr.cpp | 6 +++--- src/core/CutsceneMgr.h | 4 +++- src/core/config.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/CutsceneMgr.cpp b/src/core/CutsceneMgr.cpp index ccb0bf64..1461c858 100644 --- a/src/core/CutsceneMgr.cpp +++ b/src/core/CutsceneMgr.cpp @@ -123,7 +123,7 @@ 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)[8] = *(char(*)[8]) *(uintptr*)0x70D9D0; +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; @@ -141,7 +141,7 @@ CCutsceneMgr::Initialise(void) ms_cutsceneProcessing = false; ms_useLodMultiplier = false; - ms_pCutsceneDir = new CDirectory(512); + ms_pCutsceneDir = new CDirectory(CUTSCENEDIRSIZE); ms_pCutsceneDir->ReadDirFile("ANIM\\CUTS.DIR"); } @@ -224,7 +224,7 @@ void CCutsceneMgr::SetHeadAnim(const char *animName, CObject *pObject) { CCutsceneHead *pCutsceneHead = (CCutsceneHead*)pObject; - char szAnim[16]; + char szAnim[CUTSCENENAMESIZE * 2]; sprintf(szAnim, "%s_%s", ms_cutsceneName, animName); pCutsceneHead->PlayAnimation(szAnim); diff --git a/src/core/CutsceneMgr.h b/src/core/CutsceneMgr.h index 69ce58a6..9b942030 100644 --- a/src/core/CutsceneMgr.h +++ b/src/core/CutsceneMgr.h @@ -1,6 +1,8 @@ #pragma once #include "CutsceneObject.h" +#define CUTSCENENAMESIZE 8 + class CDirectory; class CAnimBlendAssocGroup; class CCutsceneHead; @@ -16,7 +18,7 @@ class CCutsceneMgr static bool &ms_animLoaded; static bool &ms_useLodMultiplier; - static char(&ms_cutsceneName)[8]; + static char(&ms_cutsceneName)[CUTSCENENAMESIZE]; static CAnimBlendAssocGroup &ms_cutsceneAssociations; static CVector &ms_cutsceneOffset; static float &ms_cutsceneTimer; diff --git a/src/core/config.h b/src/core/config.h index 161cf898..366b195e 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, From 5854016ec51458711eacc7b1ac1fa415ee9db979 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Sep 2019 21:39:58 +0300 Subject: [PATCH 08/32] PlayerSkin --- src/core/Frontend.cpp | 2 +- src/core/PlayerInfo.cpp | 24 +++++- src/core/PlayerInfo.h | 1 + src/core/PlayerSkin.cpp | 166 +++++++++++++++++++++++++++++++++++++++- src/core/PlayerSkin.h | 16 +++- 5 files changed, 205 insertions(+), 4 deletions(-) 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/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..6290351a 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()) { + 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 From 90f085c1ca771faa2a369efa9cc43c49bdb3199a Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 28 Sep 2019 22:07:05 +0300 Subject: [PATCH 09/32] zero check --- src/core/PlayerSkin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/PlayerSkin.cpp b/src/core/PlayerSkin.cpp index 6290351a..111333ec 100644 --- a/src/core/PlayerSkin.cpp +++ b/src/core/PlayerSkin.cpp @@ -43,7 +43,7 @@ LoadPlayerDff(void) uint8 *buffer; bool streamWasAdded = false; - if (!CdStreamGetNumImages()) { + if (CdStreamGetNumImages() == 0) { CdStreamAddImage("models\\gta3.img"); streamWasAdded = true; } From c03efd0aa152ed3c82d8990ac208933baebc826e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sun, 29 Sep 2019 19:44:51 +0300 Subject: [PATCH 10/32] Moar peds --- src/audio/DMAudio.h | 18 +- src/math/Matrix.h | 1 + src/math/math.cpp | 6 + src/peds/Ped.cpp | 793 +++++++++++++++++++++++++++++++++++++---- src/peds/Ped.h | 28 +- src/peds/PlayerPed.cpp | 2 +- src/peds/PlayerPed.h | 2 +- 7 files changed, 755 insertions(+), 95 deletions(-) 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/math/Matrix.h b/src/math/Matrix.h index 7d8c02ab..5a3473ad 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -213,6 +213,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 @@ -46,6 +46,12 @@ CMatrix::RotateX(float x) Rotate(x, 0.0f, 0.0f); } +void +CMatrix::RotateZ(float z) +{ + Rotate(0.0f, 0.0f, z); +} + void CMatrix::Reorthogonalise(void) { diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 94b45cd6..be0ebd45 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -54,7 +54,6 @@ WRAPPER void CPed::SetFollowRoute(int16, int16) { EAXJMP(0x4DD690); } WRAPPER void CPed::SetDuck(uint32) { EAXJMP(0x4E4920); } 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::ProcessBuoyancy(void) { EAXJMP(0x4C7FF0); } WRAPPER void CPed::ServiceTalking(void) { EAXJMP(0x4E5870); } @@ -69,6 +68,8 @@ WRAPPER void CPed::SetEnterCar(CVehicle*, uint32) { EAXJMP(0x4E0920); } WRAPPER bool CPed::WarpPedToNearEntityOffScreen(CEntity*) { EAXJMP(0x4E5570); } WRAPPER void CPed::SetExitCar(CVehicle*, uint32) { EAXJMP(0x4E1010); } +#define NEW_WALK_AROUND_ALGORITHM + CPed *gapTempPedList[50]; uint16 gnNumTempPedList; @@ -486,11 +487,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; @@ -508,7 +509,7 @@ 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; @@ -1695,7 +1696,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; @@ -2396,29 +2396,51 @@ 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; + } + + CVector forwardPos = pos + forwardOffset; + return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); +} +#else CPed::CanPedJumpThis(CEntity *unused) { -#ifndef VC_PED_PORTS CVector2D forward(-Sin(m_fRotationCur), Cos(m_fRotationCur)); CVector pos = GetPosition(); CVector forwardPos( forward.x + pos.x, forward.y + pos.y, pos.z); -#else - if (m_nSurfaceTouched == SURFACE_PUDDLE) - return true; - // VC makes some other calculations if there is a CVector passed with function, which isn't possible here. - - CVector pos = GetPosition(); - pos.z -= 0.15f; - - CVector forwardPos = pos + GetForward(); -#endif return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); } +#endif bool CPed::CanPedReturnToState(void) @@ -2551,7 +2573,7 @@ CPed::RestorePreviousObjective(void) m_objective = m_prevObjective; m_prevObjective = OBJECTIVE_NONE; } - m_ped_flagD40 = false; + bObjectiveCompleted = false; } void @@ -2623,7 +2645,7 @@ CPed::SetObjective(eObjective newObj, void *entity) return; } - m_ped_flagD40 = false; + bObjectiveCompleted = false; if (!IsTemporaryObjective(m_objective) || IsTemporaryObjective(newObj)) { if (m_objective != newObj) { if (IsTemporaryObjective(newObj)) @@ -2775,7 +2797,7 @@ CPed::SetObjective(eObjective newObj) m_objective = newObj; } - m_ped_flagD40 = false; + bObjectiveCompleted = false; switch (newObj) { case OBJECTIVE_NONE: @@ -2808,7 +2830,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 { @@ -4796,7 +4818,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; } @@ -5263,6 +5285,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; @@ -5284,14 +5308,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: @@ -5332,7 +5369,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) { @@ -5359,14 +5401,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 @@ -5423,7 +5513,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(); @@ -7378,8 +7472,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) @@ -9150,19 +9244,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)) { @@ -9410,7 +9515,6 @@ CPed::ProcessControl(void) DMAudio.PlayOneShot(collidingVeh->m_audioEntityId, SOUND_CAR_PED_COLLISION, adjustedImpulse); if (IsPlayer()) { - /* VC specific if (adjustedImpulse > 20.0f) adjustedImpulse = 20.0f; @@ -9418,9 +9522,9 @@ CPed::ProcessControl(void) if (adjustedImpulse <= 13.0f) playerSufferSound = true; else - Say(104); + Say(SOUND_PED_DAMAGE); } - */ + CColModel* collidingCol = CModelInfo::GetModelInfo(collidingVeh->m_modelIndex)->GetColModel(); CVector colMinVec = collidingCol->boundingBox.min; CVector colMaxVec = collidingCol->boundingBox.max; @@ -9433,15 +9537,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); @@ -9494,13 +9598,12 @@ CPed::ProcessControl(void) } /* VC specific - bPushedAlongByCar = true; + if (m_pCollidingEntity != collidingEnt) + bPushedAlongByCar = true; */ } - /* VC specific if (m_fHealth < oldHealth && playerSufferSound) - Say(105); - */ + Say(SOUND_PED_HIT); #else if (collidingVehSpeedSqr <= 1.0f / 400.0f) { if (!IsPedInControl() @@ -9566,15 +9669,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); @@ -9792,7 +9895,7 @@ 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; @@ -10191,7 +10294,7 @@ CPed::ProcessControl(void) break; } SetMoveAnim(); - if (m_ped_flagD4) { + if (bPedIsBleeding) { if (CGame::nastyGame) { if (!(CTimer::GetFrameCounter() & 3)) { CVector cameraDist = GetPosition() - TheCamera.GetPosition(); @@ -12266,7 +12369,7 @@ CPed::ProcessObjective(void) } } else { ClearLookFlag(); - m_ped_flagD40 = true; + bObjectiveCompleted = true; } } case OBJECTIVE_KILL_CHAR_ON_FOOT: @@ -12279,7 +12382,7 @@ CPed::ProcessObjective(void) if (!m_pedInObjective || m_pedInObjective->DyingOrDead()) { ClearLookFlag(); - m_ped_flagD40 = true; + bObjectiveCompleted = true; SetMoveAnim(); break; } @@ -12342,7 +12445,7 @@ CPed::ProcessObjective(void) break; } if (m_pedInObjective->m_fHealth <= 0.0f) { - m_ped_flagD40 = true; + bObjectiveCompleted = true; bScriptObjectiveCompleted = true; SetMoveAnim(); break; @@ -12427,7 +12530,7 @@ CPed::ProcessObjective(void) return; } } - if (!bKindaStayInSamePlace && !m_ped_flagD8 && m_nPedState != PED_ATTACK && !killPlayerInNoPoliceZone) { + if (!bKindaStayInSamePlace && !bStopAndShoot && m_nPedState != PED_ATTACK && !killPlayerInNoPoliceZone) { if (distWithTargetSc > wepRange || m_pedInObjective->m_getUpTimer > CTimer::GetTimeInMilliseconds() || m_pedInObjective->m_nPedState == PED_ARRESTED @@ -12462,13 +12565,13 @@ CPed::ProcessObjective(void) SetCurrentWeapon(WEAPONTYPE_COLT45); } } else { - m_ped_flagD8 = true; + bStopAndShoot = true; } SetMoveState(PEDMOVE_STILL); SetMoveAnim(); break; } - m_ped_flagD8 = false; + bStopAndShoot = false; SetMoveAnim(); break; } @@ -12490,7 +12593,7 @@ CPed::ProcessObjective(void) GetPosition().x, GetPosition().y); SetShootTimer(CGeneral::GetRandomNumberInRange(0.0f, 500.0f)); SetAttackTimer(CGeneral::GetRandomNumberInRange(0.0f, 1500.0f)); - m_ped_flagF40 = false; + bObstacleShowedUpDuringKillObjective = false; } else { CVector target; @@ -12527,22 +12630,22 @@ CPed::ProcessObjective(void) time = CGeneral::GetRandomNumberInRange(1500.0f, 3000.0f); SetAttackTimer(time); - m_ped_flagF40 = false; + bObstacleShowedUpDuringKillObjective = false; } else if (foundEnt) { if (foundEnt->IsPed()) { SetAttackTimer(CGeneral::GetRandomNumberInRange(500.0f, 1000.0f)); - m_ped_flagF40 = false; + bObstacleShowedUpDuringKillObjective = false; } else { if (foundEnt->IsObject()) { SetAttackTimer(CGeneral::GetRandomNumberInRange(200.0f, 400.0f)); - m_ped_flagF40 = true; + bObstacleShowedUpDuringKillObjective = true; } else if (foundEnt->IsVehicle()) { SetAttackTimer(CGeneral::GetRandomNumberInRange(400.0f, 600.0f)); - m_ped_flagF40 = true; + bObstacleShowedUpDuringKillObjective = true; } else { SetAttackTimer(CGeneral::GetRandomNumberInRange(700.0f, 1200.0f)); - m_ped_flagF40 = true; + bObstacleShowedUpDuringKillObjective = true; } } @@ -12553,7 +12656,7 @@ CPed::ProcessObjective(void) } } else { if (!m_pedInObjective->m_pCurrentPhysSurface) - m_ped_flagD8 = false; + bStopAndShoot = false; if (m_nPedState != PED_ATTACK && m_nPedState != PED_FIGHT) { @@ -12575,7 +12678,7 @@ CPed::ProcessObjective(void) } } } - if (m_ped_flagF40) { + if (bObstacleShowedUpDuringKillObjective) { if (m_nPedType == PEDTYPE_COP) { if (GetWeapon()->m_eWeaponType > WEAPONTYPE_COLT45 || m_fleeFrom && m_fleeFrom->IsObject()) { @@ -12598,7 +12701,7 @@ CPed::ProcessObjective(void) } } else { if (m_nPedState != PED_SEEK_ENTITY && m_nPedState != PED_SEEK_POS - && !m_ped_flagD8 && !killPlayerInNoPoliceZone && !bKindaStayInSamePlace) { + && !bStopAndShoot && !killPlayerInNoPoliceZone && !bKindaStayInSamePlace) { Say(SOUND_PED_ATTACK); SetSeek(m_pedInObjective, wepRangeAdjusted); bIsRunning = true; @@ -12770,7 +12873,7 @@ CPed::ProcessObjective(void) case OBJECTIVE_ENTER_CAR_AS_DRIVER: { if (!m_carInObjective || bInVehicle) { - m_ped_flagD40 = true; + bObjectiveCompleted = true; bScriptObjectiveCompleted = true; RestorePreviousState(); } else { @@ -12847,7 +12950,7 @@ CPed::ProcessObjective(void) { if (!m_carInObjective) { ClearLookFlag(); - m_ped_flagD40 = true; + bObjectiveCompleted = true; break; } float distWithTargetSc = distWithTarget.Magnitude(); @@ -12969,7 +13072,7 @@ CPed::ProcessObjective(void) distWithTarget = m_nextRoutePointPos - GetPosition(); distWithTarget.z = 0.0f; if (sq(m_distanceToCountSeekDone) >= distWithTarget.MagnitudeSqr()) { - m_ped_flagD40 = true; + bObjectiveCompleted = true; bScriptObjectiveCompleted = true; SetMoveState(PEDMOVE_STILL); } else if (CTimer::GetTimeInMilliseconds() > m_nPedStateTimer || m_nPedState != PED_SEEK_POS) { @@ -13270,7 +13373,7 @@ CPed::ProcessObjective(void) } #endif } - if (m_ped_flagD40 + if (bObjectiveCompleted || m_objectiveTimer != 0 && CTimer::GetTimeInMilliseconds() > m_objectiveTimer) { RestorePreviousObjective(); if (m_objectiveTimer > CTimer::GetTimeInMilliseconds() || !m_objectiveTimer) @@ -13349,6 +13452,552 @@ CPed::SetExitTrain(CVehicle* train) } } +#ifdef NEW_WALK_AROUND_ALGORITHM +CVector +LocalPosForWalkAround(CVector2D colMin, CVector2D colMax, int walkAround) { + switch (walkAround) { + case 0: + case 1: + return CVector(colMin.x, colMax.y, 0.0f); + case 2: + case 3: + return CVector(colMax.x, colMax.y, 0.0f); + case 4: + case 5: + return CVector(colMax.x, colMin.y, 0.0f); + case 6: + case 7: + return CVector(colMin.x, colMin.y, 0.0f); + default: + // case 9: + return CVector(0.0f, 0.0f, 0.0f); // just a placeholder, supposed to be -GetForward(); + } +} +#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 objIsSeekTargetAndVan = false; + bool objIsSeekTarget = 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; + float angleToFaceObjCenter = (objColCenter - GetPosition()).Heading(); + float angleDiffBtwObjCenterAndForward = CGeneral::LimitRadianAngle(dirToSet - angleToFaceObjCenter); + + // What is the purpose of using this? + float objTopRightHeading = Atan2(adjustedColMax.x - adjustedColMin.x, adjustedColMax.y - adjustedColMin.y); + + 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) { + objIsSeekTarget = true; + if (IsPlayer()) + checkIntervalInTime = 0.0f; + + if (((CVehicle*)obj)->bIsVan) + objIsSeekTargetAndVan = 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; + 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(); + cornerToGo = tl; + dirToGo = GetLocalDirection(tl); + if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + m_walkAroundType = 1; + } else { + 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()) { + cornerToGo = tr; + dirToGo = GetLocalDirection(tr); + if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + m_walkAroundType = 2; + } else { + 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()) { + cornerToGo = br; + dirToGo = GetLocalDirection(br); + if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + m_walkAroundType = 5; + } else { + 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()) { + cornerToGo = bl; + dirToGo = GetLocalDirection(bl); + if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + m_walkAroundType = 6; + } else { + 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 + } +#endif + if (entityOnTopLeftOfObj && entityOnTopRightOfObj && entityOnBottomRightOfObj && entityOnBottomLeftOfObj) { + collidingThingChanged = false; + entityOnTopLeftOfObj = 0; + entityOnBottomLeftOfObj = 0; + entityOnTopRightOfObj = 0; + entityOnBottomRightOfObj = 0; + } + +#ifndef NEW_WALK_AROUND_ALGORITHM + 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 (objIsSeekTarget && (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 (objIsSeekTarget && (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 (objIsSeekTarget && (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 (objIsSeekTarget && (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; + } + + if (CGeneral::GetRandomNumber() & 1){ + bool nextRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, nextWalkAround), + true, true, true, true, true, true, false); + if(nextRouteIsClear) + m_walkAroundType = nextWalkAround; + } else { + bool currentRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType), + true, true, true, true, true, true, false); + if (!currentRouteIsClear) { + // 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 > 6) + m_walkAroundType = 0; + else + m_walkAroundType -= 1; + } + } + } + + localPosToHead = LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType); +#else + if (Abs(angleDiffBtwObjCenterAndForward) < objTopRightHeading) { + if (objIsSeekTarget) { + if (objIsSeekTargetAndVan) { + 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 (!objIsSeekTarget || !objIsSeekTargetAndVan || m_vehEnterType != CAR_DOOR_LR && m_vehEnterType != CAR_DOOR_RR) { + if (objIsSeekTarget) { + if (m_vehEnterType == CAR_DOOR_RF || (m_vehEnterType == CAR_DOOR_RR && !objIsSeekTargetAndVan)) + 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 (objIsSeekTarget && objIsSeekTargetAndVan && (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 (objIsSeekTarget) { + if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR && !objIsSeekTargetAndVan) + 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 (objIsSeekTarget && (!objIsSeekTargetAndVan || 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; +} + class CPed_ : public CPed { public: @@ -13408,7 +14057,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); @@ -13550,4 +14198,5 @@ STARTPATCHES 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 29916bf4..91cd8f99 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -266,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; @@ -281,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; @@ -294,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; @@ -316,7 +316,7 @@ 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; @@ -328,7 +328,7 @@ public: 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 bKnockedUpIntoAir : 1; // NOT CERTAIN - has ped been knocked up into the air by a car collision uint8 m_ped_flagH2 : 1; uint8 m_ped_flagH4 : 1; uint8 bClearObjective : 1; @@ -339,7 +339,7 @@ public: 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; uint8 m_ped_flagI20 : 1; @@ -402,7 +402,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; @@ -530,7 +530,6 @@ public: void CalculateNewOrientation(void); float WorkOutHeadingForMovingFirstPerson(float); void CalculateNewVelocity(void); - bool CanPedJumpThis(CEntity*); bool CanSeeEntity(CEntity*, float); void RestorePreviousObjective(void); void SetIdle(void); @@ -732,6 +731,11 @@ public: 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]; } 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; From 9149367f86ccc711c7783183babc57308f631b73 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 1 Oct 2019 19:53:25 +0300 Subject: [PATCH 11/32] Fix CPickup --- src/control/Pickups.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/control/Pickups.h b/src/control/Pickups.h index 8c2014d6..5b51a52a 100644 --- a/src/control/Pickups.h +++ b/src/control/Pickups.h @@ -1,7 +1,7 @@ #pragma once #include "Weapon.h" -enum ePickupType +enum ePickupType : uint8 { PICKUP_NONE = 0, PICKUP_IN_SHOP = 1, @@ -25,7 +25,8 @@ class CObject; class CPickup { - ePickupType m_eType; + ePickupType m_eType; + bool m_bRemoved; uint16 m_wQuantity; CObject *m_pObject; uint32 m_nTimer; @@ -34,6 +35,8 @@ class CPickup CVector m_vecPos; }; +static_assert(sizeof(CPickup) == 0x1C, "CPickup: error"); + class CPickups { public: From d0addb8bf52486bd0adbea97787ccdaae496bb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Tue, 1 Oct 2019 23:33:00 +0300 Subject: [PATCH 12/32] Mostly fix --- src/peds/Ped.cpp | 89 +++++++++++++++++++++++++++++++++++++----------- src/peds/Ped.h | 2 -- 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index be0ebd45..3524f8f6 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -829,6 +829,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) { @@ -846,13 +862,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, @@ -869,22 +885,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) { @@ -3552,7 +3552,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; @@ -3582,6 +3631,7 @@ CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPi break; } } +#endif break; case WEAPONTYPE_COLT45: case WEAPONTYPE_UZI: @@ -3596,8 +3646,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; diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 91cd8f99..fd26f2d1 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -667,8 +667,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); From bd6e109441cb8c2012da7239364fdd3889768476 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 02:39:23 +0300 Subject: [PATCH 13/32] Fix typo in CCarCtrl::WeaveThroughPedsSectorList --- src/control/CarCtrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 0be8a0a0..710bae0f 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -1323,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); From 0ee5a46f718889f545dc8cf2d4f5c54dd3956453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Thu, 3 Oct 2019 04:02:02 +0300 Subject: [PATCH 14/32] Fixes & peds --- src/control/Script.cpp | 6 +- src/core/config.h | 1 - src/entities/Physical.h | 2 +- src/peds/Ped.cpp | 309 ++++++++++++++++++++++++++++++++++++---- src/peds/Ped.h | 10 +- 5 files changed, 289 insertions(+), 39 deletions(-) diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 885d1d47..1511b233 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -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/config.h b/src/core/config.h index 366b195e..f82967d5 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -139,5 +139,4 @@ enum Config { #define EXPLODING_AIRTRAIN // can blow up jumbo jet with rocket launcher #define ANIMATE_PED_COL_MODEL //#define REMOVE_TREADABLE_PATHFIND -#define CANCELLABLE_CAR_ENTER #define VC_PED_PORTS 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/peds/Ped.cpp b/src/peds/Ped.cpp index 3524f8f6..33b31066 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -48,7 +48,6 @@ WRAPPER void CPed::SpawnFlyingComponent(int, int8) { EAXJMP(0x4EB060); } WRAPPER void CPed::SetPedPositionInCar(void) { EAXJMP(0x4D4970); } WRAPPER void CPed::PreRender(void) { EAXJMP(0x4CFDD0); } -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); } @@ -68,7 +67,10 @@ 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 + #define NEW_WALK_AROUND_ALGORITHM +#define CANCELLABLE_CAR_ENTER CPed *gapTempPedList[50]; uint16 gnNumTempPedList; @@ -512,17 +514,17 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) 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; + bHitSteepSlope = false; m_ped_flagH4 = false; bClearObjective = false; m_ped_flagH10 = false; @@ -1891,7 +1893,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) 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; @@ -2429,6 +2431,7 @@ CPed::CanPedJumpThis(CEntity *unused, CVector *damageNormal = nil) return CWorld::GetIsLineOfSightClear(pos, forwardPos, true, false, false, true, false, false, false); } #else +bool CPed::CanPedJumpThis(CEntity *unused) { CVector2D forward(-Sin(m_fRotationCur), Cos(m_fRotationCur)); @@ -3310,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; } @@ -9976,8 +9979,8 @@ 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)) { + GetPosition().z = FEET_OFFSET + foundCol.point.z; GetMatrix().UpdateRW(); SetLanding(); bIsStanding = true; @@ -11802,7 +11805,7 @@ CPed::PedSetOutCarCB(CAnimBlendAssociation *animAssoc, void *arg) ped->ReplaceWeaponWhenExitingVehicle(); - ped->m_ped_flagG10 = false; + ped->bOnBoat = false; if (ped->bBusJacked) { ped->SetFall(1500, ANIM_KO_SKID_BACK, false); ped->bBusJacked = false; @@ -13518,8 +13521,7 @@ LocalPosForWalkAround(CVector2D colMin, CVector2D colMax, int walkAround) { case 7: return CVector(colMin.x, colMin.y, 0.0f); default: - // case 9: - return CVector(0.0f, 0.0f, 0.0f); // just a placeholder, supposed to be -GetForward(); + return CVector(0.0f, 0.0f, 0.0f); } } #endif @@ -13588,11 +13590,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) objUpsideDown = false; } float oldRotDest = m_fRotationDest; +#ifndef NEW_WALK_AROUND_ALGORITHM float angleToFaceObjCenter = (objColCenter - GetPosition()).Heading(); float angleDiffBtwObjCenterAndForward = CGeneral::LimitRadianAngle(dirToSet - angleToFaceObjCenter); - - // What is the purpose of using this? float objTopRightHeading = Atan2(adjustedColMax.x - adjustedColMin.x, adjustedColMax.y - adjustedColMin.y); +#endif if (IsPlayer()) { if (FindPlayerPed()->m_fMoveSpeed <= 0.0f) @@ -13641,7 +13643,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) collidingThingChanged = false; } else { #else - CVector cornerToGo; + CVector cornerToGo = CVector(10.0f, 10.0f, 10.0f); int dirToGo; m_walkAroundType = 0; #endif @@ -13669,10 +13671,10 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) else { CVector tl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMax.y, 0.0f) - GetPosition(); cornerToGo = tl; - dirToGo = GetLocalDirection(tl); if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { m_walkAroundType = 1; } else { + dirToGo = GetLocalDirection(tl); if (dirToGo == 1) m_walkAroundType = 0; // ALL of the next turns will be right turn else if (dirToGo == 3) @@ -13703,10 +13705,10 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector tr = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMax.y, 0.0f) - GetPosition(); if (tr.Magnitude2D() < cornerToGo.Magnitude2D()) { cornerToGo = tr; - dirToGo = GetLocalDirection(tr); if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { m_walkAroundType = 2; } else { + dirToGo = GetLocalDirection(tr); if (dirToGo == 1) m_walkAroundType = 2; // ALL of the next turns will be right turn else if (dirToGo == 3) @@ -13738,10 +13740,10 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector br = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMin.y, 0.0f) - GetPosition(); if (br.Magnitude2D() < cornerToGo.Magnitude2D()) { cornerToGo = br; - dirToGo = GetLocalDirection(br); if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { m_walkAroundType = 5; } else { + dirToGo = GetLocalDirection(br); if (dirToGo == 1) m_walkAroundType = 4; // ALL of the next turns will be right turn else if (dirToGo == 3) @@ -13773,10 +13775,10 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector bl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMin.y, 0.0f) - GetPosition(); if (bl.Magnitude2D() < cornerToGo.Magnitude2D()) { cornerToGo = bl; - dirToGo = GetLocalDirection(bl); if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { m_walkAroundType = 6; } else { + dirToGo = GetLocalDirection(bl); if (dirToGo == 1) m_walkAroundType = 6; // ALL of the next turns will be right turn else if (dirToGo == 3) @@ -13786,7 +13788,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } #else } -#endif + if (entityOnTopLeftOfObj && entityOnTopRightOfObj && entityOnBottomRightOfObj && entityOnBottomLeftOfObj) { collidingThingChanged = false; entityOnTopLeftOfObj = 0; @@ -13795,7 +13797,6 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) entityOnBottomRightOfObj = 0; } -#ifndef NEW_WALK_AROUND_ALGORITHM if (!collidingThingChanged) { m_walkAroundType = 0; } else { @@ -13879,15 +13880,25 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) nextWalkAround = 7; } - if (CGeneral::GetRandomNumber() & 1){ - bool nextRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, nextWalkAround), - true, true, true, true, true, true, false); - if(nextRouteIsClear) - m_walkAroundType = nextWalkAround; - } else { - bool currentRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType), + CVector nextPosToHead = objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, nextWalkAround); + 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); + bool currentRouteIsClear = CWorld::GetIsLineOfSightClear(GetPosition(), posToHead, true, true, true, true, true, true, false); - if (!currentRouteIsClear) { + + /* 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; @@ -13897,7 +13908,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) m_walkAroundType += 1; } else { m_walkAroundType += 2; - if (m_walkAroundType > 6) + if (m_walkAroundType > 7) m_walkAroundType = 0; else m_walkAroundType -= 1; @@ -14030,6 +14041,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) 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; @@ -14047,6 +14059,243 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) 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; + // VC conditionally sets GetPosition().z here with nonexisting flag in III + GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; + 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; + } + } + // VC conditionally sets GetPosition().z here with nonexisting flag in III + GetPosition().z = FEET_OFFSET + intersectionPoint.point.z; + 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; + // VC sets bKnockedUpIntoAir here + } +#endif + sphereNormal.Normalise(); + collidingPoints[sphere].normal = sphereNormal; + if (collidingPoints[sphere].surfaceB == SURFACE_STONE) + bHitSteepSlope = true; + } + } + } + return ourCollidedSpheres; +} + class CPed_ : public CPed { public: @@ -14060,6 +14309,7 @@ public: 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 @@ -14072,6 +14322,7 @@ STARTPATCHES 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); diff --git a/src/peds/Ped.h b/src/peds/Ped.h index fd26f2d1..bf4849b2 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -319,20 +319,20 @@ public: 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; // NOT CERTAIN - has ped been knocked up into the air by a car collision - uint8 m_ped_flagH2 : 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 bRichFromMugging : 1; // ped has lots of cash from mugging people - will drop money if someone points gun to him uint8 m_ped_flagH80 : 1; From 095b8b1e74e7d2454bfb92e22811e06702e3ae46 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 13:16:28 +0300 Subject: [PATCH 15/32] CMoneyMessages --- src/render/MoneyMessages.cpp | 86 ++++++++++++++++++++++++++++++++++++ src/render/MoneyMessages.h | 24 ++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/render/MoneyMessages.cpp create mode 100644 src/render/MoneyMessages.h diff --git a/src/render/MoneyMessages.cpp b/src/render/MoneyMessages.cpp new file mode 100644 index 00000000..c18c7a8a --- /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 dwLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; + if (dwLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0; + else { + float fLifeTime = (float)dwLifeTime / 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) + 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 From 5b119ca78d44bb2f5c63f6e14b677fbacb38711b Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 13:21:00 +0300 Subject: [PATCH 16/32] Added missed config.h --- src/core/config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/config.h b/src/core/config.h index f82967d5..4a9fa792 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -67,6 +67,7 @@ enum Config { NUMANTENNAS = 8, NUMCORONAS = 56, NUMPOINTLIGHTS = 32, + NUMMONEYMESSAGES = 16, NUMONSCREENTIMERENTRIES = 1, NUMRADARBLIPS = 32, From 6bed421ce86a83709fde4e90f6101ad2b3314053 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 13:31:31 +0300 Subject: [PATCH 17/32] No dw --- src/render/MoneyMessages.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/render/MoneyMessages.cpp b/src/render/MoneyMessages.cpp index c18c7a8a..d80be276 100644 --- a/src/render/MoneyMessages.cpp +++ b/src/render/MoneyMessages.cpp @@ -14,10 +14,10 @@ void CMoneyMessage::Render() { const float MAX_SCALE = 4.0f; - uint32 dwLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; - if (dwLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0; + uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; + if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0; else { - float fLifeTime = (float)dwLifeTime / MONEY_MESSAGE_LIFETIME_MS; + 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)) { From 72e12f6aae10e294c9265dd58c75db5c5c54bd24 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 22:28:56 +0300 Subject: [PATCH 18/32] CPickups --- src/control/Pickups.cpp | 1056 ++++++++++++++++++++++++++++++++++++++- src/control/Pickups.h | 168 ++++--- src/core/Pools.cpp | 1 + src/core/Pools.h | 1 + src/core/config.h | 7 +- src/math/Matrix.h | 16 + src/objects/Object.cpp | 4 +- src/objects/Object.h | 6 +- 8 files changed, 1174 insertions(+), 85 deletions(-) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 81642a85..a4b43106 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -1,20 +1,1036 @@ -#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_wQuantity : 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::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) { + if ((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) + && (m_pObject->GetModelIndex() != MI_PICKUP_KILLFRENZY || !CTheScripts::IsPlayerOnAMission() && !CDarkel::FrenzyOnGoing() && CGame::nastyGame)) { + 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_wQuantity != 0 ? m_wQuantity : 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 (MI_PICKUP_CAMERA == m_pObject->GetModelIndex() && vehicle) + { + 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_wQuantity != 0 ? m_wQuantity : 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_wQuantity; + sprintf(gString, "$%d", m_wQuantity); +#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_wIndex = 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_wIndex) 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_wQuantity = 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_wIndex >= 0xFFFE) + aPickUps[slot].m_wIndex = 1; + else + aPickUps[slot].m_wIndex++; + return slot | (aPickUps[slot].m_wIndex << 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_wIndex << 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)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)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)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)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)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)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)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)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 5b51a52a..44ce0c4f 100644 --- a/src/control/Pickups.h +++ b/src/control/Pickups.h @@ -1,62 +1,108 @@ -#pragma once -#include "Weapon.h" - -enum ePickupType : uint8 -{ - 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 -{ +#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_wQuantity; - CObject *m_pObject; - uint32 m_nTimer; - int16 m_eModelIndex; - int16 m_wIndex; - CVector m_vecPos; -}; - -static_assert(sizeof(CPickup) == 0x1C, "CPickup: error"); - -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); -}; + bool m_bRemoved; + uint16 m_wQuantity; + CObject *m_pObject; + uint32 m_nTimer; + int16 m_eModelIndex; + uint16 m_wIndex; + 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; } + 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/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/config.h b/src/core/config.h index 4a9fa792..49bef3fa 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -68,10 +68,14 @@ enum Config { 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, @@ -141,3 +145,4 @@ enum Config { #define ANIMATE_PED_COL_MODEL //#define REMOVE_TREADABLE_PATHFIND #define VC_PED_PORTS +//#define MONEY_MESSAGES \ No newline at end of file diff --git a/src/math/Matrix.h b/src/math/Matrix.h index 5a3473ad..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; 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); From 2cf94348f522802f423d8b6563491a4301db9b50 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 22:51:38 +0300 Subject: [PATCH 19/32] Drop w's --- src/control/Pickups.cpp | 26 +++++++++++++------------- src/control/Pickups.h | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index a4b43106..32a8fadc 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -89,7 +89,7 @@ CPickup::GiveUsAPickUpObject(int32 handle) object->bUsesCollision = false; object->bIsPickup = true; - object->field_172 = m_eModelIndex == MI_PICKUP_BONUS ? m_wQuantity : 0; + object->field_172 = m_eModelIndex == MI_PICKUP_BONUS ? m_nQuantity : 0; switch (m_eType) { @@ -202,7 +202,7 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) 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_wQuantity != 0 ? m_wQuantity : AmmoForWeapon_OnStreet[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())); } @@ -232,7 +232,7 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) 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_wQuantity != 0 ? m_wQuantity : AmmoForWeapon[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())); } @@ -256,8 +256,8 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) DMAudio.PlayFrontEndSound(SOUND_PICKUP_HIDDEN_PACKAGE, 0); return true; case PICKUP_MONEY: - CWorld::Players[playerId].m_nMoney += m_wQuantity; - sprintf(gString, "$%d", m_wQuantity); + 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 @@ -368,7 +368,7 @@ CPickups::Init(void) NumMessages = 0; for (int i = 0; i < NUMPICKUPS; i++) { aPickUps[i].m_eType = PICKUP_NONE; - aPickUps[i].m_wIndex = 1; + aPickUps[i].m_nIndex = 1; aPickUps[i].m_pObject = nil; } @@ -409,7 +409,7 @@ CPickups::GetActualPickupIndex(int32 index) if (index == -1) return -1; // doesn't look nice - if ((uint16)((index & 0xFFFF0000) >> 16) != aPickUps[(uint16)index].m_wIndex) return -1; + if ((uint16)((index & 0xFFFF0000) >> 16) != aPickUps[(uint16)index].m_nIndex) return -1; return (uint16)index; } @@ -525,7 +525,7 @@ CPickups::GenerateNewOne(CVector pos, uint32 modelIndex, uint8 type, uint32 quan aPickUps[slot].m_eType = (ePickupType)type; aPickUps[slot].m_bRemoved = false; - aPickUps[slot].m_wQuantity = quantity; + aPickUps[slot].m_nQuantity = quantity; if (type == PICKUP_ONCE_TIMEOUT) aPickUps[slot].m_nTimer = CTimer::GetTimeInMilliseconds() + 20000; else if (type == PICKUP_MONEY) @@ -554,11 +554,11 @@ CPickups::GenerateNewOne_WeaponType(CVector pos, eWeaponType weaponType, uint8 t int32 CPickups::GetNewUniquePickupIndex(int32 slot) { - if (aPickUps[slot].m_wIndex >= 0xFFFE) - aPickUps[slot].m_wIndex = 1; + if (aPickUps[slot].m_nIndex >= 0xFFFE) + aPickUps[slot].m_nIndex = 1; else - aPickUps[slot].m_wIndex++; - return slot | (aPickUps[slot].m_wIndex << 16); + aPickUps[slot].m_nIndex++; + return slot | (aPickUps[slot].m_nIndex << 16); } int32 @@ -612,7 +612,7 @@ CPickups::FindColourIndexForWeaponMI(int32 model) void CPickups::AddToCollectedPickupsArray(int32 index) { - aPickUpsCollected[CollectedPickUpIndex++] = index | (aPickUps[index].m_wIndex << 16); + aPickUpsCollected[CollectedPickUpIndex++] = index | (aPickUps[index].m_nIndex << 16); if (CollectedPickUpIndex >= NUMCOLLECTEDPICKUPS) CollectedPickUpIndex = 0; } diff --git a/src/control/Pickups.h b/src/control/Pickups.h index 44ce0c4f..4bcbdfb5 100644 --- a/src/control/Pickups.h +++ b/src/control/Pickups.h @@ -31,11 +31,11 @@ class CPickup public: ePickupType m_eType; bool m_bRemoved; - uint16 m_wQuantity; + uint16 m_nQuantity; CObject *m_pObject; uint32 m_nTimer; int16 m_eModelIndex; - uint16 m_wIndex; + uint16 m_nIndex; CVector m_vecPos; CObject *GiveUsAPickUpObject(int32 handle); From 679f7bbcfa72d47d465922f207ff325f6d205bfd Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 23:32:31 +0300 Subject: [PATCH 20/32] Checks rewritten --- src/control/Pickups.cpp | 189 +++++++++++++++++++++------------------- src/control/Pickups.h | 1 + 2 files changed, 99 insertions(+), 91 deletions(-) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 32a8fadc..733b3a7f 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -123,6 +123,18 @@ CPickup::GiveUsAPickUpObject(int32 handle) 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) { @@ -173,107 +185,102 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) } // if we didn't then we've got nothing to do - if (isPickupTouched) { - if ((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) - && (m_pObject->GetModelIndex() != MI_PICKUP_KILLFRENZY || !CTheScripts::IsPlayerOnAMission() && !CDarkel::FrenzyOnGoing() && CGame::nastyGame)) { - CPad::GetPad(0)->StartShake(120, 100); - switch (m_eType) + 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 { - 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: + CWorld::Players[playerId].m_nMoney -= CostOfWeapon[CPickups::WeaponForModel(m_pObject->GetModelIndex())]; 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 (MI_PICKUP_CAMERA == m_pObject->GetModelIndex() && vehicle) - { - DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0); - CPickups::bPickUpcamActivated = true; - CPickups::pPlayerVehicle = FindPlayerVehicle(); - CPickups::StaticCamCoors = m_pObject->GetPosition(); - CPickups::StaticCamStartTime = CTimer::GetTimeInMilliseconds(); - } + 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); } - 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(); + m_nTimer = CTimer::GetTimeInMilliseconds() + 5000; 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())); + } + 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); } - 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 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(); } - 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; } + 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 { diff --git a/src/control/Pickups.h b/src/control/Pickups.h index 4bcbdfb5..b49a5544 100644 --- a/src/control/Pickups.h +++ b/src/control/Pickups.h @@ -42,6 +42,7 @@ public: 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(); }; From 999765aadd7be0e2179243fa60bde729272b4c2d Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 23:34:02 +0300 Subject: [PATCH 21/32] Fixed some formatting --- src/control/Pickups.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 733b3a7f..1eb096a2 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -192,9 +192,7 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) case PICKUP_IN_SHOP: if (CWorld::Players[playerId].m_nMoney < CostOfWeapon[CPickups::WeaponForModel(m_pObject->GetModelIndex())]) { CGarages::TriggerMessage("PU_MONY", -1, 6000, -1); - } - else - { + } 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())]); @@ -215,9 +213,7 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) 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) - { + } else if (m_pObject->GetModelIndex() == MI_PICKUP_CAMERA && vehicle != nil) { DMAudio.PlayFrontEndSound(SOUND_PICKUP_BONUS, 0); CPickups::bPickUpcamActivated = true; CPickups::pPlayerVehicle = FindPlayerVehicle(); From 47e6cbe65e1715d11d81cbe3dc85b01f894e70c1 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 3 Oct 2019 23:35:09 +0300 Subject: [PATCH 22/32] Fix formatting mistakes --- src/control/Pickups.cpp | 3 +-- src/render/MoneyMessages.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 1eb096a2..2d112592 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -252,8 +252,7 @@ CPickup::Update(CPlayerPed *player, CVehicle *vehicle, int playerId) printf("All collectables have been picked up\n"); CGarages::TriggerMessage("CO_ALL", -1, 5000, -1); CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 1000000; - } - else + } else CGarages::TriggerMessage("CO_ONE", CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages, 5000, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages); Remove(); diff --git a/src/render/MoneyMessages.cpp b/src/render/MoneyMessages.cpp index d80be276..53d6db58 100644 --- a/src/render/MoneyMessages.cpp +++ b/src/render/MoneyMessages.cpp @@ -55,7 +55,7 @@ void CMoneyMessages::Render() { for (int32 i = 0; i < NUMMONEYMESSAGES; i++) { - if (aMoneyMessages[i].m_nTimeRegistered) + if (aMoneyMessages[i].m_nTimeRegistered != 0) aMoneyMessages[i].Render(); } } From 5e1538a2757dc495d0c15f72a71583b4b8f2610d Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Fri, 4 Oct 2019 00:49:11 +0300 Subject: [PATCH 23/32] Fixed disappearing ammo count --- src/render/Hud.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 2dae7551..ae0d4eb3 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -336,23 +336,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 +351,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 */ From 54f36ad9604190987350a9c38a0f82a0c7b960a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 4 Oct 2019 01:19:07 +0300 Subject: [PATCH 24/32] Fix radar --- src/core/Radar.cpp | 376 ++++++++++++++++++++++++++++++--------------- src/core/Radar.h | 30 ++-- 2 files changed, 270 insertions(+), 136 deletions(-) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index f04e14d1..7eff743a 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; } }; } @@ -291,82 +290,176 @@ 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; - }; + CEntity *blipEntity = nil; + for(int blipId = 0; blipId < NUMRADARBLIPS; blipId++) { + if (!ms_RadarTrace[blipId].m_bInUse) + continue; - if (e) { - if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].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); + 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) { - 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; + 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 { + ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255); + } } } - if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BLIP_ONLY) { - vec2d = e->GetPosition(); - TransformRealWorldPointToRadarSpace(in, vec2d); - 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); - } } - } + 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())) { - /* - 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) { + 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); - 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 { + ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255); + } } } - } - }; + 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; + } + + 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 + ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255); + } + } + } + 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[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[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); + 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 + ShowRadarTrace(out.x, out.y, ms_RadarTrace[blipId].m_wScale, (uint8)(color >> 24), (uint8)(color >> 16), (uint8)(color >> 8), 255); + } + } + break; + default: + break; + } } } } @@ -531,9 +624,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 +663,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 +687,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 +703,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 +731,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 +825,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) { - -} -#endif - -#if 1 -WRAPPER int32 CRadar::SetCoordBlip(eBlipType, CVector, int32, eBlipDisplay) { EAXJMP(0x4A5590); } -#else -int CRadar::SetCoordBlip(eBlipType type, CVector pos, int32 flag, eBlipDisplay) -{ - return 0; -} -#endif - -#if 1 -WRAPPER int CRadar::SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay) { EAXJMP(0x4A5640); } -#else -int CRadar::SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay) -{ - return 0; + int index = CRadar::GetActualBlipArrayIndex(i); + if (index != -1) { + ms_RadarTrace[index].m_IconID = icon; + } } #endif #if 0 -WRAPPER void CRadar::SetRadarMarkerState(int32, int32) { EAXJMP(0x4A5C60); } +WRAPPER int32 CRadar::SetCoordBlip(eBlipType, CVector, int32, eBlipDisplay display) { EAXJMP(0x4A5590); } #else -void CRadar::SetRadarMarkerState(int32 counter, int32 flag) +int CRadar::SetCoordBlip(eBlipType type, CVector pos, int32 color, eBlipDisplay display) +{ + 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 0 +WRAPPER int CRadar::SetEntityBlip(eBlipType type, int32, int32, eBlipDisplay) { EAXJMP(0x4A5640); } +#else +int CRadar::SetEntityBlip(eBlipType type, int32 handle, int32 color, eBlipDisplay display) +{ + 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, bool) { EAXJMP(0x4A5C60); } +#else +void CRadar::SetRadarMarkerState(int32 counter, bool flag) { CEntity *e; switch (ms_RadarTrace[counter].m_eBlipType) { @@ -780,11 +911,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,10 +937,13 @@ 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)); } @@ -1076,7 +1210,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 +1220,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..6bb445fd 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -47,8 +47,8 @@ enum eRadarSprite 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 +57,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 +72,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 +96,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 +111,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 +125,11 @@ 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 Shutdown(); static void StreamRadarSections(const CVector &posn); static void StreamRadarSections(int32 x, int32 y); From cf0edb3eb79626a19d1c4c5984df4d884be7e3d0 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Fri, 4 Oct 2019 02:18:23 +0300 Subject: [PATCH 25/32] Fix warnings --- src/control/Pickups.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 2d112592..8a67e248 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -657,7 +657,7 @@ CPickups::DoPickUpEffects(CEntity *entity) entity->m_flagD80 = CTheScripts::IsPlayerOnAMission() || CDarkel::FrenzyOnGoing() || !CGame::nastyGame; if (!entity->m_flagD80) { - float s = Sin((float)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)); + float s = Sin((float)((CTimer::GetTimeInMilliseconds() + (uintptr)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)); float modifiedSin = 0.3 * (s + 1.0f); @@ -735,7 +735,7 @@ CPickups::DoMineEffects(CEntity *entity) const float MAXDIST = 20.0f; if (dist < MAXDIST) { - float s = Sin((float)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)entity) & 0x1FF) * DEGTORAD(360.0f / 0x200)); + 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, @@ -757,7 +757,7 @@ CPickups::DoMoneyEffects(CEntity *entity) const float MAXDIST = 20.0f; if (dist < MAXDIST) { - float s = Sin((float)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)entity) & 0x3FF) * DEGTORAD(360.0f / 0x400)); + 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, @@ -779,7 +779,7 @@ CPickups::DoCollectableEffects(CEntity *entity) const float MAXDIST = 14.0f; if (dist < MAXDIST) { - float s = Sin((float)(((uint16)CTimer::GetTimeInMilliseconds() + (uint16)entity) & 0x7FF) * DEGTORAD(360.0f / 0x800)); + 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, From cc621ba0995f659c32dee4b7d7870902ef50c9eb Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 5 Oct 2019 16:04:27 +0300 Subject: [PATCH 26/32] Corona widescreen fix --- src/core/common.h | 4 +++- src/render/Coronas.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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/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, From aa4e7ad5eb554b1219f7eaae53e5ddc0d4478dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sat, 5 Oct 2019 16:44:03 +0300 Subject: [PATCH 27/32] CDarkel, walkaround fix --- src/control/Darkel.cpp | 298 +++++++++++++++++++---------------- src/control/Darkel.h | 10 +- src/core/Streaming.cpp | 8 +- src/core/config.h | 19 ++- src/modelinfo/ModelIndices.h | 2 - src/peds/Ped.cpp | 63 ++++---- 6 files changed, 227 insertions(+), 173 deletions(-) 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; + 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); - } - - - CPopulation::m_AllRandomPedsThisType = -1; - Status = KILLFRENZY_FAILED; - TimeOfFrenzyStart = CTimer::GetTimeInMilliseconds(); - - 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); + 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/core/Streaming.cpp b/src/core/Streaming.cpp index a7bde91e..d15415ea 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){ @@ -2408,8 +2408,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 +2421,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/config.h b/src/core/config.h index 49bef3fa..520bcc72 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -32,6 +32,7 @@ enum Config { NUMDUMMIES = 2802, // 2368 on PS2 NUMAUDIOSCRIPTOBJECTS = 256, NUMCUTSCENEOBJECTS = 50, + NUMDEFAULTMODELS = 200, NUMTEMPOBJECTS = 30, @@ -138,11 +139,25 @@ enum Config { #endif #define FIX_BUGS // fix bugs in the game, TODO: use this more + +// Pad #define KANGAROO_CHEAT + +// Hud #define ASPECT_RATIO_SCALE + +// Script #define USE_DEBUG_SCRIPT_LOADER + +// Vehicles #define EXPLODING_AIRTRAIN // can blow up jumbo jet with rocket launcher -#define ANIMATE_PED_COL_MODEL //#define REMOVE_TREADABLE_PATHFIND + +// Pickups +//#define MONEY_MESSAGES + +// Peds +#define ANIMATE_PED_COL_MODEL #define VC_PED_PORTS -//#define MONEY_MESSAGES \ No newline at end of file +#define NEW_WALK_AROUND_ALGORITHM +#define CANCELLABLE_CAR_ENTER \ No newline at end of file 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/peds/Ped.cpp b/src/peds/Ped.cpp index 33b31066..44148f14 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -69,9 +69,6 @@ WRAPPER void CPed::SetExitCar(CVehicle*, uint32) { EAXJMP(0x4E1010); } #define FEET_OFFSET 1.04f -#define NEW_WALK_AROUND_ALGORITHM -#define CANCELLABLE_CAR_ENTER - CPed *gapTempPedList[50]; uint16 gnNumTempPedList; @@ -13506,19 +13503,29 @@ CPed::SetExitTrain(CVehicle* train) #ifdef NEW_WALK_AROUND_ALGORITHM CVector -LocalPosForWalkAround(CVector2D colMin, CVector2D colMax, int walkAround) { +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); @@ -13537,8 +13544,8 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector objColCenter = (objColMin + objColMax) / 2.0f; CMatrix objMat(obj->GetMatrix()); float dirToSet = obj->GetForward().Heading(); - bool objIsSeekTargetAndVan = false; - bool objIsSeekTarget = false; + bool goingToEnterCarAndItsVan = false; + bool goingToEnterCar = false; bool objUpsideDown = false; float checkIntervalInDist = (objColMax.y - objColMin.y) * 0.1f; @@ -13620,12 +13627,12 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) 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) { - objIsSeekTarget = true; + goingToEnterCar = true; if (IsPlayer()) checkIntervalInTime = 0.0f; if (((CVehicle*)obj)->bIsVan) - objIsSeekTargetAndVan = true; + goingToEnterCarAndItsVan = true; } } @@ -13671,7 +13678,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) else { CVector tl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMax.y, 0.0f) - GetPosition(); cornerToGo = tl; - if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { m_walkAroundType = 1; } else { dirToGo = GetLocalDirection(tl); @@ -13705,7 +13712,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector tr = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMax.y, 0.0f) - GetPosition(); if (tr.Magnitude2D() < cornerToGo.Magnitude2D()) { cornerToGo = tr; - if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { m_walkAroundType = 2; } else { dirToGo = GetLocalDirection(tr); @@ -13740,7 +13747,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector br = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMin.y, 0.0f) - GetPosition(); if (br.Magnitude2D() < cornerToGo.Magnitude2D()) { cornerToGo = br; - if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { m_walkAroundType = 5; } else { dirToGo = GetLocalDirection(br); @@ -13775,7 +13782,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) CVector bl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMin.y, 0.0f) - GetPosition(); if (bl.Magnitude2D() < cornerToGo.Magnitude2D()) { cornerToGo = bl; - if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { m_walkAroundType = 6; } else { dirToGo = GetLocalDirection(bl); @@ -13803,7 +13810,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) if (Abs(angleDiffBtwObjCenterAndForward) >= objTopRightHeading) { if (PI - objTopRightHeading >= Abs(angleDiffBtwObjCenterAndForward)) { if ((angleDiffBtwObjCenterAndForward <= 0.0f || objUpsideDown) && (angleDiffBtwObjCenterAndForward < 0.0f || !objUpsideDown)) { - if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { m_walkAroundType = 0; } else { if (CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) >= 0.0f) { @@ -13821,7 +13828,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } } } else { - if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { m_walkAroundType = 0; } else { if (CGeneral::LimitRadianAngle(m_fRotationDest - angleToFaceObjCenter) <= 0.0f) { @@ -13839,7 +13846,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } } } - } else if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR) + } 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; @@ -13847,7 +13854,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } else if (entityOnTopRightOfObj == 1 || entityOnTopRightOfObj && !entityOnTopLeftOfObj && !entityOnBottomLeftOfObj) { m_walkAroundType = 4; } - } else if (objIsSeekTarget && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR) + } 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; @@ -13880,13 +13887,13 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) nextWalkAround = 7; } - CVector nextPosToHead = objMat * LocalPosForWalkAround(adjustedColMin, adjustedColMax, nextWalkAround); + 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); + 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); @@ -13916,11 +13923,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } } - localPosToHead = LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType); + localPosToHead = LocalPosForWalkAround(adjustedColMin, adjustedColMax, m_walkAroundType, goingToEnterCar ? m_vehEnterType : 0, goingToEnterCarAndItsVan); #else if (Abs(angleDiffBtwObjCenterAndForward) < objTopRightHeading) { - if (objIsSeekTarget) { - if (objIsSeekTargetAndVan) { + if (goingToEnterCar) { + if (goingToEnterCarAndItsVan) { if (m_vehEnterType == CAR_DOOR_LR || m_vehEnterType == CAR_DOOR_RR) return; } @@ -13953,9 +13960,9 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } else { if (PI - objTopRightHeading >= Abs(angleDiffBtwObjCenterAndForward)) { if (angleDiffBtwObjCenterAndForward <= 0.0f) { - if (!objIsSeekTarget || !objIsSeekTargetAndVan || m_vehEnterType != CAR_DOOR_LR && m_vehEnterType != CAR_DOOR_RR) { - if (objIsSeekTarget) { - if (m_vehEnterType == CAR_DOOR_RF || (m_vehEnterType == CAR_DOOR_RR && !objIsSeekTargetAndVan)) + 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 @@ -13977,14 +13984,14 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) localPosToHead.z = 0.0f; localPosToHead.y = adjustedColMin.y; } - } else if (objIsSeekTarget && objIsSeekTargetAndVan && (m_vehEnterType == CAR_DOOR_LR || m_vehEnterType == CAR_DOOR_RR)) { + } 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 (objIsSeekTarget) { - if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR && !objIsSeekTargetAndVan) + if (goingToEnterCar) { + if (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR && !goingToEnterCarAndItsVan) return; } if (m_walkAroundType == 1 || m_walkAroundType == 2 @@ -14002,7 +14009,7 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) } } } else { - if (objIsSeekTarget && (!objIsSeekTargetAndVan || m_vehEnterType != CAR_DOOR_LR && m_vehEnterType != CAR_DOOR_RR)) { + 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); From 365f9e9caff6f61ef08ca67526fd85f9a010d965 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 5 Oct 2019 17:32:01 +0300 Subject: [PATCH 28/32] Triangular radar blips --- src/core/Radar.cpp | 72 +++++++++++++++++++++++++++++++++++++++++ src/core/Radar.h | 8 +++++ src/core/config.h | 5 ++- src/render/Sprite2d.cpp | 14 ++++++++ src/render/Sprite2d.h | 2 ++ 5 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 7eff743a..ebb71f5f 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -335,7 +335,18 @@ void CRadar::DrawBlips() 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 } } } @@ -363,7 +374,18 @@ void CRadar::DrawBlips() 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 } } } @@ -417,7 +439,20 @@ void CRadar::DrawBlips() 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 } } } @@ -453,7 +488,20 @@ void CRadar::DrawBlips() 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; @@ -949,6 +997,30 @@ void CRadar::ShowRadarTrace(float x, float y, uint32 size, uint8 red, uint8 gree } #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 diff --git a/src/core/Radar.h b/src/core/Radar.h index 6bb445fd..d6b249db 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -45,6 +45,13 @@ enum eRadarSprite RADAR_SPRITE_COUNT = 21, }; +enum +{ + BLIP_MODE_TRIANGULAR_UP = 0, + BLIP_MODE_TRIANGULAR_DOWN, + BLIP_MODE_SQUARE, +}; + struct CBlip { uint32 m_nColor; @@ -130,6 +137,7 @@ public: 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/config.h b/src/core/config.h index 520bcc72..767abbe4 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -160,4 +160,7 @@ enum Config { #define ANIMATE_PED_COL_MODEL #define VC_PED_PORTS #define NEW_WALK_AROUND_ALGORITHM -#define CANCELLABLE_CAR_ENTER \ No newline at end of file +#define CANCELLABLE_CAR_ENTER + +// Blips +#define TRIANGULAR_BLIPS \ 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; }; }; From 42fbe50739763872320879039e0e908ce9c2c543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sat, 5 Oct 2019 21:50:02 +0300 Subject: [PATCH 29/32] Fixes --- src/core/config.h | 6 +- src/entities/Physical.cpp | 2 +- src/peds/Ped.cpp | 139 ++++++++++++++++++++++++++++++-------- src/peds/Ped.h | 6 +- 4 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/core/config.h b/src/core/config.h index 767abbe4..cfad6d85 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -143,8 +143,9 @@ enum Config { // Pad #define KANGAROO_CHEAT -// Hud +// Hud & radar #define ASPECT_RATIO_SCALE +#define TRIANGULAR_BLIPS // Script #define USE_DEBUG_SCRIPT_LOADER @@ -161,6 +162,3 @@ enum Config { #define VC_PED_PORTS #define NEW_WALK_AROUND_ALGORITHM #define CANCELLABLE_CAR_ENTER - -// Blips -#define TRIANGULAR_BLIPS \ No newline at end of file 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/peds/Ped.cpp b/src/peds/Ped.cpp index 44148f14..cbd32cea 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -520,7 +520,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) bGonnaKillTheCarJacker = false; bFadeOut = false; - bKnockedUpIntoAir = false; + m_ped_flagH1 = false; bHitSteepSlope = false; m_ped_flagH4 = false; bClearObjective = false; @@ -537,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; @@ -3336,7 +3339,7 @@ CPed::ClearAll(void) ClearLookFlag(); bIsPointingGunAt = false; bRenderPedInCar = true; - bKnockedUpIntoAir = false; + m_ped_flagH1 = false; m_pCollidingEntity = nil; } @@ -4021,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)) { @@ -7965,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)) { @@ -8514,9 +8521,9 @@ 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(); @@ -8547,7 +8554,7 @@ CPed::KillPedWithCar(CVehicle *car, float impulse) m_pCollidingEntity = car; } - bKnockedUpIntoAir = false; + m_ped_flagH1 = false; if (car->m_modelIndex != MI_TRAIN && !bHasHitWall) { m_vecMoveSpeed = car->m_vecMoveSpeed * 0.75f; } @@ -9857,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 { - lastCollidingColInOtherDirZ = 501.0f; + 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 { + 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; @@ -9977,8 +10009,17 @@ CPed::ProcessControl(void) offsetToCheck.z += 0.5f; 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; } @@ -10041,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) @@ -13531,6 +13582,19 @@ LocalPosForWalkAround(CVector2D colMin, CVector2D colMax, int walkAround, uint32 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. @@ -13677,10 +13741,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) #ifdef NEW_WALK_AROUND_ALGORITHM else { CVector tl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMax.y, 0.0f) - GetPosition(); - cornerToGo = tl; if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + cornerToGo = tl; m_walkAroundType = 1; - } else { + } 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 @@ -13711,10 +13776,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) else { CVector tr = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMax.y, 0.0f) - GetPosition(); if (tr.Magnitude2D() < cornerToGo.Magnitude2D()) { - cornerToGo = tr; if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + cornerToGo = tr; m_walkAroundType = 2; - } else { + } 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 @@ -13746,10 +13812,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) else { CVector br = obj->GetMatrix() * CVector(adjustedColMax.x, adjustedColMin.y, 0.0f) - GetPosition(); if (br.Magnitude2D() < cornerToGo.Magnitude2D()) { - cornerToGo = br; if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_RF || m_vehEnterType == CAR_DOOR_RR)) { + cornerToGo = br; m_walkAroundType = 5; - } else { + } 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 @@ -13781,10 +13848,11 @@ CPed::SetDirectionToWalkAroundObject(CEntity *obj) else { CVector bl = obj->GetMatrix() * CVector(adjustedColMin.x, adjustedColMin.y, 0.0f) - GetPosition(); if (bl.Magnitude2D() < cornerToGo.Magnitude2D()) { - cornerToGo = bl; if (goingToEnterCar && (m_vehEnterType == CAR_DOOR_LF || m_vehEnterType == CAR_DOOR_LR)) { + cornerToGo = bl; m_walkAroundType = 6; - } else { + } 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 @@ -14114,8 +14182,16 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) } if (CCollision::IsStoredPolyStillValidVerticalLine(pos, potentialGroundZ, intersectionPoint, &m_collPoly)) { bStillOnValidPoly = true; - // VC conditionally sets GetPosition().z here with nonexisting flag in III +#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 { @@ -14184,8 +14260,15 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) bOnBoat = false; } } - // VC conditionally sets GetPosition().z here with nonexisting flag in III +#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; @@ -14290,7 +14373,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) sphereNormal.x = -m_vecMoveSpeed.x / max(0.001f, speed); sphereNormal.y = -m_vecMoveSpeed.y / max(0.001f, speed); GetPosition().z -= 0.05f; - // VC sets bKnockedUpIntoAir here + bKnockedUpIntoAir = true; } #endif sphereNormal.Normalise(); diff --git a/src/peds/Ped.h b/src/peds/Ped.h index bf4849b2..0b1b80d6 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -328,7 +328,7 @@ public: uint8 bGonnaKillTheCarJacker : 1; // only set when car is jacked from right door uint8 bFadeOut : 1; - uint8 bKnockedUpIntoAir : 1; // NOT CERTAIN - has ped been knocked up into the air by a car collision + 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; @@ -342,7 +342,11 @@ public: 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; From dd99edd339a22f0309ae0917ee77c6df31c2525b Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 5 Oct 2019 22:26:29 +0300 Subject: [PATCH 30/32] Fixed a bunch of calculation mistakes in CHud --- src/render/Font.cpp | 8 +- src/render/Hud.cpp | 280 ++++++++++++++++++++++++-------------------- src/render/Hud.h | 2 +- 3 files changed, 158 insertions(+), 132 deletions(-) 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 ae0d4eb3..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; @@ -892,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); } @@ -920,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) { @@ -933,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; @@ -1099,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)); @@ -1109,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; + 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; - } - 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; - 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]); + } } /* @@ -1189,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; @@ -1205,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]); @@ -1272,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"); @@ -1282,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(); } @@ -1324,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++) { @@ -1375,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; @@ -1391,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; @@ -1424,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 From 96eee4f10ffd5b5fccf417aba580108b160e3842 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 6 Oct 2019 02:41:35 +0300 Subject: [PATCH 31/32] Fixed CCamera::SetWideScreenOff dupe, removed goto in CStreaming::RetryLoadFile --- src/control/Script.cpp | 2 +- src/core/Camera.cpp | 22 +++++++++++++++++++--- src/core/Camera.h | 16 ++++++++-------- src/core/Streaming.cpp | 9 +++------ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 1511b233..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++) diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 93680dc1..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); } @@ -33,8 +32,6 @@ 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::SetCamCutSceneOffSet(const CVector&) { EAXJMP(0x46FC30); }; -WRAPPER void CCamera::TakeControlWithSpline(short) { EAXJMP(0x471620); }; WRAPPER void CCamera::RestoreWithJumpCut(void) { EAXJMP(0x46FAE0); }; bool @@ -1333,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 ¢er, 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 de725b19..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; @@ -468,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); @@ -487,8 +488,6 @@ int m_iModeObbeCamIsInForCar; void SetCamCutSceneOffSet(const CVector&); void TakeControlWithSpline(short); - void SetWideScreenOn(void) { m_WideScreenOn = true; } - void SetWideScreenOff(void) { m_WideScreenOn = false; } void RestoreWithJumpCut(void); void dtor(void) { this->CCamera::~CCamera(); } @@ -500,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/Streaming.cpp b/src/core/Streaming.cpp index d15415ea..227a4a9f 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -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; } } From fe2ae13c80024e5167abbbbb6ab130126ab26951 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 6 Oct 2019 02:42:22 +0300 Subject: [PATCH 32/32] Fixed player blip heading when looking left/right/behind --- src/core/Radar.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index ebb71f5f..0d6cbc82 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -277,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());