Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
RangedAttackAI.inc.c
Go to the documentation of this file.
1// Used by:
2// - Monty Mole
3// - Spy Guy
4// - Dry Bones
5// - Hammer Bros
6
7#include "common.h"
8#include "npc.h"
9#include "effects.h"
10
11// prerequisites
13
14API_CALLABLE(N(RangedAttackAI_Main)) {
15 EnemyDetectVolume territory;
16 EnemyDetectVolume* territoryPtr = &territory;
17 Enemy* enemy = script->owner1.enemy;
18 Bytecode* args = script->ptrReadPos;
19 Npc* npc = get_npc_unsafe(enemy->npcID);
20 MobileAISettings* settings = (MobileAISettings*) evt_get_variable(script, *args++);
21 f32 dist;
22
23 territory.skipPlayerDetectChance = 0;
24 territory.shape = enemy->territory->wander.detectShape;
25 territory.pointX = enemy->territory->wander.detectPos.x;
26 territory.pointZ = enemy->territory->wander.detectPos.z;
27 territory.sizeX = enemy->territory->wander.detectSize.x;
28 territory.sizeZ = enemy->territory->wander.detectSize.z;
29 territory.halfHeight = 40.0f;
30 territory.detectFlags = 0;
31
32 if (isInitialCall || (enemy->aiFlags & AI_FLAG_SUSPEND)) {
33 script->AI_TEMP_STATE = 0;
34 npc->duration = 0;
36 npc->flags &= ~NPC_FLAG_JUMPING;
37
38 if (!enemy->territory->wander.isFlying) {
39 npc->flags |= NPC_FLAG_GRAVITY;
40 npc->flags &= ~NPC_FLAG_FLYING;
41 } else {
42 npc->flags &= ~NPC_FLAG_GRAVITY;
43 npc->flags |= NPC_FLAG_FLYING;
44 }
45
46 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
47 script->AI_TEMP_STATE = AI_STATE_SUSPEND;
48 script->functionTemp[1] = 0;
49 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
50 } else if (enemy->flags & ENEMY_FLAG_BEGIN_WITH_CHASING) {
51 script->AI_TEMP_STATE = AI_STATE_CHASE_INIT;
52 }
53 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
54 enemy->flags &= ~ENEMY_FLAG_BEGIN_WITH_CHASING;
55 }
56
57 switch (script->AI_TEMP_STATE) {
59 basic_ai_wander_init(script, settings, territoryPtr);
60 // fallthrough
61 case AI_STATE_WANDER:
62 basic_ai_wander(script, settings, territoryPtr);
63 break;
65 basic_ai_loiter_init(script, settings, territoryPtr);
66 // fallthrough
67 case AI_STATE_LOITER:
68 basic_ai_loiter(script, settings, territoryPtr);
69 break;
71 basic_ai_found_player_jump_init(script, settings, territoryPtr);
72 // fallthrough
73 case AI_STATE_ALERT:
74 basic_ai_found_player_jump(script, settings, territoryPtr);
75 break;
77 dist = dist2D(npc->pos.x, npc->pos.z, gPlayerStatusPtr->pos.x, gPlayerStatusPtr->pos.z);
78 if (enemy->varTable[0] == 0 || enemy->varTable[0] < dist) {
79 N(UnkNpcAIFunc48)(script, settings->chaseRadius, settings->chaseOffsetDist, territoryPtr);
80 if (script->AI_TEMP_STATE != AI_STATE_CHASE_INIT) {
81 break;
82 }
83 }
84 basic_ai_chase_init(script, settings, territoryPtr);
85 // fallthrough
86 case AI_STATE_CHASE:
87 basic_ai_chase(script, settings, territoryPtr);
88 break;
90 basic_ai_lose_player(script, settings, territoryPtr);
91 break;
93 N(ProjectileHitbox_30(script));
94 break;
96 N(ProjectileHitbox_31(script));
97 break;
99 N(ProjectileHitbox_32(script));
100 break;
102 N(ProjectileHitbox_33(script));
103 break;
104 case AI_STATE_SUSPEND:
105 basic_ai_suspend(script);
106 break;
107 }
108 return ApiStatus_BLOCK;
109}
void N ProjectileHitbox_31(Evt *script)
void N ProjectileHitbox_33(Evt *script)
void N ProjectileHitbox_30(Evt *script)
void N UnkNpcAIFunc48(Evt *script, f32 arg1, f32 arg2, EnemyDetectVolume *territory)
void N ProjectileHitbox_32(Evt *script)
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ AI_STATE_PROJECTILE_HITBOX_30
Definition enums.h:4605
@ AI_STATE_WANDER
Definition enums.h:4582
@ AI_STATE_LOITER
Definition enums.h:4588
@ AI_STATE_SUSPEND
Definition enums.h:4598
@ AI_STATE_WANDER_INIT
Definition enums.h:4581
@ 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_CHASE
Definition enums.h:4593
@ AI_STATE_PROJECTILE_HITBOX_32
Definition enums.h:4607
@ AI_STATE_PROJECTILE_HITBOX_31
Definition enums.h:4606
@ AI_STATE_PROJECTILE_HITBOX_33
Definition enums.h:4608
@ 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 basic_ai_chase_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:769
void basic_ai_lose_player(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:847
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
void basic_ai_wander(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:588
void basic_ai_chase(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:804
void basic_ai_found_player_jump_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:735
void basic_ai_wander_init(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:567
void basic_ai_found_player_jump(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:748
void basic_ai_loiter_init(Evt *script, MobileAISettings *aiSettings, EnemyDetectVolume *territory)
Definition 23680.c:681
void basic_ai_suspend(Evt *script)
Definition 25AF0.c:13
void basic_ai_loiter(Evt *script, MobileAISettings *npcAISettings, EnemyDetectVolume *territory)
Definition 23680.c:691
enum TerritoryShape shape
Definition npc.h:201
s32 flags
Definition npc.h:295
VecXZi detectSize
Definition npc.h:216
enum TerritoryShape detectShape
Definition npc.h:217
s16 npcID
Definition npc.h:300
s32 * animList
Definition npc.h:341
Npc * get_npc_unsafe(s32 npcID)
Definition npc.c:995
s16 detectFlags
Definition npc.h:207
f32 chaseRadius
Definition npc.h:102
u32 aiFlags
Definition npc.h:332
s32 skipPlayerDetectChance
Definition npc.h:200
EnemyTerritoryWander wander
Definition npc.h:232
f32 chaseOffsetDist
Definition npc.h:103
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
s32 flags
AnimID curAnim
Vec3f pos
s16 duration
PlayerStatus * gPlayerStatusPtr