Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
UnkLightningBoltFxFunc1.inc.c
Go to the documentation of this file.
1#include "common.h"
2#include "effects.h"
3
4typedef struct FxLightningBoltState {
5 /* 0x00 */ EffectInstance* effect;
6 /* 0x04 */ Vec3f pos;
7 /* 0x10 */ f32 radius;
8 /* 0x14 */ f32 yaw;
9 /* 0x18 */ f32 angularSpeed;
10 /* 0x1C */ s32 duration;
11} FxLightningBoltState; // size = 0x20
12
13API_CALLABLE(N(UnkLightningBoltFxFunc1)) {
14 Bytecode* args = script->ptrReadPos;
15 Actor* actor = get_actor(script->owner1.actorID);
16 s32 i;
17 FxLightningBoltState* effectState;
18 ActorState* actorState;
19
20 if (actor == NULL) {
21 return ApiStatus_DONE2;
22 }
23
24 actorState = &actor->state;
25
26 if (isInitialCall) {
27 s32 x, y, z;
28
29 effectState = heap_malloc(sizeof(FxLightningBoltState) * 3);
30 actorState->functionTempPtr[0] = effectState;
31
32 x = evt_get_variable(script, *args++);
33 y = 0;
34 z = evt_get_variable(script, *args++);
35
36 for (i = 0; i < 3; effectState++, i++) {
37 effectState->effect = fx_lightning_bolt(2, x, 200.0f, z, x, 0.0f, z, 1.0f, 60);
38 effectState->duration = 45;
39 effectState->pos.x = x;
40 effectState->pos.y = y;
41 effectState->pos.z = z;
42
43 effectState->radius = 10.0f;
44 effectState->yaw = i * 120;
45 effectState->angularSpeed = 15.0f;
46
47 }
48 return ApiStatus_BLOCK;
49 }
50
51 effectState = actorState->functionTempPtr[0];
52
53 for (i = 0; i < 3; effectState++, i++) {
54 f32 x = effectState->pos.x + cos_deg(effectState->yaw) * effectState->radius;
55 f32 z = effectState->pos.z + sin_deg(effectState->yaw) * effectState->radius;
56
57 effectState->effect->data.lightningBolt->tipPos.x = x;
58 effectState->effect->data.lightningBolt->startPos.x = x;
59 effectState->effect->data.lightningBolt->endPos.x = x;
60
61 effectState->effect->data.lightningBolt->tipPos.z = z;
62 effectState->effect->data.lightningBolt->startPos.z = z;
63 effectState->effect->data.lightningBolt->endPos.z = z;
64
65 if (effectState->duration > 10) {
66 effectState->radius += 1.5;
67 }
68 effectState->yaw += effectState->angularSpeed;
69 if (effectState->duration > 30) {
70 effectState->angularSpeed -= 0.3;
71 }
72 effectState->duration--;
73 }
74
75 effectState = actorState->functionTempPtr[0];
76 if (effectState->duration <= 0) {
77 heap_free(effectState);
78 return ApiStatus_DONE2;
79 } else {
80 return ApiStatus_BLOCK;
81 }
82}
ActorState state
#define sin_deg
#define cos_deg
struct LightningBoltFXData * lightningBolt
Definition effects.h:2558
EffectData data
Definition effects.h:2605
#define ApiStatus_DONE2
Definition evt.h:118
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
s32 heap_free(void *ptr)
Definition heap.c:42
Actor * get_actor(s32 actorID)
Definition actor_api.c:155
void * heap_malloc(s32 size)
Definition heap.c:34