void CMultiSource::Register( void ) { m_iTotal = 0; memset( m_rgEntities, 0, MS_MAX_TARGETS * sizeof( EHANDLE ) ); SetThink( &CMultiSource::SUB_DoNothing ); // search for all entities which target this multisource (GetTargetname()) CBaseEntity* pTarget = nullptr; while( ( pTarget = UTIL_FindEntityByTarget( pTarget, GetTargetname() ) ) != nullptr && ( m_iTotal < MS_MAX_TARGETS ) ) { m_rgEntities[ m_iTotal++ ] = pTarget; } pTarget = nullptr; while( ( pTarget = UTIL_FindEntityByClassname( pTarget, "multi_manager" ) ) != nullptr && ( m_iTotal < MS_MAX_TARGETS ) ) { if( pTarget->HasTarget( GetTargetname() ) ) m_rgEntities[ m_iTotal++ ] = pTarget; } GetSpawnFlags().ClearFlags( SF_MULTI_INIT ); }
// // ********** Cinematic Think ********** // void CCineMonster::CineThink( void ) { if( FindEntity() ) { PossessEntity(); ALERT( at_aiconsole, "script \"%s\" using monster \"%s\"\n", GetTargetname(), STRING( m_iszEntity ) ); } else { CancelScript(); ALERT( at_aiconsole, "script \"%s\" can't find monster \"%s\"\n", GetTargetname(), STRING( m_iszEntity ) ); SetNextThink( gpGlobals->time + 1.0 ); } }
void CMultiSource :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { int i = 0; // find the entity in our list while( i < m_iTotal ) { if( m_rgEntities[i++] == pCaller ) break; } // if we didn't find it, report error and leave if( i > m_iTotal ) { if( pCaller->GetTargetname( )) ALERT( at_error, "multisource \"%s\": Used by non-member %s \"%s\"\n", GetTargetname(), pCaller->GetTargetname( )); else ALERT( at_error, "multisource \"%s\": Used by non-member %s\n", GetTargetname(), pCaller->GetClassname( )); return; } // store the state before the change, so we can compare it to the new state STATE s = GetState(); // do the change m_rgTriggered[i-1] ^= 1; // did we change state? if( s == GetState( )) return; if( s == STATE_ON && !FStringNull( pev->netname )) { // the change disabled me and I have a "fire on disable" field ALERT( at_aiconsole, "Multisource %s deactivated (%d inputs)\n", GetTargetname(), m_iTotal ); if( m_globalstate ) UTIL_FireTargets( STRING( pev->netname ), NULL, this, USE_OFF, 0 ); else UTIL_FireTargets( STRING( pev->netname ), NULL, this, USE_TOGGLE, 0 ); } else if( s == STATE_OFF ) { // the change activated me ALERT( at_aiconsole, "Multisource %s enabled (%d inputs)\n", GetTargetname(), m_iTotal ); if( m_globalstate ) UTIL_FireTargets( STRING( pev->target ), NULL, this, USE_ON, 0 ); else UTIL_FireTargets( STRING( pev->target ), NULL, this, USE_TOGGLE, 0 ); } }
void CBaseDoor :: Activate( void ) { CBaseDoor *pDoorList[64]; m_bDoorGroup = true; // force movement groups to sync!!! int doorCount = GetDoorMovementGroup( pDoorList, ARRAYSIZE( pDoorList )); for( int i = 0; i < doorCount; i++ ) { if( pDoorList[i]->pev->movedir == pev->movedir ) { bool error = false; if( pDoorList[i]->IsRotatingDoor() ) { error = ( pDoorList[i]->GetLocalAngles() != GetLocalAngles()) ? true : false; } else { error = ( pDoorList[i]->GetLocalOrigin() != GetLocalOrigin()) ? true : false; } if( error ) { // don't do group blocking m_bDoorGroup = false; // UNDONE: This should probably fixup m_vecPosition1 & m_vecPosition2 ALERT( at_aiconsole, "Door group %s has misaligned origin!\n", GetTargetname( )); } } } }
// // Train next - path corner needs to change to next target // void CFuncTrain::Next( void ) { CBaseEntity *pTarg; // now find our next target //TODO: this entity is supposed to work with path_corner only. Other entities will work, but will probably misbehave. - Solokiller //Check for classname and ignore others? pTarg = GetNextTarget(); if( !pTarg ) { if( pev->noiseMovement ) STOP_SOUND( this, CHAN_STATIC, ( char* ) STRING( pev->noiseMovement ) ); // Play stop sound if( pev->noiseStopMoving ) EMIT_SOUND( this, CHAN_VOICE, ( char* ) STRING( pev->noiseStopMoving ), m_volume, ATTN_NORM ); return; } // Save last target in case we need to find it again pev->message = pev->target; pev->target = pTarg->pev->target; m_flWait = pTarg->GetDelay(); if( m_pevCurrentTarget && m_pevCurrentTarget->speed != 0 ) {// don't copy speed from target if it is 0 (uninitialized) pev->speed = m_pevCurrentTarget->speed; ALERT( at_aiconsole, "Train %s speed to %4.2f\n", GetTargetname(), pev->speed ); } m_pevCurrentTarget = pTarg->pev;// keep track of this since path corners change our target for us. pev->enemy = pTarg->edict();//hack if( FBitSet( m_pevCurrentTarget->spawnflags, SF_CORNER_TELEPORT ) ) { // Path corner has indicated a teleport to the next corner. SetBits( pev->effects, EF_NOINTERP ); SetAbsOrigin( pTarg->GetAbsOrigin() - ( pev->mins + pev->maxs )* 0.5 ); Wait(); // Get on with doing the next path corner. } else { // Normal linear move. // CHANGED this from CHAN_VOICE to CHAN_STATIC around OEM beta time because trains should // use CHAN_STATIC for their movement sounds to prevent sound field problems. // this is not a hack or temporary fix, this is how things should be. (sjb). if( pev->noiseMovement ) { STOP_SOUND( this, CHAN_STATIC, ( char* ) STRING( pev->noiseMovement ) ); EMIT_SOUND( this, CHAN_STATIC, ( char* ) STRING( pev->noiseMovement ), m_volume, ATTN_NORM ); } ClearBits( pev->effects, EF_NOINTERP ); SetMoveDone( &CFuncTrain::Wait ); LinearMove( pTarg->GetAbsOrigin() - ( pev->mins + pev->maxs )* 0.5, pev->speed ); } }
void CMultiSource :: Register( void ) { m_iTotal = 0; memset( m_rgEntities, 0, MAX_MASTER_TARGETS * sizeof( EHANDLE )); SetThink( NULL ); // search for all entities which target this multisource (pev->target) CBaseEntity *pTarget = UTIL_FindEntityByTarget( NULL, GetTargetname( )); while( pTarget && ( m_iTotal < MAX_MASTER_TARGETS )) { m_rgEntities[m_iTotal++] = pTarget; pTarget = UTIL_FindEntityByTarget( pTarget, GetTargetname( )); } // search for all monsters which target this multisource (TriggerTarget) pTarget = UTIL_FindEntityByMonsterTarget( NULL, GetTargetname( )); while( pTarget && ( m_iTotal < MAX_MASTER_TARGETS )) { m_rgEntities[m_iTotal++] = pTarget; pTarget = UTIL_FindEntityByMonsterTarget( pTarget, GetTargetname( )); } pTarget = UTIL_FindEntityByClassname( NULL, "multi_manager" ); while( pTarget && ( m_iTotal < MAX_MASTER_TARGETS )) { if( pTarget->HasTarget( pev->targetname )) m_rgEntities[m_iTotal++] = pTarget; pTarget = UTIL_FindEntityByClassname( pTarget, "multi_manager" ); } ClearBits( pev->spawnflags, SF_MULTI_INIT ); }
// find all the cinematic entities with my targetname and stop them from playing void CCineMonster::CancelScript( void ) { ALERT( at_aiconsole, "Cancelling script: %s\n", STRING( m_iszPlay ) ); if( !HasTargetname() ) { ScriptEntityCancel( this ); return; } CBaseEntity* pCineTarget = nullptr; while( ( pCineTarget = UTIL_FindEntityByTargetname( pCineTarget, GetTargetname() ) ) != nullptr ) { ScriptEntityCancel( pCineTarget ); } }
// find all the cinematic entities with my targetname and tell them to wait before starting void CCineMonster::DelayStart( const bool bState ) { CBaseEntity* pCine = nullptr; while( ( pCine = UTIL_FindEntityByTargetname( pCine, GetTargetname() ) ) != nullptr ) { if( pCine->ClassnameIs( "scripted_sequence" ) ) { CCineMonster *pTarget = static_cast<CCineMonster*>( pCine ); if( bState ) { pTarget->m_iDelay++; } else { pTarget->m_iDelay--; if( pTarget->m_iDelay <= 0 ) pTarget->m_startTime = gpGlobals->time + 0.05; } } } }
void CMultiSource::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { int i; bool bFound = false; // Find the entity in our list for( i = 0; i < m_iTotal; ++i ) { if( m_rgEntities[ i ] == pCaller ) { bFound = true; break; } } // if we didn't find it, report error and leave if( !bFound ) { ALERT( at_console, "MultiSrc:Used by non member %s.\n", pCaller->GetClassname() ); return; } // CONSIDER: a Use input to the multisource always toggles. Could check useType for ON/OFF/TOGGLE m_rgTriggered[ i ] ^= 1; // if( IsTriggered( pActivator ) ) { ALERT( at_aiconsole, "Multisource %s enabled (%d inputs)\n", GetTargetname(), m_iTotal ); USE_TYPE targetUseType = USE_TOGGLE; if( m_globalstate ) targetUseType = USE_ON; SUB_UseTargets( NULL, targetUseType, 0 ); } }
void CFuncLight :: Spawn( void ) { m_Material = matGlass; CBreakable::Spawn(); SET_MODEL( edict(), GetModel() ); // probably map compiler haven't func_light support if( m_iStyle <= 0 || m_iStyle >= 256 ) { if( GetTargetname()[0] ) ALERT( at_error, "%s with name %s has bad lightstyle %i. Disabled\n", GetClassname(), GetTargetname(), m_iStyle ); else ALERT( at_error, "%s [%i] has bad lightstyle %i. Disabled\n", GetClassname(), entindex(), m_iStyle ); m_iState = STATE_DEAD; // lamp is dead } if( FBitSet( pev->spawnflags, SF_LIGHT_START_ON )) Use( this, this, USE_ON, 0 ); else Use( this, this, USE_OFF, 0 ); if( pev->health <= 0 ) pev->takedamage = DAMAGE_NO; else pev->takedamage = DAMAGE_YES; }
void CBaseDoor::Blocked( CBaseEntity *pOther ) { CBaseDoor *pDoor = NULL; // Hurt the blocker a little. if( GetDamage() ) pOther->TakeDamage( this, this, GetDamage(), 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( m_toggle_state == TS_GOING_DOWN ) { DoorGoUp(); } else { DoorGoDown(); } } // Block all door pieces with the same targetname here. if( HasTargetname() ) { CBaseEntity* pTarget = nullptr; while( ( pTarget = UTIL_FindEntityByTargetname( pTarget, GetTargetname() ) ) != nullptr ) { if( pTarget != this ) { if( pTarget->ClassnameIs( "func_door" ) || pTarget->ClassnameIs( "func_door_rotating" ) ) { pDoor = static_cast<CBaseDoor*>( pTarget ); if( pDoor->m_flWait >= 0 ) { //TODO: comparing avel with vel is probably wrong - Solokiller if( pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetAngularVelocity() == GetAbsVelocity() ) { // this is the most hacked, evil, bastardized thing I've ever seen. kjb if( pTarget->ClassnameIs( "func_door" ) ) {// set origin to realign normal doors pDoor->SetAbsOrigin( GetAbsOrigin() ); pDoor->SetAbsVelocity( g_vecZero );// stop! } else {// set angles to realign rotating doors pDoor->SetAbsAngles( GetAbsAngles() ); pDoor->SetAngularVelocity( g_vecZero ); } } if( !GetSpawnFlags().Any( SF_DOOR_SILENT ) ) STOP_SOUND( this, CHAN_STATIC, ( char* ) STRING( pev->noiseMoving ) ); if( pDoor->m_toggle_state == TS_GOING_DOWN ) pDoor->DoorGoUp(); else pDoor->DoorGoDown(); } } } } } }
//========================================================= //========================================================= void CBasePlayer::CheatImpulseCommands( int iImpulse ) { if( !UTIL_CheatsAllowed() ) { return; } switch( iImpulse ) { case 76: { if( !g_bPrecacheGrunt ) { g_bPrecacheGrunt = true; ALERT( at_console, "You must now restart to use Grunt-o-matic.\n" ); } else { UTIL_MakeVectors( Vector( 0, GetViewAngle().y, 0 ) ); Create( "monster_human_grunt", GetAbsOrigin() + gpGlobals->v_forward * 128, GetAbsAngles() ); } break; } case 101: { gEvilImpulse101 = true; GiveNamedItem( "item_suit" ); GiveNamedItem( "item_battery" ); GiveNamedItem( "weapon_crowbar" ); GiveNamedItem( "weapon_9mmhandgun" ); GiveNamedItem( "ammo_9mmclip" ); GiveNamedItem( "weapon_shotgun" ); GiveNamedItem( "ammo_buckshot" ); GiveNamedItem( "weapon_9mmAR" ); GiveNamedItem( "ammo_9mmAR" ); GiveNamedItem( "ammo_ARgrenades" ); GiveNamedItem( "weapon_handgrenade" ); GiveNamedItem( "weapon_tripmine" ); GiveNamedItem( "weapon_357" ); GiveNamedItem( "ammo_357" ); GiveNamedItem( "weapon_crossbow" ); GiveNamedItem( "ammo_crossbow" ); GiveNamedItem( "weapon_egon" ); GiveNamedItem( "weapon_gauss" ); GiveNamedItem( "ammo_gaussclip" ); GiveNamedItem( "weapon_rpg" ); GiveNamedItem( "ammo_rpgclip" ); GiveNamedItem( "weapon_satchel" ); GiveNamedItem( "weapon_snark" ); GiveNamedItem( "weapon_hornetgun" ); #if USE_OPFOR GiveNamedItem( "weapon_knife" ); GiveNamedItem( "weapon_pipewrench" ); GiveNamedItem( "weapon_grapple" ); GiveNamedItem( "weapon_eagle" ); GiveNamedItem( "weapon_m249" ); GiveNamedItem( "weapon_displacer" ); GiveNamedItem( "weapon_sniperrifle" ); GiveNamedItem( "weapon_sporelauncher" ); GiveNamedItem( "weapon_shockrifle" ); GiveNamedItem( "ammo_556" ); GiveNamedItem( "ammo_762" ); #endif gEvilImpulse101 = false; break; } case 102: { // Gibbage!!! CGib::SpawnRandomGibs( this, 1, 1 ); break; } case 103: { // What the hell are you doing? auto pEntity = UTIL_FindEntityForward( this ); if( pEntity ) { CBaseMonster *pMonster = pEntity->MyMonsterPointer(); if( pMonster ) pMonster->ReportAIState(); } break; } case 104: { // Dump all of the global state varaibles (and global entity names) gGlobalState.DumpGlobals(); break; } case 105:// player makes no sound for monsters to hear. { if( m_fNoPlayerSound ) { ALERT( at_console, "Player is audible\n" ); m_fNoPlayerSound = false; } else { ALERT( at_console, "Player is silent\n" ); m_fNoPlayerSound = true; } break; } case 106: { // Give me the classname and targetname of this entity. auto pEntity = UTIL_FindEntityForward( this ); if( pEntity ) { ALERT( at_console, "Classname: %s", pEntity->GetClassname() ); if( pEntity->HasTargetname() ) { ALERT( at_console, " - Targetname: %s\n", pEntity->GetTargetname() ); } else { ALERT( at_console, " - TargetName: No Targetname\n" ); } ALERT( at_console, "Model: %s\n", pEntity->GetModelName() ); if( HasGlobalName() ) ALERT( at_console, "Globalname: %s\n", pEntity->GetGlobalName() ); } break; } case 107: { TraceResult tr; CBaseEntity* pWorld = CWorld::GetInstance(); Vector start = GetAbsOrigin() + GetViewOffset(); Vector end = start + gpGlobals->v_forward * 1024; UTIL_TraceLine( start, end, ignore_monsters, edict(), &tr ); if( tr.pHit ) pWorld = CBaseEntity::Instance( tr.pHit ); const texture_t* pTexture = UTIL_TraceTexture( pWorld, start, end ); if( pTexture ) ALERT( at_console, "Texture: %s\n", pTexture->name ); break; } case 195:// show shortest paths for entire level to nearest node { Create( "node_viewer_fly", GetAbsOrigin(), GetAbsAngles() ); break; } case 196:// show shortest paths for entire level to nearest node { Create( "node_viewer_large", GetAbsOrigin(), GetAbsAngles() ); break; } case 197:// show shortest paths for entire level to nearest node { Create( "node_viewer_human", GetAbsOrigin(), GetAbsAngles() ); break; } case 199:// show nearest node and all connections { ALERT( at_console, "%d\n", WorldGraph.FindNearestNode( GetAbsOrigin(), bits_NODE_GROUP_REALM ) ); WorldGraph.ShowNodeConnections( WorldGraph.FindNearestNode( GetAbsOrigin(), bits_NODE_GROUP_REALM ) ); break; } case 202:// Random blood splatter { UTIL_MakeVectors( GetViewAngle() ); TraceResult tr; UTIL_TraceLine( GetAbsOrigin() + GetViewOffset(), GetAbsOrigin() + GetViewOffset() + gpGlobals->v_forward * 128, ignore_monsters, ENT( pev ), &tr ); if( tr.flFraction != 1.0 ) {// line hit something, so paint a decal auto pBlood = static_cast< CBloodSplat* >( UTIL_CreateNamedEntity( "blood_splat" ) ); pBlood->CreateSplat( this ); } break; } case 203:// remove creature. { auto pEntity = UTIL_FindEntityForward( this ); if( pEntity ) { if( pEntity->GetTakeDamageMode() != DAMAGE_NO ) pEntity->SetThink( &CBaseEntity::SUB_Remove ); } break; } } }