Giving an NPC Memory
An NPC's current target is managed with these functions:
void SetEnemy( CBaseEntity *pEnemy, bool bSetCondNewEnemy )
- 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.
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.
GetEnemies()to access the enemy list directly.
void UpdateEnemyMemory( CBaseEntity *pEnemy, const Vector &position, CBaseEntity *pInformer )
- Adds or updates an enemy.
- The last position/time at which data on this enemy was updated.
- Eluded enemies were seen, but are now at an unknown location. They are stored in enemy memory but not normally targeted.
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.
- Test reachability.
Memory bits are flags which relate to the NPC's current state (for example,
game/server/ai_basenpc.h for a full list.
- Set/remove a particular bit.
- 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.