Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
GuardAI.inc.c File Reference

Go to the source code of this file.

Macros

#define _AI_GUARD_H_
 

Enumerations

enum  AiStateGuard { AI_STATE_GUARD_IDLE_INIT = 0 , AI_STATE_GUARD_IDLE = 1 , AI_STATE_GUARD_RETURN_HOME_INIT = 15 , AI_STATE_GUARD_RETURN_HOME = 16 }
 

Functions

void N GuardAI_IdleInit (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_Idle (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_AlertInit (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_Alert (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_ChaseInit (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_Chase (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *arg2)
 
void N GuardAI_LosePlayer (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_ReturnHomeInit (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N GuardAI_ReturnHome (Evt *script, GuardAISettings *aiSettings, EnemyDetectVolume *territory)
 

Macro Definition Documentation

◆ _AI_GUARD_H_

#define _AI_GUARD_H_

Definition at line 2 of file GuardAI.inc.c.

Enumeration Type Documentation

◆ AiStateGuard

Enumerator
AI_STATE_GUARD_IDLE_INIT 
AI_STATE_GUARD_IDLE 
AI_STATE_GUARD_RETURN_HOME_INIT 
AI_STATE_GUARD_RETURN_HOME 

Definition at line 14 of file GuardAI.inc.c.

14 {
19};
@ AI_STATE_GUARD_RETURN_HOME
Definition GuardAI.inc.c:18
@ AI_STATE_GUARD_RETURN_HOME_INIT
Definition GuardAI.inc.c:17
@ AI_STATE_GUARD_IDLE
Definition GuardAI.inc.c:16
@ AI_STATE_GUARD_IDLE_INIT
Definition GuardAI.inc.c:15

Function Documentation

◆ GuardAI_IdleInit()

void N GuardAI_IdleInit ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 25 of file GuardAI.inc.c.

25 {
26 Enemy* enemy = script->owner1.enemy;
27 Npc* npc = get_npc_unsafe(enemy->npcID);
28
30 script->AI_TEMP_STATE = AI_STATE_GUARD_IDLE;
31
32 if (enemy->flags & ENEMY_FLAG_SKIP_BATTLE) {
33 npc->yaw = enemy->varTable[0];
34 }
35
36 if (enemy->territory->wander.moveSpeedOverride <= 0) {
37 npc->moveSpeed = aiSettings->chaseSpeed;
38 } else {
39 npc->moveSpeed = enemy->territory->wander.moveSpeedOverride / 32767.0;
40 }
41}
union Evt::@8 owner1
Initially -1.
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ ENEMY_FLAG_SKIP_BATTLE
Definition enums.h:4541
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
s32 moveSpeedOverride
Definition npc.h:213
f32 chaseSpeed
Definition npc.h:111
EnemyTerritoryWander wander
Definition npc.h:232
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
AnimID curAnim
f32 moveSpeed

◆ GuardAI_Idle()

void N GuardAI_Idle ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 43 of file GuardAI.inc.c.

43 {
44 Enemy* enemy = script->owner1.enemy;
45 Npc* npc = get_npc_unsafe(enemy->npcID);
46 EffectInstance* emoteTemp;
47
48 if (aiSettings->playerSearchInterval >= 0 && basic_ai_check_player_dist(territory, enemy, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, 0)) {
49 fx_emote(EMOTE_EXCLAMATION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
51 npc->yaw = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
52
54 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
55 } else {
56 script->AI_TEMP_STATE = AI_STATE_ALERT_INIT;
57 }
58 }
59}
#define atan2
@ EMOTE_EXCLAMATION
Definition enums.h:495
@ AI_STATE_CHASE_INIT
Definition enums.h:4592
@ AI_STATE_ALERT_INIT
Definition enums.h:4590
@ SOUND_AI_ALERT_A
Definition enums.h:1078
@ AI_ACTION_JUMP_WHEN_SEE_PLAYER
Definition enums.h:4612
@ SOUND_PARAM_MORE_QUIET
Definition enums.h:1746
void ai_enemy_play_sound(Npc *npc, s32 arg1, s32 arg2)
Definition 23680.c:543
f32 chaseOffsetDist
Definition npc.h:115
f32 chaseRadius
Definition npc.h:114
s32 basic_ai_check_player_dist(EnemyDetectVolume *arg0, Enemy *arg1, f32 arg2, f32 arg3, b8 arg4)
Definition 23680.c:429
s16 actionFlags
Definition npc.h:156
s32 playerSearchInterval
Definition npc.h:110
NpcSettings * npcSettings
Definition npc.h:304
s16 collisionHeight
Vec3f pos
PlayerStatus * gPlayerStatusPtr

◆ GuardAI_AlertInit()

void N GuardAI_AlertInit ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 61 of file GuardAI.inc.c.

61 {
62 Npc* npc = get_npc_unsafe(script->owner1.enemy->npcID);
63
64 npc->jumpVel = 10.0f;
65 npc->jumpScale = 2.0f;
66 npc->moveToPos.y = npc->pos.y;
67 npc->flags |= NPC_FLAG_JUMPING;
68 script->AI_TEMP_STATE = AI_STATE_ALERT;
69}
@ AI_STATE_ALERT
Definition enums.h:4591
@ NPC_FLAG_JUMPING
Definition enums.h:3009
f32 jumpScale
f32 jumpVel
s32 flags
Vec3f moveToPos

◆ GuardAI_Alert()

void N GuardAI_Alert ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 71 of file GuardAI.inc.c.

71 {
72 Npc* npc = get_npc_unsafe(script->owner1.enemy->npcID);
73
74 npc->pos.y += npc->jumpVel;
75 npc->jumpVel -= npc->jumpScale;
76
77 if (!(npc->pos.y > npc->moveToPos.y)) {
78 npc->pos.y = npc->moveToPos.y;
79 npc->jumpVel = 0.0f;
80 npc->flags &= ~NPC_FLAG_JUMPING;
81 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
82 }
83}

◆ GuardAI_ChaseInit()

void N GuardAI_ChaseInit ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 85 of file GuardAI.inc.c.

85 {
86 Enemy* enemy = script->owner1.enemy;
87 Npc* npc = get_npc_unsafe(enemy->npcID);
88 f32 tempAngle;
89 f32 angleDiff;
90
91 npc->duration = (aiSettings->chaseUpdateInterval / 2) + rand_int(aiSettings->chaseUpdateInterval / 2 + 1);
93 npc->moveSpeed = aiSettings->chaseSpeed;
94
95 tempAngle = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
96 angleDiff = get_clamped_angle_diff(npc->yaw, tempAngle);
97
98 if (aiSettings->chaseTurnRate < fabsf(angleDiff)) {
99 tempAngle = npc->yaw;
100
101 if (angleDiff < 0.0f) {
102 tempAngle += -aiSettings->chaseTurnRate;
103 } else {
104 tempAngle += aiSettings->chaseTurnRate;
105 }
106 }
107
108 npc->yaw = clamp_angle(tempAngle);
109 script->AI_TEMP_STATE = AI_STATE_CHASE;
110}
#define rand_int
#define clamp_angle
@ ENEMY_ANIM_INDEX_CHASE
Definition enums.h:3429
@ AI_STATE_CHASE
Definition enums.h:4593
f32 fabsf(f32 f)
f32 get_clamped_angle_diff(f32, f32)
Definition 43F0.c:606
s32 chaseUpdateInterval
Definition npc.h:113
s32 chaseTurnRate
Definition npc.h:112
s16 duration

◆ GuardAI_Chase()

void N GuardAI_Chase ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * arg2 )

Definition at line 112 of file GuardAI.inc.c.

112 {
113 Enemy* enemy = script->owner1.enemy;
114 Npc* npc = get_npc_unsafe(enemy->npcID);
115 EffectInstance* emoteTemp;
116
117 if (!basic_ai_check_player_dist(arg2, enemy, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, 1)) {
118 fx_emote(EMOTE_QUESTION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
120 npc->duration = 25;
121 script->AI_TEMP_STATE = AI_STATE_LOSE_PLAYER;
122 } else {
123 npc_move_heading(npc, npc->moveSpeed, npc->yaw);
125 npc->duration--;
126 if (npc->duration == 0) {
127 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
128 }
129 }
130}
@ EMOTE_QUESTION
Definition enums.h:497
@ AI_STATE_LOSE_PLAYER
Definition enums.h:4594
@ SURFACE_INTERACT_RUN
Definition enums.h:4685
void npc_surface_spawn_fx(Npc *npc, SurfaceInteractMode mode)
Definition surfaces.c:394
void npc_move_heading(Npc *npc, f32 speed, f32 yaw)
Definition npc.c:986

◆ GuardAI_LosePlayer()

void N GuardAI_LosePlayer ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 132 of file GuardAI.inc.c.

132 {
133 Npc* npc = get_npc_unsafe(script->owner1.enemy->npcID);
134
135 npc->duration--;
136 if (npc->duration == 0) {
137 script->AI_TEMP_STATE = AI_STATE_GUARD_RETURN_HOME_INIT;
138 }
139}

◆ GuardAI_ReturnHomeInit()

void N GuardAI_ReturnHomeInit ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 141 of file GuardAI.inc.c.

141 {
142 Enemy* enemy = script->owner1.enemy;
143 Npc* npc = get_npc_unsafe(enemy->npcID);
144
146 if (enemy->territory->wander.moveSpeedOverride < 0) {
147 npc->moveSpeed = aiSettings->chaseSpeed * 0.3;
148 } else {
149 npc->moveSpeed = enemy->territory->wander.moveSpeedOverride / 32767.0;
150 }
151 script->functionTemp[1] = 0;
152 script->AI_TEMP_STATE = AI_STATE_GUARD_RETURN_HOME;
153}
@ ENEMY_ANIM_INDEX_WALK
Definition enums.h:3427

◆ GuardAI_ReturnHome()

void N GuardAI_ReturnHome ( Evt * script,
GuardAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 155 of file GuardAI.inc.c.

155 {
156 Enemy* enemy = script->owner1.enemy;
157 Npc* npc = get_npc_unsafe(enemy->npcID);
158 EffectInstance* emoteTemp;
159
160 if (aiSettings->playerSearchInterval >= 0) {
161 if (script->functionTemp[1] <= 0) {
162 script->functionTemp[1] = aiSettings->playerSearchInterval;
163 if (basic_ai_check_player_dist(territory, enemy, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, 0)) {
164 fx_emote(EMOTE_EXCLAMATION, npc, 0.0f, (f32) npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
166 npc->yaw = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
168 script->AI_TEMP_STATE = AI_STATE_ALERT_INIT;
169 } else {
170 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
171 }
172 return;
173 }
174 }
175 script->functionTemp[1]--;
176 }
177
178 if (dist2D(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z) < npc->moveSpeed) {
179 npc->pos.x = enemy->territory->wander.centerPos.x;
180 npc->pos.z = enemy->territory->wander.centerPos.z;
181 npc->yaw = enemy->territory->wander.wanderSize.x;
182 script->AI_TEMP_STATE = AI_STATE_GUARD_IDLE_INIT;
183 }
184
185 if (npc->turnAroundYawAdjustment == 0) {
186 npc->yaw = atan2(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z);
187 npc_move_heading(npc, npc->moveSpeed, npc->yaw);
188 }
189}
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
VecXZi wanderSize
Definition npc.h:212
s16 turnAroundYawAdjustment