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

Go to the source code of this file.

Functions

void N HoppingAI_HopInit (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N HoppingAI_Hop (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N HoppingAI_LoiterInit (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N HoppingAI_Loiter (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N HoppingAI_ChaseInit (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N HoppingAI_Chase (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 
void N HoppingAI_LosePlayer (Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
 

Function Documentation

◆ HoppingAI_HopInit()

void N HoppingAI_HopInit ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 5 of file HoppingAI.inc.c.

5 {
6 Enemy* enemy = script->owner1.enemy;
7 Npc* npc = get_npc_unsafe(enemy->npcID);
8 f32 x, y, z;
9 s32 i;
10
11 basic_ai_wander_init(script, aiSettings, territory);
12 npc->flags |= NPC_FLAG_JUMPING;
13 npc->jumpVel = (rand_int(45) / 10.0) + 8.0;
14 npc->jumpScale = 1.5f;
16
20 npc->pos.x, npc->pos.z,
22 {
23 npc->yaw = atan2(npc->pos.x, npc->pos.z, enemy->territory->wander.centerPos.x, enemy->territory->wander.centerPos.z);
24 x = npc->pos.x;
25 y = npc->pos.y;
26 z = npc->pos.z;
27
28 for (i = 0; i < 6; i++) {
29 if (npc_test_move_simple_with_slipping(npc->collisionChannel, &x, &y, &z, 25.0f,
30 npc->yaw, npc->collisionHeight, npc->collisionDiameter))
31 {
32 npc->yaw += 30.0;
33 } else {
34 break;
35 }
36 }
37 } else {
38 npc->yaw = clamp_angle(npc->yaw + rand_int(60) - 30.0f);
39 }
40}
union Evt::@8 owner1
Initially -1.
#define rand_int
#define clamp_angle
#define atan2
@ SOUND_SEQ_FUZZY_HOP
Definition enums.h:1722
@ NPC_FLAG_JUMPING
Definition enums.h:3009
b32 is_point_outside_territory(s32 shape, f32 centerX, f32 centerZ, f32 pointX, f32 pointZ, f32 sizeX, f32 sizeZ)
Definition 23680.c:412
void ai_enemy_play_sound(Npc *npc, s32 arg1, s32 arg2)
Definition 23680.c:543
b32 npc_test_move_simple_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void basic_ai_wander_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:567
s16 npcID
Definition npc.h:300
VecXZi wanderSize
Definition npc.h:212
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
enum TerritoryShape wanderShape
Definition npc.h:214
EnemyTerritoryWander wander
Definition npc.h:232
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
s16 collisionDiameter
f32 jumpScale
f32 jumpVel
s32 flags
s32 collisionChannel
s16 collisionHeight
Vec3f pos

◆ HoppingAI_Hop()

void N HoppingAI_Hop ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 42 of file HoppingAI.inc.c.

42 {
43 Enemy* enemy = script->owner1.enemy;
44 Npc* npc = get_npc_unsafe(enemy->npcID);
45 f32 posX, posY, posZ, hitDepth;
46
47 if (aiSettings->playerSearchInterval >= 0) {
48 if (script->functionTemp[1] <= 0) {
49 script->functionTemp[1] = aiSettings->playerSearchInterval;
50 if (basic_ai_check_player_dist(territory, enemy, aiSettings->alertRadius, aiSettings->alertOffsetDist, 0) != 0) {
51 EffectInstance* emoteTemp;
52 fx_emote(EMOTE_EXCLAMATION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
54 npc->yaw = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
55 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
56 return;
57 }
58 }
59 script->functionTemp[1]--;
60 }
61
62 if (npc->moveSpeed > 0.0) {
63 f32 collRadius;
64 f32 collHeight;
65 f32 moveSpeed;
66
67 posX = npc->pos.x;
68 posY = npc->pos.y;
69 posZ = npc->pos.z;
70 moveSpeed = npc->moveSpeed;
71 collHeight = npc->collisionHeight;
72 collRadius = npc->collisionDiameter;
73
75 &posX, &posY, &posZ,
76 moveSpeed, npc->yaw, collHeight, collRadius * 1.2))
77 {
78 npc_move_heading(npc, npc->moveSpeed, npc->yaw);
79 } else {
80 npc->moveSpeed = 0.0f;
81 }
82 }
83
84 if (npc->jumpVel < 0.0) {
85 posX = npc->pos.x;
86 posY = npc->pos.y + 13.0;
87 posZ = npc->pos.z;
88 hitDepth = fabsf(npc->jumpVel) + 16.0;
89
90 if (npc_raycast_down_sides(npc->collisionChannel, &posX, &posY, &posZ, &hitDepth) &&
91 hitDepth <= fabsf(npc->jumpVel) + 13.0)
92 {
93 npc->jumpVel = 0.0f;
94 npc->pos.y = posY;
95 npc->flags &= ~NPC_FLAG_JUMPING;
96 script->AI_TEMP_STATE = AI_STATE_LOITER_INIT;
97 script->functionTemp[1] = (rand_int(1000) % 3) + 2;
98
99 if (aiSettings->unk_AI_2C <= 0) {
100 script->AI_TEMP_STATE = AI_STATE_HOP_INIT;
101 } else if (aiSettings->moveTime <= 0) {
102 script->AI_TEMP_STATE = AI_STATE_HOP_INIT;
103 } else if (script->functionTemp[1] == 0) {
104 script->AI_TEMP_STATE = AI_STATE_HOP_INIT;
105 }
106 return;
107 }
108 }
109 npc->pos.y += npc->jumpVel;
110 npc->jumpVel -= npc->jumpScale;
111}
#define npc_raycast_down_sides
@ EMOTE_EXCLAMATION
Definition enums.h:495
@ AI_STATE_HOP_INIT
Definition enums.h:4585
@ AI_STATE_LOITER_INIT
Definition enums.h:4587
@ AI_STATE_CHASE_INIT
Definition enums.h:4592
@ SOUND_AI_ALERT_A
Definition enums.h:1078
@ SOUND_PARAM_MORE_QUIET
Definition enums.h:1746
f32 fabsf(f32 f)
s32 basic_ai_check_player_dist(EnemyDetectVolume *arg0, Enemy *arg1, f32 arg2, f32 arg3, b8 arg4)
Definition 23680.c:429
s32 moveTime
Definition npc.h:94
f32 alertOffsetDist
Definition npc.h:97
s32 playerSearchInterval
Definition npc.h:98
f32 alertRadius
Definition npc.h:96
void npc_move_heading(Npc *npc, f32 speed, f32 yaw)
Definition npc.c:986
s32 unk_AI_2C
Definition npc.h:104
f32 moveSpeed
PlayerStatus * gPlayerStatusPtr

◆ HoppingAI_LoiterInit()

void N HoppingAI_LoiterInit ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 113 of file HoppingAI.inc.c.

113 {
114 Enemy* enemy = script->owner1.enemy;
115 Npc* npc = get_npc_unsafe(enemy->npcID);
116
117 npc->duration = (aiSettings->waitTime / 2) + rand_int((aiSettings->waitTime / 2) + 1);
118 npc->yaw = clamp_angle(npc->yaw + rand_int(180) - 90.0f);
120 script->AI_TEMP_STATE = AI_STATE_LOITER;
121}
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_STATE_LOITER
Definition enums.h:4588
s32 waitTime
Definition npc.h:95
s32 * animList
Definition npc.h:341
AnimID curAnim
s16 duration

◆ HoppingAI_Loiter()

void N HoppingAI_Loiter ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 123 of file HoppingAI.inc.c.

123 {
124 Enemy* enemy = script->owner1.enemy;
125 Npc* npc = get_npc_unsafe(enemy->npcID);
126
127 if (aiSettings->playerSearchInterval >= 0 && basic_ai_check_player_dist(territory, enemy, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, 0) != 0) {
128 EffectInstance* emoteTemp;
129 fx_emote(EMOTE_EXCLAMATION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
131 npc->yaw = atan2(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
132 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
133 } else if (npc->turnAroundYawAdjustment == 0) {
134 npc->duration--;
135 if (npc->duration <= 0) {
136 script->functionTemp[1]--;
137 if (script->functionTemp[1] > 0) {
138 npc->yaw = clamp_angle(npc->yaw + 180.0f);
139 npc->duration = (rand_int(1000) % 11) + 5;
140 } else {
141 script->AI_TEMP_STATE = AI_STATE_HOP_INIT;
142 }
143 }
144 }
145}
f32 chaseRadius
Definition npc.h:102
f32 chaseOffsetDist
Definition npc.h:103
s16 turnAroundYawAdjustment

◆ HoppingAI_ChaseInit()

void N HoppingAI_ChaseInit ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 147 of file HoppingAI.inc.c.

147 {
148 Npc* enemy = get_npc_unsafe(script->owner1.enemy->npcID);
149
150 basic_ai_chase_init(script, aiSettings, territory);
151 enemy->flags |= ENEMY_FLAG_FLYING;
152 enemy->jumpVel = rand_int(5) + 10.0;
153 enemy->jumpScale = 1.5f;
154 enemy->yaw = atan2(enemy->pos.x, enemy->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
155 enemy->moveSpeed = aiSettings->chaseSpeed;
156 script->AI_TEMP_STATE = AI_STATE_CHASE;
158}
@ AI_STATE_CHASE
Definition enums.h:4593
@ ENEMY_FLAG_FLYING
Definition enums.h:4532
void basic_ai_chase_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:769
f32 chaseSpeed
Definition npc.h:99

◆ HoppingAI_Chase()

void N HoppingAI_Chase ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 160 of file HoppingAI.inc.c.

160 {
161 Enemy* enemy = script->owner1.enemy;
162 Npc* npc = get_npc_unsafe(enemy->npcID);
163 f32 posX, posY, posZ;
164 f32 groundY, hitDepth;
165 EffectInstance* emoteTemp;
166
167 if (npc->moveSpeed > 0.0) {
168 posX = npc->pos.x;
169 posY = npc->pos.y;
170 posZ = npc->pos.z;
171 if (npc_test_move_simple_with_slipping(npc->collisionChannel, &posX, &posY, &posZ, npc->moveSpeed, npc->yaw,
173 {
174 npc->moveSpeed = 0.0f;
175 } else {
176 npc_move_heading(npc, npc->moveSpeed, npc->yaw);
177 }
178 }
179
180 if (npc->jumpVel < 0.0) {
181 posX = npc->pos.x;
182 groundY = 100.0f;
183 posZ = npc->pos.z;
184 hitDepth = 1000.0f;
185 npc_raycast_down_sides(npc->collisionChannel, &posX, &groundY, &posZ, &hitDepth);
186
187 posX = npc->pos.x;
188 posY = npc->pos.y + 13.0;
189 posZ = npc->pos.z;
190 hitDepth = fabsf(npc->jumpVel) + 16.0;
191 if (npc_raycast_down_sides(npc->collisionChannel, &posX, &posY, &posZ, &hitDepth) && hitDepth <= fabsf(npc->jumpVel) + 13.0) {
192 npc->jumpVel = 0.0f;
193 npc->pos.y = posY;
194 npc->flags &= ~NPC_FLAG_JUMPING;
195 fx_walking_dust(2, npc->pos.x, npc->pos.y, npc->pos.z, 0.0f, 0.0f);
196 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
197
198 if (basic_ai_check_player_dist(territory, enemy, aiSettings->chaseRadius, aiSettings->chaseOffsetDist, 1) == 0) {
199 fx_emote(EMOTE_QUESTION, npc, 0.0f, npc->collisionHeight, 1.0f, 2.0f, -20.0f, 15, &emoteTemp);
200 npc->duration = 25;
201 script->AI_TEMP_STATE = AI_STATE_LOSE_PLAYER;
202 }
203 return;
204 }
205 }
206 npc->pos.y += npc->jumpVel;
207 npc->jumpVel -= npc->jumpScale;
208}
@ EMOTE_QUESTION
Definition enums.h:497
@ AI_STATE_LOSE_PLAYER
Definition enums.h:4594

◆ HoppingAI_LosePlayer()

void N HoppingAI_LosePlayer ( Evt * script,
MobileAISettings * aiSettings,
EnemyDetectVolume * territory )

Definition at line 210 of file HoppingAI.inc.c.

210 {
211 Npc* npc = get_npc_unsafe(script->owner1.enemy->npcID);
212
213 npc->duration--;
214 if (npc->duration <= 0) {
215 script->AI_TEMP_STATE = AI_STATE_HOP_INIT;
216 }
217}