Move some vars to C

This commit is contained in:
DizzyEggg 2019-01-13 13:15:23 +01:00
parent 11a49a7f02
commit c0bc01d301
19 changed files with 282 additions and 250 deletions

View File

@ -599,7 +599,7 @@ BattleScript_EffectBide::
ppreduce ppreduce
attackanimation attackanimation
waitanimation waitanimation
orword gHitMarker, HITMARKER_x8000000 orword gHitMarker, HITMARKER_CHARGING
setbide setbide
goto BattleScript_MoveEnd goto BattleScript_MoveEnd
@ -824,7 +824,7 @@ BattleScriptFirstChargingTurn::
ppreduce ppreduce
attackanimation attackanimation
waitanimation waitanimation
orword gHitMarker, HITMARKER_x8000000 orword gHitMarker, HITMARKER_CHARGING
setmoveeffect MOVE_EFFECT_CHARGING | MOVE_EFFECT_AFFECTS_USER setmoveeffect MOVE_EFFECT_CHARGING | MOVE_EFFECT_AFFECTS_USER
seteffectprimary seteffectprimary
copybyte cMULTISTRING_CHOOSER, sTWOTURN_STRINGID copybyte cMULTISTRING_CHOOSER, sTWOTURN_STRINGID
@ -1941,7 +1941,7 @@ BattleScript_SolarbeamDecideTurn::
call BattleScriptFirstChargingTurn call BattleScriptFirstChargingTurn
goto BattleScript_MoveEnd goto BattleScript_MoveEnd
BattleScript_SolarbeamOnFirstTurn:: BattleScript_SolarbeamOnFirstTurn::
orword gHitMarker, HITMARKER_x8000000 orword gHitMarker, HITMARKER_CHARGING
setmoveeffect MOVE_EFFECT_CHARGING | MOVE_EFFECT_AFFECTS_USER setmoveeffect MOVE_EFFECT_CHARGING | MOVE_EFFECT_AFFECTS_USER
seteffectprimary seteffectprimary
ppreduce ppreduce

View File

@ -3221,7 +3221,7 @@ EventScript_2736F8:: @ 82736F8
compare VAR_RESULT, 2 compare VAR_RESULT, 2
goto_if_eq BattleFrontier_BattlePyramidTop_EventScript_252B42 goto_if_eq BattleFrontier_BattlePyramidTop_EventScript_252B42
setvar VAR_0x8004, 10 setvar VAR_0x8004, 10
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 1 compare VAR_RESULT, 1
goto_if_eq TrainerHill_1F_EventScript_2C83C9 goto_if_eq TrainerHill_1F_EventScript_2C83C9
special sub_80B05B4 special sub_80B05B4
@ -7429,7 +7429,7 @@ TrainerHill_4F_MapScript1_2C8336: @ 82C8336
TrainerHill_Roof_MapScript1_2C8336: @ 82C8336 TrainerHill_Roof_MapScript1_2C8336: @ 82C8336
setvar VAR_TEMP_2, 0 setvar VAR_TEMP_2, 0
setvar VAR_0x8004, 4 setvar VAR_0x8004, 4
special sp194_trainer_tower special CallTrainerHillFunction
setvar VAR_0x8004, 1 setvar VAR_0x8004, 1
setvar VAR_0x8005, 5 setvar VAR_0x8005, 5
special CallFrontierUtilFunc special CallFrontierUtilFunc
@ -7462,7 +7462,7 @@ TrainerHill_Roof_MapScript2_2C8381: @ 82C8381
EventScript_TrainerHillTimer:: @ 82C8393 EventScript_TrainerHillTimer:: @ 82C8393
lockall lockall
setvar VAR_0x8004, 7 setvar VAR_0x8004, 7
special sp194_trainer_tower special CallTrainerHillFunction
msgbox TrainerHill_Entrance_Text_268D47, MSGBOX_DEFAULT msgbox TrainerHill_Entrance_Text_268D47, MSGBOX_DEFAULT
releaseall releaseall
end end
@ -7470,7 +7470,7 @@ EventScript_TrainerHillTimer:: @ 82C8393
TrainerHill_1F_EventScript_2C83A6:: @ 82C83A6 TrainerHill_1F_EventScript_2C83A6:: @ 82C83A6
setvar VAR_TEMP_2, 1 setvar VAR_TEMP_2, 1
setvar VAR_0x8004, 9 setvar VAR_0x8004, 9
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 1 compare VAR_RESULT, 1
goto_if_eq TrainerHill_1F_EventScript_2C83BF goto_if_eq TrainerHill_1F_EventScript_2C83BF
end end
@ -7482,9 +7482,9 @@ TrainerHill_1F_EventScript_2C83BF:: @ 82C83BF
TrainerHill_1F_EventScript_2C83C9:: @ 82C83C9 TrainerHill_1F_EventScript_2C83C9:: @ 82C83C9
setvar VAR_0x8004, 12 setvar VAR_0x8004, 12
special sp194_trainer_tower special CallTrainerHillFunction
setvar VAR_0x8004, 5 setvar VAR_0x8004, 5
special sp194_trainer_tower special CallTrainerHillFunction
setvar VAR_TEMP_1, 1 setvar VAR_TEMP_1, 1
end end
@ -7502,7 +7502,7 @@ TrainerHill_1F_Movement_2C83EE:: @ 82C83EE
EventScript_2C83F0:: @ 82C83F0 EventScript_2C83F0:: @ 82C83F0
trainerbattle TRAINER_BATTLE_12, TRAINER_PHILLIP, 0, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D trainerbattle TRAINER_BATTLE_12, TRAINER_PHILLIP, 0, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D, BattleFrontier_BattlePyramidEmptySquare_Text_252C8D
setvar VAR_0x8004, 11 setvar VAR_0x8004, 11
special sp194_trainer_tower special CallTrainerHillFunction
waitmessage waitmessage
waitbuttonpress waitbuttonpress
closemessage closemessage

View File

@ -16,10 +16,10 @@ TrainerHill_Entrance_MapScript1_2680CF: @ 82680CF
TrainerHill_Entrance_MapScript1_2680D0: @ 82680D0 TrainerHill_Entrance_MapScript1_2680D0: @ 82680D0
setvar VAR_0x8004, 4 setvar VAR_0x8004, 4
special sp194_trainer_tower special CallTrainerHillFunction
setvar VAR_TEMP_0, 0 setvar VAR_TEMP_0, 0
setvar VAR_0x8004, 9 setvar VAR_0x8004, 9
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 0 compare VAR_RESULT, 0
goto_if_eq TrainerHill_Entrance_EventScript_2680FF goto_if_eq TrainerHill_Entrance_EventScript_2680FF
setobjectxy EVENT_OBJ_ID_PLAYER, 9, 6 setobjectxy EVENT_OBJ_ID_PLAYER, 9, 6
@ -28,7 +28,7 @@ TrainerHill_Entrance_MapScript1_2680D0: @ 82680D0
TrainerHill_Entrance_EventScript_2680FF:: @ 82680FF TrainerHill_Entrance_EventScript_2680FF:: @ 82680FF
setvar VAR_0x8004, 16 setvar VAR_0x8004, 16
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 1 compare VAR_RESULT, 1
goto_if_eq TrainerHill_Entrance_EventScript_26811A goto_if_eq TrainerHill_Entrance_EventScript_26811A
applymovement EVENT_OBJ_ID_PLAYER, TrainerHill_Entrance_Movement_26837F applymovement EVENT_OBJ_ID_PLAYER, TrainerHill_Entrance_Movement_26837F
@ -75,7 +75,7 @@ TrainerHill_Entrance_EventScript_268160:: @ 8268160
TrainerHill_Entrance_EventScript_268182:: @ 8268182 TrainerHill_Entrance_EventScript_268182:: @ 8268182
setvar VAR_TEMP_0, 1 setvar VAR_TEMP_0, 1
setvar VAR_0x8004, 6 setvar VAR_0x8004, 6
special sp194_trainer_tower special CallTrainerHillFunction
switch VAR_RESULT switch VAR_RESULT
case 0, TrainerHill_Entrance_EventScript_2681B5 case 0, TrainerHill_Entrance_EventScript_2681B5
case 1, TrainerHill_Entrance_EventScript_2681CA case 1, TrainerHill_Entrance_EventScript_2681CA
@ -115,7 +115,7 @@ TrainerHill_Entrance_EventScript_2681FD:: @ 82681FD
lock lock
faceplayer faceplayer
setvar VAR_0x8004, 10 setvar VAR_0x8004, 10
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 0 compare VAR_RESULT, 0
goto_if_eq TrainerHill_Entrance_EventScript_26821F goto_if_eq TrainerHill_Entrance_EventScript_26821F
msgbox TrainerHill_Entrance_Text_2686F4, MSGBOX_DEFAULT msgbox TrainerHill_Entrance_Text_2686F4, MSGBOX_DEFAULT
@ -134,11 +134,11 @@ TrainerHill_Entrance_EventScript_268229:: @ 8268229
goto_if_unset FLAG_SYS_GAME_CLEAR, TrainerHill_Entrance_EventScript_26836A goto_if_unset FLAG_SYS_GAME_CLEAR, TrainerHill_Entrance_EventScript_26836A
msgbox TrainerHill_Entrance_Text_2684C6, MSGBOX_DEFAULT msgbox TrainerHill_Entrance_Text_2684C6, MSGBOX_DEFAULT
setvar VAR_0x8004, 13 setvar VAR_0x8004, 13
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 0 compare VAR_RESULT, 0
call_if_eq TrainerHill_Entrance_EventScript_26832E call_if_eq TrainerHill_Entrance_EventScript_26832E
setvar VAR_0x8004, 8 setvar VAR_0x8004, 8
special sp194_trainer_tower special CallTrainerHillFunction
compare VAR_RESULT, 1 compare VAR_RESULT, 1
goto_if_eq TrainerHill_Entrance_EventScript_268275 goto_if_eq TrainerHill_Entrance_EventScript_268275
msgbox TrainerHill_Entrance_Text_268564, MSGBOX_DEFAULT msgbox TrainerHill_Entrance_Text_268564, MSGBOX_DEFAULT
@ -170,13 +170,13 @@ TrainerHill_Entrance_EventScript_2682C8:: @ 82682C8
case 127, TrainerHill_Entrance_EventScript_268314 case 127, TrainerHill_Entrance_EventScript_268314
setvar VAR_0x8004, 17 setvar VAR_0x8004, 17
copyvar VAR_0x8005, VAR_RESULT copyvar VAR_0x8005, VAR_RESULT
special sp194_trainer_tower special CallTrainerHillFunction
setvar VAR_0x40D6, 1 setvar VAR_0x40D6, 1
setvar VAR_TEMP_5, 0 setvar VAR_TEMP_5, 0
special HealPlayerParty special HealPlayerParty
msgbox TrainerHill_Entrance_Text_26862A, MSGBOX_DEFAULT msgbox TrainerHill_Entrance_Text_26862A, MSGBOX_DEFAULT
setvar VAR_0x8004, 0 setvar VAR_0x8004, 0
special sp194_trainer_tower special CallTrainerHillFunction
releaseall releaseall
end end
@ -192,18 +192,18 @@ TrainerHill_Entrance_EventScript_268314:: @ 8268314
TrainerHill_Entrance_EventScript_26832E:: @ 826832E TrainerHill_Entrance_EventScript_26832E:: @ 826832E
msgbox TrainerHill_Entrance_Text_26851C, MSGBOX_DEFAULT msgbox TrainerHill_Entrance_Text_26851C, MSGBOX_DEFAULT
setvar VAR_0x8004, 14 setvar VAR_0x8004, 14
special sp194_trainer_tower special CallTrainerHillFunction
setvar VAR_TEMP_5, 1 setvar VAR_TEMP_5, 1
call TrainerHill_Entrance_EventScript_27134F call TrainerHill_Entrance_EventScript_27134F
compare VAR_RESULT, 0 compare VAR_RESULT, 0
goto_if_eq TrainerHill_Entrance_EventScript_26835C goto_if_eq TrainerHill_Entrance_EventScript_26835C
setvar VAR_0x8004, 14 setvar VAR_0x8004, 14
special sp194_trainer_tower special CallTrainerHillFunction
return return
TrainerHill_Entrance_EventScript_26835C:: @ 826835C TrainerHill_Entrance_EventScript_26835C:: @ 826835C
setvar VAR_0x8004, 15 setvar VAR_0x8004, 15
special sp194_trainer_tower special CallTrainerHillFunction
goto TrainerHill_Entrance_EventScript_268314 goto TrainerHill_Entrance_EventScript_268314
end end

View File

@ -5,11 +5,11 @@ TrainerHill_Roof_MapScripts:: @ 8268FA7
TrainerHill_Roof_EventScript_268FB2:: @ 8268FB2 TrainerHill_Roof_EventScript_268FB2:: @ 8268FB2
setvar VAR_0x8004, 12 setvar VAR_0x8004, 12
special sp194_trainer_tower special CallTrainerHillFunction
lock lock
faceplayer faceplayer
setvar VAR_0x8004, 1 setvar VAR_0x8004, 1
special sp194_trainer_tower special CallTrainerHillFunction
switch VAR_RESULT switch VAR_RESULT
case 0, TrainerHill_Roof_EventScript_268FEA case 0, TrainerHill_Roof_EventScript_268FEA
case 1, TrainerHill_Roof_EventScript_268FF2 case 1, TrainerHill_Roof_EventScript_268FF2
@ -20,7 +20,7 @@ TrainerHill_Roof_EventScript_268FEA:: @ 8268FEA
TrainerHill_Roof_EventScript_268FF2:: @ 8268FF2 TrainerHill_Roof_EventScript_268FF2:: @ 8268FF2
setvar VAR_0x8004, 2 setvar VAR_0x8004, 2
special sp194_trainer_tower special CallTrainerHillFunction
switch VAR_RESULT switch VAR_RESULT
case 0, TrainerHill_Roof_EventScript_269020 case 0, TrainerHill_Roof_EventScript_269020
case 1, TrainerHill_Roof_EventScript_269037 case 1, TrainerHill_Roof_EventScript_269037
@ -42,7 +42,7 @@ TrainerHill_Roof_EventScript_269037:: @ 8269037
TrainerHill_Roof_EventScript_269054:: @ 8269054 TrainerHill_Roof_EventScript_269054:: @ 8269054
setvar VAR_0x8004, 3 setvar VAR_0x8004, 3
special sp194_trainer_tower special CallTrainerHillFunction
switch VAR_RESULT switch VAR_RESULT
case 0, TrainerHill_Roof_EventScript_269082 case 0, TrainerHill_Roof_EventScript_269082
case 1, TrainerHill_Roof_EventScript_269090 case 1, TrainerHill_Roof_EventScript_269090

View File

@ -2382,56 +2382,3 @@ gUnknown_0862A5A4:: @ 862A5A4
gUnknown_0862A5CC:: @ 862A5CC gUnknown_0862A5CC:: @ 862A5CC
.4byte gUnknown_0862A57C .4byte gUnknown_0862A57C
.4byte gUnknown_0862A5A4 .4byte gUnknown_0862A5A4
gUnknown_0862A5D4:: @ 862A5D4
.incbin "graphics/pokenav/862A5D4.gbapal"
gUnknown_0862A5F4:: @ 862A5F4
.byte 0, 2, 3, 0
gUnknown_0862A5F8:: @ 862A5F8
.4byte gUnknown_08626814
.4byte gUnknown_086276FC
.4byte gUnknown_086285E4
.4byte gUnknown_086294CC
.4byte gUnknown_085EF8B6
.4byte gUnknown_085EF8B9
.4byte gUnknown_085EF8BC
.4byte gUnknown_085EF8BF
gUnknown_0862A618:: @ 862A618
.4byte sub_81D581C
.4byte sub_81D58D8
.4byte sub_81D5924
.4byte sub_81D59D0
.4byte sub_81D5A70
.4byte sub_81D5AB4
.4byte sub_81D5AD0
.4byte sub_81D5B2C
.4byte sub_81D5BBC
.4byte sub_81D5C00
.4byte sub_81D5C5C
.4byte sub_81D62B4
.4byte sub_81D64AC
.4byte sub_81D64DC
.4byte sub_81D64FC
.4byte sub_81D6518
.4byte sub_81D6568
.4byte sub_81D65A0
gUnknown_0862A660:: @ 862A660
.4byte gUnknown_085EB32D
.4byte gUnknown_085EB33E
.4byte gUnknown_085EB350
.4byte gUnknown_085EB361
gUnknown_0862A670:: @ 862A670
.byte 0, 0x64
.4byte NULL
.2byte 0, 0x103, 17, 1, 0, 0, 0, 0, 0
gUnknown_0862A688:: @ 862A688
.2byte 0x3E, 0, 0x3F, 0, 0x40, 0, 0x41, 0
gUnknown_0862A698:: @ 862A698
.byte 0, 1, 2, 3, 4, 5, 0, 0

View File

@ -515,7 +515,7 @@ gSpecials:: @ 81DBA64
def_special sub_813B514 def_special sub_813B514
def_special sub_813B568 def_special sub_813B568
def_special sub_813B534 def_special sub_813B534
def_special sp194_trainer_tower def_special CallTrainerHillFunction
def_special sub_813B7D8 def_special sub_813B7D8
def_special sub_813B80C def_special sub_813B80C
def_special sub_81D4BEC def_special sub_81D4BEC

View File

@ -174,7 +174,7 @@
#define HITMARKER_GRUDGE 0x01000000 #define HITMARKER_GRUDGE 0x01000000
#define HITMARKER_OBEYS 0x02000000 #define HITMARKER_OBEYS 0x02000000
#define HITMARKER_x4000000 0x04000000 #define HITMARKER_x4000000 0x04000000
#define HITMARKER_x8000000 0x08000000 #define HITMARKER_CHARGING 0x08000000
#define HITMARKER_FAINTED(battler) (gBitTable[battler] << 0x1C) #define HITMARKER_FAINTED(battler) (gBitTable[battler] << 0x1C)
#define HITMARKER_UNK(battler) (0x10000000 << battler) #define HITMARKER_UNK(battler) (0x10000000 << battler)

View File

@ -805,7 +805,7 @@ struct SaveTrainerHill
/*0x3D6E*/ u16 field_3D6E_0d:1; // 8 /*0x3D6E*/ u16 field_3D6E_0d:1; // 8
/*0x3D6E*/ u16 field_3D6E_0e:1; // x10 /*0x3D6E*/ u16 field_3D6E_0e:1; // x10
/*0x3D6E*/ u16 field_3D6E_0f:1; // x20 /*0x3D6E*/ u16 field_3D6E_0f:1; // x20
/*0x3D6E*/ u16 field_3D6E_1:2; // x40, x80 = xC0 /*0x3D6E*/ u16 tag:2; // x40, x80 = xC0
}; };
struct SaveBlock1 struct SaveBlock1
@ -886,7 +886,7 @@ struct SaveBlock1
/*0x31DC*/ struct Roamer roamer; /*0x31DC*/ struct Roamer roamer;
/*0x31F8*/ struct EnigmaBerry enigmaBerry; /*0x31F8*/ struct EnigmaBerry enigmaBerry;
/*0x322C*/ u8 field_322C[1260]; /*0x322C*/ u8 field_322C[1260];
/*0x3718*/ u32 field_3718[4]; /*0x3718*/ u32 trainerHillTimes[4];
/*0x3728*/ struct RamScript ramScript; /*0x3728*/ struct RamScript ramScript;
/*0x3B14*/ struct RecordMixingGift recordMixingGift; /*0x3B14*/ struct RecordMixingGift recordMixingGift;
/*0x3B24*/ u8 seen2[DEX_FLAGS_NO]; /*0x3B24*/ u8 seen2[DEX_FLAGS_NO];

View File

@ -1231,10 +1231,14 @@ extern const u8 gText_MtPyre[];
extern const u8 gText_SkyPillar[]; extern const u8 gText_SkyPillar[];
extern const u8 gText_DontRemember[]; extern const u8 gText_DontRemember[];
extern const u8 gUnknown_085EB597[]; extern const u8 gUnknown_085EB597[];
extern const u8 gUnknown_085EB32D[]; extern const u8 gText_NormalTagMatch[];
extern const u8 gUnknown_085EB33E[]; extern const u8 gText_VarietyTagMatch[];
extern const u8 gUnknown_085EB350[]; extern const u8 gText_UniqueTagMatch[];
extern const u8 gUnknown_085EB361[]; extern const u8 gText_ExpertTagMatch[];
extern const u8 gText_TrainerHill1F[];
extern const u8 gText_TrainerHill2F[];
extern const u8 gText_TrainerHill3F[];
extern const u8 gText_TrainerHill4F[];
extern const u8 OldaleTown_PokemonCenter_2F_Text_277F1B[]; extern const u8 OldaleTown_PokemonCenter_2F_Text_277F1B[];
extern const u8 OldaleTown_PokemonCenter_2F_Text_277F5A[]; extern const u8 OldaleTown_PokemonCenter_2F_Text_277F5A[];

6
include/trainer_hill.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef GUARD_TRAINER_HILL_H
#define GUARD_TRAINER_HILL_H
extern u32 *gUnknown_0203CF5C;
#endif // GUARD_TRAINER_HILL_H

View File

@ -597,6 +597,7 @@ SECTIONS {
data/pokenav.o(.rodata); data/pokenav.o(.rodata);
src/pokenav_match_call.o(.rodata); src/pokenav_match_call.o(.rodata);
data/pokenav.o(.rodata.after.match.call); data/pokenav.o(.rodata.after.match.call);
src/trainer_hill.o(.rodata);
src/rayquaza_scene.o(.rodata); src/rayquaza_scene.o(.rodata);
src/walda_phrase.o(.rodata); src/walda_phrase.o(.rodata);
src/gym_leader_rematch.o(.rodata); src/gym_leader_rematch.o(.rodata);

View File

@ -8459,7 +8459,7 @@ static u8 AttacksThisTurn(u8 battlerId, u16 move) // Note: returns 1 if it's a c
|| gBattleMoves[move].effect == EFFECT_SEMI_INVULNERABLE || gBattleMoves[move].effect == EFFECT_SEMI_INVULNERABLE
|| gBattleMoves[move].effect == EFFECT_BIDE) || gBattleMoves[move].effect == EFFECT_BIDE)
{ {
if ((gHitMarker & HITMARKER_x8000000)) if ((gHitMarker & HITMARKER_CHARGING))
return 1; return 1;
} }
return 2; return 2;

View File

@ -8,13 +8,12 @@
#include "pokemon_storage_system.h" #include "pokemon_storage_system.h"
#include "random.h" #include "random.h"
#include "save_location.h" #include "save_location.h"
#include "trainer_hill.h"
#include "gba/flash_internal.h" #include "gba/flash_internal.h"
#include "decoration_inventory.h" #include "decoration_inventory.h"
static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey);
extern void* gUnknown_0203CF5C;
extern bool16 IdentifyFlash(void); extern bool16 IdentifyFlash(void);
extern void ApplyNewEncryptionKeyToBerryPowder(u32 key); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key);

View File

@ -22,10 +22,10 @@
#include "text.h" #include "text.h"
#include "intro.h" #include "intro.h"
#include "main.h" #include "main.h"
#include "trainer_hill.h"
extern void sub_800B9B8(void); extern void sub_800B9B8(void);
extern u8 gUnknown_03002748; extern u8 gUnknown_03002748;
extern u32 *gUnknown_0203CF5C;
static void VBlankIntr(void); static void VBlankIntr(void);
static void HBlankIntr(void); static void HBlankIntr(void);

View File

@ -7,6 +7,7 @@
#include "overworld.h" #include "overworld.h"
#include "pokemon_storage_system.h" #include "pokemon_storage_system.h"
#include "main.h" #include "main.h"
#include "trainer_hill.h"
#include "constants/game_stat.h" #include "constants/game_stat.h"
static u16 CalculateChecksum(void *data, u16 size); static u16 CalculateChecksum(void *data, u16 size);
@ -17,10 +18,6 @@ static u8 ClearSaveData_2(u16 a1, const struct SaveSectionLocation *location);
static u8 TryWriteSector(u8 sector, u8 *data); static u8 TryWriteSector(u8 sector, u8 *data);
static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location); static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location);
// for the chunk declarations
extern u32 gUnknown_0203CF5C;
// Divide save blocks into individual chunks to be written to flash sectors // Divide save blocks into individual chunks to be written to flash sectors
// Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer // Each 4 KiB flash sector contains 3968 bytes of actual data followed by a 128 byte footer
@ -662,10 +659,10 @@ static void UpdateSaveAddresses(void)
u8 HandleSavingData(u8 saveType) u8 HandleSavingData(u8 saveType)
{ {
u8 i; u8 i;
u32 backupVar = gUnknown_0203CF5C; u32 *backupVar = gUnknown_0203CF5C;
u8 *tempAddr; u8 *tempAddr;
gUnknown_0203CF5C = 0; gUnknown_0203CF5C = NULL;
UpdateSaveAddresses(); UpdateSaveAddresses();
switch (saveType) switch (saveType)
{ {

View File

@ -782,10 +782,10 @@ const struct MenuAction MultichoiceList_112[] =
const struct MenuAction MultichoiceList_113[] = const struct MenuAction MultichoiceList_113[] =
{ {
{gUnknown_085EB32D, NULL}, {gText_NormalTagMatch, NULL},
{gUnknown_085EB33E, NULL}, {gText_VarietyTagMatch, NULL},
{gUnknown_085EB350, NULL}, {gText_UniqueTagMatch, NULL},
{gUnknown_085EB361, NULL}, {gText_ExpertTagMatch, NULL},
{gText_Exit, NULL}, {gText_Exit, NULL},
}; };

View File

@ -252,7 +252,7 @@ const u8 gText_ThePokemonList[] = _("the POKéMON LIST");
const u8 gText_TheShop[] = _("the shop"); const u8 gText_TheShop[] = _("the shop");
const u8 gText_ThePC[] = _("the PC"); const u8 gText_ThePC[] = _("the PC");
const u8 *const gReturnToXStringsTable[] = const u8 *const gReturnToXStringsTable[] =
{ {
gText_TheField, gText_TheField,
gText_TheBattle, gText_TheBattle,
@ -268,7 +268,7 @@ const u8 *const gReturnToXStringsTable[] =
gText_ThePC gText_ThePC
}; };
const u8 *const gReturnToXStringsTable2[] = const u8 *const gReturnToXStringsTable2[] =
{ {
gText_TheField, gText_TheField,
gText_TheBattle, gText_TheBattle,
@ -283,7 +283,7 @@ const u8 gText_TMHMPocket[] = _("TMs & HMs");
const u8 gText_BerriesPocket[] = _("BERRIES"); const u8 gText_BerriesPocket[] = _("BERRIES");
const u8 gText_KeyItemsPocket[] = _("KEY ITEMS"); const u8 gText_KeyItemsPocket[] = _("KEY ITEMS");
const u8 *const gPocketNamesStringsTable[] = const u8 *const gPocketNamesStringsTable[] =
{ {
gText_ItemsPocket, gText_ItemsPocket,
gText_PokeBallsPocket, gText_PokeBallsPocket,
@ -749,10 +749,10 @@ const u8 gUnknown_085EB2FF[] = _("I'll battle now!");
const u8 gUnknown_085EB310[] = _("I won!"); const u8 gUnknown_085EB310[] = _("I won!");
const u8 gUnknown_085EB317[] = _("I lost!"); const u8 gUnknown_085EB317[] = _("I lost!");
const u8 gUnknown_085EB31F[] = _("I won't tell."); const u8 gUnknown_085EB31F[] = _("I won't tell.");
const u8 gUnknown_085EB32D[] = _("NORMAL TAG MATCH"); const u8 gText_NormalTagMatch[] = _("NORMAL TAG MATCH");
const u8 gUnknown_085EB33E[] = _("VARIETY TAG MATCH"); const u8 gText_VarietyTagMatch[] = _("VARIETY TAG MATCH");
const u8 gUnknown_085EB350[] = _("UNIQUE TAG MATCH"); const u8 gText_UniqueTagMatch[] = _("UNIQUE TAG MATCH");
const u8 gUnknown_085EB361[] = _("EXPERT TAG MATCH"); const u8 gText_ExpertTagMatch[] = _("EXPERT TAG MATCH");
const u8 gUnknown_085EB372[] = _("TRADE CENTER"); const u8 gUnknown_085EB372[] = _("TRADE CENTER");
const u8 gUnknown_085EB37F[] = _("COLOSSEUM"); const u8 gUnknown_085EB37F[] = _("COLOSSEUM");
const u8 gUnknown_085EB389[] = _("RECORD CORNER"); const u8 gUnknown_085EB389[] = _("RECORD CORNER");
@ -1737,10 +1737,10 @@ const u8 gText_Lv[] = _("{LV}");
const u8 gText_TimeBoard[] = _("TIME BOARD"); const u8 gText_TimeBoard[] = _("TIME BOARD");
const u8 gText_TimeCleared[] = _("TIME CLEARED "); const u8 gText_TimeCleared[] = _("TIME CLEARED ");
const u8 gText_XMinYDotZSec[] = _("{STR_VAR_1} min. {STR_VAR_2}.{STR_VAR_3} sec."); const u8 gText_XMinYDotZSec[] = _("{STR_VAR_1} min. {STR_VAR_2}.{STR_VAR_3} sec.");
const u8 gUnknown_085EF8B6[] = _("1F"); const u8 gText_TrainerHill1F[] = _("1F");
const u8 gUnknown_085EF8B9[] = _("2F"); const u8 gText_TrainerHill2F[] = _("2F");
const u8 gUnknown_085EF8BC[] = _("3F"); const u8 gText_TrainerHill3F[] = _("3F");
const u8 gUnknown_085EF8BF[] = _("4F"); const u8 gText_TrainerHill4F[] = _("4F");
const u8 gText_TeachWhichMoveToPkmn[] = _("Teach which move to {STR_VAR_1}?"); const u8 gText_TeachWhichMoveToPkmn[] = _("Teach which move to {STR_VAR_1}?");
const u8 gText_TeachX[] = _("Teach {STR_VAR_2}?"); const u8 gText_TeachX[] = _("Teach {STR_VAR_2}?");
const u8 gText_PkmnLearnedMove4[] = _("{STR_VAR_1} learned\n{STR_VAR_2}!"); const u8 gText_PkmnLearnedMove4[] = _("{STR_VAR_1} learned\n{STR_VAR_2}!");

View File

@ -15,16 +15,24 @@
#include "pokemon.h" #include "pokemon.h"
#include "script.h" #include "script.h"
#include "string_util.h" #include "string_util.h"
#include "strings.h"
#include "text.h" #include "text.h"
#include "trainer_hill.h"
#include "window.h" #include "window.h"
#include "util.h" #include "util.h"
#include "constants/event_object_movement_constants.h" #include "constants/event_object_movement_constants.h"
#include "constants/event_objects.h"
#include "constants/maps.h" #include "constants/maps.h"
#define HILL_TAG_NORMAL 0
#define HILL_TAG_VARIETY 1
#define HILL_TAG_UNIQUE 2
#define HILL_TAG_EXPERT 3
#define HILL_TRAINER_NAME_LENGTH 11 #define HILL_TRAINER_NAME_LENGTH 11
#define HILL_MAX_TIME 215999 // 60 * 60 * 60 - 1 #define HILL_MAX_TIME 215999 // 60 * 60 * 60 - 1
struct TrHillStruct1 struct TrHillRoomTrainers
{ {
u8 name[2][HILL_TRAINER_NAME_LENGTH]; u8 name[2][HILL_TRAINER_NAME_LENGTH];
u8 facilityClass[2]; u8 facilityClass[2];
@ -34,7 +42,7 @@ struct TrainerHillTrainer
{ {
u8 name[HILL_TRAINER_NAME_LENGTH]; u8 name[HILL_TRAINER_NAME_LENGTH];
u8 facilityClass; u8 facilityClass;
u32 field_18; u32 unused;
u16 speechBefore[6]; u16 speechBefore[6];
u16 speechWin[6]; u16 speechWin[6];
u16 speechLose[6]; u16 speechLose[6];
@ -42,67 +50,81 @@ struct TrainerHillTrainer
struct BattleTowerPokemon mons[PARTY_SIZE]; struct BattleTowerPokemon mons[PARTY_SIZE];
}; };
struct TrHillStruct5 struct TrHillFloor
{ {
u8 unk0; u8 unk0;
u8 unk1; u8 unk1;
struct TrainerHillTrainer trainers[2]; struct TrainerHillTrainer trainers[2];
u8 data[0x100]; u8 data[0x100];
u16 unk3A0[2]; u16 unk3A0[16];
u8 data2[0x20 - 4];
u8 coords[2]; // x first 4 bits, y last 4 bites u8 coords[2]; // x first 4 bits, y last 4 bites
u8 direction; // array of 4 bites for each trainer u8 direction; // array of 4 bites for each trainer
u8 range; // array of 4 bites for each trainer u8 range; // array of 4 bites for each trainer
}; };
struct TrHillStruct4 struct TrHillTag
{ {
u8 unkField_0; u8 unkField_0;
u8 unkField_1; u8 unused1;
u8 unkField_2; u8 unkField_2;
u8 unkField_3; u8 unused3;
u8 unkField_4; u8 unused4;
u8 unkField_5; struct TrHillFloor floors[4];
u8 unkField_6;
struct TrHillStruct5 unk0[4];
}; };
struct TrHillStruct2 struct TrHillStruct2
{ {
u8 layoutId; u8 floorId;
struct TrHillStruct4 unk4; struct TrHillTag tag;
}; };
extern struct TrHillStruct2 *gUnknown_0203CF54; // EWRAM
extern struct TrHillStruct1 *gUnknown_0203CF58; static EWRAM_DATA struct TrHillStruct2 *sHillData = NULL;
static EWRAM_DATA struct TrHillRoomTrainers *sRoomTrainers = NULL;
EWRAM_DATA u32 *gUnknown_0203CF5C = NULL;
// This file's functions. // This file's functions.
void sub_81D56B0(void); void sub_81D581C(void);
void sub_81D5710(void); void sub_81D58D8(void);
void sub_81D5924(void);
void sub_81D59D0(void);
void sub_81D5A70(void);
void sub_81D5AB4(void);
void sub_81D5AD0(void);
void sub_81D5B2C(void);
void sub_81D5BBC(void);
void sub_81D5C00(void);
void sub_81D5C5C(void);
void sub_81D62B4(void);
void sub_81D64AC(void);
void sub_81D64DC(void);
void sub_81D64FC(void);
void sub_81D6518(void);
void sub_81D6568(void);
void sub_81D65A0(void);
void SetUpDataStruct(void);
void FreeDataStruct(void);
bool32 sub_81D5F48(void); bool32 sub_81D5F48(void);
void nullsub_2(void); void nullsub_2(void);
void sub_81D5DF4(u32 *dst, u32 val); void SetTimerValue(u32 *dst, u32 val);
bool32 sub_81D3B34(void); bool32 sub_81D3B34(void);
u16 sub_81D6640(void); u16 sub_81D6640(void);
u32 sub_81D5DF0(u32 *src); u32 GetTimerValue(u32 *src);
u8 GetCurrentTrainerHillMapId(void); u8 GetCurrentTrainerHillMapId(void);
u8 sub_81D6490(void); u8 sub_81D6490(void);
void sub_81D642C(struct Pokemon *mon, u8 level); void sub_81D642C(struct Pokemon *mon, u8 level);
bool32 sub_81D6534(void); bool32 sub_81D6534(void);
// const data // const data
extern void (* const gUnknown_0862A618[])(void);
extern const struct TrHillStruct4 *const gUnknown_0862A5F8[];
extern const u16 gUnknown_0862A5D4[];
extern const u8 gText_TimeBoard[]; extern const u8 gText_TimeBoard[];
extern const u8 gText_TimeCleared[]; extern const u8 gText_TimeCleared[];
extern const u8 gText_XMinYDotZSec[]; extern const u8 gText_XMinYDotZSec[];
extern const u8 gUnknown_0862A5F4[];
extern const u8 *const gUnknown_0862A660[]; extern const struct TrHillTag gUnknown_08626814;
extern const struct EventObjectTemplate gUnknown_0862A670; extern const struct TrHillTag gUnknown_086276FC;
extern const u32 gUnknown_0862A688[4]; extern const struct TrHillTag gUnknown_086285E4;
extern const u8 gUnknown_0862A698[][3]; extern const struct TrHillTag gUnknown_086294CC;
extern const u16 *const *const gUnknown_0862A5CC[]; extern const u16 *const *const gUnknown_0862A5CC[];
struct struct
{ {
@ -112,11 +134,74 @@ struct
extern const u8 EventScript_2C83F0[]; extern const u8 EventScript_2C83F0[];
void sp194_trainer_tower(void) static const u16 gUnknown_0862A5D4[] = INCBIN_U16("graphics/pokenav/862A5D4.gbapal");
static const u8 sRecordWinColors[] = {0, 2, 3};
static const struct TrHillTag *const sDataPerTag[] =
{ {
sub_81D56B0(); &gUnknown_08626814,
gUnknown_0862A618[gSpecialVar_0x8004](); &gUnknown_086276FC,
sub_81D5710(); &gUnknown_086285E4,
&gUnknown_086294CC,
};
// Unused.
static const u8 *const sFloorStrings[] =
{
gText_TrainerHill1F,
gText_TrainerHill2F,
gText_TrainerHill3F,
gText_TrainerHill4F,
};
static void (* const sHillFunctions[])(void) =
{
sub_81D581C,
sub_81D58D8,
sub_81D5924,
sub_81D59D0,
sub_81D5A70,
sub_81D5AB4,
sub_81D5AD0,
sub_81D5B2C,
sub_81D5BBC,
sub_81D5C00,
sub_81D5C5C,
sub_81D62B4,
sub_81D64AC,
sub_81D64DC,
sub_81D64FC,
sub_81D6518,
sub_81D6568,
sub_81D65A0,
};
static const u8 *const sTagMatchStrings[] =
{
gText_NormalTagMatch,
gText_VarietyTagMatch,
gText_UniqueTagMatch,
gText_ExpertTagMatch,
};
static const struct EventObjectTemplate gUnknown_0862A670 =
{
.graphicsId = EVENT_OBJ_GFX_RIVAL_BRENDAN_NORMAL,
.elevation = 3,
.movementType = MOVEMENT_TYPE_LOOK_AROUND,
.movementRangeX = 1,
.movementRangeY = 1,
.trainerType = 1,
};
static const u32 gUnknown_0862A688[] = {MAP_NUM(TRAINER_HILL_2F), MAP_NUM(TRAINER_HILL_3F), MAP_NUM(TRAINER_HILL_4F), MAP_NUM(TRAINER_HILL_ROOF)};
static const u8 gUnknown_0862A698[][3] = {{0, 1, 2}, {3, 4, 5}};
void CallTrainerHillFunction(void)
{
SetUpDataStruct();
sHillFunctions[gSpecialVar_0x8004]();
FreeDataStruct();
} }
void sub_81D54BC(void) void sub_81D54BC(void)
@ -127,10 +212,10 @@ void sub_81D54BC(void)
gSaveBlock2Ptr->frontier.field_EF9_0 = 0; gSaveBlock2Ptr->frontier.field_EF9_0 = 0;
gSaveBlock1Ptr->trainerHill.field_3D68 = 0; gSaveBlock1Ptr->trainerHill.field_3D68 = 0;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
sub_81D5DF4(&gSaveBlock1Ptr->field_3718[i], HILL_MAX_TIME); SetTimerValue(&gSaveBlock1Ptr->trainerHillTimes[i], HILL_MAX_TIME);
} }
u8 sub_81D5520(void) u8 GetFloorId(void)
{ {
return gMapHeader.mapLayoutId - 159; return gMapHeader.mapLayoutId - 159;
} }
@ -139,7 +224,7 @@ u8 GetTrainerHillOpponentClass(u16 trainerId)
{ {
u8 id = trainerId - 1; u8 id = trainerId - 1;
return gFacilityClassToTrainerClass[gUnknown_0203CF58->facilityClass[id]]; return gFacilityClassToTrainerClass[sRoomTrainers->facilityClass[id]];
} }
void GetTrainerHillTrainerName(u8 *dst, u16 trainerId) void GetTrainerHillTrainerName(u8 *dst, u16 trainerId)
@ -148,17 +233,17 @@ void GetTrainerHillTrainerName(u8 *dst, u16 trainerId)
u8 id = trainerId - 1; u8 id = trainerId - 1;
for (i = 0; i < HILL_TRAINER_NAME_LENGTH; i++) for (i = 0; i < HILL_TRAINER_NAME_LENGTH; i++)
dst[i] = gUnknown_0203CF58->name[id][i]; dst[i] = sRoomTrainers->name[id][i];
} }
u8 GetTrainerHillTrainerFrontSpriteId(u16 trainerId) u8 GetTrainerHillTrainerFrontSpriteId(u16 trainerId)
{ {
u8 id, facilityClass; u8 id, facilityClass;
sub_81D56B0(); SetUpDataStruct();
id = trainerId - 1; id = trainerId - 1;
facilityClass = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[id].facilityClass; facilityClass = sHillData->tag.floors[sHillData->floorId].trainers[id].facilityClass;
sub_81D5710(); FreeDataStruct();
return gFacilityClassToPicIndex[facilityClass]; return gFacilityClassToPicIndex[facilityClass];
} }
@ -167,69 +252,69 @@ void sub_81D55D0(void)
{ {
s32 i, j; s32 i, j;
sub_81D56B0(); SetUpDataStruct();
gUnknown_0203CF58 = AllocZeroed(sizeof(*gUnknown_0203CF58)); sRoomTrainers = AllocZeroed(sizeof(*sRoomTrainers));
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
for (j = 0; j < HILL_TRAINER_NAME_LENGTH; j++) for (j = 0; j < HILL_TRAINER_NAME_LENGTH; j++)
{ {
gUnknown_0203CF58->name[i][j] = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[i].name[j]; sRoomTrainers->name[i][j] = sHillData->tag.floors[sHillData->floorId].trainers[i].name[j];
} }
gUnknown_0203CF58->facilityClass[i] = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[i].facilityClass; sRoomTrainers->facilityClass[i] = sHillData->tag.floors[sHillData->floorId].trainers[i].facilityClass;
} }
sub_80008DC(&gSaveBlock1Ptr->trainerHill.field_3D64); sub_80008DC(&gSaveBlock1Ptr->trainerHill.field_3D64);
sub_81D5710(); FreeDataStruct();
} }
void sub_81D5694(void) void sub_81D5694(void)
{ {
if (gUnknown_0203CF58 != NULL) if (sRoomTrainers != NULL)
FREE_AND_SET_NULL(gUnknown_0203CF58); FREE_AND_SET_NULL(sRoomTrainers);
} }
void sub_81D56B0(void) void SetUpDataStruct(void)
{ {
if (gUnknown_0203CF54 == NULL) if (sHillData == NULL)
{ {
gUnknown_0203CF54 = AllocZeroed(sizeof(*gUnknown_0203CF54)); sHillData = AllocZeroed(sizeof(*sHillData));
gUnknown_0203CF54->layoutId = gMapHeader.mapLayoutId - 159; sHillData->floorId = gMapHeader.mapLayoutId - 159;
CpuCopy32(gUnknown_0862A5F8[gSaveBlock1Ptr->trainerHill.field_3D6E_1], &gUnknown_0203CF54->unk4, sizeof(gUnknown_0203CF54->unk4)); CpuCopy32(sDataPerTag[gSaveBlock1Ptr->trainerHill.tag], &sHillData->tag, sizeof(sHillData->tag));
nullsub_2(); nullsub_2();
} }
} }
void sub_81D5710(void) void FreeDataStruct(void)
{ {
if (gUnknown_0203CF54 != NULL) if (sHillData != NULL)
FREE_AND_SET_NULL(gUnknown_0203CF54); FREE_AND_SET_NULL(sHillData);
} }
void CopyTrainerHillTrainerText(u8 which, u16 trainerId) void CopyTrainerHillTrainerText(u8 which, u16 trainerId)
{ {
u8 id, layoutId; u8 id, floorId;
sub_81D56B0(); SetUpDataStruct();
layoutId = sub_81D5520(); floorId = GetFloorId();
id = trainerId - 1; id = trainerId - 1;
switch (which) switch (which)
{ {
case 2: case 2:
FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechBefore); FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechBefore);
break; break;
case 3: case 3:
FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechWin); FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechWin);
break; break;
case 4: case 4:
FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechLose); FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechLose);
break; break;
case 5: case 5:
FrontierSpeechToString(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[id].speechAfter); FrontierSpeechToString(sHillData->tag.floors[floorId].trainers[id].speechAfter);
break; break;
} }
sub_81D5710(); FreeDataStruct();
} }
void sub_81D581C(void) void sub_81D581C(void)
@ -267,7 +352,7 @@ void sub_81D5924(void)
{ {
u16 itemId = sub_81D6640(); u16 itemId = sub_81D6640();
if (gUnknown_0203CF54->unk4.unkField_2 != 4 || gSaveBlock1Ptr->trainerHill.field_3D6E_0a) if (sHillData->tag.unkField_2 != 4 || gSaveBlock1Ptr->trainerHill.field_3D6E_0a)
{ {
gSpecialVar_Result = 2; gSpecialVar_Result = 2;
} }
@ -290,10 +375,10 @@ void sub_81D59D0(void)
{ {
gSpecialVar_Result = 2; gSpecialVar_Result = 2;
} }
else if (sub_81D5DF0(&gSaveBlock1Ptr->trainerHill.field_3D68) > gSaveBlock1Ptr->trainerHill.field_3D64) else if (GetTimerValue(&gSaveBlock1Ptr->trainerHill.field_3D68) > gSaveBlock1Ptr->trainerHill.field_3D64)
{ {
sub_81D5DF4(&gSaveBlock1Ptr->trainerHill.field_3D68, gSaveBlock1Ptr->trainerHill.field_3D64); SetTimerValue(&gSaveBlock1Ptr->trainerHill.field_3D68, gSaveBlock1Ptr->trainerHill.field_3D64);
gSaveBlock1Ptr->field_3718[gSaveBlock1Ptr->trainerHill.field_3D6E_1] = gSaveBlock1Ptr->trainerHill.field_3D68; gSaveBlock1Ptr->trainerHillTimes[gSaveBlock1Ptr->trainerHill.tag] = gSaveBlock1Ptr->trainerHill.field_3D68;
gSpecialVar_Result = 0; gSpecialVar_Result = 0;
} }
else else
@ -359,10 +444,10 @@ void sub_81D5B2C(void)
void sub_81D5BBC(void) void sub_81D5BBC(void)
{ {
sub_81D56B0(); SetUpDataStruct();
if (gUnknown_0203CF54->unk4.unkField_2 != 4) if (sHillData->tag.unkField_2 != 4)
{ {
ConvertIntToDecimalStringN(gStringVar1, gUnknown_0203CF54->unk4.unkField_2, STR_CONV_MODE_LEFT_ALIGN, 1); ConvertIntToDecimalStringN(gStringVar1, sHillData->tag.unkField_2, STR_CONV_MODE_LEFT_ALIGN, 1);
gSpecialVar_Result = 0; gSpecialVar_Result = 0;
} }
else else
@ -370,14 +455,14 @@ void sub_81D5BBC(void)
gSpecialVar_Result = 1; gSpecialVar_Result = 1;
} }
sub_81D5710(); FreeDataStruct();
} }
void sub_81D5C00(void) void sub_81D5C00(void)
{ {
sub_81D56B0(); SetUpDataStruct();
gSpecialVar_Result = 0; gSpecialVar_Result = 0;
sub_81D5710(); FreeDataStruct();
} }
bool8 sub_81D5C18(void) bool8 sub_81D5C18(void)
@ -415,17 +500,17 @@ void PrintOnTrainerHillRecordsWindow(void)
s32 i, x, y; s32 i, x, y;
u32 total, minutes, secondsWhole, secondsFraction; u32 total, minutes, secondsWhole, secondsFraction;
sub_81D56B0(); SetUpDataStruct();
FillWindowPixelBuffer(0, 0); FillWindowPixelBuffer(0, 0);
x = GetStringCenterAlignXOffset(1, gText_TimeBoard, 0xD0); x = GetStringCenterAlignXOffset(1, gText_TimeBoard, 0xD0);
AddTextPrinterParameterized3(0, 1, x, 2, gUnknown_0862A5F4, TEXT_SPEED_FF, gText_TimeBoard); AddTextPrinterParameterized3(0, 1, x, 2, sRecordWinColors, TEXT_SPEED_FF, gText_TimeBoard);
y = 18; y = 18;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
AddTextPrinterParameterized3(0, 1, 0, y, gUnknown_0862A5F4, TEXT_SPEED_FF, gUnknown_0862A660[i]); AddTextPrinterParameterized3(0, 1, 0, y, sRecordWinColors, TEXT_SPEED_FF, sTagMatchStrings[i]);
y += 15; y += 15;
total = sub_81D5DF0(&gSaveBlock1Ptr->field_3718[i]); total = GetTimerValue(&gSaveBlock1Ptr->trainerHillTimes[i]);
minutes = total / (60 * 60); minutes = total / (60 * 60);
total %= (60 * 60); total %= (60 * 60);
ConvertIntToDecimalStringN(gStringVar1, minutes, STR_CONV_MODE_RIGHT_ALIGN, 2); ConvertIntToDecimalStringN(gStringVar1, minutes, STR_CONV_MODE_RIGHT_ALIGN, 2);
@ -436,74 +521,75 @@ void PrintOnTrainerHillRecordsWindow(void)
ConvertIntToDecimalStringN(gStringVar3, secondsFraction, STR_CONV_MODE_LEADING_ZEROS, 2); ConvertIntToDecimalStringN(gStringVar3, secondsFraction, STR_CONV_MODE_LEADING_ZEROS, 2);
StringExpandPlaceholders(StringCopy(gStringVar4, gText_TimeCleared), gText_XMinYDotZSec); StringExpandPlaceholders(StringCopy(gStringVar4, gText_TimeCleared), gText_XMinYDotZSec);
x = GetStringRightAlignXOffset(1, gStringVar4, 0xD0); x = GetStringRightAlignXOffset(1, gStringVar4, 0xD0);
AddTextPrinterParameterized3(0, 1, x, y, gUnknown_0862A5F4, TEXT_SPEED_FF, gStringVar4); AddTextPrinterParameterized3(0, 1, x, y, sRecordWinColors, TEXT_SPEED_FF, gStringVar4);
y += 17; y += 17;
} }
PutWindowTilemap(0); PutWindowTilemap(0);
CopyWindowToVram(0, 3); CopyWindowToVram(0, 3);
sub_81D5710(); FreeDataStruct();
} }
// In fire red the counter had to be xored by the encryption key in Sav2. // Leftover from Fire Red / Leaf Green as in these games,
u32 sub_81D5DF0(u32 *src) // the timer had to be xored by the encryption key in Sav2.
u32 GetTimerValue(u32 *src)
{ {
return *src; return *src;
} }
void sub_81D5DF4(u32 *dst, u32 val) void SetTimerValue(u32 *dst, u32 val)
{ {
*dst = val; *dst = val;
} }
void sub_81D5DF8(void) void sub_81D5DF8(void)
{ {
u8 i, layoutId; u8 i, floorId;
struct EventObjectTemplate *eventTemplates = gSaveBlock1Ptr->eventObjectTemplates; struct EventObjectTemplate *eventTemplates = gSaveBlock1Ptr->eventObjectTemplates;
if (!sub_81D5F48()) if (!sub_81D5F48())
return; return;
sub_81D56B0(); SetUpDataStruct();
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
gSaveBlock2Ptr->frontier.field_CB4[i] = 0xFFFF; gSaveBlock2Ptr->frontier.field_CB4[i] = 0xFFFF;
CpuFill32(0, gSaveBlock1Ptr->eventObjectTemplates, sizeof(gSaveBlock1Ptr->eventObjectTemplates)); CpuFill32(0, gSaveBlock1Ptr->eventObjectTemplates, sizeof(gSaveBlock1Ptr->eventObjectTemplates));
layoutId = sub_81D5520(); floorId = GetFloorId();
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
u8 bits; u8 bits;
eventTemplates[i] = gUnknown_0862A670; eventTemplates[i] = gUnknown_0862A670;
eventTemplates[i].localId = i + 1; eventTemplates[i].localId = i + 1;
eventTemplates[i].graphicsId = FacilityClassToGraphicsId(gUnknown_0203CF54->unk4.unk0[layoutId].trainers[i].facilityClass); eventTemplates[i].graphicsId = FacilityClassToGraphicsId(sHillData->tag.floors[floorId].trainers[i].facilityClass);
eventTemplates[i].x = gUnknown_0203CF54->unk4.unk0[layoutId].coords[i] & 0xF; eventTemplates[i].x = sHillData->tag.floors[floorId].coords[i] & 0xF;
eventTemplates[i].y = ((gUnknown_0203CF54->unk4.unk0[layoutId].coords[i] >> 4) & 0xF) + 5; eventTemplates[i].y = ((sHillData->tag.floors[floorId].coords[i] >> 4) & 0xF) + 5;
bits = i << 2; bits = i << 2;
eventTemplates[i].movementType = ((gUnknown_0203CF54->unk4.unk0[layoutId].direction >> bits) & 0xF) + MOVEMENT_TYPE_FACE_UP; eventTemplates[i].movementType = ((sHillData->tag.floors[floorId].direction >> bits) & 0xF) + MOVEMENT_TYPE_FACE_UP;
eventTemplates[i].trainerRange_berryTreeId = (gUnknown_0203CF54->unk4.unk0[layoutId].range >> bits) & 0xF; eventTemplates[i].trainerRange_berryTreeId = (sHillData->tag.floors[floorId].range >> bits) & 0xF;
eventTemplates[i].script = EventScript_2C83F0; eventTemplates[i].script = EventScript_2C83F0;
gSaveBlock2Ptr->frontier.field_CB4[i] = i + 1; gSaveBlock2Ptr->frontier.field_CB4[i] = i + 1;
} }
sub_81D5710(); FreeDataStruct();
} }
bool32 sub_81D5F48(void) bool32 sub_81D5F48(void)
{ {
sub_81D56B0(); SetUpDataStruct();
sub_81D5710(); FreeDataStruct();
return TRUE; return TRUE;
} }
// Functionally equivalent. // Functionally equivalent.
#ifdef NONMATCHING #ifdef NONMATCHING
u32 sub_81D5F58(u8 layoutId, u32 bit, u32 arg2, u32 arg3) u32 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3)
{ {
u32 var0, var1, var2, var3; u32 var0, var1, var2, var3;
var0 = (gUnknown_0203CF54->unk4.unk0[layoutId].unk3A0[arg2] >> (15 - bit)) & 1; var0 = (sHillData->tag.floors[floorId].unk3A0[arg2] >> (15 - bit)) & 1;
var1 = gUnknown_0203CF54->unk4.unk0[layoutId].data[arg2 * arg3 + bit]; var1 = sHillData->tag.floors[floorId].data[arg2 * arg3 + bit];
var3 = 0x200; var3 = 0x200;
var2 = 0x3000; var2 = 0x3000;
@ -511,13 +597,13 @@ u32 sub_81D5F58(u8 layoutId, u32 bit, u32 arg2, u32 arg3)
} }
#else #else
NAKED NAKED
u32 sub_81D5F58(u8 layoutId, u32 bit, u32 arg2, u32 arg3) u32 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3)
{ {
asm_unified("\n\ asm_unified("\n\
push {r4,r5,lr}\n\ push {r4,r5,lr}\n\
lsls r0, 24\n\ lsls r0, 24\n\
lsrs r0, 24\n\ lsrs r0, 24\n\
ldr r4, =gUnknown_0203CF54\n\ ldr r4, =sHillData\n\
ldr r4, [r4]\n\ ldr r4, [r4]\n\
mov r12, r4\n\ mov r12, r4\n\
lsls r4, r2, 1\n\ lsls r4, r2, 1\n\
@ -565,23 +651,23 @@ void sub_81D5FB4(u16 *mapArg)
{ {
s32 i, j; s32 i, j;
u16 *src, *dst; u16 *src, *dst;
u8 layoutId = GetCurrentTrainerHillMapId(); u8 mapId = GetCurrentTrainerHillMapId();
if (layoutId == 6) if (mapId == 6)
{ {
InitMapFromSavedGame(); InitMapFromSavedGame();
return; return;
} }
sub_81D56B0(); SetUpDataStruct();
if (layoutId == 5) if (mapId == 5)
{ {
InitMapFromSavedGame(); InitMapFromSavedGame();
sub_81D5710(); FreeDataStruct();
return; return;
} }
layoutId = sub_81D5520(); mapId = GetFloorId();
src = gMapHeader.mapLayout->map; src = gMapHeader.mapLayout->map;
gBackupMapLayout.map = mapArg; gBackupMapLayout.map = mapArg;
gBackupMapLayout.width = 31; gBackupMapLayout.width = 31;
@ -598,12 +684,12 @@ void sub_81D5FB4(u16 *mapArg)
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
for (j = 0; j < 16; j++) for (j = 0; j < 16; j++)
dst[j] = sub_81D5F58(layoutId, j, i, 0x10); dst[j] = sub_81D5F58(mapId, j, i, 0x10);
dst += 31; dst += 31;
} }
mapheader_run_script_with_tag_x1(); mapheader_run_script_with_tag_x1();
sub_81D5710(); FreeDataStruct();
} }
bool32 InTrainerHill(void) bool32 InTrainerHill(void)
@ -685,8 +771,8 @@ u16 sub_81D6180(u8 localId)
bool8 GetTrainerHillTrainerFlag(u8 eventObjectId) bool8 GetTrainerHillTrainerFlag(u8 eventObjectId)
{ {
u32 layoutId = sub_81D5520() * 2; u32 floorId = GetFloorId() * 2;
u8 bitId = gEventObjects[eventObjectId].localId - 1 + layoutId; u8 bitId = gEventObjects[eventObjectId].localId - 1 + floorId;
return gSaveBlock2Ptr->frontier.field_EE0 & gBitTable[bitId]; return gSaveBlock2Ptr->frontier.field_EE0 & gBitTable[bitId];
} }
@ -694,13 +780,13 @@ bool8 GetTrainerHillTrainerFlag(u8 eventObjectId)
void sub_81D61E8(void) void sub_81D61E8(void)
{ {
u8 i; u8 i;
u8 layoutId = sub_81D5520() * 2; u8 floorId = GetFloorId() * 2;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
if (gSaveBlock2Ptr->frontier.field_CB4[i] == gTrainerBattleOpponent_A) if (gSaveBlock2Ptr->frontier.field_CB4[i] == gTrainerBattleOpponent_A)
{ {
gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[layoutId + i]; gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[floorId + i];
break; break;
} }
} }
@ -711,7 +797,7 @@ void sub_81D61E8(void)
{ {
if (gSaveBlock2Ptr->frontier.field_CB4[i] == gTrainerBattleOpponent_B) if (gSaveBlock2Ptr->frontier.field_CB4[i] == gTrainerBattleOpponent_B)
{ {
gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[layoutId + i]; gSaveBlock2Ptr->frontier.field_EE0 |= gBitTable[floorId + i];
break; break;
} }
} }
@ -732,25 +818,25 @@ void sub_81D62B4(void)
void sub_81D62CC(u16 trainerId, u8 firstMonId) void sub_81D62CC(u16 trainerId, u8 firstMonId)
{ {
u8 trId, level; u8 trId, level;
s32 i, layoutId, arrId; s32 i, floorId, arrId;
if ((u16)(trainerId - 1) > 1) if ((u16)(trainerId - 1) > 1)
return; return;
trId = trainerId - 1; trId = trainerId - 1;
sub_81D56B0(); SetUpDataStruct();
level = GetHighestLevelInPlayerParty(); level = GetHighestLevelInPlayerParty();
layoutId = sub_81D5520(); floorId = GetFloorId();
for (i = firstMonId, arrId = 0; i < firstMonId + 3; i++, arrId++) for (i = firstMonId, arrId = 0; i < firstMonId + 3; i++, arrId++)
{ {
u8 id = gUnknown_0862A698[trId][arrId]; u8 id = gUnknown_0862A698[trId][arrId];
struct Pokemon *mon = &gEnemyParty[i]; struct Pokemon *mon = &gEnemyParty[i];
CreateBattleTowerMon(mon, &gUnknown_0203CF54->unk4.unk0[layoutId].trainers[trId].mons[id]); CreateBattleTowerMon(mon, &sHillData->tag.floors[floorId].trainers[trId].mons[id]);
sub_81D642C(mon, level); sub_81D642C(mon, level);
} }
sub_81D5710(); FreeDataStruct();
} }
void sub_81D6384(void) void sub_81D6384(void)
@ -779,10 +865,10 @@ u8 sub_81D63C8(u16 trainerId)
s32 i; s32 i;
u8 trId, facilityClass; u8 trId, facilityClass;
sub_81D56B0(); SetUpDataStruct();
trId = trainerId - 1; trId = trainerId - 1;
facilityClass = gUnknown_0203CF54->unk4.unk0[gUnknown_0203CF54->layoutId].trainers[trId].facilityClass; facilityClass = sHillData->tag.floors[sHillData->floorId].trainers[trId].facilityClass;
sub_81D5710(); FreeDataStruct();
for (i = 0; i < ARRAY_COUNT(gUnknown_0862A3B4); i++) for (i = 0; i < ARRAY_COUNT(gUnknown_0862A3B4); i++)
{ {
@ -807,9 +893,9 @@ u8 sub_81D6490(void)
{ {
u8 ret; u8 ret;
sub_81D56B0(); SetUpDataStruct();
ret = gUnknown_0203CF54->unk4.unkField_2; ret = sHillData->tag.unkField_2;
sub_81D5710(); FreeDataStruct();
return ret; return ret;
} }
@ -862,8 +948,8 @@ void sub_81D6568(void)
void sub_81D65A0(void) void sub_81D65A0(void)
{ {
gSaveBlock1Ptr->trainerHill.field_3D6E_1 = gSpecialVar_0x8005; gSaveBlock1Ptr->trainerHill.tag = gSpecialVar_0x8005;
gSaveBlock1Ptr->trainerHill.field_3D68 = gSaveBlock1Ptr->field_3718[gSpecialVar_0x8005]; gSaveBlock1Ptr->trainerHill.field_3D68 = gSaveBlock1Ptr->trainerHillTimes[gSpecialVar_0x8005];
} }
u8 sub_81D65E8(u8 arg0) u8 sub_81D65E8(u8 arg0)
@ -873,8 +959,8 @@ u8 sub_81D65E8(u8 arg0)
var = 0; var = 0;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
var ^= gUnknown_0203CF54->unk4.unk0[i].unk0 & 0x1F; var ^= sHillData->tag.floors[i].unk0 & 0x1F;
var ^= gUnknown_0203CF54->unk4.unk0[i].unk1 & 0x1F; var ^= sHillData->tag.floors[i].unk1 & 0x1F;
} }
if (arg0) if (arg0)
@ -894,18 +980,18 @@ u16 sub_81D6640(void)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
var += gUnknown_0203CF54->unk4.unk0[i].unk0; var += sHillData->tag.floors[i].unk0;
var += gUnknown_0203CF54->unk4.unk0[i].unk1; var += sHillData->tag.floors[i].unk1;
} }
var2 = var / 256; var2 = var / 256;
var2 %= 2; var2 %= 2;
if (FlagGet(FLAG_SYS_GAME_CLEAR) && gUnknown_0203CF54->unk4.unkField_0 == 8) if (FlagGet(FLAG_SYS_GAME_CLEAR) && sHillData->tag.unkField_0 == 8)
i = sub_81D65E8(1); i = sub_81D65E8(1);
else else
i = sub_81D65E8(0); i = sub_81D65E8(0);
if (gSaveBlock1Ptr->trainerHill.field_3D6E_1 == 3) if (gSaveBlock1Ptr->trainerHill.tag == HILL_TAG_EXPERT)
i = (i + 1) % 10; i = (i + 1) % 10;
ptr = gUnknown_0862A5CC[var2][i]; ptr = gUnknown_0862A5CC[var2][i];

View File

@ -289,13 +289,5 @@ gUnknown_0203CF4C: @ 203CF4C
gUnknown_0203CF50: @ 203CF50 gUnknown_0203CF50: @ 203CF50
.space 0x4 .space 0x4
gUnknown_0203CF54: @ 203CF54 .include "src/trainer_hill.o"
.space 0x4
gUnknown_0203CF58: @ 203CF58
.space 0x4
gUnknown_0203CF5C: @ 203CF5C
.space 0x4
.include "src/rayquaza_scene.o" .include "src/rayquaza_scene.o"