Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
Switch.c
Go to the documentation of this file.
1#include "common.h"
2#include "vars_access.h"
3#include "effects.h"
4#include "ld_addrs.h"
5#include "entity.h"
6
7#if VERSION_JP // TODO remove once segments are split
8extern Addr entity_model_BlueSwitch_ROM_END;
9extern Addr entity_model_BlueSwitch_ROM_START;
10extern Addr entity_model_GreenStompSwitch_ROM_END;
11extern Addr entity_model_GreenStompSwitch_ROM_START;
12extern Addr entity_model_RedSwitch_ROM_END;
13extern Addr entity_model_RedSwitch_ROM_START;
14#endif
15
16#define REFLECTED_SWITCH_HIDDEN 1
17#define REFLECTED_SWITCH_LINKED 2
18
19extern Gfx Entity_RedSwitch_Render[];
20extern Gfx Entity_BlueSwitch_Render[];
22
24
26 PlayerStatus* playerStatus = &gPlayerStatus;
27 SwitchData* data = entity->dataBuf.swtch;
28
30 if ((playerStatus->actionState == ACTION_STATE_SPIN_POUND)
31 || (playerStatus->actionState == ACTION_STATE_TORNADO_POUND)) {
33 data->greenMotionTimer = 8;
34 }
35 }
36}
37
39 SwitchData* data = entity->dataBuf.swtch;
40 u16 curTime = data->greenMotionTimer--;
41
42 if (curTime != 0) {
43 entity->pos.y -= 1.8625;
44 return;
45 }
46 entity_start_script(entity);
48 data->greenMotionTimer = 8;
49}
50
52 SwitchData* data = entity->dataBuf.swtch;
53 u16 curTime = data->greenMotionTimer--;
54
55 if (curTime != 0) {
56 entity->pos.y += 1.8625;
57 return;
58 }
60 data->greenMotionTimer = 8;
61}
62
64 SwitchData* data = entity->dataBuf.swtch;
65 f32 hitDepth = 10.0f;
66 f32 x = entity->pos.x;
67 f32 y = entity->pos.y;
68 f32 z = entity->pos.z;
69 f32 hitYaw;
70 f32 hitPitch;
71
72 entity_raycast_down(&x, &y, &z, &hitYaw, &hitPitch, &hitDepth);
73
74 if (entity->pos.y != y && entity->pos.y > y) {
75 f32 fallVelocity = data->fallVel;
76
77 fallVelocity += 0.5;
78 data->fallVel = fallVelocity;
79 entity->pos.y -= fallVelocity;
80 if (entity->pos.y < y) {
81 entity->pos.y = y;
82 }
83 }
84}
85
87 PlayerStatus* playerStatus = &gPlayerStatus;
88
90 if ((playerStatus->actionState == ACTION_STATE_SPIN_POUND)
91 || (playerStatus->actionState == ACTION_STATE_TORNADO_POUND)) {
93 }
94 }
95}
96
98 SwitchData* data = entity->dataBuf.swtch;
99 PlayerStatus* playerStatus = &gPlayerStatus;
100 PartnerStatus* partnerStatus = &gPartnerStatus;
101
103
105 if (playerStatus->actionState == ACTION_STATE_HAMMER) {
106 if (gPlayerData.hammerLevel < 0) {
107 return;
108 }
110
111 if (data->linkedSwitch == NULL) {
112 return;
113 }
114
116 return;
117 }
118 }
119
120 if (playerStatus->actionState == ACTION_STATE_SPIN_JUMP) {
121 return;
122 }
123
124 if (partnerStatus->actingPartner == PARTNER_PARAKARRY && partnerStatus->partnerActionState != PARTNER_ACTION_NONE) {
125 return;
126 }
127
129 if (!(entity->collisionFlags & ENTITY_COLLISION_PARTNER)) {
130 return;
131 }
132 }
133
135
136 if (data->linkedSwitch == NULL) {
137 return;
138 }
139
141}
142
148
150 SwitchData* data = entity->dataBuf.swtch;
151
152 data->fallVel = 1.0f;
153 data->deltaScaleX = 0.1f;
154 data->deltaScaleY = -0.1f;
155 data->animStateScaleX = 0;
156 data->animStateScaleY = 0;
157}
158
160 f32 phi_f4;
161 f32 temp_f6;
162 SwitchData* data = entity->dataBuf.swtch;
163 s32 phi_s2 = 0;
164
165 switch (data->animStateScaleX) {
166 case 0:
167 temp_f6 = data->baseScale.z * 0.3;
168 phi_f4 = ((data->baseScale.x + temp_f6) - entity->scale.x) / 4.0;
169 if (phi_f4 < 0.01) {
170 phi_f4 = 0.01f;
171 }
172 data->deltaScaleX += phi_f4;
173 entity->scale.x += data->deltaScaleX;
174 if ((data->baseScale.x + temp_f6) <= entity->scale.x) {
175 data->deltaScaleX = 0.0f;
176 data->animStateScaleX++;
177 }
178 break;
179 case 1:
180 temp_f6 = data->baseScale.z * -0.2;
181 phi_f4 = ((data->baseScale.x + temp_f6) - entity->scale.x) / 6.0;
182 if (phi_f4 > -0.01) {
183 phi_f4 = -0.01f;
184 }
185 data->deltaScaleX += phi_f4;
186 entity->scale.x += data->deltaScaleX;
187 if (entity->scale.x <= (data->baseScale.x + temp_f6)) {
188 data->deltaScaleX = 0.0f;
189 data->animStateScaleX++;
190 }
191 break;
192 case 2:
193 temp_f6 = data->baseScale.z * 0.15;
194 phi_f4 = ((data->baseScale.x + temp_f6) - entity->scale.x) / 4.0;
195 if (phi_f4 < 0.01) {
196 phi_f4 = 0.01f;
197 }
198 data->deltaScaleX += phi_f4;
199 entity->scale.x += data->deltaScaleX;
200 if ((data->baseScale.x + temp_f6) <= entity->scale.x) {
201 data->deltaScaleX = 0.0f;
202 data->animStateScaleX++;
203 }
204 break;
205 case 3:
206 temp_f6 = data->baseScale.z * -0.1;
207 phi_f4 = ((data->baseScale.x + temp_f6) - entity->scale.x) / 6.0;
208 if (phi_f4 > -0.01) {
209 phi_f4 = -0.01f;
210 }
211 data->deltaScaleX += phi_f4;
212 entity->scale.x += data->deltaScaleX;
213 if (entity->scale.x <= (data->baseScale.x + temp_f6)) {
214 data->deltaScaleX = 0.0f;
215 data->animStateScaleX++;
216 }
217 break;
218 case 4:
219 phi_f4 = (data->baseScale.x - entity->scale.x) / 4.0;
220 if (phi_f4 < 0.01) {
221 phi_f4 = 0.01f;
222 }
223 data->deltaScaleX += phi_f4;
224 entity->scale.x += data->deltaScaleX;
225 if (data->baseScale.x <= entity->scale.x) {
226 entity->scale.x = data->baseScale.x;
227 data->deltaScaleX = 0.0f;
228 data->animStateScaleX++;
229 }
230 break;
231 case 5:
232 phi_s2++;
233 break;
234 }
235
236 entity->scale.z = entity->scale.x;
237
238 switch (data->animStateScaleY) {
239 case 0:
240 temp_f6 = data->baseScale.z * -0.5;
241 phi_f4 = ((data->baseScale.y + temp_f6) - entity->scale.y) / 5.0;
242 if (phi_f4 > -0.01) {
243 phi_f4 = -0.01f;
244 }
245 data->deltaScaleY += phi_f4;
246 entity->scale.y += data->deltaScaleY;
247 if (entity->scale.y <= (data->baseScale.y + temp_f6)) {
248 data->deltaScaleY = 0.0f;
249 data->animStateScaleY++;
250 }
251 break;
252 case 1:
253 temp_f6 = data->baseScale.z * 0.1;
254 phi_f4 = ((data->baseScale.y + temp_f6) - entity->scale.y) / 10.0;
255 if (phi_f4 < 0.01) {
256 phi_f4 = 0.01f;
257 }
258 data->deltaScaleY += phi_f4;
259 entity->scale.y += data->deltaScaleY;
260 if ((data->baseScale.y + temp_f6) <= entity->scale.y) {
261 data->deltaScaleY = 0.0f;
262 data->animStateScaleY++;
263 }
264 break;
265 case 2:
266 temp_f6 = data->baseScale.z * -0.3;
267 phi_f4 = ((data->baseScale.y + temp_f6) - entity->scale.y) / 5.0;
268 if (phi_f4 > -0.01) {
269 phi_f4 = -0.01f;
270 }
271 data->deltaScaleY += phi_f4;
272 entity->scale.y += data->deltaScaleY;
273 if (entity->scale.y <= (data->baseScale.y + temp_f6)) {
274 data->deltaScaleY = 0.0f;
275 data->animStateScaleY++;
276 }
277 break;
278 case 3:
279 temp_f6 = data->baseScale.z * 0.0;
280 phi_f4 = ((data->baseScale.y + temp_f6) - entity->scale.y) / 10.0;
281 if (phi_f4 < 0.01) {
282 phi_f4 = 0.01f;
283 }
284 data->deltaScaleY += phi_f4;
285 entity->scale.y += data->deltaScaleY;
286 if ((data->baseScale.y + temp_f6) <= entity->scale.y) {
287 data->deltaScaleY = 0.0f;
288 data->animStateScaleY++;
289 }
290 break;
291 case 4:
292 phi_f4 = (data->baseScale.y - entity->scale.y) / 5.0;
293 if (phi_f4 > -0.01) {
294 phi_f4 = -0.01f;
295 }
296 data->deltaScaleY += phi_f4;
297 entity->scale.y += data->deltaScaleY;
298 if (entity->scale.y <= data->baseScale.y) {
299 entity->scale.y = data->baseScale.y;
300 data->deltaScaleY = 0.0f;
301 data->animStateScaleY++;
302 }
303 break;
304 case 5:
305 phi_s2++;
306 break;
307 }
308
310 if (phi_s2 == 2) {
311 data->animStateScaleX = 0;
312 data->animStateScaleY = 0;
314 }
315}
316
322
324 f32 phi_f4;
325 f32 scaleChange;
326 SwitchData* data = entity->dataBuf.swtch;
327 s32 phi_s2 = 0;
328
329 switch (data->animStateScaleX) {
330 case 0:
331 scaleChange = data->baseScale.z * 0.3;
332 phi_f4 = ((data->baseScale.x + scaleChange) - entity->scale.x) / 4.0;
333 if (phi_f4 < 0.01) {
334 phi_f4 = 0.01f;
335 }
336 data->deltaScaleX += phi_f4;
337 entity->scale.x += data->deltaScaleX;
338 if ((data->baseScale.x + scaleChange) <= entity->scale.x) {
339 data->deltaScaleX = 0.0f;
340 data->animStateScaleX++;
341 }
342 break;
343 case 1:
344 scaleChange = (data->baseScale.z * -0.2);
345 phi_f4 = ((data->baseScale.x + scaleChange) - entity->scale.x) / 6.0;
346 if (phi_f4 > -0.01) {
347 phi_f4 = -0.01f;
348 }
349 data->deltaScaleX += phi_f4;
350 entity->scale.x += data->deltaScaleX;
351 if (entity->scale.x <= (data->baseScale.x + scaleChange)) {
352 data->deltaScaleX = 0.0f;
353 data->animStateScaleX++;
354 }
355 break;
356 case 2:
357 scaleChange = data->baseScale.z * 0.15;
358 phi_f4 = ((data->baseScale.x + scaleChange) - entity->scale.x) / 4.0;
359 if (phi_f4 < 0.01) {
360 phi_f4 = 0.01f;
361 }
362 data->deltaScaleX += phi_f4;
363 entity->scale.x += data->deltaScaleX;
364 if ((data->baseScale.x + scaleChange) <= entity->scale.x) {
365 data->deltaScaleX = 0.0f;
366 data->animStateScaleX++;
367 }
368 break;
369 case 3:
370 scaleChange = data->baseScale.z * -0.1;
371 phi_f4 = ((data->baseScale.x + scaleChange) - entity->scale.x) / 6.0;
372 if (phi_f4 > -0.01) {
373 phi_f4 = -0.01f;
374 }
375 data->deltaScaleX += phi_f4;
376 entity->scale.x += data->deltaScaleX;
377 if (entity->scale.x <= (data->baseScale.x + scaleChange)) {
378 data->deltaScaleX = 0.0f;
379 data->animStateScaleX++;
380 }
381 break;
382 case 4:
383 phi_s2++;
384 break;
385 }
386
387 entity->scale.z = entity->scale.x;
388
389 switch (data->animStateScaleY) {
390 case 0:
391 scaleChange = data->baseScale.z * -0.5;
392 phi_f4 = ((data->baseScale.y + scaleChange) - entity->scale.y) / 5.0;
393 if (phi_f4 > -0.01) {
394 phi_f4 = -0.01f;
395 }
396 data->deltaScaleY += phi_f4;
397 entity->scale.y += data->deltaScaleY;
398 if (entity->scale.y <= (data->baseScale.y + scaleChange)) {
399 data->deltaScaleY = 0.0f;
400 data->animStateScaleY++;
401 }
402 break;
403 case 1:
404 scaleChange = data->baseScale.z * 0.1;
405 phi_f4 = ((data->baseScale.y + scaleChange) - entity->scale.y) / 10.0;
406 if (phi_f4 < 0.01) {
407 phi_f4 = 0.01f;
408 }
409 data->deltaScaleY += phi_f4;
410 entity->scale.y += data->deltaScaleY;
411 if ((data->baseScale.y + scaleChange) <= entity->scale.y) {
412 data->deltaScaleY = 0.0f;
413 data->animStateScaleY++;
414 }
415 break;
416 case 2:
417 scaleChange = data->baseScale.z * -0.3;
418 phi_f4 = ((data->baseScale.y + scaleChange) - entity->scale.y) / 5.0;
419 if (phi_f4 > -0.01) {
420 phi_f4 = -0.01f;
421 }
422 data->deltaScaleY += phi_f4;
423 entity->scale.y += data->deltaScaleY;
424 if (entity->scale.y <= (data->baseScale.y + scaleChange)) {
425 data->deltaScaleY = 0.0f;
426 data->animStateScaleY++;
427 }
428 break;
429 case 3:
430 phi_s2++;
431 break;
432 }
433
435 if (phi_s2 == 2) {
436 data->animStateScaleX = 0;
437 data->animStateScaleY = 0;
439 }
440
441 data->scaleAnimTimer++;
442 if (data->scaleAnimTimer == 10 && data->linkedSwitch == NULL) {
443 fx_cold_breath(0, entity->pos.x, entity->pos.y, entity->pos.z, 1.0f, 60);
444 }
445}
446
448 PlayerStatus* playerStatus = &gPlayerStatus;
449 SwitchData* data = entity->dataBuf.swtch;
450
451 playerStatus->animFlags |= PA_FLAG_MAP_HAS_SWITCH;
452 data->baseScale.x = 1.0f;
453 data->baseScale.y = 1.0f;
454 data->baseScale.z = 1.0f;
455}
456
458 SwitchData* data = entity->dataBuf.swtch;
459
462 SwitchToLink = entity;
463 return;
464 }
465
467 if (SwitchToLink != NULL) {
469 entity->flags |= ENTITY_FLAG_HIDDEN;
470 return;
471 }
472 } else {
473 SwitchToLink = NULL;
474 }
475}
476
478 SwitchData* data;
479
481 data = entity->dataBuf.swtch;
482 entity->scale.x = 3.0f;
483 entity->scale.y = 3.0f;
484 entity->scale.z = 3.0f;
485 data->baseScale.x = 3.0f;
486 data->baseScale.y = 3.0f;
487 data->baseScale.z = 3.0f;
488}
489
500
510
520
529
531
533
535
537
540 .typeDataSize = sizeof(SwitchData),
541 .renderCommandList = Entity_RedSwitch_RenderScript,
542 .modelAnimationNodes = 0,
543 .fpInit = entity_base_switch_init,
544 .updateEntityScript = Entity_RedSwitch_Script,
545 .fpHandleCollision = NULL,
546 { .dma = ENTITY_ROM(RedSwitch) },
547 .entityType = ENTITY_TYPE_RED_SWITCH,
548 .aabbSize = {22, 23, 22}
549};
550
553 .typeDataSize = sizeof(SwitchData),
554 .renderCommandList = Entity_BlueSwitch_RenderScript,
555 .modelAnimationNodes = 0,
556 .fpInit = entity_BlueSwitch_init,
557 .updateEntityScript = Entity_BlueSwitch_Script,
558 .fpHandleCollision = NULL,
559 { .dma = ENTITY_ROM(BlueSwitch) },
560 .entityType = ENTITY_TYPE_BLUE_SWITCH,
561 .aabbSize = {22, 23, 22}
562};
563
566 .typeDataSize = sizeof(SwitchData),
567 .renderCommandList = Entity_HugeBlueSwitch_RenderScript,
568 .modelAnimationNodes = 0,
570 .updateEntityScript = Entity_HugeBlueSwitch_Script,
571 .fpHandleCollision = NULL,
572 { .dma = ENTITY_ROM(BlueSwitch) },
573 .entityType = ENTITY_TYPE_HUGE_BLUE_SWITCH,
574 .aabbSize = {66, 75, 66}
575};
576
579 .typeDataSize = sizeof(SwitchData),
580 .renderCommandList = Entity_GreenStompSwitch_RenderScript,
581 .modelAnimationNodes = 0,
582 .fpInit = entity_base_switch_init,
583 .updateEntityScript = Entity_GreenStompSwitch_Script,
584 .fpHandleCollision = NULL,
585 { .dma = ENTITY_ROM(GreenStompSwitch) },
586 .entityType = ENTITY_TYPE_GREEN_STOMP_SWITCH,
587 .aabbSize = {50, 15, 50}
588};
#define REFLECTED_SWITCH_LINKED
Definition Switch.c:17
void entity_base_switch_animate_scale(Entity *entity)
Definition Switch.c:323
EntityModelScript Entity_BlueSwitch_RenderScript
Definition Switch.c:530
EntityModelScript Entity_HugeBlueSwitch_RenderScript
Definition Switch.c:532
void entity_switch_fall_down(Entity *entity)
Definition Switch.c:63
EntityScript Entity_BlueSwitch_Script
Definition Switch.c:511
void entity_HugeBlueSwitch_idle(Entity *entity)
Definition Switch.c:86
EntityBlueprint Entity_BlueSwitch
Definition Switch.c:551
void entity_base_switch_start_bound_script(Entity *entity)
Definition Switch.c:317
void entity_RedSwitch_wait_and_reset(Entity *entity)
Definition Switch.c:143
Gfx Entity_GreenStompSwitch_Render[]
void entity_BlueSwitch_init(Entity *entity)
Definition Switch.c:457
EntityBlueprint Entity_GreenStompSwitch
Definition Switch.c:577
void entity_GreenStompSwitch_extend(Entity *entity)
Definition Switch.c:51
EntityModelScript Entity_GreenStompSwitch_RenderScript
Definition Switch.c:536
void entity_small_switch_idle(Entity *entity)
Definition Switch.c:97
EntityScript Entity_RedSwitch_Script
Definition Switch.c:490
void entity_base_switch_init(Entity *entity)
Definition Switch.c:447
void entity_GreenStompSwitch_retract(Entity *entity)
Definition Switch.c:38
Gfx Entity_RedSwitch_Render[]
Definition RedSwitch.c:183
EntityBlueprint Entity_HugeBlueSwitch
Definition Switch.c:564
void entity_HugeBlueSwitch_init(Entity *entity)
Definition Switch.c:477
Gfx Entity_BlueSwitch_Render[]
Definition BlueSwitch.c:188
EntityScript Entity_GreenStompSwitch_Script
Definition Switch.c:521
EntityModelScript Entity_RedSwitch_RenderScript
Definition Switch.c:534
s32 entity_RedSwitch_animate_scale(Entity *entity)
Definition Switch.c:159
void entity_base_switch_anim_init(Entity *entity)
Definition Switch.c:149
void entity_GreenStompSwitch_idle(Entity *entity)
Definition Switch.c:25
EntityBlueprint Entity_RedSwitch
Definition Switch.c:538
BSS Entity * SwitchToLink
Definition Switch.c:23
#define REFLECTED_SWITCH_HIDDEN
Definition Switch.c:16
EntityScript Entity_HugeBlueSwitch_Script
Definition Switch.c:501
struct SwitchData * swtch
s32 CreateEntityVarArgBuffer[]
Definition entity.c:35
s32 EntityModelScript[]
Definition entity.h:7
#define es_Call(func)
Definition entity.h:37
s16 scaleAnimTimer
Definition entity.h:88
#define es_Restart
Definition entity.h:40
#define STANDARD_ENTITY_MODEL_SCRIPT(gfx, renderMode)
Definition entity.h:56
s8 animStateScaleX
Definition entity.h:83
#define es_SetCallback(func, time)
Definition entity.h:38
#define es_SetFlags(flags)
Definition entity.h:43
f32 deltaScaleX
Definition entity.h:80
#define ENTITY_ROM(name)
Definition entity.h:65
u16 areaFlagIndex
Definition entity.h:86
struct Entity * linkedSwitch
Definition entity.h:89
Vec3f baseScale
Definition entity.h:85
f32 fallVel
Definition entity.h:79
s32 EntityScript[]
Definition entity.h:6
#define es_End
Definition entity.h:35
s8 animStateScaleY
Definition entity.h:84
f32 deltaScaleY
Definition entity.h:81
#define es_PlaySound(soundId)
Definition entity.h:45
s16 greenMotionTimer
Definition entity.h:87
@ PARTNER_ACTION_NONE
Definition enums.h:2932
@ ENTITY_TYPE_HUGE_BLUE_SWITCH
Definition enums.h:2552
@ ENTITY_TYPE_BLUE_SWITCH
Definition enums.h:2550
@ ENTITY_TYPE_GREEN_STOMP_SWITCH
Definition enums.h:2553
@ ENTITY_TYPE_RED_SWITCH
Definition enums.h:2551
@ PA_FLAG_MAP_HAS_SWITCH
Definition enums.h:3119
@ ENTITY_COLLISION_PARTNER
Definition enums.h:2655
@ ENTITY_COLLISION_PLAYER_HAMMER
Definition enums.h:2654
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
Definition enums.h:2648
@ SOUND_ACTIVATE_SWITCH
Definition enums.h:772
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ RENDER_MODE_SURFACE_XLU_LAYER1
Definition enums.h:3282
@ ENTITY_FLAG_8000
Definition enums.h:2628
@ ENTITY_FLAG_HAS_DYNAMIC_SHADOW
Definition enums.h:2615
@ ENTITY_FLAG_FIXED_SHADOW_SIZE
Definition enums.h:2622
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_4000
Definition enums.h:2627
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
Definition enums.h:2642
@ ENTITY_FLAG_ALWAYS_FACE_CAMERA
Definition enums.h:2626
@ ENTITY_FLAG_CIRCULAR_SHADOW
Definition enums.h:2624
@ PARTNER_PARAKARRY
Definition enums.h:2889
@ ACTION_STATE_SPIN_POUND
Definition enums.h:2442
@ ACTION_STATE_SPIN_JUMP
Definition enums.h:2441
@ ACTION_STATE_TORNADO_POUND
Definition enums.h:2444
@ ACTION_STATE_HAMMER
Definition enums.h:2446
b32 entity_raycast_down(f32 *, f32 *, f32 *, f32 *, f32 *, f32 *)
Mostly used for shadows.
Definition entity.c:1637
s32 entity_start_script(Entity *entity)
Definition entity.c:560
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
#define BSS
Definition macros.h:7
EntityData dataBuf
Vec3f scale
u8 collisionFlags
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition types.h:16
PartnerStatus gPartnerStatus
Definition partners.c:42
PlayerData gPlayerData
Definition 77480.c:40
PlayerStatus gPlayerStatus
Definition 77480.c:39
s32 set_area_flag(s32 index)