Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
ItemEntityJumpToPos.inc.c
Go to the documentation of this file.
1#include "common.h"
2
3API_CALLABLE(N(ItemEntityJumpToPos)) {
4 struct {
5 /* 0x00 */ Vec3f pos;
6 /* 0x0C */ f32 moveAngle;
7 /* 0x10 */ f32 jumpAccel;
8 /* 0x14 */ f32 moveSpeed;
9 /* 0x18 */ f32 jumpVel;
10 /* 0x1C */ s32 moveTime;
11 /* 0x20 */ s32 itemEntityIndex;
12 }* jumpState;
13 Bytecode* args = script->ptrReadPos;
14 ItemEntity* item;
15 f32 moveDist;
16 f32 temp_f2;
17
18 if (isInitialCall) {
19 jumpState = heap_malloc(sizeof(*jumpState));
20 script->functionTemp[0] = (s32) jumpState;
21 jumpState->itemEntityIndex = evt_get_variable(script, *args++);
22 jumpState->pos.x = evt_get_float_variable(script, *args++);
23 jumpState->pos.y = evt_get_float_variable(script, *args++);
24 jumpState->pos.z = evt_get_float_variable(script, *args++);
25 jumpState->moveTime = evt_get_variable(script, *args++);
26 jumpState->jumpAccel = evt_get_float_variable(script, *args++);
27 item = get_item_entity(jumpState->itemEntityIndex);
28 moveDist = dist2D(item->pos.x, item->pos.z, jumpState->pos.x, jumpState->pos.z);
29 jumpState->moveAngle = atan2(item->pos.x, item->pos.z, jumpState->pos.x, jumpState->pos.z);
30
31 temp_f2 = item->pos.y;
32 jumpState->jumpVel = (jumpState->jumpAccel * jumpState->moveTime * 0.5f)
33 + ((jumpState->pos.y - temp_f2) / jumpState->moveTime);
34
35 temp_f2 = jumpState->moveTime;
36 jumpState->moveSpeed = moveDist / temp_f2;
37 }
38
39 jumpState = (void*) script->functionTemp[0];
40 item = get_item_entity(jumpState->itemEntityIndex);
41 if (!item) {
42 heap_free((void*) script->functionTemp[0]);
43 return ApiStatus_DONE2;
44 }
45
46 item->pos.x += (jumpState->moveSpeed * sin_deg(jumpState->moveAngle));
47 item->pos.z -= (jumpState->moveSpeed * cos_deg(jumpState->moveAngle));
48 item->pos.y += jumpState->jumpVel;
49 jumpState->moveTime--;
50 jumpState->jumpVel = (jumpState->jumpVel - jumpState->jumpAccel);
51 if (jumpState->moveTime < 0) {
52 item->pos.x = jumpState->pos.x;
53 item->pos.y = jumpState->pos.y;
54 item->pos.z = jumpState->pos.z;
55 jumpState->jumpVel = 0.0f;
56 heap_free((void*) script->functionTemp[0]);
57 return ApiStatus_DONE1;
58 }
59
60 return ApiStatus_BLOCK;
61}
Vec3s pos
Definition demo_api.c:17
#define sin_deg
#define cos_deg
#define atan2
#define ApiStatus_DONE2
Definition evt.h:118
s32 Bytecode
Definition evt.h:7
#define ApiStatus_DONE1
Definition evt.h:117
#define ApiStatus_BLOCK
Definition evt.h:116
s32 evt_get_variable(Evt *script, Bytecode var)
Definition evt.c:1690
ItemEntity * get_item_entity(s32 itemEntityIndex)
f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by)
Definition 43F0.c:670
s32 heap_free(void *ptr)
Definition heap.c:42
f32 evt_get_float_variable(Evt *script, Bytecode var)
Definition evt.c:1930
void * heap_malloc(s32 size)
Definition heap.c:34