diff options
author | majestic <majesticcoding@gmail.com> | 2020-10-08 03:43:50 +0200 |
---|---|---|
committer | majestic <majesticcoding@gmail.com> | 2020-10-08 14:59:08 +0200 |
commit | 7861992fe6c8bc02600917c80053e08d9dcaa501 (patch) | |
tree | 29d12a69b0817b3989bacb153e111484b0a043db /src/render | |
parent | Merge branch 'miami' of https://github.com/GTAmodding/re3 into miami (diff) | |
download | re3-7861992fe6c8bc02600917c80053e08d9dcaa501.tar re3-7861992fe6c8bc02600917c80053e08d9dcaa501.tar.gz re3-7861992fe6c8bc02600917c80053e08d9dcaa501.tar.bz2 re3-7861992fe6c8bc02600917c80053e08d9dcaa501.tar.lz re3-7861992fe6c8bc02600917c80053e08d9dcaa501.tar.xz re3-7861992fe6c8bc02600917c80053e08d9dcaa501.tar.zst re3-7861992fe6c8bc02600917c80053e08d9dcaa501.zip |
Diffstat (limited to '')
-rw-r--r-- | src/render/Fluff.cpp | 2 | ||||
-rw-r--r-- | src/render/WaterCreatures.cpp | 263 | ||||
-rw-r--r-- | src/render/WaterCreatures.h | 49 | ||||
-rw-r--r-- | src/render/WaterLevel.cpp | 2 |
4 files changed, 314 insertions, 2 deletions
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); } } } |