Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
ClubbaPatrolAI.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "world/partners.h"
3
4// prerequisites
7
8API_CALLABLE(N(ClubbaPatrolAI_Main)) {
9 Enemy* enemy = script->owner1.enemy;
10 Npc* npc = get_npc_unsafe(enemy->npcID);
11 Bytecode* args = script->ptrReadPos;
12 EnemyDetectVolume territory;
13 EnemyDetectVolume* territoryPtr = &territory;
14 MobileAISettings* npcAISettings = (MobileAISettings*)evt_get_variable(script, *args++);
15
16 territory.skipPlayerDetectChance = 0;
17 territory.shape = enemy->territory->patrol.detectShape;
18 territory.pointX = enemy->territory->patrol.detectPos.x;
19 territory.pointZ = enemy->territory->patrol.detectPos.z;
20 territory.sizeX = enemy->territory->patrol.detectSize.x;
21 territory.sizeZ = enemy->territory->patrol.detectSize.z;
22 territory.halfHeight = 65.0f;
23 territory.detectFlags = 0;
24
25 if (isInitialCall || (enemy->aiFlags & AI_FLAG_SUSPEND)) {
26 script->AI_TEMP_STATE = AI_STATE_PATROL_INIT;
27 npc->duration = 0;
29 npc->flags &= ~NPC_FLAG_JUMPING;
30 if (!enemy->territory->patrol.isFlying) {
31 npc->flags |= NPC_FLAG_GRAVITY;
32 npc->flags &= ~NPC_FLAG_FLYING;
33 } else {
34 npc->flags &= ~NPC_FLAG_GRAVITY;
35 npc->flags |= NPC_FLAG_FLYING;
36 }
37 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
38 script->AI_TEMP_STATE = AI_STATE_SUSPEND;
39 script->functionTemp[1] = AI_STATE_PATROL_INIT;
40 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
41 }
42 enemy->varTable[0] = 0;
43 }
44
45 if ((script->AI_TEMP_STATE < AI_STATE_MELEE_HITBOX_INIT) && (enemy->varTable[0] == 0) && N(MeleeHitbox_CanSeePlayer)(script)) {
46 script->AI_TEMP_STATE = AI_STATE_MELEE_HITBOX_INIT;
47 }
48
49 switch (script->AI_TEMP_STATE) {
51 N(PatrolAI_MoveInit)(script, npcAISettings, territoryPtr);
52 // fallthrough
53 case AI_STATE_PATROL:
54 N(PatrolAI_Move)(script, npcAISettings, territoryPtr);
55 break;
57 N(PatrolAI_LoiterInit)(script, npcAISettings, territoryPtr);
58 // fallthrough
59 case AI_STATE_LOITER:
60 N(PatrolAI_Loiter)(script, npcAISettings, territoryPtr);
61 break;
63 N(PatrolAI_PostLoiter)(script, npcAISettings, territoryPtr);
64 break;
66 N(PatrolAI_JumpInit)(script, npcAISettings, territoryPtr);
67 // fallthrough
68 case AI_STATE_ALERT:
69 N(PatrolAI_Jump)(script, npcAISettings, territoryPtr);
70 break;
72 N(PatrolAI_ChaseInit)(script, npcAISettings, territoryPtr);
73 // fallthrough
74 case AI_STATE_CHASE:
75 N(PatrolAI_Chase)(script, npcAISettings, territoryPtr);
76 break;
78 N(PatrolAI_LosePlayer)(script, npcAISettings, territoryPtr);
79 break;
81 N(MeleeHitbox_30)(script);
82 // fallthrough
84 N(MeleeHitbox_31)(script);
85 if (script->functionTemp[0] != AI_STATE_MELEE_HITBOX_ACTIVE) {
86 break;
87 }
88 // fallthrough
90 N(MeleeHitbox_32)(script);
91 if (script->functionTemp[0] != AI_STATE_MELEE_HITBOX_MISS) {
92 break;
93 }
94 // fallthrough
96 N(MeleeHitbox_33)(script);
97 break;
99 basic_ai_suspend(script);
100 break;
101 }
102
103 return ApiStatus_BLOCK;
104}
void N MeleeHitbox_31(Evt *script)
void N MeleeHitbox_32(Evt *script)
s32 N MeleeHitbox_CanSeePlayer(Evt *script)
void N MeleeHitbox_33(Evt *script)
void N MeleeHitbox_30(Evt *script)
void N PatrolAI_MoveInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_PostLoiter(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Loiter(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Jump(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_JumpInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_ChaseInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Chase(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_Move(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N PatrolAI_LosePlayer(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ AI_STATE_LOITER
Definition enums.h:4588
@ AI_STATE_SUSPEND
Definition enums.h:4598
@ AI_STATE_MELEE_HITBOX_INIT
Definition enums.h:4600
@ AI_STATE_MELEE_HITBOX_ACTIVE
Definition enums.h:4602
@ AI_STATE_LOITER_INIT
Definition enums.h:4587
@ AI_STATE_ALERT
Definition enums.h:4591
@ AI_STATE_CHASE_INIT
Definition enums.h:4592
@ AI_STATE_LOITER_POST
Definition enums.h:4589
@ AI_STATE_CHASE
Definition enums.h:4593
@ AI_STATE_PATROL
Definition enums.h:4584
@ AI_STATE_MELEE_HITBOX_MISS
Definition enums.h:4603
@ AI_STATE_PATROL_INIT
Definition enums.h:4583
@ AI_STATE_LOSE_PLAYER
Definition enums.h:4594
@ AI_STATE_MELEE_HITBOX_PRE
Definition enums.h:4601
@ AI_STATE_ALERT_INIT
Definition enums.h:4590
@ NPC_FLAG_FLYING
Definition enums.h:3001
@ NPC_FLAG_GRAVITY
Definition enums.h:3007
s32 Bytecode
Definition evt.h:7
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
void PatrolAI_LoiterInit(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void basic_ai_suspend(Evt *script)
Definition 25AF0.c:13
enum TerritoryShape shape
Definition npc.h:201
s16 npcID
Definition npc.h:300
s32 * animList
Definition npc.h:341
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
VecXZi detectSize
Definition npc.h:226
s16 detectFlags
Definition npc.h:207
EnemyTerritoryPatrol patrol
Definition npc.h:233
u32 aiFlags
Definition npc.h:332
s32 skipPlayerDetectChance
Definition npc.h:200
enum TerritoryShape detectShape
Definition npc.h:227
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
s32 flags
AnimID curAnim
s16 duration