From a3b519ea6420ea6fb7fbd35cd25fbc329fab5086 Mon Sep 17 00:00:00 2001 From: eray orçunus Date: Sun, 29 Mar 2020 18:26:23 +0300 Subject: CShotInfo, CWanted done, Frontend fix --- src/core/EventList.cpp | 18 ++----- src/core/Frontend.cpp | 43 +++++++++++++---- src/core/Wanted.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++------ src/core/Wanted.h | 4 +- src/core/World.cpp | 14 ++++++ src/core/World.h | 1 + src/core/config.h | 1 + 7 files changed, 166 insertions(+), 40 deletions(-) (limited to 'src/core') diff --git a/src/core/EventList.cpp b/src/core/EventList.cpp index d72e32c4..d1c76f33 100644 --- a/src/core/EventList.cpp +++ b/src/core/EventList.cpp @@ -209,21 +209,9 @@ CEventList::ReportCrimeForEvent(eEventType type, int32 crimeId, bool copsDontCar case EVENT_CAR_SET_ON_FIRE: crime = CRIME_VEHICLE_BURNED; break; default: crime = CRIME_NONE; break; } - -#ifdef VC_PED_PORTS - if (crime == CRIME_HIT_PED && ((CPed*)crimeId)->IsPointerValid() && - FindPlayerPed()->m_pWanted->m_nWantedLevel == 0 && ((CPed*)crimeId)->bBeingChasedByPolice) { - - if(!((CPed*)crimeId)->DyingOrDead()) { - sprintf(gString, "$50 Good Citizen Bonus!"); - AsciiToUnicode(gString, gUString); - CMessages::AddBigMessage(gUString, 5000, 0); - CWorld::Players[CWorld::PlayerInFocus].m_nMoney += 50; - } - } else -#endif - if(crime == CRIME_NONE) - return; + + if(crime == CRIME_NONE) + return; CVector playerPedCoors = FindPlayerPed()->GetPosition(); CVector playerCoors = FindPlayerCoors(); diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 0bade6c7..57cab619 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -1354,23 +1354,39 @@ void CMenuManager::DrawFrontEndNormal() m_aFrontEndSprites[currentSprite].Draw(CRect(MENU_X_LEFT_ALIGNED(50.0f), MENU_Y(50.0f), MENU_X_RIGHT_ALIGNED(50.0f), SCREEN_SCALE_FROM_BOTTOM(95.0f)), CRGBA(255, 255, 255, m_nMenuFadeAlpha > 255 ? 255 : m_nMenuFadeAlpha)); + static float fadeAlpha = 0.0f; + static int lastState = 0; + + // reverseAlpha = PS2 fading (wait for 255->0, then change screen) if (m_nMenuFadeAlpha < 255) { - static uint32 LastFade = 0; + if (lastState == 1 && !reverseAlpha) + fadeAlpha = 0.f; if (m_nMenuFadeAlpha <= 0 && reverseAlpha) { reverseAlpha = false; ChangeScreen(pendingScreen, pendingOption, true, false); } else { + float timestep = CTimer::GetCurrentTimeInCycles() / (float)CTimer::GetCyclesPerMillisecond(); + + // +20 per every 33 ms (1000.f/30.f - original frame limiter fps) if (!reverseAlpha) - m_nMenuFadeAlpha += min((CTimer::GetTimeInMillisecondsPauseMode() - LastFade) / 33.0f, 1.0f) * 20.0f; + fadeAlpha += (timestep * 100.f) * 20.f / 33.f; else - m_nMenuFadeAlpha = max(0, m_nMenuFadeAlpha - min((CTimer::GetTimeInMillisecondsPauseMode() - LastFade) / 33.0f, 1.0f) * 30.0f); + fadeAlpha = max(0.0f, fadeAlpha - (timestep * 100.f) * 30.f / 33.f); - LastFade = CTimer::GetTimeInMillisecondsPauseMode(); + m_nMenuFadeAlpha = fadeAlpha; } + lastState = 0; } else { - if (reverseAlpha) - m_nMenuFadeAlpha -= 20; + if (lastState == 0) fadeAlpha = 255.f; + + if (reverseAlpha) { + float timestep = CTimer::GetCurrentTimeInCycles() / (float)CTimer::GetCyclesPerMillisecond(); + fadeAlpha -= (timestep * 100.f) * 30.f / 33.f; + + m_nMenuFadeAlpha = fadeAlpha; + } + lastState = 1; // TODO: what is this? waiting mouse? if(field_518 == 4){ @@ -1568,13 +1584,20 @@ void CMenuManager::DrawFrontEndNormal() } if (m_nMenuFadeAlpha < 255) { - static uint32 LastFade = 0; - // Famous transparent menu bug. 33.0f = 1000.f/30.f (original frame limiter fps) + // Famous transparent menu bug #ifdef FIX_BUGS - m_nMenuFadeAlpha += min((CTimer::GetTimeInMillisecondsPauseMode() - LastFade) / 33.0f, 1.0f) * 20.0f; - LastFade = CTimer::GetTimeInMillisecondsPauseMode(); + static float fadeAlpha = 0.0f; + if (m_nMenuFadeAlpha == 0 && fadeAlpha > 1.0f) fadeAlpha = 0.0f; + + float timestep = CTimer::GetCurrentTimeInCycles() / (float)CTimer::GetCyclesPerMillisecond(); + + // +20 per every 33 ms (1000.f/30.f - original frame limiter fps) + fadeAlpha += (timestep * 100.f) * 20.f / 33.f; + m_nMenuFadeAlpha = fadeAlpha; #else + static uint32 LastFade = 0; + if(CTimer::GetTimeInMillisecondsPauseMode() - LastFade > 10){ m_nMenuFadeAlpha += 20; LastFade = CTimer::GetTimeInMillisecondsPauseMode(); diff --git a/src/core/Wanted.cpp b/src/core/Wanted.cpp index 7af753e8..29294a2b 100644 --- a/src/core/Wanted.cpp +++ b/src/core/Wanted.cpp @@ -7,19 +7,16 @@ #include "ZoneCull.h" #include "Darkel.h" #include "DMAudio.h" +#include "CopPed.h" #include "Wanted.h" +#include "General.h" int32 &CWanted::MaximumWantedLevel = *(int32*)0x5F7714; // 6 int32 &CWanted::nMaximumWantedLevel = *(int32*)0x5F7718; // 6400 -WRAPPER void CWanted::Reset() { EAXJMP(0x4AD790) }; -WRAPPER void CWanted::Update() { EAXJMP(0x4AD7B0) }; - void CWanted::Initialise() { - int i; - m_nChaos = 0; m_nLastUpdateTime = 0; m_nLastWantedLevelChange = 0; @@ -34,10 +31,12 @@ CWanted::Initialise() m_bArmyRequired = false; m_fCrimeSensitivity = 1.0f; m_nWantedLevel = 0; - m_CopsBeatingSuspect = 0; - for(i = 0; i < 10; i++) + m_CopsBeatingSuspect = 0; + + for (int i = 0; i < ARRAY_SIZE(m_pCops); i++) m_pCops[i] = nil; - ClearQdCrimes(); + + ClearQdCrimes(); } bool @@ -61,7 +60,7 @@ CWanted::AreArmyRequired() int32 CWanted::NumOfHelisRequired() { - if (m_bIgnoredByCops) + if (m_bIgnoredByCops || m_bIgnoredByEveryone) return 0; switch (m_nWantedLevel) { @@ -79,9 +78,10 @@ CWanted::NumOfHelisRequired() void CWanted::SetWantedLevel(int32 level) { - ClearQdCrimes(); if (level > MaximumWantedLevel) level = MaximumWantedLevel; + + ClearQdCrimes(); switch (level) { case 0: m_nChaos = 0; @@ -360,10 +360,107 @@ CWanted::WorkOutPolicePresence(CVector posn, float radius) return numPolice; } +void +CWanted::Update(void) +{ + if (CTimer::GetTimeInMilliseconds() - m_nLastUpdateTime > 1000) { + if (m_nWantedLevel > 1) { + m_nLastUpdateTime = CTimer::GetTimeInMilliseconds(); + } else { + float radius = 18.0f; + CVector playerPos = FindPlayerCoors(); + if (WorkOutPolicePresence(playerPos, radius) == 0) { + m_nLastUpdateTime = CTimer::GetTimeInMilliseconds(); + m_nChaos = max(0, m_nChaos - 1); + UpdateWantedLevel(); + } + } + UpdateCrimesQ(); + bool orderMessedUp = false; + int currCopNum = 0; + bool foundEmptySlot = false; + for (int i = 0; i < ARRAY_SIZE(m_pCops); i++) { + if (m_pCops[i]) { + ++currCopNum; + if (foundEmptySlot) + orderMessedUp = true; + } else { + foundEmptySlot = true; + } + } + if (currCopNum != m_CurrentCops) { + printf("CopPursuit total messed up: re-setting\n"); + m_CurrentCops = currCopNum; + } + if (orderMessedUp) { + printf("CopPursuit pointer list messed up: re-sorting\n"); + bool fixed = true; + for (int i = 0; i < ARRAY_SIZE(m_pCops); i++) { + if (!m_pCops[i]) { + for (int j = i; j < ARRAY_SIZE(m_pCops); j++) { + if (m_pCops[j]) { + m_pCops[i] = m_pCops[j]; + m_pCops[j] = nil; + fixed = false; + break; + } + } + if (fixed) + break; + } + } + } + } +} + +void +CWanted::ResetPolicePursuit(void) +{ + for(int i = 0; i < ARRAY_SIZE(m_pCops); i++) { + CCopPed *cop = m_pCops[i]; + if (!cop) + continue; + + cop->m_bIsInPursuit = false; + cop->m_objective = OBJECTIVE_NONE; + cop->m_prevObjective = OBJECTIVE_NONE; + cop->m_nLastPedState = PED_NONE; + if (!cop->DyingOrDead()) { + cop->SetWanderPath(CGeneral::GetRandomNumberInRange(0.0f, 8.0f)); + } + m_pCops[i] = nil; + } + m_CurrentCops = 0; +} + +void +CWanted::Reset(void) +{ + ResetPolicePursuit(); + Initialise(); +} + +void +CWanted::UpdateCrimesQ(void) +{ + for(int i = 0; i < ARRAY_SIZE(m_aCrimes); i++) { + + CCrimeBeingQd &crime = m_aCrimes[i]; + if (crime.m_nType != CRIME_NONE) { + if (CTimer::GetTimeInMilliseconds() > crime.m_nTime + 500 && !crime.m_bReported) { + ReportCrimeNow(crime.m_nType, crime.m_vecPosn, crime.m_bPoliceDoesntCare); + crime.m_bReported = true; + } + if (CTimer::GetTimeInMilliseconds() > crime.m_nTime + 10000) + crime.m_nType = CRIME_NONE; + } + } +} + STARTPATCHES InjectHook(0x4AD6E0, &CWanted::Initialise, PATCH_JUMP); -// InjectHook(0x4AD790, &CWanted::Reset, PATCH_JUMP); -// InjectHook(0x4AD7B0, &CWanted::Update, PATCH_JUMP); + InjectHook(0x4AD790, &CWanted::Reset, PATCH_JUMP); + InjectHook(0x4AD7B0, &CWanted::Update, PATCH_JUMP); InjectHook(0x4AD900, &CWanted::UpdateWantedLevel, PATCH_JUMP); InjectHook(0x4AD9F0, &CWanted::RegisterCrime, PATCH_JUMP); InjectHook(0x4ADA10, &CWanted::RegisterCrime_Immediately, PATCH_JUMP); @@ -374,10 +471,10 @@ STARTPATCHES InjectHook(0x4ADBC0, &CWanted::AreFbiRequired, PATCH_JUMP); InjectHook(0x4ADBE0, &CWanted::AreArmyRequired, PATCH_JUMP); InjectHook(0x4ADC00, &CWanted::NumOfHelisRequired, PATCH_JUMP); -// InjectHook(0x4ADC40, &CWanted::ResetPolicePursuit, PATCH_JUMP); + InjectHook(0x4ADC40, &CWanted::ResetPolicePursuit, PATCH_JUMP); InjectHook(0x4ADD00, &CWanted::WorkOutPolicePresence, PATCH_JUMP); InjectHook(0x4ADF20, &CWanted::ClearQdCrimes, PATCH_JUMP); InjectHook(0x4ADFD0, &CWanted::AddCrimeToQ, PATCH_JUMP); -// InjectHook(0x4AE090, &CWanted::UpdateCrimesQ, PATCH_JUMP); + InjectHook(0x4AE090, &CWanted::UpdateCrimesQ, PATCH_JUMP); InjectHook(0x4AE110, &CWanted::ReportCrimeNow, PATCH_JUMP); ENDPATCHES diff --git a/src/core/Wanted.h b/src/core/Wanted.h index f6dbe8d0..9823529c 100644 --- a/src/core/Wanted.h +++ b/src/core/Wanted.h @@ -30,7 +30,7 @@ class CCrimeBeingQd public: eCrimeType m_nType; uint32 m_nId; - int32 m_nTime; + uint32 m_nTime; CVector m_vecPosn; bool m_bReported; bool m_bPoliceDoesntCare; @@ -78,6 +78,8 @@ public: void ReportCrimeNow(eCrimeType type, const CVector &coors, bool policeDoesntCare); void UpdateWantedLevel(); void Reset(); + void ResetPolicePursuit(); + void UpdateCrimesQ(); void Update(); bool IsIgnored(void) { return m_bIgnoredByCops || m_bIgnoredByEveryone; } diff --git a/src/core/World.cpp b/src/core/World.cpp index 1dda1056..7913589e 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -19,6 +19,7 @@ #include "Messages.h" #include "Replay.h" #include "Population.h" +#include "Fire.h" CColPoint *gaTempSphereColPoints = (CColPoint*)0x6E64C0; // [32] @@ -1051,6 +1052,19 @@ CWorld::ExtinguishAllCarFiresInArea(CVector point, float range) } } +void +CWorld::SetCarsOnFire(float x, float y, float z, float radius, CEntity *reason) +{ + int poolSize = CPools::GetVehiclePool()->GetSize(); + for (int poolIndex = poolSize - 1; poolIndex >= 0; poolIndex--) { + CVehicle *veh = CPools::GetVehiclePool()->GetSlot(poolIndex); + if (veh && veh->m_status != STATUS_WRECKED && !veh->m_pCarFire && !veh->bFireProof) { + if (Abs(veh->GetPosition().z - z) < 5.0f && Abs(veh->GetPosition().x - x) < radius && Abs(veh->GetPosition().y - y) < radius) + gFireManager.StartFire(veh, reason, 0.8f, true); + } + } +} + void CWorld::Process(void) { diff --git a/src/core/World.h b/src/core/World.h index 4b19e629..68149ab7 100644 --- a/src/core/World.h +++ b/src/core/World.h @@ -130,6 +130,7 @@ public: static void StopAllLawEnforcersInTheirTracks(); static void SetAllCarsCanBeDamaged(bool); static void ExtinguishAllCarFiresInArea(CVector, float); + static void SetCarsOnFire(float, float, float, float, CEntity*); static void Initialise(); static void AddParticles(); diff --git a/src/core/config.h b/src/core/config.h index ba00992a..c44a388a 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -100,6 +100,7 @@ enum Config { NUMPHONES = 50, NUMPEDGROUPS = 31, NUMMODELSPERPEDGROUP = 8, + NUMSHOTINFOS = 100, NUMROADBLOCKS = 600, -- cgit v1.2.3