Rework predict

This commit is contained in:
a1batross 2016-04-13 01:11:45 +03:00
parent 94d8ade941
commit 18de99c54e

View File

@ -39,8 +39,6 @@
#include "cl_entity.h" #include "cl_entity.h"
#include "ammo.h"
#include "ammohistory.h"
#ifndef min #ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b)) #define min(a,b) (((a) < (b)) ? (a) : (b))
#endif #endif
@ -56,6 +54,10 @@ extern "C" char PM_FindTextureType( char *name );
extern globalvars_t *gpGlobals; extern globalvars_t *gpGlobals;
extern int g_iUser1; extern int g_iUser1;
extern bool g_bGlockBurstMode; extern bool g_bGlockBurstMode;
extern int g_rseq;
extern int g_gaitseq;
extern vec3_t g_clorg;
extern vec3_t g_clang;
// Pool of client side entities/entvars_t // Pool of client side entities/entvars_t
static entvars_t ev[ 32 ]; static entvars_t ev[ 32 ];
@ -69,43 +71,37 @@ static globalvars_t Globals = { 0 };
static CBasePlayerWeapon *g_pWpns[ 32 ]; static CBasePlayerWeapon *g_pWpns[ 32 ];
extern int g_rseq;
extern int g_gaitseq;
extern vec3_t g_clorg;
extern vec3_t g_clang;
float g_flApplyVel = 0.0; // CS Weapon placeholder entities
static CAK47 g_AK47;
// HLDM Weapon placeholder entities static CAUG g_AUG;
CAK47 g_AK47; static CAWP g_AWP;
CAUG g_AUG; static CC4 g_C4;
CAWP g_AWP; static CDEAGLE g_DEAGLE;
CC4 g_C4; static CELITE g_ELITE;
CDEAGLE g_DEAGLE; static CFamas g_Famas;
CELITE g_ELITE; static CFiveSeven g_FiveSeven;
CFamas g_Famas; static CFlashbang g_Flashbang;
CFiveSeven g_FiveSeven; static CG3SG1 g_G3SG1;
CFlashbang g_Flashbang; static CGalil g_Galil;
CG3SG1 g_G3SG1; static CGLOCK18 g_GLOCK18;
CGalil g_Galil; static CHEGrenade g_HEGrenade;
CGLOCK18 g_GLOCK18; static CKnife g_Knife;
CHEGrenade g_HEGrenade; static CM249 g_M249;
CKnife g_Knife; static CM3 g_M3;
CM249 g_M249; static CM4A1 g_M4A1;
CM3 g_M3; static CMAC10 g_MAC10;
CM4A1 g_M4A1; static CMP5N g_MP5N;
CMAC10 g_MAC10; static CP228 g_P228;
CMP5N g_MP5N; static CP90 g_P90;
CP228 g_P228; static CSCOUT g_SCOUT;
CP90 g_P90; static CSG550 g_SG550;
CSCOUT g_SCOUT; static CSG552 g_SG552;
CSG550 g_SG550; static CSmokeGrenade g_SmokeGrenade;
CSG552 g_SG552; static CTMP g_TMP;
CSmokeGrenade g_SmokeGrenade; static CUMP45 g_UMP45;
CTMP g_TMP; static CUSP g_USP;
CUMP45 g_UMP45; static CXM1014 g_XM1014;
CUSP g_USP;
CXM1014 g_XM1014;
int g_iWeaponFlags; int g_iWeaponFlags;
bool g_bInBombZone; bool g_bInBombZone;
@ -243,11 +239,12 @@ BOOL CBasePlayerWeapon :: DefaultReload( int iClipSize, int iAnim, float fDelay,
if( !m_pPlayer->m_pActiveItem ) if( !m_pPlayer->m_pActiveItem )
return FALSE; return FALSE;
if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 ) if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
return FALSE; return FALSE;
int j = min(iClipSize - m_iClip, player.m_rgAmmo[m_iPrimaryAmmoType]); int j = min(iClipSize - m_iClip, player.m_rgAmmo[m_iPrimaryAmmoType]);
if ( j == 0 )
if (j == 0)
return FALSE; return FALSE;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + fDelay;
@ -327,64 +324,6 @@ bool CBasePlayerWeapon::HasSecondaryAttack()
return true; return true;
} }
BOOL UTIL_GetNextBestWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon)
{
if (!pCurrentWeapon->CanHolster())
{
// can't put this gun away right now, so can't switch.
return FALSE;
}
int iBestWeight = -1; // no weapon lower than -1 can be autoswitched to
WEAPON *pBest = NULL;
int i = 0;
for ( WEAPON *pWpn = gWR.GetFirstPos(i); pWpn; pWpn = gWR.GetNextActivePos(i, pWpn->iSlotPos) )
{
int iCurrentId = pWpn->iId;
CBasePlayerWeapon *pWpnEnt = g_pWpns[iCurrentId];
if( pWpnEnt && iBestWeight < pWpnEnt->iWeight() )
{
if( pCurrentWeapon->m_iId != iCurrentId )
{
pBest = pWpn;
iBestWeight = pWpnEnt->iWeight();
}
}
++i;
}
// if we make it here, we've checked all the weapons and found no useable
// weapon in the same catagory as the current weapon.
// if pBest is null, we didn't find ANYTHING. Shouldn't be possible- should always
// at least get the crowbar, but ya never know.
if ( !pBest )
return FALSE;
CBasePlayerWeapon *pBestWeapon = g_pWpns[pBest->iId];
if( !pPlayer || !pBestWeapon )
return TRUE;
if( pBestWeapon->CanDeploy() )
{
if( pPlayer->m_pActiveItem )
pPlayer->m_pActiveItem->Holster();
pPlayer->m_pActiveItem = pBestWeapon;
pBestWeapon->Deploy();
}
return TRUE;
}
void CBasePlayerWeapon::RetireWeapon( void )
{
UTIL_GetNextBestWeapon( m_pPlayer, this );
}
void CBasePlayerWeapon::FireRemaining(int &shotsFired, float &shootTime, BOOL isGlock18) void CBasePlayerWeapon::FireRemaining(int &shotsFired, float &shootTime, BOOL isGlock18)
{ {
m_iClip--; m_iClip--;
@ -567,7 +506,7 @@ void CBasePlayerWeapon::SendWeaponAnim( int iAnim, int skiplocal )
Vector CBaseEntity::FireBullets3 ( Vector vecSrc, Vector vecDirShooting, float flSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand ) Vector CBaseEntity::FireBullets3 ( Vector vecSrc, Vector vecDirShooting, float flSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand )
{ {
float x, y; float x, y, z;
if ( pevAttacker ) if ( pevAttacker )
{ {
@ -576,7 +515,6 @@ Vector CBaseEntity::FireBullets3 ( Vector vecSrc, Vector vecDirShooting, float f
} }
else else
{ {
float z;
do do
{ {
x = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5); x = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
@ -621,7 +559,7 @@ void CBasePlayerWeapon::ItemPostFrame( void )
FireRemaining(m_iFamasShotsFired, m_flFamasShoot, FALSE); FireRemaining(m_iFamasShotsFired, m_flFamasShoot, FALSE);
} }
if (m_flNextPrimaryAttack <= UTIL_WeaponTimeBase()) if (m_flNextPrimaryAttack <= 0.0f)
{ {
if (m_pPlayer->m_bResumeZoom) if (m_pPlayer->m_bResumeZoom)
{ {
@ -708,13 +646,18 @@ void CBasePlayerWeapon::ItemPostFrame( void )
m_iShotsFired = 0; m_iShotsFired = 0;
if (!(m_iWeaponState & WPNSTATE_SHIELD_DRAWN) && if (!(m_iWeaponState & WPNSTATE_SHIELD_DRAWN))
m_iClip == 0 && !(iFlags() & ITEM_FLAG_NOAUTORELOAD) &&
m_flNextPrimaryAttack < UTIL_WeaponTimeBase() &&
m_flFamasShoot == 0 && m_flGlock18Shoot == 0)
{ {
Reload();
return; if (m_iClip == 0 && !(iFlags() & ITEM_FLAG_NOAUTORELOAD)
&& m_flNextPrimaryAttack < UTIL_WeaponTimeBase())
{
if (m_flFamasShoot == 0 && m_flGlock18Shoot == 0)
{
Reload();
return;
}
}
} }
WeaponIdle(); WeaponIdle();
@ -895,6 +838,7 @@ char UTIL_TextureHit(TraceResult *ptr, Vector vecSrc, Vector vecEnd)
char chTextureType; char chTextureType;
float rgfl1[3], rgfl2[3]; float rgfl1[3], rgfl2[3];
const char *pTextureName; const char *pTextureName;
char szbuffer[64];
CBaseEntity *pEntity; CBaseEntity *pEntity;
if( ptr->pHit == NULL ) if( ptr->pHit == NULL )
@ -915,8 +859,6 @@ char UTIL_TextureHit(TraceResult *ptr, Vector vecSrc, Vector vecEnd)
if (pTextureName) if (pTextureName)
{ {
char szbuffer[64];
if (*pTextureName == '-' || *pTextureName == '+') if (*pTextureName == '-' || *pTextureName == '+')
pTextureName += 2; pTextureName += 2;
@ -1135,7 +1077,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
int buttonsChanged; int buttonsChanged;
CBasePlayerWeapon *pWeapon = NULL; CBasePlayerWeapon *pWeapon = NULL;
CBasePlayerWeapon *pCurrent; CBasePlayerWeapon *pCurrent;
weapon_data_t *pfrom, *pto; weapon_data_t *pto;
static int lasthealth; static int lasthealth;
int flags; int flags;
@ -1145,7 +1087,6 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
gpGlobals->time = time; gpGlobals->time = time;
// Fill in data based on selected weapon // Fill in data based on selected weapon
// FIXME, make this a method in each weapon? where you pass in an entity_state_t *?
switch ( from->client.m_iId ) switch ( from->client.m_iId )
{ {
case WEAPON_P228: case WEAPON_P228:
@ -1280,7 +1221,20 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
// If we are running events/etc. go ahead and see if we // If we are running events/etc. go ahead and see if we
// managed to die between last frame and this one // managed to die between last frame and this one
// If so, run the appropriate player killed or spawn function // If so, run the appropriate player killed or spawn function
if ( g_runfuncs )
{
if ( to->client.health <= 0 && lasthealth > 0 )
{
player.Killed( NULL, 0 );
}
else if ( to->client.health > 0 && lasthealth <= 0 )
{
player.Spawn();
}
lasthealth = to->client.health;
}
// We are not predicting the current weapon, just bow out here. // We are not predicting the current weapon, just bow out here.
if ( !pWeapon ) if ( !pWeapon )
@ -1294,7 +1248,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
continue; continue;
} }
pfrom = &from->weapondata[ i ]; weapon_data_t *pfrom = from->weapondata + i;
pCurrent->m_fInReload = pfrom->m_fInReload; pCurrent->m_fInReload = pfrom->m_fInReload;
pCurrent->m_fInSpecialReload = pfrom->m_fInSpecialReload; pCurrent->m_fInSpecialReload = pfrom->m_fInSpecialReload;
@ -1310,14 +1264,19 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
pCurrent->m_iShotsFired = pfrom->m_fInZoom; pCurrent->m_iShotsFired = pfrom->m_fInZoom;
} }
pWeapon->m_iPrimaryAmmoType = (int)from->client.vuser4.x; if( from->client.vuser4.x < 0 || from->client.vuser4.x > MAX_AMMO_TYPES )
if( pWeapon->m_iPrimaryAmmoType < 0 || pWeapon->m_iPrimaryAmmoType > MAX_AMMO_TYPES ) {
pWeapon->m_iPrimaryAmmoType = 0; pWeapon->m_iPrimaryAmmoType = 0;
else
player.m_rgAmmo[ pWeapon->m_iPrimaryAmmoType ] = (int)from->client.vuser4.y;
if( pWeapon ) }
g_iWeaponFlags = pWeapon->m_iWeaponState; else
{
pWeapon->m_iPrimaryAmmoType = (int)from->client.vuser4.x;
player.m_rgAmmo[ pWeapon->m_iPrimaryAmmoType ] = (int)from->client.vuser4.y;
}
g_iWeaponFlags = pWeapon->m_iWeaponState;
// For random weapon events, use this seed to seed random # generator // For random weapon events, use this seed to seed random # generator
player.random_seed = random_seed; player.random_seed = random_seed;
@ -1353,18 +1312,16 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
g_flPlayerSpeed = from->client.velocity.Length(); g_flPlayerSpeed = from->client.velocity.Length();
//Stores all our ammo info, so the client side weapons can use them. //Stores all our ammo info, so the client side weapons can use them.
player.ammo_9mm = from->client.ammo_nails; player.ammo_9mm = (int)from->client.ammo_nails;
player.ammo_556nato = from->client.ammo_cells; player.ammo_556nato = (int)from->client.ammo_cells;
player.ammo_buckshot = from->client.ammo_shells; player.ammo_buckshot = (int)from->client.ammo_shells;
player.ammo_556natobox = from->client.ammo_rockets; player.ammo_556natobox = (int)from->client.ammo_rockets;
player.ammo_762nato = (int)from->client.vuser2.x;
player.ammo_762nato = (signed int) floor(from->client.vuser2.x); player.ammo_45acp = (int)from->client.vuser2.y;
player.ammo_45acp = (signed int) floor(from->client.vuser2.y); player.ammo_50ae = (int)from->client.vuser2.z;
player.ammo_50ae = (signed int) floor(from->client.vuser2.z); player.ammo_338mag = (int)from->client.vuser3.x;
player.ammo_57mm = (int)from->client.vuser3.y;
player.ammo_338mag = (signed int) floor(from->client.vuser3.x); player.ammo_357sig = (int)from->client.vuser3.z;
player.ammo_57mm = (signed int) floor(from->client.vuser3.y);
player.ammo_357sig = (signed int) floor(from->client.vuser3.z);
cl_entity_t *pplayer = gEngfuncs.GetLocalPlayer(); cl_entity_t *pplayer = gEngfuncs.GetLocalPlayer();
if( pplayer ) if( pplayer )
@ -1375,14 +1332,14 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
} }
flags = from->client.iuser3; flags = from->client.iuser3;
g_bHoldingKnife = pWeapon && pWeapon->m_iId == WEAPON_KNIFE; g_bHoldingKnife = pWeapon->m_iId == WEAPON_KNIFE;
player.m_bCanShoot = (flags & PLAYER_CAN_SHOOT) != 0; player.m_bCanShoot = (flags & PLAYER_CAN_SHOOT) != 0;
g_iFreezeTimeOver = !(flags & PLAYER_FREEZE_TIME_OVER); g_iFreezeTimeOver = !(flags & PLAYER_FREEZE_TIME_OVER);
g_bInBombZone = (flags & PLAYER_IN_BOMB_ZONE) != 0; g_bInBombZone = (flags & PLAYER_IN_BOMB_ZONE) != 0;
g_bHoldingShield = (flags & PLAYER_HOLDING_SHIELD) != 0; g_bHoldingShield = (flags & PLAYER_HOLDING_SHIELD) != 0;
// Point to current weapon object // Point to current weapon object
if ( pWeapon ) if ( from->client.m_iId )
{ {
player.m_pActiveItem = pWeapon; player.m_pActiveItem = pWeapon;
} }
@ -1400,20 +1357,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
pWeapon->ItemPostFrame(); pWeapon->ItemPostFrame();
} }
} }
if ( g_runfuncs )
{
if ( to->client.health <= 0 && lasthealth > 0 )
{
player.Killed( NULL, 0 );
}
else if ( to->client.health > 0 && lasthealth <= 0 )
{
player.Spawn();
}
lasthealth = to->client.health;
}
// Assume that we are not going to switch weapons // Assume that we are not going to switch weapons
to->client.m_iId = from->client.m_iId; to->client.m_iId = from->client.m_iId;
@ -1471,7 +1415,7 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
// Make sure that weapon animation matches what the game .dll is telling us // Make sure that weapon animation matches what the game .dll is telling us
// over the wire ( fixes some animation glitches ) // over the wire ( fixes some animation glitches )
if ( g_runfuncs && ( HUD_GetWeaponAnim() != to->client.weaponanim ) && ( HUD_GetWeapon() != to->client.m_iId )) if ( g_runfuncs && ( HUD_GetWeaponAnim() != to->client.weaponanim ) )
// Force a fixed anim down to viewmodel // Force a fixed anim down to viewmodel
HUD_SendWeaponAnim( to->client.weaponanim, to->client.m_iId, 2, 1 ); HUD_SendWeaponAnim( to->client.weaponanim, to->client.m_iId, 2, 1 );
@ -1583,8 +1527,6 @@ be ignored
void _DLLEXPORT HUD_PostRunCmd( local_state_t *from, local_state_t *to, struct usercmd_s *cmd, int runfuncs, double time, unsigned int random_seed ) void _DLLEXPORT HUD_PostRunCmd( local_state_t *from, local_state_t *to, struct usercmd_s *cmd, int runfuncs, double time, unsigned int random_seed )
{ {
g_runfuncs = runfuncs; g_runfuncs = runfuncs;
//g_curstate = from;
//#if defined( CLIENT_WEAPONS ) //#if defined( CLIENT_WEAPONS )
/*if ( cl_lw && cl_lw->value ) /*if ( cl_lw && cl_lw->value )
{ {