Browse Source

Add extended weapon ehandle

gravgun
mittorn 8 years ago
parent
commit
c8084e8428
  1. 6
      dlls/player.cpp
  2. 10
      dlls/player.h
  3. 4
      dlls/weapons.cpp
  4. 7
      dlls/weapons.h
  5. 46
      dlls/whandle.h

6
dlls/player.cpp

@ -92,9 +92,9 @@ TYPEDESCRIPTION CBasePlayer::m_playerSaveData[] =
DEFINE_ARRAY( CBasePlayer, m_rgflSuitNoRepeatTime, FIELD_TIME, CSUITNOREPEAT ), DEFINE_ARRAY( CBasePlayer, m_rgflSuitNoRepeatTime, FIELD_TIME, CSUITNOREPEAT ),
DEFINE_FIELD( CBasePlayer, m_lastDamageAmount, FIELD_INTEGER ), DEFINE_FIELD( CBasePlayer, m_lastDamageAmount, FIELD_INTEGER ),
DEFINE_ARRAY( CBasePlayer, m_rgpPlayerItems, FIELD_CLASSPTR, MAX_ITEM_TYPES ), DEFINE_ARRAY( CBasePlayer, m_rgpPlayerItems, FIELD_EHANDLE, MAX_ITEM_TYPES ),
DEFINE_FIELD( CBasePlayer, m_pActiveItem, FIELD_CLASSPTR ), DEFINE_FIELD( CBasePlayer, m_pActiveItem, FIELD_EHANDLE ),
DEFINE_FIELD( CBasePlayer, m_pLastItem, FIELD_CLASSPTR ), DEFINE_FIELD( CBasePlayer, m_pLastItem, FIELD_EHANDLE ),
DEFINE_ARRAY( CBasePlayer, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ), DEFINE_ARRAY( CBasePlayer, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ),
DEFINE_FIELD( CBasePlayer, m_idrowndmg, FIELD_INTEGER ), DEFINE_FIELD( CBasePlayer, m_idrowndmg, FIELD_INTEGER ),

10
dlls/player.h

@ -93,6 +93,8 @@ enum PlayerState
STATE_POINT_SELECT STATE_POINT_SELECT
}; };
#include "whandle.h"
class CBasePlayer : public CBaseMonster class CBasePlayer : public CBaseMonster
{ {
public: public:
@ -173,10 +175,10 @@ public:
int m_iClientFOV; // client's known FOV int m_iClientFOV; // client's known FOV
// usable player items // usable player items
CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES]; EHBasePlayerItem m_rgpPlayerItems[MAX_ITEM_TYPES];
CBasePlayerItem *m_pActiveItem; EHBasePlayerItem m_pActiveItem;
CBasePlayerItem *m_pClientActiveItem; // client version of the active item EHBasePlayerItem m_pClientActiveItem; // client version of the active item
CBasePlayerItem *m_pLastItem; EHBasePlayerItem m_pLastItem;
// shared ammo slots // shared ammo slots
int m_rgAmmo[MAX_AMMO_SLOTS]; int m_rgAmmo[MAX_AMMO_SLOTS];

4
dlls/weapons.cpp

@ -393,7 +393,7 @@ void W_Precache( void )
TYPEDESCRIPTION CBasePlayerItem::m_SaveData[] = TYPEDESCRIPTION CBasePlayerItem::m_SaveData[] =
{ {
DEFINE_FIELD( CBasePlayerItem, m_pPlayer, FIELD_CLASSPTR ), DEFINE_FIELD( CBasePlayerItem, m_pPlayer, FIELD_CLASSPTR ),
DEFINE_FIELD( CBasePlayerItem, m_pNext, FIELD_CLASSPTR ), DEFINE_FIELD( CBasePlayerItem, m_pNext, FIELD_EHANDLE ),
//DEFINE_FIELD( CBasePlayerItem, m_fKnown, FIELD_INTEGER ),Reset to zero on load //DEFINE_FIELD( CBasePlayerItem, m_fKnown, FIELD_INTEGER ),Reset to zero on load
DEFINE_FIELD( CBasePlayerItem, m_iId, FIELD_INTEGER ), DEFINE_FIELD( CBasePlayerItem, m_iId, FIELD_INTEGER ),
// DEFINE_FIELD( CBasePlayerItem, m_iIdPrimary, FIELD_INTEGER ), // DEFINE_FIELD( CBasePlayerItem, m_iIdPrimary, FIELD_INTEGER ),
@ -1303,7 +1303,7 @@ TYPEDESCRIPTION CWeaponBox::m_SaveData[] =
{ {
DEFINE_ARRAY( CWeaponBox, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ), DEFINE_ARRAY( CWeaponBox, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS ),
DEFINE_ARRAY( CWeaponBox, m_rgiszAmmo, FIELD_STRING, MAX_AMMO_SLOTS ), DEFINE_ARRAY( CWeaponBox, m_rgiszAmmo, FIELD_STRING, MAX_AMMO_SLOTS ),
DEFINE_ARRAY( CWeaponBox, m_rgpPlayerItems, FIELD_CLASSPTR, MAX_ITEM_TYPES ), DEFINE_ARRAY( CWeaponBox, m_rgpPlayerItems, FIELD_EHANDLE, MAX_ITEM_TYPES ),
DEFINE_FIELD( CWeaponBox, m_cAmmoTypes, FIELD_INTEGER ), DEFINE_FIELD( CWeaponBox, m_cAmmoTypes, FIELD_INTEGER ),
}; };

7
dlls/weapons.h

@ -214,6 +214,9 @@ typedef struct
int iId; int iId;
} AmmoInfo; } AmmoInfo;
#include "whandle.h"
// Items that the player has in their inventory that they can use // Items that the player has in their inventory that they can use
class CBasePlayerItem : public CBaseAnimating class CBasePlayerItem : public CBaseAnimating
{ {
@ -262,7 +265,7 @@ public:
static AmmoInfo AmmoInfoArray[ MAX_AMMO_SLOTS ]; static AmmoInfo AmmoInfoArray[ MAX_AMMO_SLOTS ];
CBasePlayer *m_pPlayer; CBasePlayer *m_pPlayer;
CBasePlayerItem *m_pNext; EHBasePlayerItem m_pNext;
int m_iId; // WEAPON_??? int m_iId; // WEAPON_???
virtual int iItemSlot( void ) { return 0; } // return 0 to MAX_ITEMS_SLOTS, used in hud virtual int iItemSlot( void ) { return 0; } // return 0 to MAX_ITEMS_SLOTS, used in hud
@ -453,7 +456,7 @@ public:
BOOL PackWeapon( CBasePlayerItem *pWeapon ); BOOL PackWeapon( CBasePlayerItem *pWeapon );
BOOL PackAmmo( int iszName, int iCount ); BOOL PackAmmo( int iszName, int iCount );
CBasePlayerItem *m_rgpPlayerItems[MAX_ITEM_TYPES];// one slot for each EHBasePlayerItem m_rgpPlayerItems[MAX_ITEM_TYPES];// one slot for each
int m_rgiszAmmo[MAX_AMMO_SLOTS];// ammo names int m_rgiszAmmo[MAX_AMMO_SLOTS];// ammo names
int m_rgAmmo[MAX_AMMO_SLOTS];// ammo quantities int m_rgAmmo[MAX_AMMO_SLOTS];// ammo quantities

46
dlls/whandle.h

@ -0,0 +1,46 @@
#ifndef WHANDLE_H
#define WHANDLE_H
class CBasePlayerItem;
class EHBasePlayerItem : public EHANDLE
{
public:
operator CBasePlayerItem *()
{
return (CBasePlayerItem *)GET_PRIVATE( Get() );
}
CBasePlayerItem *operator ->()
{
return (CBasePlayerItem *)GET_PRIVATE( Get() );
}
template <class T>
operator T()
{
return (T)GET_PRIVATE( Get() );
}
template <class T>
T *operator = ( T *pEntity )
{
edict_t *e = NULL;
if( pEntity )
e = pEntity->edict();
return (T*)CBaseEntity::Instance( Set ( e ) );
}
// handle = NULL correctly
int operator = ( int null1 )
{
//assert( !null1 );
Set(0);
return 0;
}
bool operator !=(EHBasePlayerItem &other)
{
return Get() != other.Get();
}
};
#endif
Loading…
Cancel
Save