Creating a task: Difference between revisions
(the task needs to be declared with DECLARE_TASK or else it won't work at all) |
mNo edit summary |
||
Line 16: | Line 16: | ||
DECLARE_TASK(TASK_GOOMBA_WALK_STRAIGHT) | DECLARE_TASK(TASK_GOOMBA_WALK_STRAIGHT) | ||
</pre> | </pre> | ||
<!--- Someone's been playing Super Mario lately eh? ---> | |||
That line goes under AI_BEGIN_CUSTOM_NPC( npc_custom, CNPC_Custom ). | That line goes under AI_BEGIN_CUSTOM_NPC( npc_custom, CNPC_Custom ). | ||
Revision as of 04:44, 2 January 2008
Custom tasks may be added to your NPC by first declaring a new enum.
enum { TASK_JUMP = LAST_SHARED_TASK, TASK_FIND_DODGE_DIRECTION, };
After that, the task should be declared like this:
DECLARE_TASK(TASK_GOOMBA_WALK_STRAIGHT)
That line goes under AI_BEGIN_CUSTOM_NPC( npc_custom, CNPC_Custom ).
Then you would need to add the tasks in your custom schedule in the order you wish them to execute, notice TASK_FIND_DODGE_DIRECTION
has been given a value of 3, you can pass data through with your tasks and use them when the task logic is executed.
AI_BEGIN_CUSTOM_NPC( npc_custom, CNPC_Custom ) DEFINE_SCHEDULE ( SCHED_DODGE_ENEMY_FIRE, " Tasks" " TASK_FIND_DODGE_DIRECTION 3" " TASK_JUMP 0" "" " Interrupts" " COND_LIGHT_DAMAGE" ); AI_END_CUSTOM_NPC()
We need to also provide some logic that will be executed for each task, we can do this by overriding the method StartTask( const Task_t *pTask )
and RunTask( const Task_t *pTask )
of CAI_BaseNPC
. As mentioned you can grab the data passed through with the task in these methods by using pTask->flTaskData
. An example is shown below.
void CNPC_Custom :StartTask( const Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_FIND_DODGE_DIRECTION: { if(!FindBestDodgeDirection(pTask->flTaskData)) { TaskFail( "TASK_FIND_DODGE_DIRECTION: Unable to find suitable dodge direction\n" ); } else { TaskComplete(); } } break; case TASK_JUMP: { Jump(); } break; default: { BaseClass::StartTask( pTask ); } } }