Cleaned up Sentient class

Moved combat stuff to sentient_combat.cpp
Formatted source files
This commit is contained in:
smallmodel 2023-08-09 19:45:39 +02:00
parent f313b6a058
commit 987af7eb81
No known key found for this signature in database
GPG key ID: A96F163ED4891440
3 changed files with 3873 additions and 4513 deletions

File diff suppressed because it is too large Load diff

View file

@ -23,35 +23,34 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// sentient.h: Base class of entity that can carry other entities, and use weapons. // sentient.h: Base class of entity that can carry other entities, and use weapons.
// //
#ifndef __SENTIENT_H__ #pragma once
#define __SENTIENT_H__
#include "g_local.h" #include "g_local.h"
#include "container.h" #include "container.h"
#include "animate.h" #include "animate.h"
#include "vehicle.h" #include "vehicle.h"
#define LOCATION_MISS -2 #define LOCATION_MISS -2
#define LOCATION_GENERAL -1 #define LOCATION_GENERAL -1
#define LOCATION_HEAD 0 #define LOCATION_HEAD 0
#define LOCATION_HELMET 1 #define LOCATION_HELMET 1
#define LOCATION_NECK 2 #define LOCATION_NECK 2
#define LOCATION_TORSO_UPPER 3 #define LOCATION_TORSO_UPPER 3
#define LOCATION_TORSO_MID 4 #define LOCATION_TORSO_MID 4
#define LOCATION_TORSO_LOWER 5 #define LOCATION_TORSO_LOWER 5
#define LOCATION_PELVIS 6 #define LOCATION_PELVIS 6
#define LOCATION_R_ARM_UPPER 7 #define LOCATION_R_ARM_UPPER 7
#define LOCATION_L_ARM_UPPER 8 #define LOCATION_L_ARM_UPPER 8
#define LOCATION_R_LEG_UPPER 9 #define LOCATION_R_LEG_UPPER 9
#define LOCATION_L_LEG_UPPER 10 #define LOCATION_L_LEG_UPPER 10
#define LOCATION_R_ARM_LOWER 11 #define LOCATION_R_ARM_LOWER 11
#define LOCATION_L_ARM_LOWER 12 #define LOCATION_L_ARM_LOWER 12
#define LOCATION_R_LEG_LOWER 13 #define LOCATION_R_LEG_LOWER 13
#define LOCATION_L_LEG_LOWER 14 #define LOCATION_L_LEG_LOWER 14
#define LOCATION_R_HAND 15 #define LOCATION_R_HAND 15
#define LOCATION_L_HAND 16 #define LOCATION_L_HAND 16
#define LOCATION_R_FOOT 17 #define LOCATION_R_FOOT 17
#define LOCATION_L_FOOT 18 #define LOCATION_L_FOOT 18
extern Event EV_Sentient_Attack; extern Event EV_Sentient_Attack;
extern Event EV_Sentient_Charge; extern Event EV_Sentient_Charge;
@ -90,317 +89,266 @@ class Vehicle;
class VehicleTank; class VehicleTank;
class TurretGun; class TurretGun;
#define MAX_ACTIVE_WEAPONS NUM_ACTIVE_WEAPONS #define MAX_ACTIVE_WEAPONS NUM_ACTIVE_WEAPONS
#define MAX_DAMAGE_MULTIPLIERS 19 #define MAX_DAMAGE_MULTIPLIERS 19
#define TEAM_GERMAN 0 #define TEAM_GERMAN 0
#define TEAM_AMERICAN 1 #define TEAM_AMERICAN 1
#define THREATBIAS_IGNOREME 0xFFFFE4C7 #define THREATBIAS_IGNOREME 0xFFFFE4C7
typedef SafePtr< Weapon > WeaponPtr; typedef SafePtr<Weapon> WeaponPtr;
class ActiveWeapon : public Class class ActiveWeapon : public Class
{ {
public: public:
WeaponPtr weapon; WeaponPtr weapon;
weaponhand_t hand; weaponhand_t hand;
ActiveWeapon(); ActiveWeapon();
void Archive( Archiver &arc ); void Archive(Archiver& arc);
}; };
inline ActiveWeapon::ActiveWeapon
(
)
{
hand = WEAPON_ERROR;
}
inline void ActiveWeapon::Archive
(
Archiver &arc
)
{
arc.ArchiveObjectPointer( ( Class ** )&weapon );
ArchiveEnum( hand, weaponhand_t );
}
class Sentient : public Animate class Sentient : public Animate
{ {
protected: protected:
Container<int> inventory; Container<int> inventory;
Container<Ammo *> ammo_inventory; Container<Ammo *> ammo_inventory;
float LMRF; float LMRF;
WeaponPtr newWeapon; WeaponPtr newWeapon;
int poweruptype; int poweruptype;
int poweruptimer; int poweruptimer;
Vector offset_color; Vector offset_color;
Vector offset_delta; Vector offset_delta;
float offset_time; float offset_time;
float charge_start_time; float charge_start_time;
str blood_model; str blood_model;
SafePtr<Weapon> activeWeaponList[ MAX_ACTIVE_WEAPONS ]; SafePtr<Weapon> activeWeaponList[MAX_ACTIVE_WEAPONS];
ActiveWeapon newActiveWeapon; ActiveWeapon newActiveWeapon;
WeaponPtr holsteredWeapon; WeaponPtr holsteredWeapon;
bool weapons_holstered_by_code; bool weapons_holstered_by_code;
ActiveWeapon lastActiveWeapon; ActiveWeapon lastActiveWeapon;
float m_fDamageMultipliers[ MAX_DAMAGE_MULTIPLIERS ]; float m_fDamageMultipliers[MAX_DAMAGE_MULTIPLIERS];
class SafePtr<Vehicle> m_pVehicle; class SafePtr<Vehicle> m_pVehicle;
SafePtr< TurretGun > m_pTurret; SafePtr<TurretGun> m_pTurret;
SafePtr< Entity > m_pLadder; SafePtr<Entity> m_pLadder;
str m_sHelmetSurface1; str m_sHelmetSurface1;
str m_sHelmetSurface2; str m_sHelmetSurface2;
str m_sHelmetTiki; str m_sHelmetTiki;
float m_fHelmetSpeed; float m_fHelmetSpeed;
bool m_bDontDropWeapons; bool m_bDontDropWeapons;
virtual void EventTake( Event *ev ); virtual void EventTake(Event *ev);
virtual void EventFreeInventory( Event *ev ); virtual void EventGiveAmmo(Event *ev);
virtual void EventGiveAmmo( Event *ev ); virtual void EventGiveItem(Event *ev);
virtual void EventGiveItem( Event *ev ); void EventGiveDynItem(Event *ev);
void SetBloodModel( Event *ev ); void SetBloodModel(Event *ev);
virtual void EventGiveTargetname( Event *ev ); void EventUseItem(Event *ev);
void EventUseWeaponClass(Event *ev);
virtual void EventGiveTargetname(Event *ev);
void EventGerman( Event *ev ); void EventGerman(Event *ev);
void EventAmerican( Event *ev ); void EventAmerican(Event *ev);
void EventGetTeam( Event *ev ); void EventGetTeam(Event *ev);
virtual void ClearEnemies(); virtual void ClearEnemies();
void EventGetThreatBias( Event *ev ); void EventGetThreatBias(Event *ev);
void EventSetThreatBias( Event *ev ); void EventSetThreatBias(Event *ev);
void SetDamageMult( Event *ev ); void SetDamageMult(Event *ev);
void SetupHelmet( str sHelmetTiki, float fSpeed, float fDamageMult, str sHelmetSurface1, str sHelmetSurface2 ); void SetupHelmet(str sHelmetTiki, float fSpeed, float fDamageMult, str sHelmetSurface1, str sHelmetSurface2);
void EventSetupHelmet( Event *ev ); void EventSetupHelmet(Event *ev);
void EventPopHelmet( Event *ev ); void EventPopHelmet(Event *ev);
bool WearingHelmet( void ); bool WearingHelmet(void);
int CheckHitLocation( int iLocation ); int CheckHitLocation(int iLocation);
// Squad stuff virtual void ArmorDamage(Event *ev);
bool IsTeamMate( Sentient *pOther ); virtual qboolean CanBlock(int meansofdeath, qboolean full_block);
void JoinNearbySquads( float fJoinRadius = 1024.0f ); void AddBloodSpurt(Vector direction);
void MergeWithSquad( Sentient *pFriendly ); qboolean ShouldBleed(int meansofdeath, qboolean dead);
void DisbandSquadMate( Sentient *pExFriendly ); qboolean ShouldGib(int meansofdeath, float damage);
bool IsSquadMate( Sentient *pFriendly ); str GetBloodSpurtName(void);
str GetBloodSplatName(void);
float GetBloodSplatSize(void);
str GetGibName(void);
virtual void TurnOffShadow(Event *ev);
virtual void TurnOnShadow(Event *ev);
virtual void WeaponKnockedFromHands(void);
virtual void ArmorDamage( Event *ev ); void EventDropItems(Event *ev);
virtual qboolean CanBlock( int meansofdeath, qboolean full_block ); void EventDontDropWeapons(Event *ev);
void AddBloodSpurt( Vector direction ); void DetachAllActiveWeapons(void);
qboolean ShouldBleed( int meansofdeath, qboolean dead ); void AttachAllActiveWeapons(void);
qboolean ShouldGib( int meansofdeath, float damage ); qboolean WeaponsOut(void);
str GetBloodSpurtName( void ); qboolean IsActiveWeapon(Weapon *weapon);
str GetBloodSplatName( void ); void ActivateWeapon(Weapon *weapon, weaponhand_t hand);
float GetBloodSplatSize( void ); void ActivateLastActiveWeapon(void);
str GetGibName( void ); void EventActivateLastActiveWeapon(Event *ev);
virtual void TurnOffShadow( Event *ev ); void EventToggleItemUse(Event *ev);
virtual void TurnOnShadow( Event *ev ); void DeactivateWeapon(Weapon *weapon);
virtual void WeaponKnockedFromHands( void ); void DeactivateWeapon(weaponhand_t hand);
void CheckAnimations(Event *ev);
void ChargeWeapon(weaponhand_t hand, firemode_t mode);
void FireWeapon(int number, firemode_t mode);
void ReleaseFireWeapon(int number, firemode_t mode);
void Link();
void Unlink();
void UpdateOffsetColor( Event *ev ); public:
Vector mTargetPos;
float mAccuracy;
SafePtr<Sentient> m_pNextSquadMate;
SafePtr<Sentient> m_pPrevSquadMate;
Sentient *m_NextSentient;
Sentient *m_PrevSentient;
int m_Team;
int m_iAttackerCount;
SafePtr<Entity> m_pLastAttacker;
SafePtr<Sentient> m_Enemy;
float m_fPlayerSightLevel;
bool m_bIsDisguised;
bool m_bHasDisguise;
bool m_bOvercookDied;
int m_ShowPapersTime;
int m_iLastHitTime;
int m_iThreatBias;
Vector gunoffset;
Vector eyeposition;
int viewheight;
Vector m_vViewVariation;
int means_of_death;
bool in_melee_attack;
bool in_block;
bool in_stun;
bool on_fire;
float on_fire_stop_time;
float next_catch_on_fire_time;
int on_fire_tagnums[3];
SafePtr<Entity> fire_owner;
bool attack_blocked;
float attack_blocked_time;
float max_mouth_angle;
int max_gibs;
float next_bleed_time;
bool m_bFootOnGround_Right;
bool m_bFootOnGround_Left;
void DetachAllActiveWeapons( void ); CLASS_PROTOTYPE(Sentient);
void AttachAllActiveWeapons( void );
void UpdateWeapons( void ); Sentient();
qboolean IsActiveWeapon( Weapon *weapon ); virtual ~Sentient();
void ActivateWeapon( Weapon *weapon, weaponhand_t hand ); virtual Vector EyePosition(void);
void ActivateNewWeapon( Event *ev );
void ActivateNewWeapon( void );
void DeactivateWeapon( Weapon *weapon );
void DeactivateWeapon( weaponhand_t hand );
void DeactivateWeapon( Event *ev );
void ActivateLastActiveWeapon( void );
void CheckAnimations( Event *ev );
void EventActivateLastActiveWeapon( Event *ev );
void EventDropItems( Event *ev );
void EventDontDropWeapons( Event *ev );
void EventUseItem( Event *ev );
void EventUseWeaponClass( Event *ev );
void EventToggleItem( Event *ev );
void ReloadWeapon( Event *ev );
void GetActiveWeap( Event *ev );
void GetNewActiveWeapon( Event *ev );
public: virtual void SetViewAngles(Vector angles);
Vector mTargetPos; virtual void SetTargetViewAngles(Vector angles);
float mAccuracy; virtual Vector GetViewAngles(void);
SafePtr<Sentient> m_pNextSquadMate; void AddViewVariation(const Vector &vVariation);
SafePtr<Sentient> m_pPrevSquadMate; void SetMinViewVariation(const Vector &vVariation);
Sentient *m_NextSentient; bool CanSee(Entity *ent, float fov, float vision_distance) override;
Sentient *m_PrevSentient; virtual Vector GunPosition(void);
int m_Team; virtual Vector GunTarget(bool bNoCollision = false);
int m_iAttackerCount; void ReloadWeapon(Event *ev);
SafePtr<Entity> m_pLastAttacker; void FireWeapon(Event *ev);
SafePtr<Sentient> m_Enemy; void StopFireWeapon(Event *ev);
float m_fPlayerSightLevel; void ChargeWeapon(Event *ev);
bool m_bIsDisguised; void ReleaseFireWeapon(Event *ev);
bool m_bHasDisguise; void ChangeWeapon(Weapon *weapon, weaponhand_t hand);
bool m_bOvercookDied; Weapon *GetActiveWeapon(weaponhand_t hand) const;
int m_ShowPapersTime; Weapon *WorstWeapon(Weapon *ignore = NULL, qboolean bGetItem = false, int iIgnoreClass = 0);
int m_iLastHitTime; Weapon *BestWeapon(Weapon *ignore = NULL, qboolean bGetItem = false, int iIgnoreClass = 0);
int m_iThreatBias; Weapon *NextWeapon(Weapon *weapon);
Vector gunoffset; Weapon *PreviousWeapon(Weapon *weapon);
Vector eyeposition; void useWeapon(const char *weaponname, weaponhand_t hand = WEAPON_MAIN);
int viewheight; void useWeapon(Weapon *weapon, weaponhand_t hand = WEAPON_MAIN);
Vector m_vViewVariation; void EventUseWeapon(Event *ev);
int means_of_death; void EventDeactivateWeapon(Event *ev);
bool in_melee_attack; int NumWeapons(void);
bool in_block; int AmmoCount(str ammo_type);
bool in_stun; int MaxAmmoCount(str ammo_type);
bool on_fire; int AmmoIndex(str ammo_type);
float on_fire_stop_time; int UseAmmo(str ammo_type, int amount);
float next_catch_on_fire_time; void GiveAmmo(str type, int amount, int max_amount = -1);
int on_fire_tagnums[ 3 ]; Ammo *FindAmmoByName(str name);
SafePtr<Entity> fire_owner; Item *giveItem(str itemname, int amount = 1);
bool attack_blocked; void takeItem(const char *itemname);
float attack_blocked_time; void takeAmmoType(const char *ammoname);
float max_mouth_angle; void AddItem(Item *object);
int max_gibs; void RemoveItem(Item *object);
float next_bleed_time; void RemoveWeapons(void);
bool m_bFootOnGround_Right; Weapon *GetWeapon(int index);
bool m_bFootOnGround_Left; Item *FindItemByClassName(const char *classname);
Item *FindItemByModelname(const char *modelname);
Item *FindItemByExternalName(const char *externalname);
Item *FindItem(const char *itemname);
void FreeInventory(void);
void EventFreeInventory(Event *ev);
qboolean HasItem(const char *itemname);
qboolean HasWeaponClass(int iWeaponClass);
qboolean HasPrimaryWeapon(void);
qboolean HasSecondaryWeapon(void);
int NumInventoryItems(void);
Item *NextItem(Item *item);
Item *PrevItem(Item *item);
virtual void DropInventoryItems(void);
void ListInventory(void);
CLASS_PROTOTYPE( Sentient ); qboolean PowerupActive(void);
Sentient(); void setModel(const char *model) override;
virtual ~Sentient(); void Archive(Archiver &arc) override;
Vector EyePosition( void ); void ArchivePersistantData(Archiver &arc);
void DoubleArmor(void);
virtual qboolean DoGib(int meansofdeath, Entity *inflictor);
void JumpXY(Event *ev);
void MeleeAttackStart(Event *ev);
void MeleeAttackEnd(Event *ev);
void BlockStart(Event *ev);
void BlockEnd(Event *ev);
void StunStart(Event *ev);
void StunEnd(Event *ev);
void SetAttackBlocked(bool blocked);
virtual void ReceivedItem(Item *item);
virtual void RemovedItem(Item *item);
virtual void AmmoAmountChanged(Ammo *ammo, int inclip = 0);
void AmmoAmountInClipChanged(str ammo_type, int amount);
virtual Vector GunPosition( void ); void SetMaxMouthAngle(Event *ev);
virtual Vector GunTarget( bool bNoCollision = false ); void TryLightOnFire(int meansofdeath, Entity *attacker);
void FireWeapon( Event *ev ); void OnFire(Event *ev);
void FireWeapon( int number, firemode_t mode ); void StopOnFire(Event *ev);
void StopFireWeapon( Event *ev ); void SpawnBloodyGibs(Event *ev);
void ChargeWeapon( Event *ev ); void SetMaxGibs(Event *ev);
void ChargeWeapon( weaponhand_t hand, firemode_t mode ); virtual void GetStateAnims(Container<const char *> *c);
void ReleaseFireWeapon( Event *ev ); void SpawnEffect(str modelname, Vector pos);
void ReleaseFireWeapon( int number, firemode_t mode );
void ChangeWeapon( Weapon *weapon, weaponhand_t hand );
Weapon *GetActiveWeapon( weaponhand_t hand );
Weapon *BestWeapon( Weapon *ignore = NULL, qboolean bGetItem = false, int iIgnoreClass = 0 );
Weapon *WorstWeapon( Weapon *ignore = NULL, qboolean bGetItem = false, int iIgnoreClass = 0 );
Weapon *NextWeapon( Weapon *weapon );
Weapon *PreviousWeapon( Weapon *weapon );
virtual void useWeapon( const char *weaponname, weaponhand_t hand );
virtual void useWeapon( Weapon *weapon, weaponhand_t hand );
qboolean WeaponsOut( void );
void Holster( qboolean putaway );
void SafeHolster( qboolean putaway );
bool IsNewActiveWeapon( void );
Weapon *GetNewActiveWeapon( void );
weaponhand_t GetNewActiveWeaponHand( void );
void ClearNewActiveWeapon( void );
int NumWeapons( void );
int AmmoCount( str ammo_type );
int MaxAmmoCount( str ammo_type );
int AmmoIndex( str ammo_type );
int UseAmmo( str ammo_type, int amount );
void GiveAmmo( str type, int amount, int max_amount = -1 );
Ammo *FindAmmoByName( str name );
Item *giveItem( str itemname, int amount = 1 );
void takeItem( const char *itemname );
void takeAmmoType( const char *ammoname );
void AddItem( Item *object );
void RemoveItem( Item *object );
void RemoveWeapons( void );
Weapon *GetWeapon( int index );
Item *FindItemByClassName( const char *classname );
Item *FindItemByModelname( const char *modelname );
Item *FindItemByExternalName( const char *externalname );
Item *FindItem( const char *itemname );
void FreeInventory( void );
qboolean HasItem( const char *itemname );
qboolean HasWeaponClass( int iWeaponClass );
qboolean HasPrimaryWeapon( void );
qboolean HasSecondaryWeapon( void );
int NumInventoryItems( void );
Item *NextItem( Item *item );
Item *PrevItem( Item *item );
virtual void DropInventoryItems( void );
void ListInventory( void );
bool CanSee( Entity *ent, float fov, float vision_distance ) override; bool IsNewActiveWeapon(void);
virtual void SetViewAngles( Vector angles ); Weapon *GetNewActiveWeapon(void);
virtual Vector GetViewAngles( void ); weaponhand_t GetNewActiveWeaponHand(void);
void ClearNewActiveWeapon(void);
qboolean PowerupActive( void ); void Holster(qboolean putaway);
void SafeHolster(qboolean putaway);
void setModel( const char *model ) override; void ActivateNewWeapon(void);
void Archive( Archiver &arc ) override; void ActivateNewWeapon(Event *ev);
void ArchivePersistantData( Archiver &arc ); void UpdateWeapons(void);
void DoubleArmor( void ); VehicleTank *GetVehicleTank(void);
virtual qboolean DoGib( int meansofdeath, Entity *inflictor ); void UpdateFootsteps(void);
void JumpXY( Event *ev ); qboolean AIDontFace() const override;
void MeleeAttackStart( Event *ev ); void PutawayWeapon(Event *ev);
void MeleeAttackEnd( Event *ev ); void WeaponCommand(Event *ev);
void BlockStart( Event *ev ); //
void BlockEnd( Event *ev ); // Squad stuff
void StunStart( Event *ev ); //
void StunEnd( Event *ev ); void AssertValidSquad();
void SetAttackBlocked( bool blocked ); bool IsTeamMate(Sentient *pOther);
void SetOffsetColor( float r, float g, float b, float time ); void JoinNearbySquads(float fJoinRadius = 1024.0f);
virtual void ReceivedItem( Item * item ); void MergeWithSquad(Sentient *pFriendly);
virtual void RemovedItem( Item * item ); void DisbandSquadMate(Sentient *pExFriendly);
virtual void AmmoAmountChanged( Ammo * ammo, int inclip = 0 ); bool IsSquadMate(Sentient *pFriendly);
void AmmoAmountInClipChanged( str ammo_type, int amount );
void PutawayWeapon( Event *ev );
void WeaponCommand( Event *ev );
VehicleTank *GetVehicleTank( void );
void UpdateFootsteps( void );
void SetMaxMouthAngle( Event *ev );
void TryLightOnFire( int meansofdeath, Entity *attacker );
void OnFire( Event *ev );
void StopOnFire( Event *ev );
void SpawnBloodyGibs( Event *ev );
void SetMaxGibs( Event *ev );
virtual void GetStateAnims( Container<const char *> *c );
void SpawnEffect( str modelname, Vector pos );
};
inline bool Sentient::IsNewActiveWeapon
(
void
)
{
return ( newActiveWeapon.weapon != NULL );
}
inline weaponhand_t Sentient::GetNewActiveWeaponHand
(
void
)
{
return newActiveWeapon.hand;
}
inline Weapon *Sentient::GetNewActiveWeapon
(
void
)
{
return newActiveWeapon.weapon;
}
inline void Sentient::ClearNewActiveWeapon
(
void
)
{
newActiveWeapon.weapon.Clear();
newActiveWeapon.hand = WEAPON_ERROR;
}
//
// Custom openmohaa stuff
//
void GetActiveWeap(Event *ev);
void GetNewActiveWeapon(Event *ev);
};
typedef SafePtr<Sentient> SentientPtr; typedef SafePtr<Sentient> SentientPtr;
extern Container<Sentient *> SentientList; extern Container<Sentient *> SentientList;
#endif /* sentient.h */

File diff suppressed because it is too large Load diff