// // Touch - will hurt others based on how fast the brush is spinning // void CFuncRotating :: HurtTouch ( CBaseEntity *pOther ) { entvars_t *pevOther = pOther->pev; // we can't hurt this thing, so we're not concerned with it if( !pOther->pev->takedamage ) return; // calculate damage based on rotation speed pev->dmg = GetLocalAvelocity().Length() / 10; pOther->TakeDamage( pev, pev, pev->dmg, DMG_CRUSH ); Vector vecNewVelocity = (pOther->GetAbsOrigin() - Center()).Normalize(); pOther->SetAbsVelocity( vecNewVelocity * pev->dmg ); }
void CFuncRotating :: RotateFriction( void ) { // angular impulse support if( GetLocalAvelocity() != g_vecZero ) { m_iState = STATE_ON; SetMoveDoneTime( 0.1 ); RampPitchVol(); } else { STOP_SOUND( edict(), CHAN_STATIC, STRING( pev->noise3 )); SetMoveDoneTime( -1 ); m_iState = STATE_OFF; } }
void CFuncRotating :: Precache( void ) { // set up fan sounds if( !FStringNull( pev->message )) { // if a path is set for a wave, use it pev->noise3 = UTIL_PrecacheSound( STRING( pev->message )); } else { int m_sound = UTIL_LoadSoundPreset( m_sounds ); // otherwise use preset sound switch( m_sound ) { case 1: pev->noise3 = UTIL_PrecacheSound( "fans/fan1.wav" ); break; case 2: pev->noise3 = UTIL_PrecacheSound( "fans/fan2.wav" ); break; case 3: pev->noise3 = UTIL_PrecacheSound( "fans/fan3.wav" ); break; case 4: pev->noise3 = UTIL_PrecacheSound( "fans/fan4.wav" ); break; case 5: pev->noise3 = UTIL_PrecacheSound( "fans/fan5.wav" ); break; case 0: pev->noise3 = UTIL_PrecacheSound( "common/null.wav" ); break; default: pev->noise3 = UTIL_PrecacheSound( m_sound ); break; } } if( GetLocalAvelocity() != g_vecZero && !pev->friction ) { // if fan was spinning, and we went through transition or save/restore, // make sure we restart the sound. 1.5 sec delay is magic number. KDB SetMoveDone( SpinUp ); SetMoveDoneTime( 0.2 ); } }
void CFuncRotating :: RampPitchVol( void ) { // calc volume and pitch as % of maximum vol and pitch. float fpct = fabs( GetLocalAvelocity().Length() ) / m_flMaxSpeed; float fvol = bound( 0.0f, m_flVolume * fpct, 1.0f ); // slowdown volume ramps down to 0 float fpitch = FANPITCHMIN + ( FANPITCHMAX - FANPITCHMIN ) * fpct; int pitch = bound( 0, fpitch, 255 ); if( pitch == PITCH_NORM ) { pitch = PITCH_NORM - 1; } // change the fan's vol and pitch EMIT_SOUND_DYN( edict(), CHAN_STATIC, STRING( pev->noise3 ), fvol, m_flAttenuation, SND_CHANGE_PITCH|SND_CHANGE_VOL, pitch ); }
void CFuncRotating :: Rotate( void ) { // NOTE: only full speed moving set state to "On" if( fabs( pev->speed ) == fabs( m_flMaxSpeed )) m_iState = STATE_ON; SetMoveDoneTime( 0.1f ); if( m_bStopAtStartPos ) { SetMoveDoneTime( GetNextMoveInterval() ); int checkAxis = 2; // see if we got close to the starting orientation if( pev->movedir[0] != 0 ) { checkAxis = 0; } else if( pev->movedir[1] != 0 ) { checkAxis = 1; } float angDelta = anglemod( GetLocalAngles()[checkAxis] - m_angStart[checkAxis] ); if( angDelta > 180.0f ) angDelta -= 360.0f; Vector avel = GetLocalAvelocity(); // delta per tick Vector avelpertick = avel * gpGlobals->frametime; if( fabs( angDelta ) < fabs( avelpertick[checkAxis] )) { SetTargetSpeed( 0 ); SetLocalAngles( m_angStart ); m_bStopAtStartPos = false; } } }
//========================================================= //========================================================= void CFlockingFlyer :: BoidAdvanceFrame ( ) { float flapspeed = (pev->speed - pev->armorvalue) / AFLOCK_ACCELERATE; pev->armorvalue = pev->armorvalue * .8 + pev->speed * .2; if (flapspeed < 0) flapspeed = -flapspeed; if (flapspeed < 0.25) flapspeed = 0.25; if (flapspeed > 1.9) flapspeed = 1.9; pev->framerate = flapspeed; Vector avelocity = GetLocalAvelocity(); // lean avelocity.x = - (GetAbsAngles().x + flapspeed * 5); // bank avelocity.z = - (GetAbsAngles().z + avelocity.y); SetLocalAvelocity( avelocity ); StudioFrameAdvance( 0.1 ); }
void CBaseDoor::Blocked( CBaseEntity *pOther ) { // hurt the blocker a little. if( pev->dmg ) pOther->TakeDamage( pev, pev, pev->dmg, DMG_CRUSH ); // if a door has a negative wait, it would never come back if blocked, // so let it just squash the object to death real fast if( m_flWait >= 0 ) { if( !FBitSet( pev->spawnflags, SF_DOOR_SILENT )) STOP_SOUND( edict(), CHAN_STATIC, STRING( pev->noise1 )); if( m_iState == STATE_TURN_OFF ) { DoorGoUp(); } else { DoorGoDown(); } } // block all door pieces with the same targetname here. if( !FStringNull( pev->targetname )) { CBaseDoor *pDoorList[64]; int doorCount = GetDoorMovementGroup( pDoorList, ARRAYSIZE( pDoorList )); for( int i = 0; i < doorCount; i++ ) { CBaseDoor *pDoor = pDoorList[i]; if( pDoor->m_flWait >= 0) { if( m_bDoorGroup && pDoor->pev->movedir == pev->movedir && pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetLocalAvelocity() == GetLocalAvelocity( )) { pDoor->m_iPhysicsFrame = g_ulFrameCount; // don't run physics this frame if you haven't run yet // this is the most hacked, evil, bastardized thing I've ever seen. kjb if( !pDoor->IsRotatingDoor( )) { // set origin to realign normal doors pDoor->SetLocalOrigin( GetLocalOrigin( )); pDoor->SetAbsVelocity( g_vecZero ); // stop! } else { // set angles to realign rotating doors pDoor->SetLocalAngles( GetLocalAngles( )); pDoor->SetLocalAvelocity( g_vecZero ); } } if( pDoor->m_iState == STATE_TURN_OFF ) pDoor->DoorGoUp(); else pDoor->DoorGoDown(); } } } }
void COsprey :: DyingThink( void ) { StudioFrameAdvance( ); SetNextThink( 0.1 ); Vector angVel = GetLocalAvelocity(); angVel *= 1.02; SetLocalAvelocity( angVel ); // still falling? if (m_startTime > gpGlobals->time ) { UTIL_MakeAimVectors( GetAbsAngles() ); ShowDamage( ); Vector vecSpot = GetAbsOrigin() + GetAbsVelocity() * 0.2; Vector vecVel = GetAbsVelocity(); // random explosions MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_EXPLOSION); // This just makes a dynamic light now WRITE_COORD( vecSpot.x + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.y + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.z + RANDOM_FLOAT( -150, -50 )); WRITE_SHORT( g_sModelIndexFireball ); WRITE_BYTE( RANDOM_LONG(0,29) + 30 ); // scale * 10 WRITE_BYTE( 12 ); // framerate WRITE_BYTE( TE_EXPLFLAG_NONE ); MESSAGE_END(); // lots of smoke MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_SMOKE ); WRITE_COORD( vecSpot.x + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.y + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.z + RANDOM_FLOAT( -150, -50 )); WRITE_SHORT( g_sModelIndexSmoke ); WRITE_BYTE( 100 ); // scale * 10 WRITE_BYTE( 10 ); // framerate MESSAGE_END(); vecSpot = GetAbsOrigin() + (pev->mins + pev->maxs) * 0.5; MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_BREAKMODEL); // position WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z ); // size WRITE_COORD( 800 ); WRITE_COORD( 800 ); WRITE_COORD( 132 ); // velocity WRITE_COORD( vecVel.x ); WRITE_COORD( vecVel.y ); WRITE_COORD( vecVel.z ); // randomization WRITE_BYTE( 50 ); // Model WRITE_SHORT( m_iTailGibs ); //model id# // # of shards WRITE_BYTE( 8 ); // let client decide // duration WRITE_BYTE( 200 );// 10.0 seconds // flags WRITE_BYTE( BREAK_METAL ); MESSAGE_END(); // don't stop it we touch a entity pev->flags &= ~FL_ONGROUND; pev->nextthink = gpGlobals->time + 0.2; return; } else { Vector vecSpot = GetAbsOrigin() + (pev->mins + pev->maxs) * 0.5; /* MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_EXPLOSION); // This just makes a dynamic light now WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 512 ); WRITE_SHORT( m_iExplode ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 10 ); // framerate MESSAGE_END(); */ // gibs MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_SPRITE ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 512 ); WRITE_SHORT( m_iExplode ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 255 ); // brightness MESSAGE_END(); /* MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_SMOKE ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 300 ); WRITE_SHORT( g_sModelIndexSmoke ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 6 ); // framerate MESSAGE_END(); */ Vector vecOrigin = GetAbsOrigin(); // blast circle MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, vecOrigin ); WRITE_BYTE( TE_BEAMCYLINDER ); WRITE_COORD( vecOrigin.x); WRITE_COORD( vecOrigin.y); WRITE_COORD( vecOrigin.z); WRITE_COORD( vecOrigin.x); WRITE_COORD( vecOrigin.y); WRITE_COORD( vecOrigin.z + 2000 ); // reach damage radius over .2 seconds WRITE_SHORT( m_iSpriteTexture ); WRITE_BYTE( 0 ); // startframe WRITE_BYTE( 0 ); // framerate WRITE_BYTE( 4 ); // life WRITE_BYTE( 32 ); // width WRITE_BYTE( 0 ); // noise WRITE_BYTE( 255 ); // r, g, b WRITE_BYTE( 255 ); // r, g, b WRITE_BYTE( 192 ); // r, g, b WRITE_BYTE( 128 ); // brightness WRITE_BYTE( 0 ); // speed MESSAGE_END(); EMIT_SOUND(ENT(pev), CHAN_STATIC, "weapons/mortarhit.wav", 1.0, 0.3); RadiusDamage( vecOrigin, pev, pev, 300, CLASS_NONE, DMG_BLAST ); // gibs vecSpot = vecOrigin + (pev->mins + pev->maxs) * 0.5; MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_BREAKMODEL); // position WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 64); // size WRITE_COORD( 800 ); WRITE_COORD( 800 ); WRITE_COORD( 128 ); // velocity WRITE_COORD( m_velocity.x ); WRITE_COORD( m_velocity.y ); WRITE_COORD( fabs( m_velocity.z ) * 0.25 ); // randomization WRITE_BYTE( 40 ); // Model WRITE_SHORT( m_iBodyGibs ); //model id# // # of shards WRITE_BYTE( 128 ); // duration WRITE_BYTE( 200 );// 10.0 seconds // flags WRITE_BYTE( BREAK_METAL ); MESSAGE_END(); UTIL_Remove( this ); } }
//========================================================= // Leader boids use this think every tenth //========================================================= void CFlockingFlyer :: FlockLeaderThink( void ) { TraceResult tr; Vector vecDist;// used for general measurements Vector vecDir;// used for general measurements int cProcessed = 0;// keep track of how many other boids we've processed float flLeftSide; float flRightSide; pev->nextthink = gpGlobals->time + 0.1; UTIL_MakeVectors ( GetAbsAngles() ); // is the way ahead clear? if ( !FPathBlocked () ) { // if the boid is turning, stop the trend. if ( m_fTurning ) { m_fTurning = FALSE; Vector avelocity = GetLocalAvelocity(); avelocity.y = 0; SetLocalAvelocity( avelocity ); } m_fPathBlocked = FALSE; if (pev->speed <= AFLOCK_FLY_SPEED ) pev->speed+= 5; SetAbsVelocity( gpGlobals->v_forward * pev->speed ); BoidAdvanceFrame( ); return; } // IF we get this far in the function, the leader's path is blocked! m_fPathBlocked = TRUE; if ( !m_fTurning)// something in the way and boid is not already turning to avoid { // measure clearance on left and right to pick the best dir to turn UTIL_TraceLine(GetAbsOrigin(), GetAbsOrigin() + gpGlobals->v_right * AFLOCK_CHECK_DIST, ignore_monsters, ENT(pev), &tr); vecDist = (tr.vecEndPos - GetAbsOrigin()); flRightSide = vecDist.Length(); UTIL_TraceLine(GetAbsOrigin(), GetAbsOrigin() - gpGlobals->v_right * AFLOCK_CHECK_DIST, ignore_monsters, ENT(pev), &tr); vecDist = (tr.vecEndPos - GetAbsOrigin()); flLeftSide = vecDist.Length(); // turn right if more clearance on right side if ( flRightSide > flLeftSide ) { Vector avelocity = GetLocalAvelocity(); avelocity.y = -AFLOCK_TURN_RATE; SetLocalAvelocity( avelocity ); m_fTurning = TRUE; } // default to left turn :) else if ( flLeftSide > flRightSide ) { Vector avelocity = GetLocalAvelocity(); avelocity.y = AFLOCK_TURN_RATE; SetLocalAvelocity( avelocity ); m_fTurning = TRUE; } else { // equidistant. Pick randomly between left and right. m_fTurning = TRUE; if ( RANDOM_LONG( 0, 1 ) == 0 ) { Vector avelocity = GetLocalAvelocity(); avelocity.y = AFLOCK_TURN_RATE; SetLocalAvelocity( avelocity ); } else { Vector avelocity = GetLocalAvelocity(); avelocity.y = -AFLOCK_TURN_RATE; SetLocalAvelocity( avelocity ); } } } SpreadFlock( ); SetAbsVelocity( gpGlobals->v_forward * pev->speed ); // check and make sure we aren't about to plow into the ground, don't let it happen UTIL_TraceLine(GetAbsOrigin(), GetAbsOrigin() - gpGlobals->v_up * 16, ignore_monsters, ENT(pev), &tr); if (tr.flFraction != 1.0 && GetAbsVelocity().z < 0 ) { Vector velocity = GetAbsVelocity(); velocity.z = 0; SetAbsVelocity( velocity ); } // maybe it did, though. if ( FBitSet (pev->flags, FL_ONGROUND) ) { UTIL_SetOrigin (this, GetAbsOrigin() + Vector ( 0 , 0 , 1 ) ); Vector velocity = GetAbsVelocity(); velocity.z = 0; SetAbsVelocity( velocity ); } if ( m_flFlockNextSoundTime < gpGlobals->time ) { MakeSound(); m_flFlockNextSoundTime = gpGlobals->time + RANDOM_FLOAT( 1, 3 ); } BoidAdvanceFrame( ); return; }