Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
KoopaPatrolAI.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "npc.h"
3#include "effects.h"
4
6
8
9API_CALLABLE(N(KoopaPatrolAI_Main)) {
10 Enemy* enemy = script->owner1.enemy;
11 Npc* npc = get_npc_unsafe(enemy->npcID);
12 Bytecode* args = script->ptrReadPos;
13 EnemyDetectVolume territory;
14 EnemyDetectVolume* territoryPtr = &territory;
15 MobileAISettings* settings = (MobileAISettings*) evt_get_variable(script, *args++);
16
17 territory.skipPlayerDetectChance = 0;
18 territory.shape = enemy->territory->patrol.detectShape;
19 territory.pointX = enemy->territory->patrol.detectPos.x;
20 territory.pointZ = enemy->territory->patrol.detectPos.z;
21 territory.sizeX = enemy->territory->patrol.detectSize.x;
22 territory.sizeZ = enemy->territory->patrol.detectSize.z;
23 territory.halfHeight = 100.0f;
24 territory.detectFlags = 0;
25
26 if (isInitialCall) {
27 enemy->varTable[6] = npc->collisionHeight;
29 }
30
31 if (isInitialCall || (enemy->aiFlags & AI_FLAG_SUSPEND)) {
32 npc->duration = 0;
33 script->functionTemp[0] = 0;
34 enemy->hitboxIsActive = FALSE;
36 npc->flags &= ~NPC_FLAG_JUMPING;
37 npc->collisionHeight = enemy->varTable[6];
38 enemy->instigatorValue = 0;
39 enemy->varTable[8] = 0;
40
41 if (!enemy->territory->patrol.isFlying) {
42 npc->flags |= NPC_FLAG_GRAVITY;
43 npc->flags &= ~NPC_FLAG_FLYING;
44 } else {
45 npc->flags &= ~NPC_FLAG_GRAVITY;
46 npc->flags |= NPC_FLAG_FLYING;
47 }
48
49 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
50 EffectInstance* emoteTemp;
51
52 script->functionTemp[0] = 99;
53 script->functionTemp[1] = 0;
54 fx_emote(EMOTE_QUESTION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 40, &emoteTemp);
55 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
56 } else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
57 script->functionTemp[0] = AI_STATE_CHASE_INIT;
58 enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
59 }
60 }
61
62 switch (script->functionTemp[0]) {
63 case 0:
64 N(PatrolAI_MoveInit)(script, settings, territoryPtr);
65 npc->collisionHeight = enemy->varTable[6];
66 // fallthrough
67 case 1:
68 N(PatrolAI_Move)(script, settings, territoryPtr);
69 break;
70 case 2:
71 N(PatrolAI_LoiterInit)(script, settings, territoryPtr);
72 // fallthrough
73 case 3:
74 N(PatrolAI_Loiter)(script, settings, territoryPtr);
75 break;
76 case 4:
77 N(PatrolAI_PostLoiter)(script, settings, territoryPtr);
78 break;
79 case 12:
80 N(set_script_owner_npc_anim)(script, settings, territoryPtr);
81 // fallthrough
82 case 13:
83 N(UnkDistFunc)(script, settings, territoryPtr);
84 break;
85 case 14:
86 N(UnkNpcAIFunc12)(script, settings, territoryPtr);
87 break;
88 case 15:
89 N(set_script_owner_npc_col_height)(script, settings, territoryPtr);
90 break;
91 case 99:
92 basic_ai_suspend(script);
93 break;
94 }
95 return ApiStatus_BLOCK;
96}
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_Move(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N UnkNpcAIFunc12(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
ApiStatus N UnkDistFunc(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N set_script_owner_npc_col_height(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
void N set_script_owner_npc_anim(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
@ EMOTE_QUESTION
Definition enums.h:497
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ AI_FLAG_SKIP_EMOTE_AFTER_FLEE
Definition enums.h:4572
@ AI_STATE_CHASE_INIT
Definition enums.h:4592
@ ENEMY_FLAG_BEGIN_WITH_CHASING
Definition enums.h:4551
@ 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
s32 flags
Definition npc.h:295
s16 npcID
Definition npc.h:300
s8 instigatorValue
Definition npc.h:334
s32 * animList
Definition npc.h:341
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
VecXZi detectSize
Definition npc.h:226
s8 hitboxIsActive
Definition npc.h:299
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 collisionHeight
s16 duration