Skip to content

Commit

Permalink
Merge pull request #358 from justusaac/main
Browse files Browse the repository at this point in the history
Documenting code for the Stats Judge
  • Loading branch information
lhearachel authored Feb 4, 2025
2 parents f6d8ad2 + 78a755e commit 5a48355
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion asm/macros/scrcmd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4078,7 +4078,7 @@
.short 749
.endm

.macro ScrCmd_2EE arg0, arg1, arg2, arg3
.macro JudgeStats arg0, arg1, arg2, arg3
.short 750
.short \arg0
.short \arg1
Expand Down
2 changes: 1 addition & 1 deletion include/overlay005/ov5_021F6454.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "field_script_context.h"

BOOL ScrCmd_2DE(ScriptContext *param0);
BOOL ScrCmd_2EE(ScriptContext *param0);
BOOL ScrCmd_JudgeStats(ScriptContext *param0);
BOOL ScrCmd_31D(ScriptContext *param0);
BOOL ScrCmd_31E(ScriptContext *param0);
BOOL ScrCmd_2F1(ScriptContext *param0);
Expand Down
2 changes: 1 addition & 1 deletion res/field/scripts/scripts_battle_tower.s
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ _140A:
GoToIfEq 0x8000, 0xFF, _1549
ScrCmd_198 0x8000, 0x8004
GoToIfEq 0x8004, 0, _149C
ScrCmd_2EE 0x8000, 0x8001, 0x8002, 0x8003
JudgeStats 0x8000, 0x8001, 0x8002, 0x8003
GoToIfLe 0x8001, 90, _14E9
GoToIfLe 0x8001, 120, _14F4
GoToIfLe 0x8001, 150, _14FF
Expand Down
83 changes: 42 additions & 41 deletions src/overlay005/ov5_021F6454.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
#include "unk_0206AFE0.h"
#include "vars_flags.h"

#include "res/text/bank/battle_tower.h"

typedef struct {
s16 unk_00;
s16 unk_02;
Expand Down Expand Up @@ -98,7 +100,7 @@ static void ov5_021F70CC(Pokemon *param0, int *param1, int *param2);
BOOL ScrCmd_300(ScriptContext *ctx);
BOOL ScrCmd_301(ScriptContext *ctx);
BOOL ScrCmd_30F(ScriptContext *ctx);
BOOL ScrCmd_2EE(ScriptContext *ctx);
BOOL ScrCmd_JudgeStats(ScriptContext *ctx);
BOOL ScrCmd_2F1(ScriptContext *ctx);
static void ov5_021F661C(UnkStruct_ov5_021F6704 *param0, MessageLoader *param1);
static void ov5_021F6624(FieldSystem *fieldSystem, UnkStruct_ov5_021F6704 *param1, u8 param2, u8 param3, u8 param4, u8 param5, u16 *param6, StringTemplate *param7, Window *param8, MessageLoader *param9, u16 *param10, u16 *param11);
Expand Down Expand Up @@ -435,57 +437,56 @@ static void ov5_021F6AD4(UnkStruct_ov5_021F6704 *param0)
return;
}

static const u16 Unk_ov5_02200C84[] = {
0x7A,
0x7B,
0x7C,
0x7F,
0x7D,
0x7E
static const u16 sHighestIVMessageIndices[] = {
pl_msg_00000304_00122,
pl_msg_00000304_00123,
pl_msg_00000304_00124,
pl_msg_00000304_00127,
pl_msg_00000304_00125,
pl_msg_00000304_00126
};

BOOL ScrCmd_2EE(ScriptContext *param0)
BOOL ScrCmd_JudgeStats(ScriptContext *ctx)
{
u8 v0;
u32 v1[6];
Pokemon *v2;
FieldSystem *fieldSystem = param0->fieldSystem;
u16 v4 = ScriptContext_GetVar(param0);
u16 *v5 = ScriptContext_GetVarPointer(param0);
u16 *v6 = ScriptContext_GetVarPointer(param0);
u16 *v7 = ScriptContext_GetVarPointer(param0);

v2 = Party_GetPokemonBySlotIndex(Party_GetFromSavedata(fieldSystem->saveData), v4);

v1[0] = Pokemon_GetValue(v2, MON_DATA_HP_IV, NULL);
v1[1] = Pokemon_GetValue(v2, MON_DATA_ATK_IV, NULL);
v1[2] = Pokemon_GetValue(v2, MON_DATA_DEF_IV, NULL);
v1[3] = Pokemon_GetValue(v2, MON_DATA_SPEED_IV, NULL);
v1[4] = Pokemon_GetValue(v2, MON_DATA_SPATK_IV, NULL);
v1[5] = Pokemon_GetValue(v2, MON_DATA_SPDEF_IV, NULL);

*v5 = 0;

for (v0 = 0; v0 < 6; v0++) {
*v5 += v1[v0];
FieldSystem *fieldSystem = ctx->fieldSystem;
u16 selectedIndex = ScriptContext_GetVar(ctx);
u16 *totalIVs = ScriptContext_GetVarPointer(ctx);
u16 *highestIVIndex = ScriptContext_GetVarPointer(ctx);
u16 *highestIVValue = ScriptContext_GetVarPointer(ctx);

Pokemon *targetPokemon = Party_GetPokemonBySlotIndex(Party_GetFromSavedata(fieldSystem->saveData), selectedIndex);

u32 pokemonIVs[6];
pokemonIVs[0] = Pokemon_GetValue(targetPokemon, MON_DATA_HP_IV, NULL);
pokemonIVs[1] = Pokemon_GetValue(targetPokemon, MON_DATA_ATK_IV, NULL);
pokemonIVs[2] = Pokemon_GetValue(targetPokemon, MON_DATA_DEF_IV, NULL);
pokemonIVs[3] = Pokemon_GetValue(targetPokemon, MON_DATA_SPEED_IV, NULL);
pokemonIVs[4] = Pokemon_GetValue(targetPokemon, MON_DATA_SPATK_IV, NULL);
pokemonIVs[5] = Pokemon_GetValue(targetPokemon, MON_DATA_SPDEF_IV, NULL);

*totalIVs = 0;
u8 i;

for (i = 0; i < 6; i++) {
*totalIVs += pokemonIVs[i];
}

*v6 = 0;
*v7 = v1[0];
*highestIVIndex = 0;
*highestIVValue = pokemonIVs[0];

for (v0 = 1; v0 < 6; v0++) {
if (v1[*v6] < v1[v0]) {
*v6 = v0;
*v7 = v1[v0];
} else if (v1[*v6] == v1[v0]) {
for (i = 1; i < 6; i++) {
if (pokemonIVs[*highestIVIndex] < pokemonIVs[i]) {
*highestIVIndex = i;
*highestIVValue = pokemonIVs[i];
} else if (pokemonIVs[*highestIVIndex] == pokemonIVs[i]) {
if ((LCRNG_Next() % 2) == 0) {
*v6 = v0;
*v7 = v1[v0];
*highestIVIndex = i;
*highestIVValue = pokemonIVs[i];
}
}
}

*v6 = Unk_ov5_02200C84[*v6];
*highestIVIndex = sHighestIVMessageIndices[*highestIVIndex];
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/scrcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ const ScrCmdFunc Unk_020EAC58[] = {
ScrCmd_2EB,
ScrCmd_2EC,
ScrCmd_2ED,
ScrCmd_2EE,
ScrCmd_JudgeStats,
ScrCmd_2EF,
ScrCmd_2F0,
ScrCmd_2F1,
Expand Down

0 comments on commit 5a48355

Please sign in to comment.