sync with upstream

This commit is contained in:
Nikolay Korolev
2020-05-16 01:50:45 +03:00
38 changed files with 2383 additions and 1316 deletions

View File

@ -23,7 +23,8 @@ CCopPed::CCopPed(eCopType copType, int32 modifier) : CPed(PEDTYPE_COP)
switch (copType) {
case COP_STREET:
SetModelIndex(MI_COP);
GiveWeapon(WEAPONTYPE_COLT45, 1000);
// GiveWeapon(WEAPONTYPE_NIGHTSTICK, 1000, true); // TODO(Miami)
GiveDelayedWeapon(WEAPONTYPE_COLT45, 1000);
m_currentWeapon = WEAPONTYPE_UNARMED;
m_fArmour = 0.0f;
m_wepSkills = 208; /* TODO: what is this? seems unused */
@ -31,17 +32,15 @@ CCopPed::CCopPed(eCopType copType, int32 modifier) : CPed(PEDTYPE_COP)
break;
case COP_FBI:
SetModelIndex(MI_FBI);
GiveWeapon(WEAPONTYPE_COLT45, 1000);
GiveWeapon(WEAPONTYPE_AK47, 1000);
SetCurrentWeapon(WEAPONTYPE_AK47);
GiveDelayedWeapon(WEAPONTYPE_MP5, 1000);
SetCurrentWeapon(WEAPONTYPE_MP5);
m_fArmour = 100.0f;
m_wepSkills = 176; /* TODO: what is this? seems unused */
m_wepAccuracy = 76;
break;
case COP_SWAT:
SetModelIndex(MI_SWAT);
GiveWeapon(WEAPONTYPE_COLT45, 1000);
GiveWeapon(WEAPONTYPE_UZI, 1000);
GiveDelayedWeapon(WEAPONTYPE_UZI, 1000);
SetCurrentWeapon(WEAPONTYPE_UZI);
m_fArmour = 50.0f;
m_wepSkills = 32; /* TODO: what is this? seems unused */
@ -49,10 +48,8 @@ CCopPed::CCopPed(eCopType copType, int32 modifier) : CPed(PEDTYPE_COP)
break;
case COP_ARMY:
SetModelIndex(MI_ARMY);
GiveWeapon(WEAPONTYPE_COLT45, 1000);
GiveWeapon(WEAPONTYPE_M16, 1000);
GiveWeapon(WEAPONTYPE_GRENADE, 10);
SetCurrentWeapon(WEAPONTYPE_M16);
GiveDelayedWeapon(WEAPONTYPE_MP5, 1000);
SetCurrentWeapon(WEAPONTYPE_MP5);
m_fArmour = 100.0f;
m_wepSkills = 32; /* TODO: what is this? seems unused */
m_wepAccuracy = 84;
@ -69,7 +66,7 @@ CCopPed::CCopPed(eCopType copType, int32 modifier) : CPed(PEDTYPE_COP)
case 7: SetModelIndex(MI_VICE8); break;
default: assert(0); break;
}
GiveWeapon(WEAPONTYPE_UZI, 1000);
GiveDelayedWeapon(WEAPONTYPE_UZI, 1000);
SetCurrentWeapon(WEAPONTYPE_UZI);
m_fArmour = 100.0f;
m_wepSkills = 176;

View File

@ -314,7 +314,7 @@ CEmergencyPed::MedicAI(void)
m_nEmergencyPedState = EMERGENCY_PED_STAND_STILL;
} else {
m_nEmergencyPedState = EMERGENCY_PED_FACE_TO_PATIENT;
m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_STD, ANIM_CPR, 4.0f);
m_pVehicleAnim = CAnimManager::BlendAnimation(GetClump(), ASSOCGRP_MEDIC, ANIM_CPR, 4.0f);
bIsDucking = true;
}
SetLookTimer(2000);

File diff suppressed because it is too large Load Diff

View File

@ -521,8 +521,9 @@ public:
uint8 m_stateUnused;
uint32 m_timerUnused;
CVector2D *m_wanderRangeBounds; // array with 2 CVector2D (actually unused CRange2D class) - unused
CWeapon m_weapons[WEAPONTYPE_TOTAL_INVENTORY_WEAPONS];
CWeapon m_weapons[TOTAL_WEAPON_SLOTS];
eWeaponType m_storedWeapon;
uint32 m_storedWeaponAmmo;
uint8 m_currentWeapon; // eWeaponType
uint8 m_maxWeaponTypeAllowed; // eWeaponType
uint8 m_wepSkills;
@ -548,12 +549,26 @@ public:
uint32 m_duckTimer;
uint32 m_duckAndCoverTimer;
uint32 m_bloodyFootprintCountOrDeathTime; // Death time when bDoBloodyFootprints is false. Weird decision
uint32 m_shotTime;
uint32 m_shotTimeAdd;
uint8 m_panicCounter;
bool m_deadBleeding;
int8 m_bodyPartBleeding; // PedNode, but -1 if there isn't
CPed *m_nearPeds[10];
uint16 m_numNearPeds;
int8 m_lastWepDam;
uint16 m_pedMoney;
int8 m_lastWepDam;
CEntity *m_lastDamEntity;
CEntity *m_attachedTo;
CVector m_vecAttachOffset;
uint16 m_attachType;
float m_attachRot;
uint32 m_attachWepAmmo;
uint32 m_threatFlags;
uint32 m_threatCheck;
uint32 m_lastThreatCheck;
uint32 m_sayType;
uint32 m_sayTimer;
uint32 m_lastSoundStart;
uint32 m_soundStart;
uint16 m_lastQueuedSound;
@ -601,7 +616,8 @@ public:
void ClearAttack(void);
bool IsPedHeadAbovePos(float zOffset);
void RemoveWeaponModel(int modelId);
void SetCurrentWeapon(uint32 weaponType);
void SetCurrentWeapon(eWeaponType weaponType);
void SetCurrentWeapon(int weapon);
void Duck(void);
void ClearDuck(void);
void ClearPointGunAt(void);
@ -612,7 +628,7 @@ public:
void PlayFootSteps(void);
void QuitEnteringCar(void);
void BuildPedLists(void);
uint32 GiveWeapon(eWeaponType weaponType, uint32 ammo);
int32 GiveWeapon(eWeaponType weaponType, uint32 ammo, bool unused = false);
void CalculateNewOrientation(void);
float WorkOutHeadingForMovingFirstPerson(float);
void CalculateNewVelocity(void);
@ -685,6 +701,7 @@ public:
void RemoveInCarAnims(void);
void CollideWithPed(CPed*);
void SetDirectionToWalkAroundObject(CEntity*);
void RemoveWeaponAnims(int, float);
void CreateDeadPedMoney(void);
void CreateDeadPedWeaponPickups(void);
void SetAttackTimer(uint32);
@ -700,7 +717,6 @@ public:
void EnterCar(void);
uint8 GetNearestTrainPedPosition(CVehicle*, CVector&);
uint8 GetNearestTrainDoor(CVehicle*, CVector&);
void LineUpPedWithTrain(void);
void ExitCar(void);
void Fight(void);
bool FindBestCoordsFromNodes(CVector, CVector*);
@ -747,7 +763,6 @@ public:
void SetExitCar(CVehicle*, uint32);
void SetFormation(eFormation);
bool WillChat(CPed*);
void SetEnterTrain(CVehicle*, uint32);
void SetEnterCar_AllClear(CVehicle*, uint32, uint32);
void SetSolicit(uint32 time);
void ScanForInterestingStuff(void);
@ -756,6 +771,9 @@ public:
bool WarpPedToNearLeaderOffScreen(void);
void Solicit(void);
void SetExitBoat(CVehicle*);
void ClearFollowPath();
void GiveDelayedWeapon(eWeaponType weapon, uint32 ammo);
void RequestDelayedWeapon();
// Static methods
static CVector GetLocalPositionToOpenCarDoor(CVehicle *veh, uint32 component, float offset);
@ -783,8 +801,9 @@ public:
static void PedSetDraggedOutCarCB(CAnimBlendAssociation *assoc, void *arg);
static void PedAnimStepOutCarCB(CAnimBlendAssociation *assoc, void *arg);
static void PedSetInTrainCB(CAnimBlendAssociation *assoc, void *arg);
static void PedSetOutTrainCB(CAnimBlendAssociation *assoc, void *arg);
static void PedSetOutTrainCB(CAnimBlendAssociation *assoc, void *arg); // TODO(Miami): Should be under GTA_TRAIN
static void FinishedAttackCB(CAnimBlendAssociation *assoc, void *arg);
static void FinishedReloadCB(CAnimBlendAssociation *assoc, void *arg);
static void FinishFightMoveCB(CAnimBlendAssociation *assoc, void *arg);
static void PedAnimDoorCloseRollingCB(CAnimBlendAssociation *assoc, void *arg);
static void FinishJumpCB(CAnimBlendAssociation *assoc, void *arg);
@ -813,8 +832,14 @@ public:
void SetPedStats(ePedStats);
bool IsGangMember(void);
void Die(void);
#ifdef GTA_TRAIN
void EnterTrain(void);
void ExitTrain(void);
void SetExitTrain(CVehicle*);
void SetPedPositionInTrain(void);
void LineUpPedWithTrain(void);
void SetEnterTrain(CVehicle*, uint32);
#endif
void Fall(void);
bool IsPedShootable(void);
void Look(void);
@ -822,11 +847,9 @@ public:
void RestoreHeadPosition(void);
void PointGunAt(void);
bool ServiceTalkingWhenDead(void);
void SetPedPositionInTrain(void);
void SetShootTimer(uint32);
void SetSeekCar(CVehicle*, uint32);
void SetSeekBoatPosition(CVehicle*);
void SetExitTrain(CVehicle*);
void WanderRange(void);
void SetFollowRoute(int16, int16);
void SeekBoatPosition(void);
@ -866,6 +889,35 @@ public:
void ReplaceWeaponWhenExitingVehicle(void);
void RemoveWeaponWhenEnteringVehicle(void);
bool IsNotInWreckedVehicle();
// My addons. Maybe inlined in VC?
AnimationId GetFireAnimNotDucking(CWeaponInfo* weapon) {
// TODO(Miami): Revert that when weapons got ported
if (weapon->m_AnimToPlay == ASSOCGRP_STD)
return ANIM_FIGHT_PPUNCH;
if (m_nPedType == PEDTYPE_COP && !!weapon->m_bCop3rd)
return ANIM_WEAPON_FIRE_3RD;
else
return weapon->m_bAnimDetonate ? ANIM_BOMBER : ANIM_WEAPON_FIRE;
}
static AnimationId GetFireAnimGround(CWeaponInfo* weapon, bool kickFloorIfNone = true) {
// TODO(Miami): Revert that when weapons got ported
if (weapon->m_AnimToPlay == ASSOCGRP_STD)
return ANIM_KICK_FLOOR;
if (!!weapon->m_bGround2nd)
return ANIM_WEAPON_CROUCHFIRE;
else if (!!weapon->m_bGround3rd)
return ANIM_WEAPON_SPECIAL;
else if (kickFloorIfNone)
return ANIM_KICK_FLOOR;
else
return (AnimationId)0;
}
// --
// My additions, because there were many, many instances of that.
inline void SetFindPathAndFlee(CEntity *fleeFrom, int time, bool walk = false)
{
@ -884,43 +936,24 @@ public:
if (walk)
SetMoveState(PEDMOVE_WALK);
}
// --
// Using this to abstract nodes of skinned and non-skinned meshes
CVector GetNodePosition(int32 node)
{
#ifdef PED_SKIN
if(IsClumpSkinned(GetClump())){
RwV3d pos = { 0.0f, 0.0f, 0.0f };
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump());
int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID);
RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier);
// this is just stupid
//RwV3dTransformPoints(&pos, &pos, 1, &mats[idx]);
pos = mats[idx].pos;
return pos;
}else
#endif
{
RwMatrix mat;
CPedIK::GetWorldMatrix(m_pFrames[node]->frame, &mat);
return mat.pos;
}
RwV3d pos = { 0.0f, 0.0f, 0.0f };
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump());
int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID);
RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier);
pos = mats[idx].pos;
return pos;
}
void TransformToNode(CVector &pos, int32 node)
{
#ifdef PED_SKIN
if(IsClumpSkinned(GetClump())){
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump());
int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID);
RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier);
RwV3dTransformPoints((RwV3d*)&pos, (RwV3d*)&pos, 1, &mats[idx]);
}else
#endif
{
RwFrame *frame;
for (frame = m_pFrames[node]->frame; frame; frame = RwFrameGetParent(frame))
RwV3dTransformPoints((RwV3d*)&pos, (RwV3d*)&pos, 1, RwFrameGetMatrix(frame));
}
RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(GetClump());
int32 idx = RpHAnimIDGetIndex(hier, m_pFrames[node]->nodeID);
RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier);
RwV3dTransformPoints((RwV3d*)&pos, (RwV3d*)&pos, 1, &mats[idx]);
}
// set by 0482:set_threat_reaction_range_multiplier opcode
@ -953,6 +986,7 @@ public:
void FinishFuckUCB(CAnimBlendAssociation *assoc, void *arg);
// TODO(Miami): Change those when Ped struct is done
#ifndef PED_SKIN
VALIDATE_SIZE(CPed, 0x53C);
#endif

View File

@ -7,11 +7,13 @@
#include "General.h"
#include "RwHelper.h"
LimbMovementInfo CPedIK::ms_torsoInfo = { DEGTORAD(50.0f), DEGTORAD(-50.0f), DEGTORAD(15.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(7.0f) };
LimbMovementInfo CPedIK::ms_headInfo = { DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(10.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(5.0f) };
//--MIAMI: file almost done (only some special weapon cases left)
LimbMovementInfo CPedIK::ms_torsoInfo = { DEGTORAD(50.0f), DEGTORAD(-50.0f), DEGTORAD(8.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(5.0f) };
LimbMovementInfo CPedIK::ms_headInfo = { DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(15.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(8.0f) };
LimbMovementInfo CPedIK::ms_headRestoreInfo = { DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(10.0f), DEGTORAD(45.0f), DEGTORAD(-45.0f), DEGTORAD(5.0f) };
LimbMovementInfo CPedIK::ms_upperArmInfo = { DEGTORAD(20.0f), DEGTORAD(-100.0f), DEGTORAD(20.0f), DEGTORAD(70.0f), DEGTORAD(-70.0f), DEGTORAD(10.0f) };
LimbMovementInfo CPedIK::ms_lowerArmInfo = { DEGTORAD(80.0f), DEGTORAD(0.0f), DEGTORAD(20.0f), DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(5.0f) };
LimbMovementInfo CPedIK::ms_upperArmInfo = { DEGTORAD(5.0f), DEGTORAD(-120.0f), DEGTORAD(20.0f), DEGTORAD(70.0f), DEGTORAD(-70.0f), DEGTORAD(20.0f) };
LimbMovementInfo CPedIK::ms_lowerArmInfo = { DEGTORAD(60.0f), DEGTORAD(0.0f), DEGTORAD(15.0f), DEGTORAD(90.0f), DEGTORAD(-90.0f), DEGTORAD(10.0f) };
const RwV3d XaxisIK = { 1.0f, 0.0f, 0.0f};
const RwV3d YaxisIK = { 0.0f, 1.0f, 0.0f};
@ -21,17 +23,16 @@ CPedIK::CPedIK(CPed *ped)
{
m_ped = ped;
m_flags = 0;
m_headOrient.phi = 0.0f;
m_headOrient.theta = 0.0f;
m_torsoOrient.phi = 0.0f;
m_torsoOrient.theta = 0.0f;
m_upperArmOrient.phi = 0.0f;
m_upperArmOrient.theta = 0.0f;
m_lowerArmOrient.phi = 0.0f;
m_lowerArmOrient.theta = 0.0f;
m_headOrient.yaw = 0.0f;
m_headOrient.pitch = 0.0f;
m_torsoOrient.yaw = 0.0f;
m_torsoOrient.pitch = 0.0f;
m_upperArmOrient.yaw = 0.0f;
m_upperArmOrient.pitch = 0.0f;
m_lowerArmOrient.yaw = 0.0f;
m_lowerArmOrient.pitch = 0.0f;
}
#ifdef PED_SKIN
inline RwMatrix*
GetBoneMatrix(CPed *ped, int32 bone)
{
@ -45,174 +46,60 @@ GetComponentMatrix(CPed *ped, int32 node)
{
return GetBoneMatrix(ped, ped->m_pFrames[node]->nodeID);
}
#endif
void
CPedIK::RotateTorso(AnimBlendFrameData *node, LimbOrientation *limb, bool changeRoll)
{
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
RtQuat *q = &node->hanimFrame->q;
#ifndef FIX_BUGS
// this is what the game does (also VC), but it does not look great
RtQuatRotate(q, &XaxisIK, RADTODEG(limb->phi), rwCOMBINEPRECONCAT);
RtQuatRotate(q, &ZaxisIK, RADTODEG(limb->theta), rwCOMBINEPRECONCAT); // pitch
#else
// copied the code from the non-skinned case
// this seems to work ok
// We can't get the parent matrix of an hanim frame but
// this function is always called with PED_MID, so we know the parent frame.
// Trouble is that PED_MID is "Smid" on PS2/PC but BONE_torso on mobile/xbox...
// so this doesn't exactly do what we'd like anyway
RwMatrix* mat = GetComponentMatrix(m_ped, PED_MID);
RwV3d vec1, vec2;
vec1.x = mat->right.z;
vec1.y = mat->up.z;
vec1.z = mat->at.z;
float c = Cos(m_ped->m_fRotationCur);
float s = Sin(m_ped->m_fRotationCur);
vec2.x = -(c*mat->right.x + s*mat->right.y);
vec2.y = -(c*mat->up.x + s*mat->up.y);
vec2.z = -(c*mat->at.x + s*mat->at.y);
// Not sure what exactly to do here
RtQuatRotate(q, &vec1, RADTODEG(limb->phi), rwCOMBINEPRECONCAT);
RtQuatRotate(q, &vec2, RADTODEG(limb->theta), rwCOMBINEPRECONCAT);
#endif
m_ped->bDontAcceptIKLookAts = true;
}else
#endif
{
RwFrame *f = node->frame;
RwMatrix *mat = GetWorldMatrix(RwFrameGetParent(f), RwMatrixCreate());
RwV3d upVector = { mat->right.z, mat->up.z, mat->at.z };
RwV3d rightVector;
RwV3d pos = RwFrameGetMatrix(f)->pos;
// rotation == 0 -> looking in y direction
// left? vector
float c = Cos(m_ped->m_fRotationCur);
float s = Sin(m_ped->m_fRotationCur);
rightVector.x = -(c*mat->right.x + s*mat->right.y);
rightVector.y = -(c*mat->up.x + s*mat->up.y);
rightVector.z = -(c*mat->at.x + s*mat->at.y);
if(changeRoll){
// Used when aiming only involves over the legs.(canAimWithArm)
// Automatically changes roll(forward rotation) axis of the parts above upper legs while moving, based on position of upper legs.
// Not noticeable in normal conditions...
RwV3d forwardVector;
CVector inversedForward = CrossProduct(CVector(0.0f, 0.0f, 1.0f), mat->up);
inversedForward.Normalise();
float dotProduct = DotProduct(mat->at, inversedForward);
if(dotProduct > 1.0f) dotProduct = 1.0f;
if(dotProduct < -1.0f) dotProduct = -1.0f;
float alpha = Acos(dotProduct);
if(mat->at.z < 0.0f)
alpha = -alpha;
forwardVector.x = s * mat->right.x - c * mat->right.y;
forwardVector.y = s * mat->up.x - c * mat->up.y;
forwardVector.z = s * mat->at.x - c * mat->at.y;
float curYaw, curPitch;
ExtractYawAndPitchWorld(mat, &curYaw, &curPitch);
RwMatrixRotate(RwFrameGetMatrix(f), &rightVector, RADTODEG(limb->theta), rwCOMBINEPOSTCONCAT);
RwMatrixRotate(RwFrameGetMatrix(f), &upVector, RADTODEG(limb->phi - (curYaw - m_ped->m_fRotationCur)), rwCOMBINEPOSTCONCAT);
RwMatrixRotate(RwFrameGetMatrix(f), &forwardVector, RADTODEG(alpha), rwCOMBINEPOSTCONCAT);
}else{
// pitch
RwMatrixRotate(RwFrameGetMatrix(f), &rightVector, RADTODEG(limb->theta), rwCOMBINEPOSTCONCAT);
// yaw
RwMatrixRotate(RwFrameGetMatrix(f), &upVector, RADTODEG(limb->phi), rwCOMBINEPOSTCONCAT);
}
RwFrameGetMatrix(f)->pos = pos;
RwMatrixDestroy(mat);
}
RtQuat *q = &node->hanimFrame->q;
RtQuatRotate(q, &XaxisIK, RADTODEG(limb->yaw), rwCOMBINEREPLACE);
RtQuatRotate(q, &ZaxisIK, RADTODEG(limb->pitch), rwCOMBINEPRECONCAT);
m_ped->bDontAcceptIKLookAts = true;
}
void
CPedIK::GetComponentPosition(RwV3d *pos, uint32 node)
{
RwFrame *f;
RwMatrix *mat;
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
pos->x = 0.0f;
pos->y = 0.0f;
pos->z = 0.0f;
mat = GetComponentMatrix(m_ped, node);
// could just copy the position out of the matrix...
RwV3dTransformPoints(pos, pos, 1, mat);
}else
#endif
{
f = m_ped->m_pFrames[node]->frame;
mat = RwFrameGetMatrix(f);
*pos = mat->pos;
for (f = RwFrameGetParent(f); f; f = RwFrameGetParent(f))
RwV3dTransformPoints(pos, pos, 1, RwFrameGetMatrix(f));
}
}
RwMatrix*
CPedIK::GetWorldMatrix(RwFrame *source, RwMatrix *destination)
{
RwFrame *i;
*destination = *RwFrameGetMatrix(source);
for (i = RwFrameGetParent(source); i; i = RwFrameGetParent(i))
RwMatrixTransform(destination, RwFrameGetMatrix(i), rwCOMBINEPOSTCONCAT);
return destination;
*pos = GetComponentMatrix(m_ped, node)->pos;
}
LimbMoveStatus
CPedIK::MoveLimb(LimbOrientation &limb, float approxPhi, float approxTheta, LimbMovementInfo &moveInfo)
CPedIK::MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, LimbMovementInfo &moveInfo)
{
LimbMoveStatus result = ONE_ANGLE_COULDNT_BE_SET_EXACTLY;
// phi
// yaw
if (limb.phi > approxPhi) {
limb.phi -= moveInfo.yawD;
} else if (limb.phi < approxPhi) {
limb.phi += moveInfo.yawD;
}
if (Abs(limb.phi - approxPhi) < moveInfo.yawD) {
limb.phi = approxPhi;
if(Abs(limb.yaw-targetYaw) < moveInfo.yawD){
limb.yaw = targetYaw;
result = ANGLES_SET_EXACTLY;
}else{
if (limb.yaw > targetYaw) {
limb.yaw -= moveInfo.yawD;
} else if (limb.yaw < targetYaw) {
limb.yaw += moveInfo.yawD;
}
}
if (limb.phi > moveInfo.maxYaw || limb.phi < moveInfo.minYaw) {
limb.phi = clamp(limb.phi, moveInfo.minYaw, moveInfo.maxYaw);
if (limb.yaw > moveInfo.maxYaw || limb.yaw < moveInfo.minYaw) {
limb.yaw = clamp(limb.yaw, moveInfo.minYaw, moveInfo.maxYaw);
result = ANGLES_SET_TO_MAX;
}
// theta
// pitch
if (limb.theta > approxTheta) {
limb.theta -= moveInfo.pitchD;
} else if (limb.theta < approxTheta) {
limb.theta += moveInfo.pitchD;
if (Abs(limb.pitch - targetPitch) < moveInfo.pitchD){
limb.pitch = targetPitch;
}else{
if (limb.pitch > targetPitch) {
limb.pitch -= moveInfo.pitchD;
} else if (limb.pitch < targetPitch) {
limb.pitch += moveInfo.pitchD;
}
result = ONE_ANGLE_COULDNT_BE_SET_EXACTLY;
}
if (Abs(limb.theta - approxTheta) < moveInfo.pitchD)
limb.theta = approxTheta;
else
result = ONE_ANGLE_COULDNT_BE_SET_EXACTLY;
if (limb.theta > moveInfo.maxPitch || limb.theta < moveInfo.minPitch) {
limb.theta = clamp(limb.theta, moveInfo.minPitch, moveInfo.maxPitch);
if (limb.pitch > moveInfo.maxPitch || limb.pitch < moveInfo.minPitch) {
limb.pitch = clamp(limb.pitch, moveInfo.minPitch, moveInfo.maxPitch);
result = ANGLES_SET_TO_MAX;
}
return result;
@ -226,259 +113,189 @@ CPedIK::RestoreGunPosn(void)
return limbStatus == ANGLES_SET_EXACTLY;
}
#ifdef PED_SKIN
void
CPedIK::RotateHead(void)
{
RtQuat *q = &m_ped->m_pFrames[PED_HEAD]->hanimFrame->q;
RtQuatRotate(q, &XaxisIK, RADTODEG(m_headOrient.phi), rwCOMBINEREPLACE);
RtQuatRotate(q, &ZaxisIK, RADTODEG(m_headOrient.theta), rwCOMBINEPOSTCONCAT);
m_ped->bDontAcceptIKLookAts = true;
}
#endif
bool
CPedIK::LookInDirection(float phi, float theta)
CPedIK::LookInDirection(float targetYaw, float targetPitch)
{
bool success = true;
float yaw, pitch;
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
if (!(m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION)) {
m_ped->m_pFrames[PED_HEAD]->flag |= AnimBlendFrameData::IGNORE_ROTATION;
ExtractYawAndPitchLocalSkinned(m_ped->m_pFrames[PED_HEAD], &m_headOrient.phi, &m_headOrient.theta);
}
// parent of head is torso
RwMatrix worldMat = *GetComponentMatrix(m_ped, PED_NECK);
ExtractYawAndPitchWorld(&worldMat, &yaw, &pitch);
LimbMoveStatus headStatus = MoveLimb(m_headOrient, CGeneral::LimitRadianAngle(phi - yaw),
CGeneral::LimitRadianAngle(DEGTORAD(10.0f)), ms_headInfo);
if (headStatus == ANGLES_SET_TO_MAX)
success = false;
if (headStatus != ANGLES_SET_EXACTLY){
if (!(m_flags & LOOKAROUND_HEAD_ONLY)){
if (MoveLimb(m_torsoOrient, CGeneral::LimitRadianAngle(phi), theta, ms_torsoInfo))
success = true;
}else{
RotateHead();
return success;
}
}
if (!(m_flags & LOOKAROUND_HEAD_ONLY))
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false);
RotateHead();
}else
#endif
{
RwFrame *frame = m_ped->m_pFrames[PED_HEAD]->frame;
RwMatrix *frameMat = RwFrameGetMatrix(frame);
if (!(m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION)) {
m_ped->m_pFrames[PED_HEAD]->flag |= AnimBlendFrameData::IGNORE_ROTATION;
ExtractYawAndPitchLocal(frameMat, &m_headOrient.phi, &m_headOrient.theta);
}
RwMatrix *worldMat = RwMatrixCreate();
worldMat = GetWorldMatrix(RwFrameGetParent(frame), worldMat);
ExtractYawAndPitchWorld(worldMat, &yaw, &pitch);
RwMatrixDestroy(worldMat);
yaw += m_torsoOrient.phi;
float neededPhiTurn = CGeneral::LimitRadianAngle(phi - yaw);
pitch *= Cos(neededPhiTurn);
float neededThetaTurn = CGeneral::LimitRadianAngle(theta - pitch);
LimbMoveStatus headStatus = MoveLimb(m_headOrient, neededPhiTurn, neededThetaTurn, ms_headInfo);
if (headStatus == ANGLES_SET_TO_MAX)
success = false;
if (headStatus != ANGLES_SET_EXACTLY && !(m_flags & LOOKAROUND_HEAD_ONLY)) {
float remainingTurn = CGeneral::LimitRadianAngle(phi - m_ped->m_fRotationCur);
if (MoveLimb(m_torsoOrient, remainingTurn, theta, ms_torsoInfo))
success = true;
}
CMatrix nextFrame = CMatrix(frameMat);
CVector framePos = nextFrame.GetPosition();
nextFrame.SetRotateZ(m_headOrient.theta);
nextFrame.RotateX(m_headOrient.phi);
nextFrame.GetPosition() += framePos;
nextFrame.UpdateRW();
if (!(m_flags & LOOKAROUND_HEAD_ONLY))
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false);
if (!(m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION)) {
m_ped->m_pFrames[PED_HEAD]->flag |= AnimBlendFrameData::IGNORE_ROTATION;
RwMatrix *m = GetComponentMatrix(m_ped, PED_NECK);
m_headOrient.yaw = Atan2(-m->at.y, -m->at.x);
m_headOrient.yaw -= m_ped->m_fRotationCur;
m_headOrient.yaw = CGeneral::LimitRadianAngle(m_headOrient.yaw);
float up = clamp(m->up.z, -1.0f, 1.0f);
m_headOrient.pitch = Atan2(-up, Sqrt(1.0f - SQR(-up)));
}
// parent of head is neck
RwMatrix *m = GetComponentMatrix(m_ped, PED_NECK);
yaw = CGeneral::LimitRadianAngle(Atan2(-m->at.y, -m->at.x));
float up = clamp(m->up.z, -1.0f, 1.0f);
pitch = Atan2(-up, Sqrt(1.0f - SQR(-up)));
float headYaw = CGeneral::LimitRadianAngle(targetYaw - (yaw + m_torsoOrient.yaw));
float headPitch = CGeneral::LimitRadianAngle(targetPitch - pitch) * Cos(Min(Abs(headYaw), HALFPI));
LimbMoveStatus headStatus = MoveLimb(m_headOrient, headYaw, headPitch, ms_headInfo);
if (headStatus == ANGLES_SET_TO_MAX)
success = false;
if (headStatus != ANGLES_SET_EXACTLY && !(m_flags & LOOKAROUND_HEAD_ONLY))
if (MoveLimb(m_torsoOrient, CGeneral::LimitRadianAngle(targetYaw-m_ped->m_fRotationCur), targetPitch, ms_torsoInfo))
success = true;
// This was RotateHead
RtQuat *q = &m_ped->m_pFrames[PED_HEAD]->hanimFrame->q;
RtQuatRotate(q, &ZaxisIK, RADTODEG(m_headOrient.pitch), rwCOMBINEREPLACE);
RtQuatRotate(q, &XaxisIK, RADTODEG(m_headOrient.yaw), rwCOMBINEPRECONCAT);
m_ped->bDontAcceptIKLookAts = true;
if (!(m_flags & LOOKAROUND_HEAD_ONLY))
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false);
return success;
}
bool
CPedIK::LookAtPosition(CVector const &pos)
{
float phiToFace = CGeneral::GetRadianAngleBetweenPoints(
RwV3d *pedpos = &GetComponentMatrix(m_ped, PED_MID)->pos;
float yawToFace = CGeneral::GetRadianAngleBetweenPoints(
pos.x, pos.y,
m_ped->GetPosition().x, m_ped->GetPosition().y);
pedpos->x, pedpos->y);
float thetaToFace = CGeneral::GetRadianAngleBetweenPoints(
float pitchToFace = CGeneral::GetRadianAngleBetweenPoints(
// BUG? not using pedpos here
pos.z, (m_ped->GetPosition() - pos).Magnitude2D(),
m_ped->GetPosition().z, 0.0f);
pedpos->z, 0.0f);
return LookInDirection(phiToFace, thetaToFace);
return LookInDirection(yawToFace, pitchToFace);
}
bool
CPedIK::PointGunInDirection(float phi, float theta)
CPedIK::PointGunInDirection(float targetYaw, float targetPitch)
{
bool result = true;
bool armPointedToGun = false;
float angle = CGeneral::LimitRadianAngle(phi - m_ped->m_fRotationCur);
m_flags &= (~GUN_POINTED_SUCCESSFULLY);
targetYaw = CGeneral::LimitRadianAngle(targetYaw - m_ped->GetForward().Heading());
m_flags &= ~GUN_POINTED_SUCCESSFULLY;
m_flags |= LOOKAROUND_HEAD_ONLY;
if (m_flags & AIMS_WITH_ARM) {
armPointedToGun = PointGunInDirectionUsingArm(angle, theta);
angle = CGeneral::LimitRadianAngle(angle - m_upperArmOrient.phi);
armPointedToGun = PointGunInDirectionUsingArm(targetYaw, targetPitch);
targetYaw = CGeneral::LimitRadianAngle(targetYaw - (m_upperArmOrient.yaw + m_lowerArmOrient.yaw));
}
if (armPointedToGun) {
if (m_flags & AIMS_WITH_ARM && m_torsoOrient.phi * m_upperArmOrient.phi < 0.0f)
MoveLimb(m_torsoOrient, 0.0f, m_torsoOrient.theta, ms_torsoInfo);
if (m_flags & AIMS_WITH_ARM && m_torsoOrient.yaw * m_upperArmOrient.yaw < 0.0f)
MoveLimb(m_torsoOrient, 0.0f, m_torsoOrient.pitch, ms_torsoInfo);
} else {
// Unused code
RwMatrix *matrix;
float yaw, pitch;
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
matrix = RwMatrixCreate();
*matrix = *GetComponentMatrix(m_ped, PED_UPPERARMR);
ExtractYawAndPitchWorld(matrix, &yaw, &pitch);
RwMatrixDestroy(matrix);
}else
#endif
{
matrix = GetWorldMatrix(RwFrameGetParent(m_ped->m_pFrames[PED_UPPERARMR]->frame), RwMatrixCreate());
ExtractYawAndPitchWorld(matrix, &yaw, &pitch);
RwMatrixDestroy(matrix);
}
//
matrix = RwMatrixCreate();
*matrix = *GetComponentMatrix(m_ped, PED_CLAVICLER);
ExtractYawAndPitchWorld(matrix, &yaw, &pitch);
RwMatrixDestroy(matrix);
LimbMoveStatus status = MoveLimb(m_torsoOrient, angle, theta, ms_torsoInfo);
if(m_flags & AIMS_WITH_ARM){
if(targetPitch > 0.0f)
targetPitch = Max(targetPitch - Abs(targetYaw), 0.0f);
else
targetPitch = Min(targetPitch + Abs(targetYaw), 0.0f);
}
LimbMoveStatus status = MoveLimb(m_torsoOrient, targetYaw, targetPitch, ms_torsoInfo);
if (status == ANGLES_SET_TO_MAX)
result = false;
else if (status == ANGLES_SET_EXACTLY)
m_flags |= GUN_POINTED_SUCCESSFULLY;
}
if (TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam() && m_flags & AIMS_WITH_ARM)
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, true);
else
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false);
RwMatrix *m = GetBoneMatrix(m_ped, BONE_spine); // BUG: game uses index 2 directly, which happens to be identical to BONE_spine
RwV3d axis = { 0.0f, 0.0f, 0.0f };
float axisangle = -CGeneral::LimitRadianAngle(Atan2(-m->at.y, -m->at.x) - m_ped->m_fRotationCur);
axis.y = -Sin(axisangle);
axis.z = Cos(axisangle);
// this was RotateTorso
RtQuat *q = &m_ped->m_pFrames[PED_MID]->hanimFrame->q;
RtQuatRotate(q, &axis, RADTODEG(m_torsoOrient.pitch), rwCOMBINEPOSTCONCAT);
RtQuatRotate(q, &XaxisIK, RADTODEG(m_torsoOrient.yaw), rwCOMBINEPOSTCONCAT);
m_ped->bDontAcceptIKLookAts = true;
return result;
}
bool
CPedIK::PointGunInDirectionUsingArm(float phi, float theta)
CPedIK::PointGunInDirectionUsingArm(float targetYaw, float targetPitch)
{
bool result = false;
RwV3d upVector; // only for non-skinned
RwMatrix *matrix;
float yaw, pitch;
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
matrix = RwMatrixCreate();
*matrix = *GetComponentMatrix(m_ped, PED_UPPERARMR);
ExtractYawAndPitchWorld(matrix, &yaw, &pitch);
RwMatrixDestroy(matrix);
}else
#endif
{
RwFrame *frame = m_ped->m_pFrames[PED_UPPERARMR]->frame;
matrix = GetWorldMatrix(RwFrameGetParent(frame), RwMatrixCreate());
// with PED_SKIN this is actually done below (with a memory leak)
upVector.x = matrix->right.z;
upVector.y = matrix->up.z;
upVector.z = matrix->at.z;
float uaRoll = 45.0f;
float handRoll = 30.0f;
ExtractYawAndPitchWorld(matrix, &yaw, &pitch);
RwMatrixDestroy(matrix);
}
matrix = GetComponentMatrix(m_ped, PED_CLAVICLER);
yaw = CGeneral::LimitRadianAngle(Atan2(matrix->right.y, matrix->right.x) - m_ped->m_fRotationCur);
pitch = Atan2(matrix->up.z, Sqrt(1.0f - SQR(matrix->up.z)));
RwV3d rightVector = { 0.0f, 0.0f, 1.0f };
RwV3d forwardVector = { 1.0f, 0.0f, 0.0f };
float uaPhi, uaTheta;
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
uaPhi = phi;
uaTheta = theta + DEGTORAD(10.0f);
}else
#endif
{
uaPhi = phi - m_torsoOrient.phi - DEGTORAD(15.0f);
uaTheta = CGeneral::LimitRadianAngle(theta - pitch);
}
LimbMoveStatus uaStatus = MoveLimb(m_upperArmOrient, uaPhi, uaTheta, ms_upperArmInfo);
float uaYaw, uaPitch;
uaYaw = CGeneral::LimitRadianAngle(targetYaw - yaw - DEGTORAD(15.0f));
uaPitch = CGeneral::LimitRadianAngle(targetPitch - pitch + DEGTORAD(10.0f));
LimbMoveStatus uaStatus = MoveLimb(m_upperArmOrient, uaYaw, uaPitch, ms_upperArmInfo);
if (uaStatus == ANGLES_SET_EXACTLY) {
m_flags |= GUN_POINTED_SUCCESSFULLY;
result = true;
}
#ifdef PED_SKIN
// this code is completely missing on xbox & android, but we can keep it with the check
// TODO? implement it for skinned geometry?
if(!IsClumpSkinned(m_ped->GetClump()))
#endif
if (uaStatus == ANGLES_SET_TO_MAX) {
float laPhi = uaPhi - m_upperArmOrient.phi;
float laYaw = uaYaw - m_upperArmOrient.yaw;
LimbMoveStatus laStatus;
if (laPhi > 0.0f)
laStatus = MoveLimb(m_lowerArmOrient, laPhi, -DEGTORAD(45.0f), ms_lowerArmInfo);
else
laStatus = MoveLimb(m_lowerArmOrient, laPhi, 0.0f, ms_lowerArmInfo);
if (laYaw > 0.0f){
float rollReduce = laYaw/DEGTORAD(30.0f);
uaRoll *= 1.0f - Min(rollReduce, 1.0f);
handRoll *= 1.0f - Min(rollReduce, 1.0f);
laYaw *= 1.9f;
laStatus = MoveLimb(m_lowerArmOrient, laYaw, 0.0f, ms_lowerArmInfo);
// some unused statics here
float uaPitchAmount = 1.0f - (m_lowerArmOrient.yaw + m_upperArmOrient.yaw) * 0.34f;
float f1 = ms_upperArmInfo.maxPitch * Max(uaPitchAmount, 0.0f);
float f2 = 0.2f*m_lowerArmOrient.yaw + m_upperArmOrient.pitch;
m_upperArmOrient.pitch = Min(f1, f2);
}else
laStatus = MoveLimb(m_lowerArmOrient, laYaw, 0.0f, ms_lowerArmInfo);
if (laStatus == ANGLES_SET_EXACTLY) {
m_flags |= GUN_POINTED_SUCCESSFULLY;
result = true;
}
RwFrame *child = GetFirstChild(m_ped->m_pFrames[PED_UPPERARMR]->frame);
RwV3d pos = RwFrameGetMatrix(child)->pos;
RwMatrixRotate(RwFrameGetMatrix(child), &forwardVector, RADTODEG(m_lowerArmOrient.theta), rwCOMBINEPOSTCONCAT);
RwMatrixRotate(RwFrameGetMatrix(child), &rightVector, RADTODEG(-m_lowerArmOrient.phi), rwCOMBINEPOSTCONCAT);
RwFrameGetMatrix(child)->pos = pos;
// game does this stupidly by going through the clump extension...
RtQuat *q = &m_ped->m_pFrames[PED_FOREARMR]->hanimFrame->q;
RtQuatRotate(q, &ZaxisIK, -RADTODEG(m_lowerArmOrient.yaw), rwCOMBINEREPLACE);
RtQuatRotate(q, &XaxisIK, -RADTODEG(m_lowerArmOrient.pitch), rwCOMBINEPOSTCONCAT);
m_ped->bDontAcceptIKLookAts = true;
}
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
RtQuat *q = &m_ped->m_pFrames[PED_UPPERARMR]->hanimFrame->q;
RtQuatRotate(q, &XaxisIK, RADTODEG(m_upperArmOrient.phi), rwCOMBINEPOSTCONCAT);
RtQuatRotate(q, &ZaxisIK, RADTODEG(m_upperArmOrient.theta), rwCOMBINEPOSTCONCAT);
m_ped->bDontAcceptIKLookAts = true;
}else
#endif
{
RwFrame *frame = m_ped->m_pFrames[PED_UPPERARMR]->frame;
// with PED_SKIN we're also getting upVector here
RwV3d pos = RwFrameGetMatrix(frame)->pos;
RwMatrixRotate(RwFrameGetMatrix(frame), &rightVector, RADTODEG(m_upperArmOrient.theta), rwCOMBINEPOSTCONCAT);
RwMatrixRotate(RwFrameGetMatrix(frame), &upVector, RADTODEG(m_upperArmOrient.phi), rwCOMBINEPOSTCONCAT);
RwFrameGetMatrix(frame)->pos = pos;
}
RtQuat *q = &m_ped->m_pFrames[PED_UPPERARMR]->hanimFrame->q;
RtQuatRotate(q, &XaxisIK, uaRoll, rwCOMBINEREPLACE);
RtQuatRotate(q, &YaxisIK, -RADTODEG(m_upperArmOrient.pitch), rwCOMBINEPOSTCONCAT);
RtQuatRotate(q, &ZaxisIK, -RADTODEG(m_upperArmOrient.yaw+HALFPI), rwCOMBINEPOSTCONCAT);
m_ped->bDontAcceptIKLookAts = true;
q = &m_ped->m_pFrames[PED_HANDR]->hanimFrame->q;
RtQuatRotate(q, &XaxisIK, handRoll, rwCOMBINEPRECONCAT);
return result;
}
bool
CPedIK::PointGunAtPosition(CVector const& position)
{
// TODO(MIAMI): special cases for some weapons
return PointGunInDirection(
CGeneral::GetRadianAngleBetweenPoints(position.x, position.y, m_ped->GetPosition().x, m_ped->GetPosition().y),
CGeneral::GetRadianAngleBetweenPoints(position.z, Distance2D(m_ped->GetPosition(), position.x, position.y),
m_ped->GetPosition().z,
0.0f));
CGeneral::GetRadianAngleBetweenPoints(position.z, Distance2D(m_ped->GetPosition(), position.x, position.y), m_ped->GetPosition().z, 0.0f));
}
bool
@ -487,40 +304,24 @@ CPedIK::RestoreLookAt(void)
bool result = false;
float yaw, pitch;
#ifdef PED_SKIN
if(IsClumpSkinned(m_ped->GetClump())){
if (m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION) {
m_ped->m_pFrames[PED_HEAD]->flag &= (~AnimBlendFrameData::IGNORE_ROTATION);
} else {
ExtractYawAndPitchLocalSkinned(m_ped->m_pFrames[PED_HEAD], &yaw, &pitch);
if (MoveLimb(m_headOrient, yaw, pitch, ms_headRestoreInfo) == ANGLES_SET_EXACTLY)
result = true;
}
RotateHead();
}else
#endif
{
RwMatrix *mat = RwFrameGetMatrix(m_ped->m_pFrames[PED_HEAD]->frame);
if (m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION) {
m_ped->m_pFrames[PED_HEAD]->flag &= (~AnimBlendFrameData::IGNORE_ROTATION);
} else {
ExtractYawAndPitchLocal(mat, &yaw, &pitch);
if (MoveLimb(m_headOrient, yaw, pitch, ms_headRestoreInfo) == ANGLES_SET_EXACTLY)
result = true;
}
if (m_ped->m_pFrames[PED_HEAD]->flag & AnimBlendFrameData::IGNORE_ROTATION) {
m_ped->m_pFrames[PED_HEAD]->flag &= (~AnimBlendFrameData::IGNORE_ROTATION);
} else {
ExtractYawAndPitchLocalSkinned(m_ped->m_pFrames[PED_HEAD], &yaw, &pitch);
if (MoveLimb(m_headOrient, yaw, pitch, ms_headRestoreInfo) == ANGLES_SET_EXACTLY)
result = true;
}
CMatrix matrix(mat);
CVector pos = matrix.GetPosition();
matrix.SetRotateZ(m_headOrient.theta);
matrix.RotateX(m_headOrient.phi);
matrix.Translate(pos);
matrix.UpdateRW();
}
if (!(m_flags & LOOKAROUND_HEAD_ONLY)){
// This was RotateHead
RtQuat *q = &m_ped->m_pFrames[PED_HEAD]->hanimFrame->q;
RtQuatRotate(q, &XaxisIK, RADTODEG(m_headOrient.yaw), rwCOMBINEREPLACE);
RtQuatRotate(q, &ZaxisIK, RADTODEG(m_headOrient.pitch), rwCOMBINEPRECONCAT);
m_ped->bDontAcceptIKLookAts = true;
if (!(m_flags & LOOKAROUND_HEAD_ONLY))
MoveLimb(m_torsoOrient, 0.0f, 0.0f, ms_torsoInfo);
if (!(m_flags & LOOKAROUND_HEAD_ONLY))
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false);
}
if (!(m_flags & LOOKAROUND_HEAD_ONLY))
RotateTorso(m_ped->m_pFrames[PED_MID], &m_torsoOrient, false);
return result;
}
@ -548,7 +349,6 @@ CPedIK::ExtractYawAndPitchLocal(RwMatrix *mat, float *yaw, float *pitch)
if (mat->up.x > 0.0f) *pitch = -*pitch;
}
#ifdef PED_SKIN
void
CPedIK::ExtractYawAndPitchLocalSkinned(AnimBlendFrameData *node, float *yaw, float *pitch)
{
@ -557,4 +357,3 @@ CPedIK::ExtractYawAndPitchLocalSkinned(AnimBlendFrameData *node, float *yaw, flo
ExtractYawAndPitchLocal(mat, yaw, pitch);
RwMatrixDestroy(mat);
}
#endif

View File

@ -4,8 +4,8 @@
struct LimbOrientation
{
float phi;
float theta;
float yaw;
float pitch;
};
struct LimbMovementInfo {
@ -48,19 +48,17 @@ public:
static LimbMovementInfo ms_lowerArmInfo;
CPedIK(CPed *ped);
bool PointGunInDirection(float phi, float theta);
bool PointGunInDirectionUsingArm(float phi, float theta);
bool PointGunInDirection(float targetYaw, float targetPitch);
bool PointGunInDirectionUsingArm(float targetYaw, float targetPitch);
bool PointGunAtPosition(CVector const& position);
void GetComponentPosition(RwV3d *pos, uint32 node);
static RwMatrix *GetWorldMatrix(RwFrame *source, RwMatrix *destination);
void RotateTorso(AnimBlendFrameData* animBlend, LimbOrientation* limb, bool changeRoll);
void ExtractYawAndPitchLocal(RwMatrix *mat, float *yaw, float *pitch);
void ExtractYawAndPitchLocalSkinned(AnimBlendFrameData *node, float *yaw, float *pitch);
void ExtractYawAndPitchWorld(RwMatrix *mat, float *yaw, float *pitch);
LimbMoveStatus MoveLimb(LimbOrientation &limb, float approxPhi, float approxTheta, LimbMovementInfo &moveInfo);
LimbMoveStatus MoveLimb(LimbOrientation &limb, float targetYaw, float targetPitch, LimbMovementInfo &moveInfo);
bool RestoreGunPosn(void);
void RotateHead(void);
bool LookInDirection(float phi, float theta);
bool LookInDirection(float targetYaw, float targetPitch);
bool LookAtPosition(CVector const& pos);
bool RestoreLookAt(void);
};

View File

@ -16,6 +16,7 @@
#include "Pools.h"
#include "Darkel.h"
#include "CarCtrl.h"
#include "MBlur.h"
#define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f
@ -31,6 +32,7 @@ CPlayerPed::~CPlayerPed()
delete m_pWanted;
}
// --MIAMI: Done except commented out things
CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1)
{
m_fMoveSpeed = 0.0f;
@ -44,26 +46,47 @@ CPlayerPed::CPlayerPed(void) : CPed(PEDTYPE_PLAYER1)
m_nSelectedWepSlot = WEAPONTYPE_UNARMED;
m_nSpeedTimer = 0;
m_bSpeedTimerFlag = false;
// This should be something inlined
// TODO(Miami)
// if (pPointGunAt)
// m_pPointGunAt->CleanUpOldReference(&m_pPointGunAt);
m_pPointGunAt = nil;
if (m_nPedState == PED_FOLLOW_PATH)
ClearFollowPath();
// TODO(Miami)
// This should be something inlined
m_nPedState = PED_IDLE;
m_fMaxStamina = 150.0f;
m_fCurrentStamina = m_fMaxStamina;
m_fStaminaProgress = 0.0f;
m_nEvadeAmount = 0;
field_1367 = 0;
m_pEvadingFrom = nil;
m_nHitAnimDelayTimer = 0;
m_fAttackButtonCounter = 0.0f;
m_bHaveTargetSelected = false;
m_bHasLockOnTarget = false;
m_bDrunkVisualsWearOff = true;
m_bCanBeDamaged = true;
m_fWalkAngle = 0.0f;
m_fFPSMoveHeading = 0.0f;
m_pMinigunTopAtomic = nil;
m_fGunSpinSpeed = 0.0;
m_fGunSpinAngle = 0.0;
m_nTargettableObjects[0] = m_nTargettableObjects[1] = m_nTargettableObjects[2] = m_nTargettableObjects[3] = -1;
field_1413 = 0;
unused1 = false;
for (int i = 0; i < 6; i++) {
m_vecSafePos[i] = CVector(0.0f, 0.0f, 0.0f);
m_pPedAtSafePos[i] = nil;
m_pCheckPlayers[i] = nil;
}
m_nCheckPlayersIndex = 0;
m_nPadUpPressedInMilliseconds = 0;
m_nPadDownPressedInMilliseconds = 0;
// TODO(Miami): Idle anim block index
}
void CPlayerPed::ClearWeaponTarget()
@ -181,8 +204,9 @@ CPlayerPed::UseSprintEnergy(void)
}
}
// --MIAMI: Use that on everywhere except ProcessPlayerWeapon
void
CPlayerPed::MakeChangesForNewWeapon(int8 weapon)
CPlayerPed::MakeChangesForNewWeapon(eWeaponType weapon)
{
if (m_nPedState == PED_SNIPER_MODE) {
RestorePreviousState();
@ -195,7 +219,7 @@ CPlayerPed::MakeChangesForNewWeapon(int8 weapon)
if (!(CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_bCanAim))
ClearWeaponTarget();
CAnimBlendAssociation *weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE)->m_AnimToPlay);
CAnimBlendAssociation* weaponAnim = RpAnimBlendClumpGetAssociation(GetClump(), CWeaponInfo::GetWeaponInfo(WEAPONTYPE_SNIPERRIFLE)->m_bAnimDetonate ? 62 : 205);
if (weaponAnim) {
weaponAnim->SetRun();
weaponAnim->flags |= ASSOC_FADEOUTWHENDONE;
@ -203,6 +227,14 @@ CPlayerPed::MakeChangesForNewWeapon(int8 weapon)
TheCamera.ClearPlayerWeaponMode();
}
// --MIAMI: Done, but this should be only called from ProcessPlayerWeapon
void
CPlayerPed::MakeChangesForNewWeapon(int32 slot)
{
if(slot != -1)
MakeChangesForNewWeapon(m_weapons[slot].m_eWeaponType);
}
void
CPlayerPed::ReApplyMoveAnims(void)
{
@ -222,14 +254,19 @@ CPlayerPed::ReApplyMoveAnims(void)
}
}
// --MIAMI: Done
void
CPlayerPed::SetInitialState(void)
{
m_nDrunkenness = 0;
m_nFadeDrunkenness = 0;
CMBlur::ClearDrunkBlur();
m_nDrunkCountdown = 0;
m_bAdrenalineActive = false;
m_nAdrenalineTime = 0;
CTimer::SetTimeStep(1.0f);
CTimer::SetTimeScale(1.0f);
m_pSeekTarget = nil;
m_vecSeekPos = { 0.0f, 0.0f, 0.0f };
m_vecSeekPos = CVector(0.0f, 0.0f, 0.0f);
m_fleeFromPosX = 0.0f;
m_fleeFromPosY = 0.0f;
m_fleeFrom = nil;
@ -241,9 +278,14 @@ CPlayerPed::SetInitialState(void)
ClearLookFlag();
bIsPointingGunAt = false;
bRenderPedInCar = true;
if (m_pFire)
m_pFire->Extinguish();
RpAnimBlendClumpRemoveAllAssociations(GetClump());
if (m_nPedState == PED_FOLLOW_PATH)
ClearFollowPath();
m_nPedState = PED_IDLE;
SetMoveState(PEDMOVE_STILL);
m_nLastPedState = PED_NONE;
@ -257,6 +299,11 @@ CPlayerPed::SetInitialState(void)
m_bCanBeDamaged = true;
m_pedStats->m_temper = 50;
m_fWalkAngle = 0.0f;
if (m_attachedTo && !bUsesCollision)
bUsesCollision = true;
m_attachedTo = nil;
m_attachWepAmmo = 0;
}
void
@ -497,8 +544,9 @@ CPlayerPed::DoWeaponSmoothSpray(void)
{
if (m_nPedState == PED_ATTACK && !m_pPointGunAt) {
eWeaponType weapon = GetWeapon()->m_eWeaponType;
if (weapon == WEAPONTYPE_FLAMETHROWER || weapon == WEAPONTYPE_COLT45 || weapon == WEAPONTYPE_UZI || weapon == WEAPONTYPE_SHOTGUN ||
weapon == WEAPONTYPE_AK47 || weapon == WEAPONTYPE_M16 || weapon == WEAPONTYPE_HELICANNON)
if (weapon == WEAPONTYPE_FLAMETHROWER || weapon == WEAPONTYPE_COLT45 || weapon == WEAPONTYPE_UZI ||
weapon == WEAPONTYPE_TEC9 || weapon == WEAPONTYPE_SILENCED_INGRAM || weapon == WEAPONTYPE_MP5 ||
weapon == WEAPONTYPE_SHOTGUN || weapon == WEAPONTYPE_AK47 || weapon == WEAPONTYPE_M16 || weapon == WEAPONTYPE_HELICANNON)
return true;
}
return false;
@ -586,56 +634,71 @@ CPlayerPed::PlayerControlSniper(CPad *padUsed)
GetWeapon()->Update(m_audioEntityId);
}
// --MIAMI: Made compatible with slots, but still TODO
// I think R* also used goto in here.
void
CPlayerPed::ProcessWeaponSwitch(CPad *padUsed)
{
if (CDarkel::FrenzyOnGoing())
if (CDarkel::FrenzyOnGoing() || m_attachedTo)
goto switchDetectDone;
if (padUsed->CycleWeaponRightJustDown() && !m_pPointGunAt) {
if (!m_pPointGunAt && /* !byte_A10B57 && */ GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR) {
if (padUsed->CycleWeaponRightJustDown()) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER_RUNABOUT) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER_RUNABOUT
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER_RUNABOUT) {
for (m_nSelectedWepSlot = m_currentWeapon + 1; m_nSelectedWepSlot < WEAPONTYPE_TOTAL_INVENTORY_WEAPONS; ++m_nSelectedWepSlot) {
if (HasWeapon(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
goto switchDetectDone;
for (m_nSelectedWepSlot = m_currentWeapon + 1; m_nSelectedWepSlot < TOTAL_WEAPON_SLOTS; ++m_nSelectedWepSlot) {
if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
goto spentAmmoCheck;
}
}
m_nSelectedWepSlot = 0;
}
m_nSelectedWepSlot = WEAPONTYPE_UNARMED;
}
} else if (padUsed->CycleWeaponLeftJustDown() && !m_pPointGunAt) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER) {
for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot < WEAPONTYPE_UNARMED)
m_nSelectedWepSlot = WEAPONTYPE_DETONATOR;
if (HasWeapon(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
goto switchDetectDone;
}
}
}
} else if (CWeaponInfo::GetWeaponInfo((eWeaponType)m_currentWeapon)->m_eWeaponFire != WEAPON_FIRE_MELEE) {
if (GetWeapon(m_currentWeapon).m_nAmmoTotal <= 0) {
} else if (padUsed->CycleWeaponLeftJustDown()) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER) {
for (m_nSelectedWepSlot = m_currentWeapon - 1; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && HasWeapon(WEAPONTYPE_BASEBALLBAT)
|| GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0 && m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE) {
for (m_nSelectedWepSlot = m_currentWeapon - 1; ; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot < 0)
m_nSelectedWepSlot = 9;
if (HasWeaponSlot(m_nSelectedWepSlot) && GetWeapon(m_nSelectedWepSlot).HasWeaponAmmoToBeUsed()) {
break;
}
}
}
}
}
spentAmmoCheck:
if (CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_eWeaponFire != WEAPON_FIRE_MELEE
/*&& (!padUsed->GetWeapon() || GetWeapon()->m_eWeaponType != WEAPONTYPE_MINIGUN) */) {
if (GetWeapon()->m_nAmmoTotal <= 0) {
if (TheCamera.PlayerWeaponMode.Mode != CCam::MODE_M16_1STPERSON
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_SNIPER
&& TheCamera.PlayerWeaponMode.Mode != CCam::MODE_ROCKETLAUNCHER) {
if (GetWeapon()->m_eWeaponType != WEAPONTYPE_DETONATOR
|| GetWeapon(2).m_eWeaponType != WEAPONTYPE_DETONATOR_GRENADE)
m_nSelectedWepSlot = m_currentWeapon - 1;
else
m_nSelectedWepSlot = 2;
// BUG: m_nSelectedWepSlot is slot in VC but they compared against weapon types, lol.
for (; m_nSelectedWepSlot >= 0; --m_nSelectedWepSlot) {
if (m_nSelectedWepSlot == WEAPONTYPE_BASEBALLBAT && GetWeapon(6).m_eWeaponType == WEAPONTYPE_BASEBALLBAT
|| GetWeapon(m_nSelectedWepSlot).m_nAmmoTotal > 0
/*&& m_nSelectedWepSlot != WEAPONTYPE_MOLOTOV && m_nSelectedWepSlot != WEAPONTYPE_GRENADE && m_nSelectedWepSlot != WEAPONTYPE_TEARGAS */) {
goto switchDetectDone;
}
}
m_nSelectedWepSlot = WEAPONTYPE_UNARMED;
m_nSelectedWepSlot = 0;
}
}
}
@ -643,6 +706,7 @@ CPlayerPed::ProcessWeaponSwitch(CPad *padUsed)
switchDetectDone:
if (m_nSelectedWepSlot != m_currentWeapon) {
if (m_nPedState != PED_ATTACK && m_nPedState != PED_AIM_GUN && m_nPedState != PED_FIGHT)
RemoveWeaponAnims(m_currentWeapon, -1000.0f);
MakeChangesForNewWeapon(m_nSelectedWepSlot);
}
}
@ -934,6 +998,7 @@ CPlayerPed::FindWeaponLockOnTarget(void)
return true;
}
// --MIAMI: Done, but uncomment new weapon types when weapons got ported
void
CPlayerPed::ProcessAnimGroups(void)
{
@ -946,17 +1011,29 @@ CPlayerPed::ProcessAnimGroups(void)
if (m_fWalkAngle > 0.0f) {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER)
groupToSet = ASSOCGRP_ROCKETLEFT;
else if (/*GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || */
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER
/* || GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN*/ )
groupToSet = ASSOCGRP_CHAINSAWLEFT;
else
groupToSet = ASSOCGRP_PLAYERLEFT;
} else {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER)
groupToSet = ASSOCGRP_ROCKETRIGHT;
else if (/*GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || */
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER
/* || GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN*/)
groupToSet = ASSOCGRP_CHAINSAWRIGHT;
else
groupToSet = ASSOCGRP_PLAYERRIGHT;
}
} else {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER)
groupToSet = ASSOCGRP_ROCKETBACK;
else if (/*GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || */
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER
/* || GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN*/)
groupToSet = ASSOCGRP_CHAINSAWBACK;
else
groupToSet = ASSOCGRP_PLAYERBACK;
}
@ -964,9 +1041,21 @@ CPlayerPed::ProcessAnimGroups(void)
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_ROCKETLAUNCHER) {
groupToSet = ASSOCGRP_PLAYERROCKET;
} else {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT) {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_BASEBALLBAT
/* || GetWeapon()->m_eWeaponType == WEAPONTYPE_MACHETE */)
groupToSet = ASSOCGRP_PLAYERBBBAT;
} else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_COLT45 && GetWeapon()->m_eWeaponType != WEAPONTYPE_UZI) {
else if (/*GetWeapon()->m_eWeaponType == WEAPONTYPE_CHAINSAW || */
GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER
/* || GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN*/)
groupToSet = ASSOCGRP_PLAYERCHAINSAW;
else if (GetWeapon()->m_eWeaponType != WEAPONTYPE_COLT45 && GetWeapon()->m_eWeaponType != WEAPONTYPE_UZI
// I hope this was inlined...
/*
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_PYTHON*/ && GetWeapon()->m_eWeaponType != WEAPONTYPE_TEC9
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_SILENCED_INGRAM && GetWeapon()->m_eWeaponType != WEAPONTYPE_MP5 /*
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_GOLFCLUB && GetWeapon()->m_eWeaponType != WEAPONTYPE_KATANA
&& GetWeapon()->m_eWeaponType != WEAPONTYPE_CAMERA
*/) {
if (!GetWeapon()->IsType2Handed()) {
groupToSet = ASSOCGRP_PLAYER;
} else {
@ -1185,7 +1274,7 @@ CPlayerPed::PlayerControlZelda(CPad *padUsed)
float neededTurn = CGeneral::LimitRadianAngle(padHeading - camOrientation);
if (doSmoothSpray) {
if (GetWeapon()->m_eWeaponType == WEAPONTYPE_FLAMETHROWER || GetWeapon()->m_eWeaponType == WEAPONTYPE_COLT45
|| GetWeapon()->m_eWeaponType == WEAPONTYPE_UZI)
|| CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nWeaponSlot == 5)
m_fRotationDest = m_fRotationCur - leftRight / 128.0f * (PI / 80.0f) * CTimer::GetTimeStep();
else
m_fRotationDest = m_fRotationCur - leftRight / 128.0f * (PI / 128.0f) * CTimer::GetTimeStep();

View File

@ -18,22 +18,32 @@ public:
int8 m_nSelectedWepSlot; // eWeaponType
bool m_bSpeedTimerFlag;
uint8 m_nEvadeAmount;
int8 field_1367;
uint32 m_nSpeedTimer;
uint32 m_nHitAnimDelayTimer;
uint32 m_nSpeedTimer; // m_nStandStillTimer?
uint32 m_nHitAnimDelayTimer; // m_nShotDelay?
float m_fAttackButtonCounter;
bool m_bHaveTargetSelected; // may have better name
CEntity *m_pEvadingFrom; // is this CPhysical?
int32 m_nTargettableObjects[4];
uint32 m_nAdrenalineTime;
uint8 m_nDrunkenness; // Needed to work out whether we lost target this frame
uint8 m_nFadeDrunkenness;
uint8 m_nDrunkCountdown; //countdown in frames when the drunk effect ends
bool m_bAdrenalineActive;
bool m_bHasLockOnTarget;
uint32 m_nAdrenalineTime;
bool m_bCanBeDamaged;
int8 field_1413;
bool m_bDrunkVisualsWearOff; // TODO(Miami): That may be something else
CVector m_vecSafePos[6]; // safe places from the player, for example behind a tree
CPed *m_pPedAtSafePos[6];
float m_fWalkAngle;
CPlayerPed* m_pCheckPlayers[6]; //checks something with players, could be a leftover from original multiplayer
char unused1;
int16 m_nCheckPlayersIndex;
float m_fWalkAngle; //angle between heading and walking direction
float m_fFPSMoveHeading;
RpAtomic* m_pMinigunTopAtomic; //atomic for the spinning part of the minigun model
float m_fGunSpinSpeed; // for minigun
float m_fGunSpinAngle;
unsigned int m_nPadDownPressedInMilliseconds;
unsigned int m_nPadUpPressedInMilliseconds;
CPlayerPed();
~CPlayerPed();
@ -45,7 +55,8 @@ public:
void SetWantedLevelNoDrop(int32 level);
void KeepAreaAroundPlayerClear(void);
void AnnoyPlayerPed(bool);
void MakeChangesForNewWeapon(int8);
void MakeChangesForNewWeapon(int32);
void MakeChangesForNewWeapon(eWeaponType);
void SetInitialState(void);
void ProcessControl(void);
void ClearAdrenaline(void);

View File

@ -471,9 +471,28 @@ CPopulation::AddPed(ePedType pedType, uint32 miOrCopType, CVector const &coors,
ped->SetOrientation(0.0f, 0.0f, 0.0f);
CWorld::Add(ped);
if (ms_bGivePedsWeapons) {
eWeaponType weapon = (eWeaponType)CGeneral::GetRandomNumberInRange(WEAPONTYPE_UNARMED, WEAPONTYPE_DETONATOR);
eWeaponType weapon;
// TODO(Miami): Look here when weapons have been ported
switch (CGeneral::GetRandomNumber() & 3) {
case 0:
weapon = WEAPONTYPE_COLT45;
break;
case 1:
//weapon = WEAPONTYPE_NIGHTSTICK;
//break;
case 2:
//weapon = WEAPONTYPE_GOLFCLUB;
//break;
case 3:
weapon = WEAPONTYPE_TEC9;
break;
default:
break;
}
if (weapon != WEAPONTYPE_UNARMED) {
ped->SetCurrentWeapon(ped->GiveWeapon(weapon, 25001));
ped->GiveDelayedWeapon(weapon, 25001);
ped->SetCurrentWeapon(CWeaponInfo::GetWeaponInfo(weapon)->m_nWeaponSlot);
}
}
return ped;
@ -501,12 +520,14 @@ CPopulation::AddPed(ePedType pedType, uint32 miOrCopType, CVector const &coors,
ped->SetOrientation(0.0f, 0.0f, 0.0f);
CWorld::Add(ped);
uint32 weapon;
eWeaponType weapon;
if (CGeneral::GetRandomNumberInRange(0, 100) >= 50)
weapon = ped->GiveWeapon((eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon2, 25001);
weapon = (eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon2;
else
weapon = ped->GiveWeapon((eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon1, 25001);
ped->SetCurrentWeapon(weapon);
weapon = (eWeaponType)CGangs::GetGangInfo(pedType - PEDTYPE_GANG1)->m_Weapon1;
ped->GiveDelayedWeapon(weapon, 25001);
ped->SetCurrentWeapon(CWeaponInfo::GetWeaponInfo(weapon)->m_nWeaponSlot);
return ped;
}
case PEDTYPE_EMERGENCY: