Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
PatrolNoAttackAI.inc.c
Go to the documentation of this file.
1#ifndef _PATROL_AI_NO_ATTACK_
2#define _PATROL_AI_NO_ATTACK_
3
4#include "common.h"
5#include "npc.h"
6
7// prerequisites
9
10API_CALLABLE(N(PatrolNoAttackAI_Main)) {
11 Enemy* enemy = script->owner1.enemy;
12 Npc* npc = get_npc_unsafe(enemy->npcID);
13 Bytecode* args = script->ptrReadPos;
14 EnemyDetectVolume territory;
15 EnemyDetectVolume* territoryPtr = &territory;
16 MobileAISettings* npcAISettings = (MobileAISettings*)evt_get_variable(script, *args++);
17 f32 posX, posY, posZ, posW;
18
19 territory.skipPlayerDetectChance = 0;
20 territory.shape = enemy->territory->patrol.detectShape;
21 territory.pointX = enemy->territory->patrol.detectPos.x;
22 territory.pointZ = enemy->territory->patrol.detectPos.z;
23 territory.sizeX = enemy->territory->patrol.detectSize.x;
24 territory.sizeZ = enemy->territory->patrol.detectSize.z;
25 territory.halfHeight = 65.0f;
26 territory.detectFlags = 0;
27
28 if (isInitialCall || enemy->aiFlags & AI_FLAG_SUSPEND) {
29 script->AI_TEMP_STATE = AI_STATE_PATROL_INIT;
30 npc->duration = 0;
32
33 npc->flags &= ~NPC_FLAG_JUMPING;
34 if (!enemy->territory->patrol.isFlying) {
35 npc->flags |= NPC_FLAG_GRAVITY;
36 npc->flags &= ~NPC_FLAG_FLYING;
37 } else {
38 npc->flags &= ~NPC_FLAG_GRAVITY;
39 npc->flags |= NPC_FLAG_FLYING;
40 }
41
42 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
43 script->AI_TEMP_STATE = AI_STATE_SUSPEND;
44 script->functionTemp[1] = 0;
45 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
46 } else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
47 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
48 enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
49 }
50
51 posX = npc->pos.x;
52 posY = npc->pos.y + npc->collisionHeight;
53 posZ = npc->pos.z;
54 posW = 100.0f;
55
56 if (npc_raycast_down_sides(npc->collisionChannel, &posX, &posY, &posZ, &posW)) {
57 npc->pos.y = posY;
58 }
59 }
60
61 switch (script->AI_TEMP_STATE) {
63 N(PatrolAI_MoveInit)(script, npcAISettings, territoryPtr);
64 // fallthrough
65 case AI_STATE_PATROL:
66 N(PatrolAI_Move)(script, npcAISettings, territoryPtr);
67 break;
69 N(PatrolAI_LoiterInit)(script, npcAISettings, territoryPtr);
70 // fallthrough
71 case AI_STATE_LOITER:
72 N(PatrolAI_Loiter)(script, npcAISettings, territoryPtr);
73 break;
75 N(PatrolAI_PostLoiter)(script, npcAISettings, territoryPtr);
76 break;
78 N(PatrolAI_JumpInit)(script, npcAISettings, territoryPtr);
79 // fallthrough
80 case AI_STATE_ALERT:
81 N(PatrolAI_Jump)(script, npcAISettings, territoryPtr);
82 break;
84 N(PatrolAI_ChaseInit)(script, npcAISettings, territoryPtr);
85 // fallthrough
86 case AI_STATE_CHASE:
87 N(PatrolAI_Chase)(script, npcAISettings, territoryPtr);
88 break;
90 N(PatrolAI_LosePlayer)(script, npcAISettings, territoryPtr);
91 break;
93 N(PatrolNoAttackAI_15)(script, npcAISettings, territoryPtr);
94 break;
96 basic_ai_suspend(script);
97 break;
98 }
99 return ApiStatus_BLOCK;
100}
101
102#endif
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 PatrolNoAttackAI_15(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)
#define npc_raycast_down_sides
@ 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_LOITER_INIT
Definition enums.h:4587
@ AI_STATE_ALERT
Definition enums.h:4591
@ AI_STATE_PATROL_15
Definition enums.h:4595
@ 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_PATROL_INIT
Definition enums.h:4583
@ AI_STATE_LOSE_PLAYER
Definition enums.h:4594
@ AI_STATE_ALERT_INIT
Definition enums.h:4590
@ 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
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
s32 collisionChannel
s16 collisionHeight
Vec3f pos
s16 duration