Improve weapon and bmodels support

This commit is contained in:
mittorn 2016-03-25 20:24:38 +00:00
parent e8a8fd4930
commit d548085f7c
5 changed files with 54 additions and 25 deletions

View File

@ -380,7 +380,10 @@ CBaseEntity *CGrav::GetCrossEnt( Vector gunpos, Vector aim )
continue;
if( pEdict == m_pPlayer->edict() )
continue;
vecLOS = pEdict->v.absmin + ( pEdict->v.size * 0.5 ) - gunpos;
Vector origin = pEdict->v.origin;
//if( pEdict->v.solid == SOLID_BSP || pEdict->v.movetype == MOVETYPE_PUSHSTEP )
origin = VecBModelOrigin(&pEdict->v);
vecLOS = origin - gunpos;
vecLOS = UTIL_ClampVectorToBox(vecLOS, pEdict->v.size * 0.5);
flDot = DotProduct(vecLOS, aim);
@ -456,16 +459,19 @@ CBaseEntity* CGrav::TraceForward(CBaseEntity *pMe,float radius)
void CGrav::GrabThink()
{
//CBaseEntity *ent = FindEntityForward4(m_pPlayer, 130);
if (( m_iGrabFailures < 50 )&& m_hAimentEntity && !m_hAimentEntity->pev->deadflag)
if (( m_iGrabFailures < 50 )&& m_hAimentEntity )
{
if( ( m_hAimentEntity->pev->origin - m_pPlayer->pev->origin).Length() > 150 )
Vector origin = m_hAimentEntity->pev->origin;
if( m_hAimentEntity->IsBSPModel() )
origin = VecBModelOrigin(m_hAimentEntity->pev );
if( ( origin - m_pPlayer->pev->origin).Length() > 150 )
m_iGrabFailures++;
else
m_iGrabFailures = 0;
UpdateEffect(pev->origin, m_hAimentEntity->pev->origin, 1);
UpdateEffect(pev->origin, origin, 1);
Pull(m_hAimentEntity, 100);
@ -489,6 +495,9 @@ void CGrav::GrabThink()
}
void CGrav::Pull(CBaseEntity* ent,float force)
{
Vector origin = ent->pev->origin;
if( ent->IsBSPModel())
origin = VecBModelOrigin(ent->pev);
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
ent->pev->angles.x = UTIL_AngleMod(ent->pev->angles.x);
ent->pev->angles.y = UTIL_AngleMod(ent->pev->angles.y);
@ -496,7 +505,7 @@ void CGrav::Pull(CBaseEntity* ent,float force)
Vector target = m_pPlayer->pev->origin + gpGlobals->v_forward * 75;
target.z += 32;
if ((target - VecBModelOrigin(ent->pev)).Length() > 60){
if ((target - origin).Length() > 60){
target = m_pPlayer->pev->origin + gpGlobals->v_forward * 110 ;
target.z += 60;
@ -507,9 +516,9 @@ void CGrav::Pull(CBaseEntity* ent,float force)
if( !m_iStage )
{
ent->pev->velocity = (target - VecBModelOrigin( ent->pev )).Normalize()*300;
ent->pev->velocity = (target - origin).Normalize()*300;
pev->velocity.z += 10;
if( (target - VecBModelOrigin( ent->pev )).Length() < 150 )
if( (target - origin).Length() < 150 )
{
m_iStage = 1;
SetThink( &CGrav::GrabThink );
@ -519,7 +528,7 @@ void CGrav::Pull(CBaseEntity* ent,float force)
}
else
{
ent->pev->velocity = (target - VecBModelOrigin(ent->pev)).Normalize()*550;
ent->pev->velocity = (target - origin).Normalize()*550;
pev->velocity.z += 15;
}
ent->pev->velocity = ent->pev->velocity + m_pPlayer->pev->velocity;
@ -542,9 +551,9 @@ void CGrav::Pull(CBaseEntity* ent,float force)
}
else if( ent->TouchGravGun(m_pPlayer, 2) )
{
ent->pev->velocity = (target - VecBModelOrigin(ent->pev))* 40;
ent->pev->velocity = (target - origin)* 40;
if(ent->pev->velocity.Length()>900)
ent->pev->velocity = (target - VecBModelOrigin(ent->pev)).Normalize() * 900;
ent->pev->velocity = (target - origin).Normalize() * 900;
ent->pev->velocity = ent->pev->velocity + m_pPlayer->pev->velocity;
m_iStage = 2;
SetThink( &CGrav::GrabThink );

View File

@ -92,7 +92,7 @@ void CItem::Spawn( void )
pev->movetype = MOVETYPE_TOSS;
pev->solid = SOLID_TRIGGER;
UTIL_SetOrigin( pev, pev->origin );
m_SpawnPoint = pev->origin;
m_SpawnPoint = Vector( 0, 0, 0 );
UTIL_SetSize(pev, Vector(-16, -16, 0), Vector(16, 16, 16));
SetTouch( &ItemTouch);
@ -160,7 +160,8 @@ CBaseEntity* CItem::Respawn( void )
float CItem::TouchGravGun( CBaseEntity *attacker, int stage)
{
if( stage == 2 )
Touch(attacker);
if( (attacker->pev->origin - pev->origin ).Length() < 90 )
Touch( attacker );
if( pev->movetype == MOVETYPE_FOLLOW )
return 0;
if( pev->movetype == MOVETYPE_NONE )
@ -181,10 +182,14 @@ void CItem::Materialize( void )
EMIT_SOUND_DYN( ENT(pev), CHAN_WEAPON, "items/suitchargeok1.wav", 1, ATTN_NORM, 0, 150 );
pev->effects &= ~EF_NODRAW;
pev->effects |= EF_MUZZLEFLASH;
if( m_SpawnPoint == Vector( 0, 0, 0 ) )
m_SpawnPoint = pev->origin;
}
else
else if( m_SpawnPoint != Vector( 0, 0, 0 ) )
UTIL_SetOrigin( pev, m_SpawnPoint );// blip to whereever you should respawn.
DROP_TO_FLOOR(ENT(pev));
SetTouch( &ItemTouch );
}

View File

@ -97,10 +97,12 @@ public:
virtual float TouchGravGun( CBaseEntity *attacker, int stage )
{
float speed = 2500;
if( pev->deadflag )
return 0;
if(stage)
{
pev->nextthink = gpGlobals->time + m_flRespawnTime;
SetThink( &CProp::RespawnThink);
SetThink( &CProp::RespawnThink );
}
if( stage == 2 )
{

View File

@ -476,7 +476,6 @@ void CBasePlayerItem :: FallInit( void )
pev->solid = SOLID_BBOX;
UTIL_SetOrigin( pev, pev->origin );
m_SpawnPoint = pev->origin;
UTIL_SetSize(pev, Vector( 0, 0, 0), Vector(0, 0, 0) );//pointsize until it lands on the ground.
SetTouch( &DefaultTouch );
@ -528,8 +527,10 @@ void CBasePlayerItem::Materialize( void )
}
pev->solid = SOLID_TRIGGER;
UTIL_SetOrigin( pev, pev->origin );// link into world.
if( m_SpawnPoint != Vector(0, 0, 0) )
UTIL_SetOrigin( pev, m_SpawnPoint );// link into world.
else
UTIL_SetOrigin( pev, m_SpawnPoint = pev->origin );
SetTouch( &DefaultTouch);
SetThink( NULL );
@ -1067,7 +1068,7 @@ void CBasePlayerAmmo::Spawn( void )
pev->solid = SOLID_TRIGGER;
UTIL_SetSize(pev, Vector(-16, -16, 0), Vector(16, 16, 16));
UTIL_SetOrigin( pev, pev->origin );
m_SpawnPoint = pev->origin;
m_SpawnPoint = Vector( 0, 0, 0 );
SetTouch( &DefaultTouch );
}
@ -1094,7 +1095,10 @@ void CBasePlayerAmmo::Materialize( void )
pev->effects &= ~EF_NODRAW;
pev->effects |= EF_MUZZLEFLASH;
}
if( m_SpawnPoint != Vector(0, 0, 0) )
UTIL_SetOrigin( pev, m_SpawnPoint );// link into world.
else
UTIL_SetOrigin( pev, m_SpawnPoint = pev->origin );
SetTouch( &DefaultTouch );
}
@ -1238,7 +1242,7 @@ void CWeaponBox::Spawn( void )
pev->movetype = MOVETYPE_TOSS;
pev->solid = SOLID_TRIGGER;
UTIL_SetSize( pev, g_vecZero, g_vecZero );
UTIL_SetSize( pev, Vector(-16,-16,-32), Vector(16,16,32) );
SET_MODEL( ENT(pev), "models/w_weaponbox.mdl");
}

View File

@ -285,12 +285,13 @@ public:
// int m_iIdPrimary; // Unique Id for primary ammo
// int m_iIdSecondary; // Unique Id for secondary ammo
Vector m_SpawnPoint;
Vector m_SpawnPoint = Vector( 0, 0, 0 );
virtual float TouchGravGun( CBaseEntity *attacker, int stage)
{
if( stage == 2 )
{
Touch( attacker );
if( (attacker->pev->origin - pev->origin ).Length() < 90 )
Touch( attacker );
}
if( pev->movetype == MOVETYPE_FOLLOW )
return 0;
@ -391,7 +392,8 @@ public:
{
if( stage == 2 )
{
Touch( attacker );
if( (attacker->pev->origin - pev->origin ).Length() < 90 )
Touch( attacker );
}
if( pev->movetype == MOVETYPE_FOLLOW )
return 0;
@ -496,9 +498,16 @@ public:
int m_cAmmoTypes;// how many ammo types packed into this box (if packed by a level designer)
virtual float TouchGravGun( CBaseEntity *attacker, int stage)
{
pev->framerate = 1;
pev->movetype = MOVETYPE_TOSS;
pev->gravity = 1;
if( pev->velocity.z > 20 )
pev->velocity.z = 20;
if( stage == 2 )
{
Touch( attacker );
if( (attacker->pev->origin - pev->origin ).Length() < 90 )
Touch( attacker );
return 0;
}
return 200;