2020-08-04 08:49:11 +02:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 MakeLerp(Script* script, s32 initialCall) {
|
2020-08-14 02:29:25 +02:00
|
|
|
s32* ptrReadPos = script->ptrReadPos;
|
|
|
|
|
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-14 02:29:25 +02:00
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 UpdateLerp(Script* script, s32 initialCall) {
|
2020-08-15 02:49:33 +02:00
|
|
|
script->varTable[0x0] = (s32) update_lerp(
|
|
|
|
script->varTable[0xB],
|
2020-08-15 05:12:30 +02:00
|
|
|
script->varTable[0xC],
|
|
|
|
script->varTable[0xD],
|
2020-08-15 02:49:33 +02:00
|
|
|
script->varTable[0xE],
|
|
|
|
script->varTable[0xF]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (script->varTable[0xE] >= script->varTable[0xF]) {
|
|
|
|
script->varTable[0x1] = 0; // finished
|
|
|
|
} else {
|
|
|
|
script->varTable[0x1] = 1; // lerping
|
|
|
|
}
|
|
|
|
script->varTable[0xE]++;
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 RandInt(Script* script, s32 initialCall) {
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-15 05:25:48 +02:00
|
|
|
|
2020-08-15 07:00:29 +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
|
|
|
|
2020-08-15 07:00:29 +02:00
|
|
|
set_variable(script, outVar, rand_int(max));
|
2020-08-15 05:25:48 +02:00
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 GetAngleBetweenNPCs(Script* script, s32 initialCall) {
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-15 06:27:01 +02:00
|
|
|
|
|
|
|
NPC aID = get_variable(script, *ptrReadPos++);
|
|
|
|
NPC 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));
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 GetAngleToNPC(Script* script, s32 initialCall) {
|
|
|
|
PlayerStatus* playerStatus = &gPlayerStatus;
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-15 07:00:29 +02:00
|
|
|
|
|
|
|
NPC npcID = get_variable(script, *ptrReadPos++);
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode outVar = *ptrReadPos++;
|
2020-08-15 07:00:29 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
Npc* npc = resolve_npc(script, npcID);
|
2020-08-15 07:00:29 +02:00
|
|
|
set_variable(script, outVar, atan2(playerStatus->position.x, playerStatus->position.z, npc->pos.x, npc->pos.z));
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 GetAngleToPlayer(Script* script, s32 initialCall) {
|
|
|
|
PlayerStatus* playerStatus = &gPlayerStatus;
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-15 07:00:29 +02:00
|
|
|
|
|
|
|
NPC npcID = get_variable(script, *ptrReadPos++);
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode outVar = *ptrReadPos++;
|
2020-08-15 07:00:29 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
Npc* npc = resolve_npc(script, npcID);
|
2020-08-15 07:00:29 +02:00
|
|
|
set_variable(script, outVar, atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z));
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 AwaitPlayerApproach(Script* script, s32 initialCall) {
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-16 05:19:00 +02:00
|
|
|
PlayerStatus* playerStatus = &gPlayerStatus;
|
2020-08-15 07:55:16 +02:00
|
|
|
|
|
|
|
s32* targetX = &script->functionTemp[0];
|
|
|
|
s32* targetZ = &script->functionTemp[1];
|
|
|
|
s32* distanceRequired = &script->functionTemp[2];
|
|
|
|
|
|
|
|
f32 distance;
|
|
|
|
|
|
|
|
if (initialCall) {
|
|
|
|
*targetX = get_variable(script, *ptrReadPos++);
|
|
|
|
*targetZ = get_variable(script, *ptrReadPos++);
|
|
|
|
*distanceRequired = get_variable(script, *ptrReadPos++);
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-15 07:55:16 +02:00
|
|
|
distance = dist2D(
|
|
|
|
playerStatus->position.x, playerStatus->position.z,
|
|
|
|
*targetX, *targetZ
|
|
|
|
);
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-15 07:55:16 +02:00
|
|
|
if (distance < *distanceRequired) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 IsPlayerWithin(Script* script, s32 initialCall) {
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-16 05:19:00 +02:00
|
|
|
PlayerStatus* playerStatus = &gPlayerStatus;
|
2020-08-15 07:55:16 +02:00
|
|
|
|
|
|
|
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-15 07:55:16 +02:00
|
|
|
|
2020-08-15 19:46:34 +02:00
|
|
|
if (initialCall) {
|
2020-08-15 07:55:16 +02:00
|
|
|
*targetX = get_variable(script, *ptrReadPos++);
|
|
|
|
*targetZ = get_variable(script, *ptrReadPos++);
|
|
|
|
*distanceRequired = get_variable(script, *ptrReadPos++);
|
|
|
|
outVar = *ptrReadPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
distance = dist2D(
|
|
|
|
playerStatus->position.x, playerStatus->position.z,
|
|
|
|
*targetX, *targetZ
|
|
|
|
);
|
|
|
|
|
|
|
|
set_variable(script, outVar, 0);
|
|
|
|
if (distance < *distanceRequired) {
|
|
|
|
set_variable(script, outVar, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 AwaitPlayerLeave(Script* script, s32 initialCall) {
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-16 05:19:00 +02:00
|
|
|
PlayerStatus* playerStatus = &gPlayerStatus;
|
2020-08-15 07:55:16 +02:00
|
|
|
|
|
|
|
s32* targetX = &script->functionTemp[0];
|
|
|
|
s32* targetZ = &script->functionTemp[1];
|
|
|
|
s32* distanceRequired = &script->functionTemp[2];
|
|
|
|
|
|
|
|
f32 distance;
|
|
|
|
|
|
|
|
if (initialCall) {
|
|
|
|
*targetX = get_variable(script, *ptrReadPos++);
|
|
|
|
*targetZ = get_variable(script, *ptrReadPos++);
|
|
|
|
*distanceRequired = get_variable(script, *ptrReadPos++);
|
|
|
|
}
|
|
|
|
|
|
|
|
distance = dist2D(
|
|
|
|
playerStatus->position.x, playerStatus->position.z,
|
|
|
|
*targetX, *targetZ
|
|
|
|
);
|
|
|
|
|
|
|
|
if (distance > *distanceRequired) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 AddVectorPolar(Script* script, s32 initialCall) {
|
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);
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, func_802D4BDC);
|
|
|
|
/*
|
|
|
|
s32 func_802D4BDC(script_context* script, s32 initialCall) {
|
|
|
|
s32* t0 = &script->functionTemp[0];
|
|
|
|
s32* t1 = &script->functionTemp[1];
|
|
|
|
s32 t1v;
|
|
|
|
|
|
|
|
if (initialCall) {
|
|
|
|
*t0 = 0;
|
|
|
|
*t1 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*t0 == 0) {
|
|
|
|
t1v = *t1;
|
|
|
|
if (t1v != 0xFF) {
|
|
|
|
t1v += 0xA;
|
|
|
|
*t1 = t1v;
|
|
|
|
if (t1v < 0x100) {
|
|
|
|
// Void, debug stuff was probably here
|
|
|
|
}
|
|
|
|
t1v = 0xFF;
|
|
|
|
func_80137DA4(0xA, (f32) *t1);
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Very similar to func_802D4BDC
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, func_802D4C4C);
|
|
|
|
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, func_802D4CC4);
|
|
|
|
/*
|
|
|
|
s32 func_802D4CC4(script_context* script, s32 initialCall) {
|
|
|
|
s32 value = get_variable(script, *script->ptrReadPos);
|
|
|
|
if (value < 0) {
|
2020-08-15 20:03:09 +02:00
|
|
|
func_80137DA4(0xFF, -1.0f);
|
2020-08-15 16:26:43 +02:00
|
|
|
} else {
|
|
|
|
func_80137DA4(0xA, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 func_802D4D18(Script* 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);
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 func_802D4D88(Script* script, s32 initialCall) {
|
2020-08-15 16:26:43 +02:00
|
|
|
func_80137D88(0xC, 0);
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, setup_path_data);
|
|
|
|
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, func_802D5270);
|
|
|
|
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, LoadPath);
|
|
|
|
|
|
|
|
INCLUDE_ASM(code_f8f60_len_1560, GetNextPathPos);
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 GetDist2D(Script* script, s32 initialCall) {
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode* ptrReadPos = script->ptrReadPos;
|
2020-08-15 07:55:16 +02:00
|
|
|
|
2020-08-16 05:23:40 +02:00
|
|
|
Bytecode outVar = *ptrReadPos++;
|
2020-08-15 07:55:16 +02:00
|
|
|
set_float_variable(script, outVar, dist2D(
|
|
|
|
get_float_variable(script, *ptrReadPos++),
|
|
|
|
get_float_variable(script, *ptrReadPos++),
|
|
|
|
get_float_variable(script, *ptrReadPos++),
|
|
|
|
get_float_variable(script, *ptrReadPos++)
|
|
|
|
));
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 func_802D5830(Script* script, s32 initialCall) {
|
2020-08-15 16:26:43 +02:00
|
|
|
func_80027088(get_variable(script, *script->ptrReadPos));
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 func_802D585C(Script* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 SetValueByRef(Script* script, s32 initialCall) {
|
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);
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-15 07:55:16 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 GetValueByRef(Script* script, s32 initialCall) {
|
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-15 16:26:43 +02:00
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 EnableStatusMenu(Script* script, s32 initialCall) {
|
2020-08-15 14:00:51 +02:00
|
|
|
if (get_variable(script, *script->ptrReadPos) != 0) {
|
|
|
|
decrement_status_menu_disabled();
|
|
|
|
} else {
|
|
|
|
increment_status_menu_disabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 ShowStatusMenu(Script* script, s32 initialCall) {
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
2020-08-04 08:49:11 +02:00
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 SetGameMode(Script* script, s32 initialCall) {
|
2020-08-15 16:26:43 +02:00
|
|
|
set_game_mode(
|
|
|
|
// Clear upper half
|
|
|
|
(get_variable(script, *script->ptrReadPos) << 0x10) >> 0x10
|
|
|
|
);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 ClampAngleInt(Script* script, s32 initialCall) {
|
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)));
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2020-08-16 05:19:00 +02:00
|
|
|
s32 ClampAngleFloat(Script* script, s32 initialCall) {
|
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-15 16:26:43 +02:00
|
|
|
return 2;
|
2020-08-15 18:36:00 +02:00
|
|
|
}
|