Giving an NPC Memory

From Valve Developer Community
Jump to navigation Jump to search

Entity memory

Enemies

Current

An NPC's current target is managed with these functions:

bool ChooseEnemy()
void SetEnemy( CBaseEntity *pEnemy, bool bSetCondNewEnemy )
CBaseEntity* GetEnemy()
CBaseCombatCharacter* GetEnemyCombatCharacterPointer()
float GetTimeEnemyAcquired()
Gets and sets the current enemy and the time at which they were acquired. Choosing is preferred over setting.
void OnEnemyChanged( CBaseEntity *pOldEnemy, CBaseEntity *pNewEnemy )
Callback, by default does nothing.

Available

The list of available enemies is managed by the CAI_Enemies class. Crucially, the same CAI_Enemies object is shared between all members of a squad.

Tip.pngTip:The functions below are all in CAI_BaseNPC. Use GetEnemies() to access the enemy list directly.
void UpdateEnemyMemory( CBaseEntity *pEnemy, const Vector &position, CBaseEntity *pInformer )
Adds or updates an enemy.
Vector GetEnemyLKP()
float GetEnemyLastTimeSeen()
The last position/time at which data on this enemy was updated.
void MarkEnemyAsEluded()
bool EnemyHasEludedMe()
Eluded enemies were seen, but are now at an unknown location. They are stored in enemy memory but not normally targeted.

Unreachable

RememberUnreachable( CBaseEntity *pEntity, float duration = -1 )
Causes the NPC to ignore the entity for the specified number of seconds. -1 means the AI's default, which is usually 3 seconds.
IsUnreachable(CBaseEntity *pEntity)
Test reachability.

Memory Bits

Memory bits are flags which relate to the NPC's current state (for example, bits_MEMORY_SUSPICIOUS and bits_MEMORY_FLINCHED). See game/server/ai_basenpc.h for a full list.

Remember(int iMemory)
Forget(int iMemory)
Set/remove a particular bit.
HasMemory(int iMemory)
HasAllMemories(int iMemory)
Check whether one or more memory bits are set.
CAI_SchedulesManager::GetMemoryID(const char *state_name)
Modify this function to add support for extra memory bits in schedule definitions. You shouldn't need to call it yourself.