Fixed bug with detecting door triggers

This commit is contained in:
RGreenlees 2024-03-24 21:32:34 +00:00 committed by pierow
parent f391176841
commit 1cd837b372
2 changed files with 37 additions and 21 deletions

View file

@ -2379,7 +2379,7 @@ bool HasBotCompletedClimbMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector
} }
} }
return false;
} }
bool HasBotCompletedJumpMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag) bool HasBotCompletedJumpMove(const AvHAIPlayer* pBot, Vector MoveStart, Vector MoveEnd, Vector NextMoveDestination, SamplePolyFlags NextMoveFlag)
@ -7337,12 +7337,14 @@ Vector UTIL_GetButtonFloorLocation(const Vector UserLocation, edict_t* ButtonEdi
return NewButtonAccessPoint; return NewButtonAccessPoint;
} }
bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door) bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, vector<CBaseEntity*>& CheckedTriggers, CBaseEntity* Door)
{ {
if (!TriggerEntity || !Door) { return false; } if (!TriggerEntity || !Door) { return false; }
if (TriggerEntity == Door) { return true; } if (TriggerEntity == Door) { return true; }
CheckedTriggers.push_back(TriggerEntity);
const char* DoorName = STRING(Door->pev->targetname); const char* DoorName = STRING(Door->pev->targetname);
const char* TriggerName = STRING(TriggerEntity->pev->targetname); const char* TriggerName = STRING(TriggerEntity->pev->targetname);
const char* TriggerTarget = STRING(TriggerEntity->pev->target); const char* TriggerTarget = STRING(TriggerEntity->pev->target);
@ -7358,7 +7360,7 @@ bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door)
CBaseEntity* TargetEntity = UTIL_FindEntityByTargetname(NULL, targetOnFinish); CBaseEntity* TargetEntity = UTIL_FindEntityByTargetname(NULL, targetOnFinish);
if (TargetEntity && TargetEntity != TriggerEntity && UTIL_IsTriggerLinkedToDoor(TargetEntity, Door)) { return true; } if (TargetEntity && TargetEntity != TriggerEntity && UTIL_IsTriggerLinkedToDoor(TargetEntity, CheckedTriggers, Door)) { return true; }
return false; return false;
} }
@ -7375,10 +7377,10 @@ bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door)
if (MMTargetEntity == Door) { return true; } if (MMTargetEntity == Door) { return true; }
// Don't check this if it's targeting us (circular reference) // Already checked this one!
if (FStrEq(STRING(MMTargetEntity->pev->target), STRING(TriggerEntity->pev->targetname))) { continue; } if (std::find(CheckedTriggers.begin(), CheckedTriggers.end(), MMTargetEntity) != CheckedTriggers.end()) { continue; }
if (MMTargetEntity && UTIL_IsTriggerLinkedToDoor(MMTargetEntity, Door)) { return true; } if (UTIL_IsTriggerLinkedToDoor(MMTargetEntity, CheckedTriggers, Door)) { return true; }
} }
return false; return false;
@ -7394,7 +7396,7 @@ bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door)
const char* SourceGlobalState = STRING(theEntity->m_globalstate); const char* SourceGlobalState = STRING(theEntity->m_globalstate);
if (FStrEq(EnvGlobalState, SourceGlobalState)) if (FStrEq(EnvGlobalState, SourceGlobalState))
{ {
if (UTIL_IsTriggerLinkedToDoor(theEntity, Door)) { return true; } if (UTIL_IsTriggerLinkedToDoor(theEntity, CheckedTriggers, Door)) { return true; }
} }
END_FOR_ALL_ENTITIES("multisource") END_FOR_ALL_ENTITIES("multisource")
@ -7410,21 +7412,21 @@ bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door)
FOR_ALL_ENTITIES("func_button", CBaseButton*) FOR_ALL_ENTITIES("func_button", CBaseButton*)
if (theEntity->m_sMaster && FStrEq(STRING(theEntity->m_sMaster), targetName)) if (theEntity->m_sMaster && FStrEq(STRING(theEntity->m_sMaster), targetName))
{ {
if (UTIL_IsTriggerLinkedToDoor(theEntity, Door)) { return true; } if (std::find(CheckedTriggers.begin(), CheckedTriggers.end(), theEntity) == CheckedTriggers.end() && UTIL_IsTriggerLinkedToDoor(theEntity, CheckedTriggers, Door)) { return true; }
} }
END_FOR_ALL_ENTITIES("func_button") END_FOR_ALL_ENTITIES("func_button")
FOR_ALL_ENTITIES("trigger_once", CBaseTrigger*) FOR_ALL_ENTITIES("trigger_once", CBaseTrigger*)
if (theEntity->m_sMaster && FStrEq(STRING(theEntity->m_sMaster), targetName)) if (theEntity->m_sMaster && FStrEq(STRING(theEntity->m_sMaster), targetName))
{ {
if (UTIL_IsTriggerLinkedToDoor(theEntity, Door)) { return true; } if (std::find(CheckedTriggers.begin(), CheckedTriggers.end(), theEntity) == CheckedTriggers.end() && UTIL_IsTriggerLinkedToDoor(theEntity, CheckedTriggers, Door)) { return true; }
} }
END_FOR_ALL_ENTITIES("trigger_once") END_FOR_ALL_ENTITIES("trigger_once")
FOR_ALL_ENTITIES("trigger_multiple", CBaseTrigger*) FOR_ALL_ENTITIES("trigger_multiple", CBaseTrigger*)
if (theEntity->m_sMaster && FStrEq(STRING(theEntity->m_sMaster), targetName)) if (theEntity->m_sMaster && FStrEq(STRING(theEntity->m_sMaster), targetName))
{ {
if (UTIL_IsTriggerLinkedToDoor(theEntity, Door)) { return true; } if (std::find(CheckedTriggers.begin(), CheckedTriggers.end(), theEntity) == CheckedTriggers.end() && UTIL_IsTriggerLinkedToDoor(theEntity, CheckedTriggers, Door)) { return true; }
} }
END_FOR_ALL_ENTITIES("trigger_multiple") END_FOR_ALL_ENTITIES("trigger_multiple")
@ -7444,10 +7446,13 @@ bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door)
{ {
CBaseEntity* TargetEntity = UTIL_FindEntityByTargetname(NULL, STRING(ToggleRef->pev->target)); CBaseEntity* TargetEntity = UTIL_FindEntityByTargetname(NULL, STRING(ToggleRef->pev->target));
// Don't check this if it's targeting us (circular reference) const char* TestTriggerTargetname = STRING(TriggerEntity->pev->targetname);
if (TargetEntity && !FStrEq(STRING(TargetEntity->pev->target), STRING(TriggerEntity->pev->targetname))) const char* ThisTriggerTarget = STRING(TargetEntity->pev->target);
// Don't check this if it's targeting a trigger we've already checked
if (TargetEntity && std::find(CheckedTriggers.begin(), CheckedTriggers.end(), TargetEntity) == CheckedTriggers.end())
{ {
if (TargetEntity && UTIL_IsTriggerLinkedToDoor(TargetEntity, Door)) { return true; } if (TargetEntity && UTIL_IsTriggerLinkedToDoor(TargetEntity, CheckedTriggers, Door)) { return true; }
} }
FOR_ALL_ENTITIES("trigger_changetarget", CTriggerChangeTarget*) FOR_ALL_ENTITIES("trigger_changetarget", CTriggerChangeTarget*)
@ -7508,10 +7513,12 @@ void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& Trigge
if (!DoorRef) { return; } if (!DoorRef) { return; }
vector<CBaseEntity*> CheckedTriggerList;
while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "func_button")) != NULL) while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "func_button")) != NULL)
{ {
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, DoorRef)) CheckedTriggerList.clear();
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, CheckedTriggerList, DoorRef))
{ {
DoorActivationType NewTriggerType = DOOR_BUTTON; DoorActivationType NewTriggerType = DOOR_BUTTON;
@ -7527,11 +7534,13 @@ void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& Trigge
} }
TriggerRef = NULL; TriggerRef = NULL;
while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "avhweldable")) != NULL) while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "avhweldable")) != NULL)
{ {
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, DoorRef)) CheckedTriggerList.clear();
{ if (UTIL_IsTriggerLinkedToDoor(TriggerRef, CheckedTriggerList, DoorRef))
{
DoorActivationType NewTriggerType = DOOR_WELD; DoorActivationType NewTriggerType = DOOR_WELD;
DoorTrigger NewTrigger; DoorTrigger NewTrigger;
@ -7546,10 +7555,12 @@ void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& Trigge
} }
TriggerRef = NULL; TriggerRef = NULL;
CheckedTriggerList.clear();
while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "func_breakable")) != NULL) while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "func_breakable")) != NULL)
{ {
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, DoorRef)) CheckedTriggerList.clear();
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, CheckedTriggerList, DoorRef))
{ {
DoorActivationType NewTriggerType = DOOR_BREAK; DoorActivationType NewTriggerType = DOOR_BREAK;
@ -7568,7 +7579,8 @@ void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& Trigge
while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "trigger_once")) != NULL) while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "trigger_once")) != NULL)
{ {
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, DoorRef)) CheckedTriggerList.clear();
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, CheckedTriggerList, DoorRef))
{ {
DoorActivationType NewTriggerType = DOOR_TRIGGER; DoorActivationType NewTriggerType = DOOR_TRIGGER;
@ -7587,7 +7599,8 @@ void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& Trigge
while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "trigger_multiple")) != NULL) while ((TriggerRef = UTIL_FindEntityByClassname(TriggerRef, "trigger_multiple")) != NULL)
{ {
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, DoorRef)) CheckedTriggerList.clear();
if (UTIL_IsTriggerLinkedToDoor(TriggerRef, CheckedTriggerList, DoorRef))
{ {
DoorActivationType NewTriggerType = DOOR_TRIGGER; DoorActivationType NewTriggerType = DOOR_TRIGGER;
@ -8046,7 +8059,8 @@ void UTIL_UpdateDoorTriggers(nav_door* Door)
else else
{ {
const char* classname = STRING(ActivationTarget->pev->classname); const char* classname = STRING(ActivationTarget->pev->classname);
it->bIsActivated = UTIL_IsTriggerLinkedToDoor(ActivationTarget, Door->DoorEntity); vector<CBaseEntity*> CheckedTriggerList;
it->bIsActivated = UTIL_IsTriggerLinkedToDoor(ActivationTarget, CheckedTriggerList, Door->DoorEntity);
} }
} }
} }
@ -8274,6 +8288,8 @@ void UTIL_PopulateDoors()
nav_door* UTIL_GetNavDoorByEdict(const edict_t* DoorEdict) nav_door* UTIL_GetNavDoorByEdict(const edict_t* DoorEdict)
{ {
if (FNullEnt(DoorEdict)) { return nullptr; }
for (auto it = NavDoors.begin(); it != NavDoors.end(); it++) for (auto it = NavDoors.begin(); it != NavDoors.end(); it++)
{ {
if (it->DoorEdict == DoorEdict) if (it->DoorEdict == DoorEdict)

View file

@ -470,7 +470,7 @@ void UTIL_UpdateDoorTriggers(nav_door* Door);
void UTIL_ModifyOffMeshConnectionFlag(AvHAIOffMeshConnection* Connection, const unsigned int NewFlag); void UTIL_ModifyOffMeshConnectionFlag(AvHAIOffMeshConnection* Connection, const unsigned int NewFlag);
bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, CBaseEntity* Door); bool UTIL_IsTriggerLinkedToDoor(CBaseEntity* TriggerEntity, vector<CBaseEntity*>& CheckedTriggers, CBaseEntity* Door);
void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& TriggerList); void UTIL_PopulateTriggersForEntity(edict_t* Entity, vector<DoorTrigger>& TriggerList);
void UTIL_PopulateAffectedConnectionsForDoor(nav_door* Door); void UTIL_PopulateAffectedConnectionsForDoor(nav_door* Door);