From 01845812a1e1108aa15e97733812621eac4616ed Mon Sep 17 00:00:00 2001 From: guyE <> Date: Thu, 24 Sep 2020 12:45:45 +0300 Subject: [PATCH 01/10] Experiment From 7861992fe6c8bc02600917c80053e08d9dcaa501 Mon Sep 17 00:00:00 2001 From: majestic Date: Wed, 7 Oct 2020 18:43:50 -0700 Subject: [PATCH 02/10] CWaterCreatures --- src/core/config.h | 1 + src/entities/Entity.cpp | 33 +++++ src/entities/Entity.h | 1 + src/objects/Object.h | 2 +- src/objects/Stinger.cpp | 2 +- src/render/Fluff.cpp | 2 +- src/render/WaterCreatures.cpp | 263 ++++++++++++++++++++++++++++++++++ src/render/WaterCreatures.h | 49 +++++++ src/render/WaterLevel.cpp | 2 +- 9 files changed, 351 insertions(+), 4 deletions(-) create mode 100644 src/render/WaterCreatures.cpp create mode 100644 src/render/WaterCreatures.h diff --git a/src/core/config.h b/src/core/config.h index 475a63f8..079042f0 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -137,6 +137,7 @@ enum Config { NUM_CRANES = 8, NUM_ESCALATORS = 22, + NUM_WATER_CREATURES = 8, NUM_EXPLOSIONS = 48, diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index cf1dd9e7..d7159e8c 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -1207,4 +1207,37 @@ bool CEntity::IsEntityOccluded(void) { } return false; +} + +/* +0x487A10 - SetAtomicAlphaCB +0x4879E0 - SetClumpAlphaCB +*/ + +RpMaterial* SetAtomicAlphaCB(RpMaterial *material, void *data) { + ((RwRGBA*)RpMaterialGetColor(material))->alpha = (uint8)(uintptr)data; + return material; +} + +RpAtomic* SetClumpAlphaCB(RpAtomic *atomic, void *data) { + RpGeometry *geometry = RpAtomicGetGeometry(atomic); + RpGeometrySetFlags(geometry, RpGeometryGetFlags(geometry) | rpGEOMETRYMODULATEMATERIALCOLOR); + RpGeometryForAllMaterials(geometry, SetAtomicAlphaCB, (void*)data); + return atomic; +} + +void CEntity::SetRwObjectAlpha(int32 alpha) { + if (m_rwObject != nil) { + switch (RwObjectGetType(m_rwObject)) { + case rpATOMIC: { + RpGeometry *geometry = RpAtomicGetGeometry(GetFirstAtomic(GetClump())); + RpGeometrySetFlags(geometry, RpGeometryGetFlags(geometry) | rpGEOMETRYMODULATEMATERIALCOLOR); + RpGeometryForAllMaterials(geometry, SetAtomicAlphaCB, (void*)alpha); + break; + } + case rpCLUMP: + RpClumpForAllAtomics((RpClump*)m_rwObject, SetClumpAlphaCB, (void*)alpha); + break; + } + } } \ No newline at end of file diff --git a/src/entities/Entity.h b/src/entities/Entity.h index fd01b6f8..fbf5cb3b 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -179,6 +179,7 @@ public: void ModifyMatrixForTreeInWind(void); void ModifyMatrixForBannerInWind(void); void ProcessLightsForEntity(void); + void SetRwObjectAlpha(int32 alpha); static void AddSteamsFromGround(CPtrList& list); }; diff --git a/src/objects/Object.h b/src/objects/Object.h index 5f0ec0ab..b81e84b6 100644 --- a/src/objects/Object.h +++ b/src/objects/Object.h @@ -8,7 +8,7 @@ enum { MISSION_OBJECT = 2, TEMP_OBJECT = 3, CUTSCENE_OBJECT = 4, - ESCALATOR_OBJECT = 5, + CONTROLLED_SUB_OBJECT = 5, }; enum CollisionSpecialResponseCase diff --git a/src/objects/Stinger.cpp b/src/objects/Stinger.cpp index f33125ee..b3660881 100644 --- a/src/objects/Stinger.cpp +++ b/src/objects/Stinger.cpp @@ -23,7 +23,7 @@ CStingerSegment::CStingerSegment() m_fBuoyancy = GRAVITY * m_fMass * 0.1f; bExplosionProof = true; SetModelIndex(MI_PLC_STINGER); - ObjectCreatedBy = ESCALATOR_OBJECT; + ObjectCreatedBy = CONTROLLED_SUB_OBJECT; NumOfStingerSegments++; } diff --git a/src/render/Fluff.cpp b/src/render/Fluff.cpp index 31bf92a8..f175d872 100644 --- a/src/render/Fluff.cpp +++ b/src/render/Fluff.cpp @@ -1358,7 +1358,7 @@ CEscalator::Update(void) { if (m_pSteps[i]) { m_pSteps[i]->SetPosition(m_pos1); CWorld::Add(m_pSteps[i]); - m_pSteps[i]->ObjectCreatedBy = ESCALATOR_OBJECT; + m_pSteps[i]->ObjectCreatedBy = CONTROLLED_SUB_OBJECT; } } } diff --git a/src/render/WaterCreatures.cpp b/src/render/WaterCreatures.cpp new file mode 100644 index 00000000..906aba4a --- /dev/null +++ b/src/render/WaterCreatures.cpp @@ -0,0 +1,263 @@ +#include "WaterCreatures.h" +#include "ModelIndices.h" +#include "World.h" +#include "WaterLevel.h" +#include "Camera.h" +#include "PlayerPed.h" +#include "config.h" +#include "General.h" + +int CWaterCreatures::nNumActiveSeaLifeForms; +CWaterCreature CWaterCreatures::aWaterCreatures[NUM_WATER_CREATURES]; + +struct WaterCreatureProperties aProperties[65] = { + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_JELLYFISH, 0.01f, 2.2f, 0.0005f, 3.5f }, + { &MI_JELLYFISH01, 0.01f, 2.2f, 0.0005f, 3.5f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_TURTLE, 0.01f, 2.0f, 0.0005f, 4.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_DOLPHIN, 0.03f, 1.5f, 0.0005f, 4.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_SHARK, 0.03f, 0.4f, 0.0005f, 4.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 3.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, +}; + +CWaterCreature::CWaterCreature() { + Free(); +} + +CWaterCreature::~CWaterCreature() { + //looks like unused +} + +void CWaterCreature::Initialise(CObject *pObj, float fRightMult, float fZTurnSpeed, float fWaterDepth, uint32 alpha, int eFishSlotState) { + this->m_pObj = pObj; + this->m_fRightMult = fRightMult; + this->m_fZTurnSpeed = 0.0f; + this->m_fWaterDepth = fWaterDepth; + this->m_alpha = alpha; + this->m_state = eFishSlotState; +} + +void CWaterCreature::Allocate(CObject *pObj, float fRightMult, float fZTurnSpeed, float fWaterDepth, uint32 alpha, int eFishSlotState) { + CWaterCreature::Initialise(pObj, fRightMult, fZTurnSpeed, fWaterDepth, alpha, eFishSlotState); +} + +void CWaterCreature::Free() { + CWaterCreature::Initialise(nil, 0.0f, 0.0f, 0.0f, 0, WATER_CREATURE_DISABLED); +} + +CWaterCreature *CWaterCreatures::GetFishStructSlot() { + for (int i = 0; i < NUM_WATER_CREATURES; i++) + if (aWaterCreatures[i].m_state == WATER_CREATURE_DISABLED) + return &aWaterCreatures[i]; + + return nil; +} + +CObject *CWaterCreatures::CreateSeaLifeForm(CVector pos, int16 modelID, float zRotAngle) { + if (CObject::nNoTempObjects >= 40) + return nil; + + CObject *pObj = new CObject(modelID, true); + + if (!pObj) return nil; + + pObj->GetMatrix().GetPosition() = pos; + pObj->GetMatrix().UpdateRW(); + pObj->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); + pObj->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + pObj->GetMatrix().SetRotateZOnly(DEGTORAD(zRotAngle)); + pObj->GetMatrix().UpdateRW(); + pObj->ObjectCreatedBy = CONTROLLED_SUB_OBJECT; + pObj->bIsStatic = false; + + if (pObj->ObjectCreatedBy == TEMP_OBJECT) { + CObject::nNoTempObjects++; + pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 60000; + } + + pObj->bTouchingWater = true; + pObj->bUnderwater = true; + CWorld::Add(pObj); + + return pObj; +} + +bool CWaterCreatures::IsSpaceForMoreWaterCreatures() { + return nNumActiveSeaLifeForms < NUM_WATER_CREATURES; +} + +float CWaterCreatures::CalculateFishHeading(CVector const& pos1, CVector const& pos2) { + CVector delta = pos1 - pos2; + delta.Normalise(); + + return Atan2(-delta.x, delta.y); +} + +void CWaterCreatures::CreateOne(CVector pos, int16 modelID) { + if (!IsSpaceForMoreWaterCreatures()) + return; + + float fDepth, fLevelNoWaves; + if (TheCamera.IsSphereVisible(pos, 3.0f) + && CWaterLevel::GetWaterDepth(pos, &fDepth, &fLevelNoWaves, nil) && fDepth > 4.5f) { + + if (modelID == -1 || modelID > 64) + modelID = CGeneral::GetRandomNumberInRange(0.0f, 64.0f); + + WaterCreatureProperties *creature = &aProperties[modelID]; + pos.z = fLevelNoWaves - creature->fLevel; + float fRightMult = CGeneral::GetRandomNumberInRange(0.0f, 0.01); + float angle = CWaterCreatures::CalculateFishHeading(FindPlayerPed()->GetPosition(), pos); + + CObject *fish = CreateSeaLifeForm(pos, modelID, angle); + if (!fish) + return; + fish->SetRwObjectAlpha(255); + CWaterCreature *wc = GetFishStructSlot(); + wc->Allocate(fish, fRightMult, 0.0f, creature->fWaterDepth, 255, WATER_CREATURE_ALLOCATED); + nNumActiveSeaLifeForms++; + } +} + +void CWaterCreatures::FreeFishStructSlot(CWaterCreature *wc) { + wc->Free(); +} + +void CWaterCreatures::UpdateAll() { + if (nNumActiveSeaLifeForms == 0) + return; + + CVector playerPos = FindPlayerPed()->GetPosition(); + for (int i = 0; i < NUM_WATER_CREATURES; i++) { + switch (aWaterCreatures[i].m_state) { + case WATER_CREATURE_ALLOCATED: + case WATER_CREATURE_ACTIVE: { + aWaterCreatures[i].m_pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 40000; + if (aWaterCreatures[i].m_pObj->GetIsOnScreen()) { + if ((playerPos - aWaterCreatures[i].m_pObj->GetPosition()).Magnitude() < SQR(75.0f)) { + if (aWaterCreatures[i].m_alpha < 255) + aWaterCreatures[i].m_alpha = Min(aWaterCreatures[i].m_alpha + 4, 255); + CVector newRight = aWaterCreatures[i].m_pObj->GetRight(); + newRight.Normalise(); + aWaterCreatures[i].m_pObj->m_vecMoveSpeed = newRight * aWaterCreatures[i].m_fRightMult; + aWaterCreatures[i].m_pObj->m_vecTurnSpeed = CVector(0.0f, 0.0f, aWaterCreatures[i].m_fZTurnSpeed); + aWaterCreatures[i].m_pObj->bIsStatic = false; + float fDepth = 0.0; + CWaterLevel::GetWaterDepth(aWaterCreatures[i].m_pObj->GetPosition(), &fDepth, nil, nil); + if (fDepth < 0.0f) { + if (aWaterCreatures[i].m_pObj->m_nEndOfLifeTime <= CTimer::GetTimeInMilliseconds() + 40000) + aWaterCreatures[i].m_state = WATER_CREATURE_ACTIVE; + } + else { + aWaterCreatures[i].m_state = WATER_CREATURE_UPDATE; + } + + } + else { + aWaterCreatures[i].m_state = WATER_CREATURE_TO_REMOVE; + } + } + break; + } + case WATER_CREATURE_UPDATE: { + aWaterCreatures[i].m_pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 40000; + if (aWaterCreatures[i].m_alpha <= 0) { + aWaterCreatures[i].m_state = WATER_CREATURE_TO_REMOVE; + } + else { + aWaterCreatures[i].m_alpha = Max(aWaterCreatures[i].m_alpha - 6, 0); + aWaterCreatures[i].m_pObj->SetRwObjectAlpha(aWaterCreatures[i].m_alpha); + CVector newRight = aWaterCreatures[i].m_pObj->GetRight(); + newRight.Normalise(); + newRight.x *= aWaterCreatures[i].m_fRightMult; + newRight.y *= aWaterCreatures[i].m_fRightMult; + newRight.z -= 0.015f; + aWaterCreatures[i].m_pObj->m_vecMoveSpeed = newRight; + + if (!aWaterCreatures[i].m_pObj->GetIsOnScreen()) + aWaterCreatures[i].m_state = WATER_CREATURE_TO_REMOVE; + } + break; + } + case WATER_CREATURE_TO_REMOVE: { + if (aWaterCreatures[i].m_pObj) + CWorld::Remove(aWaterCreatures[i].m_pObj); + FreeFishStructSlot(&aWaterCreatures[i]); + nNumActiveSeaLifeForms--; + aWaterCreatures[i].m_state = WATER_CREATURE_DISABLED; + break; + } + case WATER_CREATURE_DISABLED: + break; + } + } +} + +void CWaterCreatures::RemoveAll() { + for (int i = 0; i < NUM_WATER_CREATURES; i++) { + if (aWaterCreatures[i].m_state != WATER_CREATURE_DISABLED) { + CWorld::Remove(aWaterCreatures[i].m_pObj); + FreeFishStructSlot(&aWaterCreatures[i]); + aWaterCreatures[i].m_state = WATER_CREATURE_DISABLED; + nNumActiveSeaLifeForms--; + } + } +} \ No newline at end of file diff --git a/src/render/WaterCreatures.h b/src/render/WaterCreatures.h new file mode 100644 index 00000000..b935b11d --- /dev/null +++ b/src/render/WaterCreatures.h @@ -0,0 +1,49 @@ +#pragma once +#include "Object.h" + +enum { + WATER_CREATURE_ALLOCATED = 0, + WATER_CREATURE_ACTIVE, + WATER_CREATURE_UPDATE, + WATER_CREATURE_TO_REMOVE, + WATER_CREATURE_DISABLED +}; + +class CWaterCreature { +public: + CObject *m_pObj; + float m_fRightMult; + float m_fZTurnSpeed; + int32 m_alpha; + float m_fWaterDepth; + int32 m_state; + + CWaterCreature(); + ~CWaterCreature(); + void Allocate(CObject *pObj, float fRightMult, float fZTurnSpeed, float fWaterDepth, uint32 alpha, int eFishSlotState); + void Free(); + void Initialise(CObject *pObj, float fRightMult, float fZTurnSpeed, float fWaterDepth, uint32 alpha, int eFishSlotState); +}; + +class CWaterCreatures { + +public: + static CWaterCreature aWaterCreatures[NUM_WATER_CREATURES]; + static int32 nNumActiveSeaLifeForms; + static CObject *CreateSeaLifeForm(CVector pos, int16 modelID, float zRotAngle); + static void CreateOne(CVector pos, int16 modelID); + static void UpdateAll(); + static void FreeFishStructSlot(CWaterCreature *wc); + static bool IsSpaceForMoreWaterCreatures(); + static float CalculateFishHeading(CVector const& pos1, CVector const& pos2); + static void RemoveAll(); + static CWaterCreature* GetFishStructSlot(); +}; + +struct WaterCreatureProperties { + int16 *modelID; + float fRightMult; + float fLevel; + float fUnk2; + float fWaterDepth; +}; \ No newline at end of file diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index efcb6c14..995dbec5 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -2839,7 +2839,7 @@ CWaterLevel::HandleSeaLifeForms() vecPos.y += (fSin + fCos) * fAngle; //TODO(MIAMI) - //CWaterCreatures::CreateOne(vecPos, 0xFFFFFFFF); + //CWaterCreatures::CreateOne(vecPos, -1); } } } From dd039677a097168b0488482a19f55a3e33e8b3c6 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sat, 10 Oct 2020 23:50:00 +0300 Subject: [PATCH 03/10] Zones saving and loading --- src/core/Zones.cpp | 183 +++++++++++++++++++++++---------------------- src/core/Zones.h | 2 + src/core/common.h | 40 ++++++++++ 3 files changed, 136 insertions(+), 89 deletions(-) diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 1eb1513e..288b975e 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -9,7 +9,7 @@ #include "World.h" #include "Timer.h" -//--MIAMI: file almost done (loading/saving will perhaps stay different) +//--MIAMI: file done eLevelName CTheZones::m_CurrLevel; int16 CTheZones::FindIndex; @@ -638,127 +638,132 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) + sizeof(int16) // padding + sizeof(NavigationZoneArray) + sizeof(InfoZoneArray) + sizeof(ZoneInfoArray) + sizeof(TotalNumberOfNavigationZones) + sizeof(TotalNumberOfInfoZones) + sizeof(TotalNumberOfZoneInfos) + + sizeof(int16) // padding + sizeof(MapZoneArray) + sizeof(AudioZoneArray) + sizeof(TotalNumberOfMapZones) + sizeof(NumberOfAudioZones); - WriteSaveHeader(buffer, 'Z', 'N', 'S', '\0', *size - SAVE_HEADER_SIZE); + uint32 length = 0; + WriteSaveHeaderWithLength(buffer, length, 'Z', 'N', 'S', '\0', *size - SAVE_HEADER_SIZE); - WriteSaveBuf(buffer, m_CurrLevel); - WriteSaveBuf(buffer, FindIndex); - WriteSaveBuf(buffer, (int16)0); // padding + WriteSaveBuf(buffer, length, m_CurrLevel); + WriteSaveBuf(buffer, length, FindIndex); + WriteSaveBuf(buffer, length, (int16)0); // padding -// TODO(MIAMI) ? implement SaveOneZone - for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){ - CZone *zone = WriteSaveBuf(buffer, NavigationZoneArray[i]); - zone->child = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].child); - zone->parent = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].parent); - zone->next = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].next); - } + for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++) + SaveOneZone(&NavigationZoneArray[i], &buffer, &length, ZONE_NAVIG); - for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){ - CZone *zone = WriteSaveBuf(buffer, InfoZoneArray[i]); - /* - The call of GetIndexForZonePointer is wrong, as it is - meant for a different array, but the game doesn't brake - if those fields are nil. Let's make sure they are. - */ - assert(InfoZoneArray[i].child == nil); - assert(InfoZoneArray[i].parent == nil); - assert(InfoZoneArray[i].next == nil); - zone->child = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].child); - zone->parent = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].parent); - zone->next = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].next); - } + for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++) + SaveOneZone(&InfoZoneArray[i], &buffer, &length, ZONE_INFO); for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) - WriteSaveBuf(buffer, ZoneInfoArray[i]); + WriteSaveBuf(buffer, length, ZoneInfoArray[i]); - WriteSaveBuf(buffer, TotalNumberOfNavigationZones); - WriteSaveBuf(buffer, TotalNumberOfInfoZones); - WriteSaveBuf(buffer, TotalNumberOfZoneInfos); + WriteSaveBuf(buffer, length, TotalNumberOfNavigationZones); + WriteSaveBuf(buffer, length, TotalNumberOfInfoZones); + WriteSaveBuf(buffer, length, TotalNumberOfZoneInfos); + WriteSaveBuf(buffer, length, (int16)0); // padding - for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) { - CZone* zone = WriteSaveBuf(buffer, MapZoneArray[i]); - - // see above - assert(MapZoneArray[i].child == nil); - assert(MapZoneArray[i].parent == nil); - assert(MapZoneArray[i].next == nil); - zone->child = (CZone*)GetIndexForZonePointer(MapZoneArray[i].child); - zone->parent = (CZone*)GetIndexForZonePointer(MapZoneArray[i].parent); - zone->next = (CZone*)GetIndexForZonePointer(MapZoneArray[i].next); - } + for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) + SaveOneZone(&MapZoneArray[i], &buffer, &length, ZONE_MAPZONE); for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++) - WriteSaveBuf(buffer, AudioZoneArray[i]); + WriteSaveBuf(buffer, length, AudioZoneArray[i]); - WriteSaveBuf(buffer, TotalNumberOfMapZones); - WriteSaveBuf(buffer, NumberOfAudioZones); + WriteSaveBuf(buffer, length, TotalNumberOfMapZones); + WriteSaveBuf(buffer, length, NumberOfAudioZones); VALIDATESAVEBUF(*size) } +void +CTheZones::SaveOneZone(CZone *zone, uint8 **buffer, uint32 *length, eZoneType zoneType) +{ + WriteSaveBuf(*buffer, *length, *(uint32*)&zone->name[0]); + WriteSaveBuf(*buffer, *length, *(uint32*)&zone->name[4]); + + WriteSaveBuf(*buffer, *length, zone->minx); + WriteSaveBuf(*buffer, *length, zone->miny); + WriteSaveBuf(*buffer, *length, zone->minz); + WriteSaveBuf(*buffer, *length, zone->maxx); + WriteSaveBuf(*buffer, *length, zone->maxy); + WriteSaveBuf(*buffer, *length, zone->maxz); + + WriteSaveBuf(*buffer, *length, zone->type); + WriteSaveBuf(*buffer, *length, zone->level); + WriteSaveBuf(*buffer, *length, zone->zoneinfoDay); + WriteSaveBuf(*buffer, *length, zone->zoneinfoNight); + + int32 zoneId; + zoneId = GetIndexForZonePointer(zone->child); + WriteSaveBuf(*buffer, *length, zoneId); + zoneId = GetIndexForZonePointer(zone->parent); + WriteSaveBuf(*buffer, *length, zoneId); + zoneId = GetIndexForZonePointer(zone->next); + WriteSaveBuf(*buffer, *length, zoneId); +} + void CTheZones::LoadAllZones(uint8 *buffer, uint32 size) { INITSAVEBUF int i; - CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE); + uint32 length = 0; + CheckSaveHeaderWithLength(buffer, length, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE); - m_CurrLevel = ReadSaveBuf(buffer); - FindIndex = ReadSaveBuf(buffer); - ReadSaveBuf(buffer); + m_CurrLevel = ReadSaveBuf(buffer, length); + FindIndex = ReadSaveBuf(buffer, length); + ReadSaveBuf(buffer, length); -// TODO(MIAMI) ? implement LoadOneZone - for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){ - NavigationZoneArray[i] = ReadSaveBuf(buffer); + for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++) + LoadOneZone(&NavigationZoneArray[i], &buffer, &length, ZONE_NAVIG); - NavigationZoneArray[i].child = GetPointerForZoneIndex((uintptr)NavigationZoneArray[i].child); - NavigationZoneArray[i].parent = GetPointerForZoneIndex((uintptr)NavigationZoneArray[i].parent); - NavigationZoneArray[i].next = GetPointerForZoneIndex((uintptr)NavigationZoneArray[i].next); - } - - for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){ - InfoZoneArray[i] = ReadSaveBuf(buffer); - - /* - The call of GetPointerForZoneIndex is wrong, as it is - meant for a different array, but the game doesn't brake - if save data stored is -1. - */ - InfoZoneArray[i].child = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].child); - InfoZoneArray[i].parent = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].parent); - InfoZoneArray[i].next = GetPointerForZoneIndex((uintptr)InfoZoneArray[i].next); - assert(InfoZoneArray[i].child == nil); - assert(InfoZoneArray[i].parent == nil); - assert(InfoZoneArray[i].next == nil); - } + for (i = 0; i < ARRAY_SIZE(InfoZoneArray); i++) + LoadOneZone(&InfoZoneArray[i], &buffer, &length, ZONE_INFO); for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) - ZoneInfoArray[i] = ReadSaveBuf(buffer); + ZoneInfoArray[i] = ReadSaveBuf(buffer, length); - TotalNumberOfNavigationZones = ReadSaveBuf(buffer); - TotalNumberOfInfoZones = ReadSaveBuf(buffer); - TotalNumberOfZoneInfos = ReadSaveBuf(buffer); + TotalNumberOfNavigationZones = ReadSaveBuf(buffer, length); + TotalNumberOfInfoZones = ReadSaveBuf(buffer, length); + TotalNumberOfZoneInfos = ReadSaveBuf(buffer, length); + ReadSaveBuf(buffer, length); - for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){ - MapZoneArray[i] = ReadSaveBuf(buffer); - - // see above - MapZoneArray[i].child = GetPointerForZoneIndex((uintptr)MapZoneArray[i].child); - MapZoneArray[i].parent = GetPointerForZoneIndex((uintptr)MapZoneArray[i].parent); - MapZoneArray[i].next = GetPointerForZoneIndex((uintptr)MapZoneArray[i].next); - assert(MapZoneArray[i].child == nil); - assert(MapZoneArray[i].parent == nil); - assert(MapZoneArray[i].next == nil); - } + for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) + LoadOneZone(&MapZoneArray[i], &buffer, &length, ZONE_MAPZONE); for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++) - AudioZoneArray[i] = ReadSaveBuf(buffer); + AudioZoneArray[i] = ReadSaveBuf(buffer, length); - TotalNumberOfMapZones = ReadSaveBuf(buffer); - NumberOfAudioZones = ReadSaveBuf(buffer); + TotalNumberOfMapZones = ReadSaveBuf(buffer, length); + NumberOfAudioZones = ReadSaveBuf(buffer, length); VALIDATESAVEBUF(size) } + +void +CTheZones::LoadOneZone(CZone *zone, uint8 **buffer, uint32 *length, eZoneType zoneType) +{ + *(uint32*)&zone->name[0] = ReadSaveBuf(*buffer, *length); + *(uint32*)&zone->name[4] = ReadSaveBuf(*buffer, *length); + + zone->minx = ReadSaveBuf(*buffer, *length); + zone->miny = ReadSaveBuf(*buffer, *length); + zone->minz = ReadSaveBuf(*buffer, *length); + zone->maxx = ReadSaveBuf(*buffer, *length); + zone->maxy = ReadSaveBuf(*buffer, *length); + zone->maxz = ReadSaveBuf(*buffer, *length); + + zone->type = ReadSaveBuf(*buffer, *length); + zone->level = ReadSaveBuf(*buffer, *length); + zone->zoneinfoDay = ReadSaveBuf(*buffer, *length); + zone->zoneinfoNight = ReadSaveBuf(*buffer, *length); + + int32 zoneId; + zoneId = ReadSaveBuf(*buffer, *length); + zone->child = GetPointerForZoneIndex(zoneId); + zoneId = ReadSaveBuf(*buffer, *length); + zone->parent = GetPointerForZoneIndex(zoneId); + zoneId = ReadSaveBuf(*buffer, *length); + zone->next = GetPointerForZoneIndex(zoneId); +} \ No newline at end of file diff --git a/src/core/Zones.h b/src/core/Zones.h index 92e292b8..3a74427d 100644 --- a/src/core/Zones.h +++ b/src/core/Zones.h @@ -108,5 +108,7 @@ public: static void AddZoneToAudioZoneArray(CZone *zone); static void InitialiseAudioZoneArray(void); static void SaveAllZones(uint8 *buffer, uint32 *length); + static void SaveOneZone(CZone *zone, uint8 **buffer, uint32 *length, eZoneType zoneType); static void LoadAllZones(uint8 *buffer, uint32 length); + static void LoadOneZone(CZone *zone, uint8 **buffer, uint32 *length, eZoneType zoneType); }; diff --git a/src/core/common.h b/src/core/common.h index c4c133fa..0e6bd60f 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -412,6 +412,15 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip) #endif } +inline void SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip) +{ + buf += skip; + length += skip; +#ifdef VALIDATE_SAVE_SIZE + _saveBufCount += skip; +#endif +} + template inline const T ReadSaveBuf(uint8 *&buf) { @@ -420,6 +429,14 @@ inline const T ReadSaveBuf(uint8 *&buf) return value; } +template +inline const T ReadSaveBuf(uint8 *&buf, uint32 &length) +{ + T &value = *(T*)buf; + SkipSaveBuf(buf, length, sizeof(T)); + return value; +} + template inline T *WriteSaveBuf(uint8 *&buf, const T &value) { @@ -429,6 +446,15 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) return p; } +template +inline T *WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value) +{ + T *p = (T*)buf; + *p = value; + SkipSaveBuf(buf, length, sizeof(T)); + return p; +} + #define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32)) @@ -439,6 +465,13 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) WriteSaveBuf(buf, d);\ WriteSaveBuf(buf, size); +#define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \ + WriteSaveBuf(buf, len, a);\ + WriteSaveBuf(buf, len, b);\ + WriteSaveBuf(buf, len, c);\ + WriteSaveBuf(buf, len, d);\ + WriteSaveBuf(buf, len, size); + #define CheckSaveHeader(buf,a,b,c,d,size)\ assert(ReadSaveBuf(buf) == a);\ assert(ReadSaveBuf(buf) == b);\ @@ -446,5 +479,12 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) assert(ReadSaveBuf(buf) == d);\ assert(ReadSaveBuf(buf) == size); +#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size)\ + assert(ReadSaveBuf(buf,len) == a);\ + assert(ReadSaveBuf(buf,len) == b);\ + assert(ReadSaveBuf(buf,len) == c);\ + assert(ReadSaveBuf(buf,len) == d);\ + assert(ReadSaveBuf(buf,len) == size); + void cprintf(char*, ...); \ No newline at end of file From 6fe6d0cb9a4dcce468cf66e6f6bc392542224bd4 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 11 Oct 2020 00:56:16 +0300 Subject: [PATCH 04/10] Finish Text stuff --- src/text/Text.cpp | 80 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/src/text/Text.cpp b/src/text/Text.cpp index 53259ea0..a59516e3 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -9,11 +9,12 @@ #include "Text.h" #include "Timer.h" +//--MIAMI: file done + static wchar WideErrorString[25]; CText TheText; -//--MIAMI: DONE CText::CText(void) { encoding = 'e'; @@ -23,7 +24,6 @@ CText::CText(void) memset(WideErrorString, 0, sizeof(WideErrorString)); } -//--MIAMI: DONE void CText::Load(void) { @@ -95,7 +95,6 @@ CText::Load(void) CFileMgr::SetDir(""); } -//--MIAMI: DONE void CText::Unload(void) { @@ -108,7 +107,6 @@ CText::Unload(void) memset(szMissionTableName, 0, sizeof(szMissionTableName)); } -//--MIAMI: DONE wchar* CText::Get(const char *key) { @@ -158,7 +156,6 @@ wchar FrenchUpperCaseTable[128] = { 253, 254, 255 }; -//--MIAMI: TODO (check tables) wchar CText::GetUpperCase(wchar c) { @@ -190,7 +187,6 @@ CText::GetUpperCase(wchar c) return c; } -//--MIAMI: DONE void CText::UpperCase(wchar *s) { @@ -200,23 +196,28 @@ CText::UpperCase(wchar *s) } } -//--MIAMI: DONE void CText::GetNameOfLoadedMissionText(char *outName) { strcpy(outName, szMissionTableName); } -//--MIAMI: DONE void CText::ReadChunkHeader(ChunkHeader *buf, int32 file, size_t *offset) { +#if DUMB + char *_buf = (char*)buf; + for (int i = 0; i < sizeof(ChunkHeader); i++) { + CFileMgr::Read(file, &_buf[i], 1); + (*offset)++; + } +#else // original code loops 8 times to read 1 byte with CFileMgr::Read, that's retarded CFileMgr::Read(file, (char*)buf, sizeof(ChunkHeader)); *offset += sizeof(ChunkHeader); +#endif } -//--MIAMI: DONE void CText::LoadMissionText(char *MissionTableName) { @@ -307,7 +308,6 @@ CText::LoadMissionText(char *MissionTableName) } -//--MIAMI: DONE void CKeyArray::Load(size_t length, int file, size_t* offset) { @@ -319,14 +319,16 @@ CKeyArray::Load(size_t length, int file, size_t* offset) rawbytes = (char*)entries; #if DUMB - for (uint32 i = 0; i < length; i++) + for (uint32 i = 0; i < length; i++) { CFileMgr::Read(file, &rawbytes[i], 1); + (*offset)++; + } #else CFileMgr::Read(file, rawbytes, length); + *offset += length; #endif } -//--MIAMI: DONE void CKeyArray::Unload(void) { @@ -335,7 +337,6 @@ CKeyArray::Unload(void) numEntries = 0; } -//--MIAMI: DONE void CKeyArray::Update(wchar *chars) { @@ -346,7 +347,6 @@ CKeyArray::Update(wchar *chars) #endif } -//--MIAMI: DONE CKeyEntry* CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high) { @@ -367,7 +367,6 @@ CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 hi return nil; } -//--MIAMI: DONE wchar* #ifdef FIX_BUGS CKeyArray::Search(const char *key, wchar *data, uint8 *result) @@ -403,7 +402,6 @@ CKeyArray::Search(const char *key, uint8 *result) return WideErrorString; } -//--MIAMI: DONE void CData::Load(size_t length, int file, size_t * offset) { @@ -415,14 +413,16 @@ CData::Load(size_t length, int file, size_t * offset) rawbytes = (char*)chars; #if DUMB - for(uint32 i = 0; i < length; i++) + for(uint32 i = 0; i < length; i++){ CFileMgr::Read(file, &rawbytes[i], 1); + (*offset)++; + } #else CFileMgr::Read(file, rawbytes, length); + *offset += length; #endif } -//--MIAMI: DONE void CData::Unload(void) { @@ -431,16 +431,31 @@ CData::Unload(void) numChars = 0; } -//--MIAMI: DONE void CMissionTextOffsets::Load(size_t table_size, int file, size_t *offset, int) { +#if DUMB + size_t num_of_entries = table_size / sizeof(CMissionTextOffsets::Entry); + for (size_t mi = 0; mi < num_of_entries; mi++) { + for (uint32 i = 0; i < sizeof(data[mi].szMissionName); i++) { + CFileMgr::Read(file, &data[i].szMissionName[i], 1); + (*offset)++; + } + char* _buf = (char*)&data[mi].offset; + for (uint32 i = 0; i < sizeof(data[mi].offset); i++) { + CFileMgr::Read(file, &_buf[i], 1); + (*offset)++; + } + } + size = (uint16)num_of_entries; +#else // not exact VC code but smaller and better :P // You can make this size_t if you want to exceed 32-bit boundaries, everything else should be ready. size = (uint16) (table_size / sizeof(CMissionTextOffsets::Entry)); CFileMgr::Read(file, (char*)data, sizeof(CMissionTextOffsets::Entry) * size); *offset += sizeof(CMissionTextOffsets::Entry) * size; +#endif } void @@ -461,8 +476,29 @@ UnicodeToAscii(wchar *src) if(*src < 128) #endif aStr[len] = *src; - else - aStr[len] = '#'; + // convert to CP1252 + else if(*src <= 131) + aStr[len] = *src + 64; + else if (*src <= 141) + aStr[len] = *src + 66; + else if (*src <= 145) + aStr[len] = *src + 68; + else if (*src <= 149) + aStr[len] = *src + 71; + else if (*src <= 154) + aStr[len] = *src + 73; + else if (*src <= 164) + aStr[len] = *src + 75; + else if (*src <= 168) + aStr[len] = *src + 77; + else if (*src <= 204) + aStr[len] = *src + 80; + else switch (*src) { + case 205: aStr[len] = 209; break; + case 206: aStr[len] = 241; break; + case 207: aStr[len] = 191; break; + default: aStr[len] = '#'; break; + } aStr[len] = '\0'; return aStr; } @@ -472,7 +508,7 @@ UnicodeToAsciiForSaveLoad(wchar *src) { static char aStr[256]; int len; - for(len = 0; *src != '\0' && len < 256-1; len++, src++) + for(len = 0; *src != '\0' && len < 256; len++, src++) if(*src < 256) aStr[len] = *src; else From e26e85deb8d18ed99f94a50fd819886673d35c6a Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 11 Oct 2020 10:33:02 +0300 Subject: [PATCH 05/10] Some unicode funcs belong to Font.cpp + small fix --- src/audio/DMAudio.cpp | 1 + src/render/Font.cpp | 26 ++++++++++++++++++++++++++ src/render/Font.h | 5 +++++ src/save/GenericGameStorage.cpp | 1 + src/save/PCSave.cpp | 1 + src/text/Text.cpp | 30 ++---------------------------- src/text/Text.h | 4 ---- 7 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 9d278046..7174c23c 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -5,6 +5,7 @@ #include "AudioManager.h" #include "AudioScriptObject.h" #include "sampman.h" +#include "Font.h" #include "Text.h" #include "crossplatform.h" diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 58e44a5b..d0b554dd 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -4,6 +4,32 @@ #include "TxdStore.h" #include "Font.h" +void +AsciiToUnicode(const char *src, wchar *dst) +{ + while((*dst++ = (unsigned char)*src++) != '\0'); +} + +void +UnicodeStrcat(wchar *dst, wchar *append) +{ + UnicodeStrcpy(&dst[UnicodeStrlen(dst)], append); +} + +void +UnicodeStrcpy(wchar *dst, const wchar *src) +{ + while((*dst++ = *src++) != '\0'); +} + +int +UnicodeStrlen(const wchar *str) +{ + int len; + for(len = 0; *str != '\0'; len++, str++); + return len; +} + CFontDetails CFont::Details; int16 CFont::NewLine; CSprite2d CFont::Sprite[MAX_FONTS]; diff --git a/src/render/Font.h b/src/render/Font.h index 48f5703d..51035601 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -1,5 +1,10 @@ #pragma once +void AsciiToUnicode(const char *src, wchar *dst); +void UnicodeStrcpy(wchar *dst, const wchar *src); +void UnicodeStrcat(wchar *dst, wchar *append); +int UnicodeStrlen(const wchar *str); + struct CFontDetails { CRGBA color; diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 81bcb6b0..a7cafec8 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -11,6 +11,7 @@ #include "Clock.h" #include "Date.h" #include "FileMgr.h" +#include "Font.h" #include "Frontend.h" #include "GameLogic.h" #include "Gangs.h" diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp index 3103c7ab..d8ede0d3 100644 --- a/src/save/PCSave.cpp +++ b/src/save/PCSave.cpp @@ -3,6 +3,7 @@ #include "crossplatform.h" #include "FileMgr.h" +#include "Font.h" #ifdef MORE_LANGUAGES #include "Game.h" #endif diff --git a/src/text/Text.cpp b/src/text/Text.cpp index a4f2af7f..f3324fd7 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -278,12 +278,6 @@ CData::Unload(void) numChars = 0; } -void -AsciiToUnicode(const char *src, wchar *dst) -{ - while((*dst++ = (unsigned char)*src++) != '\0'); -} - char* UnicodeToAscii(wchar *src) { @@ -307,7 +301,7 @@ UnicodeToAsciiForSaveLoad(wchar *src) { static char aStr[256]; int len; - for(len = 0; *src != '\0' && len < 256-1; len++, src++) + for(len = 0; *src != '\0' && len < 256; len++, src++) if(*src < 256) aStr[len] = *src; else @@ -321,7 +315,7 @@ UnicodeToAsciiForMemoryCard(wchar *src) { static char aStr[256]; int len; - for(len = 0; *src != '\0' && len < 256-1; len++, src++) + for(len = 0; *src != '\0' && len < 256; len++, src++) if(*src < 256) aStr[len] = *src; else @@ -330,26 +324,6 @@ UnicodeToAsciiForMemoryCard(wchar *src) return aStr; } -void -UnicodeStrcpy(wchar *dst, const wchar *src) -{ - while((*dst++ = *src++) != '\0'); -} - -void -UnicodeStrcat(wchar *dst, wchar *append) -{ - UnicodeStrcpy(&dst[UnicodeStrlen(dst)], append); -} - -int -UnicodeStrlen(const wchar *str) -{ - int len; - for(len = 0; *str != '\0'; len++, str++); - return len; -} - void TextCopy(wchar *dst, const wchar *src) { diff --git a/src/text/Text.h b/src/text/Text.h index 4be9b6e6..52c17e27 100644 --- a/src/text/Text.h +++ b/src/text/Text.h @@ -1,12 +1,8 @@ #pragma once -void AsciiToUnicode(const char *src, wchar *dst); char *UnicodeToAscii(wchar *src); char *UnicodeToAsciiForSaveLoad(wchar *src); char *UnicodeToAsciiForMemoryCard(wchar *src); -void UnicodeStrcpy(wchar *dst, const wchar *src); -void UnicodeStrcat(wchar *dst, wchar *append); -int UnicodeStrlen(const wchar *str); void TextCopy(wchar *dst, const wchar *src); struct CKeyEntry From b0becb5a2d28550a089e6e0ef2d041956dc887e4 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 11 Oct 2020 10:39:04 +0300 Subject: [PATCH 06/10] UnicodeMakeUpperCase move + arg fix --- src/render/Font.cpp | 14 ++++++++++++++ src/render/Font.h | 1 + src/text/Text.cpp | 16 +--------------- src/text/Text.h | 1 - 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 7459c101..8deac7bf 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -31,6 +31,20 @@ UnicodeStrlen(const wchar *str) return len; } +void +UnicodeMakeUpperCase(wchar *dst, const wchar *src) //idk what to do with it, seems to be incorrect implementation by R* +{ + while (*src != '\0') { + if (*src < 'a' || *src > 'z') + *dst = *src; + else + *dst = *src - 32; + dst++; + src++; + } + *dst = '\0'; +} + CFontDetails CFont::Details; int16 CFont::NewLine; CSprite2d CFont::Sprite[MAX_FONTS]; diff --git a/src/render/Font.h b/src/render/Font.h index f0ca9760..47a39f73 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -4,6 +4,7 @@ void AsciiToUnicode(const char *src, wchar *dst); void UnicodeStrcpy(wchar *dst, const wchar *src); void UnicodeStrcat(wchar *dst, wchar *append); int UnicodeStrlen(const wchar *str); +void UnicodeMakeUpperCase(wchar *dst, const wchar *src); struct CFontDetails { diff --git a/src/text/Text.cpp b/src/text/Text.cpp index a76bc404..5adc576a 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -431,6 +431,7 @@ CData::Unload(void) numChars = 0; } +void CMissionTextOffsets::Load(size_t table_size, int file, size_t *offset, int) { #if DUMB @@ -457,7 +458,6 @@ CMissionTextOffsets::Load(size_t table_size, int file, size_t *offset, int) #endif } -void char* UnicodeToAscii(wchar *src) { @@ -525,20 +525,6 @@ UnicodeToAsciiForMemoryCard(wchar *src) return aStr; } -void -UnicodeMakeUpperCase(wchar *dst, wchar *src) //idk what to do with it, seems to be incorrect implementation by R* -{ - while (*src != '\0') { - if (*src < 'a' || *src > 'z') - *dst = *src; - else - *dst = *src - 32; - dst++; - src++; - } - *dst = '\0'; -} - void TextCopy(wchar *dst, const wchar *src) { diff --git a/src/text/Text.h b/src/text/Text.h index d18c564b..33dc313e 100644 --- a/src/text/Text.h +++ b/src/text/Text.h @@ -4,7 +4,6 @@ char *UnicodeToAscii(wchar *src); char *UnicodeToAsciiForSaveLoad(wchar *src); char *UnicodeToAsciiForMemoryCard(wchar *src); void TextCopy(wchar *dst, const wchar *src); -void UnicodeMakeUpperCase(wchar *dst, wchar *src); struct CKeyEntry { From 8a622a0e724cd00acc7e61b159462355319b39cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sat, 10 Oct 2020 14:23:17 +0300 Subject: [PATCH 07/10] Hud, Fire, OnscreenBlaBla --- src/control/OnscreenTimer.cpp | 142 +++--- src/control/OnscreenTimer.h | 37 +- src/core/Fire.cpp | 118 +++-- src/core/Fire.h | 12 +- src/core/User.cpp | 2 + src/core/config.h | 3 +- src/peds/EmergencyPed.cpp | 8 - src/render/Font.cpp | 3 +- src/render/Hud.cpp | 787 ++++++++++++++++++++-------------- src/render/Hud.h | 55 ++- src/render/WaterCannon.cpp | 10 +- 11 files changed, 680 insertions(+), 497 deletions(-) diff --git a/src/control/OnscreenTimer.cpp b/src/control/OnscreenTimer.cpp index d94e993e..52d00f43 100644 --- a/src/control/OnscreenTimer.cpp +++ b/src/control/OnscreenTimer.cpp @@ -7,29 +7,38 @@ #include "Timer.h" #include "Script.h" #include "OnscreenTimer.h" +#include "Camera.h" + +// --MIAMI: file done void COnscreenTimer::Init() { m_bDisabled = false; - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - m_sEntries[i].m_nTimerOffset = 0; - m_sEntries[i].m_nCounterOffset = 0; + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + m_sCounters[i].m_nCounterOffset = 0; - for(uint32 j = 0; j < 10; j++) { - m_sEntries[i].m_aTimerText[j] = 0; - m_sEntries[i].m_aCounterText[j] = 0; + for(uint32 j = 0; j < ARRAY_SIZE(COnscreenCounterEntry::m_aCounterText); j++) { + m_sCounters[i].m_aCounterText[j] = 0; } - m_sEntries[i].m_nType = COUNTER_DISPLAY_NUMBER; - m_sEntries[i].m_bTimerProcessed = false; - m_sEntries[i].m_bCounterProcessed = false; - m_sEntries[i].m_bTimerGoingDown = true; + m_sCounters[i].m_nType = COUNTER_DISPLAY_NUMBER; + m_sCounters[i].m_bCounterProcessed = false; + } + for(uint32 i = 0; i < NUMONSCREENCLOCKS; i++) { + m_sClocks[i].m_nClockOffset = 0; + + for(uint32 j = 0; j < ARRAY_SIZE(COnscreenTimerEntry::m_aClockText); j++) { + m_sClocks[i].m_aClockText[j] = 0; + } + + m_sClocks[i].m_bClockProcessed = false; + m_sClocks[i].m_bClockGoingDown = true; } } void COnscreenTimer::Process() { if(!CReplay::IsPlayingBack() && !m_bDisabled) { - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - m_sEntries[i].Process(); + for(uint32 i = 0; i < NUMONSCREENCLOCKS; i++) { + m_sClocks[i].Process(); } } } @@ -37,8 +46,19 @@ void COnscreenTimer::Process() { void COnscreenTimer::ProcessForDisplay() { if(CHud::m_Wants_To_Draw_Hud) { m_bProcessed = false; - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - if(m_sEntries[i].ProcessForDisplay()) { + for(uint32 i = 0; i < NUMONSCREENCLOCKS; i++) { + m_sClocks[i].m_bClockProcessed = false; + if (m_sClocks[i].m_nClockOffset != 0) { + m_sClocks[i].ProcessForDisplayClock(); + m_sClocks[i].m_bClockProcessed = true; + m_bProcessed = true; + } + } + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + m_sCounters[i].m_bCounterProcessed = false; + if (m_sCounters[i].m_nCounterOffset != 0) { + m_sCounters[i].ProcessForDisplayCounter(); + m_sCounters[i].m_bCounterProcessed = true; m_bProcessed = true; } } @@ -46,77 +66,81 @@ void COnscreenTimer::ProcessForDisplay() { } void COnscreenTimer::ClearCounter(uint32 offset) { - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - if(offset == m_sEntries[i].m_nCounterOffset) { - m_sEntries[i].m_nCounterOffset = 0; - m_sEntries[i].m_aCounterText[0] = 0; - m_sEntries[i].m_nType = COUNTER_DISPLAY_NUMBER; - m_sEntries[i].m_bCounterProcessed = 0; + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + if(offset == m_sCounters[i].m_nCounterOffset) { + m_sCounters[i].m_nCounterOffset = 0; + m_sCounters[i].m_aCounterText[0] = 0; + m_sCounters[i].m_nType = COUNTER_DISPLAY_NUMBER; + m_sCounters[i].m_bCounterProcessed = 0; } } } void COnscreenTimer::ClearClock(uint32 offset) { - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - if(offset == m_sEntries[i].m_nTimerOffset) { - m_sEntries[i].m_nTimerOffset = 0; - m_sEntries[i].m_aTimerText[0] = 0; - m_sEntries[i].m_bTimerProcessed = 0; + for(uint32 i = 0; i < NUMONSCREENCLOCKS; i++) { + if(offset == m_sClocks[i].m_nClockOffset) { + m_sClocks[i].m_nClockOffset = 0; + m_sClocks[i].m_aClockText[0] = 0; + m_sClocks[i].m_bClockProcessed = 0; + m_sClocks[i].m_bClockGoingDown = true; } } } void COnscreenTimer::AddCounter(uint32 offset, uint16 type, char* text, uint16 pos) { - m_sEntries[pos].m_nCounterOffset = offset; - if (m_sEntries[pos].m_aCounterText[0] != '\0') + if (m_sCounters[pos].m_aCounterText[0] != '\0') return; + + m_sCounters[pos].m_nCounterOffset = offset; if(text) { - strncpy(m_sEntries[pos].m_aCounterText, text, 10); + strncpy(m_sCounters[pos].m_aCounterText, text, ARRAY_SIZE(COnscreenCounterEntry::m_aCounterText)); } else { - m_sEntries[pos].m_aCounterText[0] = 0; + m_sCounters[pos].m_aCounterText[0] = 0; } - m_sEntries[pos].m_nType = type; + m_sCounters[pos].m_nType = type; } void COnscreenTimer::AddClock(uint32 offset, char* text, bool bGoingDown) { - uint32 i = 0; - for(uint32 i = 0; i < NUMONSCREENTIMERENTRIES; i++) { - if(m_sEntries[i].m_nTimerOffset == 0) { + + // dead code in here + uint32 i; + for(i = 0; i < NUMONSCREENCLOCKS; i++) { + if(m_sClocks[i].m_nClockOffset == 0) { break; } return; } - m_sEntries[i].m_nTimerOffset = offset; - m_sEntries[i].m_bTimerGoingDown = bGoingDown; + m_sClocks[i].m_nClockOffset = offset; + m_sClocks[i].m_bClockGoingDown = bGoingDown; if(text) { - strncpy(m_sEntries[i].m_aTimerText, text, 10); + strncpy(m_sClocks[i].m_aClockText, text, ARRAY_SIZE(COnscreenTimerEntry::m_aClockText)); } else { - m_sEntries[i].m_aTimerText[0] = 0; + m_sClocks[i].m_aClockText[0] = 0; } } void COnscreenTimerEntry::Process() { - if(m_nTimerOffset == 0) { + if(m_nClockOffset == 0) { return; } - int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nTimerOffset); + int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nClockOffset); int32 oldTime = *timerPtr; - if (m_bTimerGoingDown) { + if (m_bClockGoingDown) { int32 newTime = oldTime - int32(CTimer::GetTimeStepInMilliseconds()); + *timerPtr = newTime; if (newTime < 0) { *timerPtr = 0; - m_bTimerProcessed = 0; - m_nTimerOffset = 0; - m_aTimerText[0] = 0; + m_bClockProcessed = 0; + m_nClockOffset = 0; + m_aClockText[0] = 0; } else { - *timerPtr = newTime; int32 oldTimeSeconds = oldTime / 1000; - if (oldTimeSeconds < 12 && newTime / 1000 != oldTimeSeconds) { + if (oldTimeSeconds < 12 && newTime / 1000 != oldTimeSeconds && !TheCamera.m_WideScreenOn) { DMAudio.PlayFrontEndSound(SOUND_CLOCK_TICK, newTime / 1000); } } @@ -125,33 +149,13 @@ void COnscreenTimerEntry::Process() { *timerPtr = oldTime + int32(CTimer::GetTimeStepInMilliseconds()); } -bool COnscreenTimerEntry::ProcessForDisplay() { - m_bTimerProcessed = false; - m_bCounterProcessed = false; - - if(m_nTimerOffset == 0 && m_nCounterOffset == 0) { - return false; - } - - if(m_nTimerOffset != 0) { - m_bTimerProcessed = true; - ProcessForDisplayClock(); - } - - if(m_nCounterOffset != 0) { - m_bCounterProcessed = true; - ProcessForDisplayCounter(); - } - return true; -} - void COnscreenTimerEntry::ProcessForDisplayClock() { - uint32 time = *CTheScripts::GetPointerToScriptVariable(m_nTimerOffset); - sprintf(m_bTimerBuffer, "%02d:%02d", time / 1000 / 60, + uint32 time = *CTheScripts::GetPointerToScriptVariable(m_nClockOffset); + sprintf(m_aClockBuffer, "%02d:%02d", time / 1000 / 60 % 100, time / 1000 % 60); } -void COnscreenTimerEntry::ProcessForDisplayCounter() { +void COnscreenCounterEntry::ProcessForDisplayCounter() { uint32 counter = *CTheScripts::GetPointerToScriptVariable(m_nCounterOffset); - sprintf(m_bCounterBuffer, "%d", counter); + sprintf(m_aCounterBuffer, "%d", counter); } diff --git a/src/control/OnscreenTimer.h b/src/control/OnscreenTimer.h index 09473397..8c049d7d 100644 --- a/src/control/OnscreenTimer.h +++ b/src/control/OnscreenTimer.h @@ -9,30 +9,37 @@ enum class COnscreenTimerEntry { public: - uint32 m_nTimerOffset; - uint32 m_nCounterOffset; - char m_aTimerText[10]; - char m_aCounterText[10]; - uint16 m_nType; - char m_bCounterBuffer[42]; - char m_bTimerBuffer[42]; - bool m_bTimerProcessed; - bool m_bTimerGoingDown; - bool m_bCounterProcessed; + uint32 m_nClockOffset; + char m_aClockText[10]; + char m_aClockBuffer[40]; + bool m_bClockProcessed; + bool m_bClockGoingDown; void Process(); - bool ProcessForDisplay(); - void ProcessForDisplayClock(); +}; + +VALIDATE_SIZE(COnscreenTimerEntry, 0x3C); + +class COnscreenCounterEntry +{ +public: + uint32 m_nCounterOffset; + char m_aCounterText[10]; + uint16 m_nType; + char m_aCounterBuffer[40]; + bool m_bCounterProcessed; + void ProcessForDisplayCounter(); }; -VALIDATE_SIZE(COnscreenTimerEntry, 0x74); +VALIDATE_SIZE(COnscreenCounterEntry, 0x3C); class COnscreenTimer { public: - COnscreenTimerEntry m_sEntries[NUMONSCREENTIMERENTRIES]; + COnscreenTimerEntry m_sClocks[NUMONSCREENCLOCKS]; + COnscreenCounterEntry m_sCounters[NUMONSCREENCOUNTERS]; bool m_bProcessed; bool m_bDisabled; @@ -47,4 +54,4 @@ public: void AddClock(uint32 offset, char* text, bool bGoingDown); }; -VALIDATE_SIZE(COnscreenTimer, 0x78); +VALIDATE_SIZE(COnscreenTimer, 0xF4); diff --git a/src/core/Fire.cpp b/src/core/Fire.cpp index a6928def..5b57cb73 100644 --- a/src/core/Fire.cpp +++ b/src/core/Fire.cpp @@ -16,6 +16,9 @@ #include "Ped.h" #include "Fire.h" #include "GameLogic.h" +#include "CarAI.h" + +// --MIAMI: file done CFireManager gFireManager; @@ -26,14 +29,13 @@ CFire::CFire() m_bPropagationFlag = true; m_bAudioSet = true; m_vecPos = CVector(0.0f, 0.0f, 0.0f); - m_pEntity = nil; - m_pSource = nil; - m_nFiremenPuttingOut = 0; m_nExtinguishTime = 0; m_nStartTime = 0; - field_20 = 1; - m_nNextTimeToAddFlames = 0; + m_pEntity = nil; + m_pSource = nil; m_fStrength = 0.8f; + m_fWaterExtinguishCountdown = 1.0f; + m_bExtinguishedWithWater = false; } CFire::~CFire() {} @@ -52,6 +54,8 @@ CFire::ProcessFire(void) CPed *ped = (CPed *)m_pEntity; CVehicle *veh = (CVehicle*)m_pEntity; + m_fWaterExtinguishCountdown = Min(1.0f, 0.002f * CTimer::GetTimeStep() + m_fWaterExtinguishCountdown); + if (m_pEntity) { m_vecPos = m_pEntity->GetPosition(); @@ -109,7 +113,7 @@ CFire::ProcessFire(void) gFireManager.StartFire(FindPlayerPed(), m_pSource, 0.8f, 1); } if (CTimer::GetTimeInMilliseconds() > m_nNextTimeToAddFlames) { - m_nNextTimeToAddFlames = CTimer::GetTimeInMilliseconds() + 80; + m_nNextTimeToAddFlames = CTimer::GetTimeInMilliseconds() + (m_fWaterExtinguishCountdown < 0.3f ? 400 : (m_fWaterExtinguishCountdown < 0.7f ? 200 : 80)); firePos = m_vecPos; if (veh && veh->IsVehicle() && veh->IsCar()) { @@ -170,11 +174,23 @@ CFire::Extinguish(void) m_nExtinguishTime = 0; m_bIsOngoing = false; + m_bExtinguishedWithWater = false; if (m_pEntity) { if (m_pEntity->IsPed()) { - ((CPed *)m_pEntity)->RestorePreviousState(); - ((CPed *)m_pEntity)->m_pFire = nil; + CPed *ped = (CPed*)m_pEntity; + if (ped->CanSetPedState()) { + if (ped->m_nPedState != PED_DRIVING && ped->m_nPedState != PED_FALL) { + if (ped->IsPlayer()) { + ped->SetIdle(); + } else { + ped->m_nLastPedState = PED_NONE; + ped->SetWanderPath(0); + ped->SetWaitState(WAITSTATE_FINISH_FLEE, 0); + } + } + } + ped->m_pFire = nil; } else if (m_pEntity->IsVehicle()) { ((CVehicle *)m_pEntity)->m_pCarFire = nil; } @@ -184,7 +200,7 @@ CFire::Extinguish(void) } void -CFireManager::StartFire(CVector pos, float size, bool propagation) +CFireManager::StartFire(CVector pos, float size, uint8 propagation) { CFire *fire = GetNextFreeFire(); @@ -201,11 +217,12 @@ CFireManager::StartFire(CVector pos, float size, bool propagation) fire->m_nNextTimeToAddFlames = 0; fire->ReportThisFire(); fire->m_fStrength = size; + fire->m_bExtinguishedWithWater = false; } } CFire * -CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength, bool propagation) +CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength, uint8 propagation) { CPed *ped = (CPed *)entityOnFire; CVehicle *veh = (CVehicle *)entityOnFire; @@ -234,10 +251,11 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength ped->SetFlee(pos, 10000); ped->m_fleeFrom = nil; } + ped->m_fleeTimer = CTimer::GetTimeInMilliseconds() + 10000; ped->bDrawLast = false; ped->SetMoveState(PEDMOVE_SPRINT); ped->SetMoveAnim(); - ped->m_nPedState = PED_ON_FIRE; + ped->SetPedState(PED_ON_FIRE); } if (fleeFrom) { if (ped->m_nPedType == PEDTYPE_COP) { @@ -251,6 +269,9 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength } else { if (entityOnFire->IsVehicle()) { veh->m_pCarFire = fire; + if (CModelInfo::IsBikeModel(veh->GetModelIndex()) || CModelInfo::IsCarModel(veh->GetModelIndex())) + CCarAI::TellOccupantsToFleeCar(veh); + if (fleeFrom) { CEventList::RegisterEvent(EVENT_CAR_SET_ON_FIRE, EVENT_ENTITY_VEHICLE, entityOnFire, (CPed *)fleeFrom, 10000); @@ -259,6 +280,7 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength } fire->m_bIsOngoing = true; + fire->m_bExtinguishedWithWater = false; fire->m_bIsScriptFire = false; fire->m_vecPos = entityOnFire->GetPosition(); @@ -297,26 +319,23 @@ CFireManager::Update(void) CFire* CFireManager::FindNearestFire(CVector vecPos, float *pDistance) { - for (int i = 0; i < MAX_FIREMEN_ATTENDING; i++) { - int fireId = -1; - float minDistance = 999999; - for (int j = 0; j < NUM_FIRES; j++) { - if (!m_aFires[j].m_bIsOngoing) - continue; - if (m_aFires[j].m_bIsScriptFire) - continue; - if (m_aFires[j].m_nFiremenPuttingOut != i) - continue; - float distance = (m_aFires[j].m_vecPos - vecPos).Magnitude2D(); - if (distance < minDistance) { - minDistance = distance; - fireId = j; - } + int fireId = -1; + float minDistance = 999999; + for (int j = 0; j < NUM_FIRES; j++) { + if (!m_aFires[j].m_bIsOngoing) + continue; + if (m_aFires[j].m_bIsScriptFire) + continue; + float distance = (m_aFires[j].m_vecPos - vecPos).Magnitude2D(); + if (distance < minDistance) { + minDistance = distance; + fireId = j; } - *pDistance = minDistance; - if (fireId != -1) - return &m_aFires[fireId]; } + *pDistance = minDistance; + if (fireId != -1) + return &m_aFires[fireId]; + return nil; } @@ -369,8 +388,39 @@ CFireManager::ExtinguishPoint(CVector point, float range) } } +bool +CFireManager::ExtinguishPointWithWater(CVector point, float range) +{ + int fireI = 0; + for (int i = 0; i < NUM_FIRES; i++) { + if (m_aFires[i].m_bIsOngoing) { + if ((point - m_aFires[i].m_vecPos).MagnitudeSqr() < sq(range)) { + fireI = i; + break; + } + } + } + if (fireI == NUM_FIRES) + return false; + + CFire *fireToExtinguish = &m_aFires[fireI]; + fireToExtinguish->m_fWaterExtinguishCountdown -= 0.012f * CTimer::GetTimeStep(); + CVector steamPos = fireToExtinguish->m_vecPos + + CVector((CGeneral::GetRandomNumber() - 128) * 31.f / 200.f, + (CGeneral::GetRandomNumber() - 128) * 31.f / 200.f, + CGeneral::GetRandomNumber() / 200.f); + + CParticle::AddParticle(PARTICLE_STEAM_NY_SLOWMOTION, steamPos, CVector(0.f, 0.f, 0.2f), nil, 0.5f); + CParticle::AddParticle(PARTICLE_STEAM_NY_SLOWMOTION, steamPos, CVector(0.f, 0.f, 0.1f), nil, 0.8f); + fireToExtinguish->m_bExtinguishedWithWater = true; + if (fireToExtinguish->m_fWaterExtinguishCountdown < 0.0f ) + fireToExtinguish->Extinguish(); + + return true; +} + int32 -CFireManager::StartScriptFire(const CVector &pos, CEntity *target, float strength, bool propagation) +CFireManager::StartScriptFire(const CVector &pos, CEntity *target, float strength, uint8 propagation) { CFire *fire; CPed *ped = (CPed *)target; @@ -397,12 +447,15 @@ CFireManager::StartScriptFire(const CVector &pos, CEntity *target, float strengt fire->m_vecPos = pos; fire->m_nStartTime = CTimer::GetTimeInMilliseconds() + 400; fire->m_pEntity = target; + fire->m_bExtinguishedWithWater = false; if (target) target->RegisterReference(&fire->m_pEntity); fire->m_pSource = nil; fire->m_nNextTimeToAddFlames = 0; fire->m_fStrength = strength; + fire->m_fWaterExtinguishCountdown = 1.0f; + if (target) { if (target->IsPed()) { ped->m_pFire = fire; @@ -410,7 +463,7 @@ CFireManager::StartScriptFire(const CVector &pos, CEntity *target, float strengt CVector2D pos = target->GetPosition(); ped->SetFlee(pos, 10000); ped->SetMoveAnim(); - ped->m_nPedState = PED_ON_FIRE; + ped->SetPedState(PED_ON_FIRE); } } else if (target->IsVehicle()) { veh->m_pCarFire = fire; @@ -430,8 +483,7 @@ CFireManager::RemoveAllScriptFires(void) { for (int i = 0; i < NUM_FIRES; i++) { if (m_aFires[i].m_bIsScriptFire) { - m_aFires[i].Extinguish(); - m_aFires[i].m_bIsScriptFire = false; + RemoveScriptFire(i); } } } diff --git a/src/core/Fire.h b/src/core/Fire.h index 85e53f61..8126f830 100644 --- a/src/core/Fire.h +++ b/src/core/Fire.h @@ -14,10 +14,10 @@ public: CEntity *m_pSource; uint32 m_nExtinguishTime; uint32 m_nStartTime; - int32 field_20; uint32 m_nNextTimeToAddFlames; - uint32 m_nFiremenPuttingOut; float m_fStrength; + float m_fWaterExtinguishCountdown; + bool m_bExtinguishedWithWater; CFire(); ~CFire(); @@ -34,15 +34,17 @@ class CFireManager public: uint32 m_nTotalFires; CFire m_aFires[NUM_FIRES]; - void StartFire(CVector pos, float size, bool propagation); - CFire *StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength, bool propagation); + + void StartFire(CVector pos, float size, uint8 propagation); + CFire *StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength, uint8 propagation); void Update(void); CFire *FindFurthestFire_NeverMindFireMen(CVector coords, float minRange, float maxRange); CFire *FindNearestFire(CVector vecPos, float *pDistance); CFire *GetNextFreeFire(void); uint32 GetTotalActiveFires() const; void ExtinguishPoint(CVector point, float range); - int32 StartScriptFire(const CVector &pos, CEntity *target, float strength, bool propagation); + bool ExtinguishPointWithWater(CVector point, float range); + int32 StartScriptFire(const CVector &pos, CEntity *target, float strength, uint8 propagation); bool IsScriptFireExtinguish(int16 index); void RemoveAllScriptFires(void); void RemoveScriptFire(int16 index); diff --git a/src/core/User.cpp b/src/core/User.cpp index 53196d03..8d584b74 100644 --- a/src/core/User.cpp +++ b/src/core/User.cpp @@ -10,6 +10,8 @@ #include "World.h" #include "Zones.h" +// --MIAMI: file done + CPlaceName CUserDisplay::PlaceName; COnscreenTimer CUserDisplay::OnscnTimer; CPager CUserDisplay::Pager; diff --git a/src/core/config.h b/src/core/config.h index 475a63f8..f69cf7f8 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -87,7 +87,8 @@ enum Config { NUMMBLURSTREAKS = 4, NUMSKIDMARKS = 32, - NUMONSCREENTIMERENTRIES = 1, + NUMONSCREENCLOCKS = 1, + NUMONSCREENCOUNTERS = 3, NUMRADARBLIPS = 75, NUMGENERALPICKUPS = 320, NUMSCRIPTEDPICKUPS = 16, diff --git a/src/peds/EmergencyPed.cpp b/src/peds/EmergencyPed.cpp index a33e31f9..5b91daad 100644 --- a/src/peds/EmergencyPed.cpp +++ b/src/peds/EmergencyPed.cpp @@ -104,7 +104,6 @@ CEmergencyPed::FiremanAI(void) m_pAttendedFire = nearestFire; #ifdef FIX_BUGS bIsRunning = true; - ++nearestFire->m_nFiremenPuttingOut; #endif } break; @@ -116,10 +115,6 @@ CEmergencyPed::FiremanAI(void) SetMoveState(PEDMOVE_RUN); #ifdef FIX_BUGS bIsRunning = true; - if (m_pAttendedFire) { - --m_pAttendedFire->m_nFiremenPuttingOut; - } - ++nearestFire->m_nFiremenPuttingOut; m_pAttendedFire = nearestFire; } else if (!nearestFire) { #else @@ -153,10 +148,7 @@ CEmergencyPed::FiremanAI(void) case EMERGENCY_PED_STOP: #ifdef FIX_BUGS bIsRunning = false; - if (m_pAttendedFire) #endif - --m_pAttendedFire->m_nFiremenPuttingOut; - m_nPedState = PED_NONE; SetWanderPath(CGeneral::GetRandomNumber() & 7); m_pAttendedFire = nil; diff --git a/src/render/Font.cpp b/src/render/Font.cpp index c0cc333a..26d9f08b 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -1102,6 +1102,7 @@ CFont::ParseToken(wchar *s) switch(*s){ case 'B': Details.bBold = !Details.bBold; + break; case 'N': case 'n': NewLine = 1; @@ -1109,7 +1110,7 @@ CFont::ParseToken(wchar *s) case 'b': SetColor(CRGBA(27, 89, 130, 255)); Details.anonymous_23 = true; break; case 'f': Details.bFlash = !Details.bFlash; - if (Details.bFlash) + if (!Details.bFlash) Details.color.a = 255; break; case 'g': SetColor(CRGBA(255, 150, 225, 255)); Details.anonymous_23 = true; break; diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 36815ab5..52e542f4 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -23,6 +23,9 @@ #include "CutsceneMgr.h" #include "Stats.h" #include "main.h" +#include "General.h" + +// --MIAMI: file done // Game has colors inlined in code. // For easier modification we collect them here: @@ -46,13 +49,14 @@ CRGBA ODDJOB_COLOR(0, 207, 133, 255); CRGBA ODDJOB2_COLOR(97, 194, 247, 255); CRGBA MISSIONTITLE_COLOR(220, 172, 2, 255); -wchar CHud::m_HelpMessage[256]; -wchar CHud::m_LastHelpMessage[256]; +wchar CHud::m_HelpMessage[HELP_MSG_LENGTH]; +wchar CHud::m_LastHelpMessage[HELP_MSG_LENGTH]; uint32 CHud::m_HelpMessageState; uint32 CHud::m_HelpMessageTimer; int32 CHud::m_HelpMessageFadeTimer; -wchar CHud::m_HelpMessageToPrint[256]; -float CHud::m_fHelpMessageTime; +wchar CHud::m_HelpMessageToPrint[HELP_MSG_LENGTH]; +float CHud::m_HelpMessageDisplayTime; +bool CHud::m_HelpMessageDisplayForever; bool CHud::m_HelpMessageQuick; uint32 CHud::m_ZoneState; int32 CHud::m_ZoneFadeTimer; @@ -73,16 +77,16 @@ bool CHud::m_Wants_To_Draw_3dMarkers; wchar CHud::m_BigMessage[6][128]; int16 CHud::m_ItemToFlash; bool CHud::m_HideRadar; -int32 CHud::m_DrawClock; +int32 CHud::m_ClockState; // These aren't really in CHud float CHud::BigMessageInUse[6]; float CHud::BigMessageAlpha[6]; float CHud::BigMessageX[6]; float CHud::OddJob2OffTimer; -bool CHud::CounterOnLastFrame; +bool CHud::CounterOnLastFrame[NUMONSCREENCOUNTERS]; float CHud::OddJob2XOffset; -uint16 CHud::CounterFlashTimer; +uint16 CHud::CounterFlashTimer[NUMONSCREENCOUNTERS]; uint16 CHud::OddJob2Timer; bool CHud::TimerOnLastFrame; int16 CHud::OddJob2On; @@ -110,6 +114,8 @@ uint32 CHud::m_WeaponTimer; uint32 CHud::m_LastDisplayScore; uint32 CHud::m_LastWanted; +uint32 CHud::m_LastWeapon; +uint32 CHud::m_LastTimeEnergyLost; CSprite2d CHud::Sprites[NUM_HUD_SPRITES]; @@ -118,33 +124,82 @@ 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", "radardisc"}, - {"pager", "pagerm"}, - {"", ""}, - {"", ""}, - {"bleeder", ""}, - {"sitesniper", "sitesniperm"}, - {"siteM16", "siteM16m"}, - {"siterocket", "siterocket"} + { "fist", "fistm" }, + { "brassk", "brasskA" }, + { "screw", "screwA" }, + { "golf", "golfA" }, + { "nightstick", "nightstickA" }, + { "knife", "knifeA" }, + { "bat", "batm" }, + { "hammer", "hammerA" }, + { "cleaver", "cleaverA" }, + { "machete", "macheteA" }, + { "sword", "swordA" }, + { "chainsaw", "chainsawA" }, + { "grenade", "grenadeA" }, + { "grenade", "grenadeA" }, + { "teargas", "teargasA" }, + { "molotov", "molotovA" }, + { "rocket", "rocketA" }, + { "handGun1", "handGun1A" }, + { "", "" }, + { "python", "pythonA" }, + { "chromegun", "chromegunA" }, + { "spasshotGun", "spasshotGunA" }, + { "stubshotGun", "stubshotGunA" }, + { "tec9", "tec9A" }, + { "uzi1", "uzi1A" }, + { "uzi2", "uzi2A" }, + { "mp5", "mp5A" }, + { "", "" }, + { "m4", "m4A" }, + { "ruger", "rugerA" }, + { "sniper", "sniperA" }, + { "laserscope", "laserscopeA" }, + { "", "" }, + { "rocket", "rocketA" }, + { "flamer", "flamerA" }, + { "m60", "m60A" }, + { "minigun", "minigunA" }, + { "bomb", "bombA" }, + { "", "" }, + { "camera", "cameraA" }, + { "", "" }, + { "siterocket", "siterocket" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "radardisc", "radardisc" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "sitesniper", "sitesniperm" }, + { "siteM16", "siteM16m" }, + { "sitelaser", "sitelaserm" }, + { "laserdot", "laserdotm" }, + { "viewfinder_128", "viewfinder_128m" }, + { "bleeder", "" } }; RwTexture *gpSniperSightTex; RwTexture *gpRocketSightTex; +RwTexture *gpLaserSightTex; +RwTexture *gpLaserDotTex; +RwTexture *gpViewFinderTex; void CHud::Draw() { @@ -160,7 +215,9 @@ void CHud::Draw() return; if (m_Wants_To_Draw_Hud && !TheCamera.m_WideScreenOn) { + // unused statics in here bool DrawCrossHair = false; + bool CrossHairHidesHud = false; bool DrawCrossHairPC = false; CPlayerPed *playerPed = FindPlayerPed(); @@ -251,38 +308,70 @@ void CHud::Draw() CSprite::RenderOneXLUSprite(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 1.0f, SCREEN_SCALE_X(40.0f), SCREEN_SCALE_Y(40.0f), (100.0f * fMultBright), (200.0f * fMultBright), (100.0f * fMultBright), 255, 1.0f, 255); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); } else { + int sprite = HUD_SITESNIPER; + float xOffset = SCREEN_SCALE_X(210.0f); + float yOffset = SCREEN_SCALE_Y(210.0f); - // TODO(Miami) - // Sniper - rect.left = SCREEN_WIDTH/2 - SCREEN_SCALE_X(210.0f); - rect.top = SCREEN_HEIGHT/2 - SCREEN_SCALE_Y(210.0f); + if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE) + sprite = HUD_SITELASER; + + if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_CAMERA) { + sprite = HUD_VIEWFINDER; + CrossHairHidesHud = true; + xOffset = SCREEN_SCALE_X(256.0f); + yOffset = SCREEN_SCALE_Y(192.0f); + } + + rect.left = SCREEN_WIDTH/2 - xOffset; + rect.top = SCREEN_HEIGHT/2 - yOffset; rect.right = SCREEN_WIDTH/2; rect.bottom = SCREEN_HEIGHT/2; - Sprites[HUD_SITESNIPER].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), 0.01f, 0.01f, 1.0f, 0.0f, 0.01f, 1.0f, 1.0f, 1.0f); rect.left = SCREEN_WIDTH/2; - rect.top = SCREEN_HEIGHT/2 - SCREEN_SCALE_Y(210.0f); - rect.right = SCREEN_WIDTH/2 + SCREEN_SCALE_X(210.0f); + rect.top = SCREEN_HEIGHT/2 - yOffset; + rect.right = SCREEN_WIDTH/2 + xOffset; rect.bottom = SCREEN_HEIGHT/2; - Sprites[HUD_SITESNIPER].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), 0.99f, 0.0f, 0.01f, 0.01f, 0.99f, 1.0f, 0.01f, 1.0f); - rect.left = SCREEN_WIDTH/2 - SCREEN_SCALE_X(210.0f); + rect.left = SCREEN_WIDTH/2 - xOffset; rect.top = SCREEN_HEIGHT/2; rect.right = SCREEN_WIDTH/2; - rect.bottom = SCREEN_HEIGHT/2 + SCREEN_SCALE_Y(210.0f); - Sprites[HUD_SITESNIPER].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + rect.bottom = SCREEN_HEIGHT/2 + yOffset; + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), 0.01f, 0.99f, 1.0f, 0.99f, 0.01f, 0.01f, 1.0f, 0.01f); rect.left = SCREEN_WIDTH/2; rect.top = SCREEN_HEIGHT/2; - rect.right = SCREEN_WIDTH/2 + SCREEN_SCALE_X(210.0f); - rect.bottom = SCREEN_HEIGHT/2 + SCREEN_SCALE_Y(210.0f); - Sprites[HUD_SITESNIPER].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + rect.right = SCREEN_WIDTH/2 + xOffset; + rect.bottom = SCREEN_HEIGHT/2 + yOffset; + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), 0.99f, 0.99f, 0.01f, 0.99f, 0.99f, 0.01f, 0.1f, 0.01f); + + CVector dotPos; + float size = 25.0f; + if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE && FindPlayerPed()->GetWeapon()->LaserScopeDot(&dotPos, &size)) { + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVDESTALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpLaserDotTex)); +#ifdef FIX_BUGS + int intensity = CGeneral::GetRandomNumberInRange(0, 37); +#else + int intensity = CGeneral::GetRandomNumberInRange(0, 35); +#endif + CSprite::RenderOneXLUSprite(dotPos.x, dotPos.y, dotPos.z, + SCREEN_SCALE_X(size), SCREEN_SCALE_Y(size), intensity - 36, 0, 0, intensity - 36, 1.0f, 127); + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + } } } RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); @@ -293,6 +382,9 @@ void CHud::Draw() SpriteBrightness = 0; } + if (CrossHairHidesHud) + return; + /* DrawMoneyCounter */ @@ -303,9 +395,9 @@ void CHud::Draw() float alpha; if (m_LastDisplayScore == CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney) { - alpha = CHud::DrawFadeState(HUD_SCORE_FADING, 0); + alpha = DrawFadeState(HUD_SCORE_FADING, 0); } else { - alpha = CHud::DrawFadeState(HUD_SCORE_FADING, 1); + alpha = DrawFadeState(HUD_SCORE_FADING, 1); m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; } if (m_DisplayScoreState != FADED_OUT) { @@ -334,151 +426,168 @@ void CHud::Draw() /* DrawAmmo */ - CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType); - CWeapon *weapon = playerPed->GetWeapon(); - uint32 AmmoAmount = weaponInfo->m_nAmountofAmmunition; - uint32 AmmoInClip = weapon->m_nAmmoInClip; - uint32 TotalAmmo = weapon->m_nAmmoTotal; - uint32 Ammo, Clip; - - if (AmmoAmount <= 1 || AmmoAmount >= 1000) - sprintf(sTemp, "%d", TotalAmmo); - else { - if (WeaponType == WEAPONTYPE_FLAMETHROWER) { - Clip = AmmoInClip / 10; - - if ((TotalAmmo - AmmoInClip) / 10 <= 9999) - Ammo = (TotalAmmo - AmmoInClip) / 10; - else - Ammo = 9999; - } - else { - Clip = AmmoInClip; - - if ((TotalAmmo - AmmoInClip) > 9999) - Ammo = 9999; - else - Ammo = TotalAmmo - AmmoInClip; - } - - sprintf(sTemp, "%d-%d", Ammo, Clip); - } - - AsciiToUnicode(sTemp, sPrint); - - /* - DrawWeaponIcon - */ - - if (weaponInfo->m_nModelId <= 0) { - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); - Sprites[WeaponType].Draw( - CRect(SCREEN_SCALE_FROM_RIGHT(99.0f), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(91.0f)), - CRGBA(255, 255, 255, 255), - 0.015f, - 0.015f, - 1.0f, - 0.0f, - 0.015f, - 1.0f, - 1.0f, - 1.0f); + if (m_LastWeapon == playerPed->GetWeapon()->m_eWeaponType) { + alpha = CHud::DrawFadeState(HUD_WEAPON_FADING, 0); } else { - CBaseModelInfo *weaponModel = CModelInfo::GetModelInfo(weaponInfo->m_nModelId); - RwTexDictionary *weaponTxd = CTxdStore::GetSlot(weaponModel->GetTxdSlot())->texDict; - if (weaponTxd) { - RwTexture *weaponIcon = RwTexDictionaryFindNamedTexture(weaponTxd, weaponModel->GetName()); - if (weaponIcon) { + alpha = CHud::DrawFadeState(HUD_WEAPON_FADING, 1); + m_LastWeapon = playerPed->GetWeapon()->m_eWeaponType; + } + if (m_WeaponState != FADED_OUT) { + CWeapon *weapon = playerPed->GetWeapon(); + uint32 AmmoAmount = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType)->m_nAmountofAmmunition; + uint32 AmmoInClip = weapon->m_nAmmoInClip; + uint32 TotalAmmo = weapon->m_nAmmoTotal; + uint32 Ammo, Clip; + + if (AmmoAmount <= 1 || AmmoAmount >= 1000) + sprintf(sTemp, "%d", TotalAmmo); + else { + if (WeaponType == WEAPONTYPE_FLAMETHROWER) { + Clip = AmmoInClip / 10; + + Ammo = Min((TotalAmmo - AmmoInClip) / 10, 9999); + } else { + Clip = AmmoInClip; + + Ammo = Min(TotalAmmo - AmmoInClip, 9999); + } + + sprintf(sTemp, "%d-%d", Ammo, Clip); + } + + AsciiToUnicode(sTemp, sPrint); + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType); + /* + DrawWeaponIcon + */ + + if (FrontEndMenuManager.m_PrefsShowHud) { + if (weaponInfo->m_nModelId <= 0) { RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(weaponIcon)); - const float xSize = SCREEN_SCALE_X(64.0f / 2.0f); - const float ySize = SCREEN_SCALE_X(64.0f / 2.0f); - CSprite::RenderOneXLUSprite(SCREEN_SCALE_FROM_RIGHT(99.0f) + xSize, SCREEN_SCALE_Y(25.0f) + ySize, 1.0f, xSize, ySize, - 255, 255, 255, 255, 1.0f, 255); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + if (FrontEndMenuManager.m_PrefsShowHud) + Sprites[WeaponType].Draw( + CRect(SCREEN_SCALE_FROM_RIGHT(99.0f), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(91.0f)), + CRGBA(255, 255, 255, alpha), + 0.015f, + 0.015f, + 1.0f, + 0.0f, + 0.015f, + 1.0f, + 1.0f, + 1.0f); + } else { + CBaseModelInfo *weaponModel = CModelInfo::GetModelInfo(weaponInfo->m_nModelId); + RwTexDictionary *weaponTxd = CTxdStore::GetSlot(weaponModel->GetTxdSlot())->texDict; + if (weaponTxd) { + RwTexture *weaponIcon = RwTexDictionaryFindNamedTexture(weaponTxd, weaponModel->GetName()); + if (weaponIcon) { + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(weaponIcon)); + const float xSize = SCREEN_SCALE_X(64.0f / 2.0f); + const float ySize = SCREEN_SCALE_X(64.0f / 2.0f); + CSprite::RenderOneXLUSprite(SCREEN_SCALE_FROM_RIGHT(99.0f) + xSize, SCREEN_SCALE_Y(25.0f) + ySize, 1.0f, xSize, ySize, + 255, 255, 255, 255, 1.0f, 255); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + } + } + } + + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.8f)); + CFont::SetJustifyOff(); + CFont::SetCentreOn(); + CFont::SetCentreSize(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); + CFont::SetPropOn(); + CFont::SetDropShadowPosition(0); + CFont::SetFontStyle(FONT_STANDARD); + + if (Min(9999, TotalAmmo - AmmoInClip) != 9999 && !CDarkel::FrenzyOnGoing() && weaponInfo->m_nWeaponSlot > 1 && weapon->m_eWeaponType != WEAPONTYPE_DETONATOR) { + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, alpha)); + AMMO_COLOR.a = alpha; + CFont::SetColor(AMMO_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(66.0f), SCREEN_SCALE_Y(90.0f), sPrint); + CFont::SetDropShadowPosition(0); } } } - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.8f)); - CFont::SetJustifyOff(); - CFont::SetCentreOn(); - CFont::SetCentreSize(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); - CFont::SetPropOn(); - CFont::SetDropShadowPosition(0); - CFont::SetFontStyle(FONT_STANDARD); - - if (Min(9999, TotalAmmo - AmmoInClip) != 9999 && !CDarkel::FrenzyOnGoing() && weaponInfo->m_nWeaponSlot > 1 && weapon->m_eWeaponType != WEAPONTYPE_DETONATOR) { - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(AMMO_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(66.0f), SCREEN_SCALE_Y(90.0f), sPrint); - CFont::SetDropShadowPosition(0); - } - /* DrawHealth */ - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetJustifyOff(); - CFont::SetCentreOff(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetRightJustifyOn(); - CFont::SetPropOff(); - CFont::SetFontStyle(FONT_HEADING); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - - if (m_ItemToFlash == ITEM_HEALTH && CTimer::GetFrameCounter() & 8 - || m_ItemToFlash != ITEM_HEALTH - || playerPed->m_fHealth < 10 - && CTimer::GetFrameCounter() & 8) { - if (playerPed->m_fHealth >= 10 - || playerPed->m_fHealth < 10 && CTimer::GetFrameCounter() & 8) { - - AsciiToUnicode("{", sPrintIcon); -#ifdef FIX_BUGS - sprintf(sTemp, "%03d", int32(playerPed->m_fHealth + 0.5f)); -#else - sprintf(sTemp, "%03d", (int32)playerPed->m_fHealth); -#endif - AsciiToUnicode(sTemp, sPrint); - - CFont::SetColor(HEALTH_COLOR); - - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(65.0f), sPrint); - - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) { - // CFont::SetColor(HEALTH_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 54.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); - } - } + if ( m_LastTimeEnergyLost == CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss ) { + CHud::DrawFadeState(HUD_ENERGY_FADING, 0); + } else { + CHud::DrawFadeState(HUD_ENERGY_FADING, 1); + m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; } - /* - DrawArmour - */ - if (m_ItemToFlash == ITEM_ARMOUR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_ARMOUR) { + if (m_EnergyLostState != FADED_OUT) { + CFont::SetBackgroundOff(); CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - if (playerPed->m_fArmour > 1.0f) { - AsciiToUnicode("<", sPrintIcon); + CFont::SetJustifyOff(); + CFont::SetCentreOff(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetRightJustifyOn(); + CFont::SetPropOff(); + CFont::SetFontStyle(FONT_HEADING); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + + if (m_ItemToFlash == ITEM_HEALTH && CTimer::GetFrameCounter() & 8 + || m_ItemToFlash != ITEM_HEALTH + || playerPed->m_fHealth < 10 + && CTimer::GetFrameCounter() & 8) { + if (playerPed->m_fHealth >= 10 + || playerPed->m_fHealth < 10 && CTimer::GetFrameCounter() & 8) { + + AsciiToUnicode("{", sPrintIcon); #ifdef FIX_BUGS - sprintf(sTemp, "%03d", int32(playerPed->m_fArmour + 0.5f)); + sprintf(sTemp, "%03d", int32(playerPed->m_fHealth + 0.5f)); #else - sprintf(sTemp, "%03d", (int32)playerPed->m_fArmour); + sprintf(sTemp, "%03d", (int32)playerPed->m_fHealth); #endif - AsciiToUnicode(sTemp, sPrint); + AsciiToUnicode(sTemp, sPrint); - CFont::SetColor(ARMOUR_COLOR); + CFont::SetColor(HEALTH_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) { + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(65.0f), sPrint); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f), SCREEN_SCALE_Y(65.0f), sPrint); + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) { + // CFont::SetColor(HEALTH_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 54.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); + } + } + } + } - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 1) { - // CFont::SetColor(ARMOUR_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f + 52.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); + /* + DrawArmour + */ + if (m_ItemToFlash == ITEM_ARMOUR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_ARMOUR) { + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + if (playerPed->m_fArmour > 1.0f) { + AsciiToUnicode("<", sPrintIcon); +#ifdef FIX_BUGS + sprintf(sTemp, "%03d", int32(playerPed->m_fArmour + 0.5f)); +#else + sprintf(sTemp, "%03d", (int32)playerPed->m_fArmour); +#endif + AsciiToUnicode(sTemp, sPrint); + + CFont::SetColor(ARMOUR_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) { + + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f), SCREEN_SCALE_Y(65.0f), sPrint); + + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 1) { + // CFont::SetColor(ARMOUR_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f + 52.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); + } + } } } } @@ -486,10 +595,10 @@ void CHud::Draw() /* DrawWantedLevel */ - if (m_LastWanted == playerPed->m_pWanted->m_nWantedLevel) - alpha = CHud::DrawFadeState(HUD_WANTED_FADING, 0); - else { - alpha = CHud::DrawFadeState(HUD_WANTED_FADING, 1); + if (m_LastWanted == playerPed->m_pWanted->m_nWantedLevel) { + alpha = DrawFadeState(HUD_WANTED_FADING, 0); + } else { + alpha = DrawFadeState(HUD_WANTED_FADING, 1); m_LastWanted = playerPed->m_pWanted->m_nWantedLevel; } @@ -787,7 +896,7 @@ void CHud::Draw() /* DrawClock */ - if (m_DrawClock) { + if (m_ClockState) { CFont::SetJustifyOff(); CFont::SetCentreOff(); CFont::SetBackgroundOff(); @@ -814,30 +923,28 @@ void CHud::Draw() wchar sTimer[16]; - if (!CUserDisplay::OnscnTimer.m_sEntries[0].m_bTimerProcessed) + if (!CUserDisplay::OnscnTimer.m_sClocks[0].m_bClockProcessed) TimerOnLastFrame = false; - if (!CUserDisplay::OnscnTimer.m_sEntries[0].m_bCounterProcessed) - CounterOnLastFrame = false; -#ifdef FIX_BUGS -#define TIMER_RIGHT_OFFSET 34.0f // Taken from VC frenzy timer -#else -#define TIMER_RIGHT_OFFSET 27.0f -#endif + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + if (!CUserDisplay::OnscnTimer.m_sCounters[0].m_bCounterProcessed) + CounterOnLastFrame[i] = false; + } + if (CUserDisplay::OnscnTimer.m_bProcessed) { - if (CUserDisplay::OnscnTimer.m_sEntries[0].m_bTimerProcessed) { + if (CUserDisplay::OnscnTimer.m_sClocks[0].m_bClockProcessed) { if (!TimerOnLastFrame) TimerFlashTimer = 1; TimerOnLastFrame = true; - if (TimerFlashTimer) { + if (TimerFlashTimer != 0) { if (++TimerFlashTimer > 50) TimerFlashTimer = 0; } - if (CTimer::GetFrameCounter() & 4 || !TimerFlashTimer) { - AsciiToUnicode(CUserDisplay::OnscnTimer.m_sEntries[0].m_bTimerBuffer, sTimer); + if (CTimer::GetFrameCounter() & 4 || TimerFlashTimer == 0) { + AsciiToUnicode(CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockBuffer, sTimer); CFont::SetPropOn(); CFont::SetBackgroundOff(); CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); @@ -846,126 +953,84 @@ void CHud::Draw() CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetPropOff(); CFont::SetBackGroundOnlyTextOn(); - CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(110.0f) + SCREEN_SCALE_Y(2.0f), sTimer); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); CFont::SetColor(TIMER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET), SCREEN_SCALE_Y(110.0f), sTimer); - - if (CUserDisplay::OnscnTimer.m_sEntries[0].m_aTimerText[0]) { - CFont::SetPropOn(); - CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::SetScale(SCREEN_SCALE_X(0.64f), SCREEN_SCALE_Y(1.35f)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) - SCREEN_SCALE_X(80.0f) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(110.0f) + SCREEN_SCALE_Y(2.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sEntries[0].m_aTimerText)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f), SCREEN_SCALE_Y(110.0f), sTimer); + CFont::SetPropOn(); + if (CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockText[0]) { + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); CFont::SetColor(TIMER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) - SCREEN_SCALE_X(80.0f), SCREEN_SCALE_Y(110.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sEntries[0].m_aTimerText)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f) - SCREEN_SCALE_X(80.0f), SCREEN_SCALE_Y(110.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockText)); } } } - if (CUserDisplay::OnscnTimer.m_sEntries[0].m_bCounterProcessed) { - if (!CounterOnLastFrame) - CounterFlashTimer = 1; - CounterOnLastFrame = true; + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + if (CUserDisplay::OnscnTimer.m_sCounters[i].m_bCounterProcessed) { + if (!CounterOnLastFrame[i]) + CounterFlashTimer[i] = 1; - if (CounterFlashTimer) { - if (++CounterFlashTimer > 50) - CounterFlashTimer = 0; - } + CounterOnLastFrame[i] = true; - if (CTimer::GetFrameCounter() & 4 || !CounterFlashTimer) { - if (CUserDisplay::OnscnTimer.m_sEntries[0].m_nType == COUNTER_DISPLAY_NUMBER) { - AsciiToUnicode(CUserDisplay::OnscnTimer.m_sEntries[0].m_bCounterBuffer, sTimer); - CFont::SetPropOn(); - - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetCentreOff(); - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); - CFont::SetColor(CRGBA(244, 20, 20, 255)); - CFont::SetWrapx(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); - CFont::SetPropOff(); - CFont::SetBackGroundOnlyTextOn(); - - CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) + SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(2.0f), sTimer); - - CFont::SetColor(COUNTER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET), SCREEN_SCALE_Y(132.0f), sTimer); - } else { - int counter = atoi(CUserDisplay::OnscnTimer.m_sEntries[0].m_bCounterBuffer); -#ifdef FIX_BUGS - counter = Min(counter, 100); -#endif - CSprite2d::DrawRect(CRect(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) - SCREEN_SCALE_X(100.0f) / 2 + SCREEN_SCALE_X(4.0f), SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(8.0f), SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) + SCREEN_SCALE_X(4.0f), SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(11.0f) + SCREEN_SCALE_Y(8.0f)), CRGBA(0, 106, 164, 80)); - CSprite2d::DrawRect(CRect(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) - SCREEN_SCALE_X(100.0f) / 2 + SCREEN_SCALE_X(4.0f), SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(8.0f), SCREEN_SCALE_X(counter) / 2.0f + SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET + 50.0f) + SCREEN_SCALE_X(4.0f), SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(11.0f) + SCREEN_SCALE_Y(8.0f)), CRGBA(0, 106, 164, 255)); + if (CounterFlashTimer[i] != 0) { + if (++CounterFlashTimer[i] > 50) + CounterFlashTimer[i] = 0; } - if (CUserDisplay::OnscnTimer.m_sEntries[0].m_aCounterText[0]) { - CFont::SetPropOn(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) - SCREEN_SCALE_X(61.0f) + SCREEN_SCALE_Y(2.0f), SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(2.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sEntries[0].m_aCounterText)); + if (CTimer::GetFrameCounter() & 4 || CounterFlashTimer[i] == 0) { + if (CUserDisplay::OnscnTimer.m_sCounters[i].m_nType == COUNTER_DISPLAY_NUMBER) { + AsciiToUnicode(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterBuffer, sTimer); + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetCentreOff(); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); + CFont::SetWrapx(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); + CFont::SetPropOn(); + CFont::SetBackGroundOnlyTextOn(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(COUNTER_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i) + SCREEN_SCALE_Y(132.0f), sTimer); + } else { + int counter = atoi(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterBuffer); - CFont::SetColor(COUNTER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(TIMER_RIGHT_OFFSET) - SCREEN_SCALE_X(61.0f), SCREEN_SCALE_Y(132.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sEntries[0].m_aCounterText)); + const float barWidth = SCREEN_SCALE_X(100.f / 2.f); + const float right = SCREEN_SCALE_FROM_RIGHT(37.0f); + const float left = right - barWidth; + + const float barHeight = SCREEN_SCALE_Y(11.0f); + const float top = SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(8.0f) + SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i); + const float bottom = top + barHeight; + + // shadow + CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(6.0f), top + SCREEN_SCALE_Y(2.0f), right + SCREEN_SCALE_X(6.0f), bottom + SCREEN_SCALE_Y(2.0f)), CRGBA(0, 0, 0, 255)); + + CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(4.0f), top, right + SCREEN_SCALE_X(4.0f), bottom), CRGBA(27, 89, 130, 255)); + CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(4.0f), top, left + SCREEN_SCALE_X(counter) / 2.0f + SCREEN_SCALE_X(4.0f), bottom), CRGBA(97, 194, 247, 255)); + } + + if (CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterText[0]) { + CFont::SetPropOn(); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(COUNTER_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f) - SCREEN_SCALE_X(61.0f), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i) + SCREEN_SCALE_Y(132.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterText)); + } + // unused/leftover color. I wonder what was it for + CFont::SetColor(CRGBA(244, 225, 91, 255)); } } } } -#undef TIMER_RIGHT_OFFSET - - /* - DrawPager - */ - if (!m_PagerMessage[0] && PagerOn == 1) { - PagerSoundPlayed = false; - PagerOn = 2; - } - if (m_PagerMessage[0] || PagerOn == 2) { - if (!PagerOn) { - PagerOn = 1; - PagerXOffset = 150.0f; - } - if (PagerOn == 1) { - if (PagerXOffset > 0.0f) { - float fStep = PagerXOffset * 0.1f; - if (fStep > 10.0f) - fStep = 10.0f; - PagerXOffset -= fStep * CTimer::GetTimeStep(); - } - if (!PagerSoundPlayed) { - DMAudio.PlayFrontEndSound(SOUND_PAGER, 0); - PagerSoundPlayed = 1; - } - } - else if (PagerOn == 2) { - float fStep = PagerXOffset * 0.1f; - if (fStep < 2.0f) - fStep = 2.0f; - PagerXOffset += fStep; - if (PagerXOffset > 150.0f) { - PagerXOffset = 150.0f; - PagerOn = 0; - } - } - - Sprites[HUD_PAGER].Draw(CRect(SCREEN_SCALE_X(26.0f - PagerXOffset), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_X(160.0 + 26.0f - PagerXOffset), SCREEN_SCALE_Y(80.0f + 27.0f)), CRGBA(255, 255, 255, 255)); - - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(0.84f), SCREEN_SCALE_Y(1.0f)); - CFont::SetColor(PAGER_COLOR); - CFont::SetRightJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetCentreOff(); - CFont::SetJustifyOff(); - CFont::SetPropOff(); - CFont::SetFontStyle(FONT_STANDARD); - CFont::PrintString(SCREEN_SCALE_X(52.0f - PagerXOffset), SCREEN_SCALE_Y(54.0f), m_PagerMessage); - } /* DrawRadar @@ -1126,14 +1191,14 @@ void CHud::Draw() */ if (m_HelpMessage[0]) { - if (!CMessages::WideStringCompare(m_HelpMessage, m_LastHelpMessage, 256)) { + if (!CMessages::WideStringCompare(m_HelpMessage, m_LastHelpMessage, HELP_MSG_LENGTH)) { switch (m_HelpMessageState) { case 0: m_HelpMessageFadeTimer = 0; m_HelpMessageState = 2; m_HelpMessageTimer = 0; - CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, 256); - m_fHelpMessageTime = CMessages::GetWideStringLength(m_HelpMessage) * 0.05f + 3.0f; + CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, HELP_MSG_LENGTH); + m_HelpMessageDisplayTime = CMessages::GetWideStringLength(m_HelpMessage) * 0.05f + 3.0f; if (TheCamera.m_ScreenReductionPercentage == 0.0f) DMAudio.PlayFrontEndSound(SOUND_HUD_SOUND, 0); @@ -1148,7 +1213,7 @@ void CHud::Draw() default: break; } - CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, 256); + CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, HELP_MSG_LENGTH); } float fAlpha = 225.0f; @@ -1158,7 +1223,9 @@ void CHud::Draw() case 1: fAlpha = 225.0f; m_HelpMessageFadeTimer = 600; - if (m_HelpMessageTimer > m_fHelpMessageTime * 1000.0f || m_HelpMessageQuick && m_HelpMessageTimer > 1500.0f) { + if (!m_HelpMessageDisplayForever && m_HelpMessageTimer > m_HelpMessageDisplayTime * 1000.0f || + m_HelpMessageQuick && m_HelpMessageTimer > 1500.0f) { + m_HelpMessageFadeTimer = 600; m_HelpMessageState = 3; } @@ -1187,7 +1254,7 @@ void CHud::Draw() if (m_HelpMessageFadeTimer < 0) { m_HelpMessageState = 2; m_HelpMessageFadeTimer = 0; - CMessages::WideStringCopy(m_HelpMessageToPrint, m_LastHelpMessage, 256); + CMessages::WideStringCopy(m_HelpMessageToPrint, m_LastHelpMessage, HELP_MSG_LENGTH); } fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; break; @@ -1212,7 +1279,7 @@ void CHud::Draw() CFont::SetScale(SCREEN_SCALE_X(0.52f), SCREEN_SCALE_Y(1.1f)); CFont::DrawFonts(); - // CFont::SetColor(CRGBA(175, 175, 175, 255)); + CFont::SetColor(CRGBA(175, 175, 175, 255)); CFont::SetJustifyOff(); #ifdef MORE_LANGUAGES if (CFont::IsJapanese()) @@ -1224,9 +1291,9 @@ void CHud::Draw() CFont::SetBackgroundOn(); CFont::SetBackGroundOnlyTextOff(); CFont::SetDropShadowPosition(0); - CFont::SetColor(CRGBA(175, 175, 175, 255)); CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.9f)); - CFont::PrintString(SCREEN_SCALE_X(34.0f), SCREEN_SCALE_Y(28.0f + (150.0f - PagerXOffset) * 0.6f), CHud::m_HelpMessageToPrint); + CFont::SetColor(CRGBA(175, 175, 175, 255)); + CFont::PrintString(SCREEN_SCALE_X(34.0f), SCREEN_SCALE_Y(28.0f + (150.0f - PagerXOffset) * 0.6f), m_HelpMessageToPrint); CFont::SetAlphaFade(255.0f); CFont::SetWrapx(SCREEN_WIDTH); } @@ -1320,10 +1387,10 @@ void CHud::Draw() else { BigMessageInUse[2] = 1.0f; BigMessageAlpha[2] = 0.0f; - if (CHud::m_VehicleState != 0) - CHud::m_VehicleState = 0; - if (CHud::m_ZoneState != 0) - CHud::m_ZoneState = 0; + if (m_VehicleState != 0) + m_VehicleState = 0; + if (m_ZoneState != 0) + m_ZoneState = 0; } } else { @@ -1332,7 +1399,6 @@ void CHud::Draw() } } -// --MIAMI: Done void CHud::DrawAfterFade() { RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); @@ -1522,7 +1588,7 @@ void CHud::DrawAfterFade() BigMessageInUse[1] = 120.0f; BigMessageAlpha[1] -= CTimer::GetTimeStepInMilliseconds(); } - if (BigMessageAlpha[1] <= 0) { + if (BigMessageAlpha[1] <= 0.0f) { m_BigMessage[1][0] = 0; BigMessageInUse[1] = 0.0f; BigMessageAlpha[1] = 0.0f; @@ -1558,12 +1624,11 @@ void CHud::DrawAfterFade() void CHud::GetRidOfAllHudMessages() { - m_ZoneState = 0; - m_pLastZoneName = nil; m_ZoneNameTimer = 0; m_pZoneName = nil; + m_ZoneState = 0; - for (int i = 0; i < 256; i++) { + for (int i = 0; i < HELP_MSG_LENGTH; i++) { m_HelpMessage[i] = 0; m_LastHelpMessage[i] = 0; m_HelpMessageToPrint[i] = 0; @@ -1573,15 +1638,15 @@ void CHud::GetRidOfAllHudMessages() m_HelpMessageFadeTimer = 0; m_HelpMessageState = 0; m_HelpMessageQuick = 0; - m_fHelpMessageTime = 1.0f; + m_HelpMessageDisplayForever = false; + m_HelpMessageDisplayTime = 1.0f; m_VehicleName = nil; - m_pLastVehicleName = nil; m_pVehicleNameToPrint = nil; m_VehicleNameTimer = 0; m_VehicleFadeTimer = 0; m_VehicleState = 0; - for (int i = 0; i < 256; i++) + for (int i = 0; i < ARRAY_SIZE(m_Message); i++) m_Message[i] = 0; for (int i = 0; i < 6; i++) { @@ -1631,21 +1696,34 @@ void CHud::Initialise() Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask); } + m_pLastZoneName = nil; GetRidOfAllHudMessages(); + m_pLastVehicleName = nil; if (gpSniperSightTex == nil) - gpSniperSightTex = RwTextureRead("sitesniper", nil); + gpSniperSightTex = RwTextureRead("sitesniper", nil); // unused if (gpRocketSightTex == nil) gpRocketSightTex = RwTextureRead("siterocket", nil); + if (gpLaserSightTex == nil) + gpLaserSightTex = RwTextureRead("sitelaser", nil); // unused + if (gpLaserDotTex == nil) + gpLaserDotTex = RwTextureRead("laserdot", "laserdotm"); + if (gpViewFinderTex == nil) + gpViewFinderTex = RwTextureRead("viewfinder_128", "viewfinder_128m"); // unused - m_DrawClock = 1; - CounterOnLastFrame = false; + m_ClockState = 1; + CounterOnLastFrame[0] = false; + CounterOnLastFrame[1] = false; + CounterOnLastFrame[2] = false; + m_ItemToFlash = ITEM_NONE; OddJob2Timer = 0; OddJob2OffTimer = 0.0f; OddJob2On = 0; OddJob2XOffset = 0.0f; - CounterFlashTimer = 0; + CounterFlashTimer[0] = 0; + CounterFlashTimer[1] = 0; + CounterFlashTimer[2] = 0; TimerOnLastFrame = false; TimerFlashTimer = 0; SpriteBrightness = 0; @@ -1676,7 +1754,9 @@ void CHud::Initialise() m_HideRadar = false; m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; + m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; m_LastWanted = 0; + m_LastWeapon = 0; CTxdStore::PopCurrentTxd(); } @@ -1685,16 +1765,22 @@ void CHud::ReInitialise() { m_Wants_To_Draw_Hud = true; m_Wants_To_Draw_3dMarkers = true; + m_pLastZoneName = nil; GetRidOfAllHudMessages(); + m_pLastVehicleName = nil; - CounterOnLastFrame = false; + CounterOnLastFrame[0] = false; + CounterOnLastFrame[1] = false; + CounterOnLastFrame[2] = false; m_ItemToFlash = ITEM_NONE; - m_DrawClock = 1; + m_ClockState = 1; OddJob2Timer = 0; OddJob2OffTimer = 0.0f; OddJob2On = 0; OddJob2XOffset = 0.0f; - CounterFlashTimer = 0; + CounterFlashTimer[0] = 0; + CounterFlashTimer[1] = 0; + CounterFlashTimer[2] = 0; TimerOnLastFrame = false; TimerFlashTimer = 0; SpriteBrightness = 0; @@ -1725,15 +1811,20 @@ void CHud::ReInitialise() { m_HideRadar = false; m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; + m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; m_LastWanted = 0; + m_LastWeapon = 0; } wchar LastBigMessage[6][128]; -void CHud::SetBigMessage(wchar *message, int16 style) +void CHud::SetBigMessage(wchar *message, uint16 style) { int i = 0; + if (BigMessageInUse[style] != 0.0f) + return; + if (style == 5) { for (i = 0; i < 128; i++) { if (message[i] == 0) @@ -1758,18 +1849,42 @@ void CHud::SetBigMessage(wchar *message, int16 style) m_BigMessage[style][i] = 0; } -void CHud::SetHelpMessage(wchar *message, bool quick) +void CHud::SetHelpMessage(wchar *message, bool quick, bool displayForever) { if (!CReplay::IsPlayingBack()) { - CMessages::WideStringCopy(m_HelpMessage, message, 256); - CMessages::InsertPlayerControlKeysInString(m_HelpMessage); - - for (int i = 0; i < 256; i++) { + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_HelpMessage[i] = 0; + } + for (int i = 0; i < HELP_MSG_LENGTH; i++) { m_LastHelpMessage[i] = 0; } + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_HelpMessageToPrint[i] = 0; + } + + CMessages::WideStringCopy(m_HelpMessage, message, HELP_MSG_LENGTH); + CMessages::InsertPlayerControlKeysInString(m_HelpMessage); + if (m_HelpMessageState == 0 || !CMessages::WideStringCompare(m_HelpMessage, m_HelpMessageToPrint, HELP_MSG_LENGTH)) { + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_LastHelpMessage[i] = 0; + } + + if (!message) { + m_HelpMessage[0] = 0; + m_HelpMessageToPrint[0] = 0; + } + if (!displayForever) { + m_HelpMessageState = displayForever; + } else { + m_HelpMessageState = 1; + CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, HELP_MSG_LENGTH); + CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, HELP_MSG_LENGTH); + } + + m_HelpMessageQuick = quick; + m_HelpMessageDisplayForever = displayForever; + } - m_HelpMessageState = 0; - m_HelpMessageQuick = quick; } } @@ -1778,11 +1893,10 @@ bool CHud::IsHelpMessageBeingDisplayed(void) return m_HelpMessageState != 0; } - void CHud::SetMessage(wchar *message) { int i = 0; - for (i = 0; i < 256; i++) { + for (i = 0; i < ARRAY_SIZE(m_Message); i++) { if (message[i] == 0) break; @@ -1794,7 +1908,7 @@ void CHud::SetMessage(wchar *message) void CHud::SetPagerMessage(wchar *message) { int i = 0; - for (i = 0; i < 256; i++) { + for (i = 0; i < ARRAY_SIZE(m_PagerMessage); i++) { if (message[i] == 0) break; @@ -1825,6 +1939,15 @@ void CHud::Shutdown() RwTextureDestroy(gpRocketSightTex); gpRocketSightTex = nil; + RwTextureDestroy(gpLaserSightTex); + gpLaserSightTex = nil; + + RwTextureDestroy(gpLaserDotTex); + gpLaserDotTex = nil; + + RwTextureDestroy(gpViewFinderTex); + gpViewFinderTex = nil; + int HudTXD = CTxdStore::FindTxdSlot("hud"); CTxdStore::RemoveTxdSlot(HudTXD); } diff --git a/src/render/Hud.h b/src/render/Hud.h index f4c0d8c4..a4b9609a 100644 --- a/src/render/Hud.h +++ b/src/render/Hud.h @@ -1,6 +1,11 @@ #pragma once #include "Sprite2d.h" +#define HELP_MSG_LENGTH 256 + +#define HUD_TEXT_SCALE_X 0.7f +#define HUD_TEXT_SCALE_Y 1.25f + enum eItems { ITEM_NONE = -1, @@ -31,41 +36,29 @@ enum eFadeOperation enum eSprites { HUD_FIST, - HUD_BAT, - HUD_PISTOL, - HUD_UZI, - HUD_SHOTGUN, - HUD_AK47, - HUD_M16, - HUD_SNIPER, - HUD_ROCKET, - HUD_FLAME, - HUD_MOLOTOV, - HUD_GRENADE, - HUD_DETONATOR, - HUD_RADARDISC = 15, - HUD_PAGER = 16, - HUD_SITESNIPER = 20, + HUD_SITEROCKET = 41, + HUD_RADARDISC = 50, + HUD_SITESNIPER = 63, HUD_SITEM16, - HUD_SITEROCKET, - NUM_HUD_SPRITES, + HUD_SITELASER, + HUD_LASERDOT, + HUD_VIEWFINDER, + HUD_BLEEDER, + NUM_HUD_SPRITES = 69, }; -#define HUD_TEXT_SCALE_X 0.7f -#define HUD_TEXT_SCALE_Y 1.25f - class CHud { public: static CSprite2d Sprites[NUM_HUD_SPRITES]; - static wchar m_HelpMessage[256]; - static wchar m_LastHelpMessage[256]; + static wchar m_HelpMessage[HELP_MSG_LENGTH]; + static wchar m_LastHelpMessage[HELP_MSG_LENGTH]; static uint32 m_HelpMessageState; static uint32 m_HelpMessageTimer; static int32 m_HelpMessageFadeTimer; - static wchar m_HelpMessageToPrint[256]; - static float &m_HelpMessageDisplayTime; - static float m_fHelpMessageTime; + static wchar m_HelpMessageToPrint[HELP_MSG_LENGTH]; + static float m_HelpMessageDisplayTime; + static bool m_HelpMessageDisplayForever; static bool m_HelpMessageQuick; static uint32 m_ZoneState; static int32 m_ZoneFadeTimer; @@ -86,16 +79,16 @@ public: static wchar m_BigMessage[6][128]; static int16 m_ItemToFlash; static bool m_HideRadar; - static int32 m_DrawClock; + static int32 m_ClockState; // These aren't really in CHud static float BigMessageInUse[6]; static float BigMessageAlpha[6]; static float BigMessageX[6]; static float OddJob2OffTimer; - static bool CounterOnLastFrame; + static bool CounterOnLastFrame[NUMONSCREENCOUNTERS]; static float OddJob2XOffset; - static uint16 CounterFlashTimer; + static uint16 CounterFlashTimer[NUMONSCREENCOUNTERS]; static uint16 OddJob2Timer; static bool TimerOnLastFrame; static int16 OddJob2On; @@ -121,6 +114,8 @@ public: static uint32 m_LastDisplayScore; static uint32 m_LastWanted; + static uint32 m_LastWeapon; + static uint32 m_LastTimeEnergyLost; public: static void Draw(); @@ -131,8 +126,8 @@ public: #endif static void Initialise(); static void ReInitialise(); - static void SetBigMessage(wchar *message, int16 style); - static void SetHelpMessage(wchar *message, bool quick); + static void SetBigMessage(wchar *message, uint16 style); + static void SetHelpMessage(wchar *message, bool quick, bool displayForever = false); static bool IsHelpMessageBeingDisplayed(void); static void SetMessage(wchar *message); static void SetPagerMessage(wchar *message); diff --git a/src/render/WaterCannon.cpp b/src/render/WaterCannon.cpp index 2b34db37..bd2b9a68 100644 --- a/src/render/WaterCannon.cpp +++ b/src/render/WaterCannon.cpp @@ -77,9 +77,13 @@ void CWaterCannon::Update_OncePerFrame(int16 index) } } - int32 extinguishingPoint = CGeneral::GetRandomNumber() & (NUM_SEGMENTPOINTS - 1); - if ( m_abUsed[extinguishingPoint] ) - gFireManager.ExtinguishPoint(m_avecPos[extinguishingPoint], 3.0f); + for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) + { + if ( m_abUsed[i] && gFireManager.ExtinguishPointWithWater(m_avecPos[i], 4.0f) ) + { + break; + } + } if ( ((index + CTimer::GetFrameCounter()) & 3) == 0 ) PushPeds(); From b1e235535c513fde1ced6f7b255c7d5a04bee712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 12 Oct 2020 12:16:24 +0300 Subject: [PATCH 08/10] Cutscene aspect ratio fix --- src/render/Draw.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/render/Draw.cpp b/src/render/Draw.cpp index 131534a3..912399c9 100644 --- a/src/render/Draw.cpp +++ b/src/render/Draw.cpp @@ -24,12 +24,17 @@ float CDraw::CalculateAspectRatio(void) { if (FrontEndMenuManager.m_PrefsUseWideScreen) { +#ifdef ASPECT_RATIO_SCALE + if (TheCamera.m_WideScreenOn) + CDraw::ms_fAspectRatio = FrontEndMenuManager.m_PrefsUseWideScreen == AR_AUTO ? + (5.f / 3.f) * (SCREEN_WIDTH / SCREEN_HEIGHT) / (16.f / 9.f) : + 5.f / 3.f; // It's used on theatrical showings according to Wiki + else + CDraw::ms_fAspectRatio = FrontEndMenuManager.m_PrefsUseWideScreen == AR_AUTO ? SCREEN_WIDTH / SCREEN_HEIGHT : 16.f / 9.f; +#else if (TheCamera.m_WideScreenOn) CDraw::ms_fAspectRatio = 5.f / 3.f; // It's used on theatrical showings according to Wiki else -#ifdef ASPECT_RATIO_SCALE - CDraw::ms_fAspectRatio = FrontEndMenuManager.m_PrefsUseWideScreen == AR_AUTO ? SCREEN_WIDTH / SCREEN_HEIGHT : 16.f / 9.f; -#else CDraw::ms_fAspectRatio = 16.f / 9.f; #endif } else if (TheCamera.m_WideScreenOn) { From 40020f4e1e7d34e5d357a54df42c3e7356da1082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 12 Oct 2020 12:36:15 +0300 Subject: [PATCH 09/10] Fix forgotten wanted/busted text --- src/core/config.h | 1 - src/render/Hud.cpp | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/core/config.h b/src/core/config.h index 13ebef52..57545f4c 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -261,7 +261,6 @@ enum Config { //#define BIND_VEHICLE_FIREWEAPON // Adds ability to rebind fire key for 'in vehicle' controls // Hud, frontend and radar -#define HUD_ENHANCEMENTS // Adjusts some aspects to make the HUD look/behave a little bit better. //#define BETA_SLIDING_TEXT #define TRIANGULAR_BLIPS // height indicating triangular radar blips, as in VC #define PC_MENU diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 52e542f4..3ea756fa 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -854,11 +854,7 @@ void CHud::Draw() break; } -#ifndef HUD_ENHANCEMENTS if (!m_Message[0]) { -#else - if (!m_Message[0] && !m_BigMessage[2][0]) { // Hide vehicle name if wasted/busted text is displaying -#endif m_VehicleNameTimer += CTimer::GetTimeStepInMilliseconds(); CFont::SetJustifyOff(); CFont::SetPropOn(); @@ -1378,16 +1374,16 @@ void CHud::Draw() CFont::SetRightJustifyOn(); CFont::SetFontStyle(FONT_HEADING); - CFont::SetColor(CRGBA(0, 0, 0, BigMessageAlpha[2])); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f - 4.0f), SCREEN_SCALE_FROM_BOTTOM(78.0f), m_BigMessage[2]); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[2])); CFont::SetColor(CRGBA(WASTEDBUSTED_COLOR.r, WASTEDBUSTED_COLOR.g, WASTEDBUSTED_COLOR.b, BigMessageAlpha[2])); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(82.0f), m_BigMessage[2]); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(90.0f), m_BigMessage[2]); } else { BigMessageInUse[2] = 1.0f; BigMessageAlpha[2] = 0.0f; - if (m_VehicleState != 0) + if (m_VehicleState != 0) // Hide vehicle name if wasted/busted text is displaying m_VehicleState = 0; if (m_ZoneState != 0) m_ZoneState = 0; From be6b97b5d8fe253b6cca1c26214bfdc7d55bf42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 12 Oct 2020 20:30:49 +0300 Subject: [PATCH 10/10] Streaming and cross-platform fixes --- src/core/CdStreamPosix.cpp | 17 ++++++++--------- src/skel/crossplatform.cpp | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index a6ab62bc..fdc63a05 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -240,9 +240,8 @@ CdStreamRead(int32 channel, void *buffer, uint32 offset, uint32 size) CdReadInfo *pChannel = &gpReadInfo[channel]; ASSERT( pChannel != nil ); - if ( pChannel->nSectorsToRead != 0 || pChannel->bReading ) { - if (pChannel->nSectorOffset == _GET_OFFSET(offset) && pChannel->nSectorsToRead >= size) + if (pChannel->hFile == hImage - 1 && pChannel->nSectorOffset == _GET_OFFSET(offset) && pChannel->nSectorsToRead >= size) return STREAM_SUCCESS; flushStream[channel] = 1; @@ -293,7 +292,6 @@ CdStreamGetStatus(int32 channel) if ( pChannel->nStatus != STREAM_NONE ) { int32 status = pChannel->nStatus; - pChannel->nStatus = STREAM_NONE; return status; @@ -322,15 +320,16 @@ CdStreamSync(int32 channel) pthread_kill(pChannel->pChannelThread, SIGUSR1); if (pChannel->bReading) { pChannel->bLocked = true; - sem_wait(pChannel->pDoneSemaphore); + while (pChannel->bLocked) + sem_wait(pChannel->pDoneSemaphore); } #else pChannel->nSectorsToRead = 0; if (pChannel->bReading) { pChannel->bLocked = true; pthread_kill(_gCdStreamThread, SIGUSR1); - sem_wait(pChannel->pDoneSemaphore); - + while (pChannel->bLocked) + sem_wait(pChannel->pDoneSemaphore); } #endif pChannel->bReading = false; @@ -341,8 +340,8 @@ CdStreamSync(int32 channel) if ( pChannel->nSectorsToRead != 0 ) { pChannel->bLocked = true; - - sem_wait(pChannel->pDoneSemaphore); + while (pChannel->bLocked) + sem_wait(pChannel->pDoneSemaphore); } pChannel->bReading = false; @@ -443,9 +442,9 @@ void *CdStreamThread(void *param) #endif pChannel->nSectorsToRead = 0; - if ( pChannel->bLocked ) { + pChannel->bLocked = 0; sem_post(pChannel->pDoneSemaphore); } pChannel->bReading = false; diff --git a/src/skel/crossplatform.cpp b/src/skel/crossplatform.cpp index 452ad9fa..ac4bbe85 100644 --- a/src/skel/crossplatform.cpp +++ b/src/skel/crossplatform.cpp @@ -27,13 +27,28 @@ void GetLocalTime_CP(SYSTEMTIME *out) { #ifndef _WIN32 HANDLE FindFirstFile(const char* pathname, WIN32_FIND_DATA* firstfile) { char newpathname[32]; + strncpy(newpathname, pathname, 32); - char* path = strtok(newpathname, "\\*"); + char* path = strtok(newpathname, "*"); + + // Case-sensitivity and backslashes... + char *real = casepath(path); + if (real) { + real[strlen(real)] = '*'; + char *extension = strtok(NULL, "*"); + if (extension) + strcat(real, extension); + + strncpy(newpathname, real, 32); + free(real); + path = strtok(newpathname, "*"); + } + strncpy(firstfile->folder, path, sizeof(firstfile->folder)); // Both w/ extension and w/o extension is ok - if (strlen(path) + 2 != strlen(pathname)) - strncpy(firstfile->extension, strtok(NULL, "\\*"), sizeof(firstfile->extension)); + if (strlen(path) + 1 != strlen(pathname)) + strncpy(firstfile->extension, strtok(NULL, "*"), sizeof(firstfile->extension)); else strncpy(firstfile->extension, "", sizeof(firstfile->extension)); @@ -52,8 +67,8 @@ bool FindNextFile(HANDLE d, WIN32_FIND_DATA* finddata) { while ((file = readdir((DIR*)d)) != NULL) { // We only want "DT_REG"ular Files, but reportedly some FS and OSes gives DT_UNKNOWN as type. - if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG) && - (extensionLen == 0 || strncmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) { + if ((file->d_type == DT_UNKNOWN || file->d_type == DT_REG || file->d_type == DT_LNK) && + (extensionLen == 0 || strncasecmp(&file->d_name[strlen(file->d_name) - extensionLen], finddata->extension, extensionLen) == 0)) { sprintf(relativepath, "%s/%s", finddata->folder, file->d_name); realpath(relativepath, path);