diff options
Diffstat (limited to 'src/vehicles/Boat.cpp')
-rw-r--r-- | src/vehicles/Boat.cpp | 172 |
1 files changed, 144 insertions, 28 deletions
diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index d86627de..673372b0 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -3,6 +3,7 @@ #include "General.h" #include "Timecycle.h" #include "HandlingMgr.h" +#include "CarAI.h" #include "CarCtrl.h" #include "RwHelper.h" #include "ModelIndices.h" @@ -18,17 +19,20 @@ #include "Pools.h" #include "Pad.h" #include "Boat.h" +#include "AnimBlendAssociation.h" +#include "RpAnimBlend.h" +#include "Record.h" #define INVALID_ORIENTATION (-9999.99f) float fShapeLength = 0.4f; float fShapeTime = 0.05f; -float fRangeMult = 0.75f; //0.6f; // 0.75f gta 3 +float fRangeMult = 0.6f; float fTimeMult; -float MAX_WAKE_LENGTH = 50.0f; -float MIN_WAKE_INTERVAL = 1.0f; -float WAKE_LIFETIME = 400.0f; +float CBoat::MAX_WAKE_LENGTH = 50.0f; +float CBoat::MIN_WAKE_INTERVAL = 2.0f; +float CBoat::WAKE_LIFETIME = 150.0f; CBoat *CBoat::apFrameWakeGeneratingBoats[4]; @@ -51,6 +55,7 @@ CBoat::CBoat(int mi, uint8 owner) : CVehicle(owner) SetModelIndex(mi); pHandling = mod_HandlingManager.GetHandlingData((eHandlingId)minfo->m_handlingId); + pFlyingHandling = mod_HandlingManager.GetFlyingPointer((eHandlingId)minfo->m_handlingId); minfo->ChooseVehicleColour(m_currentColour1, m_currentColour2); m_fMass = pHandling->fMass; @@ -96,7 +101,7 @@ CBoat::CBoat(int mi, uint8 owner) : CVehicle(owner) void CBoat::SetModelIndex(uint32 id) { - CEntity::SetModelIndex(id); + CVehicle::SetModelIndex(id); SetupModelNodes(); } @@ -109,9 +114,6 @@ CBoat::GetComponentWorldPosition(int32 component, CVector &pos) void CBoat::ProcessControl(void) { - if(m_nZoneLevel > LEVEL_NONE && m_nZoneLevel != CCollision::ms_collisionInMemory) - return; - bool onLand = m_fDamageImpulse > 0.0f && m_vecDamageNormal.z > 0.1f; PruneWakeTrail(); @@ -151,10 +153,14 @@ CBoat::ProcessControl(void) ProcessControlInputs(0); if(GetModelIndex() == MI_PREDATOR) DoFixedMachineGuns(); + + if (!CRecordDataForChase::IsRecording()) + DoDriveByShootings(); break; case STATUS_SIMPLE: m_bIsAnchored = false; m_fOrientation = INVALID_ORIENTATION; + CCarAI::UpdateCarAI(this); CPhysical::ProcessControl(); bBoatInWater = true; bPropellerInWater = true; @@ -163,7 +169,8 @@ CBoat::ProcessControl(void) case STATUS_PHYSICS: m_bIsAnchored = false; m_fOrientation = INVALID_ORIENTATION; - CCarCtrl::SteerAIBoatWithPhysics(this); + CCarAI::UpdateCarAI(this); + CCarCtrl::SteerAICarWithPhysics(this); break; case STATUS_ABANDONED: case STATUS_WRECKED: @@ -267,9 +274,17 @@ CBoat::ProcessControl(void) if(0.1f * m_fMass * GRAVITY*CTimer::GetTimeStep() < buoyanceImpulse.z){ bBoatInWater = true; bIsInWater = true; + if (GetUp().z < -0.6f && Abs(GetMoveSpeed().x) < 0.05 && Abs(GetMoveSpeed().y) < 0.05) { + bIsDrowning = true; + if (pDriver) + pDriver->InflictDamage(nil, WEAPONTYPE_DROWNING, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); + } + else + bIsDrowning = false; }else{ bBoatInWater = false; bIsInWater = false; + bIsDrowning = false; } m_fVolumeUnderWater = mod_Buoyancy.m_volumeUnderWater; @@ -295,8 +310,8 @@ CBoat::ProcessControl(void) AddWakePoint(GetPosition()); float steerFactor = 1.0f - DotProduct(m_vecMoveSpeed, GetForward()); - if (GetModelIndex() == MI_GHOST) - steerFactor = 1.0f - DotProduct(m_vecMoveSpeed, GetForward())*0.3f; +// if (GetModelIndex() == MI_GHOST) +// steerFactor = 1.0f - DotProduct(m_vecMoveSpeed, GetForward())*0.3f; if(steerFactor < 0.0f) steerFactor = 0.0f; CVector propeller(0.0f, -pHandling->Dimension.y*m_fPropellerY, -pHandling->Dimension.z*m_fPropellerZ); @@ -368,8 +383,9 @@ CBoat::ProcessControl(void) CGeneral::GetRandomNumberInRange(0, 30), CGeneral::GetRandomNumberInRange(0, 90), 3); #endif - if(!cameraHack) - CParticle::AddParticle(PARTICLE_BOAT_WAKE, wakePos, wakeDir, nil, 0.0f, jetColor); + //TODO: MIAMI: + //if(!cameraHack) + // CParticle::AddParticle(PARTICLE_BOAT_WAKE, wakePos, wakeDir, nil, 0.0f, jetColor); }else if((CTimer::GetFrameCounter() + m_randomSeed) & 1){ #ifdef PC_PARTICLE jetDir.z = 0.018f; @@ -406,10 +422,10 @@ CBoat::ProcessControl(void) } // Slow down or push down boat as it approaches the world limits - m_vecMoveSpeed.x = Min(m_vecMoveSpeed.x, -(GetPosition().x - 1900.0f)*0.01f); // east - m_vecMoveSpeed.x = Max(m_vecMoveSpeed.x, -(GetPosition().x - -1515.0f)*0.01f); // west - m_vecMoveSpeed.y = Min(m_vecMoveSpeed.y, -(GetPosition().y - 600.0f)*0.01f); // north - m_vecMoveSpeed.y = Max(m_vecMoveSpeed.y, -(GetPosition().y - -1900.0f)*0.01f); // south + m_vecMoveSpeed.x = Min(m_vecMoveSpeed.x, -(GetPosition().x - (WORLD_MAX_X-100.0f))*0.01f); // east + m_vecMoveSpeed.x = Max(m_vecMoveSpeed.x, -(GetPosition().x - (WORLD_MIN_X+100.0f))*0.01f); // west + m_vecMoveSpeed.y = Min(m_vecMoveSpeed.y, -(GetPosition().y - (WORLD_MAX_Y-100.0f))*0.01f); // north + m_vecMoveSpeed.y = Max(m_vecMoveSpeed.y, -(GetPosition().y - (WORLD_MIN_Y+100.0f))*0.01f); // south if(!onLand && bBoatInWater) ApplyWaterResistance(); @@ -439,7 +455,7 @@ CBoat::ProcessControl(void) speedUp = pHandling->fBrakeDeceleration - m_vecMoveSpeed.z; if(speedUp < 0.0f) speedUp = 0.0f; float speedFwd = DotProduct(m_vecMoveSpeed, GetForward()); - speedFwd *= -m_nDeltaVolumeUnderWater * 0.01f * pHandling->fTractionLoss; + speedFwd *= -m_nDeltaVolumeUnderWater * 0.01f * pHandling->fBrakeBias; CVector speed = speedFwd*GetForward() + CVector(0.0f, 0.0f, speedUp); CVector splashImpulse = speed * m_fMass; ApplyMoveForce(splashImpulse); @@ -513,6 +529,7 @@ CBoat::ProcessControl(void) }else{ bBoatInWater = false; bIsInWater = false; + bIsDrowning = false; } if(m_bIsAnchored){ @@ -529,6 +546,28 @@ CBoat::ProcessControl(void) } } + if (m_modelIndex == MI_SKIMMER && CTimer::GetTimeStep() > 0.0f) { + if (GetStatus() == STATUS_PLAYER) { + if (m_fPropellerY <= CTimer::GetTimeStep() * 0.0005f) { + m_fPropellerY = 0.0f; + } + else { + m_fPropellerY -= CTimer::GetTimeStep() * 0.0005f; + } + } + else { + if (m_fPropellerY < 0.22f) { + m_fPropellerY += CTimer::GetTimeStep() * 0.001f; + } + FlyingControl(FLIGHT_MODEL_SEAPLANE); + } + } + else { + if (bCheat8) { + FlyingControl(FLIGHT_MODEL_PLANE); + } + } + ProcessDelayedExplosion(); } @@ -547,7 +586,7 @@ CBoat::ProcessControlInputs(uint8 pad) m_fAccelerate += (CPad::GetPad(pad)->GetAccelerate()/255.0f - m_fAccelerate)*0.1f; m_fAccelerate = clamp(m_fAccelerate, 0.0f, 1.0f); }else - m_fAccelerate = -m_fBrake*0.2f; + m_fAccelerate = -m_fBrake*0.3f; m_fSteeringLeftRight += (-CPad::GetPad(pad)->GetSteeringLeftRight()/128.0f - m_fSteeringLeftRight)*0.2f; m_fSteeringLeftRight = clamp(m_fSteeringLeftRight, -1.0f, 1.0f); @@ -896,24 +935,101 @@ void CBoat::AddWakePoint(CVector point) { int i; - if(m_afWakePointLifeTime[0] > 0.0f){ - if((CVector2D(GetPosition()) - m_avec2dWakePoints[0]).MagnitudeSqr() < SQR(1.0f)){ - for(i = Min(m_nNumWakePoints, ARRAY_SIZE(m_afWakePointLifeTime)-1); i != 0; i--){ - m_avec2dWakePoints[i] = m_avec2dWakePoints[i-1]; - m_afWakePointLifeTime[i] = m_afWakePointLifeTime[i-1]; + if (m_afWakePointLifeTime[0] > 0.0f) { + if ((CVector2D(GetPosition()) - m_avec2dWakePoints[0]).MagnitudeSqr() < SQR(2.0f)) { + if (GetStatus() == STATUS_PHYSICS) { + if (VehicleCreatedBy == MISSION_VEHICLE) { + if (m_nNumWakePoints >= 20) + m_nNumWakePoints = 20; + } + else { + if (m_nNumWakePoints >= 15) + m_nNumWakePoints = 15; + } + } + else { + if (m_nNumWakePoints >= 31) + m_nNumWakePoints = 31; + } + for (i = m_nNumWakePoints; i != 0; i--) { + m_avec2dWakePoints[i] = m_avec2dWakePoints[i - 1]; + m_afWakePointLifeTime[i] = m_afWakePointLifeTime[i - 1]; } m_avec2dWakePoints[0] = point; - m_afWakePointLifeTime[0] = 400.0f; - if(m_nNumWakePoints < ARRAY_SIZE(m_afWakePointLifeTime)) + m_afWakePointLifeTime[0] = 150.0f; + if (m_nNumWakePoints < ARRAY_SIZE(m_afWakePointLifeTime)) m_nNumWakePoints++; } - }else{ + } + else { m_avec2dWakePoints[0] = point; - m_afWakePointLifeTime[0] = 400.0f; + m_afWakePointLifeTime[0] = 150.0f; m_nNumWakePoints = 1; } } +void +CBoat::DoDriveByShootings(void) +{ + CAnimBlendAssociation *anim = nil; + CPlayerInfo* playerInfo = ((CPlayerPed*)this)->GetPlayerInfoForThisPlayerPed(); + if (playerInfo && !playerInfo->m_bDriveByAllowed) + return; + + CWeapon *weapon = pDriver->GetWeapon(); + if(CWeaponInfo::GetWeaponInfo(weapon->m_eWeaponType)->m_nWeaponSlot != 5) + return; + + weapon->Update(pDriver->m_audioEntityId, nil); + + bool lookingLeft = false; + bool lookingRight = false; + if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN){ + if(CPad::GetPad(0)->GetLookLeft()) + lookingLeft = true; + if(CPad::GetPad(0)->GetLookRight()) + lookingRight = true; + }else{ + if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) + lookingLeft = true; + if(TheCamera.Cams[TheCamera.ActiveCam].LookingRight) + lookingRight = true; + } + + if(lookingLeft || lookingRight){ + if(lookingLeft){ + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); + if(anim) + anim->blendDelta = -1000.0f; + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); + if(anim == nil || anim->blendDelta < 0.0f) + anim = CAnimManager::AddAnimation(pDriver->GetClump(), ASSOCGRP_STD, ANIM_DRIVEBY_L); + }else if(pDriver->m_pMyVehicle->pPassengers[0] == nil || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON){ + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); + if(anim) + anim->blendDelta = -1000.0f; + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); + if(anim == nil || anim->blendDelta < 0.0f) + anim = CAnimManager::AddAnimation(pDriver->GetClump(), ASSOCGRP_STD, ANIM_DRIVEBY_R); + } + + if (!anim || !anim->IsRunning()) { + if (CPad::GetPad(0)->GetCarGunFired() && CTimer::GetTimeInMilliseconds() > weapon->m_nTimer) { + weapon->FireFromCar(this, lookingLeft, true); + weapon->m_nTimer = CTimer::GetTimeInMilliseconds() + 70; + } + } + }else{ + weapon->Reload(); + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_L); + if(anim) + anim->blendDelta = -1000.0f; + anim = RpAnimBlendClumpGetAssociation(pDriver->GetClump(), ANIM_DRIVEBY_R); + if(anim) + anim->blendDelta = -1000.0f; + } +} + #ifdef COMPATIBLE_SAVES void CBoat::Save(uint8*& buf) |