diff --git a/asm/include/main_0204B018.inc b/asm/include/main_0204B018.inc index 08af7c11..cf9a4392 100644 --- a/asm/include/main_0204B018.inc +++ b/asm/include/main_0204B018.inc @@ -11,3 +11,4 @@ .public SCRIPT_VARS .public SCRIPT_VARS_LOCALS .public SCRIPT_VARS_VALUES +.public ZinitScriptVariable diff --git a/asm/main_0204B018.s b/asm/main_0204B018.s index 41f657ad..9af6580e 100644 --- a/asm/main_0204B018.s +++ b/asm/main_0204B018.s @@ -336,36 +336,4 @@ _0204B41C: _0204B42C: .word SCRIPT_VARS _0204B430: .word SCRIPT_VARS_LOCALS arm_func_end sub_0204B3D0 - - arm_func_start ZinitScriptVariable -ZinitScriptVariable: ; 0x0204B434 - stmdb sp!, {r4, r5, r6, r7, r8, lr} - mov r5, r1 - cmp r5, #0x400 - mov r6, r0 - ldrlt r0, _0204B494 ; =SCRIPT_VARS - mov r8, #0 - addlt r4, r0, r5, lsl #4 - ldrge r1, _0204B498 ; =SCRIPT_VARS_LOCALS - subge r0, r5, #0x400 - addge r4, r1, r0, lsl #4 - mov r7, r8 - b _0204B484 -_0204B464: - mov r0, r6 - mov r1, r5 - mov r2, r8 - mov r3, r7 - bl SaveScriptVariableValueAtIndex - add r0, r8, #1 - mov r0, r0, lsl #0x10 - mov r8, r0, lsr #0x10 -_0204B484: - ldrsh r0, [r4, #8] - cmp r8, r0 - blt _0204B464 - ldmia sp!, {r4, r5, r6, r7, r8, pc} - .align 2, 0 -_0204B494: .word SCRIPT_VARS -_0204B498: .word SCRIPT_VARS_LOCALS - arm_func_end ZinitScriptVariable + \ No newline at end of file diff --git a/include/has_played_old_game.h b/include/has_played_old_game.h deleted file mode 100644 index cdc51261..00000000 --- a/include/has_played_old_game.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef PMDSKY_HAS_PLAYED_OLD_GAME_H -#define PMDSKY_HAS_PLAYED_OLD_GAME_H - -#include "util.h" - -bool8 HasPlayedOldGame(); - -#endif //PMDSKY_HAS_PLAYED_OLD_GAME_H diff --git a/include/performance_progress.h b/include/performance_progress.h deleted file mode 100644 index 2450eebc..00000000 --- a/include/performance_progress.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef PMDSKY_PERFORMANCE_PROGRESS_H -#define PMDSKY_PERFORMANCE_PROGRESS_H - -#include "util.h" - -bool8 GetResolvedPerformanceProgressFlag(u32 idx); -void SetResolvedPerformanceProgressFlag(u32 idx, s32 value); - -#endif //PMDSKY_PERFORMANCE_PROGRESS_H diff --git a/include/main_0204CB94.h b/include/progression.h similarity index 61% rename from include/main_0204CB94.h rename to include/progression.h index 963a88ab..e75bb18b 100644 --- a/include/main_0204CB94.h +++ b/include/progression.h @@ -1,6 +1,11 @@ -#ifndef PMDSKY_MAIN_0204CB94_H -#define PMDSKY_MAIN_0204CB94_H +#ifndef PMDSKY_PROGRESSION_H +#define PMDSKY_PROGRESSION_H +#include "util.h" + +bool8 HasPlayedOldGame(); +bool8 GetResolvedPerformanceProgressFlag(u32 idx); +void SetResolvedPerformanceProgressFlag(u32 idx, s32 value); // Returns the current SCENARIO_BALANCE value. // The exact value returned depends on multiple factors: // - If the first special episode is active, returns 1 @@ -9,4 +14,4 @@ // - In all other cases, the value of the SCENARIO_BALANCE_FLAG variable is returned u8 GetScenarioBalance(); -#endif //PMDSKY_MAIN_0204CB94_H +#endif //PMDSKY_PROGRESSION_H diff --git a/include/script_variable.h b/include/script_variable.h index d354440d..b3a01250 100644 --- a/include/script_variable.h +++ b/include/script_variable.h @@ -29,6 +29,7 @@ struct script_var_raw { union script_var_value *value; }; +void ZinitScriptVariable(union script_var_value sv_locals[], enum script_var_id sv_id); void LoadScriptVariableRaw(struct script_var_raw* sv_raw, union script_var_value sv_val_local[], const enum script_var_id sv_id); s32 LoadScriptVariableValue(union script_var_value sv_local[], enum script_var_id sv_id); s32 LoadScriptVariableValueAtIndex(union script_var_value sv_local[], enum script_var_id id, u16 idx); diff --git a/main.lsf b/main.lsf index 4f8c3ef1..88efd8d5 100644 --- a/main.lsf +++ b/main.lsf @@ -88,9 +88,7 @@ Static main Object asm/main_rodata_020A18BC.o Object src/story_progress.o Object src/special_episode.o - Object src/has_played_old_game.o - Object src/performance_progress.o - Object src/main_0204CB94.o + Object src/progression.o Object src/scenario_flag.o Object asm/main_0204CD88.o Object src/main_0204DA2C.o diff --git a/src/dungeon_pokemon_attributes_1.c b/src/dungeon_pokemon_attributes_1.c index 609b18c0..5942a625 100644 --- a/src/dungeon_pokemon_attributes_1.c +++ b/src/dungeon_pokemon_attributes_1.c @@ -8,11 +8,9 @@ #include "main_02058E68.h" #include "overlay_29_022FF898.h" #include "overlay_29_023000E4.h" -#include "performance_progress.h" +#include "progression.h" #include "pokemon.h" -extern bool8 GetPerformanceFlagWithChecks(s32 flag_id); - bool8 CanSeeInvisibleMonsters(struct entity *entity) { if (GetEntInfo(entity)->blinker_class_status.blinded == STATUS_BLINKER_EYEDROPS) diff --git a/src/dungeon_recruitment.c b/src/dungeon_recruitment.c index 49bba6e8..38f081d4 100644 --- a/src/dungeon_recruitment.c +++ b/src/dungeon_recruitment.c @@ -5,7 +5,6 @@ #include "dungeon_pokemon_attributes_1.h" #include "dungeon_recruitment.h" #include "dungeon_recruitment_2.h" -#include "has_played_old_game.h" #include "dg_random.h" #include "dungeon_visibility.h" #include "enums.h" @@ -14,6 +13,7 @@ #include "main_0208655C.h" #include "math.h" #include "overlay_29_0230E578.h" // ItemIsActive__0230E578 +#include "progression.h" extern bool8 IsLegendaryChallengeFloor(void); extern bool8 IsCurrentMissionTypeExact(u32 mission_type, u32 mission_subtype); diff --git a/src/has_played_old_game.c b/src/has_played_old_game.c deleted file mode 100644 index 28546d32..00000000 --- a/src/has_played_old_game.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "has_played_old_game.h" -#include "enums.h" -#include "script_variable.h" -#include "util.h" - -bool8 HasPlayedOldGame() -{ - if(LoadScriptVariableValue(0, VAR_PLAY_OLD_GAME)) { - return TRUE; - } else { - return FALSE; - } -} diff --git a/src/main_0200EDC0.c b/src/main_0200EDC0.c index 6d9a614b..f07ea6fc 100644 --- a/src/main_0200EDC0.c +++ b/src/main_0200EDC0.c @@ -1,8 +1,7 @@ #include "main_0200EDC0.h" #include "item.h" -#include "main_0204CB94.h" #include "main_020517D4.h" -#include "performance_progress.h" +#include "progression.h" #include "script_variable.h" #include "special_episode.h" diff --git a/src/main_0204CB94.c b/src/main_0204CB94.c deleted file mode 100644 index 31185870..00000000 --- a/src/main_0204CB94.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "main_0204CB94.h" -#include "script_variable.h" - -u8 GetScenarioBalance() -{ - s32 special_episode_type = LoadScriptVariableValue(0, VAR_EXECUTE_SPECIAL_EPISODE_TYPE); - if (special_episode_type == EPISODE_NONE) - { - s32 scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_DEBUG); - if (scenario_balance < 0) - scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_FLAG); - - return scenario_balance; - } - - if (special_episode_type == EPISODE_BIDOOFS_WISH) - return 1; - return 3; -} diff --git a/src/performance_progress.c b/src/progression.c similarity index 67% rename from src/performance_progress.c rename to src/progression.c index 31cfac86..ab0b3345 100644 --- a/src/performance_progress.c +++ b/src/progression.c @@ -1,9 +1,18 @@ #include "enums.h" -#include "performance_progress.h" +#include "progression.h" #include "script_variable.h" extern enum game_mode GetGameMode(); +bool8 HasPlayedOldGame() +{ + if(LoadScriptVariableValue(0, VAR_PLAY_OLD_GAME)) { + return TRUE; + } else { + return FALSE; + } +} + bool8 GetResolvedPerformanceProgressFlag(u32 idx) { switch (idx) { case 0: @@ -55,3 +64,20 @@ void SetResolvedPerformanceProgressFlag(u32 idx, s32 value) { return; } } + +u8 GetScenarioBalance() +{ + s32 special_episode_type = LoadScriptVariableValue(0, VAR_EXECUTE_SPECIAL_EPISODE_TYPE); + if (special_episode_type == EPISODE_NONE) + { + s32 scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_DEBUG); + if (scenario_balance < 0) + scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_FLAG); + + return scenario_balance; + } + + if (special_episode_type == EPISODE_BIDOOFS_WISH) + return 1; + return 3; +} diff --git a/src/script_variable.c b/src/script_variable.c index 952dfadc..31688bf8 100644 --- a/src/script_variable.c +++ b/src/script_variable.c @@ -8,7 +8,7 @@ #include "special_episode.h" #include "story_progress.h" -#define LOCAL_SCRIPT_VAR_OFFSET 0x400 +#define LOCAL_SCRIPT_VAR_OFFSET (s16) 0x400 // Global script variable definitions extern struct script_var_def SCRIPT_VARS[]; @@ -39,7 +39,20 @@ extern s32 AddMoneyCarried(s32 arg0); extern s32 SetMoneyCarried(s32 arg0); extern s32 SetMoneyStored(s32 arg0); extern s32 SetNotifyNote(s32 arg0); -extern void ZinitScriptVariable(u32 param_1, u32 param_2); + +void ZinitScriptVariable(union script_var_value sv_locals[], enum script_var_id sv_id) { + struct script_var_def* def; + + if (sv_id < LOCAL_SCRIPT_VAR_OFFSET) { + def = &SCRIPT_VARS[sv_id]; + } else { + def = &SCRIPT_VARS_LOCALS[sv_id - LOCAL_SCRIPT_VAR_OFFSET]; + } + + for(u16 idx = 0; idx < def->n_values; idx++) { + SaveScriptVariableValueAtIndex(sv_locals, sv_id, idx, 0); + } +} void LoadScriptVariableRaw(struct script_var_raw* sv_raw, union script_var_value sv_val_local[],