Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
WanderMeleeAI.inc.c
Go to the documentation of this file.
1#ifndef _WANDER_MELEE_AI_
2#define _WANDER_MELEE_AI_
3
4// Used by:
5// - Clubba + White Clubba
6// - Spear Guy
7// - Piranha Plant
8// - Putrid Piranha + Frost Piranha
9
10#include "common.h"
11#include "npc.h"
12
13// prerequisites
15
16API_CALLABLE(N(WanderMeleeAI_Main)) {
17 Enemy* enemy = script->owner1.enemy;
18 Npc *npc = get_npc_unsafe(enemy->npcID);
19 Bytecode* args = script->ptrReadPos;
20 EnemyDetectVolume territory;
21 EnemyDetectVolume* territoryPtr = &territory;
22 MobileAISettings* npcAISettings = (MobileAISettings*)evt_get_variable(script, *args++);
23
24 territory.skipPlayerDetectChance = 0;
25 territory.shape = enemy->territory->wander.detectShape;
26 territory.pointX = enemy->territory->wander.detectPos.x;
27 territory.pointZ = enemy->territory->wander.detectPos.z;
28 territory.sizeX = enemy->territory->wander.detectSize.x;
29 territory.sizeZ = enemy->territory->wander.detectSize.z;
30 territory.halfHeight = 65.0f;
31 territory.detectFlags = 0;
32
33 if (isInitialCall || (enemy->aiFlags & AI_FLAG_SUSPEND)) {
34 script->AI_TEMP_STATE = AI_STATE_WANDER_INIT;
35 npc->duration = 0;
37
38 npc->flags &= ~NPC_FLAG_JUMPING;
39 if (!enemy->territory->wander.isFlying) {
40 npc->flags |= NPC_FLAG_GRAVITY;
41 npc->flags &= ~NPC_FLAG_FLYING;
42 } else {
43 npc->flags &= ~NPC_FLAG_GRAVITY;
44 npc->flags |= NPC_FLAG_FLYING;
45 }
46
47 if (enemy->aiFlags & AI_FLAG_SUSPEND) {
48 script->AI_TEMP_STATE = AI_STATE_SUSPEND;
49 script->functionTemp[1] = AI_STATE_WANDER_INIT;
50 enemy->aiFlags &= ~AI_FLAG_SUSPEND;
51 }
52 enemy->AI_VAR_ATTACK_STATE = MELEE_HITBOX_STATE_NONE;
53 }
54
55 if (script->AI_TEMP_STATE < AI_STATE_MELEE_HITBOX_INIT
56 && enemy->AI_VAR_ATTACK_STATE == MELEE_HITBOX_STATE_NONE
57 && N(MeleeHitbox_CanSeePlayer)(script)) {
58 script->AI_TEMP_STATE = AI_STATE_MELEE_HITBOX_INIT;
59 }
60
61 switch (script->AI_TEMP_STATE) {
63 basic_ai_wander_init(script, npcAISettings, territoryPtr);
64 // fallthrough
65 case AI_STATE_WANDER:
66 basic_ai_wander(script, npcAISettings, territoryPtr);
67 break;
69 basic_ai_loiter_init(script, npcAISettings, territoryPtr);
70 // fallthrough
71 case AI_STATE_LOITER:
72 basic_ai_loiter(script, npcAISettings, territoryPtr);
73 break;
75 basic_ai_found_player_jump_init(script, npcAISettings, territoryPtr);
76 // fallthrough
77 case AI_STATE_ALERT:
78 basic_ai_found_player_jump(script, npcAISettings, territoryPtr);
79 break;
81 basic_ai_chase_init(script, npcAISettings, territoryPtr);
82 // fallthrough
83 case AI_STATE_CHASE:
84 basic_ai_chase(script, npcAISettings, territoryPtr);
85 break;
87 basic_ai_lose_player(script, npcAISettings, territoryPtr);
88 break;
90 N(MeleeHitbox_30)(script);
91 // fallthrough
93 N(MeleeHitbox_31)(script);
94 if (script->AI_TEMP_STATE != AI_STATE_MELEE_HITBOX_ACTIVE) {
95 break;
96 }
97 // fallthrough
99 N(MeleeHitbox_32)(script);
100 if (script->AI_TEMP_STATE != AI_STATE_MELEE_HITBOX_MISS) {
101 break;
102 }
103 // fallthrough
105 N(MeleeHitbox_33)(script);
106 break;
107 case AI_STATE_SUSPEND:
108 basic_ai_suspend(script);
109 break;
110 }
111
112 return ApiStatus_BLOCK;
113}
114
115#endif
void N MeleeHitbox_31(Evt *script)
void N MeleeHitbox_32(Evt *script)
s32 N MeleeHitbox_CanSeePlayer(Evt *script)
void N MeleeHitbox_33(Evt *script)
void N MeleeHitbox_30(Evt *script)
@ ENEMY_ANIM_INDEX_IDLE
Definition enums.h:3426
@ AI_FLAG_SUSPEND
Definition enums.h:4571
@ AI_STATE_WANDER
Definition enums.h:4582
@ AI_STATE_LOITER
Definition enums.h:4588
@ AI_STATE_SUSPEND
Definition enums.h:4598
@ AI_STATE_MELEE_HITBOX_INIT
Definition enums.h:4600
@ AI_STATE_WANDER_INIT
Definition enums.h:4581
@ AI_STATE_MELEE_HITBOX_ACTIVE
Definition enums.h:4602
@ 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_MELEE_HITBOX_MISS
Definition enums.h:4603
@ AI_STATE_LOSE_PLAYER
Definition enums.h:4594
@ AI_STATE_MELEE_HITBOX_PRE
Definition enums.h:4601
@ AI_STATE_ALERT_INIT
Definition enums.h:4590
@ MELEE_HITBOX_STATE_NONE
Definition enums.h:4643
@ 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
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
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
u32 aiFlags
Definition npc.h:332
s32 skipPlayerDetectChance
Definition npc.h:200
EnemyTerritoryWander wander
Definition npc.h:232
EnemyTerritory * territory
Definition npc.h:342
Definition npc.h:294
s32 flags
AnimID curAnim
s16 duration