-
Notifications
You must be signed in to change notification settings - Fork 140
NPC memory fixes and NPC VScript expansions #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,6 +298,43 @@ CBaseEntity *CAI_Senses::GetNextSeenEntity( AISightIter_t *pIter ) const | |
return NULL; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
|
||
#ifdef MAPBASE | ||
bool CAI_Senses::GetSeenEntityIndex( AISightIter_t *pIter, CBaseEntity *pSightEnt, seentype_t iSeenType ) const | ||
{ | ||
COMPILE_TIME_ASSERT( sizeof( AISightIter_t ) == sizeof( AISightIterVal_t ) ); | ||
|
||
AISightIterVal_t *pIterVal = (AISightIterVal_t *)pIter; | ||
|
||
// If we're searching for a specific type, start in that array | ||
pIterVal->SeenArray = (char)iSeenType; | ||
int iFirstArray = ( iSeenType == SEEN_ALL ) ? 0 : iSeenType; | ||
|
||
for ( int i = iFirstArray; i < ARRAYSIZE( m_SeenArrays ); i++ ) | ||
{ | ||
for ( int j = pIterVal->iNext; j < m_SeenArrays[i]->Count(); j++ ) | ||
{ | ||
if ( (*m_SeenArrays[i])[j].Get() == pSightEnt ) | ||
{ | ||
pIterVal->array = i; | ||
pIterVal->iNext = j+1; | ||
return true; | ||
} | ||
} | ||
pIterVal->iNext = 0; | ||
|
||
// If we're searching for a specific type, don't move to the next array | ||
if ( pIterVal->SeenArray != SEEN_ALL ) | ||
break; | ||
} | ||
|
||
(*pIter) = (AISightIter_t)(-1); | ||
return false; | ||
} | ||
#endif | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
|
||
void CAI_Senses::BeginGather() | ||
|
@@ -749,4 +786,27 @@ void CAI_SensedObjectsManager::AddEntity( CBaseEntity *pEntity ) | |
m_SensedObjects.AddToTail( pEntity ); | ||
} | ||
|
||
#ifdef MAPBASE | ||
void CAI_SensedObjectsManager::RemoveEntity( CBaseEntity *pEntity ) | ||
{ | ||
int i = m_SensedObjects.Find( pEntity ); | ||
if (i == m_SensedObjects.InvalidIndex()) | ||
return; | ||
|
||
pEntity->RemoveFlag( FL_OBJECT ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does removing this flag from the entity do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It prevents the entity from being sensed anymore. |
||
m_SensedObjects.FastRemove( i ); | ||
} | ||
#endif | ||
|
||
//----------------------------------------------------------------------------- | ||
|
||
#ifdef MAPBASE_VSCRIPT | ||
BEGIN_SCRIPTDESC_ROOT( CAI_SensedObjectsManager, SCRIPT_SINGLETON "Manager which handles sensed objects." ) | ||
|
||
DEFINE_SCRIPTFUNC_NAMED( ScriptAddEntity, "AddEntity", "Adds an entity to the sensed object list." ) | ||
DEFINE_SCRIPTFUNC_NAMED( ScriptRemoveEntity, "RemoveEntity", "Removes an entity from the sensed object list." ) | ||
|
||
END_SCRIPTDESC(); | ||
#endif | ||
|
||
//============================================================================= |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,10 @@ | |
|
||
CAI_SquadManager g_AI_SquadManager; | ||
|
||
#ifdef MAPBASE | ||
ConVar ai_squad_broadcast_elusion("ai_squad_broadcast_elusion", "0", FCVAR_NONE, "Tells the entire squad when an enemy is eluded"); | ||
#endif | ||
|
||
//----------------------------------------------------------------------------- | ||
// CAI_SquadManager | ||
// | ||
|
@@ -740,6 +744,25 @@ void CAI_Squad::UpdateEnemyMemory( CAI_BaseNPC *pUpdater, CBaseEntity *pEnemy, c | |
|
||
//------------------------------------------------------------------------------ | ||
|
||
#ifdef MAPBASE | ||
void CAI_Squad::MarkEnemyAsEluded( CAI_BaseNPC *pUpdater, CBaseEntity *pEnemy ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is gated by a convar, there isn't really any concern about it affecting normal gameplay. But I have to wonder what happens if one NPC in a squad can't see the enemy and another can. Isn't it possible an NPC could be marked as eluded while still being visible by another squad member? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's visible to another squad member, then the squad member will broadcast that to others in the squad and update the enemy's last known position. The eluded code only runs when the NPC is at the enemy's last known position and the enemy is nowhere to be found. I'm reasonably certain those two situations can't happen at once |
||
{ | ||
if (!ai_squad_broadcast_elusion.GetBool()) | ||
return; | ||
|
||
//Broadcast to all members of the squad | ||
for ( int i = 0; i < m_SquadMembers.Count(); i++ ) | ||
{ | ||
if ( m_SquadMembers[i] != pUpdater ) | ||
{ | ||
m_SquadMembers[i]->GetEnemies()->MarkAsEluded( pEnemy ); | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
//------------------------------------------------------------------------------ | ||
|
||
#ifdef PER_ENEMY_SQUADSLOTS | ||
|
||
AISquadEnemyInfo_t *CAI_Squad::FindEnemyInfo( CBaseEntity *pEnemy ) | ||
|
@@ -883,14 +906,14 @@ void CAI_Squad::ScriptRemoveFromSquad( HSCRIPT hNPC ) { RemoveFromSquad( HScrip | |
|
||
bool CAI_Squad::ScriptIsSilentMember( HSCRIPT hNPC ) { return IsSilentMember( HScriptToClass<CAI_BaseNPC>( hNPC ) ); } | ||
|
||
void CAI_Squad::ScriptSetSquadData( int iSlot, const char *data ) | ||
void CAI_Squad::ScriptSetSquadData( int iSlot, int data ) | ||
{ | ||
SetSquadData( iSlot, data ); | ||
} | ||
|
||
const char *CAI_Squad::ScriptGetSquadData( int iSlot ) | ||
int CAI_Squad::ScriptGetSquadData( int iSlot ) | ||
{ | ||
const char *data; | ||
int data; | ||
GetSquadData( iSlot, &data ); | ||
return data; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,12 @@ class CAI_Squad | |
|
||
void SquadNewEnemy ( CBaseEntity *pEnemy ); | ||
void UpdateEnemyMemory( CAI_BaseNPC *pUpdater, CBaseEntity *pEnemy, const Vector &position ); | ||
#ifdef MAPBASE | ||
// The idea behind this is that, if one squad member fails to locate the enemy, nobody in the squad knows where the enemy is | ||
// Makes combat utilizing elusion a bit smoother | ||
// (gated by ai_squad_broadcast_elusion cvar) | ||
void MarkEnemyAsEluded( CAI_BaseNPC *pUpdater, CBaseEntity *pEnemy ); | ||
#endif | ||
|
||
bool OccupyStrategySlotRange( CBaseEntity *pEnemy, int slotIDStart, int slotIDEnd, int *pSlot ); | ||
void VacateStrategySlot( CBaseEntity *pEnemy, int slot); | ||
|
@@ -186,8 +192,8 @@ class CAI_Squad | |
|
||
bool ScriptIsSilentMember( HSCRIPT hNPC ); | ||
|
||
void ScriptSetSquadData( int iSlot, const char *data ); | ||
const char *ScriptGetSquadData( int iSlot ); | ||
void ScriptSetSquadData( int iSlot, int data ); | ||
int ScriptGetSquadData( int iSlot ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the intended purpose of this return type being changed from char* to int? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was one of the points in the PR description:
|
||
#endif | ||
|
||
private: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to reread the comment a couple of times before I understood this. Just to be absolutely clear: There is no chance that TASK_GET_PATH_TO_ENEMY_LKP could use this code? Is it worth preserving the original case just to be sure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is within a switch statement case that is used by
TASK_GET_PATH_TO_ENEMY_LOS
,TASK_GET_FLANK_RADIUS_PATH_TO_ENEMY_LOS
,TASK_GET_FLANK_ARC_PATH_TO_ENEMY_LOS
, andTASK_GET_PATH_TO_ENEMY_LKP_LOS
. The case forTASK_GET_PATH_TO_ENEMY_LKP
is farther above and does not fall back into this code.