diff options
author | erorcun <erorcunerorcun@hotmail.com.tr> | 2020-12-15 15:45:06 +0100 |
---|---|---|
committer | erorcun <erorcunerorcun@hotmail.com.tr> | 2020-12-15 15:45:06 +0100 |
commit | 970f84514a45e0181bd05ae02493908ec86f5683 (patch) | |
tree | 37e568870361124e7e34dfe20a7f66af254a8d39 /src | |
parent | Radio scroll to prev. station & radio off text (diff) | |
parent | fixed water.dat code (diff) | |
download | re3-970f84514a45e0181bd05ae02493908ec86f5683.tar re3-970f84514a45e0181bd05ae02493908ec86f5683.tar.gz re3-970f84514a45e0181bd05ae02493908ec86f5683.tar.bz2 re3-970f84514a45e0181bd05ae02493908ec86f5683.tar.lz re3-970f84514a45e0181bd05ae02493908ec86f5683.tar.xz re3-970f84514a45e0181bd05ae02493908ec86f5683.tar.zst re3-970f84514a45e0181bd05ae02493908ec86f5683.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/control/Phones.cpp | 6 | ||||
-rw-r--r-- | src/control/Script5.cpp | 2 | ||||
-rw-r--r-- | src/core/Fire.cpp | 4 | ||||
-rw-r--r-- | src/core/PlayerInfo.cpp | 2 | ||||
-rw-r--r-- | src/peds/CivilianPed.cpp | 8 | ||||
-rw-r--r-- | src/peds/CopPed.cpp | 6 | ||||
-rw-r--r-- | src/peds/EmergencyPed.cpp | 14 | ||||
-rw-r--r-- | src/peds/Ped.cpp | 99 | ||||
-rw-r--r-- | src/peds/PedAI.cpp | 34 | ||||
-rw-r--r-- | src/peds/PedFight.cpp | 14 | ||||
-rw-r--r-- | src/peds/PlayerPed.cpp | 41 | ||||
-rw-r--r-- | src/peds/Population.cpp | 6 | ||||
-rw-r--r-- | src/render/WaterLevel.cpp | 367 | ||||
-rw-r--r-- | src/render/WaterLevel.h | 13 |
14 files changed, 426 insertions, 190 deletions
diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp index c951e868..4769559c 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -67,7 +67,7 @@ CPhoneInfo::Update(void) } else { CPad::GetPad(0)->SetEnablePlayerControls(PLAYERCONTROL_PHONE); if (player->m_nPedState == PED_MAKE_CALL) - player->m_nPedState = PED_IDLE; + player->SetPedState(PED_IDLE); } } bool notInCar; @@ -114,7 +114,7 @@ CPhoneInfo::Update(void) player->m_fRotationCur = angleToFace; player->m_fRotationDest = angleToFace; player->SetHeading(angleToFace); - player->m_nPedState = PED_MAKE_CALL; + player->SetPedState(PED_MAKE_CALL); CPad::GetPad(0)->SetDisablePlayerControls(PLAYERCONTROL_PHONE); TheCamera.SetWideScreenOn(); playerInfo->MakePlayerSafe(true); @@ -412,7 +412,7 @@ PhonePutDownCB(CAnimBlendAssociation *assoc, void *arg) ped->bUpdateAnimHeading = true; if (ped->m_nPedState == PED_MAKE_CALL) - ped->m_nPedState = PED_IDLE; + ped->SetPedState(PED_IDLE); } void diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp index 164ca036..4826192e 100644 --- a/src/control/Script5.cpp +++ b/src/control/Script5.cpp @@ -1921,7 +1921,7 @@ void CTheScripts::CleanUpThisPed(CPed* pPed) if (pPed->IsPedInControl()) pPed->SetWanderPath(CGeneral::GetRandomNumber() & 7); if (flees) { - pPed->m_nPedState = state; + pPed->SetPedState(state); pPed->SetMoveState(ms); } --CPopulation::ms_nTotalMissionPeds; diff --git a/src/core/Fire.cpp b/src/core/Fire.cpp index e1be4194..2c57c066 100644 --- a/src/core/Fire.cpp +++ b/src/core/Fire.cpp @@ -228,7 +228,7 @@ CFireManager::StartFire(CEntity *entityOnFire, CEntity *fleeFrom, float strength 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) { @@ -401,7 +401,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; diff --git a/src/core/PlayerInfo.cpp b/src/core/PlayerInfo.cpp index 09b3a499..5866485d 100644 --- a/src/core/PlayerInfo.cpp +++ b/src/core/PlayerInfo.cpp @@ -419,7 +419,7 @@ CPlayerInfo::Process(void) if (found) sth.z = 1.0f + groundZ; - m_pPed->m_nPedState = PED_IDLE; + m_pPed->SetPedState(PED_IDLE); m_pPed->SetMoveState(PEDMOVE_STILL); CPed::PedSetOutCarCB(0, m_pPed); CAnimManager::BlendAnimation(m_pPed->GetClump(), m_pPed->m_animGroup, ANIM_IDLE_STANCE, 100.0f); diff --git a/src/peds/CivilianPed.cpp b/src/peds/CivilianPed.cpp index 401d2e67..a2f44357 100644 --- a/src/peds/CivilianPed.cpp +++ b/src/peds/CivilianPed.cpp @@ -274,7 +274,7 @@ CCivilianPed::ProcessControl(void) } else { crimeReporters[m_phoneId] = this; m_facePhoneStart = true; - m_nPedState = PED_FACE_PHONE; + SetPedState(PED_FACE_PHONE); } #else } else if (bRunningToPhone) { @@ -283,7 +283,7 @@ CCivilianPed::ProcessControl(void) m_phoneId = -1; } else { gPhoneInfo.m_aPhones[m_phoneId].m_nState = PHONE_STATE_REPORTING_CRIME; - m_nPedState = PED_FACE_PHONE; + SetPedState(PED_FACE_PHONE); } #endif } else if (m_objective != OBJECTIVE_KILL_CHAR_ANY_MEANS && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT) { @@ -305,7 +305,7 @@ CCivilianPed::ProcessControl(void) break; case PED_FACE_PHONE: if (FacePhone()) - m_nPedState = PED_MAKE_CALL; + SetPedState(PED_MAKE_CALL); break; case PED_MAKE_CALL: if (MakePhonecall()) @@ -331,7 +331,7 @@ CCivilianPed::ProcessControl(void) for (int j = 0; j < m_numNearPeds; ++j) { CPed *nearPed = m_nearPeds[j]; if (nearPed->m_nPedType == m_nPedType && nearPed->m_nPedState == PED_WANDER_PATH) { - nearPed->m_nPedState = PED_UNKNOWN; + nearPed->SetPedState(PED_UNKNOWN); } } } diff --git a/src/peds/CopPed.cpp b/src/peds/CopPed.cpp index de7b8ad2..b2888082 100644 --- a/src/peds/CopPed.cpp +++ b/src/peds/CopPed.cpp @@ -114,14 +114,14 @@ CCopPed::SetArrestPlayer(CPed *player) } else if (player->m_nPedState != PED_DIE && player->m_nPedState != PED_DEAD && player->m_nPedState != PED_ARRESTED) { player->m_nLastPedState = player->m_nPedState; - player->m_nPedState = PED_ARRESTED; + player->SetPedState(PED_ARRESTED); FindPlayerPed()->m_bCanBeDamaged = false; ((CPlayerPed*)player)->m_pArrestingCop = this; this->RegisterReference((CEntity**) &((CPlayerPed*)player)->m_pArrestingCop); } - m_nPedState = PED_ARREST_PLAYER; + SetPedState(PED_ARREST_PLAYER); SetObjective(OBJECTIVE_NONE); m_prevObjective = OBJECTIVE_NONE; bIsPointingGunAt = false; @@ -229,7 +229,7 @@ CCopPed::ArrestPlayer(void) CPed *suspect = (CPed*)m_pSeekTarget; if (suspect) { if (suspect->CanSetPedState()) - suspect->m_nPedState = PED_ARRESTED; + suspect->SetPedState(PED_ARRESTED); if (suspect->bInVehicle && m_pMyVehicle && suspect->m_pMyVehicle == m_pMyVehicle) { diff --git a/src/peds/EmergencyPed.cpp b/src/peds/EmergencyPed.cpp index 8d6999c3..65aa97ef 100644 --- a/src/peds/EmergencyPed.cpp +++ b/src/peds/EmergencyPed.cpp @@ -100,7 +100,7 @@ CEmergencyPed::FiremanAI(void) case EMERGENCY_PED_READY: nearestFire = gFireManager.FindNearestFire(GetPosition(), &fireDist); if (nearestFire) { - m_nPedState = PED_NONE; + SetPedState(PED_NONE); SetSeek(nearestFire->m_vecPos, 1.0f); SetMoveState(PEDMOVE_RUN); m_nEmergencyPedState = EMERGENCY_PED_DETERMINE_NEXT_STATE; @@ -114,7 +114,7 @@ CEmergencyPed::FiremanAI(void) case EMERGENCY_PED_DETERMINE_NEXT_STATE: nearestFire = gFireManager.FindNearestFire(GetPosition(), &fireDist); if (nearestFire && nearestFire != m_pAttendedFire) { - m_nPedState = PED_NONE; + SetPedState(PED_NONE); SetSeek(nearestFire->m_vecPos, 1.0f); SetMoveState(PEDMOVE_RUN); #ifdef FIX_BUGS @@ -160,7 +160,7 @@ CEmergencyPed::FiremanAI(void) #endif --m_pAttendedFire->m_nFiremenPuttingOut; - m_nPedState = PED_NONE; + SetPedState(PED_NONE); SetWanderPath(CGeneral::GetRandomNumber() & 7); m_pAttendedFire = nil; m_nEmergencyPedState = EMERGENCY_PED_READY; @@ -307,7 +307,7 @@ CEmergencyPed::MedicAI(void) } else { m_pRevivedPed->m_bloodyFootprintCountOrDeathTime = CTimer::GetTimeInMilliseconds(); SetMoveState(PEDMOVE_STILL); - m_nPedState = PED_CPR; + SetPedState(PED_CPR); m_nLastPedState = PED_CPR; SetLookFlag(m_pRevivedPed, 0); SetLookTimer(500); @@ -366,12 +366,12 @@ CEmergencyPed::MedicAI(void) break; } m_nEmergencyPedState = EMERGENCY_PED_STOP_CPR; - m_nPedState = PED_NONE; + SetPedState(PED_NONE); SetMoveState(PEDMOVE_WALK); m_pVehicleAnim = nil; if (!m_pRevivedPed->bBodyPartJustCameOff) { m_pRevivedPed->m_fHealth = 100.0f; - m_pRevivedPed->m_nPedState = PED_NONE; + m_pRevivedPed->SetPedState(PED_NONE); m_pRevivedPed->m_nLastPedState = PED_WANDER_PATH; m_pRevivedPed->SetGetUp(); m_pRevivedPed->bUsesCollision = true; @@ -400,7 +400,7 @@ CEmergencyPed::MedicAI(void) break; case EMERGENCY_PED_STOP: m_bStartedToCPR = false; - m_nPedState = PED_NONE; + SetPedState(PED_NONE); if (m_pAttendedAccident) { m_pAttendedAccident->m_pVictim = nil; --m_pAttendedAccident->m_nMedicsAttending; diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index c41c1f0c..5e1911ec 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -641,7 +641,7 @@ CPed::RestorePreviousState(void) return; if (InVehicle()) { - m_nPedState = PED_DRIVING; + SetPedState(PED_DRIVING); m_nLastPedState = PED_NONE; } else { if (m_nLastPedState == PED_NONE) { @@ -658,7 +658,7 @@ CPed::RestorePreviousState(void) SetIdle(); break; case PED_WANDER_PATH: - m_nPedState = PED_WANDER_PATH; + SetPedState(PED_WANDER_PATH); bIsRunning = false; if (bFindNewNodeAfterStateRestore) { if (m_pNextPathNode) { @@ -672,7 +672,7 @@ CPed::RestorePreviousState(void) SetWanderPath(CGeneral::GetRandomNumber() & 7); break; default: - m_nPedState = m_nLastPedState; + SetPedState(m_nLastPedState); SetMoveState((eMoveState) m_nPrevMoveState); break; } @@ -1511,8 +1511,8 @@ CPed::ClearAll(void) if (!IsPedInControl() && m_nPedState != PED_DEAD) return; - m_nPedState = PED_NONE; - m_nMoveState = PEDMOVE_NONE; + SetPedState(PED_NONE); + SetMoveState(PEDMOVE_NONE); m_pSeekTarget = nil; m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f); m_fleeFromPosX = 0.0f; @@ -1585,7 +1585,7 @@ CPed::ProcessBuoyancy(void) CParticleObject::AddObject(POBJECT_PED_WATER_SPLASH, pos, CVector(0.0f, 0.0f, 0.0f), 0.0f, 50, CRGBA(0, 0, 0, 0), true); #endif m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); return; } } @@ -2692,36 +2692,6 @@ CPed::ProcessControl(void) case PED_WANDER_PATH: WanderPath(); break; - case PED_SEEK_POS: - case PED_SEEK_ENTITY: - case PED_PURSUE: - case PED_SNIPER_MODE: - case PED_ROCKET_MODE: - case PED_DUMMY: - case PED_FACE_PHONE: - case PED_MAKE_CALL: - case PED_MUG: - case PED_AI_CONTROL: - case PED_FOLLOW_ROUTE: - case PED_CPR: - case PED_SOLICIT: - case PED_BUY_ICECREAM: - case PED_STEP_AWAY: - case PED_UNKNOWN: - case PED_STATES_NO_AI: - case PED_JUMP: - case PED_STAGGER: - case PED_DIVE_AWAY: - case PED_STATES_NO_ST: - case PED_ARREST_PLAYER: - case PED_PASSENGER: - case PED_TAXI_PASSENGER: - case PED_OPEN_DOOR: - case PED_DEAD: - case PED_DRAG_FROM_CAR: - case PED_EXIT_CAR: - case PED_STEAL_CAR: - break; case PED_ENTER_CAR: case PED_CARJACK: { @@ -4467,7 +4437,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) if (!veh->bEngineOn) veh->bEngineOn = true; - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); ped->StopNonPartialAnims(); return; } @@ -4512,7 +4482,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) else if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_PASSENGER) { if (ped->m_nPedState == PED_CARJACK) { veh->AddPassenger(ped, 0); - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); ped->RestorePreviousObjective(); ped->SetObjective(OBJECTIVE_LEAVE_CAR, veh); } else if (veh->pDriver && ped->CharCreatedBy == RANDOM_CHAR) { @@ -4552,7 +4522,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) veh->AutoPilot.m_nDrivingStyle = DRIVINGSTYLE_AVOID_CARS; veh->AutoPilot.m_nCruiseSpeed = 25; } - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); if (ped->m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER) { if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) @@ -4580,7 +4550,7 @@ CPed::PedSetInCarCB(CAnimBlendAssociation *animAssoc, void *arg) break; } } - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); if (ped->m_prevObjective == OBJECTIVE_RUN_TO_AREA || ped->m_prevObjective == OBJECTIVE_GOTO_CHAR_ON_FOOT || ped->m_prevObjective == OBJECTIVE_KILL_CHAR_ON_FOOT) ped->m_prevObjective = OBJECTIVE_NONE; @@ -4967,7 +4937,7 @@ CPed::SetIdle(void) m_nLastPedState = PED_NONE; #endif - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); SetMoveState(PEDMOVE_STILL); } if (m_nWaitState == WAITSTATE_FALSE) { @@ -5055,7 +5025,7 @@ CPed::SetFall(int extraTime, AnimationId animId, uint8 evenIfNotInControl) ClearLookFlag(); ClearAimFlag(); SetStoredState(); - m_nPedState = PED_FALL; + SetPedState(PED_FALL); CAnimBlendAssociation *fallAssoc = RpAnimBlendClumpGetAssociation(GetClump(), animId); if (fallAssoc) { @@ -5220,7 +5190,7 @@ CPed::SetGetUp(void) } if (m_nPedState != PED_GETUP) { SetStoredState(); - m_nPedState = PED_GETUP; + SetPedState(PED_GETUP); } CVehicle *collidingVeh = (CVehicle*)m_pCollidingEntity; @@ -5375,7 +5345,7 @@ CPed::SetSeek(CVector pos, float distanceToCountDone) if (m_nPedState != PED_SEEK_POS) SetStoredState(); - m_nPedState = PED_SEEK_POS; + SetPedState(PED_SEEK_POS); m_distanceToCountSeekDone = distanceToCountDone; m_vecSeekPos = pos; } @@ -5395,7 +5365,7 @@ CPed::SetSeek(CEntity *seeking, float distanceToCountDone) if (m_nPedState != PED_SEEK_ENTITY) SetStoredState(); - m_nPedState = PED_SEEK_ENTITY; + SetPedState(PED_SEEK_ENTITY); m_distanceToCountSeekDone = distanceToCountDone; m_pSeekTarget = seeking; m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); @@ -5572,7 +5542,7 @@ CPed::SetFlee(CVector2D const &from, int time) if (m_nPedState != PED_FLEE_ENTITY) { SetStoredState(); - m_nPedState = PED_FLEE_POS; + SetPedState(PED_FLEE_POS); SetMoveState(PEDMOVE_RUN); m_fleeFromPosX = from.x; m_fleeFromPosY = from.y; @@ -5601,7 +5571,7 @@ CPed::SetFlee(CEntity *fleeFrom, int time) return; SetStoredState(); - m_nPedState = PED_FLEE_ENTITY; + SetPedState(PED_FLEE_ENTITY); bUsePedNodeSeek = true; SetMoveState(PEDMOVE_RUN); m_fleeFrom = fleeFrom; @@ -5862,7 +5832,7 @@ CPed::SetWanderPath(int8 pathStateDest) // We did it, save next path state and return true m_nPathDir = nextPathState; - m_nPedState = PED_WANDER_PATH; + SetPedState(PED_WANDER_PATH); SetMoveState(PEDMOVE_WALK); bIsRunning = false; return true; @@ -6047,7 +6017,7 @@ CPed::SetFollowPath(CVector dest) return false; SetStoredState(); - m_nPedState = PED_FOLLOW_PATH; + SetPedState(PED_FOLLOW_PATH); SetMoveState(PEDMOVE_WALK); return true; } @@ -6150,7 +6120,7 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType) m_fRotationCur = CGeneral::LimitRadianAngle(angleToFace); ClearAimFlag(); SetStoredState(); - m_nPedState = PED_STEP_AWAY; + SetPedState(PED_STEP_AWAY); } } } @@ -6247,13 +6217,13 @@ CPed::SetEvasiveDive(CPhysical *reason, uint8 onlyRandomJump) animAssoc->flags &= ~ASSOC_DELETEFADEDOUT; animAssoc->SetFinishCallback(PedEvadeCB, this); SetStoredState(); - m_nPedState = PED_STEP_AWAY; + SetPedState(PED_STEP_AWAY); } else { m_fRotationCur = angleToFace; ClearLookFlag(); ClearAimFlag(); SetStoredState(); - m_nPedState = PED_DIVE_AWAY; + SetPedState(PED_DIVE_AWAY); animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_EV_DIVE, 8.0f); animAssoc->SetFinishCallback(PedEvadeCB, this); } @@ -6291,7 +6261,7 @@ CPed::PedEvadeCB(CAnimBlendAssociation* animAssoc, void* arg) if (ped->m_nPedState == PED_DIVE_AWAY) { ped->m_getUpTimer = CTimer::GetTimeInMilliseconds() + 1; - ped->m_nPedState = PED_FALL; + ped->SetPedState(PED_FALL); } animAssoc->flags &= ~ASSOC_FADEOUTWHENDONE; animAssoc->flags |= ASSOC_DELETEFADEDOUT; @@ -6342,7 +6312,7 @@ CPed::SetDie(AnimationId animId, float delta, float speed) QuitEnteringCar(); } - m_nPedState = PED_DIE; + SetPedState(PED_DIE); if (animId == NUM_ANIMS) { bIsPedDieAnimPlaying = false; } else { @@ -6384,7 +6354,7 @@ CPed::SetDead(void) if (m_nPedState == PED_DRIVING) bIsVisible = false; - m_nPedState = PED_DEAD; + SetPedState(PED_DEAD); m_pVehicleAnim = nil; m_pCollidingEntity = nil; @@ -6417,7 +6387,7 @@ CPed::SetChat(CEntity *chatWith, uint32 time) if(m_nPedState != PED_CHAT) SetStoredState(); - m_nPedState = PED_CHAT; + SetPedState(PED_CHAT); SetMoveState(PEDMOVE_STILL); #if defined VC_PED_PORTS || defined FIX_BUGS m_lookTimer = 0; @@ -6658,7 +6628,7 @@ CPed::SetSeekCar(CVehicle *car, uint32 doorNode) // m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget); m_vehEnterType = doorNode; m_distanceToCountSeekDone = 0.5f; - m_nPedState = PED_SEEK_CAR; + SetPedState(PED_SEEK_CAR); } @@ -7683,10 +7653,11 @@ CPed::FlagToDestroyWhenNextProcessed(void) } bInVehicle = false; m_pMyVehicle = nil; + if (CharCreatedBy == MISSION_CHAR) - m_nPedState = PED_DEAD; + SetPedState(PED_DEAD); else - m_nPedState = PED_NONE; + SetPedState(PED_NONE); m_pVehicleAnim = nil; } @@ -7710,7 +7681,7 @@ CPed::SetSolicit(uint32 time) if(!m_carInObjective->bIsVan && !m_carInObjective->bIsBus) m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_HOOKERTALK, 4.0f); - m_nPedState = PED_SOLICIT; + SetPedState(PED_SOLICIT); } } } @@ -7769,7 +7740,7 @@ CPed::SetBuyIceCream(void) // Simulating BuyIceCream CPed* driver = m_carInObjective->pDriver; if (driver) { - m_nPedState = PED_BUY_ICECREAM; + SetPedState(PED_BUY_ICECREAM); bFindNewNodeAfterStateRestore = true; SetObjectiveTimer(8000); SetChat(driver, 8000); @@ -7783,7 +7754,7 @@ CPed::SetBuyIceCream(void) if (Abs(m_fRotationDest - m_fRotationCur) < HALFPI) { m_standardTimer = CTimer::GetTimeInMilliseconds() + 3000; - m_nPedState = PED_BUY_ICECREAM; + SetPedState(PED_BUY_ICECREAM); } } @@ -7985,7 +7956,7 @@ CPed::SetJump(void) #endif (m_nSurfaceTouched != SURFACE_STEEP_CLIFF || DotProduct(GetForward(), m_vecDamageNormal) >= 0.0f)) { SetStoredState(); - m_nPedState = PED_JUMP; + SetPedState(PED_JUMP); CAnimBlendAssociation *jumpAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_JUMP_LAUNCH, 8.0f); jumpAssoc->SetFinishCallback(FinishLaunchCB, this); m_fRotationDest = m_fRotationCur; @@ -8287,7 +8258,7 @@ CPed::WarpPedIntoCar(CVehicle *car) m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle); m_carInObjective = car; m_carInObjective->RegisterReference((CEntity **) &m_carInObjective); - m_nPedState = PED_DRIVING; + SetPedState(PED_DRIVING); bUsesCollision = false; bIsInTheAir = false; bVehExitWillBeInstant = true; diff --git a/src/peds/PedAI.cpp b/src/peds/PedAI.cpp index 5eaf8cd8..d4385385 100644 --- a/src/peds/PedAI.cpp +++ b/src/peds/PedAI.cpp @@ -809,10 +809,10 @@ CPed::ProcessObjective(void) break; } case OBJECTIVE_WAIT_IN_CAR: - m_nPedState = PED_DRIVING; + SetPedState(PED_DRIVING); break; case OBJECTIVE_WAIT_IN_CAR_THEN_GET_OUT: - m_nPedState = PED_DRIVING; + SetPedState(PED_DRIVING); break; case OBJECTIVE_KILL_CHAR_ANY_MEANS: { @@ -2617,7 +2617,7 @@ CPed::PedAnimGetInCB(CAnimBlendAssociation *animAssoc, void *arg) if (ped->IsPlayer() && ped->bGonnaKillTheCarJacker && ((CPlayerPed*)ped)->m_pArrestingCop) { PedSetInCarCB(nil, ped); ped->m_nLastPedState = ped->m_nPedState; - ped->m_nPedState = PED_ARRESTED; + ped->SetPedState(PED_ARRESTED); ped->bGonnaKillTheCarJacker = false; if (veh) { veh->m_nNumGettingIn = 0; @@ -3340,7 +3340,7 @@ CPed::SetCarJack_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) m_pSeekTarget = car; m_pSeekTarget->RegisterReference((CEntity**)&m_pSeekTarget); - m_nPedState = PED_CARJACK; + SetPedState(PED_CARJACK); car->bIsBeingCarJacked = true; m_pMyVehicle = (CVehicle*)m_pSeekTarget; m_pMyVehicle->RegisterReference((CEntity**)&m_pMyVehicle); @@ -3387,7 +3387,7 @@ CPed::SetBeingDraggedFromCar(CVehicle *veh, uint32 vehEnterType, bool quickJack) SetMoveState(PEDMOVE_NONE); LineUpPedWithCar(LINE_UP_TO_CAR_START); m_pVehicleAnim = nil; - m_nPedState = PED_DRAG_FROM_CAR; + SetPedState(PED_DRAG_FROM_CAR); bChangedSeat = false; bWillBeQuickJacked = quickJack; @@ -3512,7 +3512,7 @@ CPed::SetEnterCar_AllClear(CVehicle *car, uint32 doorNode, uint32 doorFlag) m_pSeekTarget = car; m_pSeekTarget->RegisterReference((CEntity **) &m_pSeekTarget); m_vehEnterType = doorNode; - m_nPedState = PED_ENTER_CAR; + SetPedState(PED_ENTER_CAR); if (m_vehEnterType == CAR_DOOR_RF && m_objective == OBJECTIVE_ENTER_CAR_AS_DRIVER && car->m_vehType != VEHICLE_TYPE_BIKE) { car->bIsBeingCarJacked = true; } @@ -3674,14 +3674,14 @@ void CPed::SetExitBoat(CVehicle *boat) { #ifndef VC_PED_PORTS - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); CVector firstPos = GetPosition(); CAnimManager::BlendAnimation(GetClump(), m_animGroup, ANIM_IDLE_STANCE, 100.0f); if (boat->GetModelIndex() == MI_SPEEDER && boat->IsUpsideDown()) { m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CAR_CRAWLOUT_RHS, 8.0f); m_pVehicleAnim->SetFinishCallback(PedSetOutCarCB, this); m_vehEnterType = CAR_DOOR_RF; - m_nPedState = PED_EXIT_CAR; + SetPedState(PED_EXIT_CAR); } else { m_vehEnterType = CAR_DOOR_RF; PedSetOutCarCB(nil, this); @@ -3694,7 +3694,7 @@ CPed::SetExitBoat(CVehicle *boat) m_vecMoveSpeed = boat->m_vecMoveSpeed; bTryingToReachDryLand = true; #else - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); CVector newPos = GetPosition(); RemoveInCarAnims(); CColModel* boatCol = boat->GetColModel(); @@ -3921,7 +3921,7 @@ CPed::SetExitCar(CVehicle *veh, uint32 wantedDoorNode) m_pSeekTarget = veh; m_pSeekTarget->RegisterReference((CEntity**) &m_pSeekTarget); m_vehEnterType = optedDoorNode; - m_nPedState = PED_EXIT_CAR; + SetPedState(PED_EXIT_CAR); if (m_pVehicleAnim && m_pVehicleAnim->flags & ASSOC_PARTIAL) m_pVehicleAnim->blendDelta = -1000.0f; SetMoveState(PEDMOVE_NONE); @@ -4469,7 +4469,7 @@ CPed::PedSetDraggedOutCarPositionCB(CAnimBlendAssociation* animAssoc, void* arg) ped->bGonnaKillTheCarJacker = false; if (!ped->m_pedInObjective || !(CGeneral::GetRandomNumber() & 1)) { if (!driver || driver == ped || driver->IsPlayer() && CTheScripts::IsPlayerOnAMission()) { - ped->m_nPedState = PED_NONE; + ped->SetPedState(PED_NONE); ped->m_nLastPedState = PED_NONE; ped->SetFlee(ped->m_pMyVehicle->GetPosition(), 4000); } else { @@ -4498,7 +4498,7 @@ CPed::PedSetDraggedOutCarPositionCB(CAnimBlendAssociation* animAssoc, void* arg) else #endif { - ped->m_nPedState = PED_NONE; + ped->SetPedState(PED_NONE); ped->m_nLastPedState = PED_NONE; ped->SetFindPathAndFlee(ped->m_pMyVehicle->GetPosition(), 10000); } @@ -4591,7 +4591,7 @@ CPed::PedSetInTrainCB(CAnimBlendAssociation* animAssoc, void* arg) return; ped->bInVehicle = true; - ped->m_nPedState = PED_DRIVING; + ped->SetPedState(PED_DRIVING); ped->RestorePreviousObjective(); ped->SetMoveState(PEDMOVE_STILL); veh->AddPassenger(ped); @@ -4612,7 +4612,7 @@ CPed::SetEnterTrain(CVehicle *train, uint32 unused) m_pMyVehicle = train; m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle); - m_nPedState = PED_ENTER_TRAIN; + SetPedState(PED_ENTER_TRAIN); m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_TRAIN_GETIN, 4.0f); m_pVehicleAnim->SetFinishCallback(PedSetInTrainCB, this); bUsesCollision = false; @@ -4686,7 +4686,7 @@ CPed::SetExitTrain(CVehicle* train) CVector exitPos; GetNearestTrainPedPosition(train, exitPos); */ - m_nPedState = PED_EXIT_TRAIN; + SetPedState(PED_EXIT_TRAIN); m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_TRAIN_GETOUT, 4.0f); m_pVehicleAnim->SetFinishCallback(PedSetOutTrainCB, this); bUsesCollision = false; @@ -4712,7 +4712,7 @@ CPed::PedSetOutTrainCB(CAnimBlendAssociation *animAssoc, void *arg) ped->bUsesCollision = true; ped->m_pVehicleAnim = nil; ped->bInVehicle = false; - ped->m_nPedState = PED_IDLE; + ped->SetPedState(PED_IDLE); ped->RestorePreviousObjective(); ped->SetMoveState(PEDMOVE_STILL); @@ -5180,7 +5180,7 @@ CPed::SetSeekBoatPosition(CVehicle *boat) m_pMyVehicle = boat; m_pMyVehicle->RegisterReference((CEntity **) &m_pMyVehicle); m_distanceToCountSeekDone = 0.5f; - m_nPedState = PED_SEEK_IN_BOAT; + SetPedState(PED_SEEK_IN_BOAT); } void diff --git a/src/peds/PedFight.cpp b/src/peds/PedFight.cpp index c219d94f..b4be0954 100644 --- a/src/peds/PedFight.cpp +++ b/src/peds/PedFight.cpp @@ -164,7 +164,7 @@ CPed::SetPointGunAt(CEntity *to) if (m_nPedState != PED_ATTACK) SetStoredState(); - m_nPedState = PED_AIM_GUN; + SetPedState(PED_AIM_GUN); bIsPointingGunAt = true; CWeaponInfo *curWeapon = CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType); SetMoveState(PEDMOVE_NONE); @@ -222,7 +222,7 @@ CPed::ClearPointGunAt(void) RestorePreviousState(); #else if (m_nPedState == PED_AIM_GUN || m_nPedState == PED_ATTACK) { - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); RestorePreviousState(); } #endif @@ -281,7 +281,7 @@ CPed::SetAttack(CEntity *victim) (m_nPedState != PED_FIGHT && m_nMoveState != PEDMOVE_NONE && m_nMoveState != PEDMOVE_STILL && !(m_pedStats->m_flags & STAT_SHOPPING_BAGS))) { if (m_nPedState != PED_ATTACK) { - m_nPedState = PED_ATTACK; + SetPedState(PED_ATTACK); bIsAttacking = false; animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, curWeapon->m_AnimToPlay, 8.0f); animAssoc->SetRun(); @@ -348,7 +348,7 @@ CPed::SetAttack(CEntity *victim) if (m_nPedState != PED_AIM_GUN) SetStoredState(); - m_nPedState = PED_ATTACK; + SetPedState(PED_ATTACK); SetMoveState(PEDMOVE_NONE); if (bCrouchWhenShooting) { animAssoc = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_RBLOCK_CSHOOT, 4.0f); @@ -786,7 +786,7 @@ CPed::StartFightAttack(uint8 buttonPressure) RestoreHeadingRate(); } - m_nPedState = PED_FIGHT; + SetPedState(PED_FIGHT); m_fightButtonPressure = 0; RpAnimBlendClumpRemoveAssociations(GetClump(), ASSOC_REPEAT); CAnimBlendAssociation *animAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK_START); @@ -1062,7 +1062,7 @@ CPed::StartFightDefend(uint8 direction, uint8 hitLevel, uint8 unk) m_nWaitState = WAITSTATE_FALSE; RestoreHeadingRate(); } - m_nPedState = PED_FIGHT; + SetPedState(PED_FIGHT); m_fightButtonPressure = 0; RpAnimBlendClumpRemoveAssociations(GetClump(), ASSOC_REPEAT); CAnimBlendAssociation *walkStartAssoc = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_WALK_START); @@ -1796,7 +1796,7 @@ CPed::SetInvestigateEvent(eEventType event, CVector2D pos, float distanceToCount SetStoredState(); bFindNewNodeAfterStateRestore = false; - m_nPedState = PED_INVESTIGATE; + SetPedState(PED_INVESTIGATE); m_standardTimer = CTimer::GetTimeInMilliseconds() + time; m_eventType = event; m_eventOrThreat = pos; diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index ef9cf201..86d8e9f5 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -244,7 +244,7 @@ CPlayerPed::SetInitialState(void) if (m_pFire) m_pFire->Extinguish(); RpAnimBlendClumpRemoveAllAssociations(GetClump()); - m_nPedState = PED_IDLE; + SetPedState(PED_IDLE); SetMoveState(PEDMOVE_STILL); m_nLastPedState = PED_NONE; m_animGroup = ASSOCGRP_PLAYER; @@ -989,7 +989,7 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) GetWeapon()->m_eWeaponType == WEAPONTYPE_SNIPERRIFLE || GetWeapon()->m_eWeaponType == WEAPONTYPE_M16) { if (padUsed->TargetJustDown()) { SetStoredState(); - m_nPedState = PED_SNIPER_MODE; + SetPedState(PED_SNIPER_MODE); #ifdef FREE_CAM if (CCamera::bFreeCam && TheCamera.Cams[0].Using3rdPersonMouseCam()) { m_fRotationCur = CGeneral::LimitRadianAngle(-TheCamera.Orientation); @@ -1343,41 +1343,6 @@ CPlayerPed::ProcessControl(void) if (IsPedInControl() && padUsed) ProcessPlayerWeapon(padUsed); break; - case PED_LOOK_ENTITY: - case PED_LOOK_HEADING: - case PED_WANDER_RANGE: - case PED_WANDER_PATH: - case PED_PURSUE: - case PED_FOLLOW_PATH: - case PED_ROCKET_MODE: - case PED_DUMMY: - case PED_PAUSE: - case PED_FACE_PHONE: - case PED_MAKE_CALL: - case PED_CHAT: - case PED_MUG: - case PED_AI_CONTROL: - case PED_FOLLOW_ROUTE: - case PED_CPR: - case PED_SOLICIT: - case PED_BUY_ICECREAM: - case PED_INVESTIGATE: - case PED_STEP_AWAY: - case PED_ON_FIRE: - case PED_UNKNOWN: - case PED_STATES_NO_AI: - case PED_STAGGER: - case PED_DIVE_AWAY: - case PED_STATES_NO_ST: - case PED_ARREST_PLAYER: - case PED_DRIVING: - case PED_PASSENGER: - case PED_TAXI_PASSENGER: - case PED_OPEN_DOOR: - case PED_DIE: - case PED_DEAD: - case PED_HANDS_UP: - break; case PED_SEEK_ENTITY: m_vecSeekPos = m_pSeekTarget->GetPosition(); @@ -1457,6 +1422,8 @@ CPlayerPed::ProcessControl(void) if (m_nLastPedState == PED_DRAG_FROM_CAR && m_pVehicleAnim) BeingDraggedFromCar(); break; + default: + break; } if (padUsed && IsPedShootable()) { ProcessWeaponSwitch(padUsed); diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index b3eaf471..5dbde649 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -718,10 +718,10 @@ CPopulation::AddToPopulation(float minDist, float maxDist, float minDistOffScree if (i != 0) { // Gang member newPed->SetLeader(gangLeader); -#ifndef FIX_BUGS +#if !defined(FIX_BUGS) && GTA_VERSION >= GTA3_PC_10 // seems to be a miami leftover (this code is not on PS2) but gang peds end up just being frozen - newPed->m_nPedState = PED_UNKNOWN; - gangLeader->m_nPedState = PED_UNKNOWN; + newPed->SetPedState(PED_UNKNOWN); + gangLeader->SetPedState(PED_UNKNOWN); newPed->m_fRotationCur = CGeneral::GetRadianAngleBetweenPoints( gangLeader->GetPosition().x, gangLeader->GetPosition().y, newPed->GetPosition().x, newPed->GetPosition().y); diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp index ecfccc90..49fc3a22 100644 --- a/src/render/WaterLevel.cpp +++ b/src/render/WaterLevel.cpp @@ -1,6 +1,7 @@ #include "common.h" #include "main.h" #include "FileMgr.h" +#include "FileLoader.h" #include "TxdStore.h" #include "Timer.h" #include "Weather.h" @@ -30,8 +31,8 @@ float TEXTURE_ADDV; int32 CWaterLevel::ms_nNoOfWaterLevels; float CWaterLevel::ms_aWaterZs[48]; CRect CWaterLevel::ms_aWaterRects[48]; -uint8 CWaterLevel::aWaterBlockList[WATER_BLOCK_SIZE][WATER_BLOCK_SIZE]; -uint8 CWaterLevel::aWaterFineBlockList[WATER_FINEBLOCK_SIZE][WATER_FINEBLOCK_SIZE]; +int8 CWaterLevel::aWaterBlockList[MAX_LARGE_SECTORS][MAX_LARGE_SECTORS]; +int8 CWaterLevel::aWaterFineBlockList[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; bool CWaterLevel::WavesCalculatedThisFrame; RpAtomic *CWaterLevel::ms_pWavyAtomic; RpGeometry *CWaterLevel::apGeomArray[8]; @@ -53,33 +54,163 @@ const float fGreenMult = 1.0f; const float fBlueMult = 1.4f; - void CWaterLevel::Initialise(Const char *pWaterDat) { ms_nNoOfWaterLevels = 0; - + +#ifdef MASTER int32 hFile = -1; - - do + + while ((hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb")) < 0); +#else + int32 hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb"); +#endif + + if (hFile > 0) { - hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb"); + CFileMgr::Read(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); + CFileMgr::Read(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); + CFileMgr::Read(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); + CFileMgr::Read(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); + CFileMgr::Read(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); + + CFileMgr::CloseFile(hFile); } - while ( hFile < 0 ); - - if ( hFile > 0 ) +#ifndef MASTER + else { - if ( hFile >= 0 ) + printf("Init waterlevels\n"); + + CFileMgr::SetDir(""); + hFile = CFileMgr::OpenFile(pWaterDat, "r"); + + char *line; + + while ((line = CFileLoader::LoadLine(hFile))) { - CFileMgr::Read(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); - CFileMgr::Read(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); - CFileMgr::Read(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); - CFileMgr::Read(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); - CFileMgr::Read(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); + if (*line && *line != ';') + { + float z, l, b, r, t; + sscanf(line, "%f %f %f %f %f", &z, &l, &b, &r, &t); + AddWaterLevel(l, b, r, t, z); + } } - + CFileMgr::CloseFile(hFile); + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + aWaterFineBlockList[x][y] = NO_WATER; + } + } + + // rasterize water rects read from file + for (int32 i = 0; i < ms_nNoOfWaterLevels; i++) + { + int32 l = WATER_HUGE_X(ms_aWaterRects[i].left); + int32 r = WATER_HUGE_X(ms_aWaterRects[i].right) + 1.0f; + int32 t = WATER_HUGE_Y(ms_aWaterRects[i].top); + int32 b = WATER_HUGE_Y(ms_aWaterRects[i].bottom) + 1.0f; + +#ifdef FIX_BUGS + // water.dat has rects that go out of bounds + // which causes memory corruption + l = clamp(l, 0, MAX_SMALL_SECTORS - 1); + r = clamp(r, 0, MAX_SMALL_SECTORS - 1); + t = clamp(t, 0, MAX_SMALL_SECTORS - 1); + b = clamp(b, 0, MAX_SMALL_SECTORS - 1); +#endif + + for (int32 x = l; x <= r; x++) + { + for (int32 y = t; y <= b; y++) + { + aWaterFineBlockList[x][y] = i; + } + } + } + + // remove tiles that are obscured by land + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + float worldX = WATER_START_X + x * SMALL_SECTOR_SIZE; + + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + if (aWaterFineBlockList[x][y] >= 0) + { + float worldY = WATER_START_Y + y * SMALL_SECTOR_SIZE; + + int32 i; + for (i = 0; i <= 8; i++) + { + for (int32 j = 0; j <= 8; j++) + { + CVector worldPos = CVector(worldX + i * (SMALL_SECTOR_SIZE / 8), worldY + j * (SMALL_SECTOR_SIZE / 8), ms_aWaterZs[aWaterFineBlockList[x][y]]); + + if ((worldPos.x > WORLD_MIN_X && worldPos.x < WORLD_MAX_X) && (worldPos.y > WORLD_MIN_Y && worldPos.y < WORLD_MAX_Y) && + (!WaterLevelAccordingToRectangles(worldPos.x, worldPos.y) || TestVisibilityForFineWaterBlocks(worldPos))) + continue; + + // at least one point in the tile wasn't blocked, so don't remove water + i = 1000; + break; + } + } + + if (i < 1000) + aWaterFineBlockList[x][y] = NO_WATER; + } + } + } + + RemoveIsolatedWater(); + + // calculate coarse tiles from fine tiles + for (int32 x = 0; x < MAX_LARGE_SECTORS; x++) + { + for (int32 y = 0; y < MAX_LARGE_SECTORS; y++) + { + if (aWaterFineBlockList[x * 2][y * 2] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2][y * 2]; + } + else if (aWaterFineBlockList[x * 2 + 1][y * 2] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2 + 1][y * 2]; + } + else if (aWaterFineBlockList[x * 2][y * 2 + 1] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2][y * 2 + 1]; + } + else if (aWaterFineBlockList[x * 2 + 1][y * 2 + 1] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2 + 1][y * 2 + 1]; + } + else + { + aWaterBlockList[x][y] = NO_WATER; + } + } + } + + hFile = CFileMgr::OpenFileForWriting("data\\waterpro.dat"); + + if (hFile > 0) + { + CFileMgr::Write(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); + CFileMgr::Write(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); + CFileMgr::Write(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); + CFileMgr::Write(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); + CFileMgr::Write(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); + + CFileMgr::CloseFile(hFile); + } } +#endif CTxdStore::PushCurrentTxd(); @@ -222,6 +353,170 @@ CWaterLevel::DestroyWavyAtomic() RwFrameDestroy(frame); } +#ifndef MASTER +void +CWaterLevel::AddWaterLevel(float fXLeft, float fYBottom, float fXRight, float fYTop, float fLevel) +{ + ms_aWaterRects[ms_nNoOfWaterLevels] = CRect(fXLeft, fYBottom, fXRight, fYTop); + ms_aWaterZs[ms_nNoOfWaterLevels] = fLevel; + ms_nNoOfWaterLevels++; +} + +bool +CWaterLevel::WaterLevelAccordingToRectangles(float fX, float fY, float *pfOutLevel) +{ + if (ms_nNoOfWaterLevels <= 0) return false; + + for (int32 i = 0; i < ms_nNoOfWaterLevels; i++) + { + if (fX >= ms_aWaterRects[i].left && fX <= ms_aWaterRects[i].right + && fY >= ms_aWaterRects[i].top && fY <= ms_aWaterRects[i].bottom) + { + if (pfOutLevel) *pfOutLevel = ms_aWaterZs[i]; + + return true; + } + } + + return false; +} + +bool +CWaterLevel::TestVisibilityForFineWaterBlocks(const CVector &worldPos) +{ + static CVector2D tab[] = + { + { 50.0f, 50.0f }, + { -50.0f, 50.0f }, + { -50.0f, -50.0f }, + { 50.0f, -50.0f }, + { 50.0f, 0.0f }, + { -50.0f, 0.0f }, + { 0.0f, -50.0f }, + { 0.0f, 50.0f }, + }; + + CEntity *entity; + CColPoint col; + CVector lineStart, lineEnd; + + lineStart = worldPos; + + if (!CWorld::ProcessVerticalLine(lineStart, lineStart.z + 100.0f, col, entity, true, false, false, false, true, false, nil)) + { + lineStart.x += 0.4f; + lineStart.y += 0.4f; + + if (!CWorld::ProcessVerticalLine(lineStart, lineStart.z + 100.0f, col, entity, true, false, false, false, true, false, nil)) + { + return false; + } + } + + for (int32 i = 0; i < ARRAY_SIZE(tab); i++) + { + lineStart = worldPos; + lineEnd = worldPos; + + lineEnd.x += tab[i].x; + lineEnd.y += tab[i].y; + lineEnd.z += 100.0f; + + if ((lineEnd.x > WORLD_MIN_X && lineEnd.x < WORLD_MAX_X) && (lineEnd.y > WORLD_MIN_Y && lineEnd.y < WORLD_MAX_Y)) + { + if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false, nil)) + { + lineStart.x += 0.4f; + lineStart.y += 0.4f; + lineEnd.x += 0.4f; + lineEnd.y += 0.4f; + + if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false, nil)) + { + return false; + } + } + } + } + + return true; +} + +void +CWaterLevel::RemoveIsolatedWater() +{ + bool (*isConnected)[MAX_SMALL_SECTORS] = new bool[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + isConnected[x][y] = false; + } + } + + isConnected[0][0] = true; + bool keepGoing; + + do + { + keepGoing = false; + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + if (aWaterFineBlockList[x][y] < 0 || isConnected[x][y]) + continue; + + if (x > 0 && isConnected[x - 1][y]) + { + isConnected[x][y] = true; + keepGoing = true; + } + + if (y > 0 && isConnected[x][y - 1]) + { + isConnected[x][y] = true; + keepGoing = true; + } + + if (x + 1 < MAX_SMALL_SECTORS && isConnected[x + 1][y]) + { + isConnected[x][y] = true; + keepGoing = true; + } + + if (y + 1 < MAX_SMALL_SECTORS && isConnected[x][y + 1]) + { + isConnected[x][y] = true; + keepGoing = true; + } + } + } + } + while (keepGoing); + + int32 numRemoved = 0; + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + if (aWaterFineBlockList[x][y] >= 0 && !isConnected[x][y] && ms_aWaterZs[aWaterFineBlockList[x][y]] == 0.0f) + { + numRemoved++; + aWaterFineBlockList[x][y] = NO_WATER; + } + } + } + + printf("Removed %d isolated patches of water\n", numRemoved); + + delete[] isConnected; +} +#endif + bool CWaterLevel::GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ) { @@ -231,9 +526,9 @@ CWaterLevel::GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool ASSERT( x >= 0 && x < HUGE_SECTOR_SIZE ); ASSERT( y >= 0 && y < HUGE_SECTOR_SIZE ); - uint8 nBlock = aWaterFineBlockList[x][y]; + int8 nBlock = aWaterFineBlockList[x][y]; - if ( nBlock == 128 ) + if ( nBlock == NO_WATER ) return false; ASSERT( pfOutLevel != NULL ); @@ -270,9 +565,9 @@ CWaterLevel::GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLeve ASSERT( x >= 0 && x < HUGE_SECTOR_SIZE ); ASSERT( y >= 0 && y < HUGE_SECTOR_SIZE ); - uint8 nBlock = aWaterFineBlockList[x][y]; + int8 nBlock = aWaterFineBlockList[x][y]; - if ( nBlock == 128 ) + if ( nBlock == NO_WATER ) return false; ASSERT( pfOutLevel != NULL ); @@ -418,10 +713,10 @@ CWaterLevel::RenderWater() { for ( int32 y = nStartY; y <= nEndY; y++ ) { - if ( !(aWaterBlockList[2*x+0][2*y+0] & 128) - || !(aWaterBlockList[2*x+1][2*y+0] & 128) - || !(aWaterBlockList[2*x+0][2*y+1] & 128) - || !(aWaterBlockList[2*x+1][2*y+1] & 128) ) + if ( aWaterBlockList[2*x+0][2*y+0] >= 0 + || aWaterBlockList[2*x+1][2*y+0] >= 0 + || aWaterBlockList[2*x+0][2*y+1] >= 0 + || aWaterBlockList[2*x+1][2*y+1] >= 0 ) { float fX = WATER_FROM_HUGE_SECTOR_X(x); float fY = WATER_FROM_HUGE_SECTOR_Y(y); @@ -443,16 +738,16 @@ CWaterLevel::RenderWater() { float fZ; - if ( !(aWaterBlockList[2*x+0][2*y+0] & 128) ) + if ( aWaterBlockList[2*x+0][2*y+0] >= 0 ) fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+0] ]; - if ( !(aWaterBlockList[2*x+1][2*y+0] & 128) ) + if ( aWaterBlockList[2*x+1][2*y+0] >= 0 ) fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+0] ]; - if ( !(aWaterBlockList[2*x+0][2*y+1] & 128) ) + if ( aWaterBlockList[2*x+0][2*y+1] >= 0 ) fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+1] ]; - if ( !(aWaterBlockList[2*x+1][2*y+1] & 128) ) + if ( aWaterBlockList[2*x+1][2*y+1] >= 0 ) fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+1] ]; RenderOneFlatHugeWaterPoly(fX, fY, fZ, color); @@ -463,7 +758,7 @@ CWaterLevel::RenderWater() { for ( int32 y2 = 2*y; y2 <= 2*y+1; y2++ ) { - if ( !(aWaterBlockList[x2][y2] & 128) ) + if ( aWaterBlockList[x2][y2] >= 0 ) { float fLargeX = WATER_FROM_LARGE_SECTOR_X(x2); float fLargeY = WATER_FROM_LARGE_SECTOR_Y(y2); @@ -498,7 +793,7 @@ CWaterLevel::RenderWater() float fZ; // WS - if ( !(aWaterFineBlockList[2*x2+0][2*y2+0] & 128) ) + if ( aWaterFineBlockList[2*x2+0][2*y2+0] >= 0 ) { float fSmallX = fLargeX; float fSmallY = fLargeY; @@ -519,7 +814,7 @@ CWaterLevel::RenderWater() } // SE - if ( !(aWaterFineBlockList[2*x2+1][2*y2+0] & 128) ) + if ( aWaterFineBlockList[2*x2+1][2*y2+0] >= 0 ) { float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2); float fSmallY = fLargeY; @@ -540,7 +835,7 @@ CWaterLevel::RenderWater() } // WN - if ( !(aWaterFineBlockList[2*x2+0][2*y2+1] & 128) ) + if ( aWaterFineBlockList[2*x2+0][2*y2+1] >= 0 ) { float fSmallX = fLargeX; float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2); @@ -561,7 +856,7 @@ CWaterLevel::RenderWater() } //NE - if ( !(aWaterFineBlockList[2*x2+1][2*y2+1] & 128) ) + if ( aWaterFineBlockList[2*x2+1][2*y2+1] >= 0 ) { float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2); float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2); @@ -591,7 +886,7 @@ CWaterLevel::RenderWater() } } // if ( TheCamera.IsSphereVisible } // if ( fLargeSectorDistToCamSqr < fHugeSectorMaxRenderDistSqr ) - } // if ( !(aWaterBlockList[x2][y2] & 128) ) + } // if ( aWaterBlockList[x2][y2] >= 0 ) } // for ( int32 y2 = 2*y; y2 <= 2*y+1; y2++ ) } // for ( int32 x2 = 2*x; x2 <= 2*x+1; x2++ ) // @@ -1116,7 +1411,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY) { for ( int32 y = nStartY; y <= nEndY; y++ ) { - if ( !(aWaterFineBlockList[x][y] & 128) ) + if ( aWaterFineBlockList[x][y] >= 0 ) { float fSectorX = WATER_FROM_SMALL_SECTOR_X(x); float fSectorY = WATER_FROM_SMALL_SECTOR_Y(y); diff --git a/src/render/WaterLevel.h b/src/render/WaterLevel.h index 269d6091..cf3537ae 100644 --- a/src/render/WaterLevel.h +++ b/src/render/WaterLevel.h @@ -1,9 +1,9 @@ #pragma once -#define WATER_BLOCK_SIZE LARGE_SECTOR_SIZE -#define WATER_FINEBLOCK_SIZE HUGE_SECTOR_SIZE #define WATER_Z_OFFSET (1.5f) +#define NO_WATER -128 + #define MAX_SMALL_SECTORS 128 #define MAX_LARGE_SECTORS 64 #define MAX_HUGE_SECTORS 32 @@ -23,7 +23,6 @@ #define WATER_WIDTH ((WATER_END_X - WATER_START_X)) #define WATER_HEIGHT ((WATER_END_Y - WATER_START_Y)) - #define WATER_UNSIGN_X(x) ( (x) + (WATER_WIDTH /2) ) #define WATER_UNSIGN_Y(y) ( (y) + (WATER_HEIGHT/2) ) #define WATER_SIGN_X(x) ( (x) - (WATER_WIDTH /2) ) @@ -72,8 +71,8 @@ class CWaterLevel static int32 ms_nNoOfWaterLevels; static float ms_aWaterZs[48]; static CRect ms_aWaterRects[48]; - static uint8 aWaterBlockList[WATER_BLOCK_SIZE][WATER_BLOCK_SIZE]; - static uint8 aWaterFineBlockList[WATER_FINEBLOCK_SIZE][WATER_FINEBLOCK_SIZE]; + static int8 aWaterBlockList[MAX_LARGE_SECTORS][MAX_LARGE_SECTORS]; + static int8 aWaterFineBlockList[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; static bool WavesCalculatedThisFrame; static RpAtomic *ms_pWavyAtomic; static RpGeometry *apGeomArray[MAX_BOAT_WAKES]; @@ -84,6 +83,10 @@ public: static void Shutdown(); static void CreateWavyAtomic(); static void DestroyWavyAtomic(); + static void AddWaterLevel(float fXLeft, float fYBottom, float fXRight, float fYTop, float fLevel); + static bool WaterLevelAccordingToRectangles(float fX, float fY, float *pfOutLevel = nil); + static bool TestVisibilityForFineWaterBlocks(const CVector &worldPos); + static void RemoveIsolatedWater(); static bool GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ); static bool GetWaterLevel(CVector coors, float *pfOutLevel, bool bDontCheckZ) { return GetWaterLevel(coors.x, coors.y, coors.z, pfOutLevel, bDontCheckZ); } static bool GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLevel); |