papermario/src/code_f8f60_len_1560.c

441 lines
13 KiB
C
Raw Normal View History

2020-08-04 08:49:11 +02:00
#include "common.h"
2020-08-16 08:55:51 +02:00
ApiStatus MakeLerp(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-14 02:29:25 +02:00
2020-08-15 02:17:20 +02:00
script->varTable[0xC] = get_variable(script, *ptrReadPos++); // start
script->varTable[0xD] = get_variable(script, *ptrReadPos++); // end
script->varTable[0xF] = get_variable(script, *ptrReadPos++); // duration
script->varTable[0xB] = get_variable(script, *ptrReadPos++); // easing type
2020-08-15 02:49:33 +02:00
script->varTable[0xE] = 0; // elapsed
2020-08-15 02:17:20 +02:00
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-14 02:29:25 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus UpdateLerp(ScriptInstance* script, s32 isInitialCall) {
2020-08-15 02:49:33 +02:00
script->varTable[0x0] = (s32) update_lerp(
2020-08-19 02:16:12 +02:00
script->varTable[0xB],
script->varTable[0xC],
script->varTable[0xD],
script->varTable[0xE],
script->varTable[0xF]
);
2020-08-15 02:49:33 +02:00
if (script->varTable[0xE] >= script->varTable[0xF]) {
script->varTable[0x1] = 0; // finished
} else {
script->varTable[0x1] = 1; // lerping
}
script->varTable[0xE]++;
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 02:49:33 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus RandInt(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 05:25:48 +02:00
s32 max = get_variable(script, *ptrReadPos++);
2020-08-16 05:23:40 +02:00
Bytecode outVar = *ptrReadPos++;
2020-08-15 05:25:48 +02:00
set_variable(script, outVar, rand_int(max));
2020-08-15 05:25:48 +02:00
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 05:25:48 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus GetAngleBetweenNPCs(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 06:27:01 +02:00
2020-08-16 06:24:20 +02:00
NpcId aID = get_variable(script, *ptrReadPos++);
NpcId bID = get_variable(script, *ptrReadPos++);
2020-08-16 05:23:40 +02:00
Bytecode outVar = *ptrReadPos++;
2020-08-15 06:27:01 +02:00
2020-08-16 05:19:00 +02:00
Npc* a = resolve_npc(script, aID);
Npc* b = resolve_npc(script, bID);
2020-08-15 06:27:01 +02:00
set_variable(script, outVar, atan2(a->pos.x, a->pos.z, b->pos.x, b->pos.z));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 06:27:01 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus GetAngleToNPC(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:19:00 +02:00
PlayerStatus* playerStatus = &gPlayerStatus;
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 06:24:20 +02:00
NpcId npcID = get_variable(script, *ptrReadPos++);
2020-08-16 05:23:40 +02:00
Bytecode outVar = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
Npc* npc = resolve_npc(script, npcID);
set_variable(script, outVar, atan2(playerStatus->position.x, playerStatus->position.z, npc->pos.x, npc->pos.z));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus GetAngleToPlayer(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:19:00 +02:00
PlayerStatus* playerStatus = &gPlayerStatus;
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 06:24:20 +02:00
NpcId npcID = get_variable(script, *ptrReadPos++);
2020-08-16 05:23:40 +02:00
Bytecode outVar = *ptrReadPos++;
2020-08-16 05:19:00 +02:00
Npc* npc = resolve_npc(script, npcID);
set_variable(script, outVar, atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AwaitPlayerApproach(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 05:19:00 +02:00
PlayerStatus* playerStatus = &gPlayerStatus;
s32* targetX = &script->functionTemp[0];
s32* targetZ = &script->functionTemp[1];
s32* distanceRequired = &script->functionTemp[2];
f32 distance;
2020-08-16 08:55:51 +02:00
if (isInitialCall) {
*targetX = get_variable(script, *ptrReadPos++);
*targetZ = get_variable(script, *ptrReadPos++);
*distanceRequired = get_variable(script, *ptrReadPos++);
}
2020-08-04 08:49:11 +02:00
distance = dist2D(
2020-08-19 02:16:12 +02:00
playerStatus->position.x, playerStatus->position.z,
*targetX, *targetZ
);
2020-08-04 08:49:11 +02:00
if (distance < *distanceRequired) {
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
} else {
2020-08-16 08:55:51 +02:00
return ApiStatus_BLOCK;
}
}
2020-08-16 08:55:51 +02:00
ApiStatus IsPlayerWithin(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 05:19:00 +02:00
PlayerStatus* playerStatus = &gPlayerStatus;
s32* targetX = &script->functionTemp[0];
s32* targetZ = &script->functionTemp[1];
s32* distanceRequired = &script->functionTemp[2];
f32 distance;
2020-08-16 05:23:40 +02:00
Bytecode outVar = SI_VAR_0;
2020-08-16 08:55:51 +02:00
if (isInitialCall) {
*targetX = get_variable(script, *ptrReadPos++);
*targetZ = get_variable(script, *ptrReadPos++);
*distanceRequired = get_variable(script, *ptrReadPos++);
outVar = *ptrReadPos++;
}
distance = dist2D(
2020-08-19 02:16:12 +02:00
playerStatus->position.x, playerStatus->position.z,
*targetX, *targetZ
);
set_variable(script, outVar, 0);
if (distance < *distanceRequired) {
set_variable(script, outVar, 1);
}
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus AwaitPlayerLeave(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 05:19:00 +02:00
PlayerStatus* playerStatus = &gPlayerStatus;
s32* targetX = &script->functionTemp[0];
s32* targetZ = &script->functionTemp[1];
s32* distanceRequired = &script->functionTemp[2];
f32 distance;
2020-08-16 08:55:51 +02:00
if (isInitialCall) {
*targetX = get_variable(script, *ptrReadPos++);
*targetZ = get_variable(script, *ptrReadPos++);
*distanceRequired = get_variable(script, *ptrReadPos++);
}
distance = dist2D(
2020-08-19 02:16:12 +02:00
playerStatus->position.x, playerStatus->position.z,
*targetX, *targetZ
);
if (distance > *distanceRequired) {
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
} else {
2020-08-16 08:55:51 +02:00
return ApiStatus_BLOCK;
}
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus AddVectorPolar(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 16:26:43 +02:00
2020-08-16 05:23:40 +02:00
Bytecode xVar = *ptrReadPos++;
2020-08-15 16:26:43 +02:00
f32 x = get_float_variable(script, xVar);
2020-08-16 05:23:40 +02:00
Bytecode yVar = *ptrReadPos++;
2020-08-15 16:26:43 +02:00
f32 y = get_float_variable(script, yVar);
f32 r = get_float_variable(script, *ptrReadPos++);
add_vec2D_polar(&x, &y, r, get_float_variable(script, *ptrReadPos++));
set_float_variable(script, xVar, x);
set_float_variable(script, yVar, y);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D4BDC(ScriptInstance* script, s32 initialCall) {
2020-08-15 16:26:43 +02:00
s32* t0 = &script->functionTemp[0];
s32* t1 = &script->functionTemp[1];
s32 t1v;
if (initialCall) {
*t0 = 0;
*t1 = 0;
}
if (*t0 == 0) {
t1v = *t1;
2020-08-22 09:43:30 +02:00
if (t1v == 255) {
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-22 09:43:30 +02:00
t1v += 10;
*t1 = t1v;
if (t1v > 255) {
*t1 = 255;
}
func_80137DA4(10, *t1);
2020-08-15 16:26:43 +02:00
}
2020-08-22 09:43:30 +02:00
return ApiStatus_BLOCK;
2020-08-15 16:26:43 +02:00
}
2020-08-22 09:43:30 +02:00
ApiStatus func_802D4C4C(ScriptInstance* script, s32 initialCall) {
s32* t0 = &script->functionTemp[0];
s32* t1 = &script->functionTemp[1];
s32 t1v;
if (initialCall) {
*t0 = 0;
*t1 = 255;
}
if (*t0 == 0) {
t1v = *t1;
if (t1v == 0) {
func_80137DA4(255, -1.0f);
return ApiStatus_DONE2;
}
t1v -= 10;
*t1 = t1v;
if(t1v < 0) {
*t1 = 0;
}
func_80137DA4(10, *t1);
}
return ApiStatus_BLOCK;
}
2020-08-15 16:26:43 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus func_802D4CC4(ScriptInstance* script, s32 initialCall) {
2020-08-15 16:26:43 +02:00
s32 value = get_variable(script, *script->ptrReadPos);
if (value < 0) {
2020-08-22 09:43:30 +02:00
func_80137DA4(255, -1.0f);
2020-08-15 16:26:43 +02:00
} else {
2020-08-22 09:43:30 +02:00
func_80137DA4(10, value);
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D4D18(ScriptInstance* script, s32 initialCall) {
2020-08-15 16:26:43 +02:00
s32 value = get_float_variable(script, *script->ptrReadPos);
func_80137E4C(0, 0, 0xC, 0x14);
func_80137E4C(0, 1, 0x134, 0xDC);
func_80137D88(0xC, value);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D4D88(ScriptInstance* script, s32 initialCall) {
2020-08-15 16:26:43 +02:00
func_80137D88(0xC, 0);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-04 08:49:11 +02:00
INCLUDE_ASM("code_f8f60_len_1560", setup_path_data);
2020-08-22 09:43:30 +02:00
/*void setup_path_data(s32 numVecs, f32* arg1, struct Vec3f* arg2, struct Vec3f* arg3) {
struct Vec3f *temp_s4;
f32 *temp_s7;
s32 i;
temp_s7 = heap_malloc(numVecs * sizeof(f32));
temp_s4 = heap_malloc(numVecs * sizeof(Vec3f));
arg1[0] = 0.0f;
for (i = 1; i < numVecs; i++) {
arg1[i] = (arg1[i - 1] + sqrtf(SQ(arg2[i].x - arg2[i - 1].x) + SQ(arg2[i].y - arg2[i - 1].y) + SQ(arg2[i].z - arg2[i - 1].z)));
}
for (i = 1; i < numVecs; i++) {
arg1[i] = arg1[i] / arg1[numVecs - 1];
}
arg3[0].x = 0;
arg3[0].y = 0;
arg3[0].z = 0;
arg3[numVecs - 1].x = 0;
arg3[numVecs - 1].y = 0;
arg3[numVecs - 1].z = 0;
for (i = 0; i < (numVecs - 1); i++) {
temp_s7[i] = arg1[i + 1] - arg1[i];
temp_s4[i + 1].x = ((arg2[i + 1].x - arg2[i].x) / temp_s7[i]);
temp_s4[i + 1].y = ((arg2[i + 1].y - arg2[i].y) / temp_s7[i]);
temp_s4[i + 1].z = ((arg2[i + 1].z - arg2[i].z) / temp_s7[i]);
}
arg3[0].x = temp_s4[2].x - temp_s4[1].x;
arg3[0].y = temp_s4[2].y - temp_s4[1].y;
arg3[0].z = temp_s4[2].z - temp_s4[1].z;
temp_s4[1].x = ((arg1[2] - arg1[0]) * 2);
temp_s4[1].y = ((arg1[2] - arg1[0]) * 2);
temp_s4[1].z = ((arg1[2] - arg1[0]) * 2);
for (i = 1; i < numVecs - 2; i++) {
arg3[i + 1].x = (temp_s4[i + 2].x - temp_s4[i].x) - (arg3[i].x * (temp_s7[i] / temp_s4[i].x));
arg3[i + 1].y = (temp_s4[i + 2].y - temp_s4[i].y) - (arg3[i].y * (temp_s7[i] / temp_s4[i].y));
arg3[i + 1].z = (temp_s4[i + 2].z - temp_s4[i].z) - (arg3[i].z * (temp_s7[i] / temp_s4[i].z));
temp_s4[i].x = ((arg1[i + 2] - arg1[i]) * 2) - (temp_s7[i] * (temp_s7[i] / temp_s4[i].x));
temp_s4[i].y = ((arg1[i + 2] - arg1[i]) * 2) - (temp_s7[i] * (temp_s7[i] / temp_s4[i].y));
temp_s4[i].z = ((arg1[i + 2] - arg1[i]) * 2) - (temp_s7[i] * (temp_s7[i] / temp_s4[i].z));
}
arg3[numVecs - 2].x = arg3[numVecs - 2].x - (temp_s7[numVecs - 2] * arg3[numVecs - 1].x);
arg3[numVecs - 2].y = arg3[numVecs - 2].y - (temp_s7[numVecs - 2] * arg3[numVecs - 1].y);
arg3[numVecs - 2].z = arg3[numVecs - 2].z - (temp_s7[numVecs - 2] * arg3[numVecs - 1].z);
for(i = (numVecs - 2); i > 0; i--) {
arg3[i].x = (arg3[i].x - (temp_s7[0] * arg3[i].x)) / temp_s4[i].x;
arg3[i].y = (arg3[i].y - (temp_s7[0] * arg3[i].y)) / temp_s4[i].y;
arg3[i].z = (arg3[i].z - (temp_s7[0] * arg3[i].z)) / temp_s4[i].z;
}
heap_free(temp_s7);
heap_free(temp_s4);
}*/
2020-08-04 08:49:11 +02:00
INCLUDE_ASM("code_f8f60_len_1560", func_802D5270);
2020-08-04 08:49:11 +02:00
INCLUDE_API_ASM("code_f8f60_len_1560", LoadPath);
2020-08-04 08:49:11 +02:00
INCLUDE_API_ASM("code_f8f60_len_1560", GetNextPathPos);
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus GetDist2D(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-16 05:23:40 +02:00
Bytecode outVar = *ptrReadPos++;
set_float_variable(script, outVar, dist2D(
2020-08-19 02:16:12 +02:00
get_float_variable(script, *ptrReadPos++),
get_float_variable(script, *ptrReadPos++),
get_float_variable(script, *ptrReadPos++),
get_float_variable(script, *ptrReadPos++)
));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D5830(ScriptInstance* script, s32 initialCall) {
2020-08-15 16:26:43 +02:00
func_80027088(get_variable(script, *script->ptrReadPos));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus func_802D585C(ScriptInstance* script, s32 initialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 16:26:43 +02:00
s32 setMode = get_variable(script, *ptrReadPos++);
s32 flags = get_variable(script, *ptrReadPos++);
if (setMode) {
// Set flag
D_8009A650[0] |= flags;
} else {
// Unset flag
D_8009A650[0] &= ~flags;
}
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus SetValueByRef(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 16:26:43 +02:00
s32 dest = get_variable(script, *ptrReadPos++); /* Reference */
s32 src = get_variable(script, *ptrReadPos++);
set_variable(script, dest, src);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus GetValueByRef(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 16:26:43 +02:00
s32 src = get_variable(script, *ptrReadPos++); /* Reference */
2020-08-16 05:23:40 +02:00
Bytecode dest = *ptrReadPos++;
2020-08-04 08:49:11 +02:00
2020-08-15 16:26:43 +02:00
set_variable(script, dest, get_variable(script, src));
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus EnableStatusMenu(ScriptInstance* script, s32 isInitialCall) {
2020-08-15 14:00:51 +02:00
if (get_variable(script, *script->ptrReadPos) != 0) {
decrement_status_menu_disabled();
} else {
increment_status_menu_disabled();
}
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 14:00:51 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus ShowStatusMenu(ScriptInstance* script, s32 isInitialCall) {
2020-08-15 14:00:51 +02:00
if (get_variable(script, *script->ptrReadPos) != 0) {
status_menu_enable_ignore_changes();
func_800E97B8();
} else {
status_menu_disable_ignore_changes();
}
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 14:00:51 +02:00
}
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
ApiStatus SetGameMode(ScriptInstance* script, s32 isInitialCall) {
2020-08-22 09:43:30 +02:00
s16 mode = get_variable(script, *script->ptrReadPos);
set_game_mode(mode);
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus ClampAngleInt(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-15 16:26:43 +02:00
set_variable(script, *ptrReadPos, clamp_angle(get_variable(script, *ptrReadPos)));
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 16:26:43 +02:00
}
2020-08-16 08:55:51 +02:00
ApiStatus ClampAngleFloat(ScriptInstance* script, s32 isInitialCall) {
2020-08-16 05:23:40 +02:00
Bytecode* ptrReadPos = script->ptrReadPos;
2020-08-04 08:49:11 +02:00
2020-08-15 16:26:43 +02:00
set_float_variable(script, *ptrReadPos, clamp_angle(get_float_variable(script, *ptrReadPos)));
2020-08-04 08:49:11 +02:00
2020-08-16 08:55:51 +02:00
return ApiStatus_DONE2;
2020-08-15 18:36:00 +02:00
}