CPed review part2; and reverting some stylistic changes

This commit is contained in:
aap 2020-11-16 09:50:33 +01:00
parent acdf602505
commit b82b79fa11
2 changed files with 227 additions and 273 deletions

View File

@ -287,8 +287,8 @@ CPed::CPed(uint32 pedType) : m_pedIK(this)
m_fleeFromPos = CVector2D(0.0f, 0.0f); m_fleeFromPos = CVector2D(0.0f, 0.0f);
m_fleeTimer = 0; m_fleeTimer = 0;
m_threatEx = nil; m_threatEx = nil;
m_vecSeekPosEx = CVector(0.0f, 0.0f, 0.0f); m_vecSpotToGuard = CVector(0.0f, 0.0f, 0.0f);
m_distanceToCountSeekDoneEx = 0.0f; m_radiusToGuard = 0.0f;
m_nWaitState = WAITSTATE_FALSE; m_nWaitState = WAITSTATE_FALSE;
m_nWaitTimer = 0; m_nWaitTimer = 0;
m_pCollidingEntity = nil; m_pCollidingEntity = nil;
@ -1069,9 +1069,7 @@ CPed::FinishedAttackCB(CAnimBlendAssociation *attackAssoc, void *arg)
} }
} }
} }
return; } else if (attackAssoc && attackAssoc->animId == ANIM_THROWABLE_START_THROW && currentWeapon->m_AnimToPlay == ASSOCGRP_THROW) {
}
if (attackAssoc && attackAssoc->animId == ANIM_THROWABLE_START_THROW && currentWeapon->m_AnimToPlay == ASSOCGRP_THROW) {
if ((!ped->IsPlayer() || ((CPlayerPed*)ped)->m_bHaveTargetSelected) && ped->IsPlayer()) { if ((!ped->IsPlayer() || ((CPlayerPed*)ped)->m_bHaveTargetSelected) && ped->IsPlayer()) {
attackAssoc->blendDelta = -1000.0f; attackAssoc->blendDelta = -1000.0f;
newAnim = CAnimManager::AddAnimation(ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_THROWABLE_THROWU); newAnim = CAnimManager::AddAnimation(ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_THROWABLE_THROWU);
@ -1080,10 +1078,7 @@ CPed::FinishedAttackCB(CAnimBlendAssociation *attackAssoc, void *arg)
newAnim = CAnimManager::AddAnimation(ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_THROWABLE_THROW); newAnim = CAnimManager::AddAnimation(ped->GetClump(), currentWeapon->m_AnimToPlay, ANIM_THROWABLE_THROW);
} }
newAnim->SetFinishCallback(FinishedAttackCB, ped); newAnim->SetFinishCallback(FinishedAttackCB, ped);
return; } else if (ped->bIsDucking && ped->bCrouchWhenShooting) {
}
if (ped->bIsDucking && ped->bCrouchWhenShooting) {
if (currentWeapon->m_bReload) { if (currentWeapon->m_bReload) {
reloadAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), GetCrouchReloadAnim(currentWeapon)); reloadAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), GetCrouchReloadAnim(currentWeapon));
} }
@ -1098,13 +1093,10 @@ CPed::FinishedAttackCB(CAnimBlendAssociation *attackAssoc, void *arg)
if (!ped->bIsAttacking) if (!ped->bIsAttacking)
ped->ClearAttack(); ped->ClearAttack();
return; } else if (GetSecondFireAnim(currentWeapon) && ped->bIsAttacking && currentWeapon->m_AnimToPlay != ASSOCGRP_THROW) {
}
if (GetSecondFireAnim(currentWeapon) && ped->bIsAttacking && currentWeapon->m_AnimToPlay != ASSOCGRP_THROW) {
AnimationId groundAnim = GetFireAnimGround(currentWeapon); AnimationId groundAnim = GetFireAnimGround(currentWeapon);
CAnimBlendAssociation *groundAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), groundAnim); CAnimBlendAssociation *groundAnimAssoc = RpAnimBlendClumpGetAssociation(ped->GetClump(), groundAnim);
if (!groundAnimAssoc || groundAnimAssoc->blendAmount <= 0.95f && groundAnimAssoc->blendDelta <= 0.0f) { if (!(groundAnimAssoc && (groundAnimAssoc->blendAmount > 0.95f || groundAnimAssoc->blendDelta > 0.0f))) {
if (attackAssoc && attackAssoc->animId == ANIM_MELEE_ATTACK) { if (attackAssoc && attackAssoc->animId == ANIM_MELEE_ATTACK) {
newAnim = CAnimManager::BlendAnimation( newAnim = CAnimManager::BlendAnimation(
ped->GetClump(), currentWeapon->m_AnimToPlay, GetSecondFireAnim(currentWeapon), 8.0f); ped->GetClump(), currentWeapon->m_AnimToPlay, GetSecondFireAnim(currentWeapon), 8.0f);
@ -2773,8 +2765,11 @@ CPed::SetPedStats(ePedStats pedStat)
bool bool
CPed::CanUseTorsoWhenLooking(void) CPed::CanUseTorsoWhenLooking(void)
{ {
return m_nPedState != PED_DRIVING && m_nPedState != PED_DRAG_FROM_CAR && !bIsDucking && if (m_nPedState != PED_DRIVING && m_nPedState != PED_DRAG_FROM_CAR && !bIsDucking) {
m_animGroup != ASSOCGRP_SEXYWOMAN && m_animGroup != ASSOCGRP_WOMAN; if (m_animGroup != ASSOCGRP_SEXYWOMAN && m_animGroup != ASSOCGRP_WOMAN)
return true;
}
return false;
} }
// --MIAMI: Done // --MIAMI: Done
@ -3306,7 +3301,9 @@ CPed::SetObjective(eObjective newObj, void *entity)
bObjectiveCompleted = false; bObjectiveCompleted = false;
ClearPointGunAt(); ClearPointGunAt();
m_objectiveTimer = 0; m_objectiveTimer = 0;
if (!IsTemporaryObjective(m_objective) || IsTemporaryObjective(newObj)) { if (IsTemporaryObjective(m_objective) && !IsTemporaryObjective(newObj)) {
m_prevObjective = newObj;
} else {
if (m_objective != newObj) { if (m_objective != newObj) {
if (IsTemporaryObjective(newObj)) if (IsTemporaryObjective(newObj))
ForceStoredObjective(newObj); ForceStoredObjective(newObj);
@ -3314,8 +3311,6 @@ CPed::SetObjective(eObjective newObj, void *entity)
SetStoredObjective(); SetStoredObjective();
} }
m_objective = newObj; m_objective = newObj;
} else {
m_prevObjective = newObj;
} }
switch (newObj) { switch (newObj) {
@ -3372,13 +3367,12 @@ CPed::SetObjective(eObjective newObj, void *entity)
case OBJECTIVE_FLEE_CAR: case OBJECTIVE_FLEE_CAR:
m_carInObjective = (CVehicle*)entity; m_carInObjective = (CVehicle*)entity;
m_carInObjective->RegisterReference((CEntity **)&m_carInObjective); m_carInObjective->RegisterReference((CEntity **)&m_carInObjective);
if (!m_carInObjective->bIsBus || m_leaveCarTimer != 0) if (m_carInObjective->bIsBus && m_leaveCarTimer == 0) {
break; for (int i = 0; i < m_carInObjective->m_nNumMaxPassengers; i++) {
if (m_carInObjective->pPassengers[i] == this) {
for (int i = 0; i < m_carInObjective->m_nNumMaxPassengers; i++) { m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 1200 * i;
if (m_carInObjective->pPassengers[i] == this) { break;
m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 1200 * i; }
break;
} }
} }
@ -3395,7 +3389,7 @@ CPed::SetObjective(eObjective newObj, void *entity)
if (m_nMoveState == PEDMOVE_STILL) if (m_nMoveState == PEDMOVE_STILL)
SetMoveState(PEDMOVE_RUN); SetMoveState(PEDMOVE_RUN);
if (((CVehicle*)entity)->m_vehType == VEHICLE_TYPE_BOAT && !IsPlayer() && m_pCurrentPhysSurface != entity) { if (((CVehicle*)entity)->IsBoat() && !IsPlayer() && m_pCurrentPhysSurface != entity) {
RestorePreviousObjective(); RestorePreviousObjective();
break; break;
} }
@ -3671,8 +3665,7 @@ CPed::ReactToAttack(CEntity *attacker)
} }
} else if ((IsPedInControl() || m_nPedState == PED_DRIVING) && (CharCreatedBy != MISSION_CHAR || bRespondsToThreats)) { } else if ((IsPedInControl() || m_nPedState == PED_DRIVING) && (CharCreatedBy != MISSION_CHAR || bRespondsToThreats)) {
CPed *ourLeader = m_leader; if (m_leader != attacker && (!m_leader || FindPlayerPed() != m_leader) && attacker->IsPed()) {
if (ourLeader != attacker && (!ourLeader || FindPlayerPed() != ourLeader) && attacker->IsPed()) {
CPed *attackerPed = (CPed*)attacker; CPed *attackerPed = (CPed*)attacker;
if (bNotAllowedToDuck) { if (bNotAllowedToDuck) {
@ -4820,12 +4813,8 @@ CPed::SetGetUp(void)
bGetUpAnimStarted = false; bGetUpAnimStarted = false;
if (IsPlayer()) if (IsPlayer())
InflictDamage(nil, WEAPONTYPE_RUNOVERBYCAR, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0); InflictDamage(nil, WEAPONTYPE_RUNOVERBYCAR, CTimer::GetTimeStep(), PEDPIECE_TORSO, 0);
else { else if(CPad::GetPad(0)->ArePlayerControlsDisabled())
if (!CPad::GetPad(0)->ArePlayerControlsDisabled())
return;
InflictDamage(nil, WEAPONTYPE_RUNOVERBYCAR, 1000.0f, PEDPIECE_TORSO, 0); InflictDamage(nil, WEAPONTYPE_RUNOVERBYCAR, 1000.0f, PEDPIECE_TORSO, 0);
}
return; return;
} }
bGetUpAnimStarted = true; bGetUpAnimStarted = true;
@ -5246,7 +5235,7 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType)
neededTurn = TWOPI - neededTurn; neededTurn = TWOPI - neededTurn;
CVehicle *veh = (CVehicle*)reason; CVehicle *veh = (CVehicle*)reason;
if (reason->IsVehicle() && veh->m_vehType == VEHICLE_TYPE_CAR) { if (reason->IsVehicle() && veh->IsCar()) {
if (veh->m_nCarHornTimer != 0) { if (veh->m_nCarHornTimer != 0) {
vehPressedHorn = true; vehPressedHorn = true;
if (!IsPlayer()) if (!IsPlayer())
@ -5274,10 +5263,10 @@ CPed::SetEvasiveStep(CEntity *reason, uint8 animType)
dangerZone = CGeneral::LimitRadianAngle(dangerZone); dangerZone = CGeneral::LimitRadianAngle(dangerZone);
// So, add or subtract 90deg (jump to left/right) according to that // So, add or subtract 90deg (jump to left/right) according to that
if (dangerZone <= 0.0f) if (dangerZone > 0.0f)
angleToFace = HALFPI + vehDirection;
else
angleToFace = vehDirection - HALFPI; angleToFace = vehDirection - HALFPI;
else
angleToFace = vehDirection + HALFPI;
stepAnim = NUM_STD_ANIMS; stepAnim = NUM_STD_ANIMS;
if (animType == 0 || animType == 1) if (animType == 0 || animType == 1)
@ -5818,8 +5807,9 @@ CPed::FightStrike(CVector &touchedNodePos, bool fightWithWeapon)
if (m_fightState == FIGHTSTATE_JUST_ATTACKED) if (m_fightState == FIGHTSTATE_JUST_ATTACKED)
return false; return false;
CGlass::BreakGlassPhysically(touchedNodePos, radius); if (this == FindPlayerPed() && fightWithWeapon && GetWeapon()->m_eWeaponType != WEAPONTYPE_UNARMED)
CGlass::BreakGlassPhysically(touchedNodePos, radius);
for (int i = 0; i < m_numNearPeds; i++) { for (int i = 0; i < m_numNearPeds; i++) {
int8 pedFound = 0; int8 pedFound = 0;
@ -6317,17 +6307,17 @@ CPed::ChooseAttackAI(uint8 buttonPressure, bool fightWithWeapon)
if (fightWithWeapon) { if (fightWithWeapon) {
if (m_pedInObjective->OnGroundOrGettingUp()) { if (m_pedInObjective->OnGroundOrGettingUp()) {
if (!CGame::nastyGame || dist >= 1.2f || m_pedInObjective->IsPlayer() if (CGame::nastyGame && dist < 1.2f && !m_pedInObjective->IsPlayer()
|| m_pedInObjective->m_nPedState != PED_DEAD && m_pedInObjective->IsPedHeadAbovePos(-0.3f)) { && (m_pedInObjective->m_nPedState == PED_DEAD || !m_pedInObjective->IsPedHeadAbovePos(-0.3f))) {
if (weaponInfo->m_bGround2nd)
return FIGHTMOVE_MELEE2;
if (weaponInfo->m_bGround3rd)
return FIGHTMOVE_MELEE3;
return FIGHTMOVE_GROUNDKICK;
} else {
return FIGHTMOVE_IDLE; return FIGHTMOVE_IDLE;
} }
if (weaponInfo->m_bGround2nd)
return FIGHTMOVE_MELEE2;
if (weaponInfo->m_bGround3rd)
return FIGHTMOVE_MELEE3;
return FIGHTMOVE_GROUNDKICK;
} }
if (dist < 2.f) { if (dist < 2.f) {
if (m_curFightMove == FIGHTMOVE_MELEE1) { if (m_curFightMove == FIGHTMOVE_MELEE1) {
@ -6348,12 +6338,12 @@ CPed::ChooseAttackAI(uint8 buttonPressure, bool fightWithWeapon)
return FIGHTMOVE_PUNCH; return FIGHTMOVE_PUNCH;
} else { } else {
if (m_pedInObjective->OnGroundOrGettingUp()) { if (m_pedInObjective->OnGroundOrGettingUp()) {
if (!CGame::nastyGame || dist >= 1.2f || m_pedInObjective->IsPlayer() if (CGame::nastyGame && dist < 1.2f && !m_pedInObjective->IsPlayer()
|| m_pedInObjective->m_nPedState != PED_DEAD && m_pedInObjective->IsPedHeadAbovePos(-0.3f)) { && (m_pedInObjective->m_nPedState == PED_DEAD || !m_pedInObjective->IsPedHeadAbovePos(-0.3f))) {
return FIGHTMOVE_IDLE;
} else {
return FIGHTMOVE_GROUNDKICK; return FIGHTMOVE_GROUNDKICK;
} else {
return FIGHTMOVE_IDLE;
} }
} }
if (dist < 0.95f && canKneeHead) if (dist < 0.95f && canKneeHead)
@ -6416,15 +6406,15 @@ CPed::SetFall(int extraTime, AnimationId animId, uint8 evenIfNotInControl)
m_getUpTimer = UINT32_MAX; m_getUpTimer = UINT32_MAX;
} else if (fallAssoc) { } else if (fallAssoc) {
if (IsPlayer()) { if (IsPlayer()) {
if (fallAssoc->animId != ANIM_CAR_ROLLOUT_LHS && fallAssoc->animId != ANIM_CAR_ROLLOUT_RHS) { if (fallAssoc->animId == ANIM_CAR_ROLLOUT_LHS || fallAssoc->animId == ANIM_CAR_ROLLOUT_RHS) {
m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength
+ CTimer::GetTimeInMilliseconds()
+ 500.0f;
} else {
m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength
+ CTimer::GetTimeInMilliseconds() + CTimer::GetTimeInMilliseconds()
- 1000.0f * fallAssoc->currentTime - 1000.0f * fallAssoc->currentTime
+ 100.0f; + 100.0f;
} else {
m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength
+ CTimer::GetTimeInMilliseconds()
+ 500.0f;
} }
} else { } else {
m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength
@ -7072,7 +7062,9 @@ CPed::CreateDeadPedMoney(void)
if (!CGame::nastyGame) if (!CGame::nastyGame)
return; return;
if ((GetModelIndex() >= MI_COP && GetModelIndex() <= MI_FIREMAN) || (CharCreatedBy == MISSION_CHAR && !bMoneyHasBeenGivenByScript) || bInVehicle) int mi = GetModelIndex();
if ((mi >= MI_COP && mi <= MI_FIREMAN) || (CharCreatedBy == MISSION_CHAR && !bMoneyHasBeenGivenByScript) || bInVehicle)
return; return;
int money = m_nPedMoney; int money = m_nPedMoney;
@ -7095,8 +7087,8 @@ CPed::CreateDeadPedPickupCoors(float *x, float *y, float *z)
for (int i = 0; i < NUMBER_OF_ATTEMPTS; i++) { for (int i = 0; i < NUMBER_OF_ATTEMPTS; i++) {
pickupPos = GetPosition(); pickupPos = GetPosition();
pickupPos.x = 1.5f * Sin((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().x; pickupPos.x = 1.5f * Sin((CGeneral::GetRandomNumber() % 256)/256.0f * TWOPI) + GetPosition().x;
pickupPos.y = 1.5f * Cos((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().y; pickupPos.y = 1.5f * Cos((CGeneral::GetRandomNumber() % 256)/256.0f * TWOPI) + GetPosition().y;
pickupPos.z = CWorld::FindGroundZFor3DCoord(pickupPos.x, pickupPos.y, pickupPos.z, &found) + 0.5f; pickupPos.z = CWorld::FindGroundZFor3DCoord(pickupPos.x, pickupPos.y, pickupPos.z, &found) + 0.5f;
if (!found) if (!found)
@ -8187,12 +8179,12 @@ SelectClosestNodeForSeek(CPed *ped, CPathNode *node, CVector2D closeDist, CVecto
if (farDist.MagnitudeSqr() > dist) { if (farDist.MagnitudeSqr() > dist) {
if (closeDist.MagnitudeSqr() <= dist) { if (closeDist.MagnitudeSqr() > dist) {
ped->m_pNextPathNode = closeNode;
closeDist = posDiff;
} else {
ped->m_pNextPathNode = (closeNode2 ? closeNode2 : testNode); ped->m_pNextPathNode = (closeNode2 ? closeNode2 : testNode);
farDist = posDiff; farDist = posDiff;
} else {
ped->m_pNextPathNode = closeNode;
closeDist = posDiff;
} }
} }
@ -8209,9 +8201,9 @@ CPed::FindBestCoordsFromNodes(CVector unused, CVector *bestCoords)
if (m_pNextPathNode || !bUsePedNodeSeek) if (m_pNextPathNode || !bUsePedNodeSeek)
return false; return false;
CVector ourPos = GetPosition(); const CVector &ourPos = GetPosition();
int closestNodeId = ThePaths.FindNodeClosestToCoors(GetPosition(), 1, 999999.9f, false, false); int closestNodeId = ThePaths.FindNodeClosestToCoors(GetPosition(), 1, 999999.9f);
CVector seekObjPos = m_vecSeekPos; CVector seekObjPos = m_vecSeekPos;
seekObjPos.z += 1.0f; seekObjPos.z += 1.0f;
@ -8234,8 +8226,7 @@ CPed::FindBestCoordsFromNodes(CVector unused, CVector *bestCoords)
CVector correctedCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); CVector correctedCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed);
if ((correctedCoords - ourPos).MagnitudeSqr2D() < seekPosDist.MagnitudeSqr()) { if ((correctedCoords - ourPos).MagnitudeSqr2D() < seekPosDist.MagnitudeSqr()) {
correctedCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed); *bestCoords = CPathFind::TakeWidthIntoAccountForWandering(m_pNextPathNode, m_randomSeed);
*bestCoords = correctedCoords;
return true; return true;
} }
m_pNextPathNode = nil; m_pNextPathNode = nil;
@ -8305,7 +8296,7 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg)
return; return;
CVector forward(0.09f * ped->GetForward() + ped->GetPosition()); CVector forward(0.09f * ped->GetForward() + ped->GetPosition());
forward.z += CModelInfo::GetModelInfo(ped->GetModelIndex())->GetColModel()->spheres->center.z + 0.35f; forward.z += CModelInfo::GetModelInfo(ped->GetModelIndex())->GetColModel()->spheres[2].center.z + 0.35f;
CEntity *obstacle = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false); CEntity *obstacle = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false);
if (!obstacle) { if (!obstacle) {
@ -9628,7 +9619,7 @@ CPed::Initialise(void)
void void
CPed::SetAnimOffsetForEnterOrExitVehicle(void) CPed::SetAnimOffsetForEnterOrExitVehicle(void)
{ {
// FIX: If there were no translations on enter anims, there were overflows all over this function. // FIX_BUGS: If there were no translations on enter anims, there were overflows all over this function.
int vanBlock = CAnimManager::GetAnimationBlockIndex("van"); int vanBlock = CAnimManager::GetAnimationBlockIndex("van");
int bikesBlock = CAnimManager::GetAnimationBlockIndex("bikes"); int bikesBlock = CAnimManager::GetAnimationBlockIndex("bikes");
@ -13116,18 +13107,16 @@ CPed::PedSetDraggedOutCarPositionCB(CAnimBlendAssociation* animAssoc, void* arg)
} else if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear && ped->CharCreatedBy != MISSION_CHAR } else if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear && ped->CharCreatedBy != MISSION_CHAR
&& ped->m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE && driver && ped->m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE && driver
&& driver->IsPlayer() && !CTheScripts::IsPlayerOnAMission()) { && driver->IsPlayer() && !CTheScripts::IsPlayerOnAMission()) {
ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, ped->m_pMyVehicle); ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, ped->m_pMyVehicle);
} else { } else if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear && ped->CharCreatedBy != MISSION_CHAR
if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear && ped->CharCreatedBy != MISSION_CHAR && ped->m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE && !driver
&& ped->m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE && !driver && FindPlayerPed()->m_carInObjective == ped->m_pMyVehicle && !CTheScripts::IsPlayerOnAMission())
&& FindPlayerPed()->m_carInObjective == ped->m_pMyVehicle && !CTheScripts::IsPlayerOnAMission()) ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, ped->m_pMyVehicle);
ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, ped->m_pMyVehicle); else {
else { ped->SetPedState(PED_NONE);
ped->SetPedState(PED_NONE); ped->m_nLastPedState = PED_NONE;
ped->m_nLastPedState = PED_NONE; ped->SetFindPathAndFlee(ped->m_pMyVehicle->GetPosition(), 10000);
ped->SetFindPathAndFlee(ped->m_pMyVehicle->GetPosition(), 10000);
}
} }
ped->SetGetUp(); ped->SetGetUp();
} }
@ -13552,12 +13541,14 @@ CPed::ReactToPointGun(CEntity *entWithGun)
if (m_nPedType == PEDTYPE_COP) { if (m_nPedType == PEDTYPE_COP) {
if (pedWithGun->IsPlayer()) { if (pedWithGun->IsPlayer()) {
((CPlayerPed*)pedWithGun)->m_pWanted->SetWantedLevelNoDrop(2); ((CPlayerPed*)pedWithGun)->m_pWanted->SetWantedLevelNoDrop(2);
if (bCrouchWhenShooting || bKindaStayInSamePlace) {
SetDuck(CGeneral::GetRandomNumberInRange(1000, 3000));
return;
}
} }
if (bCrouchWhenShooting || bKindaStayInSamePlace) { }
SetDuck(CGeneral::GetRandomNumberInRange(1000, 3000));
}
} else if (m_nPedType != PEDTYPE_COP if (m_nPedType != PEDTYPE_COP
&& (m_nPedState != PED_ATTACK || GetWeapon()->IsTypeMelee()) && (m_nPedState != PED_ATTACK || GetWeapon()->IsTypeMelee())
&& (m_nPedState != PED_FLEE_ENTITY || pedWithGun->IsPlayer() && m_fleeFrom != pedWithGun) && (m_nPedState != PED_FLEE_ENTITY || pedWithGun->IsPlayer() && m_fleeFrom != pedWithGun)
&& m_nPedState != PED_AIM_GUN && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT) { && m_nPedState != PED_AIM_GUN && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT) {
@ -13579,9 +13570,8 @@ CPed::ReactToPointGun(CEntity *entWithGun)
int moneyPerPickup = money / pickupCount; int moneyPerPickup = money / pickupCount;
for (int i = 0; i < pickupCount; i++) { for (int i = 0; i < pickupCount; i++) {
// (CGeneral::GetRandomNumber() % 256) * PI / 128 gives a float up to something TWOPI-ish. float pickupX = 1.5f * Sin((CGeneral::GetRandomNumber() % 256)/256.0f * TWOPI) + GetPosition().x;
float pickupX = 1.5f * Sin((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().x; float pickupY = 1.5f * Cos((CGeneral::GetRandomNumber() % 256)/256.0f * TWOPI) + GetPosition().y;
float pickupY = 1.5f * Cos((CGeneral::GetRandomNumber() % 256) * PI / 128) + GetPosition().y;
bool found = false; bool found = false;
float groundZ = CWorld::FindGroundZFor3DCoord(pickupX, pickupY, GetPosition().z, &found) + 0.5f; float groundZ = CWorld::FindGroundZFor3DCoord(pickupX, pickupY, GetPosition().z, &found) + 0.5f;
if (found) { if (found) {
@ -13900,7 +13890,6 @@ CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *animAssoc, void
CVector finalPos; CVector finalPos;
CVector draggedOutOffset; CVector draggedOutOffset;
CVector finalLocalPos;
CMatrix pedMat(ped->GetMatrix()); CMatrix pedMat(ped->GetMatrix());
ped->bUsesCollision = true; ped->bUsesCollision = true;
@ -13909,8 +13898,7 @@ CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *animAssoc, void
if (ped->m_vehEnterType == CAR_DOOR_RF || ped->m_vehEnterType == CAR_DOOR_RR) if (ped->m_vehEnterType == CAR_DOOR_RF || ped->m_vehEnterType == CAR_DOOR_RR)
draggedOutOffset.x = -draggedOutOffset.x; draggedOutOffset.x = -draggedOutOffset.x;
finalLocalPos = Multiply3x3(pedMat, draggedOutOffset); finalPos = Multiply3x3(pedMat, draggedOutOffset) + ped->GetPosition();
finalPos = finalLocalPos + ped->GetPosition();
CPedPlacement::FindZCoorForPed(&finalPos); CPedPlacement::FindZCoorForPed(&finalPos);
ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); ped->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
ped->SetPosition(finalPos); ped->SetPosition(finalPos);
@ -13955,28 +13943,25 @@ CPed::PedSetQuickDraggedOutCarPositionCB(CAnimBlendAssociation *animAssoc, void
ped->m_pNextPathNode = nil; ped->m_pNextPathNode = nil;
ped->Say(SOUND_PED_FLEE_RUN); ped->Say(SOUND_PED_FLEE_RUN);
} }
} else if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear
&& ped->CharCreatedBy != MISSION_CHAR && veh->VehicleCreatedBy != MISSION_VEHICLE
&& veh->pDriver && veh->pDriver->IsPlayer()
&& !CTheScripts::IsPlayerOnAMission()) {
ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
} else if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear
&& ped->CharCreatedBy != MISSION_CHAR && veh->VehicleCreatedBy != MISSION_VEHICLE
&& !veh->pDriver && FindPlayerPed()->m_carInObjective == veh
&& !CTheScripts::IsPlayerOnAMission()) {
ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
} else { } else {
if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear ped->SetFindPathAndFlee(veh->GetPosition(), 10000);
&& ped->CharCreatedBy != MISSION_CHAR && veh->VehicleCreatedBy != MISSION_VEHICLE if (CGeneral::GetRandomNumber() & 1 || ped->m_pedStats->m_fear > 70) {
&& veh->pDriver && veh->pDriver->IsPlayer() ped->SetMoveState(PEDMOVE_SPRINT);
&& !CTheScripts::IsPlayerOnAMission()) { ped->Say(SOUND_PED_FLEE_SPRINT);
ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
} else { } else {
if (ped->m_pedStats->m_temper > ped->m_pedStats->m_fear && ped->CharCreatedBy != MISSION_CHAR ped->Say(SOUND_PED_FLEE_RUN);
&& ped->m_pMyVehicle->VehicleCreatedBy != MISSION_VEHICLE && !veh->pDriver
&& FindPlayerPed()->m_carInObjective == ped->m_pMyVehicle && !CTheScripts::IsPlayerOnAMission())
ped->SetObjective(OBJECTIVE_ENTER_CAR_AS_DRIVER, veh);
else {
ped->SetFindPathAndFlee(veh->GetPosition(), 10000);
if (CGeneral::GetRandomNumber() & 1 || ped->m_pedStats->m_fear > 70) {
ped->SetMoveState(PEDMOVE_SPRINT);
ped->Say(SOUND_PED_FLEE_SPRINT);
} else {
ped->Say(SOUND_PED_FLEE_RUN);
}
}
} }
} }
} }
@ -14446,7 +14431,7 @@ CPed::ProcessObjective(void)
break; break;
case OBJECTIVE_GUARD_SPOT: case OBJECTIVE_GUARD_SPOT:
{ {
distWithTarget = m_vecSeekPosEx - GetPosition(); distWithTarget = m_vecSpotToGuard - GetPosition();
if (m_pedInObjective) { if (m_pedInObjective) {
SetLookFlag(m_pedInObjective, true); SetLookFlag(m_pedInObjective, true);
m_pLookTarget = m_pedInObjective; m_pLookTarget = m_pedInObjective;
@ -14454,13 +14439,13 @@ CPed::ProcessObjective(void)
TurnBody(); TurnBody();
} }
float distWithTargetSc = distWithTarget.Magnitude(); float distWithTargetSc = distWithTarget.Magnitude();
if (2.0f * m_distanceToCountSeekDoneEx >= distWithTargetSc) { if (2.0f * m_radiusToGuard >= distWithTargetSc) {
if (m_pedInObjective && m_pedInObjective->m_nPedState != PED_DEAD) { if (m_pedInObjective && m_pedInObjective->m_nPedState != PED_DEAD) {
if (distWithTargetSc <= m_distanceToCountSeekDoneEx) if (distWithTargetSc <= m_radiusToGuard)
SetIdle(); SetIdle();
else { else {
CVector seekPos = m_vecSeekPosEx; CVector seekPos = m_vecSpotToGuard;
SetSeek(seekPos, m_distanceToCountSeekDoneEx); SetSeek(seekPos, m_radiusToGuard);
} }
} else if (CTimer::GetTimeInMilliseconds() > m_lookTimer) { } else if (CTimer::GetTimeInMilliseconds() > m_lookTimer) {
int threatType = ScanForThreats(); int threatType = ScanForThreats();
@ -14473,8 +14458,8 @@ CPed::ProcessObjective(void)
} }
} }
} else { } else {
CVector seekPos = m_vecSeekPosEx; CVector seekPos = m_vecSpotToGuard;
SetSeek(seekPos, m_distanceToCountSeekDoneEx); SetSeek(seekPos, m_radiusToGuard);
} }
break; break;
} }
@ -17033,7 +17018,6 @@ CPed::SetFollowPathStatic(void)
SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_followPathDestPos); SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_followPathDestPos);
} }
SetPedState(PED_NONE); SetPedState(PED_NONE);
return true;
} else { } else {
ThePaths.DoPathSearch(PATH_PED, GetPosition(), -1, m_followPathDestPos, m_pathNodesToGo, &m_nNumPathNodes, ThePaths.DoPathSearch(PATH_PED, GetPosition(), -1, m_followPathDestPos, m_pathNodesToGo, &m_nNumPathNodes,
ARRAY_SIZE(m_pathNodesToGo), nil, nil, 999999.9f, -1); ARRAY_SIZE(m_pathNodesToGo), nil, nil, 999999.9f, -1);
@ -17073,7 +17057,6 @@ CPed::SetFollowPathStatic(void)
m_nPedState = PED_FOLLOW_PATH; m_nPedState = PED_FOLLOW_PATH;
m_nMoveState = m_followPathMoveState; m_nMoveState = m_followPathMoveState;
return true;
} else { } else {
RestorePreviousState(); RestorePreviousState();
if (m_objective == OBJECTIVE_NONE) { if (m_objective == OBJECTIVE_NONE) {
@ -17083,9 +17066,9 @@ CPed::SetFollowPathStatic(void)
SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_followPathDestPos); SetObjective(OBJECTIVE_GOTO_AREA_ON_FOOT, m_followPathDestPos);
} }
SetPedState(PED_NONE); SetPedState(PED_NONE);
return true;
} }
} }
return true;
} }
// --MIAMI: Done // --MIAMI: Done
@ -17955,31 +17938,7 @@ CPed::ScanForInterestingStuff(void)
return; return;
if (m_nPedType == PEDTYPE_CRIMINAL && m_hitRecoverTimer < CTimer::GetTimeInMilliseconds()) { if (m_nPedType == PEDTYPE_CRIMINAL && m_hitRecoverTimer < CTimer::GetTimeInMilliseconds()) {
if (CGeneral::GetRandomNumber() % 100 >= 10) { if (CGeneral::GetRandomNumber() % 100 < 10) {
if (m_objective != OBJECTIVE_MUG_CHAR && !(CGeneral::GetRandomNumber() & 7)) {
CPed *charToMug = nil;
for (int i = 0; i < m_numNearPeds; ++i) {
CPed *nearPed = m_nearPeds[i];
if ((nearPed->GetPosition() - GetPosition()).MagnitudeSqr() > sq(7.0f))
break;
if ((nearPed->m_nPedType == PEDTYPE_CIVFEMALE || nearPed->m_nPedType == PEDTYPE_CIVMALE
|| nearPed->m_nPedType == PEDTYPE_CRIMINAL || nearPed->m_nPedType == PEDTYPE_UNUSED1
|| nearPed->m_nPedType == PEDTYPE_PROSTITUTE)
&& nearPed->CharCreatedBy != MISSION_CHAR
&& nearPed->IsPedShootable()
&& nearPed->m_objective != OBJECTIVE_MUG_CHAR) {
charToMug = nearPed;
break;
}
}
if (charToMug)
SetObjective(OBJECTIVE_MUG_CHAR, charToMug);
m_hitRecoverTimer = CTimer::GetTimeInMilliseconds() + 5000;
}
} else {
int mostExpensiveVehAround = -1; int mostExpensiveVehAround = -1;
int bestMonetaryValue = 0; int bestMonetaryValue = 0;
@ -18005,13 +17964,33 @@ CPed::ScanForInterestingStuff(void)
return; return;
} }
m_hitRecoverTimer = CTimer::GetTimeInMilliseconds() + 5000; m_hitRecoverTimer = CTimer::GetTimeInMilliseconds() + 5000;
} else if (m_objective != OBJECTIVE_MUG_CHAR && !(CGeneral::GetRandomNumber() & 7)) {
CPed *charToMug = nil;
for (int i = 0; i < m_numNearPeds; ++i) {
CPed *nearPed = m_nearPeds[i];
if ((nearPed->GetPosition() - GetPosition()).MagnitudeSqr() > sq(7.0f))
break;
if ((nearPed->m_nPedType == PEDTYPE_CIVFEMALE || nearPed->m_nPedType == PEDTYPE_CIVMALE
|| nearPed->m_nPedType == PEDTYPE_CRIMINAL || nearPed->m_nPedType == PEDTYPE_UNUSED1
|| nearPed->m_nPedType == PEDTYPE_PROSTITUTE)
&& nearPed->CharCreatedBy != MISSION_CHAR
&& nearPed->IsPedShootable()
&& nearPed->m_objective != OBJECTIVE_MUG_CHAR) {
charToMug = nearPed;
break;
}
}
if (charToMug)
SetObjective(OBJECTIVE_MUG_CHAR, charToMug);
m_hitRecoverTimer = CTimer::GetTimeInMilliseconds() + 5000;
} }
} }
if (m_nPedState == PED_WANDER_PATH) { if (m_nPedState == PED_WANDER_PATH) {
if (CGeneral::GetRandomNumberInRange(0.0f, 1.0f) >= 0.5f) { if (CGeneral::GetRandomNumberInRange(0.0f, 1.0f) < 0.5f) {
m_standardTimer = CTimer::GetTimeInMilliseconds() + 200;
} else {
if (CTimer::GetTimeInMilliseconds() > m_standardTimer) { if (CTimer::GetTimeInMilliseconds() > m_standardTimer) {
for (int i = 0; i < m_numNearPeds; i ++) { for (int i = 0; i < m_numNearPeds; i ++) {
if (m_nearPeds[i] && m_nearPeds[i]->m_nPedState == PED_WANDER_PATH) { if (m_nearPeds[i] && m_nearPeds[i]->m_nPedState == PED_WANDER_PATH) {
@ -18027,33 +18006,10 @@ CPed::ScanForInterestingStuff(void)
} }
} }
} }
} else {
m_standardTimer = CTimer::GetTimeInMilliseconds() + 200;
} }
} }
/*
// This part isn't there in VC, is it removed?
if (!CGame::noProstitutes && m_nPedType == PEDTYPE_PROSTITUTE && CharCreatedBy != MISSION_CHAR
&& m_objectiveTimer < CTimer::GetTimeInMilliseconds() && !CTheScripts::IsPlayerOnAMission()) {
CVector pos = GetPosition();
int16 lastVehicle;
CEntity* vehicles[8];
CWorld::FindObjectsInRange(pos, CHECK_NEARBY_THINGS_MAX_DIST, true, &lastVehicle, 6, vehicles, false, true, false, false, false);
for (int i = 0; i < lastVehicle; i++) {
CVehicle* veh = (CVehicle*)vehicles[i];
if (veh->IsVehicleNormal()) {
if (veh->IsCar()) {
if ((GetPosition() - veh->GetPosition()).Magnitude() < 5.0f && veh->IsRoomForPedToLeaveCar(CAR_DOOR_LF, nil)) {
SetObjective(OBJECTIVE_SOLICIT_VEHICLE, veh);
Say(SOUND_PED_SOLICIT);
return;
}
}
}
}
}
*/
} }
// --MIAMI: Done // --MIAMI: Done
@ -18695,91 +18651,89 @@ CPed::UpdateFromLeader(void)
return; return;
} }
} }
if (bInVehicle || !m_leader->bInVehicle || m_leader->m_nPedState != PED_DRIVING) { if (!bInVehicle && m_leader->bInVehicle && m_leader->m_nPedState == PED_DRIVING) {
if (m_leader->m_objective != OBJECTIVE_NONE && (!m_leader->IsPlayer() || m_leader->m_objective != OBJECTIVE_WAIT_ON_FOOT) if (m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) {
&& m_objective != m_leader->m_objective) { if (m_leader->m_pMyVehicle->m_nNumPassengers < m_leader->m_pMyVehicle->m_nNumMaxPassengers)
SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_leader->m_pMyVehicle);
}
} else if (m_leader->m_objective == OBJECTIVE_NONE || (m_leader->IsPlayer() && m_leader->m_objective == OBJECTIVE_WAIT_ON_FOOT)
|| m_objective == m_leader->m_objective) {
switch (m_leader->m_objective) { if (m_leader->m_nPedState == PED_ATTACK && !bDontFight) {
case OBJECTIVE_WAIT_ON_FOOT: CEntity *lookTargetOfLeader = m_leader->m_pLookTarget;
case OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE:
case OBJECTIVE_WAIT_IN_CAR: if (lookTargetOfLeader && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT && lookTargetOfLeader->IsPed() && lookTargetOfLeader != this) {
case OBJECTIVE_FOLLOW_ROUTE: SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, lookTargetOfLeader);
SetObjective(m_leader->m_objective); SetObjectiveTimer(8000);
m_objectiveTimer = m_leader->m_objectiveTimer; SetLookFlag(m_leader->m_pLookTarget, false);
break; SetLookTimer(500);
case OBJECTIVE_GUARD_SPOT:
SetObjective(OBJECTIVE_GUARD_SPOT, m_leader->m_vecSeekPosEx);
m_objectiveTimer = m_leader->m_objectiveTimer;
break;
case OBJECTIVE_KILL_CHAR_ON_FOOT:
case OBJECTIVE_KILL_CHAR_ANY_MEANS:
case OBJECTIVE_GOTO_CHAR_ON_FOOT:
case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING:
case OBJECTIVE_HASSLE_CHAR:
if (m_leader->m_pedInObjective) {
SetObjective(m_leader->m_objective, m_leader->m_pedInObjective);
m_objectiveTimer = m_leader->m_objectiveTimer;
}
break;
case OBJECTIVE_ENTER_CAR_AS_PASSENGER:
case OBJECTIVE_ENTER_CAR_AS_DRIVER:
if (m_leader->m_carInObjective) {
m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 150;
SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_leader->m_carInObjective);
return;
}
break;
case OBJECTIVE_GUARD_ATTACK:
return;
case OBJECTIVE_HAIL_TAXI:
m_leader = nil;
SetObjective(OBJECTIVE_NONE);
break;
default:
SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT, m_leader);
SetObjectiveTimer(0);
break;
} }
} else { } else {
if (m_leader->m_nPedState == PED_ATTACK && !bDontFight) { if (IsPedInControl() && m_nPedState != PED_ATTACK) {
CEntity *lookTargetOfLeader = m_leader->m_pLookTarget; if (m_leader->m_objective == OBJECTIVE_NONE && m_objective == OBJECTIVE_NONE && m_leader->m_nPedState == PED_CHAT && m_nPedState == PED_CHAT) {
SetObjective(OBJECTIVE_NONE);
if (lookTargetOfLeader && m_objective != OBJECTIVE_KILL_CHAR_ON_FOOT && lookTargetOfLeader->IsPed() && lookTargetOfLeader != this) { } else {
SetObjective(OBJECTIVE_KILL_CHAR_ON_FOOT, lookTargetOfLeader); SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT, m_leader);
SetObjectiveTimer(8000); SetObjectiveTimer(0);
SetLookFlag(m_leader->m_pLookTarget, false);
SetLookTimer(500);
} }
} else { }
if (IsPedInControl() && m_nPedState != PED_ATTACK) { if (m_nPedState == PED_IDLE && m_leader->IsPlayer() && !bDontFight) {
if (m_leader->m_objective != OBJECTIVE_NONE || m_objective != OBJECTIVE_NONE || m_leader->m_nPedState != PED_CHAT || m_nPedState != PED_CHAT) { if (ScanForThreats() && m_threatEntity) {
SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT, m_leader); m_pLookTarget = m_threatEntity;
SetObjectiveTimer(0); m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget);
} else { TurnBody();
SetObjective(OBJECTIVE_NONE); if (m_attackTimer < CTimer::GetTimeInMilliseconds() && !GetWeapon()->IsTypeMelee()) {
} if (m_pPointGunAt)
} m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt);
if (m_nPedState == PED_IDLE && m_leader->IsPlayer() && !bDontFight) { m_pPointGunAt = m_threatEntity;
if (ScanForThreats() && m_threatEntity) { if (m_threatEntity)
m_pLookTarget = m_threatEntity; m_threatEntity->RegisterReference((CEntity **) &m_pPointGunAt);
m_pLookTarget->RegisterReference((CEntity **) &m_pLookTarget); SetAttack(m_threatEntity);
TurnBody();
if (m_attackTimer < CTimer::GetTimeInMilliseconds() && !GetWeapon()->IsTypeMelee()) {
if (m_pPointGunAt)
m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt);
m_pPointGunAt = m_threatEntity;
if (m_threatEntity)
m_threatEntity->RegisterReference((CEntity **) &m_pPointGunAt);
SetAttack(m_threatEntity);
}
} }
} }
} }
} }
} else { } else {
if (m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_ENTER_CAR_AS_DRIVER) { switch (m_leader->m_objective) {
if (m_leader->m_pMyVehicle->m_nNumPassengers < m_leader->m_pMyVehicle->m_nNumMaxPassengers) case OBJECTIVE_WAIT_ON_FOOT:
SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_leader->m_pMyVehicle); case OBJECTIVE_FLEE_ON_FOOT_TILL_SAFE:
case OBJECTIVE_WAIT_IN_CAR:
case OBJECTIVE_FOLLOW_ROUTE:
SetObjective(m_leader->m_objective);
m_objectiveTimer = m_leader->m_objectiveTimer;
break;
case OBJECTIVE_GUARD_SPOT:
SetObjective(OBJECTIVE_GUARD_SPOT, m_leader->m_vecSpotToGuard);
m_objectiveTimer = m_leader->m_objectiveTimer;
break;
case OBJECTIVE_KILL_CHAR_ON_FOOT:
case OBJECTIVE_KILL_CHAR_ANY_MEANS:
case OBJECTIVE_GOTO_CHAR_ON_FOOT:
case OBJECTIVE_GOTO_CHAR_ON_FOOT_WALKING:
case OBJECTIVE_HASSLE_CHAR:
if (m_leader->m_pedInObjective) {
SetObjective(m_leader->m_objective, m_leader->m_pedInObjective);
m_objectiveTimer = m_leader->m_objectiveTimer;
}
break;
case OBJECTIVE_ENTER_CAR_AS_PASSENGER:
case OBJECTIVE_ENTER_CAR_AS_DRIVER:
if (m_leader->m_carInObjective) {
m_leaveCarTimer = CTimer::GetTimeInMilliseconds() + 150;
SetObjective(OBJECTIVE_ENTER_CAR_AS_PASSENGER, m_leader->m_carInObjective);
return;
}
break;
case OBJECTIVE_GUARD_ATTACK:
return;
case OBJECTIVE_HAIL_TAXI:
m_leader = nil;
SetObjective(OBJECTIVE_NONE);
break;
default:
SetObjective(OBJECTIVE_GOTO_CHAR_ON_FOOT, m_leader);
SetObjectiveTimer(0);
break;
} }
} }
} else if (bInVehicle) { } else if (bInVehicle) {
@ -18816,34 +18770,32 @@ CPed::UpdatePosition(void)
SetHeading(m_fRotationCur); SetHeading(m_fRotationCur);
if (m_pCurrentPhysSurface) { if (m_pCurrentPhysSurface) {
CVector2D velocityOfSurface; CVector2D velocityOfSurface;
CPhysical *curSurface = m_pCurrentPhysSurface;
if (!IsPlayer() && m_pCurrentPhysSurface->IsVehicle() && ((CVehicle*)m_pCurrentPhysSurface)->IsBoat()) { if (!IsPlayer() && m_pCurrentPhysSurface->IsVehicle() && ((CVehicle*)m_pCurrentPhysSurface)->IsBoat()) {
// It seems R* didn't like m_vecOffsetFromPhysSurface for boats // It seems R* didn't like m_vecOffsetFromPhysSurface for boats
CVector offsetToSurface = GetPosition() - curSurface->GetPosition(); CVector offsetToSurface = GetPosition() - m_pCurrentPhysSurface->GetPosition();
offsetToSurface.z -= FEET_OFFSET; offsetToSurface.z -= FEET_OFFSET;
CVector surfaceMoveVelocity = curSurface->m_vecMoveSpeed; CVector surfaceMoveVelocity = m_pCurrentPhysSurface->m_vecMoveSpeed;
CVector surfaceTurnVelocity = CrossProduct(curSurface->m_vecTurnSpeed, offsetToSurface); CVector surfaceTurnVelocity = CrossProduct(m_pCurrentPhysSurface->m_vecTurnSpeed, offsetToSurface);
// Also we use that weird formula instead of friction if it's boat // Also we use that weird formula instead of friction if it's boat
float slideMult = -curSurface->m_vecTurnSpeed.MagnitudeSqr(); float slideMult = -m_pCurrentPhysSurface->m_vecTurnSpeed.MagnitudeSqr();
velocityOfSurface = slideMult * offsetToSurface * CTimer::GetTimeStep() + (surfaceTurnVelocity + surfaceMoveVelocity); velocityOfSurface = slideMult * offsetToSurface * CTimer::GetTimeStep() + (surfaceTurnVelocity + surfaceMoveVelocity);
m_vecMoveSpeed.z = slideMult * offsetToSurface.z * CTimer::GetTimeStep() + (surfaceTurnVelocity.z + surfaceMoveVelocity.z); m_vecMoveSpeed.z = slideMult * offsetToSurface.z * CTimer::GetTimeStep() + (surfaceTurnVelocity.z + surfaceMoveVelocity.z);
} else { } else {
velocityOfSurface = curSurface->GetSpeed(m_vecOffsetFromPhysSurface); velocityOfSurface = m_pCurrentPhysSurface->GetSpeed(m_vecOffsetFromPhysSurface);
} }
// Reminder: m_moved is displacement from walking/running. // Reminder: m_moved is displacement from walking/running.
velocityChange = m_moved + velocityOfSurface - m_vecMoveSpeed; velocityChange = m_moved + velocityOfSurface - m_vecMoveSpeed;
m_fRotationCur += curSurface->m_vecTurnSpeed.z * CTimer::GetTimeStep(); m_fRotationCur += m_pCurrentPhysSurface->m_vecTurnSpeed.z * CTimer::GetTimeStep();
m_fRotationDest += curSurface->m_vecTurnSpeed.z * CTimer::GetTimeStep(); m_fRotationDest += m_pCurrentPhysSurface->m_vecTurnSpeed.z * CTimer::GetTimeStep();
} else if (m_nSurfaceTouched != SURFACE_STEEP_CLIFF || m_vecDamageNormal.x == 0.0f && m_vecDamageNormal.y == 0.0f) { } else if (m_nSurfaceTouched == SURFACE_STEEP_CLIFF && (m_vecDamageNormal.x != 0.0f || m_vecDamageNormal.y != 0.0f)) {
velocityChange = m_moved - m_vecMoveSpeed;
} else {
// Ped got damaged by steep slope // Ped got damaged by steep slope
m_vecMoveSpeed = CVector(0.0f, 0.0f, -0.001f); m_vecMoveSpeed = CVector(0.0f, 0.0f, -0.001f);
// some kind of // some kind of
CVector2D reactionForce = m_vecDamageNormal * (1.0f / m_vecDamageNormal.Magnitude2D()); CVector2D reactionForce = m_vecDamageNormal;
reactionForce.Normalise();
velocityChange = 0.02f * reactionForce + m_moved; velocityChange = 0.02f * reactionForce + m_moved;
@ -18852,17 +18804,18 @@ CPed::UpdatePosition(void)
if (reactionAndVelocityDotProd < 0.0f) { if (reactionAndVelocityDotProd < 0.0f) {
velocityChange -= reactionAndVelocityDotProd * reactionForce; velocityChange -= reactionAndVelocityDotProd * reactionForce;
} }
} else {
velocityChange = m_moved - m_vecMoveSpeed;
} }
// Take time step into account // Take time step into account
if (m_pCurrentPhysSurface && (!m_pCurrentPhysSurface->bInfiniteMass || m_pCurrentPhysSurface->m_phy_flagA08)) { if (m_pCurrentPhysSurface && (!m_pCurrentPhysSurface->bInfiniteMass || m_pCurrentPhysSurface->m_phy_flagA08)) {
float speedChange = velocityChange.Magnitude(); float speedChange = velocityChange.Magnitude();
float changeMult = speedChange; float changeMult = speedChange;
if (m_nPedState != PED_DIE || !m_pCurrentPhysSurface->IsVehicle()) { if (m_nPedState == PED_DIE && m_pCurrentPhysSurface->IsVehicle()) {
if (!m_pCurrentPhysSurface->IsVehicle() || !((CVehicle*)m_pCurrentPhysSurface)->IsBoat())
changeMult = 0.01f * CTimer::GetTimeStep();
} else {
changeMult = 0.002f * CTimer::GetTimeStep(); changeMult = 0.002f * CTimer::GetTimeStep();
} else if (!(m_pCurrentPhysSurface->IsVehicle() && ((CVehicle*)m_pCurrentPhysSurface)->IsBoat())) {
changeMult = 0.01f * CTimer::GetTimeStep();
} }
if (speedChange > changeMult) { if (speedChange > changeMult) {
@ -18950,9 +18903,10 @@ CPed::SetPedPositionInCar(void)
m_fRotationCur = m_pMyVehicle->GetForward().Heading() - HALFPI; m_fRotationCur = m_pMyVehicle->GetForward().Heading() - HALFPI;
tempMat.SetTranslate(0.0f, 0.0f, 0.0f); tempMat.SetTranslate(0.0f, 0.0f, 0.0f);
tempMat.RotateZ(-HALFPI); tempMat.RotateZ(-HALFPI);
tempMat.Translate(0.0f, 0.6f, 0.0f);
newMat = newMat * tempMat; newMat = newMat * tempMat;
} else if (m_pMyVehicle->pPassengers[2] == this) { } else if (m_pMyVehicle->pPassengers[2] == this) {
m_fRotationCur = HALFPI + m_pMyVehicle->GetForward().Heading(); m_fRotationCur = m_pMyVehicle->GetForward().Heading() + HALFPI;
tempMat.SetTranslate(0.0f, 0.0f, 0.0f); tempMat.SetTranslate(0.0f, 0.0f, 0.0f);
tempMat.RotateZ(HALFPI); tempMat.RotateZ(HALFPI);
newMat = newMat * tempMat; newMat = newMat * tempMat;
@ -19094,7 +19048,7 @@ CPed::SetObjective(eObjective newObj, CVector dest)
if (m_nextRoutePointPos == dest) if (m_nextRoutePointPos == dest)
return; return;
} else if (newObj == OBJECTIVE_GUARD_SPOT) { } else if (newObj == OBJECTIVE_GUARD_SPOT) {
if (m_vecSeekPosEx == dest) if (m_vecSpotToGuard == dest)
return; return;
} }
} }
@ -19104,8 +19058,8 @@ CPed::SetObjective(eObjective newObj, CVector dest)
bObjectiveCompleted = false; bObjectiveCompleted = false;
switch (newObj) { switch (newObj) {
case OBJECTIVE_GUARD_SPOT: case OBJECTIVE_GUARD_SPOT:
m_vecSeekPosEx = dest; m_vecSpotToGuard = dest;
m_distanceToCountSeekDoneEx = 5.0f; m_radiusToGuard = 5.0f;
SetMoveState(PEDMOVE_STILL); SetMoveState(PEDMOVE_STILL);
break; break;
case OBJECTIVE_GUARD_AREA: case OBJECTIVE_GUARD_AREA:

View File

@ -641,8 +641,8 @@ public:
uint16 m_queuedSound; uint16 m_queuedSound;
bool m_canTalk; bool m_canTalk;
uint32 m_lastComment; uint32 m_lastComment;
CVector m_vecSeekPosEx; // used for OBJECTIVE_GUARD_SPOT CVector m_vecSpotToGuard;
float m_distanceToCountSeekDoneEx; // used for OBJECTIVE_GUARD_SPOT float m_radiusToGuard;
static void *operator new(size_t); static void *operator new(size_t);
static void *operator new(size_t, int); static void *operator new(size_t, int);