@@ -34,7 +34,7 @@ NPC::NPC(NPCComponent* component, IPlayer* playerPtr)
3434 , ammo_(0 )
3535 , ammoInClip_(0 )
3636 , infiniteAmmo_(false )
37- , hasReloading_(false )
37+ , hasReloading_(true )
3838 , reloading_(false )
3939 , shooting_(false )
4040 , shootDelay_(0 )
@@ -44,7 +44,7 @@ NPC::NPC(NPCComponent* component, IPlayer* playerPtr)
4444 , aimOffsetFrom_({ 0 .0f , 0 .0f , 0 .0f })
4545 , aimOffset_({ 0 .0f , 0 .0f , 0 .0f })
4646 , updateAimAngle_(false )
47- , betweenCheckFlags_(0 )
47+ , betweenCheckFlags_(EntityCheckType::None )
4848 , hitId_(0 )
4949 , hitType_(PlayerBulletHitType_None)
5050 , lastDamager_(nullptr )
@@ -374,6 +374,7 @@ void NPC::setWeapon(uint8_t weapon)
374374 {
375375 weapon_ = weapon;
376376 }
377+ updateWeaponState ();
377378}
378379
379380uint8_t NPC::getWeapon () const
@@ -389,6 +390,8 @@ void NPC::setAmmo(int ammo)
389390 {
390391 ammoInClip_ = ammo_;
391392 }
393+ updateWeaponState ();
394+ setAmmoInClip (ammo);
392395}
393396
394397int NPC::getAmmo () const
@@ -455,7 +458,7 @@ void NPC::setAmmoInClip(int ammo)
455458{
456459 auto clipSize = getWeaponActualClipSize (weapon_, ammo_, getWeaponSkillLevel (getWeaponSkillID (weapon_)), infiniteAmmo_);
457460
458- ammoInClip_ = ammo_ < clipSize ? ammo_ : clipSize;
461+ ammoInClip_ = ammo < clipSize ? ammo : clipSize;
459462}
460463
461464int NPC::getAmmoInClip () const
@@ -579,7 +582,7 @@ PlayerFightingStyle NPC::getFightingStyle() const
579582 return PlayerFightingStyle_Normal;
580583}
581584
582- void NPC::shoot (int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Vector3& endPoint, const Vector3& offset, bool isHit, uint8_t betweenCheckFlags)
585+ void NPC::shoot (int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Vector3& endPoint, const Vector3& offset, bool isHit, EntityCheckType betweenCheckFlags)
583586{
584587 auto weaponData = WeaponInfo::get (weapon);
585588 if (weaponData.type != PlayerWeaponType_Bullet)
@@ -611,7 +614,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
611614 }
612615
613616 // If something is in between the origin and the target (we currently don't handle checking beyond the target, even when missing with leftover range)
614- uint8_t closestEntityType = EntityCheckType_None ;
617+ EntityCheckType closestEntityType = EntityCheckType::None ;
615618 int playerObjectOwnerId = INVALID_PLAYER_ID;
616619 Vector3 hitMapPos = bulletData.hitPos ;
617620 float range = weaponData.range ;
@@ -626,7 +629,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
626629
627630 switch (EntityCheckType (closestEntityType))
628631 {
629- case EntityCheckType_Player :
632+ case EntityCheckType::Player :
630633 {
631634 if (closestEntity)
632635 {
@@ -640,7 +643,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
640643 }
641644 break ;
642645 }
643- case EntityCheckType_NPC :
646+ case EntityCheckType::NPC :
644647 {
645648 if (closestEntity)
646649 {
@@ -654,7 +657,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
654657 }
655658 break ;
656659 }
657- case EntityCheckType_Actor :
660+ case EntityCheckType::Actor :
658661 {
659662 bulletData.hitType = PlayerBulletHitType_None;
660663 bulletData.hitID = INVALID_PLAYER_ID;
@@ -664,7 +667,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
664667 });
665668 break ;
666669 }
667- case EntityCheckType_Vehicle :
670+ case EntityCheckType::Vehicle :
668671 {
669672 if (closestEntity)
670673 {
@@ -678,7 +681,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
678681 }
679682 break ;
680683 }
681- case EntityCheckType_Object :
684+ case EntityCheckType::Object :
682685 {
683686 if (closestEntity)
684687 {
@@ -692,8 +695,8 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
692695 }
693696 break ;
694697 }
695- case EntityCheckType_ProjectOrig :
696- case EntityCheckType_ProjectTarg :
698+ case EntityCheckType::ProjectOrig :
699+ case EntityCheckType::ProjectTarg :
697700 {
698701 if (closestEntity)
699702 {
@@ -707,7 +710,7 @@ void NPC::shoot(int hitId, PlayerBulletHitType hitType, uint8_t weapon, const Ve
707710 }
708711 break ;
709712 }
710- case EntityCheckType_Map :
713+ case EntityCheckType::Map :
711714 default :
712715 {
713716 bulletData.hitType = PlayerBulletHitType_None;
@@ -754,7 +757,7 @@ bool NPC::isShooting() const
754757 return aiming_ && shooting_;
755758}
756759
757- void NPC::aimAt (const Vector3& point, bool shoot, int shootDelay, bool setAngle, const Vector3& offsetFrom, uint8_t betweenCheckFlags)
760+ void NPC::aimAt (const Vector3& point, bool shoot, int shootDelay, bool setAngle, const Vector3& offsetFrom, EntityCheckType betweenCheckFlags)
758761{
759762 if (moving_ && moveType_ == NPCMoveType_Sprint)
760763 {
@@ -798,7 +801,7 @@ void NPC::aimAt(const Vector3& point, bool shoot, int shootDelay, bool setAngle,
798801 betweenCheckFlags_ = betweenCheckFlags;
799802}
800803
801- void NPC::aimAtPlayer (IPlayer& atPlayer, bool shoot, int shootDelay, bool setAngle, const Vector3& offset, const Vector3& offsetFrom, uint8_t betweenCheckFlags)
804+ void NPC::aimAtPlayer (IPlayer& atPlayer, bool shoot, int shootDelay, bool setAngle, const Vector3& offset, const Vector3& offsetFrom, EntityCheckType betweenCheckFlags)
802805{
803806 aimAt (atPlayer.getPosition () + offset, shoot, shootDelay, setAngle, offsetFrom, betweenCheckFlags);
804807 hitId_ = atPlayer.getID ();
@@ -826,7 +829,7 @@ void NPC::stopAim()
826829 hitId_ = INVALID_PLAYER_ID;
827830 hitType_ = PlayerBulletHitType_None;
828831 updateAimAngle_ = false ;
829- betweenCheckFlags_ = EntityCheckType_None ;
832+ betweenCheckFlags_ = EntityCheckType::None ;
830833
831834 // Reset keys
832835 removeKey (Key::AIM);
@@ -1150,6 +1153,60 @@ void NPC::processDamage(IPlayer* damager, float damage, uint8_t weapon, BodyPart
11501153 lastDamagerWeapon_ = weapon;
11511154}
11521155
1156+ void NPC::updateAim ()
1157+ {
1158+ if (aiming_)
1159+ {
1160+ PlayerWeaponType weaponType = WeaponInfo::get (weapon_).type ;
1161+
1162+ // Set the camera mode
1163+ if (weaponType == PlayerWeaponType_Melee)
1164+ {
1165+ aimSync_.CamMode = 4 ;
1166+ }
1167+ else if (weapon_ == PlayerWeapon_Sniper)
1168+ {
1169+ aimSync_.CamMode = 7 ;
1170+ }
1171+ else if (weapon_ == PlayerWeapon_Camera)
1172+ {
1173+ aimSync_.CamMode = 46 ;
1174+ }
1175+ else if (weapon_ == PlayerWeapon_RocketLauncher)
1176+ {
1177+ aimSync_.CamMode = 8 ;
1178+ }
1179+ else if (weapon_ == PlayerWeapon_HeatSeeker)
1180+ {
1181+ aimSync_.CamMode = 51 ;
1182+ }
1183+ else
1184+ {
1185+ aimSync_.CamMode = 53 ;
1186+ }
1187+ }
1188+ else
1189+ {
1190+ // Set the camera mode and weapon state
1191+ aimSync_.CamMode = 0 ;
1192+ // Convert the player angle to radians
1193+
1194+ float angle = glm::radians (player_->getRotation ().ToEuler ().z );
1195+ // Calculate the camera target
1196+ Vector3 vecTarget (aimSync_.CamPos .x - glm::sin (angle) * 0 .2f ,
1197+ aimSync_.CamPos .z + glm::cos (angle) * 0 .2f ,
1198+ aimSync_.CamPos .z );
1199+
1200+ // Calculate the camera front vector
1201+ aimSync_.CamFrontVector = vecTarget - aimSync_.CamPos ;
1202+ }
1203+
1204+ // Update the weapon state
1205+ updateWeaponState ();
1206+ // Set the aim sync flag
1207+ // m_pPlayer->bHasAimSync = true;
1208+ }
1209+
11531210void NPC::updateAimData (const Vector3& point, bool setAngle)
11541211{
11551212 // Adjust the player position
@@ -1442,6 +1499,7 @@ void NPC::tick(Microseconds elapsed, TimePoint now)
14421499 if (duration_cast<Milliseconds>(now - lastFootSyncUpdate_).count () > npcComponent_->getFootSyncRate ())
14431500 {
14441501 sendFootSync ();
1502+ updateAim ();
14451503 lastFootSyncUpdate_ = now;
14461504 }
14471505
0 commit comments