//----------------------------------------------------------------------------- // Purpose: Creates the NPC. //----------------------------------------------------------------------------- void CNPCMaker::MakeNPC( void ) { if (!CanMakeNPC()) return; CAI_BaseNPC *pent = (CAI_BaseNPC*)CreateEntityByName( STRING(m_iszNPCClassname) ); if ( !pent ) { Warning("NULL Ent in NPCMaker!\n" ); return; } // ------------------------------------------------ // Intialize spawned NPC's relationships // ------------------------------------------------ pent->SetRelationshipString( m_RelationshipString ); m_OnSpawnNPC.Set( pent, pent, this ); pent->SetAbsOrigin( GetAbsOrigin() ); // Strip pitch and roll from the spawner's angles. Pass only yaw to the spawned NPC. QAngle angles = GetAbsAngles(); angles.x = 0.0; angles.z = 0.0; pent->SetAbsAngles( angles ); pent->AddSpawnFlags( SF_NPC_FALL_TO_GROUND ); if ( m_spawnflags & SF_NPCMAKER_FADE ) { pent->AddSpawnFlags( SF_NPC_FADE_CORPSE ); } pent->m_spawnEquipment = m_spawnEquipment; pent->SetSquadName( m_SquadName ); pent->SetHintGroup( m_strHintGroup ); ChildPreSpawn( pent ); DispatchSpawn( pent ); pent->SetOwnerEntity( this ); DispatchActivate( pent ); if ( m_ChildTargetName != NULL_STRING ) { // if I have a netname (overloaded), give the child NPC that name as a targetname pent->SetName( m_ChildTargetName ); } ChildPostSpawn( pent ); m_nLiveChildren++;// count this NPC if (!(m_spawnflags & SF_NPCMAKER_INF_CHILD)) { m_nMaxNumNPCs--; if ( IsDepleted() ) { m_OnAllSpawned.FireOutput( this, this ); // Disable this forever. Don't kill it because it still gets death notices SetThink( NULL ); SetUse( NULL ); } } }
//--------------------------------------------------------- //--------------------------------------------------------- void CRopeAnchor::RemoveThink() { UTIL_Remove( m_hRope ); SetThink( &CRopeAnchor::SUB_Remove ); SetNextThink( gpGlobals->curtime ); }
void CApache :: DyingThink( void ) { StudioFrameAdvance( ); pev->nextthink = gpGlobals->time + 0.1; pev->avelocity = pev->avelocity * 1.02; // still falling? if (m_flNextRocket > gpGlobals->time ) { // random explosions MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin ); WRITE_BYTE( TE_EXPLOSION); // This just makes a dynamic light now WRITE_COORD( pev->origin.x + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( pev->origin.y + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( pev->origin.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, pev->origin ); WRITE_BYTE( TE_SMOKE ); WRITE_COORD( pev->origin.x + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( pev->origin.y + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( pev->origin.z + RANDOM_FLOAT( -150, -50 )); WRITE_SHORT( g_sModelIndexSmoke ); WRITE_BYTE( 100 ); // scale * 10 WRITE_BYTE( 10 ); // framerate MESSAGE_END(); Vector vecSpot = pev->origin + (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( 400 ); WRITE_COORD( 400 ); WRITE_COORD( 132 ); // velocity WRITE_COORD( pev->velocity.x ); WRITE_COORD( pev->velocity.y ); WRITE_COORD( pev->velocity.z ); // randomization WRITE_BYTE( 50 ); // Model WRITE_SHORT( m_iBodyGibs ); //model id# // # of shards WRITE_BYTE( 4 ); // let client decide // duration WRITE_BYTE( 30 );// 3.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 = pev->origin + (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 + 300 ); WRITE_SHORT( g_sModelIndexFireball ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 8 ); // framerate MESSAGE_END(); */ // fireball MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_SPRITE ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 256 ); WRITE_SHORT( m_iExplode ); WRITE_BYTE( 120 ); // scale * 10 WRITE_BYTE( 255 ); // brightness MESSAGE_END(); // big smoke MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_SMOKE ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 512 ); WRITE_SHORT( g_sModelIndexSmoke ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 5 ); // framerate MESSAGE_END(); // blast circle MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin ); WRITE_BYTE( TE_BEAMCYLINDER ); WRITE_COORD( pev->origin.x); WRITE_COORD( pev->origin.y); WRITE_COORD( pev->origin.z); WRITE_COORD( pev->origin.x); WRITE_COORD( pev->origin.y); WRITE_COORD( pev->origin.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( pev->origin, pev, pev, 300, CLASS_NONE, DMG_BLAST ); if (/*!(pev->spawnflags & SF_NOWRECKAGE) && */(pev->flags & FL_ONGROUND)) { CBaseEntity *pWreckage = Create( "cycler_wreckage", pev->origin, pev->angles ); // SET_MODEL( ENT(pWreckage->pev), STRING(pev->model) ); UTIL_SetSize( pWreckage->pev, Vector( -200, -200, -128 ), Vector( 200, 200, -32 ) ); pWreckage->pev->frame = pev->frame; pWreckage->pev->sequence = pev->sequence; pWreckage->pev->framerate = 0; pWreckage->pev->dmgtime = gpGlobals->time + 5; } // gibs vecSpot = pev->origin + (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 + 64); // size WRITE_COORD( 400 ); WRITE_COORD( 400 ); WRITE_COORD( 128 ); // velocity WRITE_COORD( 0 ); WRITE_COORD( 0 ); WRITE_COORD( 200 ); // randomization WRITE_BYTE( 30 ); // Model WRITE_SHORT( m_iBodyGibs ); //model id# // # of shards WRITE_BYTE( 200 ); // duration WRITE_BYTE( 200 );// 10.0 seconds // flags WRITE_BYTE( BREAK_METAL ); MESSAGE_END(); SetThink( &CApache::SUB_Remove ); pev->nextthink = gpGlobals->time + 0.1; } }
//========================================================= // TryMakeMonster- check that it's ok to drop a monster. //========================================================= void CMonsterMaker::TryMakeMonster( void ) { if ( m_iMaxLiveChildren > 0 && m_cLiveChildren >= m_iMaxLiveChildren ) {// not allowed to make a new one yet. Too many live ones out right now. return; } CBaseEntity* pTemp; if (pev->noise){ // AJH dynamic origin for monstermakers pTemp = UTIL_FindEntityByTargetname(NULL,STRING(pev->noise),this); if (pTemp) { pev->vuser1 = pTemp->pev->origin; // ALERT(at_debug,"DEBUG: Monstermaker setting dynamic position %f %f %f \n", pWhere->pev->origin.x,pWhere->pev->origin.y,pWhere->pev->origin.z); } }else{ pev->vuser1=pev->origin; } if (pev->noise1) { //AJH dynamic offset for monstermaker Vector vTemp =CalcLocus_Position(this, NULL, STRING(pev->noise1)); pev->vuser1 = pev->vuser1 + vTemp; // ALERT(at_debug,"DEBUG: Monstermaker dynamic offset is %f %f %f\n",vTemp.x,vTemp.y,vTemp.z); // ALERT(at_debug,"DEBUG: Monstermaker position now %f %f %f \n", pWhere->pev->origin.x,pWhere->pev->origin.y,pWhere->pev->origin.z); } if (pev->noise2){ // AJH dynamic angles for monstermakers pTemp = UTIL_FindEntityByTargetname(NULL,STRING(pev->noise2),this); if (pTemp) pev->vuser2=pTemp->pev->angles; // ALERT(at_debug,"DEBUG: Monstermaker setting angles to %f %f %f\n",pWhere->pev->angles.x,pWhere->pev->angles.y,pWhere->pev->angles.z); }else{ pev->vuser2=pev->angles; } if (pev->noise3){ // AJH dynamic velocity for monstermakers pTemp = UTIL_FindEntityByTargetname(NULL,STRING(pev->noise3),this); if (pTemp) pev->vuser3 = pTemp->pev->velocity; // ALERT(at_debug,"DEBUG: Monstermaker setting velocity to %f %f %f\n",pWhere->pev->velocity.x,pWhere->pev->velocity.y,pWhere->pev->velocity.z); } // ALERT(at_debug,"DEBUG: Montermaker spawnpoint set to %f, %f, %f\n", pWhere->pev->origin.x,pWhere->pev->origin.y,pWhere->pev->origin.z); if ( !m_flGround ) { // set altitude. Now that I'm activated, any breakables, etc should be out from under me. TraceResult tr; UTIL_TraceLine ( pev->vuser1, pev->vuser1 - Vector ( 0, 0, 2048 ), ignore_monsters, ENT(pev), &tr ); m_flGround = tr.vecEndPos.z; } Vector mins = pev->vuser1 - Vector( 34, 34, 0 ); Vector maxs = pev->vuser1 + Vector( 34, 34, 0 ); maxs.z = pev->vuser1.z; mins.z = m_flGround; CBaseEntity *pList[2]; int count = UTIL_EntitiesInBox( pList, 2, mins, maxs, FL_CLIENT|FL_MONSTER ); if ( !SF_MONSTERMAKER_FORCESPAWN&&count ) { // don't build a stack of monsters! return; } if (m_fSpawnDelay) { // If I have a target, fire. (no locus) if ( !FStringNull ( pev->target ) ) { // delay already overloaded for this entity, so can't call SUB_UseTargets() FireTargets( STRING(pev->target), this, this, USE_TOGGLE, 0 ); } // ALERT(at_console,"Making Monster in %f seconds\n",m_fSpawnDelay); SetThink(&CMonsterMaker:: MakeMonsterThink ); SetNextThink( m_fSpawnDelay ); } else { // ALERT(at_console,"No delay. Making monster.\n",m_fSpawnDelay); CBaseMonster* pMonst = MakeMonster(); // If I have a target, fire! (the new monster is the locus) if ( !FStringNull ( pev->target ) ) { ALERT(at_debug,"DEBUG: Monstermaker fires target %s locus is child\n",STRING(pev->target)); FireTargets( STRING(pev->target), pMonst, this, USE_TOGGLE, 0 ); } } }
//----------------------------------------------------------------------------- // Purpose: Make this rocket lock onto it's target and track it //----------------------------------------------------------------------------- void CGrenadeRocket::LockOnto( CBaseEntity *pTarget ) { m_hLockTarget = pTarget; SetThink( FollowThink ); SetNextThink( gpGlobals->curtime + 0.1f ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CAI_AllyManager::Spawn() { SetThink( &CAI_AllyManager::WatchCounts ); SetNextThink( gpGlobals->curtime + 1.0 ); }
//----------------------------------------------------------------------------- // Purpose: Target doesn't exist or has eluded us, so search for one //----------------------------------------------------------------------------- void CNPC_CeilingTurret::SearchThink( void ) { //Allow descended classes a chance to do something before the think function if ( PreThink( TURRET_SEARCHING ) ) return; SetNextThink( gpGlobals->curtime + 0.05f ); SetActivity( (Activity) ACT_CEILING_TURRET_OPEN_IDLE ); //If our enemy has died, pick a new enemy if ( ( GetEnemy() != NULL ) && ( GetEnemy()->IsAlive() == false ) ) { SetEnemy( NULL ); } //Acquire the target if ( GetEnemy() == NULL ) { GetSenses()->Look( CEILING_TURRET_RANGE ); CBaseEntity *pEnemy = BestEnemy(); if ( pEnemy ) { SetEnemy( pEnemy ); } } //If we've found a target, spin up the barrel and start to attack if ( GetEnemy() != NULL ) { //Give players a grace period if ( GetEnemy()->IsPlayer() ) { m_flShotTime = gpGlobals->curtime + 0.5f; } else { m_flShotTime = gpGlobals->curtime + 0.1f; } m_flLastSight = 0; SetThink( &CNPC_CeilingTurret::ActiveThink ); SetEyeState( TURRET_EYE_SEE_TARGET ); SpinUp(); EmitSound( "NPC_CeilingTurret.Active" ); return; } //Are we out of time and need to retract? if ( gpGlobals->curtime > m_flLastSight ) { //Before we retrace, make sure that we are spun down. m_flLastSight = 0; SetThink( &CNPC_CeilingTurret::Retire ); return; } //Display that we're scanning m_vecGoalAngles.x = 15.0f; m_vecGoalAngles.y = GetAbsAngles().y + ( sin( gpGlobals->curtime * 2.0f ) * 45.0f ); //Turn and ping UpdateFacing(); Ping(); }
//----------------------------------------------------------------------------- // Purpose: Allows the turret to fire on targets if they're visible //----------------------------------------------------------------------------- void CNPC_RocketTurret::FollowThink( void ) { // Default to player as enemy if ( GetEnemy() == NULL ) { SetEnemy( UTIL_GetLocalPlayer() ); } SetSequence ( LookupSequence( "idle" ) ); //Allow descended classes a chance to do something before the think function if ( PreThink() || GetEnemy() == NULL ) { return; } //Update our think time SetNextThink( gpGlobals->curtime + ROCKET_TURRET_THINK_RATE ); UpdateAimPoint(); m_vecGoalAngles = m_vecAnglesToEnemy; // Chase enemy if ( !m_bHasSightOfEnemy ) { // Aim at the last known location m_vecGoalAngles = m_vecCurrentAngles; // Lost sight, move to search think SetThink( &CNPC_RocketTurret::SearchThink ); } //Turn to face UpdateFacing(); // If our facing direction hits our enemy, fire the beam Ray_t rayDmg; Vector vForward; AngleVectors( m_vecCurrentAngles, &vForward, NULL, NULL ); Vector vEndPoint = EyePosition() + vForward*ROCKET_TURRET_RANGE; rayDmg.Init( EyePosition(), vEndPoint ); rayDmg.m_IsRay = true; trace_t traceDmg; // This version reorients through portals CTraceFilterSimple subfilter( this, COLLISION_GROUP_NONE ); CTraceFilterTranslateClones filter ( &subfilter ); float flRequiredParameter = 2.0f; CProp_Portal* pFirstPortal = UTIL_Portal_FirstAlongRay( rayDmg, flRequiredParameter ); UTIL_Portal_TraceRay_Bullets( pFirstPortal, rayDmg, MASK_VISIBLE_AND_NPCS, &filter, &traceDmg, false ); if ( traceDmg.m_pEnt ) { // This thing we're hurting is our enemy if ( traceDmg.m_pEnt == GetEnemy() ) { // If we're past the cooldown time, fire another rocket if ( (gpGlobals->curtime - m_flTimeLastFired) > ROCKET_TURRET_ROCKET_FIRE_COOLDOWN_TIME ) { SetThink( &CNPC_RocketTurret::LockingThink ); } } } }
void CTripmineGrenade :: PowerupThink( void ) { TraceResult tr; if (m_hOwner == NULL) { // find an owner edict_t *oldowner = pev->owner; pev->owner = NULL; UTIL_TraceLine( pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 32, dont_ignore_monsters, ENT( pev ), &tr ); if (tr.fStartSolid || (oldowner && tr.pHit == oldowner)) { pev->owner = oldowner; m_flPowerUp += 0.1; pev->nextthink = gpGlobals->time + 0.1; return; } if (tr.flFraction < 1.0) { pev->owner = tr.pHit; m_hOwner = CBaseEntity::Instance( pev->owner ); m_posOwner = m_hOwner->pev->origin; m_angleOwner = m_hOwner->pev->angles; } else { STOP_SOUND( ENT(pev), CHAN_VOICE, "weapons/mine_deploy.wav" ); STOP_SOUND( ENT(pev), CHAN_BODY, "weapons/mine_charge.wav" ); SetThink(&CTripmineGrenade::SUB_Remove ); pev->nextthink = gpGlobals->time + 0.1; ALERT( at_console, "WARNING:Tripmine at %.0f, %.0f, %.0f removed\n", pev->origin.x, pev->origin.y, pev->origin.z ); KillBeam(); return; } } else if (m_posOwner != m_hOwner->pev->origin || m_angleOwner != m_hOwner->pev->angles) { // disable STOP_SOUND( ENT(pev), CHAN_VOICE, "weapons/mine_deploy.wav" ); STOP_SOUND( ENT(pev), CHAN_BODY, "weapons/mine_charge.wav" ); CBaseEntity *pMine = Create( "weapon_tripmine", pev->origin + m_vecDir * 24, pev->angles ); pMine->pev->spawnflags |= SF_NORESPAWN; SetThink( &CTripmineGrenade::SUB_Remove ); KillBeam(); pev->nextthink = gpGlobals->time + 0.1; return; } // ALERT( at_console, "%d %.0f %.0f %0.f\n", pev->owner, m_pOwner->pev->origin.x, m_pOwner->pev->origin.y, m_pOwner->pev->origin.z ); if (gpGlobals->time > m_flPowerUp) { // make solid pev->solid = SOLID_BBOX; UTIL_SetOrigin( pev, pev->origin ); MakeBeam( ); // play enabled sound EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "weapons/mine_activate.wav", 0.5, ATTN_NORM, 1.0, 75 ); } pev->nextthink = gpGlobals->time + 0.1; }
//========================================================= //========================================================= void CHornet::Spawn(void) { Precache(); pev->movetype = MOVETYPE_FLY; pev->solid = SOLID_BBOX; pev->takedamage = DAMAGE_YES; pev->flags |= FL_MONSTER; pev->health = 1;// weak! if (g_pGameRules->IsMultiplayer()) { // hornets don't live as long in multiplayer m_flStopAttack = gpGlobals->time + 3.5; } else { m_flStopAttack = gpGlobals->time + 5.0; } m_flFieldOfView = 0.9; // +- 25 degrees if (RANDOM_LONG(1, 5) <= 2) { m_iHornetType = HORNET_TYPE_RED; m_flFlySpeed = HORNET_RED_SPEED; } else { m_iHornetType = HORNET_TYPE_ORANGE; m_flFlySpeed = HORNET_ORANGE_SPEED; } SET_MODEL(ENT(pev), "models/hornet.mdl"); UTIL_SetSize(pev, Vector(-4, -4, -4), Vector(4, 4, 4)); SetTouch(&CHornet::DieTouch); SetThink(&CHornet::StartTrack); edict_t *pSoundEnt = pev->owner; if (!pSoundEnt) pSoundEnt = edict(); switch (RANDOM_LONG(0, 2)) { case 0: EMIT_SOUND(pSoundEnt, CHAN_WEAPON, "agrunt/ag_fire1.wav", 1, ATTN_NORM); break; case 1: EMIT_SOUND(pSoundEnt, CHAN_WEAPON, "agrunt/ag_fire2.wav", 1, ATTN_NORM); break; case 2: EMIT_SOUND(pSoundEnt, CHAN_WEAPON, "agrunt/ag_fire3.wav", 1, ATTN_NORM); break; } if (!FNullEnt(pev->owner) && (pev->owner->v.flags & FL_CLIENT)) { pev->dmg = gSkillData.plrDmgHornet; } else { // no real owner, or owner isn't a client. pev->dmg = gSkillData.monDmgHornet; } SetNextThink(0.1); ResetSequenceInfo(); }
//----------------------------------------------------------------------------- // Purpose: Explode and set death think //----------------------------------------------------------------------------- void CNPC_RocketTurret::Destroy( void ) { SetThink( &CNPC_RocketTurret::DyingThink ); SetNextThink( gpGlobals->curtime + 0.1f ); }
//========================================================= // Hornet is flying, gently tracking target //========================================================= void CHornet::TrackTarget(void) { Vector vecFlightDir; Vector vecDirToEnemy; float flDelta; StudioFrameAdvance(); if (gpGlobals->time > m_flStopAttack) { SetTouch(NULL); SetThink(&CHornet::SUB_Remove); SetNextThink(0.1); return; } // UNDONE: The player pointer should come back after returning from another level if (m_hEnemy == NULL) {// enemy is dead. Look(512); m_hEnemy = BestVisibleEnemy(); } if (m_hEnemy != NULL && FVisible(m_hEnemy)) { m_vecEnemyLKP = m_hEnemy->BodyTarget(pev->origin); } else { m_vecEnemyLKP = m_vecEnemyLKP + pev->velocity * m_flFlySpeed * 0.1; } vecDirToEnemy = (m_vecEnemyLKP - pev->origin).Normalize(); if (pev->velocity.Length() < 0.1) vecFlightDir = vecDirToEnemy; else vecFlightDir = pev->velocity.Normalize(); // measure how far the turn is, the wider the turn, the slow we'll go this time. flDelta = DotProduct(vecFlightDir, vecDirToEnemy); if (flDelta < 0.5) {// hafta turn wide again. play sound switch (RANDOM_LONG(0, 2)) { case 0: EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 1: EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 2: EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; } } if (flDelta <= 0 && m_iHornetType == HORNET_TYPE_RED) {// no flying backwards, but we don't want to invert this, cause we'd go fast when we have to turn REAL far. flDelta = 0.25; } pev->velocity = (vecFlightDir + vecDirToEnemy).Normalize(); if (pev->owner && (pev->owner->v.flags & FL_MONSTER)) { // random pattern only applies to hornets fired by monsters, not players. pev->velocity.x += RANDOM_FLOAT(-0.10, 0.10);// scramble the flight dir a bit. pev->velocity.y += RANDOM_FLOAT(-0.10, 0.10); pev->velocity.z += RANDOM_FLOAT(-0.10, 0.10); } switch (m_iHornetType) { case HORNET_TYPE_RED: pev->velocity = pev->velocity * (m_flFlySpeed * flDelta);// scale the dir by the ( speed * width of turn ) SetNextThink(RANDOM_FLOAT(0.1, 0.3)); break; case HORNET_TYPE_ORANGE: pev->velocity = pev->velocity * m_flFlySpeed;// do not have to slow down to turn. SetNextThink(0.1);// fixed think time break; } pev->angles = UTIL_VecToAngles(pev->velocity); pev->solid = SOLID_BBOX; // if hornet is close to the enemy, jet in a straight line for a half second. // (only in the single player game) if (m_hEnemy != NULL && !g_pGameRules->IsMultiplayer()) { if (flDelta >= 0.4 && (pev->origin - m_vecEnemyLKP).Length() <= 300) { MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, pev->origin); WRITE_BYTE(TE_SPRITE); WRITE_COORD(pev->origin.x); // pos WRITE_COORD(pev->origin.y); WRITE_COORD(pev->origin.z); WRITE_SHORT(iHornetPuff); // model // WRITE_BYTE( 0 ); // life * 10 WRITE_BYTE(2); // size * 10 WRITE_BYTE(128); // brightness MESSAGE_END(); switch (RANDOM_LONG(0, 2)) { case 0: EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 1: EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; case 2: EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM); break; } pev->velocity = pev->velocity * 2; SetNextThink(1.0); // don't attack again m_flStopAttack = gpGlobals->time; } } }
//----------------------------------------------------------------------------- // Purpose: Breaks the breakable. m_hBreaker is the entity that caused us to break. //----------------------------------------------------------------------------- void CBreakable::Die( void ) { Vector vecVelocity;// shard velocity char cFlag = 0; int pitch; float fvol; pitch = 95 + random->RandomInt(0,29); if (pitch > 97 && pitch < 103) { pitch = 100; } // The more negative m_iHealth, the louder // the sound should be. fvol = random->RandomFloat(0.85, 1.0) + (abs(m_iHealth) / 100.0); if (fvol > 1.0) { fvol = 1.0; } const char *soundname = NULL; switch (m_Material) { default: break; case matGlass: soundname = "Breakable.Glass"; cFlag = BREAK_GLASS; break; case matWood: soundname = "Breakable.Crate"; cFlag = BREAK_WOOD; break; case matComputer: soundname = "Breakable.Computer"; cFlag = BREAK_METAL; break; case matMetal: soundname = "Breakable.Metal"; cFlag = BREAK_METAL; break; case matFlesh: case matWeb: soundname = "Breakable.Flesh"; cFlag = BREAK_FLESH; break; case matRocks: case matCinderBlock: soundname = "Breakable.Concrete"; cFlag = BREAK_CONCRETE; break; case matCeilingTile: soundname = "Breakable.Ceiling"; break; } if ( soundname ) { if ( m_hBreaker && m_hBreaker->IsPlayer() ) { IGameEvent * event = gameeventmanager->CreateEvent( "break_breakable" ); if ( event ) { event->SetInt( "userid", ToBasePlayer( m_hBreaker )->GetUserID() ); event->SetInt( "entindex", entindex() ); event->SetInt( "material", cFlag ); gameeventmanager->FireEvent( event ); } } CSoundParameters params; if ( GetParametersForSound( soundname, params, NULL ) ) { CPASAttenuationFilter filter( this ); EmitSound_t ep; ep.m_nChannel = params.channel; ep.m_pSoundName = params.soundname; ep.m_flVolume = fvol; ep.m_SoundLevel = params.soundlevel; ep.m_nPitch = pitch; EmitSound( filter, entindex(), ep ); } } switch( m_Explosion ) { case expDirected: vecVelocity = g_vecAttackDir * -200; break; case expUsePrecise: { AngleVectors( m_GibDir, &vecVelocity, NULL, NULL ); vecVelocity *= 200; } break; case expRandom: vecVelocity.x = 0; vecVelocity.y = 0; vecVelocity.z = 0; break; default: DevMsg("**ERROR - Unspecified gib dir method in func_breakable!\n"); break; } Vector vecSpot = WorldSpaceCenter(); CPVSFilter filter2( vecSpot ); int iModelIndex = 0; CCollisionProperty *pCollisionProp = CollisionProp(); Vector vSize = pCollisionProp->OBBSize(); int iCount = ( vSize[0] * vSize[1] + vSize[1] * vSize[2] + vSize[2] * vSize[0] ) / ( 3 * 12 * 12 ); if ( iCount > func_break_max_pieces.GetInt() ) { iCount = func_break_max_pieces.GetInt(); } ConVarRef breakable_disable_gib_limit( "breakable_disable_gib_limit" ); if ( !breakable_disable_gib_limit.GetBool() && iCount ) { if ( m_PerformanceMode == PM_NO_GIBS ) { iCount = 0; } else if ( m_PerformanceMode == PM_REDUCED_GIBS ) { int iNewCount = iCount * func_break_reduction_factor.GetFloat(); iCount = max( iNewCount, 1 ); } } if ( m_iszModelName != NULL_STRING ) { for ( int i = 0; i < iCount; i++ ) { #ifdef HL1_DLL // Use the passed model instead of the propdata type const char *modelName = STRING( m_iszModelName ); // if the map specifies a model by name if( strstr( modelName, ".mdl" ) != NULL ) { iModelIndex = modelinfo->GetModelIndex( modelName ); } else // do the hl2 / normal way #endif iModelIndex = modelinfo->GetModelIndex( g_PropDataSystem.GetRandomChunkModel( STRING( m_iszModelName ) ) ); // All objects except the first one in this run are marked as slaves... int slaveFlag = 0; if ( i != 0 ) { slaveFlag = BREAK_SLAVE; } te->BreakModel( filter2, 0.0, vecSpot, pCollisionProp->GetCollisionAngles(), vSize, vecVelocity, iModelIndex, 100, 1, 2.5, cFlag | slaveFlag ); } } ResetOnGroundFlags(); // Don't fire something that could fire myself SetName( NULL_STRING ); AddSolidFlags( FSOLID_NOT_SOLID ); // Fire targets on break m_OnBreak.FireOutput( m_hBreaker, this ); VPhysicsDestroyObject(); SetThink( &CBreakable::SUB_Remove ); SetNextThink( gpGlobals->curtime + 0.1f ); if ( m_iszSpawnObject != NULL_STRING ) { CBaseEntity::Create( STRING(m_iszSpawnObject), vecSpot, pCollisionProp->GetCollisionAngles(), this ); } if ( Explodable() ) { ExplosionCreate( vecSpot, pCollisionProp->GetCollisionAngles(), this, GetExplosiveDamage(), GetExplosiveRadius(), true ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTemplateNPCMaker::MakeNPC( void ) { // If we should be using the radius spawn method instead, do so if ( m_flRadius && HasSpawnFlags(SF_NPCMAKER_ALWAYSUSERADIUS) ) { MakeNPCInRadius(); return; } if (!CanMakeNPC( ( m_iszDestinationGroup != NULL_STRING ) )) return; CNPCSpawnDestination *pDestination = NULL; if ( m_iszDestinationGroup != NULL_STRING ) { pDestination = FindSpawnDestination(); if ( !pDestination ) { DevMsg( 2, "%s '%s' failed to find a valid spawnpoint in destination group: '%s'\n", GetClassname(), STRING(GetEntityName()), STRING(m_iszDestinationGroup) ); return; } } CAI_BaseNPC *pent = NULL; CBaseEntity *pEntity = NULL; MapEntity_ParseEntity( pEntity, STRING(m_iszTemplateData), NULL ); if ( pEntity != NULL ) { pent = (CAI_BaseNPC *)pEntity; } if ( !pent ) { Warning("NULL Ent in NPCMaker!\n" ); return; } if ( pDestination ) { pent->SetAbsOrigin( pDestination->GetAbsOrigin() ); // Strip pitch and roll from the spawner's angles. Pass only yaw to the spawned NPC. QAngle angles = pDestination->GetAbsAngles(); angles.x = 0.0; angles.z = 0.0; pent->SetAbsAngles( angles ); pDestination->OnSpawnedNPC( pent ); } else { pent->SetAbsOrigin( GetAbsOrigin() ); // Strip pitch and roll from the spawner's angles. Pass only yaw to the spawned NPC. QAngle angles = GetAbsAngles(); angles.x = 0.0; angles.z = 0.0; pent->SetAbsAngles( angles ); } m_OnSpawnNPC.Set( pEntity, pEntity, this ); if ( m_spawnflags & SF_NPCMAKER_FADE ) { pent->AddSpawnFlags( SF_NPC_FADE_CORPSE ); } pent->RemoveSpawnFlags( SF_NPC_TEMPLATE ); if ( ( m_spawnflags & SF_NPCMAKER_NO_DROP ) == false ) { pent->RemoveSpawnFlags( SF_NPC_FALL_TO_GROUND ); // don't fall, slam } ChildPreSpawn( pent ); DispatchSpawn( pent ); pent->SetOwnerEntity( this ); DispatchActivate( pent ); ChildPostSpawn( pent ); m_nLiveChildren++;// count this NPC if (!(m_spawnflags & SF_NPCMAKER_INF_CHILD)) { m_nMaxNumNPCs--; if ( IsDepleted() ) { m_OnAllSpawned.FireOutput( this, this ); // Disable this forever. Don't kill it because it still gets death notices SetThink( NULL ); SetUse( NULL ); } } }
//========================================================= // Revive - bring a suspended laser sight back. //========================================================= void CLaserSpot::Revive( void ) { pev->effects &= ~EF_NODRAW; SetThink( NULL ); }
//========================================================= // Suspend- make the laser sight invisible. //========================================================= void CEagleLaser::Suspend( float flSuspendTime ) { pev->effects |= EF_NODRAW; SetThink( &CEagleLaser::Revive ); pev->nextthink = gpGlobals->time + flSuspendTime; }
//========================================================= // RunTask //========================================================= void CBaseMonster :: RunTask ( Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_TURN_RIGHT: case TASK_TURN_LEFT: { ChangeYaw( pev->yaw_speed ); if ( FacingIdeal() ) { TaskComplete(); } break; } case TASK_PLAY_SEQUENCE_FACE_ENEMY: case TASK_PLAY_SEQUENCE_FACE_TARGET: { CBaseEntity *pTarget; if ( pTask->iTask == TASK_PLAY_SEQUENCE_FACE_TARGET ) pTarget = m_hTargetEnt; else pTarget = m_hEnemy; if ( pTarget ) { pev->ideal_yaw = UTIL_VecToYaw( pTarget->pev->origin - pev->origin ); ChangeYaw( pev->yaw_speed ); } if ( m_fSequenceFinished ) TaskComplete(); } break; case TASK_PLAY_SEQUENCE: case TASK_PLAY_ACTIVE_IDLE: { if ( m_fSequenceFinished ) { TaskComplete(); } break; } case TASK_FACE_ENEMY: { MakeIdealYaw( m_vecEnemyLKP ); ChangeYaw( pev->yaw_speed ); if ( FacingIdeal() ) { TaskComplete(); } break; } case TASK_FACE_HINTNODE: case TASK_FACE_LASTPOSITION: case TASK_FACE_TARGET: case TASK_FACE_IDEAL: case TASK_FACE_ROUTE: { ChangeYaw( pev->yaw_speed ); if ( FacingIdeal() ) { TaskComplete(); } break; } case TASK_WAIT_PVS: { if ( !FNullEnt(FIND_CLIENT_IN_PVS(edict())) ) { TaskComplete(); } break; } case TASK_WAIT_INDEFINITE: { // don't do anything. break; } case TASK_WAIT: case TASK_WAIT_RANDOM: { if ( gpGlobals->time >= m_flWaitFinished ) { TaskComplete(); } break; } case TASK_WAIT_FACE_ENEMY: { MakeIdealYaw ( m_vecEnemyLKP ); ChangeYaw( pev->yaw_speed ); if ( gpGlobals->time >= m_flWaitFinished ) { TaskComplete(); } break; } case TASK_MOVE_TO_TARGET_RANGE: { float distance; if ( m_hTargetEnt == NULL ) TaskFail(); else { distance = ( m_vecMoveGoal - pev->origin ).Length2D(); // Re-evaluate when you think your finished, or the target has moved too far if ( (distance < pTask->flData) || (m_vecMoveGoal - m_hTargetEnt->pev->origin).Length() > pTask->flData * 0.5 ) { m_vecMoveGoal = m_hTargetEnt->pev->origin; distance = ( m_vecMoveGoal - pev->origin ).Length2D(); FRefreshRoute(); } // Set the appropriate activity based on an overlapping range // overlap the range to prevent oscillation if ( distance < pTask->flData ) { TaskComplete(); RouteClear(); // Stop moving } else if ( distance < 190 && m_movementActivity != ACT_WALK ) m_movementActivity = ACT_WALK; else if ( distance >= 270 && m_movementActivity != ACT_RUN ) m_movementActivity = ACT_RUN; } break; } case TASK_WAIT_FOR_MOVEMENT: { if (MovementIsComplete()) { TaskComplete(); RouteClear(); // Stop moving } break; } case TASK_DIE: { if ( m_fSequenceFinished && pev->frame >= 255 ) { pev->deadflag = DEAD_DEAD; SetThink ( NULL ); StopAnimation(); if ( !BBoxFlat() ) { // a bit of a hack. If a corpses' bbox is positioned such that being left solid so that it can be attacked will // block the player on a slope or stairs, the corpse is made nonsolid. // pev->solid = SOLID_NOT; UTIL_SetSize ( pev, Vector ( -4, -4, 0 ), Vector ( 4, 4, 1 ) ); } else // !!!HACKHACK - put monster in a thin, wide bounding box until we fix the solid type/bounding volume problem UTIL_SetSize ( pev, Vector ( pev->mins.x, pev->mins.y, pev->mins.z ), Vector ( pev->maxs.x, pev->maxs.y, pev->mins.z + 1 ) ); if ( ShouldFadeOnDeath() ) { // this monster was created by a monstermaker... fade the corpse out. SUB_StartFadeOut(); } else { // body is gonna be around for a while, so have it stink for a bit. CSoundEnt::InsertSound ( bits_SOUND_CARCASS, pev->origin, 384, 30 ); } } break; } case TASK_RANGE_ATTACK1_NOTURN: case TASK_MELEE_ATTACK1_NOTURN: case TASK_MELEE_ATTACK2_NOTURN: case TASK_RANGE_ATTACK2_NOTURN: case TASK_RELOAD_NOTURN: { if ( m_fSequenceFinished ) { m_Activity = ACT_RESET; TaskComplete(); } break; } case TASK_RANGE_ATTACK1: case TASK_MELEE_ATTACK1: case TASK_MELEE_ATTACK2: case TASK_RANGE_ATTACK2: case TASK_SPECIAL_ATTACK1: case TASK_SPECIAL_ATTACK2: case TASK_RELOAD: { MakeIdealYaw ( m_vecEnemyLKP ); ChangeYaw ( pev->yaw_speed ); if ( m_fSequenceFinished ) { m_Activity = ACT_RESET; TaskComplete(); } break; } case TASK_SMALL_FLINCH: { if ( m_fSequenceFinished ) { TaskComplete(); } } break; case TASK_WAIT_FOR_SCRIPT: { if ( m_pCine->m_iDelay <= 0 && gpGlobals->time >= m_pCine->m_startTime ) { TaskComplete(); m_pCine->StartSequence( (CBaseMonster *)this, m_pCine->m_iszPlay, TRUE ); if ( m_fSequenceFinished ) ClearSchedule(); pev->framerate = 1.0; //ALERT( at_aiconsole, "Script %s has begun for %s\n", STRING( m_pCine->m_iszPlay ), STRING(pev->classname) ); } break; } case TASK_PLAY_SCRIPT: { if (m_fSequenceFinished) { m_pCine->SequenceDone( this ); } break; } } }
//========================================================= // Revive - bring a suspended laser sight back. //========================================================= void CEagleLaser::Revive( void ) { pev->effects &= ~EF_NODRAW; SetThink( NULL ); }
//----------------------------------------------------------------------------- // Purpose: Allows the turret to fire on targets if they're visible //----------------------------------------------------------------------------- void CNPC_CeilingTurret::ActiveThink( void ) { //Allow descended classes a chance to do something before the think function if ( PreThink( TURRET_ACTIVE ) ) return; //Update our think time SetNextThink( gpGlobals->curtime + 0.1f ); //If we've become inactive, go back to searching if ( ( m_bActive == false ) || ( GetEnemy() == NULL ) ) { SetEnemy( NULL ); SetLastSightTime(); SetThink( &CNPC_CeilingTurret::SearchThink ); m_vecGoalAngles = GetAbsAngles(); return; } //Get our shot positions Vector vecMid = EyePosition(); Vector vecMidEnemy = GetEnemy()->GetAbsOrigin(); //Store off our last seen location UpdateEnemyMemory( GetEnemy(), vecMidEnemy ); //Look for our current enemy bool bEnemyVisible = FInViewCone( GetEnemy() ) && FVisible( GetEnemy() ) && GetEnemy()->IsAlive(); //Calculate dir and dist to enemy Vector vecDirToEnemy = vecMidEnemy - vecMid; float flDistToEnemy = VectorNormalize( vecDirToEnemy ); //We want to look at the enemy's eyes so we don't jitter Vector vecDirToEnemyEyes = GetEnemy()->WorldSpaceCenter() - vecMid; VectorNormalize( vecDirToEnemyEyes ); QAngle vecAnglesToEnemy; VectorAngles( vecDirToEnemyEyes, vecAnglesToEnemy ); //Draw debug info if ( g_debug_turret_ceiling.GetBool() ) { NDebugOverlay::Cross3D( vecMid, -Vector(2,2,2), Vector(2,2,2), 0, 255, 0, false, 0.05 ); NDebugOverlay::Cross3D( GetEnemy()->WorldSpaceCenter(), -Vector(2,2,2), Vector(2,2,2), 0, 255, 0, false, 0.05 ); NDebugOverlay::Line( vecMid, GetEnemy()->WorldSpaceCenter(), 0, 255, 0, false, 0.05 ); NDebugOverlay::Cross3D( vecMid, -Vector(2,2,2), Vector(2,2,2), 0, 255, 0, false, 0.05 ); NDebugOverlay::Cross3D( vecMidEnemy, -Vector(2,2,2), Vector(2,2,2), 0, 255, 0, false, 0.05 ); NDebugOverlay::Line( vecMid, vecMidEnemy, 0, 255, 0, false, 0.05f ); } //Current enemy is not visible if ( ( bEnemyVisible == false ) || ( flDistToEnemy > CEILING_TURRET_RANGE )) { if ( m_flLastSight ) { m_flLastSight = gpGlobals->curtime + 0.5f; } else if ( gpGlobals->curtime > m_flLastSight ) { // Should we look for a new target? ClearEnemyMemory(); SetEnemy( NULL ); SetLastSightTime(); SetThink( &CNPC_CeilingTurret::SearchThink ); m_vecGoalAngles = GetAbsAngles(); SpinDown(); return; } bEnemyVisible = false; } Vector vecMuzzle, vecMuzzleDir; QAngle vecMuzzleAng; GetAttachment( "eyes", vecMuzzle, vecMuzzleAng ); AngleVectors( vecMuzzleAng, &vecMuzzleDir ); if ( m_flShotTime < gpGlobals->curtime ) { //Fire the gun if ( DotProduct( vecDirToEnemy, vecMuzzleDir ) >= 0.9848 ) // 10 degree slop { if ( m_spawnflags & SF_CEILING_TURRET_OUT_OF_AMMO ) { SetActivity( (Activity) ACT_CEILING_TURRET_DRYFIRE ); } else { SetActivity( (Activity) ACT_CEILING_TURRET_FIRE ); } //Fire the weapon Shoot( vecMuzzle, vecMuzzleDir ); } } else { SetActivity( (Activity) ACT_CEILING_TURRET_OPEN_IDLE ); } //If we can see our enemy, face it if ( bEnemyVisible ) { m_vecGoalAngles.y = vecAnglesToEnemy.y; m_vecGoalAngles.x = vecAnglesToEnemy.x; } //Turn to face UpdateFacing(); }
void CCrossbowBolt::BoltTouch( CBaseEntity *pOther ) { SetTouch( NULL ); SetThink( NULL ); if (pOther->pev->takedamage) { TraceResult tr = UTIL_GetGlobalTrace( ); entvars_t *pevOwner; pevOwner = VARS( pev->owner ); // UNDONE: this needs to call TraceAttack instead ClearMultiDamage( ); if ( pOther->IsPlayer() ) { pOther->TraceAttack(pevOwner, gSkillData.plrDmgCrossbowClient, pev->velocity.Normalize(), &tr, DMG_NEVERGIB ); } else { pOther->TraceAttack(pevOwner, gSkillData.plrDmgCrossbowMonster, pev->velocity.Normalize(), &tr, DMG_BULLET | DMG_NEVERGIB ); } ApplyMultiDamage( pev, pevOwner ); pev->velocity = Vector( 0, 0, 0 ); // play body "thwack" sound switch( RANDOM_LONG(0,1) ) { case 0: EMIT_SOUND(ENT(pev), CHAN_BODY, "weapons/xbow_hitbod1.wav", 1, ATTN_NORM); break; case 1: EMIT_SOUND(ENT(pev), CHAN_BODY, "weapons/xbow_hitbod2.wav", 1, ATTN_NORM); break; } if ( !g_pGameRules->IsMultiplayer() ) { Killed( pev, GIB_NEVER ); } } else { EMIT_SOUND_DYN(ENT(pev), CHAN_BODY, "weapons/xbow_hit1.wav", RANDOM_FLOAT(0.95, 1.0), ATTN_NORM, 0, 98 + RANDOM_LONG(0,7)); SetThink( &CCrossbowBolt::SUB_Remove ); pev->nextthink = gpGlobals->time;// this will get changed below if the bolt is allowed to stick in what it hit. if ( FClassnameIs( pOther->pev, "worldspawn" ) ) { // if what we hit is static architecture, can stay around for a while. Vector vecDir = pev->velocity.Normalize( ); UTIL_SetOrigin( pev, pev->origin - vecDir * 12 ); pev->angles = UTIL_VecToAngles( vecDir ); pev->solid = SOLID_NOT; pev->movetype = MOVETYPE_FLY; pev->velocity = Vector( 0, 0, 0 ); pev->avelocity.z = 0; pev->angles.z = RANDOM_LONG(0,360); pev->nextthink = gpGlobals->time + 10.0; } if (UTIL_PointContents(pev->origin) != CONTENTS_WATER) { UTIL_Sparks( pev->origin ); } } if ( g_pGameRules->IsMultiplayer() ) { SetThink( &CCrossbowBolt::ExplodeThink ); pev->nextthink = gpGlobals->time + 0.1; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CASW_Broadcast_Camera::Enable( void ) { m_state = USE_ON; //if ( !m_hPlayer || !m_hPlayer->IsPlayer() ) //{ //m_hPlayer = UTIL_GetLocalPlayer(); //} //if ( !m_hPlayer ) //{ //DispatchUpdateTransmitState(); //return; //} //if ( m_hPlayer->IsPlayer() ) //{ //m_nPlayerButtons = ((CBasePlayer*)m_hPlayer.Get())->m_nButtons; //} //if ( HasSpawnFlags( SF_CAMERA_PLAYER_NOT_SOLID ) ) //{ //m_hPlayer->AddSolidFlags( FSOLID_NOT_SOLID ); //} m_flReturnTime = gpGlobals->curtime + m_flWait; m_flSpeed = m_initialSpeed; m_targetSpeed = m_initialSpeed; if ( HasSpawnFlags( SF_CAMERA_PLAYER_SNAP_TO ) ) { m_bSnapToGoal = true; } //if ( HasSpawnFlags(SF_CAMERA_PLAYER_TARGET ) ) //{ //m_hTarget = m_hPlayer; //} //else //{ m_hTarget = GetNextTarget(); //} // If we don't have a target, ignore the attachment / etc if ( m_hTarget ) { m_iAttachmentIndex = 0; if ( m_iszTargetAttachment != NULL_STRING ) { if ( !m_hTarget->GetBaseAnimating() ) { Warning("%s tried to target an attachment (%s) on target %s, which has no model.\n", GetClassname(), STRING(m_iszTargetAttachment), STRING(m_hTarget->GetEntityName()) ); } else { m_iAttachmentIndex = m_hTarget->GetBaseAnimating()->LookupAttachment( STRING(m_iszTargetAttachment) ); if ( !m_iAttachmentIndex ) { Warning("%s could not find attachment %s on target %s.\n", GetClassname(), STRING(m_iszTargetAttachment), STRING(m_hTarget->GetEntityName()) ); } } } } //if (HasSpawnFlags(SF_CAMERA_PLAYER_TAKECONTROL ) ) //{ //((CBasePlayer*)m_hPlayer.Get())->EnableControl(FALSE); //} if ( m_sPath != NULL_STRING ) { m_pPath = gEntList.FindEntityByName( NULL, m_sPath, NULL); //, m_hPlayer ); } else { m_pPath = NULL; } m_flStopTime = gpGlobals->curtime; if ( m_pPath ) { if ( m_pPath->m_flSpeed != 0 ) m_targetSpeed = m_pPath->m_flSpeed; m_flStopTime += m_pPath->GetDelay(); m_vecMoveDir = m_pPath->GetLocalOrigin() - GetLocalOrigin(); m_moveDistance = VectorNormalize( m_vecMoveDir ); m_flStopTime = gpGlobals->curtime + m_pPath->GetDelay(); } else { m_moveDistance = 0; } /* if ( m_pPath ) { if ( m_pPath->m_flSpeed != 0 ) m_targetSpeed = m_pPath->m_flSpeed; Msg("target speed is %f\n", m_targetSpeed); m_flStopTime += m_pPath->GetDelay(); } */ // copy over player information //if (HasSpawnFlags(SF_CAMERA_PLAYER_POSITION ) ) //{ //UTIL_SetOrigin( this, m_hPlayer->EyePosition() ); //SetLocalAngles( QAngle( m_hPlayer->GetLocalAngles().x, m_hPlayer->GetLocalAngles().y, 0 ) ); //SetAbsVelocity( m_hPlayer->GetAbsVelocity() ); //} //else //{ SetAbsVelocity( vec3_origin ); //} UpdateAllPlayers(); //((CBasePlayer*)m_hPlayer.Get())->SetViewEntity( this ); // Hide the player's viewmodel //if ( ((CBasePlayer*)m_hPlayer.Get())->GetActiveWeapon() ) //{ //((CBasePlayer*)m_hPlayer.Get())->GetActiveWeapon()->AddEffects( EF_NODRAW ); //} // Only track if we have a target if ( m_hTarget ) { // follow the player down SetThink( &CASW_Broadcast_Camera::FollowTarget ); SetNextThink( gpGlobals->curtime ); } //m_moveDistance = 0; m_vecLastPos = GetAbsOrigin(); Move(); DispatchUpdateTransmitState(); }
void CAI_GoalEntity::Spawn() { SetThink( &CAI_GoalEntity::DelayedRefresh ); SetNextThink( gpGlobals->curtime + 0.1f ); }
//========================================================= // MakeMonster- this is the code that drops the monster //========================================================= CBaseMonster* CMonsterMaker::MakeMonster( void ) { edict_t *pent; entvars_t *pevCreate; // ALERT(at_console,"Making Monster NOW\n"); pent = CREATE_NAMED_ENTITY( m_iszMonsterClassname ); if ( FNullEnt( pent ) ) { ALERT ( at_debug, "NULL Ent in MonsterMaker!\n" ); return NULL; } pevCreate = VARS( pent ); pevCreate->origin = pev->vuser1; //AJH dynamic (*locus) position pevCreate->angles = pev->vuser2; pevCreate->velocity = pev->vuser3; SetBits( pevCreate->spawnflags, SF_MONSTER_FALL_TO_GROUND ); if (pev->spawnflags & SF_MONSTERMAKER_NO_WPN_DROP) SetBits( pevCreate->spawnflags, SF_MONSTER_NO_WPN_DROP); // Children hit monsterclip brushes if ( pev->spawnflags & SF_MONSTERMAKER_MONSTERCLIP ) SetBits( pevCreate->spawnflags, SF_MONSTER_HITMONSTERCLIP ); DispatchSpawn( ENT( pevCreate ) ); pevCreate->owner = edict(); //LRC - custom monster behaviour CBaseEntity *pEntity = CBaseEntity::Instance( pevCreate ); CBaseMonster *pMonst = NULL; if (pEntity && (pMonst = pEntity->MyMonsterPointer()) != NULL) { pMonst->m_iClass = this->m_iClass; pMonst->m_iPlayerReact = this->m_iPlayerReact; pMonst->m_iTriggerCondition = this->m_iTriggerCondition; //AJH pMonst->m_iszTriggerTarget = this->m_iszTriggerTarget; //AJH } if ( !FStringNull( pev->netname ) ) { // if I have a netname (overloaded), give the child monster that name as a targetname pevCreate->targetname = pev->netname; } m_cLiveChildren++;// count this monster m_cNumMonsters--; if ( m_cNumMonsters == 0 ) { // Disable this forever. Don't kill it because it still gets death notices SetThink( NULL ); SetUse( NULL ); } else if (m_fActive) { SetNextThink( m_flDelay ); SetThink(&CMonsterMaker:: MakerThink ); } return pMonst; }
void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { // if it's not a player, ignore if (!FClassnameIs(pActivator->pev, "player")) return; // if there is no juice left, turn it off if (m_iJuice <= 0) { pev->frame = 1; Off(); } // if the player doesn't have the suit, or there is no juice left, make the deny noise if ((m_iJuice <= 0) || (!(pActivator->pev->weapons & (1<<WEAPON_SUIT)))) { if (m_flSoundTime <= gpGlobals->time) { m_flSoundTime = gpGlobals->time + 0.62; EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/suitchargeno1.wav", 0.85, ATTN_NORM ); } return; } pev->nextthink = pev->ltime + 0.25; SetThink(&CRecharge::Off); // Time to recharge yet? if (m_flNextCharge >= gpGlobals->time) return; // Make sure that we have a caller if (!pActivator) return; m_hActivator = pActivator; //only recharge the player if (!m_hActivator->IsPlayer() ) return; // Play the on sound or the looping charging sound if (!m_iOn) { m_iOn++; EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM ); m_flSoundTime = 0.56 + gpGlobals->time; } if ((m_iOn == 1) && (m_flSoundTime <= gpGlobals->time)) { m_iOn++; EMIT_SOUND(ENT(pev), CHAN_STATIC, "items/suitcharge1.wav", 0.85, ATTN_NORM ); } // charge the player if (m_hActivator->pev->armorvalue < 100) { m_iJuice--; m_hActivator->pev->armorvalue += 1; if (m_hActivator->pev->armorvalue > 100) m_hActivator->pev->armorvalue = 100; } // govern the rate of charge m_flNextCharge = gpGlobals->time + 0.1; }
// // ambient_generic - general-purpose user-defined static sound // void CAmbientGeneric :: Spawn( void ) { /* -1 : "Default" 0 : "Everywhere" 200 : "Small Radius" 125 : "Medium Radius" 80 : "Large Radius" */ if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_EVERYWHERE) ) { m_flAttenuation = ATTN_NONE; } else if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_SMALLRADIUS) ) { m_flAttenuation = ATTN_IDLE; } else if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_MEDIUMRADIUS) ) { m_flAttenuation = ATTN_STATIC; } else if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_LARGERADIUS) ) { m_flAttenuation = ATTN_NORM; } else {// if the designer didn't set a sound attenuation, default to one. m_flAttenuation = ATTN_STATIC; } char* szSoundFile = (char*) STRING(pev->message); if ( FStringNull( pev->message ) || strlen( szSoundFile ) < 1 ) { ALERT( at_error, "EMPTY AMBIENT AT: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z ); pev->nextthink = gpGlobals->time + 0.1; SetThink( &CBaseEntity::SUB_Remove ); return; } pev->solid = SOLID_NOT; pev->movetype = MOVETYPE_NONE; // Set up think function for dynamic modification // of ambient sound's pitch or volume. Don't // start thinking yet. SetThink( &CAmbientGeneric::RampThink ); pev->nextthink = 0; // allow on/off switching via 'use' function. SetUse ( &CAmbientGeneric::ToggleUse ); m_fActive = FALSE; if ( FBitSet ( pev->spawnflags, AMBIENT_SOUND_NOT_LOOPING ) ) m_fLooping = FALSE; else m_fLooping = TRUE; Precache( ); }
void CRecharge::Recharge(void) { m_iJuice = gSkillData.suitchargerCapacity; pev->frame = 0; SetThink( &CRecharge::SUB_DoNothing ); }
//----------------------------------------------------------------------------- // Purpose: This should remove the rope next time it reaches a resting state. // Right now only the client knows when it reaches a resting state, so // for now it just removes itself after a short time. //----------------------------------------------------------------------------- void CRopeKeyframe::DieAtNextRest( void ) { SetThink( &CBaseEntity::SUB_Remove ); SetNextThink( gpGlobals->curtime + 1.0f ); }
void CGrenadeAR2::Spawn( void ) { Precache( ); SetSolid( SOLID_BBOX ); SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); // Hits everything but debris SetCollisionGroup( COLLISION_GROUP_PROJECTILE ); SetModel( "models/Weapons/ar2_grenade.mdl"); UTIL_SetSize(this, Vector(-3, -3, -3), Vector(3, 3, 3)); // UTIL_SetSize(this, Vector(0, 0, 0), Vector(0, 0, 0)); SetUse( &CGrenadeAR2::DetonateUse ); SetTouch( &CGrenadeAR2::GrenadeAR2Touch ); SetThink( &CGrenadeAR2::GrenadeAR2Think ); SetNextThink( gpGlobals->curtime + 0.1f ); if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() ) { m_flDamage = sk_plr_dmg_smg1_grenade.GetFloat(); } else { m_flDamage = sk_npc_dmg_smg1_grenade.GetFloat(); } m_DmgRadius = sk_smg1_grenade_radius.GetFloat(); m_takedamage = DAMAGE_YES; m_bIsLive = true; m_iHealth = 1; SetGravity( UTIL_ScaleForGravity( 400 ) ); // use a lower gravity for grenades to make them easier to see SetFriction( 0.8 ); SetSequence( 0 ); m_fDangerRadius = 100; m_fSpawnTime = gpGlobals->curtime; // ------------- // Smoke trail. // ------------- if( g_CV_SmokeTrail.GetInt() && !IsXbox() ) { m_hSmokeTrail = SmokeTrail::CreateSmokeTrail(); if( m_hSmokeTrail ) { m_hSmokeTrail->m_SpawnRate = 48; m_hSmokeTrail->m_ParticleLifetime = 1; m_hSmokeTrail->m_StartColor.Init(0.1f, 0.1f, 0.1f); m_hSmokeTrail->m_EndColor.Init(0,0,0); m_hSmokeTrail->m_StartSize = 12; m_hSmokeTrail->m_EndSize = m_hSmokeTrail->m_StartSize * 4; m_hSmokeTrail->m_SpawnRadius = 4; m_hSmokeTrail->m_MinSpeed = 4; m_hSmokeTrail->m_MaxSpeed = 24; m_hSmokeTrail->m_Opacity = 0.2f; m_hSmokeTrail->SetLifetime(10.0f); m_hSmokeTrail->FollowEntity(this); } } }
void EXPORT CEnvSpark::SparkStart(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { SetUse(&CEnvSpark::SparkStop); SetThink(&CEnvSpark::SparkThink); pev->nextthink = gpGlobals->time + (0.1 + RANDOM_FLOAT ( 0, m_flDelay)); }
//----------------------------------------------------------------------------- // Purpose: Stop the spawner //----------------------------------------------------------------------------- void CBaseNPCMaker::Disable( void ) { m_bDisabled = true; SetThink ( NULL ); }