Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
StoneChomp.inc.c
Go to the documentation of this file.
1
2#include "StoneChomp.h"
3
5
6API_CALLABLE(N(StoneChompFXA)) {
8 NpcBlueprint* bpPtr = &bp;
9 NpcChompBlur* blurData;
10 Npc* npc;
11 Npc* newNpc;
12 s32 i;
13
14 npc = get_npc_safe(script->owner2.npcID);
15 blurData = heap_malloc(8 * sizeof(*blurData));
16 npc->blur.chomp = blurData;
17
20 bp.initialAnim = ANIM_StoneChomp_Chain;
21 bp.onUpdate = NULL;
22 bp.onRender = NULL;
23
24 for (i = 0; i < 8; i++, blurData++) {
25 blurData->npc = newNpc = get_npc_by_index(create_basic_npc(bpPtr));
26 newNpc->pos.x = npc->pos.x;
27 newNpc->pos.y = npc->pos.y;
28 newNpc->pos.z = npc->pos.z;
29 newNpc->yaw = npc->yaw;
30 newNpc->verticalRenderOffset = 3;
31 disable_npc_shadow(newNpc);
32 blurData->offset.x = 0.0f;
33 blurData->offset.y = 0.0f;
34 blurData->offset.z = 0.0f;
35 }
36 return ApiStatus_DONE2;
37}
38
39API_CALLABLE(N(StoneChompFXB)) {
40 NpcChompBlur* blurData;
41 Npc* ownerNpc;
42 Npc* childNpc;
43 f32 posX, posY, posZ;
44 f32 nextX, nextY, nextZ;
45 f32 invDist;
46 f32 floorY;
47 s32 i;
48
49 floorY = (f32) script->owner1.enemy->varTable[0];
50 ownerNpc = get_npc_safe(script->owner2.npcID);
51 blurData = ownerNpc->blur.chomp;
52 posX = ownerNpc->pos.x;
53 posY = ownerNpc->pos.y + (ownerNpc->collisionHeight * 0.2f);
54 posZ = ownerNpc->pos.z;
55 add_vec2D_polar(&posX, &posZ, ownerNpc->collisionDiameter * 0.3f, clamp_angle(ownerNpc->renderYaw + 180.0f));
56
57 if (ownerNpc->flags & NPC_FLAG_INVISIBLE) {
58 for (i = 0; i < 8; i++, blurData++) {
59 childNpc = blurData->npc;
60 childNpc->pos.x = posX;
61 childNpc->pos.y = posY;
62 childNpc->pos.z = posZ;
63 }
64 return ApiStatus_BLOCK;
65 }
66
67 for (i = 0; i < 8; i++, blurData++) {
68 childNpc = blurData->npc;
69 if (dist3D(childNpc->pos.x, childNpc->pos.y, childNpc->pos.z, posX, posY, posZ) >= 10.0) {
70 invDist = 10.0 / dist3D(
71 ((childNpc->pos.x - posX) * 0.8f) + posX, childNpc->pos.y, ((childNpc->pos.z - posZ) * 0.8f) + posZ,
72 posX, posY,posZ);
73
74 nextX = posX = ((childNpc->pos.x - posX) * 0.8f * invDist) + posX;
75 nextY = posY = ((childNpc->pos.y - posY) * invDist) + posY;
76 nextZ = posZ = ((childNpc->pos.z - posZ) * 0.8f * invDist) + posZ;
77
78 blurData->offset.x = (nextX - childNpc->pos.x) * 0.7f;
79 blurData->offset.y = (nextY - childNpc->pos.y) * 0.7f;
80 blurData->offset.z = (nextZ - childNpc->pos.z) * 0.7f;
81
82 childNpc->pos.x = nextX;
83 childNpc->pos.y = nextY;
84 childNpc->pos.z = nextZ;
85
86 if (blurData->offset.y > 10.0f) {
87 blurData->offset.y = 10.0f;
88 }
89 } else {
90 blurData->offset.x = blurData->offset.x * 0.9f;
91 blurData->offset.z = blurData->offset.z * 0.9f;
92 childNpc->pos.x += blurData->offset.x;
93 childNpc->pos.z += blurData->offset.z;
94 }
95
96 blurData->offset.y -= 1.0f;
97 if (blurData->offset.y < -10.0f) {
98 blurData->offset.y = -10.0f;
99 }
100 childNpc->pos.y += blurData->offset.y;
101 if (childNpc->pos.y <= floorY) {
102 childNpc->pos.y = floorY;
103 blurData->offset.y = -blurData->offset.y * 0.5;
104 }
105
106 posX = childNpc->pos.x;
107 posY = childNpc->pos.y;
108 posZ = childNpc->pos.z;
109 childNpc->flags = ownerNpc->flags;
110 }
111
112 return ApiStatus_BLOCK;
113}
114
115API_CALLABLE(N(StoneChompFXC)) {
116 NpcChompBlur* blurData = get_npc_safe(script->owner2.npcID)->blur.chomp;
117 s32 i;
118
119 for (i = 0; i < 8; i++, blurData++) {
120 free_npc(blurData->npc);
121 }
122
123 return ApiStatus_DONE2;
124}
125
126EvtScript N(EVS_NpcAuxAI_StoneChomp) = {
127 Call(N(StoneChompFXA))
128 Return
129 End
130};
131
132MobileAISettings N(AISettings_StoneChomp) = {
133 .moveSpeed = 2.0f,
134 .moveTime = 30,
135 .waitTime = 30,
136 .alertRadius = 100.0f,
137 .playerSearchInterval = 10,
138 .chaseSpeed = 5.3f,
139 .chaseTurnRate = 70,
140 .chaseUpdateInterval = 10,
141 .chaseRadius = 500.0f,
142 .unk_AI_2C = 1,
143};
144
145EvtScript N(EVS_NpcAI_StoneChomp) = {
147 Loop(0)
148 Call(N(StoneChompFXB))
149 Wait(1)
150 EndLoop
153 Call(N(StoneChompAI_Main), Ref(N(AISettings_StoneChomp)))
154 Return
155 End
156};
157
158EvtScript N(EVS_NpcHit_StoneChomp) = {
169 Thread
171 IfEq(LVar0, 0)
172 Set(LVarA, 0)
173 Loop(30)
174 Add(LVarA, 40)
176 Wait(1)
177 EndLoop
178 EndIf
182 Return
183 End
184};
185
186EvtScript N(EVS_NpcDefeat_StoneChomp) = {
190 Call(N(StoneChompFXC))
195 Return
196 End
197};
198
199NpcSettings N(NpcSettings_StoneChomp) = {
200 .height = 32,
201 .radius = 32,
202 .level = ACTOR_LEVEL_STONE_CHOMP,
203 .otherAI = &N(EVS_NpcAuxAI_StoneChomp),
204 .ai = &N(EVS_NpcAI_StoneChomp),
205 .onHit = &N(EVS_NpcHit_StoneChomp),
206 .onDefeat = &N(EVS_NpcDefeat_StoneChomp),
207};
struct Npc * npc
Bytecode EvtScript[]
#define clamp_angle
@ ENEMY_ANIM_INDEX_HIT
Definition enums.h:3433
@ SONG_SPECIAL_BATTLE
Definition enums.h:285
@ ENCOUNTER_TRIGGER_JUMP
Definition enums.h:269
@ ENCOUNTER_TRIGGER_HAMMER
Definition enums.h:271
@ ENCOUNTER_TRIGGER_NONE
Definition enums.h:268
@ ENCOUNTER_TRIGGER_PARTNER
Definition enums.h:273
@ ENCOUNTER_TRIGGER_SPIN
Definition enums.h:270
@ NPC_SELF
Definition enums.h:2526
@ OUTCOME_PLAYER_WON
Definition enums.h:1902
@ OUTCOME_PLAYER_LOST
Definition enums.h:1903
@ OUTCOME_PLAYER_FLED
Definition enums.h:1904
@ NPC_FLAG_IGNORE_ENTITY_COLLISION
Definition enums.h:3013
@ NPC_FLAG_FLYING
Definition enums.h:3001
@ NPC_FLAG_IGNORE_WORLD_COLLISION
Definition enums.h:3004
@ NPC_FLAG_IGNORE_PLAYER_COLLISION
Definition enums.h:3006
@ NPC_FLAG_INVISIBLE
Definition enums.h:2999
#define ApiStatus_DONE2
Definition evt.h:118
#define ApiStatus_BLOCK
Definition evt.h:116
f32 dist3D(f32 ax, f32 ay, f32 az, f32 bx, f32 by, f32 bz)
Definition 43F0.c:677
void add_vec2D_polar(f32 *x, f32 *y, f32 r, f32 theta)
Definition 43F0.c:685
void * heap_malloc(s32 size)
Definition heap.c:34
void free_npc(Npc *npc)
Definition npc.c:237
s32 create_basic_npc(NpcBlueprint *blueprint)
Definition npc.c:190
void disable_npc_shadow(Npc *npc)
Definition npc.c:1037
Npc * get_npc_by_index(s32 listIndex)
Definition npc.c:271
Npc * get_npc_safe(s32 npcID)
Definition npc.c:1010
ApiStatus SetBattleMusic(Evt *script, b32 isInitialCall)
ApiStatus SetNpcRotation(Evt *script, b32 isInitialCall)
ApiStatus GetSelfAnimationFromTable(Evt *script, b32 isInitialCall)
ApiStatus DoNpcDefeat(Evt *script, b32 isInitialCall)
ApiStatus GetOwnerEncounterTrigger(Evt *script, b32 isInitialCall)
ApiStatus func_800458CC(Evt *script, b32 isInitialCall)
ApiStatus GetBattleOutcome(Evt *script, b32 isInitialCall)
ApiStatus GetSelfVar(Evt *script, b32 isInitialCall)
#define Switch(LVAR)
Marks the start of a switch statement.
Definition macros.h:311
#define Ref(sym)
Address/pointer constant.
Definition macros.h:60
#define Set(VAR, INT_VALUE)
Sets the given variable to a given value casted to an integer.
Definition macros.h:365
#define CaseEq(RVAR)
Marks the start of a switch case that executes only if LVAR == RVAR. It also marks the end of any pre...
Definition macros.h:319
#define EndChildThread
Marks the end of a child thread block.
Definition macros.h:563
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#define Add(VAR, INT_VALUE)
Definition macros.h:376
#define EndLoop
Marks the end of a loop.
Definition macros.h:248
#define EndCaseGroup
Marks the end of a switch case group (CaseOrEq and/or CaseAndEq), stopping fallthrough.
Definition macros.h:352
#define CaseOrEq(RVAR)
Marks the start of a switch case that executes only if LVAR == RVAR.
Definition macros.h:341
#define EndIf
Marks the end of an if statement or an else block.
Definition macros.h:298
#define ExecWait(EVT_SOURCE)
Launches a new child thread.
Definition macros.h:475
#define Thread
Marks the start of a thread block.
Definition macros.h:544
#define EndThread
Marks the end of a thread block.
Definition macros.h:547
#define LVarA
Definition macros.h:158
#define Wait(NUM_FRAMES)
Blocks for the given number of frames.
Definition macros.h:254
#define EndSwitch
Marks the end of a switch statement and any case.
Definition macros.h:362
#define IfEq(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR == RVAR.
Definition macros.h:269
#define Call(FUNC, ARGS...)
Calls a given C EVT API function with any number of arguments.
Definition macros.h:576
#define ChildThread
Marks the start of a child thread block.
Definition macros.h:560
#define Loop(TIMES)
Marks the beginning of a loop.
Definition macros.h:245
#define LVar0
Definition macros.h:148
#define Return
Kills the current EVT thread.
Definition macros.h:217
EvtScript EVS_NpcHitRecoil
Definition 38F00.c:13
void(* onRender)(struct Npc *)
Definition npc.h:89
void(* onUpdate)(struct Npc *)
Definition npc.h:88
s32 initialAnim
Definition npc.h:87
s32 flags
Definition npc.h:86
s8 verticalRenderOffset
Vec3f pos
union Npc::@0 blur