FF Diff Viewer

Comparing 2006 Base SDK to Fortress Forever 2.46

dlls/triggers.cpp

343536373839
#include "ai_behavior_lead.h" #include "gameinterface.h" #ifdef HL2_DLL #include "hl2_player.h" #endif
34353637383940414243444546474849
#include "ai_behavior_lead.h" #include "gameinterface.h" #include "omnibot_interface.h" // --> Mirv: Temp test for triggers #include "ff_scriptman.h" #include "ff_luacontext.h" // <-- Mirv: Temp test for triggers #undef MINMAX_H #include "minmax.h" #ifdef HL2_DLL #include "hl2_player.h" #endif
331332333334335336337338339340341342343
//----------------------------------------------------------------------------- bool CBaseTrigger::PassesTriggerFilters(CBaseEntity *pOther) { // First test spawn flag filters if ( HasSpawnFlags(SF_TRIGGER_ALLOW_ALL) || (HasSpawnFlags(SF_TRIGGER_ALLOW_CLIENTS) && (pOther->GetFlags() & FL_CLIENT)) || (HasSpawnFlags(SF_TRIGGER_ALLOW_NPCS) && (pOther->GetFlags() & FL_NPC)) || (HasSpawnFlags(SF_TRIGGER_ALLOW_PUSHABLES) && FClassnameIs(pOther, "func_pushable")) || (HasSpawnFlags(SF_TRIGGER_ALLOW_PHYSICS) && pOther->GetMoveType() == MOVETYPE_VPHYSICS)) { bool bOtherIsPlayer = pOther->IsPlayer(); if( HasSpawnFlags(SF_TRIGGER_ONLY_PLAYER_ALLY_NPCS) && !bOtherIsPlayer ) {
341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
//----------------------------------------------------------------------------- bool CBaseTrigger::PassesTriggerFilters(CBaseEntity *pOther) { // Check for removed state here if( Classify() == CLASS_TRIGGERSCRIPT ) { CFuncFFScript *pScript = dynamic_cast< CFuncFFScript * >( this ); if( pScript && pScript->IsRemoved() ) return false; } // First test spawn flag filters if ( HasSpawnFlags(SF_TRIGGER_ALLOW_ALL) || (HasSpawnFlags(SF_TRIGGER_ALLOW_CLIENTS) && (pOther->GetFlags() & FL_CLIENT)) || (HasSpawnFlags(SF_TRIGGER_ALLOW_NPCS) && (pOther->GetFlags() & FL_NPC)) || (HasSpawnFlags(SF_TRIGGER_ALLOW_PUSHABLES) && FClassnameIs(pOther, "func_pushable")) || (HasSpawnFlags(SF_TRIGGER_ALLOW_PHYSICS) && pOther->GetMoveType() == MOVETYPE_VPHYSICS) || (HasSpawnFlags(SF_TRIGGER_ALLOW_FF_GRENADES) && (pOther->GetFlags() & FL_GRENADE)) || (HasSpawnFlags(SF_TRIGGER_ALLOW_FF_BUILDABLES) && ((pOther->Classify() == CLASS_SENTRYGUN) || (pOther->Classify() == CLASS_DISPENSER))) //(HasSpawnFlags(SF_TRIGGER_ALLOW_FF_INFOSCRIPTS) && ((pOther->Classify() == CLASS_INFOSCRIPT))) ) { // This is needed as CBaseTrigger::StartTouch can fail // but the superclass (like a push or teleporter) will // still call it's individual Touch function - when it // shouldn't. A better solution would be when StartTouch // doesn't finish (like allowed is false) the super class // touch function never gets called - but I don't know // where that code is... // If we're set to check all entities if( HasSpawnFlags( SF_TRIGGER_ALLOW_ALL ) ) { // If the entity sys allowed func returns false then // bail. If true, run these other checks. CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( !hAllowed.GetBool() ) { _scriptman.RunPredicates_LUA( this, &hAllowed, "onfailtouch" ); return false; } } } else { // Always check players... Doing this double check // as most allowed functions are only set up to check // a player_id and not an ent_id (so I don't want // to crash anybody's script) if( pOther->IsPlayer() ) { // If the entity sys allowed func returns false then // bail. If true, run these other checks. CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( !hAllowed.GetBool() ) { _scriptman.RunPredicates_LUA( this, &hAllowed, "onfailtouch" ); return false; } } } } if( HasSpawnFlags( SF_TRIGGER_ALLOW_FF_GRENADES )) { if( pOther->GetFlags() & FL_GRENADE ) { // If the entity sys allowed func returns false then // bail. If true, run these other checks. CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( !hAllowed.GetBool() ) { _scriptman.RunPredicates_LUA( this, &hAllowed, "onfailtouch" ); return false; } } } } if( HasSpawnFlags( SF_TRIGGER_ALLOW_FF_BUILDABLES )) { if(( pOther->Classify() == CLASS_SENTRYGUN ) || (pOther->Classify() == CLASS_DISPENSER )) { // If the entity sys allowed func returns false then // bail. If true, run these other checks. CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( !hAllowed.GetBool() ) { _scriptman.RunPredicates_LUA( this, &hAllowed, "onfailtouch" ); return false; } } } } /* if( HasSpawnFlags( SF_TRIGGER_ALLOW_FF_INFOSCRIPTS )) { if( pOther->Classify() == CLASS_INFOSCRIPT ) { // If the entity sys allowed func returns false then // bail. If true, run these other checks. CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( !hAllowed.GetBool() ) { _scriptman.RunPredicates_LUA( this, &hAllowed, "onfailtouch" ); return false; } } } } */ bool bOtherIsPlayer = pOther->IsPlayer(); if( HasSpawnFlags(SF_TRIGGER_ONLY_PLAYER_ALLY_NPCS) && !bOtherIsPlayer ) {
410411412413414415416
hOther = pOther; m_hTouchingEntities.AddToTail( hOther ); m_OnStartTouch.FireOutput(pOther, this); } }
533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
hOther = pOther; m_hTouchingEntities.AddToTail( hOther ); m_OnStartTouch.FireOutput(pOther, this); // Fire the lua output CFFLuaSC hTouch( 1, pOther ); _scriptman.RunPredicates_LUA( this, &hTouch, "ontouch" ); // Got a trigger_ff_script - do special stuff if( Classify() == CLASS_TRIGGERSCRIPT ) { // Add this trigger to m_hActiveScripts int iEntIndex = entindex(); if( iEntIndex ) { // Don't want dups bool bFound = false; for( int i = 0; ( i < pOther->m_hActiveScripts.Count() ) && !bFound; i++ ) if( pOther->m_hActiveScripts[ i ] == iEntIndex ) bFound = true; if( !bFound ) { pOther->m_hActiveScripts.AddToTail( iEntIndex ); } } // Change our goal state CFuncFFScript *pScript = dynamic_cast< CFuncFFScript * >( this ); if( pScript ) pScript->SetActive(); } } }
426427428429430431432433434435436437
EHANDLE hOther; hOther = pOther; m_hTouchingEntities.FindAndRemove( hOther ); //FIXME: Without this, triggers fire their EndTouch outputs when they are disabled! //if ( !m_bDisabled ) //{ m_OnEndTouch.FireOutput(pOther, this); //} // If there are no more entities touching this trigger, fire the lost all touches // Loop through the touching entities backwards. Clean out old ones, and look for existing
579580581582583584585586587588589590591592593594595596597598599600601602603
EHANDLE hOther; hOther = pOther; m_hTouchingEntities.FindAndRemove( hOther ); // Do this to clear the entry. Don't care if we're not allowed // to touch this trigger still. // Remove this trigger from m_hActiveScripts. Want to do this even // if we're removed so we don't leave entries in. int iEntIndex = entindex(); if( iEntIndex ) { for( int i = 0; i < pOther->m_hActiveScripts.Count(); i++ ) if( pOther->m_hActiveScripts[ i ] == iEntIndex ) pOther->m_hActiveScripts.Remove( i ); } //FIXME: Without this, triggers fire their EndTouch outputs when they are disabled! //if ( !m_bDisabled ) //{ // squeek: moved this line down below so it only gets fired if Lua allows it //m_OnEndTouch.FireOutput(pOther, this); //} // If there are no more entities touching this trigger, fire the lost all touches // Loop through the touching entities backwards. Clean out old ones, and look for existing
458459460461462463
{ m_OnEndTouchAll.FireOutput(pOther, this); } } }
624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
{ m_OnEndTouchAll.FireOutput(pOther, this); } if( Classify() == CLASS_TRIGGERSCRIPT ) { CFuncFFScript *pScript = dynamic_cast< CFuncFFScript * >( this ); if( pScript ) { if( !bFoundOtherTouchee ) pScript->SetInactive(); if( pScript->IsRemoved() ) return; } } // Tell lua we're not touching this thing anymore. Run allowed // just to make sure we're allowed to still be touching it. CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( hAllowed.GetBool() ) { // Fire the output m_OnEndTouch.FireOutput(pOther, this); } } } }
838839840841842843844
// ################################################################################## LINK_ENTITY_TO_CLASS( trigger_multiple, CTriggerMultiple ); BEGIN_DATADESC( CTriggerMultiple ) // Function Pointers
102910301031103210331034
// ################################################################################## LINK_ENTITY_TO_CLASS( trigger_multiple, CTriggerMultiple ); BEGIN_DATADESC( CTriggerMultiple ) // Function Pointers
895896897898899900
m_hActivator = pActivator; m_OnTrigger.FireOutput(m_hActivator, this); if (m_flWait > 0)
1085108610871088108910901091109210931094
m_hActivator = pActivator; // Run lua trigger event CFFLuaSC hOnTrigger( 1, pActivator ); _scriptman.RunPredicates_LUA( this, &hOnTrigger, "ontrigger" ); m_OnTrigger.FireOutput(m_hActivator, this); if (m_flWait > 0)
922923924925926927
} // ################################################################################## // >> TriggerOnce // ################################################################################## class CTriggerOnce : public CTriggerMultiple
11161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
} // ################################################################################## // >> func_ff_script // ################################################################################## LINK_ENTITY_TO_CLASS( trigger_ff_script, CFuncFFScript ); //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CFuncFFScript::CFuncFFScript() { m_iGoalState = GS_INACTIVE; // bot info m_BotTeamFlags = 0; m_BotGoalType = Omnibot::kNone; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFuncFFScript::SetActive( void ) { m_iGoalState = GS_ACTIVE; DispatchUpdateTransmitState(); CFFLuaSC hContext; _scriptman.RunPredicates_LUA( this, &hContext, "onactive" ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFuncFFScript::SetInactive( void ) { m_iGoalState = GS_INACTIVE; DispatchUpdateTransmitState(); CFFLuaSC hContext; _scriptman.RunPredicates_LUA( this, &hContext, "oninactive" ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFuncFFScript::SetRemoved( void ) { m_iGoalState = GS_REMOVED; DispatchUpdateTransmitState(); CFFLuaSC hContext; _scriptman.RunPredicates_LUA( this, &hContext, "onremoved" ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFuncFFScript::SetRestored( void ) { CFFLuaSC hContext; _scriptman.RunPredicates_LUA( this, &hContext, "onrestored" ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFuncFFScript::Spawn( void ) { BaseClass::Spawn(); CFFLuaSC hContext; _scriptman.RunPredicates_LUA( this, &hContext, "spawn" ); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int CFuncFFScript::UpdateTransmitState() { if ( IsRemoved() ) return SetTransmitState( FL_EDICT_DONTSEND ); return BaseClass::UpdateTransmitState(); } void CFuncFFScript::LuaSetLocation() { } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CFuncFFScript::SetBotGoalInfo(int _type, int _team) { m_BotGoalType = _type; m_BotTeamFlags = 0; const int iAllTeams = (1< (1< (1< (1< switch(_team) { case 0: m_BotTeamFlags = iAllTeams; break; case TEAM_BLUE: m_BotTeamFlags = iAllTeams & ~(1< break; case TEAM_RED: m_BotTeamFlags = iAllTeams & ~(1< break; case TEAM_YELLOW: m_BotTeamFlags = iAllTeams & ~(1< break; case TEAM_GREEN: m_BotTeamFlags = iAllTeams & ~(1< break; } Omnibot::Notify_GoalInfo(this, m_BotGoalType, m_BotTeamFlags); } // ################################################################################## // >> TriggerOnce // ################################################################################## class CTriggerOnce : public CTriggerMultiple
280828092810281128122813
int CTriggerCamera::UpdateTransmitState() { // always tranmit if currently used by a monitor if ( m_state == USE_ON ) {
31243125312631273128312931303131313231333134313531363137
int CTriggerCamera::UpdateTransmitState() { // --> FF #ifdef GAME_DLL // always transmit if you're an objective if ( m_ObjectivePlayerRefs.Count() > 0 ) return SetTransmitState( FL_EDICT_ALWAYS ); #endif // GAME_DLL // <-- FF // always tranmit if currently used by a monitor if ( m_state == USE_ON ) {
419441954196419741984199
if ( pOther->GetMoveType() != MOVETYPE_VPHYSICS && !pOther->IsPlayer() ) return false; // First test spawn flag filters if ( HasSpawnFlags(SF_TRIGGER_ALLOW_ALL) || (HasSpawnFlags(SF_TRIGGER_ALLOW_CLIENTS) && (pOther->GetFlags() & FL_CLIENT)) ||
45184519452045214522452345244525452645274528452945304531453245334534453545364537
if ( pOther->GetMoveType() != MOVETYPE_VPHYSICS && !pOther->IsPlayer() ) return false; // Removing this for now... what is a CBaseVPhysicsTrigger // anyway and when is it used? Also, we never fire a // ontouch/ontrigger with anything but a CBaseTrigger so // CBaseVPhysicsTrigger should be set up fully and not half // assed like it currently is. /* CFFLuaSC hAllowed( 1, pOther ); if( _scriptman.RunPredicates_LUA( this, &hAllowed, "allowed" ) ) { if( !hAllowed.GetBool() ) return false; } */ // First test spawn flag filters if ( HasSpawnFlags(SF_TRIGGER_ALLOW_ALL) || (HasSpawnFlags(SF_TRIGGER_ALLOW_CLIENTS) && (pOther->GetFlags() & FL_CLIENT)) ||