Refactor again, change push mechanizm

This commit is contained in:
mittorn 2016-03-23 19:08:13 +00:00
parent 67b7e91461
commit 7e37c5449b
7 changed files with 127 additions and 73 deletions

View File

@ -330,9 +330,11 @@ public:
BOOL ExitScriptedSequence( ); BOOL ExitScriptedSequence( );
BOOL CineCleanup( ); 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. CBaseEntity* DropItem ( char *pszItemName, const Vector &vecPos, const Vector &vecAng );// drop an item.

View File

@ -211,9 +211,9 @@ public:
if (m_pfnUse) if (m_pfnUse)
(this->*m_pfnUse)( pActivator, pCaller, useType, value ); (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 // allow engine to allocate instance data
void *operator new( size_t stAllocateBlock, entvars_t *pev ) void *operator new( size_t stAllocateBlock, entvars_t *pev )
{ {

View File

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

View File

@ -53,9 +53,9 @@ public:
BOOL Deploy(void); BOOL Deploy(void);
void Holster(int skiplocal = 0); void Holster(int skiplocal = 0);
int m_iGrabFailures = 0; int m_iGrabFailures = 0;
CBaseEntity* m_AimentEntity = NULL; EHANDLE m_hAimentEntity;
void UpdateEffect(const Vector &startPoint, const Vector &endPoint, float timeBlend); 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 CreateEffect(void);
void DestroyEffect(void); void DestroyEffect(void);
void EndAttack(void); void EndAttack(void);
@ -66,6 +66,7 @@ public:
void WeaponIdle(void); void WeaponIdle(void);
void Pull(CBaseEntity* ent, float force); void Pull(CBaseEntity* ent, float force);
void GravAnim(int iAnim, int skiplocal, int body); void GravAnim(int iAnim, int skiplocal, int body);
CBaseEntity *GetCrossEnt( Vector gunpos, Vector aim );
float m_flNextGravgunAttack = gpGlobals->time; float m_flNextGravgunAttack = gpGlobals->time;
float m_flAmmoUseTime;// since we use < 1 point of ammo per update, we subtract ammo on a timer. float m_flAmmoUseTime;// since we use < 1 point of ammo per update, we subtract ammo on a timer.
@ -87,15 +88,12 @@ public:
return false; return false;
} }
unsigned short m_usEgonStop;
private: private:
float m_shootTime; float m_shootTime;
GRAV_FIREMODE m_fireMode; GRAV_FIREMODE m_fireMode;
float m_shakeTime; float m_shakeTime;
BOOL m_deployed; BOOL m_deployed;
float m_fPushSpeed;
unsigned short m_usEgonFire;
}; };
LINK_ENTITY_TO_CLASS(weapon_gravgun, CGrav); LINK_ENTITY_TO_CLASS(weapon_gravgun, CGrav);
@ -160,8 +158,8 @@ void CGrav::Holster(int skiplocal /* = 0 */)
{ {
SetThink(NULL); SetThink(NULL);
if (m_AimentEntity) { m_AimentEntity->pev->velocity = Vector(0, 0, 0); } if (m_hAimentEntity) { m_hAimentEntity->pev->velocity = Vector(0, 0, 0); }
m_AimentEntity = NULL; m_hAimentEntity = NULL;
EndAttack(); EndAttack();
m_iStage = 0; m_iStage = 0;
m_flNextGravgunAttack = gpGlobals->time + 0.5; m_flNextGravgunAttack = gpGlobals->time + 0.5;
@ -200,7 +198,6 @@ BOOL CGrav::HasAmmo(void)
void CGrav::Attack(void) void CGrav::Attack(void)
{ {
if (m_AimentEntity) { m_AimentEntity = NULL; m_iStage = 0; }
pev->nextthink = gpGlobals->time + 1.1; pev->nextthink = gpGlobals->time + 1.1;
m_flNextGravgunAttack - gpGlobals->time + 0.5; m_flNextGravgunAttack - gpGlobals->time + 0.5;
@ -238,37 +235,46 @@ void CGrav::Attack(void)
} }
CBaseEntity* crosent; //CBaseEntity* crosent = TraceForward(m_pPlayer, 1000);
crosent = FindEntityForward4(m_pPlayer, 1000); CBaseEntity* crossent = m_hAimentEntity;
m_hAimentEntity = NULL;
if( !crossent)
crossent = GetCrossEnt(vecSrc, gpGlobals->v_forward);
//int oc = 0; //int oc = 0;
if (crosent) { if (crossent) {
m_flNextGravgunAttack = gpGlobals->time + 0.8; m_flNextGravgunAttack = gpGlobals->time + 0.8;
//oc = crosent->ObjectCaps(); //oc = crosent->ObjectCaps();
//int propc = (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE; //int propc = (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE;
if( !(m_fPushSpeed = crossent->TouchGravGun(m_pPlayer,3) ) )
if (crosent->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_STARTUP, 1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34)); 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; }; //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; Vector pusher = vecAiming;
pusher.x = pusher.x * 2500; pusher.x = pusher.x * m_fPushSpeed;
pusher.y = pusher.y * 2500; pusher.y = pusher.y * m_fPushSpeed;
pusher.z = pusher.z * 1700; pusher.z = pusher.z * m_fPushSpeed * 0.7;
crosent->pev->velocity = pusher+m_pPlayer->pev->velocity; crossent->pev->velocity = pusher+m_pPlayer->pev->velocity;
crosent->pev->avelocity.y = pev->avelocity.y*3.5 + RANDOM_FLOAT(100, -100); crossent->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); crossent->pev->avelocity.x = pev->avelocity.x*3.5 + RANDOM_FLOAT(100, -100);
crosent->pev->avelocity.z = pev->avelocity.z + 3; 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) if (gpGlobals->time >= m_flNextGravgunAttack)
{ {
@ -330,31 +336,67 @@ void CGrav::Attack2(void)
pev->fuser1 = 1000; pev->fuser1 = 1000;
} }
CBaseEntity* crossent = FindEntityForward4(m_pPlayer,500); //CBaseEntity* crossent = TraceForward(m_pPlayer,500);
CBaseEntity* crossent = GetCrossEnt(vecSrc, gpGlobals->v_forward);
if (crossent && crossent->TouchGravGun(m_pPlayer, 0) ){ 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)); 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)) if(crossent->TouchGravGun(m_pPlayer, 0))
{ {
m_AimentEntity = crossent; m_hAimentEntity = crossent;
Pull(crossent,5); Pull(crossent,5);
GravAnim(GAUSS_SPIN, 0, 0); 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; break;
} }
} }
CBaseEntity *CGrav::GetCrossEnt( Vector gunpos, Vector aim )
CBaseEntity* CGrav::FindEntityForward4(CBaseEntity *pMe,float radius) {
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::TraceForward(CBaseEntity *pMe,float radius)
{ {
#ifdef USEGUN #ifdef USEGUN
@ -367,7 +409,7 @@ CBaseEntity* CGrav::FindEntityForward4(CBaseEntity *pMe,float radius)
float flMaxDot = 0.4; float flMaxDot = 0.4;
float flDot; 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) while ((pObject = UTIL_FindEntityInSphere(pObject, m_pPlayer->pev->origin, radius)) != NULL)
{//pObject->ObjectCaps() & (FCAP_ACROSS_TRANSITION | FCAP_CONTINUOUS_USE )&& {//pObject->ObjectCaps() & (FCAP_ACROSS_TRANSITION | FCAP_CONTINUOUS_USE )&&
@ -416,16 +458,16 @@ void CGrav::GrabThink()
//CBaseEntity *ent = FindEntityForward4(m_pPlayer, 130); //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++; m_iGrabFailures++;
else else
m_iGrabFailures = 0; 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; pev->nextthink = gpGlobals->time + 0.001;
} }
@ -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)); EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, GRAV_SOUND_OFF, 1, ATTN_NORM, 0, 70 + RANDOM_LONG(0, 34));
m_iGrabFailures = 0; m_iGrabFailures = 0;
SetThink(NULL); SetThink(NULL);
if(m_AimentEntity) if(m_hAimentEntity)
{ {
m_AimentEntity->pev->velocity = Vector(0,0,0); m_hAimentEntity->pev->velocity = Vector(0,0,0);
m_AimentEntity = NULL; m_hAimentEntity = NULL;
} }
EndAttack(); EndAttack();
m_iStage = 0; m_iStage = 0;
@ -499,17 +541,7 @@ void CGrav::Pull(CBaseEntity* ent,float force)
ALERT(at_console, "%s 2: %f\n", STRING(ent->pev->classname), m_iStage, ent->pev->velocity.Length()); ALERT(at_console, "%s 2: %f\n", STRING(ent->pev->classname), m_iStage, ent->pev->velocity.Length());
} }
else 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; ent->pev->velocity = (target - VecBModelOrigin(ent->pev))* 40;
if(ent->pev->velocity.Length()>900) if(ent->pev->velocity.Length()>900)
ent->pev->velocity = (target - VecBModelOrigin(ent->pev)).Normalize() * 900; ent->pev->velocity = (target - VecBModelOrigin(ent->pev)).Normalize() * 900;
@ -554,14 +586,14 @@ void CGrav::SecondaryAttack(void)
} }
EndAttack(); EndAttack();
SetThink(NULL); SetThink(NULL);
m_flNextGravgunAttack = gpGlobals->time + 1.5; m_flNextGravgunAttack = gpGlobals->time + 0.6;
//m_flTimeWeaponIdle = gpGlobals->time + 0.1; //m_flTimeWeaponIdle = gpGlobals->time + 0.1;
m_iStage = 0; m_iStage = 0;
if( m_AimentEntity ) if( m_hAimentEntity )
{ {
m_AimentEntity->pev->velocity = Vector(0,0,0); m_hAimentEntity->pev->velocity = Vector(0,0,0);
m_AimentEntity = NULL; m_hAimentEntity = NULL;
} }
} }
else { else {

View File

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

View File

@ -94,28 +94,44 @@ public:
virtual void BounceSound(void); virtual void BounceSound(void);
virtual int BloodColor(void) { return DONT_BLEED; } virtual int BloodColor(void) { return DONT_BLEED; }
virtual void Killed(entvars_t *pevAttacker, int iGib); 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) if(stage)
{ {
pev->nextthink = gpGlobals->time + m_flRespawnTime; pev->nextthink = gpGlobals->time + m_flRespawnTime;
SetThink( &CProp::RespawnThink); 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) if( !m_attacker)
{ {
m_owner2 = attacker; m_owner2 = attacker;
m_attacker = attacker; m_attacker = attacker;
return true; return speed;
} }
if( m_attacker && ( pev->velocity.Length() < 600) ) if( m_attacker && ( pev->velocity.Length() < 600) )
m_attacker = attacker; m_attacker = attacker;
return true; return speed;
if( ( stage == 2 ) && ( m_attacker == attacker ) ) if( ( stage == 2 ) && ( m_attacker == attacker ) )
{ {
m_owner2 = attacker; m_owner2 = attacker;
return true;
return speed;
} }
return false; return 0;
} }
void CheckRotate(); void CheckRotate();
void EXPORT RespawnThink(); void EXPORT RespawnThink();
@ -813,7 +829,7 @@ void CProp::BounceTouch(CBaseEntity *pOther)
} }
m_flNextAttack = gpGlobals->time + 1.0; // debounce 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; pev->nextthink = gpGlobals->time + 0.1;
SetThink( &CProp::DieThink ); SetThink( &CProp::DieThink );

View File

@ -51,10 +51,10 @@ public:
virtual void BounceSound( void ); virtual void BounceSound( void );
virtual int BloodColor( void ) { return DONT_BLEED; } virtual int BloodColor( void ) { return DONT_BLEED; }
virtual void Killed( entvars_t *pevAttacker, int iGib ); 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(); 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. BOOL m_fRegisteredSound;// whether or not this grenade has issued its DANGER sound to the world sound list yet.