Giving an NPC Memory: Difference between revisions
Jump to navigation
Jump to search
Tip:The functions below are all in
mNo edit summary |
No edit summary |
||
| (5 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
{{npc tut}} | {{npc tut}} | ||
== | == Entity memory == | ||
*<code> | |||
=== 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>void UpdateEnemyMemory( [[CBaseEntity]] *pEnemy, const [[Vector]] &position, [[CBaseEntity]] *pInformer )</code> | |||
: Adds or updates an enemy. | |||
; <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 === | |||
; <code>RememberUnreachable( [[CBaseEntity]] *pEntity, [[float]] duration = -1 )</code> | |||
: Causes the NPC to ignore the entity for the specified number of seconds. -1 means the AI's default, which is usually 3 seconds. | |||
; <code>IsUnreachable([[CBaseEntity]] *pEntity)</code> | |||
: Test reachability. | |||
== Memory Bits == | |||
'''Memory bits''' are [[flag]]s which relate to the NPC's current state (for example, <code>bits_MEMORY_SUSPICIOUS</code> and <code>bits_MEMORY_FLINCHED</code>). See <code>game/server/ai_basenpc.h</code> for a full list. | |||
;<code>Remember([[int]] iMemory)</code> | |||
;<code>Forget([[int]] iMemory)</code> | |||
: Set/remove a particular bit. | |||
;<code>HasMemory([[int]] iMemory)</code> | |||
;<code>HasAllMemories([[int]] iMemory)</code> | |||
: Check whether one or more memory bits are set. | |||
;<code>CAI_SchedulesManager::GetMemoryID(const [[char]] *state_name)</code> | |||
: Modify this function to add support for extra memory bits in schedule definitions. You shouldn't need to call it yourself. | |||
{{navbar|Defining the NPC|Creating an NPC|Creating a condition}} | {{navbar|Defining the NPC|Creating an NPC|Creating a condition}} | ||
[[Category:AI Programming]] | |||
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.