Browse Source

Refactor again, change push mechanizm

foolsday
mittorn 9 years ago
parent
commit
7e37c5449b
  1. 6
      dlls/basemonster.h
  2. 4
      dlls/cbase.h
  3. 4
      dlls/func_break.h
  4. 144
      dlls/gravgun.cpp
  5. 4
      dlls/player.h
  6. 28
      dlls/prop.cpp
  7. 4
      dlls/weapons.h

6
dlls/basemonster.h

@ -330,9 +330,11 @@ public: @@ -330,9 +330,11 @@ public:
BOOL ExitScriptedSequence( );
BOOL CineCleanup( );
virtual bool TouchGravGun( CBaseEntity *attacker, int stage )
virtual float TouchGravGun( CBaseEntity *attacker, int stage )
{
return true;
if( (pev->maxs - pev->mins).Length() > 200 )
return 0;
return 200;
}
CBaseEntity* DropItem ( char *pszItemName, const Vector &vecPos, const Vector &vecAng );// drop an item.

4
dlls/cbase.h

@ -211,9 +211,9 @@ public: @@ -211,9 +211,9 @@ public:
if (m_pfnUse)
(this->*m_pfnUse)( pActivator, pCaller, useType, value );
}
virtual void Blocked( CBaseEntity *pOther ) { if (m_pfnBlocked) (this->*m_pfnBlocked)( pOther ); };
virtual void Blocked( CBaseEntity *pOther ) { if (m_pfnBlocked) (this->*m_pfnBlocked)( pOther ); }
virtual bool TouchGravGun( CBaseEntity *attacker, int stage ){ return false; };
virtual float TouchGravGun( CBaseEntity *attacker, int stage ){ return 0; }
// allow engine to allocate instance data
void *operator new( size_t stAllocateBlock, entvars_t *pev )
{

4
dlls/func_break.h

@ -69,9 +69,9 @@ public: @@ -69,9 +69,9 @@ public:
float m_angle;
int m_iszGibModel;
int m_iszSpawnObject;
bool TouchGravGun( CBaseEntity *attacker, int stage )
virtual float TouchGravGun( CBaseEntity *attacker, int stage )
{
return true;
return 200;
}
};

144
dlls/gravgun.cpp

@ -53,9 +53,9 @@ public: @@ -53,9 +53,9 @@ public:
BOOL Deploy(void);
void Holster(int skiplocal = 0);
int m_iGrabFailures = 0;
CBaseEntity* m_AimentEntity = NULL;
EHANDLE m_hAimentEntity;
void UpdateEffect(const Vector &startPoint, const Vector &endPoint, float timeBlend);
CBaseEntity * FindEntityForward4(CBaseEntity *pMe, float radius);
CBaseEntity * TraceForward(CBaseEntity *pMe, float radius);
void CreateEffect(void);
void DestroyEffect(void);
void EndAttack(void);
@ -66,6 +66,7 @@ public: @@ -66,6 +66,7 @@ public:
void WeaponIdle(void);
void Pull(CBaseEntity* ent, float force);
void GravAnim(int iAnim, int skiplocal, int body);
CBaseEntity *GetCrossEnt( Vector gunpos, Vector aim );
float m_flNextGravgunAttack = gpGlobals->time;
float m_flAmmoUseTime;// since we use < 1 point of ammo per update, we subtract ammo on a timer.
@ -87,15 +88,12 @@ public: @@ -87,15 +88,12 @@ public:
return false;
}
unsigned short m_usEgonStop;
private:
float m_shootTime;
GRAV_FIREMODE m_fireMode;
float m_shakeTime;
BOOL m_deployed;
unsigned short m_usEgonFire;
float m_fPushSpeed;
};
LINK_ENTITY_TO_CLASS(weapon_gravgun, CGrav);
@ -160,8 +158,8 @@ void CGrav::Holster(int skiplocal /* = 0 */) @@ -160,8 +158,8 @@ void CGrav::Holster(int skiplocal /* = 0 */)
{
SetThink(NULL);
if (m_AimentEntity) { m_AimentEntity->pev->velocity = Vector(0, 0, 0); }
m_AimentEntity = NULL;
if (m_hAimentEntity) { m_hAimentEntity->pev->velocity = Vector(0, 0, 0); }
m_hAimentEntity = NULL;
EndAttack();
m_iStage = 0;
m_flNextGravgunAttack = gpGlobals->time + 0.5;
@ -200,7 +198,6 @@ BOOL CGrav::HasAmmo(void) @@ -200,7 +198,6 @@ BOOL CGrav::HasAmmo(void)
void CGrav::Attack(void)
{
if (m_AimentEntity) { m_AimentEntity = NULL; m_iStage = 0; }
pev->nextthink = gpGlobals->time + 1.1;
m_flNextGravgunAttack - gpGlobals->time + 0.5;
@ -238,37 +235,46 @@ void CGrav::Attack(void) @@ -238,37 +235,46 @@ void CGrav::Attack(void)
}
CBaseEntity* crosent;
crosent = FindEntityForward4(m_pPlayer, 1000);
//CBaseEntity* crosent = TraceForward(m_pPlayer, 1000);
CBaseEntity* crossent = m_hAimentEntity;
m_hAimentEntity = NULL;
if( !crossent)
crossent = GetCrossEnt(vecSrc, gpGlobals->v_forward);
//int oc = 0;
if (crosent) {
if (crossent) {
m_flNextGravgunAttack = gpGlobals->time + 0.8;
//oc = crosent->ObjectCaps();
//int propc = (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE;
if( !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3) ) )
{
crossent = TraceForward(m_pPlayer, 1000);
if( !crossent || !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3)) )
{
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_FAILRUN, 0.6, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
crossent = NULL;
}
}
if (crosent->TouchGravGun(m_pPlayer,3)) {
if(crossent) {
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_STARTUP, 1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
//if (crosent->pev->flags& FL_ONGROUND) { pev->velocity = pev->velocity * 0.95; };
crosent->TouchGravGun(m_pPlayer,3);
crossent->TouchGravGun(m_pPlayer,3);
Vector pusher = vecAiming;
pusher.x = pusher.x * 2500;
pusher.y = pusher.y * 2500;
pusher.z = pusher.z * 1700;
crosent->pev->velocity = pusher+m_pPlayer->pev->velocity;
crosent->pev->avelocity.y = pev->avelocity.y*3.5 + RANDOM_FLOAT(100, -100);
crosent->pev->avelocity.x = pev->avelocity.x*3.5 + RANDOM_FLOAT(100, -100);
crosent->pev->avelocity.z = pev->avelocity.z + 3;
pusher.x = pusher.x * m_fPushSpeed;
pusher.y = pusher.y * m_fPushSpeed;
pusher.z = pusher.z * m_fPushSpeed * 0.7;
crossent->pev->velocity = pusher+m_pPlayer->pev->velocity;
crossent->pev->avelocity.y = pev->avelocity.y*3.5 + RANDOM_FLOAT(100, -100);
crossent->pev->avelocity.x = pev->avelocity.x*3.5 + RANDOM_FLOAT(100, -100);
crossent->pev->avelocity.z = pev->avelocity.z + 3;
}
else {
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_FAILRUN, 0.6, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
}
}
if (gpGlobals->time >= m_flNextGravgunAttack)
{
@ -330,31 +336,67 @@ void CGrav::Attack2(void) @@ -330,31 +336,67 @@ void CGrav::Attack2(void)
pev->fuser1 = 1000;
}
CBaseEntity* crossent = FindEntityForward4(m_pPlayer,500);
if (crossent && crossent->TouchGravGun(m_pPlayer, 0) ){
//CBaseEntity* crossent = TraceForward(m_pPlayer,500);
CBaseEntity* crossent = GetCrossEnt(vecSrc, gpGlobals->v_forward);
if( !crossent || !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3)) )
{
crossent = TraceForward(m_pPlayer, 1000);
if( !crossent || !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3)) )
{
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_FAILRUN, 0.6, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
crossent = NULL;
}
}
if ( crossent ){
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_RUN, 0.6, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
if(crossent->TouchGravGun(m_pPlayer, 0))
{
m_AimentEntity = crossent;
m_hAimentEntity = crossent;
Pull(crossent,5);
GravAnim(GAUSS_SPIN, 0, 0);
}
}
else {
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_FAILRUN, 1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
}
}
break;
}
}
CBaseEntity *CGrav::GetCrossEnt( Vector gunpos, Vector aim )
{
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
edict_t *pClosest = NULL;
Vector vecLOS;
float flMaxDot = 0.4;
float flDot;
if ( !pEdict )
return NULL;
for ( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
{
if ( pEdict->free ) // Not in use
continue;
if( pEdict == m_pPlayer->edict() )
continue;
vecLOS = pEdict->v.absmin + ( pEdict->v.size * 0.5 ) - gunpos;
vecLOS = UTIL_ClampVectorToBox(vecLOS, pEdict->v.size * 0.5);
flDot = DotProduct(vecLOS, aim);
if (flDot > flMaxDot)
{
pClosest = pEdict;
flMaxDot = flDot;
}
}
return GET_PRIVATE(pClosest);
}
CBaseEntity* CGrav::FindEntityForward4(CBaseEntity *pMe,float radius)
CBaseEntity* CGrav::TraceForward(CBaseEntity *pMe,float radius)
{
#ifdef USEGUN
@ -367,7 +409,7 @@ CBaseEntity* CGrav::FindEntityForward4(CBaseEntity *pMe,float radius) @@ -367,7 +409,7 @@ CBaseEntity* CGrav::FindEntityForward4(CBaseEntity *pMe,float radius)
float flMaxDot = 0.4;
float flDot;
UTIL_MakeVectors(m_pPlayer->pev->v_angle);// so we know which way we are facing
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);// so we know which way we are facing
while ((pObject = UTIL_FindEntityInSphere(pObject, m_pPlayer->pev->origin, radius)) != NULL)
{//pObject->ObjectCaps() & (FCAP_ACROSS_TRANSITION | FCAP_CONTINUOUS_USE )&&
@ -416,16 +458,16 @@ void CGrav::GrabThink() @@ -416,16 +458,16 @@ void CGrav::GrabThink()
//CBaseEntity *ent = FindEntityForward4(m_pPlayer, 130);
if (( m_iGrabFailures < 50 )&& m_AimentEntity && !m_AimentEntity->pev->deadflag)
if (( m_iGrabFailures < 50 )&& m_hAimentEntity && !m_hAimentEntity->pev->deadflag)
{
if( ( m_AimentEntity->pev->origin - m_pPlayer->pev->origin).Length() > 150 )
if( ( m_hAimentEntity->pev->origin - m_pPlayer->pev->origin).Length() > 150 )
m_iGrabFailures++;
else
m_iGrabFailures = 0;
UpdateEffect(pev->origin, m_AimentEntity->pev->origin, 1);
UpdateEffect(pev->origin, m_hAimentEntity->pev->origin, 1);
Pull(m_AimentEntity, 100);
Pull(m_hAimentEntity, 100);
pev->nextthink = gpGlobals->time + 0.001;
}
@ -433,10 +475,10 @@ void CGrav::GrabThink() @@ -433,10 +475,10 @@ void CGrav::GrabThink()
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_OFF, 1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
m_iGrabFailures = 0;
SetThink(NULL);
if(m_AimentEntity)
if(m_hAimentEntity)
{
m_AimentEntity->pev->velocity = Vector(0,0,0);
m_AimentEntity = NULL;
m_hAimentEntity->pev->velocity = Vector(0,0,0);
m_hAimentEntity = NULL;
}
EndAttack();
m_iStage = 0;
@ -500,16 +542,6 @@ void CGrav::Pull(CBaseEntity* ent,float force) @@ -500,16 +542,6 @@ void CGrav::Pull(CBaseEntity* ent,float force)
}
else
{
Vector atarget = UTIL_VecToAngles(gpGlobals->v_forward);
atarget.x = UTIL_AngleMod(atarget.x);
atarget.y = UTIL_AngleMod(atarget.y);
atarget.z = UTIL_AngleMod(atarget.z);
ent->pev->avelocity.x = UTIL_AngleDiff(atarget.x, ent->pev->angles.x) * 10;
ent->pev->avelocity.y = UTIL_AngleDiff(atarget.y, ent->pev->angles.y) * 10;
ent->pev->avelocity.z = UTIL_AngleDiff(atarget.z, ent->pev->angles.z) * 10;
ent->pev->velocity = (target - VecBModelOrigin(ent->pev))* 40;
if(ent->pev->velocity.Length()>900)
ent->pev->velocity = (target - VecBModelOrigin(ent->pev)).Normalize() * 900;
@ -554,14 +586,14 @@ void CGrav::SecondaryAttack(void) @@ -554,14 +586,14 @@ void CGrav::SecondaryAttack(void)
}
EndAttack();
SetThink(NULL);
m_flNextGravgunAttack = gpGlobals->time + 1.5;
m_flNextGravgunAttack = gpGlobals->time + 0.6;
//m_flTimeWeaponIdle = gpGlobals->time + 0.1;
m_iStage = 0;
if( m_AimentEntity )
if( m_hAimentEntity )
{
m_AimentEntity->pev->velocity = Vector(0,0,0);
m_AimentEntity = NULL;
m_hAimentEntity->pev->velocity = Vector(0,0,0);
m_hAimentEntity = NULL;
}
}
else {

4
dlls/player.h

@ -309,6 +309,10 @@ public: @@ -309,6 +309,10 @@ public:
char m_SbarString1[ SBAR_STRING_SIZE ];
float m_flNextChatTime;
virtual float TouchGravGun( CBaseEntity *attacker, int stage )
{
return 700;
}
};

28
dlls/prop.cpp

@ -94,28 +94,44 @@ public: @@ -94,28 +94,44 @@ public:
virtual void BounceSound(void);
virtual int BloodColor(void) { return DONT_BLEED; }
virtual void Killed(entvars_t *pevAttacker, int iGib);
virtual bool TouchGravGun( CBaseEntity *attacker, int stage )
virtual float TouchGravGun( CBaseEntity *attacker, int stage )
{
float speed = 2500;
if(stage)
{
pev->nextthink = gpGlobals->time + m_flRespawnTime;
SetThink( &CProp::RespawnThink);
}
if( stage == 2 )
{
UTIL_MakeVectors( attacker->pev->v_angle + attacker->pev->punchangle);
Vector atarget = UTIL_VecToAngles(gpGlobals->v_forward);
pev->angles.x = UTIL_AngleMod(pev->angles.x);
pev->angles.y = UTIL_AngleMod(pev->angles.y);
pev->angles.z = UTIL_AngleMod(pev->angles.z);
atarget.x = UTIL_AngleMod(atarget.x);
atarget.y = UTIL_AngleMod(atarget.y);
atarget.z = UTIL_AngleMod(atarget.z);
pev->avelocity.x = UTIL_AngleDiff(atarget.x, pev->angles.x) * 10;
pev->avelocity.y = UTIL_AngleDiff(atarget.y, pev->angles.y) * 10;
pev->avelocity.z = UTIL_AngleDiff(atarget.z, pev->angles.z) * 10;
}
if( !m_attacker)
{
m_owner2 = attacker;
m_attacker = attacker;
return true;
return speed;
}
if( m_attacker && ( pev->velocity.Length() < 600) )
m_attacker = attacker;
return true;
return speed;
if( ( stage == 2 ) && ( m_attacker == attacker ) )
{
m_owner2 = attacker;
return true;
return speed;
}
return false;
return 0;
}
void CheckRotate();
void EXPORT RespawnThink();
@ -813,7 +829,7 @@ void CProp::BounceTouch(CBaseEntity *pOther) @@ -813,7 +829,7 @@ void CProp::BounceTouch(CBaseEntity *pOther)
}
m_flNextAttack = gpGlobals->time + 1.0; // debounce
}
if( (pOther != m_owner2) && (pev->spawnflags & SF_PROP_BREAKABLE) && (pev->velocity.Length() > 900) )
if( (pOther != m_owner2) && (pev->spawnflags & SF_PROP_BREAKABLE) && (pev->velocity.Length() > 1800) )
{
pev->nextthink = gpGlobals->time + 0.1;
SetThink( &CProp::DieThink );

4
dlls/weapons.h

@ -51,10 +51,10 @@ public: @@ -51,10 +51,10 @@ public:
virtual void BounceSound( void );
virtual int BloodColor( void ) { return DONT_BLEED; }
virtual void Killed( entvars_t *pevAttacker, int iGib );
virtual bool TouchGravGun( CBaseEntity *attacker, int stage )
virtual float TouchGravGun( CBaseEntity *attacker, int stage )
{
pev->owner = attacker->edict();
return true;
return 200;
}
BOOL m_fRegisteredSound;// whether or not this grenade has issued its DANGER sound to the world sound list yet.

Loading…
Cancel
Save