Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
twink.c
Go to the documentation of this file.
1#include "battle/battle.h"
2#include "script_api/battle.h"
3#include "sprite/npc/Twink.h"
4#include "sprite/player.h"
5
6#define NAMESPACE battle_partner_twink
7
8extern EvtScript N(EVS_Init);
9extern EvtScript N(EVS_TakeTurn);
10extern EvtScript N(EVS_Idle);
11extern EvtScript N(EVS_HandleEvent);
12extern EvtScript N(EVS_HandlePhase);
13extern EvtScript N(EVS_ExecuteAction);
14extern EvtScript N(EVS_Celebrate);
15extern EvtScript N(EVS_RunAway);
17
18enum N(ActorPartIDs) {
19 PRT_MAIN = 1,
20};
21
22enum N(ActorVars) {
23 AVAR_Twink_PowerLevel = 0,
24 AVAR_Twink_DefensePtr = 1,
25 AVAR_Kammy_Speaking = 1,
26};
27
28API_CALLABLE(N(IsPeachBattle)) {
29 BattleStatus* battleStatus = &gBattleStatus;
30
31 if (battleStatus->flags2 & BS_FLAGS2_PEACH_BATTLE) {
32 script->varTable[0] = TRUE;
33 } else {
34 script->varTable[0] = FALSE;
35 }
36
37 return ApiStatus_DONE2;
38}
39
40s32 N(DefaultAnims)[] = {
41 STATUS_KEY_NORMAL, ANIM_Twink_Angry,
42 STATUS_KEY_INACTIVE, ANIM_Twink_Still,
44};
45
46s32 N(DefenseTable)[] = {
49};
50
51s32 N(StatusTable)[] = {
58 STATUS_KEY_FEAR, 100,
62 STATUS_KEY_STOP, 100,
74};
75
76ActorPartBlueprint N(ActorParts)[] = {
77 {
78 .flags = 0,
79 .index = PRT_MAIN,
80 .posOffset = { 0, 0, 0 },
81 .targetOffset = { 0, 0 },
82 .opacity = 255,
83 .idleAnimations = N(DefaultAnims),
84 .defenseTable = N(DefenseTable),
85 .eventFlags = 0,
86 .elementImmunityFlags = 0,
87 .projectileTargetOffset = { 0, 0 },
88 },
89};
90
91ActorBlueprint NAMESPACE = {
93 .type = ACTOR_TYPE_TWINK,
94 .level = ACTOR_LEVEL_TWINK,
95 .maxHP = 99,
96 .partCount = ARRAY_COUNT(N(ActorParts)),
97 .partsData = N(ActorParts),
98 .initScript = &N(EVS_Init),
99 .statusTable = N(StatusTable),
100 .escapeChance = 0,
101 .airLiftChance = 0,
102 .hurricaneChance = 0,
103 .spookChance = 0,
104 .upAndAwayChance = 0,
105 .spinSmashReq = 4,
106 .powerBounceChance = 80,
107 .coinReward = 0,
108 .size = { 20, 20 },
109 .healthBarOffset = { 0, 0 },
110 .statusIconOffset = { -10, 30 },
111 .statusTextOffset = { 13, 31 },
112};
113
114EvtScript N(EVS_Init) = {
115 Call(BindTakeTurn, ACTOR_SELF, Ref(N(EVS_TakeTurn)))
116 Call(BindIdle, ACTOR_SELF, Ref(N(EVS_Idle)))
117 Call(BindHandleEvent, ACTOR_SELF, Ref(N(EVS_HandleEvent)))
118 Call(BindHandlePhase, ACTOR_SELF, Ref(N(EVS_HandlePhase)))
119 Call(N(IsPeachBattle))
120 IfNe(LVar0, TRUE)
121 Call(SetActorFlagBits, ACTOR_SELF, ACTOR_FLAG_NO_ATTACK, TRUE)
122 EndIf
123 Call(SetActorVar, ACTOR_SELF, AVAR_Twink_PowerLevel, 0)
124 Call(SetActorVar, ACTOR_SELF, AVAR_Twink_DefensePtr, Ref(N(DefenseTable)))
125 Call(AddActorDecoration, ACTOR_SELF, PRT_MAIN, 0, ACTOR_DECORATION_SPARKLES)
126 Call(ModifyActorDecoration, ACTOR_SELF, PRT_MAIN, 0, 0, 0, 0, 0)
127 Return
128 End
129};
130
131s32 N(BobPhase) = 0;
132
133API_CALLABLE(N(AddFlightBobbing)) {
134 Actor* actor = get_actor(script->owner1.actorID);
135
136 N(BobPhase) += 18;
137 N(BobPhase) = clamp_angle(N(BobPhase));
138 actor->verticalRenderOffset = 2.0f * sin_rad(DEG_TO_RAD(N(BobPhase)));
139 return ApiStatus_DONE2;
140}
141
142EvtScript N(EVS_Idle) = {
143 Loop(0)
144 Call(N(AddFlightBobbing))
145 Wait(1)
146 EndLoop
147 Return
148 End
149};
150
151EvtScript N(EVS_HandleEvent) = {
152 Call(UseIdleAnimation, ACTOR_PLAYER, FALSE)
153 Call(UseIdleAnimation, ACTOR_PARTNER, FALSE)
154 Call(CloseActionCommandInfo)
155 Call(GetLastEvent, ACTOR_PARTNER, LVar0)
159 Call(SetAnimation, ACTOR_PLAYER, 0, ANIM_Peach2_Gasp)
160 SetConst(LVar0, PRT_MAIN)
161 SetConst(LVar1, ANIM_Twink_Hurt)
163 Call(SetAnimation, ACTOR_PLAYER, 0, ANIM_Peach1_Walk)
167 Call(SetAnimation, ACTOR_PLAYER, 0, ANIM_Peach2_Gasp)
168 SetConst(LVar0, PRT_MAIN)
169 SetConst(LVar1, ANIM_Twink_Angry)
171 Call(SetAnimation, ACTOR_PLAYER, 0, ANIM_Peach1_Walk)
174 Call(UseIdleAnimation, ACTOR_PARTNER, TRUE)
175 Call(UseIdleAnimation, ACTOR_PLAYER, TRUE)
176 Return
177 End
178};
179
180EvtScript N(EVS_TakeTurn) = {
181 Call(GetBattlePhase, LVar0)
184 ExecWait(N(EVS_ExecuteAction))
186 ExecWait(N(EVS_Celebrate))
188 ExecWait(N(EVS_RunAway))
192 Return
193 End
194};
195
196EvtScript N(EVS_Celebrate) = {
197 SetConst(LVar0, PRT_MAIN)
198 SetConst(LVar1, ANIM_Twink_Fly)
199 SetConst(LVar2, ANIM_Twink_Fly)
201 Return
202 End
203};
204
205EvtScript N(EVS_RunAway) = {
206 SetConst(LVar0, PRT_MAIN)
207 SetConst(LVar1, ANIM_Twink_Angry)
209 Return
210 End
211};
212
214 Call(UseIdleAnimation, ACTOR_PARTNER, FALSE)
215 Call(SetGoalToHome, ACTOR_PARTNER)
216 Call(SetActorSpeed, ACTOR_PARTNER, Float(6.0))
217 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Angry)
218 Call(SetActorYaw, ACTOR_PARTNER, 0)
219 Call(RunToGoal, ACTOR_PARTNER, 0)
220 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Idle)
221 Call(UseIdleAnimation, ACTOR_PARTNER, TRUE)
222 Return
223 End
224};
225
226EvtScript N(EVS_HandlePhase) = {
227 Return
228 End
229};
230
231EvtScript N(EVS_ExecuteAction) = {
232 Call(EnableIdleScript, ACTOR_PARTNER, IDLE_SCRIPT_DISABLE)
233 Call(UseIdleAnimation, ACTOR_PARTNER, FALSE)
235 Call(UseBattleCamPreset, BTL_CAM_PARTNER_MIDAIR)
236 Call(BattleCamTargetActor, ACTOR_SELF)
237 Call(InitTargetIterator)
238 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Angry)
239 Call(SetGoalToTarget, ACTOR_PARTNER)
240 Call(AddGoalPos, ACTOR_PARTNER, -20, 0, 0)
241 Call(SetActorSpeed, ACTOR_PARTNER, Float(4.0))
242 Call(FlyToGoal, ACTOR_PARTNER, 0, -10, EASING_COS_IN_OUT)
243 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Idle)
244 Wait(3)
245 Call(UseBattleCamPreset, BTL_CAM_PARTNER_MIDAIR)
246 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Cringe)
247 Call(AddGoalPos, ACTOR_PARTNER, 0, 10, 0)
248 Call(FlyToGoal, ACTOR_PARTNER, 5, 0, EASING_LINEAR)
249 Wait(2)
251 Call(PlaySoundAtActor, ACTOR_PARTNER, SOUND_ACTOR_JUMP)
252 Call(UseBattleCamPreset, BTL_CAM_PARTNER_MIDAIR)
253 Call(AddGoalPos, ACTOR_PARTNER, -40, 15, 0)
254 Call(FlyToGoal, ACTOR_PARTNER, 20, -20, EASING_QUARTIC_OUT)
255 Call(GetActorVar, ACTOR_SELF, AVAR_Twink_PowerLevel, LVarF)
256 IfGt(LVarF, 1)
257 Call(EnableActorBlur, ACTOR_PARTNER, ACTOR_BLUR_ENABLE)
258 EndIf
259 Call(PlaySoundAtActor, ACTOR_PARTNER, SOUND_TWINK_ATTACK)
260 Call(SetGoalToTarget, ACTOR_PARTNER)
261 Call(AddGoalPos, ACTOR_PARTNER, -10, 0, 0)
262 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Angry)
263 Call(FlyToGoal, ACTOR_PARTNER, 5, 0, EASING_LINEAR)
264 Call(GetActorVar, ACTOR_SELF, AVAR_Twink_PowerLevel, LVarF)
265 IfGt(LVarF, 0)
267 Else
269 EndIf
270 Call(UseBattleCamPreset, BTL_CAM_VIEW_ENEMIES)
271 Call(MoveBattleCamOver, 10)
272 Call(AddGoalPos, ACTOR_PARTNER, 150, 100, 0)
273 Call(FlyToGoal, ACTOR_PARTNER, 15, 20, EASING_LINEAR)
274 Call(EnableActorBlur, ACTOR_PARTNER, ACTOR_BLUR_DISABLE)
275 Wait(20)
276 Call(UseBattleCamPreset, BTL_CAM_DEFAULT)
277 Loop(0)
278 Wait(1)
279 Call(GetActorVar, ACTOR_ENEMY0, AVAR_Kammy_Speaking, LVar0)
280 IfEq(LVar0, 0)
282 EndIf
283 EndLoop
285 Call(SetGoalToHome, ACTOR_PARTNER)
286 Call(SetAnimation, ACTOR_PARTNER, -1, ANIM_Twink_Angry)
287 Call(SetActorSpeed, ACTOR_PARTNER, Float(8.0))
288 Call(FlyToGoal, ACTOR_PARTNER, 0, -20, EASING_COS_IN_OUT)
289 Call(EnableIdleScript, ACTOR_PARTNER, IDLE_SCRIPT_ENABLE)
290 Call(UseIdleAnimation, ACTOR_PARTNER, TRUE)
291 Return
292 End
293};
s8 verticalRenderOffset
Bytecode EvtScript[]
#define clamp_angle
@ ACTOR_SOUND_FLY
Definition enums.h:2035
@ BS_FLAGS1_TRIGGER_EVENTS
Definition enums.h:3575
@ BS_FLAGS1_INCLUDE_POWER_UPS
Definition enums.h:3571
@ ELEMENT_END
Definition enums.h:2114
@ ELEMENT_NORMAL
Definition enums.h:2115
@ ACTOR_DECORATION_SPARKLES
Definition enums.h:2052
@ PHASE_RUN_AWAY_START
Definition enums.h:2060
@ PHASE_EXECUTE_ACTION
Definition enums.h:2058
@ PHASE_CELEBRATE
Definition enums.h:2062
@ PHASE_RUN_AWAY_FAIL
Definition enums.h:2064
@ BS_FLAGS2_PEACH_BATTLE
Definition enums.h:3610
@ STATUS_KEY_PARALYZE
Definition enums.h:2201
@ STATUS_TURN_MOD_DEFAULT
Definition enums.h:2227
@ STATUS_TURN_MOD_PARALYZE
Definition enums.h:2234
@ STATUS_KEY_FROZEN
Definition enums.h:2203
@ STATUS_TURN_MOD_SLEEP
Definition enums.h:2228
@ STATUS_TURN_MOD_DIZZY
Definition enums.h:2232
@ STATUS_KEY_STATIC
Definition enums.h:2207
@ STATUS_END
Definition enums.h:2196
@ STATUS_TURN_MOD_POISON
Definition enums.h:2233
@ STATUS_KEY_FEAR
Definition enums.h:2199
@ STATUS_TURN_MOD_STOP
Definition enums.h:2237
@ STATUS_KEY_SLEEP
Definition enums.h:2202
@ STATUS_KEY_STOP
Definition enums.h:2204
@ STATUS_KEY_INACTIVE
Definition enums.h:2214
@ STATUS_TURN_MOD_FROZEN
Definition enums.h:2230
@ STATUS_KEY_SHRINK
Definition enums.h:2206
@ STATUS_KEY_DIZZY
Definition enums.h:2200
@ STATUS_KEY_POISON
Definition enums.h:2205
@ STATUS_TURN_MOD_STATIC
Definition enums.h:2229
@ STATUS_TURN_MOD_FEAR
Definition enums.h:2231
@ STATUS_KEY_NORMAL
Definition enums.h:2197
@ STATUS_TURN_MOD_SHRINK
Definition enums.h:2235
@ STATUS_KEY_DEFAULT
Definition enums.h:2198
@ BTL_CAM_DEFAULT
Definition enums.h:4824
@ BTL_CAM_PARTNER_MIDAIR
Definition enums.h:4874
@ BTL_CAM_VIEW_ENEMIES
Definition enums.h:4825
@ EASING_COS_IN_OUT
Definition enums.h:520
@ EASING_QUARTIC_OUT
Definition enums.h:516
@ EASING_LINEAR
Definition enums.h:510
@ IDLE_SCRIPT_ENABLE
Definition enums.h:6408
@ IDLE_SCRIPT_DISABLE
Definition enums.h:6407
@ SOUND_TWINK_FLY_A
Definition enums.h:1423
@ SOUND_NONE
Definition enums.h:547
@ SOUND_TWINK_FLY_B
Definition enums.h:1028
@ SOUND_TWINK_ATTACK
Definition enums.h:1422
@ SOUND_ACTOR_JUMP
Definition enums.h:1290
@ ACTOR_PLAYER
Definition enums.h:2085
@ ACTOR_PARTNER
Definition enums.h:2086
@ ACTOR_ENEMY0
Definition enums.h:2087
@ ACTOR_SELF
Definition enums.h:2084
@ ACTOR_FLAG_NO_DMG_APPLY
Damage is not applied to actor HP.
Definition enums.h:3340
@ ACTOR_FLAG_NO_ATTACK
Skip attack turn.
Definition enums.h:3339
@ ACTOR_BLUR_ENABLE
Definition enums.h:6414
@ ACTOR_BLUR_DISABLE
Definition enums.h:6413
@ EVENT_HIT
Definition enums.h:2132
@ EVENT_IMMUNE
Definition enums.h:2146
@ EVENT_ZERO_DAMAGE
Definition enums.h:2144
@ EVENT_HIT_COMBO
Definition enums.h:2131
#define ApiStatus_DONE2
Definition evt.h:118
Actor * get_actor(s32 actorID)
Definition actor_api.c:155
f32 sin_rad(f32 x)
Definition 43F0.c:713
EvtScript EVS_Enemy_Hit
EvtScript EVS_Partner_Celebrate
EvtScript EVS_RunAwayFail
EvtScript EVS_Partner_RunAway
EvtScript EVS_Enemy_NoDamageHit
#define Else
Marks the end of an if statement and the start of the else block.
Definition macros.h:295
#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 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 LVarF
Definition macros.h:163
#define IfNe(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR != RVAR.
Definition macros.h:272
#define End
Signals the end of EVT script data. A script missing this will likely crash on load.
Definition macros.h:213
#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 ARRAY_COUNT(arr)
Definition macros.h:40
#define IfGt(LVAR, RVAR)
Marks the beginning of an if statement that only executes if LVAR <= RVAR.
Definition macros.h:278
#define Float(DOUBLE)
Definition macros.h:51
#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 BreakLoop
Breaks out of the innermost loop.
Definition macros.h:251
#define LVar2
Definition macros.h:150
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define LVar1
Definition macros.h:149
#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 Loop(TIMES)
Marks the beginning of a loop.
Definition macros.h:245
#define LVar0
Definition macros.h:148
#define SetConst(VAR, CONST)
Sets the given variable to a given value, skipping the evt_get_variable call.
Definition macros.h:370
#define Return
Kills the current EVT thread.
Definition macros.h:217
BattleStatus gBattleStatus
Definition battle.c:11