Giving an NPC Memory: Difference between revisions
Jump to navigation
Jump to search
Tip:The functions below are all in
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
== Entity memory == | == Entity memory == | ||
=== Enemies === | |||
==== Current ==== | |||
An NPC's current target is managed with these functions: | |||
; <code>[[bool]] ChooseEnemy()</code> | |||
; <code>void SetEnemy( [[CBaseEntity]] *pEnemy, [[bool]] bSetCondNewEnemy )</code> | |||
; <code>[[CBaseEntity]]* GetEnemy()</code> | |||
; <code>[[CBaseCombatCharacter]]* GetEnemyCombatCharacterPointer()</code> | |||
; <code>[[float]] GetTimeEnemyAcquired()</code> | |||
: Gets and sets the current enemy and the time at which they were acquired. Choosing is preferred over setting. | |||
; <code>void OnEnemyChanged( [[CBaseEntity]] *pOldEnemy, [[CBaseEntity]] *pNewEnemy )</code> | |||
: Callback, by default does nothing. | |||
=== | ==== Available ==== | ||
The list of available enemies is managed by the <code>CAI_Enemies</code> class. ''Crucially, the same <code>CAI_Enemies</code> object is shared between all members of a squad.'' | |||
{{tip|The functions below are all in <code>CAI_BaseNPC</code>. Use <code>GetEnemies()</code> to access the enemy list directly.}} | |||
; <code>UpdateEnemyMemory( [[CBaseEntity]] *pEnemy, const [[Vector]] &position, [[CBaseEntity]] *pInformer )</code> | ; <code>void UpdateEnemyMemory( [[CBaseEntity]] *pEnemy, const [[Vector]] &position, [[CBaseEntity]] *pInformer )</code> | ||
; <code> | : Adds or updates an enemy. | ||
; <code> | ; <code>[[Vector]] GetEnemyLKP()</code> | ||
; <code>[[float]] GetEnemyLastTimeSeen()</code> | |||
: The last position/time at which data on this enemy was updated. | |||
; <code>void MarkEnemyAsEluded()</code> | |||
; <code>[[bool]] EnemyHasEludedMe()</code> | |||
: Eluded enemies were seen, but are now at an unknown location. They are stored in enemy memory but not normally targeted. | |||
=== Unreachable === | === Unreachable === | ||
Latest revision as of 07:31, 12 September 2011
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.
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.