add FREE_TRAINER_HILL/TOWER functionality

This commit is contained in:
cawtds
2025-03-21 19:33:50 +01:00
parent 8d18c52508
commit 69ce201014
5 changed files with 70 additions and 2 deletions

View File

@@ -3,7 +3,7 @@
// SaveBlock1 configs
#define FREE_EXTRA_SEEN_FLAGS_SAVEBLOCK1 FALSE // Free up unused Pokédex seen flags (52 bytes).
#define FREE_TRAINER_HILL FALSE // Frees up Trainer Hill data (28 bytes).
#define FREE_TRAINER_HILL FALSE // Frees up Trainer Tower data (28 bytes).
#define FREE_MYSTERY_EVENT_BUFFERS FALSE // Frees up ramScript (1104 bytes).
#define FREE_MATCH_CALL FALSE // Frees up match call and rematch / VS Seeker data. (104 bytes).
#define FREE_UNION_ROOM_CHAT FALSE // Frees up union room chat (212 bytes).

View File

@@ -867,8 +867,10 @@ struct SaveBlock1
#endif //FREE_UNION_ROOM_CHAT
/*0x3BA8*/ struct TrainerNameRecord trainerNameRecords[20];
/*0x3C98*/ struct DaycareMon route5DayCareMon;
#if FREE_TRAINER_HILL == FALSE
/*0x3D34*/ u32 towerChallengeId;
/*0x3D38*/ struct TrainerTower trainerTower[NUM_TOWER_CHALLENGE_TYPES];
#endif //FREE_TRAINER_HILL
/*0x3D24*/ u8 unusedSB1[0x1C];
}; // size: 0x3D68

View File

@@ -12,7 +12,11 @@ STATIC_ASSERT(SEC30_SIZE + SEC31_SIZE <= SECTOR_COUNTER_OFFSET * 2, EReaderTrain
static u8 GetTrainerHillUnkVal(void)
{
#if FREE_TRAINER_HILL == FALSE
return (gSaveBlock1Ptr->trainerTower[0].unk9 + 1) % 256;
#else
return 0;
#endif //FREE_TRAINER_HILL
}
static bool32 ValidateTrainerTowerTrainer(struct TrainerTowerFloor * floor)

View File

@@ -55,7 +55,9 @@ void SetWhiteoutRespawnWarpAndHealerNpc(struct WarpData * warp)
if (VarGet(VAR_MAP_SCENE_TRAINER_TOWER) == 1)
{
#if FREE_TRAINER_HILL == FALSE
if (!gSaveBlock1Ptr->trainerTower[gSaveBlock1Ptr->towerChallengeId].spokeToOwner)
#endif //FREE_TRAINER_HILL
VarSet(VAR_MAP_SCENE_TRAINER_TOWER, 0);
gSpecialVar_LastTalked = 1;
warp->x = 4;

View File

@@ -94,8 +94,10 @@ static void HasSpokenToOwner(void);
static void BuildEnemyParty(void);
static s32 GetPartyMaxLevel(void);
static void ValidateOrResetCurTrainerTowerRecord(void);
#if FREE_TRAINER_HILL == FALSE
static u32 GetTrainerTowerRecordTime(u32 *);
static void SetTrainerTowerRecordTime(u32 *, u32);
#endif //FREE_TRAINER_HILL
extern const u8 gText_TimeBoard[];
extern const u8 gText_XMinYZSec[];
@@ -481,7 +483,9 @@ void InitTrainerTowerBattleStruct(void)
sTrainerTowerOpponent->battleType = CURR_FLOOR.challengeType;
sTrainerTowerOpponent->facilityClass = CURR_FLOOR.trainers[trainerId].facilityClass;
sTrainerTowerOpponent->textColor = CURR_FLOOR.trainers[trainerId].textColor;
#if FREE_TRAINER_HILL == FALSE
SetTrainerTowerVBlankCounter(&TRAINER_TOWER.timer);
#endif //FREE_TRAINER_HILL
FreeTrainerTowerDataStruct();
}
@@ -512,7 +516,11 @@ void GetTrainerTowerOpponentLoseText(u8 *dest, u8 opponentIdx)
static void SetUpTrainerTowerDataStruct(void)
{
#if FREE_TRAINER_HILL == FALSE
u32 challengeType = gSaveBlock1Ptr->towerChallengeId;
#else
u32 challengeType = CHALLENGE_TYPE_SINGLE;
#endif // FREE_TRAINER_HILL
s32 i;
const struct TrainerTowerFloor *const * floors_p;
@@ -537,7 +545,7 @@ static void SetUpTrainerTowerDataStruct(void)
static void FreeTrainerTowerDataStruct(void)
{
FREE_AND_SET_NULL(sTrainerTowerState);
TRY_FREE_AND_SET_NULL(sTrainerTowerState);
}
static void InitTrainerTowerFloor(void)
@@ -751,22 +759,29 @@ static void TrainerTowerGetChallengeType(void)
static void TrainerTowerAddFloorCleared(void)
{
#if FREE_TRAINER_HILL == FALSE
TRAINER_TOWER.floorsCleared++;
#endif //FREE_TRAINER_HILL
}
// So the player can safely go back through defeated floors to use the Poke Center (or exit challenge)
static void GetFloorAlreadyCleared(void)
{
#if FREE_TRAINER_HILL == FALSE
u16 mapLayoutId = gMapHeader.mapLayoutId;
if (mapLayoutId - LAYOUT_TRAINER_TOWER_1F == TRAINER_TOWER.floorsCleared
&& mapLayoutId - LAYOUT_TRAINER_TOWER_LOBBY <= CURR_FLOOR.floorIdx)
gSpecialVar_Result = FALSE;
else
gSpecialVar_Result = TRUE;
#else
gSpecialVar_Result = TRUE;
#endif //FREE_TRAINER_HILL
}
static void StartTrainerTowerChallenge(void)
{
#if FREE_TRAINER_HILL == FALSE
gSaveBlock1Ptr->towerChallengeId = gSpecialVar_0x8005;
if (gSaveBlock1Ptr->towerChallengeId >= NUM_TOWER_CHALLENGE_TYPES)
gSaveBlock1Ptr->towerChallengeId = 0;
@@ -780,10 +795,12 @@ static void StartTrainerTowerChallenge(void)
TRAINER_TOWER.timer = 0;
TRAINER_TOWER.spokeToOwner = FALSE;
TRAINER_TOWER.checkedFinalTime = FALSE;
#endif //FREE_TRAINER_HILL
}
static void GetOwnerState(void)
{
#if FREE_TRAINER_HILL == FALSE
ClearTrainerTowerVBlankCounter();
gSpecialVar_Result = 0;
@@ -793,10 +810,14 @@ static void GetOwnerState(void)
gSpecialVar_Result++;
TRAINER_TOWER.spokeToOwner = TRUE;
#else
gSpecialVar_Result = 2;
#endif //FREE_TRAINER_HILL
}
static void GiveChallengePrize(void)
{
#if FREE_TRAINER_HILL == FALSE
u16 itemId = sPrizeList[sTrainerTowerState->data.floors->prize];
if (TRAINER_TOWER.receivedPrize)
@@ -813,10 +834,14 @@ static void GiveChallengePrize(void)
{
gSpecialVar_Result = 1;
}
#else
gSpecialVar_Result = 0;
#endif //FREE_TRAINER_HILL
}
static void CheckFinalTime(void)
{
#if FREE_TRAINER_HILL == FALSE
if (TRAINER_TOWER.checkedFinalTime)
{
gSpecialVar_Result = 2;
@@ -832,10 +857,14 @@ static void CheckFinalTime(void)
}
TRAINER_TOWER.checkedFinalTime = TRUE;
#else
gSpecialVar_Result = 0;
#endif //FREE_TRAINER_HILL
}
static void TrainerTowerResumeTimer(void)
{
#if FREE_TRAINER_HILL == FALSE
if (!TRAINER_TOWER.spokeToOwner)
{
if (TRAINER_TOWER.timer >= TRAINER_TOWER_MAX_TIME)
@@ -843,15 +872,19 @@ static void TrainerTowerResumeTimer(void)
else
SetTrainerTowerVBlankCounter(&TRAINER_TOWER.timer);
}
#endif //FREE_TRAINER_HILL
}
static void TrainerTowerSetPlayerLost(void)
{
#if FREE_TRAINER_HILL == FALSE
TRAINER_TOWER.hasLost = TRUE;
#endif //FREE_TRAINER_HILL
}
static void GetTrainerTowerChallengeStatus(void)
{
#if FREE_TRAINER_HILL == FALSE
if (TRAINER_TOWER.hasLost)
{
TRAINER_TOWER.hasLost = FALSE;
@@ -866,6 +899,9 @@ static void GetTrainerTowerChallengeStatus(void)
{
gSpecialVar_Result = CHALLENGE_STATUS_NORMAL;
}
#else
gSpecialVar_Result = CHALLENGE_STATUS_NORMAL;
#endif //FREE_TRAINER_HILL
}
#define PRINT_TOWER_TIME(src) ({ \
@@ -886,6 +922,7 @@ static void GetTrainerTowerChallengeStatus(void)
static void GetCurrentTime(void)
{
#if FREE_TRAINER_HILL == FALSE
if (TRAINER_TOWER.timer >= TRAINER_TOWER_MAX_TIME)
{
ClearTrainerTowerVBlankCounter();
@@ -893,10 +930,16 @@ static void GetCurrentTime(void)
}
PRINT_TOWER_TIME(TRAINER_TOWER.timer);
#else
ConvertIntToDecimalStringN(gStringVar1, 0, STR_CONV_MODE_RIGHT_ALIGN, 2);
ConvertIntToDecimalStringN(gStringVar2, 0, STR_CONV_MODE_RIGHT_ALIGN, 2);
ConvertIntToDecimalStringN(gStringVar3, 0, STR_CONV_MODE_LEADING_ZEROS, 2);
#endif //FREE_TRAINER_HILL
}
static void ShowResultsBoard(void)
{
#if FREE_TRAINER_HILL == FALSE
u8 windowId;
s32 i;
@@ -918,13 +961,16 @@ static void ShowResultsBoard(void)
PutWindowTilemap(windowId);
CopyWindowToVram(windowId, COPYWIN_FULL);
VarSet(VAR_TEMP_1, windowId);
#endif //FREE_TRAINER_HILL
}
static void CloseResultsBoard(void)
{
#if FREE_TRAINER_HILL == FALSE
u8 windowId = VarGet(VAR_TEMP_1);
ClearStdWindowAndFrameToTransparent(windowId, TRUE);
RemoveWindow(windowId);
#endif //FREE_TRAINER_HILL
}
static void TrainerTowerGetDoublesEligiblity(void)
@@ -981,14 +1027,20 @@ static void PlayTrainerTowerEncounterMusic(void)
static void HasSpokenToOwner(void)
{
#if FREE_TRAINER_HILL == FALSE
gSpecialVar_Result = TRAINER_TOWER.spokeToOwner;
#endif //FREE_TRAINER_HILL
}
static void BuildEnemyParty(void)
{
u16 trainerIdx = VarGet(VAR_TEMP_1);
s32 level = GetPartyMaxLevel();
#if FREE_TRAINER_HILL == FALSE
u8 floorIdx = TRAINER_TOWER.floorsCleared;
#else
u8 floorIdx = gMapHeader.mapLayoutId - LAYOUT_TRAINER_TOWER_1F;
#endif //FREE_TRAINER_HILL
s32 i;
u8 monIdx;
@@ -1042,16 +1094,19 @@ static s32 GetPartyMaxLevel(void)
static void ValidateOrResetCurTrainerTowerRecord(void)
{
#if FREE_TRAINER_HILL == FALSE
if (TRAINER_TOWER.unk9 != sTrainerTowerState->data.id)
{
TRAINER_TOWER.unk9 = sTrainerTowerState->data.id;
SetTrainerTowerRecordTime(&TRAINER_TOWER.bestTime, TRAINER_TOWER_MAX_TIME);
TRAINER_TOWER.receivedPrize = FALSE;
}
#endif //FREE_TRAINER_HILL
}
void PrintTrainerTowerRecords(void)
{
#if FREE_TRAINER_HILL == FALSE
s32 i;
u8 windowId = 0;
@@ -1071,8 +1126,10 @@ void PrintTrainerTowerRecords(void)
PutWindowTilemap(windowId);
CopyWindowToVram(windowId, COPYWIN_FULL);
FreeTrainerTowerDataStruct();
#endif //FREE_TRAINER_HILL
}
#if FREE_TRAINER_HILL == FALSE
static u32 GetTrainerTowerRecordTime(u32 *counter)
{
return *counter;
@@ -1082,13 +1139,16 @@ static void SetTrainerTowerRecordTime(u32 *counter, u32 value)
{
*counter = value;
}
#endif //FREE_TRAINER_HILL
void ResetTrainerTowerResults(void)
{
#if FREE_TRAINER_HILL == FALSE
s32 i;
for (i = 0; i < NUM_TOWER_CHALLENGE_TYPES; i++)
{
SetTrainerTowerRecordTime(&gSaveBlock1Ptr->trainerTower[i].bestTime, TRAINER_TOWER_MAX_TIME);
}
#endif //FREE_TRAINER_HILL
}