Browse Source

Bouncing items and weapons

hlzbot-dirty
mittorn 8 years ago
parent
commit
b64ad02deb
  1. 48
      dlls/items.cpp
  2. 1
      dlls/items.h
  3. 17
      dlls/prop.cpp
  4. 121
      dlls/weapons.cpp
  5. 8
      dlls/weapons.h

48
dlls/items.cpp

@ -90,6 +90,8 @@ void CItem::Spawn( void )
{ {
pev->movetype = MOVETYPE_TOSS; pev->movetype = MOVETYPE_TOSS;
pev->solid = SOLID_TRIGGER; pev->solid = SOLID_TRIGGER;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity = Vector( 0, 0, 0 );
UTIL_SetOrigin( pev, pev->origin ); UTIL_SetOrigin( pev, pev->origin );
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) ); UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) );
SetTouch( &CItem::ItemTouch ); SetTouch( &CItem::ItemTouch );
@ -101,15 +103,31 @@ void CItem::Spawn( void )
return; return;
} }
m_SpawnPoint = pev->origin; m_SpawnPoint = pev->origin;
m_SpawnAngles = pev->angles;
} }
extern int gEvilImpulse101; extern int gEvilImpulse101;
void CItem::ItemTouch( CBaseEntity *pOther ) void CItem::ItemTouch( CBaseEntity *pOther )
{ {
pev->velocity = ( pev->velocity + pOther->pev->velocity) / 2;
pev->avelocity = pev->avelocity / 3;
// if it's not a player, ignore // if it's not a player, ignore
if( !pOther->IsPlayer() ) if( !pOther->IsPlayer() )
{ {
if( pev->velocity.Length() < 5 )
pev->velocity = Vector( 0, 0 ,0 );
SetThink( &CItem::Materialize );
pev->nextthink = g_pGameRules->FlItemRespawnTime( this );
if( ( pOther->pev->solid == SOLID_BSP || pOther->entindex() == 0 ) && pev->movetype == MOVETYPE_BOUNCE && pev->velocity.Length() )
switch( RANDOM_LONG( 0, 2 ) )
{
case 0:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete1.wav", 0.15, ATTN_NORM );break;
case 1:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete2.wav", 0.15, ATTN_NORM );break;
case 2:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete3.wav", 0.15, ATTN_NORM );break;
}
else if( !( pev->flags & FL_ONGROUND ) || !( (pOther->pev->solid == SOLID_BSP) || (pOther->entindex() <= 1) ) )
pev->movetype = MOVETYPE_TOSS;
return; return;
} }
@ -142,6 +160,11 @@ void CItem::ItemTouch( CBaseEntity *pOther )
{ {
UTIL_Remove( this ); UTIL_Remove( this );
} }
else
{
pev->movetype = MOVETYPE_TOSS;
pev->velocity = Vector( 0 ,0 ,0 );
}
} }
CBaseEntity* CItem::Respawn( void ) CBaseEntity* CItem::Respawn( void )
@ -169,13 +192,30 @@ float CItem::TouchGravGun( CBaseEntity *attacker, int stage)
return 0; return 0;
//if( pev->mins == pev->maxs ) //if( pev->mins == pev->maxs )
//return 0; //return 0;
if( stage == 2 )
{
UTIL_MakeVectors( attacker->pev->v_angle + attacker->pev->punchangle);
float atarget = UTIL_VecToAngles(gpGlobals->v_forward).y;
pev->angles.y = UTIL_AngleMod(pev->angles.y);
atarget = UTIL_AngleMod(atarget);
pev->avelocity.y = UTIL_AngleDiff(atarget, pev->angles.y) * 10;
}
if( stage == 3 )
{
pev->avelocity.y = pev->avelocity.y*1.5 + RANDOM_FLOAT(100, -100);
}
SetThink( &CItem::Materialize ); SetThink( &CItem::Materialize );
pev->nextthink = g_pGameRules->FlItemRespawnTime( this ); pev->nextthink = g_pGameRules->FlItemRespawnTime( this );
return 200; pev->movetype = MOVETYPE_BOUNCE;
return 400;
} }
void CItem::Materialize( void ) void CItem::Materialize( void )
{ {
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity = Vector( 0, 0, 0 );
pev->movetype = MOVETYPE_TOSS;
if( pev->effects & EF_NODRAW ) if( pev->effects & EF_NODRAW )
{ {
// changing from invisible state to visible. // changing from invisible state to visible.
@ -183,10 +223,16 @@ void CItem::Materialize( void )
pev->effects &= ~EF_NODRAW; pev->effects &= ~EF_NODRAW;
pev->effects |= EF_MUZZLEFLASH; pev->effects |= EF_MUZZLEFLASH;
if( m_SpawnPoint == Vector( 0, 0, 0 ) ) if( m_SpawnPoint == Vector( 0, 0, 0 ) )
{
m_SpawnPoint = pev->origin; m_SpawnPoint = pev->origin;
m_SpawnAngles = pev->angles;
}
} }
if( m_SpawnPoint != Vector( 0, 0, 0 ) ) if( m_SpawnPoint != Vector( 0, 0, 0 ) )
{
pev->angles = m_SpawnAngles;
UTIL_SetOrigin( pev, m_SpawnPoint );// blip to whereever you should respawn. UTIL_SetOrigin( pev, m_SpawnPoint );// blip to whereever you should respawn.
}
SetTouch( &CItem::ItemTouch ); SetTouch( &CItem::ItemTouch );
} }

1
dlls/items.h

@ -28,5 +28,6 @@ public:
}; };
virtual float TouchGravGun( CBaseEntity *attacker, int stage); virtual float TouchGravGun( CBaseEntity *attacker, int stage);
Vector m_SpawnPoint; Vector m_SpawnPoint;
Vector m_SpawnAngles;
}; };
#endif // ITEMS_H #endif // ITEMS_H

17
dlls/prop.cpp

@ -264,12 +264,11 @@ const char **CProp::MaterialSoundList( Materials precacheMaterial, int &soundCou
case matCinderBlock: case matCinderBlock:
case matRocks: case matRocks:
case matCeilingTile:
pSoundList = pSoundsConcrete; pSoundList = pSoundsConcrete;
soundCount = ARRAYSIZE(pSoundsConcrete); soundCount = ARRAYSIZE(pSoundsConcrete);
break; break;
case matCeilingTile:
case matNone: case matNone:
default: default:
soundCount = 0; soundCount = 0;
@ -310,6 +309,8 @@ void CProp::Precache( void )
if( !pev->model ) if( !pev->model )
pev->model = MAKE_STRING( "models/xash/barrel_brown.mdl" ); pev->model = MAKE_STRING( "models/xash/barrel_brown.mdl" );
if( m_Material == matGlass && !(pev->spawnflags & SF_PROP_BREAKABLE) )
m_Material = matWood;
switch (m_Material) switch (m_Material)
{ {
case matWood: case matWood:
@ -438,7 +439,10 @@ void CProp::DamageSound( void )
case matCeilingTile: case matCeilingTile:
// UNDONE: no ceiling tile shard sound yet // UNDONE: no ceiling tile shard sound yet
i = 0; rgpsz[0] = "debris/concrete1.wav";
rgpsz[1] = "debris/concrete2.wav";
rgpsz[2] = "debris/concrete3.wav";
i = 3;
break; break;
} }
@ -928,12 +932,7 @@ void CProp::BounceTouch(CBaseEntity *pOther)
void CProp::BounceSound(void) void CProp::BounceSound(void)
{ {
switch (RANDOM_LONG(0, 2)) MaterialSoundRandom( edict(), m_Material, 0.2 );
{
case 0: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/grenade_hit1.wav", 0.25, ATTN_NORM); break;
case 1: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/grenade_hit2.wav", 0.25, ATTN_NORM); break;
case 2: EMIT_SOUND(ENT(pev), CHAN_VOICE, "weapons/grenade_hit3.wav", 0.25, ATTN_NORM); break;
}
} }
void CProp::Spawn(void) void CProp::Spawn(void)

121
dlls/weapons.cpp

@ -478,8 +478,6 @@ void CBasePlayerItem::FallThink( void )
//========================================================= //=========================================================
void CBasePlayerItem::Materialize( void ) void CBasePlayerItem::Materialize( void )
{ {
ALERT( at_console, "Materialize: %s\n", STRING(pev->classname) );
if( pev->effects & EF_NODRAW ) if( pev->effects & EF_NODRAW )
{ {
// changing from invisible state to visible. // changing from invisible state to visible.
@ -489,10 +487,19 @@ void CBasePlayerItem::Materialize( void )
} }
pev->solid = SOLID_TRIGGER; pev->solid = SOLID_TRIGGER;
pev->movetype = MOVETYPE_TOSS;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity = Vector( 0, 0, 0 );
if( m_SpawnPoint != Vector(0, 0, 0) ) if( m_SpawnPoint != Vector(0, 0, 0) )
{
pev->angles = m_SpawnAngles;
UTIL_SetOrigin( pev, m_SpawnPoint );// link into world. UTIL_SetOrigin( pev, m_SpawnPoint );// link into world.
}
else else
{
m_SpawnAngles = pev->angles;
UTIL_SetOrigin( pev, m_SpawnPoint = pev->origin ); UTIL_SetOrigin( pev, m_SpawnPoint = pev->origin );
}
SetTouch( &CBasePlayerItem::DefaultTouch ); SetTouch( &CBasePlayerItem::DefaultTouch );
SetThink( NULL ); SetThink( NULL );
@ -500,6 +507,8 @@ void CBasePlayerItem::Materialize( void )
float CBasePlayerItem::TouchGravGun( CBaseEntity *attacker, int stage ) float CBasePlayerItem::TouchGravGun( CBaseEntity *attacker, int stage )
{ {
if( m_pfnTouch == &CBasePlayerItem::DefaultTouch )
pev->movetype = MOVETYPE_BOUNCE;
if( stage == 2 ) if( stage == 2 )
{ {
if( (attacker->pev->origin - pev->origin ).Length() < 90 ) if( (attacker->pev->origin - pev->origin ).Length() < 90 )
@ -511,6 +520,19 @@ float CBasePlayerItem::TouchGravGun( CBaseEntity *attacker, int stage )
return 0; return 0;
if( pev->effects & EF_NODRAW ) if( pev->effects & EF_NODRAW )
return 0; return 0;
if( stage == 2 )
{
UTIL_MakeVectors( attacker->pev->v_angle + attacker->pev->punchangle);
float atarget = UTIL_VecToAngles(gpGlobals->v_forward).y;
pev->angles.y = UTIL_AngleMod(pev->angles.y);
atarget = UTIL_AngleMod(atarget);
pev->avelocity.y = UTIL_AngleDiff(atarget, pev->angles.y) * 10;
}
if( stage == 3 )
{
pev->avelocity.y = pev->avelocity.y*1.5 + RANDOM_FLOAT(100, -100);
}
if( m_pfnThink == NULL || m_pfnThink == &CBasePlayerItem::AttemptToMaterialize ) if( m_pfnThink == NULL || m_pfnThink == &CBasePlayerItem::AttemptToMaterialize )
{ {
SetThink( &CBasePlayerItem::AttemptToMaterialize ); SetThink( &CBasePlayerItem::AttemptToMaterialize );
@ -518,7 +540,7 @@ float CBasePlayerItem::TouchGravGun( CBaseEntity *attacker, int stage )
} }
//if( pev->mins == pev->maxs ) //if( pev->mins == pev->maxs )
//return 0; //return 0;
return 200; return 400;
} }
//========================================================= //=========================================================
@ -587,9 +609,31 @@ CBaseEntity* CBasePlayerItem::Respawn( void )
void CBasePlayerItem::DefaultTouch( CBaseEntity *pOther ) void CBasePlayerItem::DefaultTouch( CBaseEntity *pOther )
{ {
pev->velocity = ( pev->velocity + pOther->pev->velocity) / 2;
pev->avelocity = pev->avelocity / 3;
// if it's not a player, ignore // if it's not a player, ignore
if( !pOther->IsPlayer() ) if( !pOther->IsPlayer() )
{
if( pev->velocity.Length() < 5 )
pev->velocity = Vector( 0, 0 ,0 );
if( m_pfnThink == NULL || m_pfnThink == &CBasePlayerItem::AttemptToMaterialize )
{
SetThink( &CBasePlayerItem::AttemptToMaterialize );
pev->nextthink = g_pGameRules->FlWeaponRespawnTime(this);
if( ( pOther->pev->solid == SOLID_BSP || pOther->entindex() == 0 )&& !(pev->flags & FL_ONGROUND) && pev->movetype == MOVETYPE_BOUNCE && pev->velocity.Length() )
switch( RANDOM_LONG( 0, 4 ) )
{
case 0:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/metal4.wav", 0.15, ATTN_NORM );break;
case 1:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/metal1.wav", 0.15, ATTN_NORM );break;
case 2:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "doors/doorstop4.wav", 0.15, ATTN_NORM );break;
case 3:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/metal6.wav", 0.15, ATTN_NORM );break;
case 4:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/metal3.wav", 0.15, ATTN_NORM );break;
}
else if( !( pev->flags & FL_ONGROUND ) || !( (pOther->pev->solid == SOLID_BSP) || (pOther->entindex() <= 1) ) )
pev->movetype = MOVETYPE_TOSS;
}
return; return;
}
CBasePlayer *pPlayer = (CBasePlayer *)pOther; CBasePlayer *pPlayer = (CBasePlayer *)pOther;
@ -608,6 +652,11 @@ void CBasePlayerItem::DefaultTouch( CBaseEntity *pOther )
AttachToPlayer( pPlayer ); AttachToPlayer( pPlayer );
EMIT_SOUND( ENT( pPlayer->pev ), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM ); EMIT_SOUND( ENT( pPlayer->pev ), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM );
} }
else
{
pev->movetype = MOVETYPE_TOSS;
pev->velocity = Vector( 0 ,0 ,0 );
}
SUB_UseTargets( pOther, USE_TOGGLE, 0 ); // UNDONE: when should this happen? SUB_UseTargets( pOther, USE_TOGGLE, 0 ); // UNDONE: when should this happen?
} }
@ -1044,6 +1093,7 @@ void CBasePlayerAmmo::Spawn( void )
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) ); UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 16 ) );
UTIL_SetOrigin( pev, pev->origin ); UTIL_SetOrigin( pev, pev->origin );
m_SpawnPoint = pev->origin; m_SpawnPoint = pev->origin;
m_SpawnAngles = pev->angles;
SetTouch( &CBasePlayerAmmo::DefaultTouch ); SetTouch( &CBasePlayerAmmo::DefaultTouch );
} }
@ -1062,6 +1112,8 @@ CBaseEntity* CBasePlayerAmmo::Respawn( void )
} }
float CBasePlayerAmmo::TouchGravGun( CBaseEntity *attacker, int stage) float CBasePlayerAmmo::TouchGravGun( CBaseEntity *attacker, int stage)
{ {
if( m_pfnTouch == &CBasePlayerAmmo::DefaultTouch )
pev->movetype = MOVETYPE_BOUNCE;
if( stage == 2 ) if( stage == 2 )
{ {
if( (attacker->pev->origin - pev->origin ).Length() < 90 ) if( (attacker->pev->origin - pev->origin ).Length() < 90 )
@ -1073,10 +1125,26 @@ float CBasePlayerAmmo::TouchGravGun( CBaseEntity *attacker, int stage)
return 0; return 0;
if( pev->effects & EF_NODRAW ) if( pev->effects & EF_NODRAW )
return 0; return 0;
//if( pev->mins == pev->maxs )
//return 0; if( stage == 2 )
SetThink( &CBasePlayerAmmo::Materialize ); {
pev->nextthink = g_pGameRules->FlAmmoRespawnTime( this ); UTIL_MakeVectors( attacker->pev->v_angle + attacker->pev->punchangle);
float atarget = UTIL_VecToAngles(gpGlobals->v_forward).y;
pev->angles.y = UTIL_AngleMod(pev->angles.y);
atarget = UTIL_AngleMod(atarget);
pev->avelocity.y = UTIL_AngleDiff(atarget, pev->angles.y) * 10;
}
if( stage == 3 )
{
pev->avelocity.y = pev->avelocity.y*1.5 + RANDOM_FLOAT(100, -100);
}
if( m_pfnThink == NULL || m_pfnThink == &CBasePlayerAmmo::Materialize )
{
SetThink( &CBasePlayerAmmo::Materialize );
pev->nextthink = g_pGameRules->FlAmmoRespawnTime( this );
}
return 200; return 200;
} }
void CBasePlayerAmmo::Materialize( void ) void CBasePlayerAmmo::Materialize( void )
@ -1089,17 +1157,41 @@ void CBasePlayerAmmo::Materialize( void )
pev->effects |= EF_MUZZLEFLASH; pev->effects |= EF_MUZZLEFLASH;
} }
//if( m_SpawnPoint != Vector(0, 0, 0) ) //if( m_SpawnPoint != Vector(0, 0, 0) )
pev->angles = m_SpawnAngles;
UTIL_SetOrigin( pev, m_SpawnPoint );// link into world. UTIL_SetOrigin( pev, m_SpawnPoint );// link into world.
DROP_TO_FLOOR(edict()); DROP_TO_FLOOR(edict());
pev->movetype = MOVETYPE_TOSS;
//else //else
// UTIL_SetOrigin( pev, m_SpawnPoint = pev->origin ); // UTIL_SetOrigin( pev, m_SpawnPoint = pev->origin );
SetTouch( &CBasePlayerAmmo::DefaultTouch ); SetTouch( &CBasePlayerAmmo::DefaultTouch );
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity = Vector( 0, 0, 0 );
} }
void CBasePlayerAmmo::DefaultTouch( CBaseEntity *pOther ) void CBasePlayerAmmo::DefaultTouch( CBaseEntity *pOther )
{ {
pev->velocity = ( pev->velocity + pOther->pev->velocity) / 2;
pev->avelocity = pev->avelocity / 3;
if( !pOther->IsPlayer() ) if( !pOther->IsPlayer() )
{ {
if( pev->velocity.Length() < 5 )
pev->velocity = Vector( 0, 0 ,0 );
if( m_pfnThink == NULL || m_pfnThink == &CBasePlayerAmmo::Materialize )
{
SetThink( &CBasePlayerAmmo::Materialize );
pev->nextthink = g_pGameRules->FlAmmoRespawnTime(this);
if( ( pOther->pev->solid == SOLID_BSP || pOther->entindex() == 0 ) && !(pev->flags & FL_ONGROUND) && pev->movetype == MOVETYPE_BOUNCE && pev->velocity.Length() )
switch( RANDOM_LONG( 0, 2 ) )
{
case 0:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete1.wav", 0.15, ATTN_NORM );break;
case 1:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete2.wav", 0.15, ATTN_NORM );break;
case 2:EMIT_SOUND( ENT( pev ), CHAN_VOICE, "debris/concrete3.wav", 0.15, ATTN_NORM );break;
}
else if( !( pev->flags & FL_ONGROUND ) || !( (pOther->pev->solid == SOLID_BSP) || (pOther->entindex() <= 1) ) )
pev->movetype = MOVETYPE_TOSS;
}
return; return;
} }
@ -1123,6 +1215,11 @@ void CBasePlayerAmmo::DefaultTouch( CBaseEntity *pOther )
SetThink( &CBaseEntity::SUB_Remove ); SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time + .1; pev->nextthink = gpGlobals->time + .1;
} }
else
{
pev->movetype = MOVETYPE_TOSS;
pev->velocity = Vector( 0 ,0 ,0 );
}
} }
//========================================================= //=========================================================
@ -1233,7 +1330,7 @@ void CWeaponBox::Spawn( void )
{ {
Precache(); Precache();
pev->movetype = MOVETYPE_TOSS; pev->movetype = MOVETYPE_BOUNCE;
pev->solid = SOLID_TRIGGER; pev->solid = SOLID_TRIGGER;
UTIL_SetSize( pev, Vector(-16,-16,-32), Vector(16,16,32) ); UTIL_SetSize( pev, Vector(-16,-16,-32), Vector(16,16,32) );
@ -1273,10 +1370,14 @@ void CWeaponBox::Kill( void )
//========================================================= //=========================================================
void CWeaponBox::Touch( CBaseEntity *pOther ) void CWeaponBox::Touch( CBaseEntity *pOther )
{ {
if( !( pev->flags & FL_ONGROUND ) ) /*if( !( pev->flags & FL_ONGROUND ) )
{ {
return; return;
} }*/
pev->velocity = ( pev->velocity + pOther->pev->velocity) / 2;
if( pev->velocity.Length() > 300 )
return;
if( !pOther->IsPlayer() ) if( !pOther->IsPlayer() )
{ {

8
dlls/weapons.h

@ -280,6 +280,7 @@ public:
// int m_iIdPrimary; // Unique Id for primary ammo // int m_iIdPrimary; // Unique Id for primary ammo
// int m_iIdSecondary; // Unique Id for secondary ammo // int m_iIdSecondary; // Unique Id for secondary ammo
Vector m_SpawnPoint; Vector m_SpawnPoint;
Vector m_SpawnAngles;
#ifndef CLIENT_DLL #ifndef CLIENT_DLL
virtual float TouchGravGun( CBaseEntity *attacker, int stage); virtual float TouchGravGun( CBaseEntity *attacker, int stage);
#endif #endif
@ -369,6 +370,7 @@ public:
virtual float TouchGravGun( CBaseEntity *attacker, int stage); virtual float TouchGravGun( CBaseEntity *attacker, int stage);
#endif #endif
Vector m_SpawnPoint; Vector m_SpawnPoint;
Vector m_SpawnAngles;
}; };
extern DLL_GLOBAL short g_sModelIndexLaser;// holds the index for the laser beam extern DLL_GLOBAL short g_sModelIndexLaser;// holds the index for the laser beam
@ -460,17 +462,17 @@ public:
virtual float TouchGravGun( CBaseEntity *attacker, int stage) virtual float TouchGravGun( CBaseEntity *attacker, int stage)
{ {
pev->framerate = 1; pev->framerate = 1;
pev->movetype = MOVETYPE_TOSS; pev->movetype = MOVETYPE_BOUNCE;
pev->gravity = 1; pev->gravity = 1;
if( pev->velocity.z > 20 ) if( pev->velocity.z > 20 )
pev->velocity.z = 20; pev->velocity.z = 20;
if( stage == 2 ) /*if( stage == 2 )
{ {
if( (attacker->pev->origin - pev->origin ).Length() < 90 ) if( (attacker->pev->origin - pev->origin ).Length() < 90 )
Touch( attacker ); Touch( attacker );
return 0; return 0;
} }*/
return 200; return 200;
} }
}; };

Loading…
Cancel
Save