sp/src/game/server/lab/weapon_custom_flaregun.cpp
void CFlareGunProjectile::FlareGunProjectileTouch(CBaseEntity *pOther)
{
	Assert(pOther);
	if (!pOther->IsSolid())
		return;

	if ((m_nBounces < 10) && (GetWaterLevel() < 1))
	{
		// Throw some real chunks here
		g_pEffects->Sparks(GetAbsOrigin());
	}

	//If the flare hit a person or NPC, do damage here.
	if (pOther && pOther->m_takedamage)
	{
		Vector vecNewVelocity = GetAbsVelocity();
		vecNewVelocity *= 0.1f;
		SetAbsVelocity(vecNewVelocity);
		SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE);
		SetGravity(1.0f);
		Die(0.5);
		IgniteOtherIfAllowed(pOther);
		m_nBounces++;
		return;
	}
	else
	{
		// hit the world, check the material type here, see if the flare should stick.
		trace_t tr;
		tr = CBaseEntity::GetTouchTrace();

		//Only do this on the first bounce
		if (m_nBounces == 0)
		{
			const surfacedata_t *pdata = physprops->GetSurfaceData(tr.surface.surfaceProps);

			if (pdata != NULL)
			{
				//Only embed into concrete and wood (jdw: too obscure for players?)
				//if ( ( pdata->gameMaterial == 'C' ) || ( pdata->gameMaterial == 'W' ) )
				{
					Vector	impactDir = (tr.endpos - tr.startpos);
					VectorNormalize(impactDir);

					float	surfDot = tr.plane.normal.Dot(impactDir);

					//Do not stick to ceilings or on shallow impacts
					if ((tr.plane.normal.z > -0.5f) && (surfDot < -0.9f))
					{
						RemoveSolidFlags(FSOLID_NOT_SOLID);
						AddSolidFlags(FSOLID_TRIGGER);
						UTIL_SetOrigin(this, tr.endpos + (tr.plane.normal * 2.0f));
						SetAbsVelocity(vec3_origin);
						SetMoveType(MOVETYPE_NONE);

						SetTouch(&CFlareGunProjectile::FlareGunProjectileBurnTouch);

						int index = decalsystem->GetDecalIndexForName("SmallScorch");
						if (index >= 0)
						{
							CBroadcastRecipientFilter filter;
							te->Decal(filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX(tr.m_pEnt), tr.hitbox, index);
						}

						CPASAttenuationFilter filter2(this, "Flare.Touch");
						EmitSound(filter2, entindex(), "Flare.Touch");

						return;
					}
				}
			}
		}

		//Scorch decal
		if (GetAbsVelocity().LengthSqr() > (250 * 250))
		{
			int index = decalsystem->GetDecalIndexForName("FadingScorch");
			if (index >= 0)
			{
				CBroadcastRecipientFilter filter;
				te->Decal(filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX(tr.m_pEnt), tr.hitbox, index);
			}
		}

		// Change our flight characteristics
		SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE);
		SetGravity(UTIL_ScaleForGravity(640));

		m_nBounces++;

		//After the first bounce, smacking into whoever fired the flare is fair game
		SetOwnerEntity(this);

		// Slow down
		Vector vecNewVelocity = GetAbsVelocity();
		vecNewVelocity.x *= 0.8f;
		vecNewVelocity.y *= 0.8f;
		SetAbsVelocity(vecNewVelocity);

		//Stopped?
		if (GetAbsVelocity().Length() < flaregun_stop_velocity.GetFloat())
		{
			RemoveSolidFlags(FSOLID_NOT_SOLID);
			AddSolidFlags(FSOLID_TRIGGER);
			SetAbsVelocity(vec3_origin);
			SetMoveType(MOVETYPE_NONE);
			SetTouch(&CFlareGunProjectile::FlareGunProjectileBurnTouch);
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Touch function for flaregun projectiles
// Input  : *pOther - The entity that the flare has collided with
//-----------------------------------------------------------------------------
Touch function for flaregun projectiles
Input  : *pOther - The entity that the flare has collided with
Touch function for flaregun projectiles Input : * pOther - The entity that the flare has collided with
void CFlareGunProjectile::FlareGunProjectileTouch(CBaseEntity *pOther)
{
	Assert(pOther);
	if (!pOther->IsSolid())
		return;
	if ((m_nBounces < 10) && (GetWaterLevel() < 1))
	{
		g_pEffects->Sparks(GetAbsOrigin());
	}
	if (pOther && pOther->m_takedamage)
	{
		Vector vecNewVelocity = GetAbsVelocity();
		vecNewVelocity *= 0.1f;
		SetAbsVelocity(vecNewVelocity);
		SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE);
		SetGravity(1.0f);
		Die(0.5);
		IgniteOtherIfAllowed(pOther);
		m_nBounces++;
		return;
	}
	else
	{
		trace_t tr;
		tr = CBaseEntity::GetTouchTrace();
		if (m_nBounces == 0)
		{
			const surfacedata_t *pdata = physprops->GetSurfaceData(tr.surface.surfaceProps);
			if (pdata != NULL)
			{
				{
					Vector	impactDir = (tr.endpos - tr.startpos);
					VectorNormalize(impactDir);
					float	surfDot = tr.plane.normal.Dot(impactDir);
					if ((tr.plane.normal.z > -0.5f) && (surfDot < -0.9f))
					{
						RemoveSolidFlags(FSOLID_NOT_SOLID);
						AddSolidFlags(FSOLID_TRIGGER);
						UTIL_SetOrigin(this, tr.endpos + (tr.plane.normal * 2.0f));
						SetAbsVelocity(vec3_origin);
						SetMoveType(MOVETYPE_NONE);
						SetTouch(&CFlareGunProjectile::FlareGunProjectileBurnTouch);
						int index = decalsystem->GetDecalIndexForName("SmallScorch");
						if (index >= 0)
						{
							CBroadcastRecipientFilter filter;
							te->Decal(filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX(tr.m_pEnt), tr.hitbox, index);
						}
						CPASAttenuationFilter filter2(this, "Flare.Touch");
						EmitSound(filter2, entindex(), "Flare.Touch");
						return;
					}
				}
			}
		}
		if (GetAbsVelocity().LengthSqr() > (250 * 250))
		{
			int index = decalsystem->GetDecalIndexForName("FadingScorch");
			if (index >= 0)
			{
				CBroadcastRecipientFilter filter;
				te->Decal(filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX(tr.m_pEnt), tr.hitbox, index);
			}
		}
		SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE);
		SetGravity(UTIL_ScaleForGravity(640));
		m_nBounces++;
		SetOwnerEntity(this);
		Vector vecNewVelocity = GetAbsVelocity();
		vecNewVelocity.x *= 0.8f;
		vecNewVelocity.y *= 0.8f;
		SetAbsVelocity(vecNewVelocity);
		if (GetAbsVelocity().Length() < flaregun_stop_velocity.GetFloat())
		{
			RemoveSolidFlags(FSOLID_NOT_SOLID);
			AddSolidFlags(FSOLID_TRIGGER);
			SetAbsVelocity(vec3_origin);
			SetMoveType(MOVETYPE_NONE);
			SetTouch(&CFlareGunProjectile::FlareGunProjectileBurnTouch);
		}
	}
}
void CFlareGunProjectile :: FlareGunProjectileTouch ( CBaseEntity * pOther ) { Assert ( pOther ) ; if ( ! pOther -> IsSolid ( ) ) return ; if ( ( m_nBounces < 10 ) && ( GetWaterLevel ( ) < 1 ) ) { g_pEffects -> Sparks ( GetAbsOrigin ( ) ) ; } if ( pOther && pOther -> m_takedamage ) { Vector vecNewVelocity = GetAbsVelocity ( ) ; vecNewVelocity *= 0.1f ; SetAbsVelocity ( vecNewVelocity ) ; SetMoveType ( MOVETYPE_FLYGRAVITY , MOVECOLLIDE_FLY_BOUNCE ) ; SetGravity ( 1.0f ) ; Die ( 0.5 ) ; IgniteOtherIfAllowed ( pOther ) ; m_nBounces ++ ; return ; } else { trace_t tr ; tr = CBaseEntity :: GetTouchTrace ( ) ; if ( m_nBounces == 0 ) { const surfacedata_t * pdata = physprops -> GetSurfaceData ( tr . surface . surfaceProps ) ; if ( pdata != NULL ) { { Vector impactDir = ( tr . endpos - tr . startpos ) ; VectorNormalize ( impactDir ) ; float surfDot = tr . plane . normal . Dot ( impactDir ) ; if ( ( tr . plane . normal . z > -0.5f ) && ( surfDot < -0.9f ) ) { RemoveSolidFlags ( FSOLID_NOT_SOLID ) ; AddSolidFlags ( FSOLID_TRIGGER ) ; UTIL_SetOrigin ( this , tr . endpos + ( tr . plane . normal * 2.0f ) ) ; SetAbsVelocity ( vec3_origin ) ; SetMoveType ( MOVETYPE_NONE ) ; SetTouch ( & CFlareGunProjectile :: FlareGunProjectileBurnTouch ) ; int index = decalsystem -> GetDecalIndexForName ( " " ) ; if ( index >= 0 ) { CBroadcastRecipientFilter filter ; te -> Decal ( filter , 0.0 , & tr . endpos , & tr . startpos , ENTINDEX ( tr . m_pEnt ) , tr . hitbox , index ) ; } CPASAttenuationFilter filter2 ( this , " " ) ; EmitSound ( filter2 , entindex ( ) , " " ) ; return ; } } } } if ( GetAbsVelocity ( ) . LengthSqr ( ) > ( 250 * 250 ) ) { int index = decalsystem -> GetDecalIndexForName ( " " ) ; if ( index >= 0 ) { CBroadcastRecipientFilter filter ; te -> Decal ( filter , 0.0 , & tr . endpos , & tr . startpos , ENTINDEX ( tr . m_pEnt ) , tr . hitbox , index ) ; } } SetMoveType ( MOVETYPE_FLYGRAVITY , MOVECOLLIDE_FLY_BOUNCE ) ; SetGravity ( UTIL_ScaleForGravity ( 640 ) ) ; m_nBounces ++ ; SetOwnerEntity ( this ) ; Vector vecNewVelocity = GetAbsVelocity ( ) ; vecNewVelocity . x *= 0.8f ; vecNewVelocity . y *= 0.8f ; SetAbsVelocity ( vecNewVelocity ) ; if ( GetAbsVelocity ( ) . Length ( ) < flaregun_stop_velocity . GetFloat ( ) ) { RemoveSolidFlags ( FSOLID_NOT_SOLID ) ; AddSolidFlags ( FSOLID_TRIGGER ) ; SetAbsVelocity ( vec3_origin ) ; SetMoveType ( MOVETYPE_NONE ) ; SetTouch ( & CFlareGunProjectile :: FlareGunProjectileBurnTouch ) ; } } }
Purpose: Touch function for flaregun projectiles
Input  : *pOther - The entity that the flare has collided with
Purpose : Touch function for flaregun projectiles Input : * pOther - The entity that the flare has collided with
// Throw some real chunks here //If the flare hit a person or NPC, do damage here. // hit the world, check the material type here, see if the flare should stick. //Only do this on the first bounce //Only embed into concrete and wood (jdw: too obscure for players?) //if ( ( pdata->gameMaterial == 'C' ) || ( pdata->gameMaterial == 'W' ) ) //Do not stick to ceilings or on shallow impacts //Scorch decal // Change our flight characteristics //After the first bounce, smacking into whoever fired the flare is fair game // Slow down //Stopped?