diff options
Diffstat (limited to 'src')
115 files changed, 3771 insertions, 3300 deletions
diff --git a/src/apprentice.c b/src/apprentice.c index ec8fea27b..5d636d05d 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -1,5 +1,6 @@ #include "global.h" #include "apprentice.h" +#include "battle.h" #include "battle_tower.h" #include "data2.h" #include "event_data.h" @@ -1298,7 +1299,7 @@ static u16 sub_819FF98(u8 arg0) knownMovesCount = j; i = 0; - while (i < 5) + while (i <= MAX_MON_MOVES) { if (Random() % 2 == 0 || var_24 == TRUE) { @@ -1317,7 +1318,7 @@ static u16 sub_819FF98(u8 arg0) if (knownMovesCount < 5) j = 0; else - j = knownMovesCount - 4; + j = knownMovesCount - MAX_MON_MOVES; for (; j < knownMovesCount; j++) { @@ -1331,7 +1332,7 @@ static u16 sub_819FF98(u8 arg0) } else { - if (knownMovesCount < 5) + if (knownMovesCount <= MAX_MON_MOVES) { var_24 = TRUE; continue; @@ -1340,10 +1341,10 @@ static u16 sub_819FF98(u8 arg0) { do { - u8 learnsetId = Random() % (knownMovesCount - 4); + u8 learnsetId = Random() % (knownMovesCount - MAX_MON_MOVES); moveId = learnset[learnsetId] & 0x1FF; valid = TRUE; - for (j = knownMovesCount - 4; j < knownMovesCount; j++) + for (j = knownMovesCount - MAX_MON_MOVES; j < knownMovesCount; j++) { if ((learnset[j] & 0x1FF) == moveId) { @@ -1400,8 +1401,8 @@ static void GetLatestLearnedMoves(u16 species, u16 *moves) } knownMovesCount = i; - if (knownMovesCount > 4) - knownMovesCount = 4; + if (knownMovesCount > MAX_MON_MOVES) + knownMovesCount = MAX_MON_MOVES; for (j = 0; j < knownMovesCount; j++) moves[j] = learnset[(i - 1) - j] & 0x1FF; @@ -1447,7 +1448,7 @@ static void sub_81A0390(u8 arg0) { gSaveBlock2Ptr->apprentices[0].party[i].species = 0; gSaveBlock2Ptr->apprentices[0].party[i].item = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) gSaveBlock2Ptr->apprentices[0].party[i].moves[j] = 0; } diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index a88189870..6098e2d3a 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -320,7 +320,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) data[i] = 0; // Conditional score reset, unlike Ruby. - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (defaultScoreMoves & 1) AI_THINKING_STRUCT->score[i] = 100; @@ -333,7 +333,7 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves) moveLimitations = CheckMoveLimitations(gActiveBattler, 0, 0xFF); // Ignore moves that aren't possible to use. - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBitTable[i] & moveLimitations) AI_THINKING_STRUCT->score[i] = 0; @@ -424,7 +424,7 @@ static u8 ChooseMoveOrAction_Singles(void) currentMoveArray[0] = AI_THINKING_STRUCT->score[0]; consideredMoveArray[0] = 0; - for (i = 1; i < 4; i++) + for (i = 1; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI].moves[i] != MOVE_NONE) { @@ -459,7 +459,7 @@ static u8 ChooseMoveOrAction_Doubles(void) s32 mostViableMovesNo; s16 mostMovePoints; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_BATTLERS_COUNT; i++) { if (i == sBattler_AI || gBattleMons[i].hp == 0) { @@ -506,7 +506,7 @@ static u8 ChooseMoveOrAction_Doubles(void) mostViableMovesScores[0] = AI_THINKING_STRUCT->score[0]; mostViableMovesIndices[0] = 0; mostViableMovesNo = 1; - for (j = 1; j < 4; j++) + for (j = 1; j < MAX_MON_MOVES; j++) { if (gBattleMons[sBattler_AI].moves[j] != 0) { @@ -541,7 +541,7 @@ static u8 ChooseMoveOrAction_Doubles(void) mostViableTargetsArray[0] = 0; mostViableTargetsNo = 1; - for (i = 1; i < 4; i++) + for (i = 1; i < MAX_MON_MOVES; i++) { if (mostMovePoints == bestMovePointsForTarget[i]) { @@ -594,7 +594,7 @@ static void BattleAI_DoAIProcessing(void) { AI_THINKING_STRUCT->movesetIndex++; - if (AI_THINKING_STRUCT->movesetIndex < 4 && !(AI_THINKING_STRUCT->aiAction & AI_ACTION_DO_NOT_ATTACK)) + if (AI_THINKING_STRUCT->movesetIndex < MAX_MON_MOVES && !(AI_THINKING_STRUCT->aiAction & AI_ACTION_DO_NOT_ATTACK)) AI_THINKING_STRUCT->aiState = AIState_SettingUp; else AI_THINKING_STRUCT->aiState++; @@ -610,7 +610,7 @@ static void RecordLastUsedMoveByTarget(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) break; @@ -627,7 +627,7 @@ void ClearBattlerMoveHistory(u8 battlerId) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) BATTLE_HISTORY->usedMoves[battlerId].moves[i] = MOVE_NONE; } @@ -1067,14 +1067,14 @@ static void BattleAICmd_if_user_has_attacking_move(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].power != 0) break; } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 5; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1); @@ -1084,14 +1084,14 @@ static void BattleAICmd_if_user_has_no_attacking_moves(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].power != 0) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 5; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 1); @@ -1182,7 +1182,7 @@ static void BattleAICmd_get_how_powerful_move_is(void) gMoveResultFlags = 0; gCritMultiplier = 1; - for (checkedMove = 0; checkedMove < 4; checkedMove++) + for (checkedMove = 0; checkedMove < MAX_MON_MOVES; checkedMove++) { for (i = 0; sDiscouragedPowerfulMoveEffects[i] != 0xFFFF; i++) { @@ -1207,13 +1207,13 @@ static void BattleAICmd_get_how_powerful_move_is(void) } } - for (checkedMove = 0; checkedMove < 4; checkedMove++) + for (checkedMove = 0; checkedMove < MAX_MON_MOVES; checkedMove++) { if (moveDmgs[checkedMove] > moveDmgs[AI_THINKING_STRUCT->movesetIndex]) break; } - if (checkedMove == 4) + if (checkedMove == MAX_MON_MOVES) AI_THINKING_STRUCT->funcResult = MOVE_MOST_POWERFUL; // Is the most powerful. else AI_THINKING_STRUCT->funcResult = MOVE_NOT_MOST_POWERFUL; // Not the most powerful. @@ -1464,7 +1464,7 @@ static void BattleAICmd_get_highest_type_effectiveness(void) gCritMultiplier = 1; AI_THINKING_STRUCT->funcResult = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { gBattleMoveDamage = 40; gCurrentMove = gBattleMons[sBattler_AI].moves[i]; @@ -1765,12 +1765,12 @@ static void BattleAICmd_if_has_move(void) switch (gAIScriptPtr[1]) { case AI_USER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI].moves[i] == *movePtr) break; } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 8; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); @@ -1783,25 +1783,25 @@ static void BattleAICmd_if_has_move(void) } else { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI ^ BIT_FLANK].moves[i] == *movePtr) break; } } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 8; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); break; case AI_TARGET: case AI_TARGET_PARTNER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) break; } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 8; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); @@ -1818,24 +1818,24 @@ static void BattleAICmd_if_doesnt_have_move(void) { case AI_USER: case AI_USER_PARTNER: // UB: no separate check for user partner. - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI].moves[i] == *movePtr) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 8; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); break; case AI_TARGET: case AI_TARGET_PARTNER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] == *movePtr) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 8; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 4); @@ -1851,25 +1851,25 @@ static void BattleAICmd_if_has_move_with_effect(void) { case AI_USER: case AI_USER_PARTNER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].effect == gAIScriptPtr[2]) break; } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 7; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); break; case AI_TARGET: case AI_TARGET_PARTNER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { // UB: checks sBattler_AI instead of gBattlerTarget. if (gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2]) break; } - if (i == 4) + if (i == MAX_MON_MOVES) gAIScriptPtr += 7; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); @@ -1885,24 +1885,24 @@ static void BattleAICmd_if_doesnt_have_move_with_effect(void) { case AI_USER: case AI_USER_PARTNER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if(gBattleMons[sBattler_AI].moves[i] != 0 && gBattleMoves[gBattleMons[sBattler_AI].moves[i]].effect == gAIScriptPtr[2]) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 7; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); break; case AI_TARGET: case AI_TARGET_PARTNER: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i] && gBattleMoves[BATTLE_HISTORY->usedMoves[gBattlerTarget].moves[i]].effect == gAIScriptPtr[2]) break; } - if (i != 4) + if (i != MAX_MON_MOVES) gAIScriptPtr += 7; else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index ad25b483c..a5958ebc6 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -49,7 +49,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) return FALSE; // Check if Pokemon has a super effective move. - for (opposingBattler = GetBattlerAtPosition(opposingPosition), i = 0; i < 4; i++) + for (opposingBattler = GetBattlerAtPosition(opposingPosition), i = 0; i < MAX_MON_MOVES; i++) { move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) @@ -93,7 +93,7 @@ static bool8 ShouldSwitchIfWonderGuard(void) GetMonData(&party[i], MON_DATA_SPECIES); // Unused return value. GetMonData(&party[i], MON_DATA_ALT_ABILITY); // Unused return value. - for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < 4; j++) + for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < MAX_MON_MOVES; j++) { move = GetMonData(&party[i], MON_DATA_MOVE1 + j); if (move == MOVE_NONE) @@ -262,7 +262,7 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) @@ -285,7 +285,7 @@ static bool8 HasSuperEffectiveMoveAgainstOpponents(bool8 noRng) if (!(gAbsentBattlerFlags & gBitTable[opposingBattler])) { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { move = gBattleMons[gActiveBattler].moves[i]; if (move == MOVE_NONE) @@ -400,7 +400,7 @@ static bool8 FindMonWithFlagsAndSuperEffective(u8 flags, u8 moduloPercent) { battlerIn1 = gLastHitBy[gActiveBattler]; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { move = GetMonData(&party[i], MON_DATA_MOVE1 + j); if (move == 0) @@ -715,14 +715,14 @@ u8 GetMostSuitableMonToSwitchInto(void) // Ok, we know the mon has the right typing but does it have at least one super effective move? if (bestMonId != PARTY_SIZE) { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { move = GetMonData(&party[bestMonId], MON_DATA_MOVE1 + i); if (move != MOVE_NONE && TypeCalc(move, gActiveBattler, opposingBattler) & MOVE_RESULT_SUPER_EFFECTIVE) break; } - if (i != 4) + if (i != MAX_MON_MOVES) return bestMonId; // Has both the typing and at least one super effective move. invalidMons |= gBitTable[bestMonId]; // Sorry buddy, we want something better. @@ -757,7 +757,7 @@ u8 GetMostSuitableMonToSwitchInto(void) if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { move = GetMonData(&party[i], MON_DATA_MOVE1 + j); gBattleMoveDamage = 0; diff --git a/src/battle_anim.c b/src/battle_anim.c index d1550f31e..7dd1526dd 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -2283,7 +2283,7 @@ static void ScriptCmd_setalpha(void) sBattleAnimScriptPtr++; half1 = *(sBattleAnimScriptPtr++); half2 = *(sBattleAnimScriptPtr++) << 8; - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, half1 | half2); } diff --git a/src/battle_anim_80A5C6C.c b/src/battle_anim_80A5C6C.c index f85104bc7..92815b56c 100644 --- a/src/battle_anim_80A5C6C.c +++ b/src/battle_anim_80A5C6C.c @@ -2092,17 +2092,17 @@ u8 sub_80A8394(u16 species, bool8 isBackpic, u8 a3, s16 x, s16 y, u8 subpriority return spriteId; } -void sub_80A8610(struct Sprite *sprite) +void DestroySpriteAndFreeResources_(struct Sprite *sprite) { DestroySpriteAndFreeResources(sprite); } -s16 sub_80A861C(u8 battlerId, u8 a2) +s16 GetBattlerSpriteCoordAttr(u8 battlerId, u8 attr) { u16 species; u32 personality; u16 letter; - u16 var; + u16 unownSpecies; int ret; const struct MonCoords *coords; struct BattleSpriteInfo *spriteInfo; @@ -2123,10 +2123,10 @@ s16 sub_80A861C(u8 battlerId, u8 a2) { letter = GET_UNOWN_LETTER(personality); if (!letter) - var = SPECIES_UNOWN; + unownSpecies = SPECIES_UNOWN; else - var = letter + SPECIES_UNOWN_B - 1; - coords = &gMonBackPicCoords[var]; + unownSpecies = letter + SPECIES_UNOWN_B - 1; + coords = &gMonBackPicCoords[unownSpecies]; } else if (species == SPECIES_CASTFORM) { @@ -2156,16 +2156,17 @@ s16 sub_80A861C(u8 battlerId, u8 a2) species = spriteInfo[battlerId].transformSpecies; personality = gTransformedPersonalities[battlerId]; } + if (species == SPECIES_UNOWN) { letter = GET_UNOWN_LETTER(personality); if (!letter) - var = SPECIES_UNOWN; + unownSpecies = SPECIES_UNOWN; else - var = letter + SPECIES_UNOWN_B - 1; - coords = &gMonBackPicCoords[var]; + unownSpecies = letter + SPECIES_UNOWN_B - 1; + coords = &gMonBackPicCoords[unownSpecies]; } - else if (species > SPECIES_EGG) + else if (species > NUM_SPECIES) { coords = &gMonBackPicCoords[0]; } @@ -2187,20 +2188,21 @@ s16 sub_80A861C(u8 battlerId, u8 a2) species = spriteInfo[battlerId].transformSpecies; personality = gTransformedPersonalities[battlerId]; } + if (species == SPECIES_UNOWN) { letter = GET_UNOWN_LETTER(personality); if (!letter) - var = SPECIES_UNOWN; + unownSpecies = SPECIES_UNOWN; else - var = letter + SPECIES_UNOWN_B - 1; - coords = &gMonFrontPicCoords[var]; + unownSpecies = letter + SPECIES_UNOWN_B - 1; + coords = &gMonFrontPicCoords[unownSpecies]; } else if (species == SPECIES_CASTFORM) { coords = &gCastformFrontSpriteCoords[gBattleMonForms[battlerId]]; } - else if (species > SPECIES_EGG) + else if (species > NUM_SPECIES) { coords = &gMonFrontPicCoords[0]; } @@ -2211,22 +2213,22 @@ s16 sub_80A861C(u8 battlerId, u8 a2) } } - switch (a2) + switch (attr) { - case 0: + case BATTLER_COORD_ATTR_HEIGHT: return (coords->coords & 0xf) * 8; - case 1: + case BATTLER_COORD_ATTR_WIDTH: return (coords->coords >> 4) * 8; - case 4: - return GetBattlerSpriteCoord(battlerId, 2) - ((coords->coords >> 4) * 4); - case 5: - return GetBattlerSpriteCoord(battlerId, 2) + ((coords->coords >> 4) * 4); - case 2: - return GetBattlerSpriteCoord(battlerId, 3) - ((coords->coords & 0xf) * 4); - case 3: - return GetBattlerSpriteCoord(battlerId, 3) + ((coords->coords & 0xf) * 4); - case 6: - ret = GetBattlerSpriteCoord(battlerId, 1) + 0x1f; + case BATTLER_COORD_ATTR_LEFT: + return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X_2) - ((coords->coords >> 4) * 4); + case BATTLER_COORD_ATTR_RIGHT: + return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_X_2) + ((coords->coords >> 4) * 4); + case BATTLER_COORD_ATTR_TOP: + return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y_PIC_OFFSET) - ((coords->coords & 0xf) * 4); + case BATTLER_COORD_ATTR_BOTTOM: + return GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y_PIC_OFFSET) + ((coords->coords & 0xf) * 4); + case BATTLER_COORD_ATTR_RAW_BOTTOM: + ret = GetBattlerSpriteCoord(battlerId, BATTLER_COORD_Y) + 31; return ret - coords->y_offset; default: return 0; diff --git a/src/battle_anim_8170478.c b/src/battle_anim_8170478.c index 502c4cdbb..5b7a4ec1c 100755 --- a/src/battle_anim_8170478.c +++ b/src/battle_anim_8170478.c @@ -388,7 +388,7 @@ const struct SpriteTemplate gBattleAnimSpriteTemplate_085E535C = }; extern const struct SpriteTemplate gUnknown_085CE388; -extern const struct SpriteTemplate gUnknown_085CE3A0; +extern const struct SpriteTemplate gMiniTwinklingStarSpriteTemplate; void unref_sub_8170478(u8 taskId) { @@ -2081,12 +2081,12 @@ static void sub_8172FEC(u8 taskId) } else if (state >= 0 && gTasks[taskId].data[11] < 4) { - spriteId = CreateSprite(&gUnknown_085CE3A0, x, y, 5); + spriteId = CreateSprite(&gMiniTwinklingStarSpriteTemplate, x, y, 5); gSprites[spriteId].oam.tileNum += 4; } else { - spriteId = CreateSprite(&gUnknown_085CE3A0, x, y, 5); + spriteId = CreateSprite(&gMiniTwinklingStarSpriteTemplate, x, y, 5); gSprites[spriteId].oam.tileNum += 5; } diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index e37d2b5b8..25eb14637 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -3297,8 +3297,8 @@ void sub_80FFFC0(u8 taskId) task->data[4] = GetBattlerSpriteSubpriority(gBattleAnimTarget) - 1; task->data[6] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); task->data[7] = GetBattlerSpriteCoord(gBattleAnimTarget, 3); - task->data[10] = sub_80A861C(gBattleAnimTarget, 1); - task->data[11] = sub_80A861C(gBattleAnimTarget, 0); + task->data[10] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_WIDTH); + task->data[11] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_HEIGHT); task->data[5] = (GetBattlerSide(gBattleAnimTarget) == B_SIDE_OPPONENT) ? 1 : -1; task->data[9] = 56 - (task->data[5] * 64); task->data[8] = task->data[7] - task->data[9] + task->data[6]; @@ -5452,11 +5452,11 @@ static void sub_81030B0(struct Sprite* sprite) void sub_810310C(u8 battler, struct Sprite* sprite) { if (GetBattlerSide(battler) == B_SIDE_PLAYER) - sprite->pos1.x = sub_80A861C(battler, 5) + 8; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_RIGHT) + 8; else - sprite->pos1.x = sub_80A861C(battler, 4) - 8; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_LEFT) - 8; - sprite->pos1.y = GetBattlerSpriteCoord(battler, 3) - (s16)sub_80A861C(battler, 0) / 4; + sprite->pos1.y = GetBattlerSpriteCoord(battler, 3) - (s16)GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_HEIGHT) / 4; } void sub_8103164(struct Sprite* sprite) @@ -5520,7 +5520,7 @@ void sub_8103284(struct Sprite* sprite) battler = gBattleAnimTarget; sprite->pos1.x = GetBattlerSpriteCoord(battler, 0); - sprite->pos1.y = sub_80A861C(battler, 2); + sprite->pos1.y = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_TOP); if (sprite->pos1.y <= 9) sprite->pos1.y = 10; diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 1a7fb8736..8306ada1c 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -2446,7 +2446,7 @@ void sub_8104E74(u8 taskId) task->data[3] = 0; task->data[4] = 0; task->data[5] = 0; - task->data[15] = sub_80A861C(gBattleAnimTarget, 0); + task->data[15] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_HEIGHT); if (GetBattlerSpriteBGPriorityRank(gBattleAnimTarget) == 1) { @@ -2531,7 +2531,7 @@ void sub_810501C(struct Sprite *sprite) sprite->data[2] = 0; sprite->data[3] = 16; sprite->data[4] = 0; - sprite->data[5] = sub_80A861C(gBattleAnimTarget, 0) + 2; + sprite->data[5] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_HEIGHT) + 2; sprite->data[6] = BattleAnimAdjustPanning(63); sprite->callback = sub_8105078; } @@ -3134,7 +3134,7 @@ void sub_8105EB0(u8 taskId) SetGpuReg(REG_OFFSET_WIN0V, gBattle_WIN0V); SetGpuReg(REG_OFFSET_WININ, 0x3F1F); SetGpuReg(REG_OFFSET_WINOUT, 0x3F3F); - SetGpuReg(REG_OFFSET_BLDCNT, 0xC8); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_DARKEN); SetGpuReg(REG_OFFSET_BLDY, 0x10); gTasks[taskId].data[0] = win0v; gTasks[taskId].data[1] = win0h; diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index 72d9722b3..018cc48e4 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -22,6 +22,7 @@ #include "constants/rgb.h" #include "constants/songs.h" #include "constants/species.h" +#include "constants/weather.h" extern u8 sub_807521C(s16 x, s16 y, u8 a3); extern void sub_810E2C8(struct Sprite *); @@ -45,7 +46,7 @@ void sub_815ACD0(struct Sprite *); void sub_815B27C(struct Sprite *); void sub_815B394(struct Sprite *); void sub_815B49C(struct Sprite *); -void sub_815B570(struct Sprite *); +void AnimMiniTwinklingStar(struct Sprite *); void sub_815B70C(struct Sprite *); void sub_815BE04(struct Sprite *); void sub_815C400(struct Sprite *); @@ -61,15 +62,15 @@ void sub_815E01C(struct Sprite *); void sub_815E404(struct Sprite *); void sub_815E444(struct Sprite *); void sub_815E6D8(struct Sprite *); -void sub_815E954(struct Sprite *); -void sub_815EA14(struct Sprite *); -void sub_815EE84(struct Sprite *); -void sub_815F18C(struct Sprite *); -void sub_815F48C(struct Sprite *); +void AnimSmellingSaltExclamation(struct Sprite *); +void AnimHelpingHandClap(struct Sprite *); +void AnimForesightMagnifyingGlass(struct Sprite *); +void AnimMeteorMashStar(struct Sprite *); +void AnimBlockX(struct Sprite *); void sub_815FE80(struct Sprite *); void sub_81061C4(struct Sprite *); -void sub_8160338(struct Sprite *); -void sub_81603A8(struct Sprite *); +void AnimKnockOffStrike(struct Sprite *); +void AnimRecycle(struct Sprite *); static void sub_815A114(struct Sprite *); static void sub_815A1F4(struct Sprite *); static void sub_815A234(struct Sprite *); @@ -111,15 +112,18 @@ static void sub_815E20C(u8); static void sub_815E34C(s16, s16, s16, s16, u8, u8, s16 *, s16 *); static void sub_815E5CC(u8); static void sub_815E784(struct Sprite *); -static void sub_815E898(u8); -static void sub_815E9BC(struct Sprite *); -static void sub_815EA60(struct Sprite *); -static void sub_815ECE4(u8); -static void sub_815EF08(struct Sprite *); -static void sub_815F330(u8); -static void sub_815F4F0(struct Sprite *); -static void sub_815F79C(u8); -static void sub_815F7C4(struct Sprite *); +static void AnimTask_SmellingSaltSquishStep(u8); +static void AnimSmellingSaltExclamationStep(struct Sprite *); +static void AnimHelpingHandClapStep(struct Sprite *); +static void AnimTask_HelpingHandAttackerMovementStep(u8); +static void AnimForesightMagnifyingGlassStep(struct Sprite *); +static void AnimTask_MonToSubstituteDoll(u8); +static void AnimBlockXStep(struct Sprite *); +static void AnimTask_OdorSleuthMovementWaitFinish(u8); +static void MoveOdorSleuthClone(struct Sprite *); +static void AnimTask_TeeterDanceMovementStep(u8); +static void AnimRecycleStep(struct Sprite *); +static void AnimTask_SlackOffSquishStep(u8); const union AnimCmd gUnknown_085CE004[] = { @@ -535,7 +539,7 @@ const struct SpriteTemplate gUnknown_085CE388 = .callback = sub_815B49C, }; -const struct SpriteTemplate gUnknown_085CE3A0 = +const struct SpriteTemplate gMiniTwinklingStarSpriteTemplate = { .tileTag = ANIM_TAG_GOLD_STARS, .paletteTag = ANIM_TAG_GOLD_STARS, @@ -543,7 +547,7 @@ const struct SpriteTemplate gUnknown_085CE3A0 = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_815B570, + .callback = AnimMiniTwinklingStar, }; const union AffineAnimCmd gUnknown_085CE3B8[] = @@ -995,14 +999,14 @@ const struct SpriteTemplate gUnknown_085CE864 = .callback = sub_815E6D8, }; -const union AffineAnimCmd gUnknown_085CE87C[] = +const union AffineAnimCmd gSmellingSaltSquishAffineAnimCmds[] = { AFFINEANIMCMD_FRAME(0, -16, 0, 6), AFFINEANIMCMD_FRAME(0, 16, 0, 6), AFFINEANIMCMD_END, }; -const struct SpriteTemplate gUnknown_085CE894 = +const struct SpriteTemplate gSmellingSaltExclamationSpriteTemplate = { .tileTag = ANIM_TAG_SMELLINGSALT_EFFECT, .paletteTag = ANIM_TAG_SMELLINGSALT_EFFECT, @@ -1010,10 +1014,10 @@ const struct SpriteTemplate gUnknown_085CE894 = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_815E954, + .callback = AnimSmellingSaltExclamation, }; -const struct SpriteTemplate gUnknown_085CE8AC = +const struct SpriteTemplate gHelpingHandClapSpriteTemplate = { .tileTag = ANIM_TAG_TAG_HAND, .paletteTag = ANIM_TAG_TAG_HAND, @@ -1021,10 +1025,10 @@ const struct SpriteTemplate gUnknown_085CE8AC = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_815EA14, + .callback = AnimHelpingHandClap, }; -const struct SpriteTemplate gUnknown_085CE8C4 = +const struct SpriteTemplate gForesightMagnifyingGlassSpriteTemplate = { .tileTag = ANIM_TAG_MAGNIFYING_GLASS, .paletteTag = ANIM_TAG_MAGNIFYING_GLASS, @@ -1032,10 +1036,10 @@ const struct SpriteTemplate gUnknown_085CE8C4 = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_815EE84, + .callback = AnimForesightMagnifyingGlass, }; -const struct SpriteTemplate gUnknown_085CE8DC = +const struct SpriteTemplate gMeteorMashStarSpriteTemplate = { .tileTag = ANIM_TAG_GOLD_STARS, .paletteTag = ANIM_TAG_GOLD_STARS, @@ -1043,7 +1047,7 @@ const struct SpriteTemplate gUnknown_085CE8DC = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_815F18C, + .callback = AnimMeteorMashStar, }; const struct SpriteTemplate gUnknown_085CE8F4 = @@ -1057,7 +1061,7 @@ const struct SpriteTemplate gUnknown_085CE8F4 = .callback = sub_81061C4, }; -const struct SpriteTemplate gUnknown_085CE90C = +const struct SpriteTemplate gBlockXSpriteTemplate = { .tileTag = ANIM_TAG_X_SIGN, .paletteTag = ANIM_TAG_X_SIGN, @@ -1065,7 +1069,7 @@ const struct SpriteTemplate gUnknown_085CE90C = .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_815F48C, + .callback = AnimBlockX, }; const struct SpriteTemplate gUnknown_085CE924 = @@ -1079,72 +1083,72 @@ const struct SpriteTemplate gUnknown_085CE924 = .callback = sub_815FE80, }; -const union AnimCmd gUnknown_085CE93C[] = +const union AnimCmd gKnockOffStrikeAnimCmds[] = { ANIMCMD_FRAME(0, 4), ANIMCMD_FRAME(64, 4), ANIMCMD_END, }; -const union AnimCmd *const gUnknown_085CE948[] = +const union AnimCmd *const gKnockOffStrikeAnimTable[] = { - gUnknown_085CE93C, + gKnockOffStrikeAnimCmds, }; -const union AffineAnimCmd gUnknown_085CE94C[] = +const union AffineAnimCmd gKnockOffStrikeAffineanimCmds1[] = { AFFINEANIMCMD_FRAME(0x100, 0x100, 0, 0), AFFINEANIMCMD_FRAME(0, 0, -4, 8), AFFINEANIMCMD_END, }; -const union AffineAnimCmd gUnknown_085CE964[] = +const union AffineAnimCmd gKnockOffStrikeAffineanimCmds2[] = { AFFINEANIMCMD_FRAME(-0x100, 0x100, 0, 0), AFFINEANIMCMD_FRAME(0, 0, 4, 8), AFFINEANIMCMD_END, }; -const union AffineAnimCmd *const gUnknown_085CE97C[] = +const union AffineAnimCmd *const gKnockOffStrikeAffineAnimTable[] = { - gUnknown_085CE94C, - gUnknown_085CE964, + gKnockOffStrikeAffineanimCmds1, + gKnockOffStrikeAffineanimCmds2, }; -const struct SpriteTemplate gUnknown_085CE984 = +const struct SpriteTemplate gKnockOffStrikeSpriteTemplate = { .tileTag = ANIM_TAG_SLAM_HIT_2, .paletteTag = ANIM_TAG_SLAM_HIT_2, .oam = &gUnknown_0852497C, - .anims = gUnknown_085CE948, + .anims = gKnockOffStrikeAnimTable, .images = NULL, - .affineAnims = gUnknown_085CE97C, - .callback = sub_8160338, + .affineAnims = gKnockOffStrikeAffineAnimTable, + .callback = AnimKnockOffStrike, }; -const union AffineAnimCmd gUnknown_085CE99C[] = +const union AffineAnimCmd gRecycleSpriteAffineAnimCmds[] = { AFFINEANIMCMD_FRAME(0, 0, -4, 64), AFFINEANIMCMD_JUMP(0), }; -const union AffineAnimCmd *const gUnknown_085CE9AC[] = +const union AffineAnimCmd *const gRecycleSpriteAffineAnimTable[] = { - gUnknown_085CE99C, + gRecycleSpriteAffineAnimCmds, }; -const struct SpriteTemplate gUnknown_085CE9B0 = +const struct SpriteTemplate gRecycleSpriteTemplate = { .tileTag = ANIM_TAG_RECYCLE, .paletteTag = ANIM_TAG_RECYCLE, .oam = &gUnknown_08524A9C, .anims = gDummySpriteAnimTable, .images = NULL, - .affineAnims = gUnknown_085CE9AC, - .callback = sub_81603A8, + .affineAnims = gRecycleSpriteAffineAnimTable, + .callback = AnimRecycle, }; -const union AffineAnimCmd gUnknown_085CE9C8[] = +const union AffineAnimCmd gSlackOffSquishAffineAnimCmds[] = { AFFINEANIMCMD_FRAME(0, 16, 0, 4), AFFINEANIMCMD_FRAME(-2, 0, 0, 8), @@ -1450,11 +1454,9 @@ void sub_815A7B0(struct Sprite *sprite) StoreSpriteCallbackInData6(sprite, DestroyAnimSprite); } -// This is likely fakematching due to some strange type casting behavior. void sub_815A7EC(struct Sprite *sprite) { int var0; - int var1; if (sprite->data[0] == 0) { SetSpriteCoordsToAnimAttackerCoords(sprite); @@ -1468,16 +1470,13 @@ void sub_815A7EC(struct Sprite *sprite) } else { - var1 = -gBattleAnimArgs[2]; - sprite->data[1] = var1; - var1 = -gBattleAnimArgs[3]; - sprite->data[2] = var1; + sprite->data[1] = -1 * gBattleAnimArgs[2]; + sprite->data[2] = -1 * gBattleAnimArgs[3]; } } else { - var1 = -gBattleAnimArgs[2]; - sprite->data[1] = var1; + sprite->data[1] = -1 * gBattleAnimArgs[2]; sprite->data[2] = gBattleAnimArgs[3]; } } @@ -1486,8 +1485,8 @@ void sub_815A7EC(struct Sprite *sprite) var0 = (sprite->data[0] * 20) & 0xFF; sprite->data[3] += sprite->data[1]; sprite->data[4] += sprite->data[2]; - sprite->pos2.x = (sprite->data[3] + (s32)((u32)sprite->data[3] >> 31)) >> 1; - sprite->pos2.y = Sin(var0 & 0xFF, 5) + ((s32)(sprite->data[4] + ((u32)sprite->data[4] >> 31)) >> 1); + sprite->pos2.x = sprite->data[3] / 2; + sprite->pos2.y = Sin(var0 & 0xFF, 5) + (sprite->data[4] / 2); if ((u16)(sprite->pos1.x + sprite->pos2.x) > 240) DestroyAnimSprite(sprite); @@ -1688,7 +1687,6 @@ void sub_815AC8C(u8 taskId) void sub_815ACD0(struct Sprite *sprite) { - int var0; if (gBattleAnimArgs[0] == 0) { sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 0) + gBattleAnimArgs[1]; @@ -1701,11 +1699,8 @@ void sub_815ACD0(struct Sprite *sprite) } sprite->pos2.y = gBattleAnimArgs[2]; - var0 = 0; - if (sprite->pos2.y > gBattleAnimArgs[3]) - var0 = 1; - sprite->data[0] = var0; + sprite->data[0] = (sprite->pos2.y > gBattleAnimArgs[3]); sprite->data[1] = 0; sprite->data[2] = gBattleAnimArgs[4]; sprite->data[3] = gBattleAnimArgs[5]; @@ -2113,7 +2108,7 @@ static void sub_815B4D4(struct Sprite *sprite) if (++sprite->data[2] % 3 == 0) { CreateSpriteAndAnimate( - &gUnknown_085CE3A0, + &gMiniTwinklingStarSpriteTemplate, sprite->pos1.x + sprite->pos2.x, sprite->pos1.y + sprite->pos2.y, sprite->subpriority + 1); @@ -2124,7 +2119,7 @@ static void sub_815B4D4(struct Sprite *sprite) DestroyAnimSprite(sprite); } -void sub_815B570(struct Sprite *sprite) +void AnimMiniTwinklingStar(struct Sprite *sprite) { u8 rand; s8 y; @@ -3143,8 +3138,6 @@ static void sub_815CDFC(struct Sprite *sprite) } } - - extern void sub_815D160(u8); void sub_815CED8(u8 taskId) @@ -3220,7 +3213,7 @@ void sub_815CED8(u8 taskId) gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; FillPalette(RGB(31, 31, 31), (gSprites[spriteId].oam.paletteNum << 4) + 0x100, 32); gSprites[spriteId].oam.priority = priority; - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F40); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[1], 16 - gTasks[taskId].data[1])); gTasks[taskId].data[0] = spriteId; @@ -3253,7 +3246,7 @@ static void sub_815D1BC(u8 taskId) if (++gTasks[taskId].data[12] == 9) { sub_80A749C(&gSprites[spriteId]); - sub_80A8610(&gSprites[spriteId]); + DestroySpriteAndFreeResources_(&gSprites[spriteId]); gTasks[taskId].func = sub_80A6814; } } @@ -3888,11 +3881,11 @@ void sub_815E114(u8 taskId) } if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) - task->data[11] = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) + sub_80A861C(gBattleAnimAttacker, 0) / 4; + task->data[11] = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) + GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_HEIGHT) / 4; else - task->data[11] = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) - sub_80A861C(gBattleAnimAttacker, 0) / 4; + task->data[11] = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) - GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_HEIGHT) / 4; - task->data[12] = GetBattlerSpriteCoord(gBattleAnimAttacker, 3) - sub_80A861C(gBattleAnimAttacker, 0) / 4; + task->data[12] = GetBattlerSpriteCoord(gBattleAnimAttacker, 3) - GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_HEIGHT) / 4; task->data[13] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); task->data[14] = GetBattlerSpriteCoord(gBattleAnimTarget, 3); task->func = sub_815E20C; @@ -4019,7 +4012,7 @@ void sub_815E47C(u8 taskId) task->data[11] = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); task->data[12] = GetBattlerSpriteCoord(gBattleAnimAttacker, 3); task->data[13] = GetBattlerSpriteCoord(gBattleAnimTarget, 2); - task->data[14] = GetBattlerSpriteCoord(gBattleAnimTarget, 3) + sub_80A861C(gBattleAnimTarget, 0) / 4; + task->data[14] = GetBattlerSpriteCoord(gBattleAnimTarget, 3) + GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_HEIGHT) / 4; task->data[15] = CreateSprite(&gUnknown_085CE84C, task->data[11], task->data[12], GetBattlerSpriteSubpriority(gBattleAnimTarget) - 5); if (task->data[15] != MAX_SPRITES) { @@ -4098,11 +4091,11 @@ void sub_815E6D8(struct Sprite *sprite) if (gBattleAnimArgs[1] == 0) { sprite->oam.matrixNum |= 0x8; - sprite->pos1.x = sub_80A861C(battler, 4) - 8; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_LEFT) - 8; } else { - sprite->pos1.x = sub_80A861C(battler, 5) + 8; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_RIGHT) + 8; } sprite->callback = sub_815E784; @@ -4154,9 +4147,12 @@ static void sub_815E784(struct Sprite *sprite) } } -void sub_815E840(u8 taskId) +// Squishes the mon horizontally a few times. +// arg 0: which mon +// arg 1: number of squishes +void AnimTask_SmellingSaltSquish(u8 taskId) { - if (gBattleAnimArgs[0] == 0) + if (gBattleAnimArgs[0] == ANIM_ATTACKER) { DestroyAnimVisualTask(taskId); } @@ -4164,12 +4160,12 @@ void sub_815E840(u8 taskId) { gTasks[taskId].data[0] = gBattleAnimArgs[1]; gTasks[taskId].data[15] = GetAnimBattlerSpriteId(gBattleAnimArgs[0]); - PrepareAffineAnimInTaskData(&gTasks[taskId], gTasks[taskId].data[15], gUnknown_085CE87C); - gTasks[taskId].func = sub_815E898; + PrepareAffineAnimInTaskData(&gTasks[taskId], gTasks[taskId].data[15], gSmellingSaltSquishAffineAnimCmds); + gTasks[taskId].func = AnimTask_SmellingSaltSquishStep; } } -static void sub_815E898(u8 taskId) +static void AnimTask_SmellingSaltSquishStep(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -4187,7 +4183,7 @@ static void sub_815E898(u8 taskId) gSprites[task->data[15]].pos2.x = 0; if (--task->data[0]) { - PrepareAffineAnimInTaskData(&gTasks[taskId], gTasks[taskId].data[15], gUnknown_085CE87C); + PrepareAffineAnimInTaskData(&gTasks[taskId], gTasks[taskId].data[15], gSmellingSaltSquishAffineAnimCmds); task->data[1] = 0; task->data[2] = 0; } @@ -4198,17 +4194,21 @@ static void sub_815E898(u8 taskId) } } -void sub_815E954(struct Sprite *sprite) +// Blinks an exclamation image over the mon a few times. +// arg 0: which mon +// arg 1: blink delay +// arg 2: number of blinks +void AnimSmellingSaltExclamation(struct Sprite *sprite) { - if (gBattleAnimArgs[0] == 0) + if (gBattleAnimArgs[0] == ANIM_ATTACKER) { sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); - sprite->pos1.y = sub_80A861C(gBattleAnimAttacker, 2); + sprite->pos1.y = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_TOP); } else { sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimTarget, 2); - sprite->pos1.y = sub_80A861C(gBattleAnimTarget, 2); + sprite->pos1.y = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_TOP); } if (sprite->pos1.y < 8) @@ -4218,10 +4218,10 @@ void sub_815E954(struct Sprite *sprite) sprite->data[1] = gBattleAnimArgs[1]; sprite->data[2] = 0; sprite->data[3] = gBattleAnimArgs[2]; - sprite->callback = sub_815E9BC; + sprite->callback = AnimSmellingSaltExclamationStep; } -static void sub_815E9BC(struct Sprite *sprite) +static void AnimSmellingSaltExclamationStep(struct Sprite *sprite) { if (++sprite->data[0] >= sprite->data[1]) { @@ -4233,11 +4233,14 @@ static void sub_815E9BC(struct Sprite *sprite) } } -void sub_815EA14(struct Sprite *sprite) +// Claps a hand several times. +// arg 0: which hand +// arg 1: +void AnimHelpingHandClap(struct Sprite *sprite) { if (gBattleAnimArgs[0] == 0) { - sprite->oam.matrixNum |= 0x8; + sprite->oam.matrixNum |= 0x8; // horizontal flip sprite->pos1.x = 100; sprite->data[7] = 1; } @@ -4248,10 +4251,10 @@ void sub_815EA14(struct Sprite *sprite) } sprite->pos1.y = 56; - sprite->callback = sub_815EA60; + sprite->callback = AnimHelpingHandClapStep; } -static void sub_815EA60(struct Sprite *sprite) +static void AnimHelpingHandClapStep(struct Sprite *sprite) { switch (sprite->data[0]) { @@ -4334,7 +4337,9 @@ static void sub_815EA60(struct Sprite *sprite) } } -void sub_815EC48(u8 taskId) +// Repeatedly moves the attacking mon in a horizontal lunging motion. +// No args. +void AnimTask_HelpingHandAttackerMovement(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -4363,10 +4368,10 @@ void sub_815EC48(u8 taskId) task->data[14] = 1; } - task->func = sub_815ECE4; + task->func = AnimTask_HelpingHandAttackerMovementStep; } -static void sub_815ECE4(u8 taskId) +static void AnimTask_HelpingHandAttackerMovementStep(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -4448,9 +4453,11 @@ static void sub_815ECE4(u8 taskId) } } -void sub_815EE84(struct Sprite *sprite) +// Moves a magnifying glass around in straight lines. +// arg 0: magnifying glass target mon +void AnimForesightMagnifyingGlass(struct Sprite *sprite) { - if (gBattleAnimArgs[0] == 0) + if (gBattleAnimArgs[0] == ANIM_ATTACKER) { InitSpritePosToAnimAttacker(sprite, TRUE); sprite->data[7] = gBattleAnimAttacker; @@ -4461,14 +4468,14 @@ void sub_815EE84(struct Sprite *sprite) } if (GetBattlerSide(sprite->data[7]) == B_SIDE_OPPONENT) - sprite->oam.matrixNum = 8; + sprite->oam.matrixNum = 8; // horizontal flip sprite->oam.priority = GetBattlerSpriteBGPriority(sprite->data[7]); sprite->oam.objMode = ST_OAM_OBJ_BLEND; - sprite->callback = sub_815EF08; + sprite->callback = AnimForesightMagnifyingGlassStep; } -static void sub_815EF08(struct Sprite *sprite) +static void AnimForesightMagnifyingGlassStep(struct Sprite *sprite) { u16 x, y; @@ -4481,20 +4488,20 @@ static void sub_815EF08(struct Sprite *sprite) sprite->data[6] = 0; case 0: case 4: - x = sub_80A861C(sprite->data[7], 5) - 4; - y = sub_80A861C(sprite->data[7], 3) - 4; + x = GetBattlerSpriteCoordAttr(sprite->data[7], 5) - 4; + y = GetBattlerSpriteCoordAttr(sprite->data[7], 3) - 4; break; case 1: - x = sub_80A861C(sprite->data[7], 5) - 4; - y = sub_80A861C(sprite->data[7], 2) + 4; + x = GetBattlerSpriteCoordAttr(sprite->data[7], 5) - 4; + y = GetBattlerSpriteCoordAttr(sprite->data[7], 2) + 4; break; case 2: - x = sub_80A861C(sprite->data[7], 4) + 4; - y = sub_80A861C(sprite->data[7], 3) - 4; + x = GetBattlerSpriteCoordAttr(sprite->data[7], 4) + 4; + y = GetBattlerSpriteCoordAttr(sprite->data[7], 3) - 4; break; case 3: - x = sub_80A861C(sprite->data[7], 4) + 4; - y = sub_80A861C(sprite->data[7], 2) - 4; + x = GetBattlerSpriteCoordAttr(sprite->data[7], 4) + 4; + y = GetBattlerSpriteCoordAttr(sprite->data[7], 2) - 4; break; case 5: x = GetBattlerSpriteCoord(sprite->data[7], 2); @@ -4570,14 +4577,14 @@ static void sub_815EF08(struct Sprite *sprite) } } -static void sub_815F10C(struct Sprite *sprite) +static void AnimMeteorMashStarStep(struct Sprite *sprite) { sprite->pos2.x = ((sprite->data[2] - sprite->data[0]) * sprite->data[5]) / sprite->data[4]; sprite->pos2.y = ((sprite->data[3] - sprite->data[1]) * sprite->data[5]) / sprite->data[4]; if (!(sprite->data[5] & 1)) { CreateSprite( - &gUnknown_085CE3A0, + &gMiniTwinklingStarSpriteTemplate, sprite->pos1.x + sprite->pos2.x, sprite->pos1.y + sprite->pos2.y, 5); } @@ -4588,10 +4595,16 @@ static void sub_815F10C(struct Sprite *sprite) sprite->data[5]++; } -void sub_815F18C(struct Sprite *sprite) +// Moves a shooting star across the screen that leaves little twinkling stars behind its path. +// arg 0: initial x pixel offset +// arg 1: initial y pixel offset +// arg 2: destination x pixel offset +// arg 3: destination y pixel offset +// arg 4: duration +void AnimMeteorMashStar(struct Sprite *sprite) { - GetBattlerSpriteCoord(gBattleAnimTarget, 2); // unused local variable - GetBattlerSpriteCoord(gBattleAnimTarget, 3); // unused local variable + s16 y = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X_2); // unused local variable + s16 x = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y_PIC_OFFSET); // unused local variable if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER || IsContest()) { @@ -4609,13 +4622,13 @@ void sub_815F18C(struct Sprite *sprite) sprite->data[4] = gBattleAnimArgs[4]; sprite->pos1.x = sprite->data[0]; sprite->pos1.y = sprite->data[1]; - sprite->callback = sub_815F10C; + sprite->callback = AnimMeteorMashStarStep; } void AnimTask_MonToSubstitute(u8 taskId) { int i; - u8 spriteId = GetAnimBattlerSpriteId(0); + u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); if (gTasks[taskId].data[0] == 0) { @@ -4649,11 +4662,11 @@ void AnimTask_MonToSubstitute(u8 taskId) for (i = 0; i < 16; i++) gTasks[taskId].data[i] = 0; - gTasks[taskId].func = sub_815F330; + gTasks[taskId].func = AnimTask_MonToSubstituteDoll; } } -static void sub_815F330(u8 taskId) +static void AnimTask_MonToSubstituteDoll(u8 taskId) { u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); @@ -4706,27 +4719,29 @@ static void sub_815F330(u8 taskId) } } -void sub_815F48C(struct Sprite *sprite) +// Moves down an X that flickers and disappears. +// No args. +void AnimBlockX(struct Sprite *sprite) { - s16 y2; + s16 y; if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) { sprite->subpriority = GetBattlerSpriteSubpriority(gBattleAnimTarget) - 2; - y2 = -144; + y = -144; } else { sprite->subpriority = GetBattlerSpriteSubpriority(gBattleAnimTarget) + 2; - y2 = -96; + y = -96; } sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimTarget, 3); - sprite->pos2.y = y2; - sprite->callback = sub_815F4F0; + sprite->pos2.y = y; + sprite->callback = AnimBlockXStep; } -static void sub_815F4F0(struct Sprite *sprite) +static void AnimBlockXStep(struct Sprite *sprite) { switch (sprite->data[0]) { @@ -4742,7 +4757,7 @@ static void sub_815F4F0(struct Sprite *sprite) case 1: sprite->data[1] += 4; sprite->pos2.y = -(gSineTable[sprite->data[1]] >> 3); - if (sprite->data[1] > 127) + if (sprite->data[1] > 0x7F) { PlaySE12WithPanning(SE_W166, BattleAnimAdjustPanning(63)); sprite->data[1] = 0; @@ -4753,7 +4768,7 @@ static void sub_815F4F0(struct Sprite *sprite) case 2: sprite->data[1] += 6; sprite->pos2.y = -(gSineTable[sprite->data[1]] >> 4); - if (sprite->data[1] > 127) + if (sprite->data[1] > 0x7F) { sprite->data[1] = 0; sprite->pos2.y = 0; @@ -4781,7 +4796,9 @@ static void sub_815F4F0(struct Sprite *sprite) } } -void sub_815F620(u8 taskId) +// Quickly moves two clones of the target mon back and forth. +// No args. +void AnimTask_OdorSleuthMovement(u8 taskId) { s16 spriteId1, spriteId2; @@ -4837,21 +4854,20 @@ void sub_815F620(u8 taskId) gSprites[spriteId1].invisible = 1; } - gSprites[spriteId2].oam.objMode = ST_OAM_OBJ_NORMAL; gSprites[spriteId1].oam.objMode = ST_OAM_OBJ_NORMAL; - gSprites[spriteId2].callback = sub_815F7C4; - gSprites[spriteId1].callback = sub_815F7C4; - gTasks[taskId].func = sub_815F79C; + gSprites[spriteId2].callback = MoveOdorSleuthClone; + gSprites[spriteId1].callback = MoveOdorSleuthClone; + gTasks[taskId].func = AnimTask_OdorSleuthMovementWaitFinish; } -static void sub_815F79C(u8 taskId) +static void AnimTask_OdorSleuthMovementWaitFinish(u8 taskId) { if (gTasks[taskId].data[0] == 0) DestroyAnimVisualTask(taskId); } -static void sub_815F7C4(struct Sprite *sprite) +static void MoveOdorSleuthClone(struct Sprite *sprite) { int zero = 0; if (++sprite->data[1] > 1) @@ -4902,3 +4918,477 @@ void AnimTask_GetReturnPowerLevel(u8 taskId) DestroyAnimVisualTask(taskId); } + +// Makes the mon run out of screen, run past the opposing mon, and return to its original position. +// No args. +void AnimTask_SnatchOpposingMonMove(u8 taskId) +{ + u8 spriteId, spriteId2; + int personality; + int otId; + u16 species; + u8 subpriority; + u8 isBackPic; + s16 x; + + switch (gTasks[taskId].data[0]) + { + case 0: + spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + gTasks[taskId].data[1] += 0x800; + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + gSprites[spriteId].pos2.x += (gTasks[taskId].data[1] >> 8); + else + gSprites[spriteId].pos2.x -= (gTasks[taskId].data[1] >> 8); + + gTasks[taskId].data[1] &= 0xFF; + x = gSprites[spriteId].pos1.x + gSprites[spriteId].pos2.x; + if ((u16)(x + 32) > 304) + { + gTasks[taskId].data[1] = 0; + gTasks[taskId].data[0]++; + } + break; + case 1: + if (IsContest()) + { + personality = gContestResources->field_18->unk8; + otId = gContestResources->field_18->unkC; + species = gContestResources->field_18->species; + subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker); + isBackPic = 0; + x = -32; + } + else + { + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + { + personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); + otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) + species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + else + species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; + + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; + isBackPic = 0; + x = 272; + } + else + { + personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); + otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) + species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + else + species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; + + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; + isBackPic = 1; + x = -32; + } + } + + spriteId2 = sub_80A8394(species, isBackPic, 0, x, GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y), subpriority, personality, otId, gBattleAnimAttacker, 0); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies != SPECIES_NONE) + BlendPalette((gSprites[spriteId2].oam.paletteNum * 16) | 0x100, 16, 6, RGB_WHITE); + + gTasks[taskId].data[15] = spriteId2; + gTasks[taskId].data[0]++; + break; + case 2: + spriteId2 = gTasks[taskId].data[15]; + gTasks[taskId].data[1] += 0x800; + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + gSprites[spriteId2].pos2.x -= (gTasks[taskId].data[1] >> 8); + else + gSprites[spriteId2].pos2.x += (gTasks[taskId].data[1] >> 8); + + gTasks[taskId].data[1] &= 0xFF; + x = gSprites[spriteId2].pos1.x + gSprites[spriteId2].pos2.x; + if (gTasks[taskId].data[14] == 0) + { + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + { + if (x < GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) + { + gTasks[taskId].data[14]++; + gBattleAnimArgs[7] = 0xFFFF; + } + } + else + { + if (x > GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) + { + gTasks[taskId].data[14]++; + gBattleAnimArgs[7] = 0xFFFF; + } + } + } + + if ((u16)(x + 32) > 304) + { + gTasks[taskId].data[1] = 0; + gTasks[taskId].data[0]++; + } + break; + case 3: + spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + spriteId2 = gTasks[taskId].data[15]; + DestroySpriteAndFreeResources_(&gSprites[spriteId2]); + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + gSprites[spriteId].pos2.x = -gSprites[spriteId].pos1.x - 32; + else + gSprites[spriteId].pos2.x = 272 - gSprites[spriteId].pos1.x; + + gTasks[taskId].data[0]++; + break; + case 4: + spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + gTasks[taskId].data[1] += 0x800; + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + { + gSprites[spriteId].pos2.x += (gTasks[taskId].data[1] >> 8); + if (gSprites[spriteId].pos2.x + gSprites[spriteId].pos1.x >= GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X)) + gSprites[spriteId].pos2.x = 0; + } + else + { + gSprites[spriteId].pos2.x -= (gTasks[taskId].data[1] >> 8); + if (gSprites[spriteId].pos2.x + gSprites[spriteId].pos1.x <= GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X)) + gSprites[spriteId].pos2.x = 0; + } + + gTasks[taskId].data[1] = (u8)gTasks[taskId].data[1]; + if (gSprites[spriteId].pos2.x == 0) + DestroyAnimVisualTask(taskId); + break; + } +} + +void sub_815FE80(struct Sprite *sprite) +{ + switch (sprite->data[7]) + { + case 0: + if (gBattleAnimArgs[7] == -1) + { + PlaySE12WithPanning(SE_W233, BattleAnimAdjustPanning(63)); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y) + 16; + sprite->data[0] = -32; + sprite->data[7]++; + sprite->invisible = 0; + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_OPPONENT && !IsContest()) + sprite->subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; + } + else + { + sprite->invisible = 1; + } + break; + case 1: + sprite->pos2.y = Sin(sprite->data[1], sprite->data[0]); + sprite->data[1] += 5; + if (sprite->data[1] > 0x7F) + { + sprite->data[0] = sprite->data[0] / 2; + sprite->data[3]++; + sprite->data[1] -= 0x7F; + } + + sprite->data[2] += 0x100; + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + sprite->pos2.x -= (sprite->data[2] >> 8); + else + sprite->pos2.x += (sprite->data[2] >> 8); + + sprite->data[2] &= 0xFF; + if (sprite->data[3] == 2) + DestroyAnimSprite(sprite); + break; + } +} + +// Quickly moves the mon towards its partner and back. +// No args. +void AnimTask_SnatchPartnerMove(u8 taskId) +{ + s16 attackerX, targetX; + u8 spriteId; + + switch (gTasks[taskId].data[15]) + { + case 0: + attackerX = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X); + targetX = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X); + gTasks[taskId].data[0] = 6; + if (attackerX > targetX) + gTasks[taskId].data[0] *= -1; + + gTasks[taskId].data[1] = attackerX; + gTasks[taskId].data[2] = targetX; + gTasks[taskId].data[15]++; + break; + case 1: + spriteId = gBattlerSpriteIds[gBattleAnimAttacker]; + gSprites[spriteId].pos2.x += gTasks[taskId].data[0]; + if (gTasks[taskId].data[0] > 0) + { + if (gSprites[spriteId].pos1.x + gSprites[spriteId].pos2.x >= gTasks[taskId].data[2]) + gTasks[taskId].data[15]++; + } + else + { + if (gSprites[spriteId].pos1.x + gSprites[spriteId].pos2.x <= gTasks[taskId].data[2]) + gTasks[taskId].data[15]++; + } + break; + case 2: + gTasks[taskId].data[0] *= -1; + gTasks[taskId].data[15]++; + break; + case 3: + spriteId = gBattlerSpriteIds[gBattleAnimAttacker]; + gSprites[spriteId].pos2.x += gTasks[taskId].data[0]; + if (gTasks[taskId].data[0] < 0) + { + if (gSprites[spriteId].pos1.x + gSprites[spriteId].pos2.x <= gTasks[taskId].data[1]) + gTasks[taskId].data[15]++; + } + else + { + if (gSprites[spriteId].pos1.x + gSprites[spriteId].pos2.x >= gTasks[taskId].data[1]) + gTasks[taskId].data[15]++; + } + break; + case 4: + default: + spriteId = gBattlerSpriteIds[gBattleAnimAttacker]; + gSprites[spriteId].pos2.x = 0; + DestroyAnimVisualTask(taskId); + break; + } +} + +// Moves the mon's sprite back and forth in an unpredictable swaying motion. +// No args. +void AnimTask_TeeterDanceMovement(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + task->data[3] = GetAnimBattlerSpriteId(ANIM_ATTACKER); + task->data[4] = GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER ? 1 : -1; + task->data[6] = gSprites[task->data[3]].pos1.y; + task->data[5] = gSprites[task->data[3]].pos1.x; + task->data[9] = 0; + task->data[11] = 0; + task->data[10] = 1; + task->data[12] = 0; + task->func = AnimTask_TeeterDanceMovementStep; +} + +static void AnimTask_TeeterDanceMovementStep(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + switch (task->data[0]) + { + case 0: + task->data[11] += 8; + task->data[11] &= 0xFF; + gSprites[task->data[3]].pos2.x = gSineTable[task->data[11]] >> 5; + task->data[9] += 2; + task->data[9] &= 0xFF; + gSprites[task->data[3]].pos1.x = (gSineTable[task->data[9]] >> 3) * task->data[4] + task->data[5]; + if (task->data[9] == 0) + { + gSprites[task->data[3]].pos1.x = task->data[5]; + task->data[0]++; + } + break; + case 1: + task->data[11] += 8; + task->data[11] &= 0xFF; + gSprites[task->data[3]].pos2.x = gSineTable[task->data[11]] >> 5; + if (task->data[11] == 0) + { + gSprites[task->data[3]].pos2.x = 0; + task->data[0]++; + } + break; + case 2: + DestroyAnimVisualTask(taskId); + break; + } +} + +static void AnimKnockOffStrikeStep(struct Sprite *sprite) +{ + // These two cases are identical. + if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) + { + sprite->data[1] += sprite->data[0]; + sprite->data[1] &= 0xFF; + } + else + { + sprite->data[1] += sprite->data[0]; + sprite->data[1] &= 0xFF; + } + + sprite->pos2.x = Cos(sprite->data[1], 20); + sprite->pos2.y = Sin(sprite->data[1], 20); + if (sprite->animEnded) + DestroyAnimSprite(sprite); + + sprite->data[2]++; +} + +// Animates a strike that swipes downard at the target mon. +// arg 0: initial x pixel offset +// arg 1: initial y pixel offset +void AnimKnockOffStrike(struct Sprite *sprite) +{ + if (GetBattlerSide(gBattleAnimTarget) == B_SIDE_PLAYER) + { + sprite->pos1.x -= gBattleAnimArgs[0]; + sprite->pos1.y += gBattleAnimArgs[1]; + sprite->data[0] = -11; + sprite->data[1] = 192; + StartSpriteAffineAnim(sprite, 1); + } + else + { + sprite->data[0] = 11; + sprite->data[1] = 192; + sprite->pos1.x += gBattleAnimArgs[0]; + sprite->pos1.y += gBattleAnimArgs[1]; + } + + sprite->callback = AnimKnockOffStrikeStep; +} + +// Gradually fades a rotating recyle arrow sprite in and back out. +// No args. +void AnimRecycle(struct Sprite *sprite) +{ + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2); + sprite->pos1.y = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_TOP); + if (sprite->pos1.y < 16) + sprite->pos1.y = 16; + + sprite->data[6] = 0; + sprite->data[7] = 16; + sprite->callback = AnimRecycleStep; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(sprite->data[6], sprite->data[7])); +} + +static void AnimRecycleStep(struct Sprite *sprite) +{ + switch (sprite->data[2]) + { + case 0: + if (++sprite->data[0] > 1) + { + sprite->data[0] = 0; + if (!(sprite->data[1] & 1)) + { + if (sprite->data[6] < 16) + sprite->data[6]++; + } + else + { + if (sprite->data[7] != 0) + sprite->data[7]--; + } + + sprite->data[1]++; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(sprite->data[6], sprite->data[7])); + if (sprite->data[7] == 0) + sprite->data[2]++; + } + break; + case 1: + if (++sprite->data[0] == 10) + { + sprite->data[0] = 0; + sprite->data[1] = 0; + sprite->data[2]++; + } + break; + case 2: + if (++sprite->data[0] > 1) + { + sprite->data[0] = 0; + if (!(sprite->data[1] & 1)) + { + if (sprite->data[6] != 0) + sprite->data[6]--; + } + else + { + if (sprite->data[7] < 16) + sprite->data[7]++; + } + + sprite->data[1]++; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(sprite->data[6], sprite->data[7])); + if (sprite->data[7] == 16) + sprite->data[2]++; + } + break; + case 3: + DestroySpriteAndMatrix(sprite); + break; + } +} + +void AnimTask_GetWeather(u8 taskId) +{ + gBattleAnimArgs[7] = ANIM_WEATHER_NONE; + if (gWeatherMoveAnim & WEATHER_SUN_ANY) + gBattleAnimArgs[7] = ANIM_WEATHER_SUN; + else if (gWeatherMoveAnim & WEATHER_RAIN_ANY) + gBattleAnimArgs[7] = ANIM_WEATHER_RAIN; + else if (gWeatherMoveAnim & WEATHER_SANDSTORM_ANY) + gBattleAnimArgs[7] = ANIM_WEATHER_SANDSTORM; + else if (gWeatherMoveAnim & WEATHER_HAIL_ANY) + gBattleAnimArgs[7] = ANIM_WEATHER_HAIL; + + DestroyAnimVisualTask(taskId); +} + +// Squishes the mon sprite vertically, and shakes it back and forth. +// arg 0: which battler +void AnimTask_SlackOffSquish(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + task->data[0] = 0; + task->data[15] = GetAnimBattlerSpriteId(gBattleAnimArgs[0]); + PrepareAffineAnimInTaskData(task, task->data[15], gSlackOffSquishAffineAnimCmds); + task->func = AnimTask_SlackOffSquishStep; +} + +static void AnimTask_SlackOffSquishStep(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + + gTasks[taskId].data[0]++; + if (gTasks[taskId].data[0] > 16 && gTasks[taskId].data[0] < 40) + { + if (++task->data[1] > 2) + { + task->data[1] = 0; + task->data[2]++; + if (!(task->data[2] & 1)) + gSprites[task->data[15]].pos2.x = -1; + else + gSprites[task->data[15]].pos2.x = 1; + } + } + else + { + gSprites[task->data[15]].pos2.x = 0; + } + + if (!RunAffineAnimFromTaskData(&gTasks[taskId])) + DestroyAnimVisualTask(taskId); +} diff --git a/src/battle_arena.c b/src/battle_arena.c index 39bb6936d..cfcb10a0d 100644 --- a/src/battle_arena.c +++ b/src/battle_arena.c @@ -782,7 +782,7 @@ static void sub_81A58B4(void) if (!isCurrent) gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode] = 0; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); gTrainerBattleOpponent_A = 0; } diff --git a/src/battle_bg.c b/src/battle_bg.c index a6919be1d..a072a2cda 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -1092,7 +1092,7 @@ void DrawBattleEntryBackground(void) LZDecompressVram(gUnknown_08D778F0, (void*)(VRAM + 0x4000)); LZDecompressVram(gUnknown_08D77B0C, (void*)(VRAM + 0x10000)); LoadCompressedPalette(gUnknown_08D77AE4, 0x60, 0x20); - SetBgAttribute(1, BG_CTRL_ATTR_MAPBASEINDEX, 1); + SetBgAttribute(1, BG_ATTR_SCREENSIZE, 1); SetGpuReg(REG_OFFSET_BG1CNT, 0x5C04); CopyToBgTilemapBuffer(1, gUnknown_08D779D8, 0, 0); CopyToBgTilemapBuffer(2, gUnknown_08D779D8, 0, 0); @@ -1113,8 +1113,8 @@ void DrawBattleEntryBackground(void) } else { - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 2); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 2); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 2); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 2); CopyToBgTilemapBuffer(1, gUnknown_08D857A8, 0, 0); CopyToBgTilemapBuffer(2, gUnknown_08D85A1C, 0, 0); CopyBgTilemapBufferToVram(1); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 85756309d..33f557388 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -581,7 +581,7 @@ static u32 CopyLinkOpponentMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); @@ -628,7 +628,7 @@ static u32 CopyLinkOpponentMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); @@ -648,7 +648,7 @@ static u32 CopyLinkOpponentMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP_BONUSES); size++; @@ -913,7 +913,7 @@ static void SetLinkOpponentMonData(u8 monId) SetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gEnemyParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -952,7 +952,7 @@ static void SetLinkOpponentMonData(u8 monId) SetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gEnemyParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index ef18c14aa..78c2c409d 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -466,7 +466,7 @@ static u32 CopyLinkPartnerMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -513,7 +513,7 @@ static u32 CopyLinkPartnerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -533,7 +533,7 @@ static u32 CopyLinkPartnerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP_BONUSES); size++; @@ -798,7 +798,7 @@ static void SetLinkPartnerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -837,7 +837,7 @@ static void SetLinkPartnerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 30aa3217b..4e600ea71 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -564,7 +564,7 @@ static u32 GetOpponentMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); @@ -611,7 +611,7 @@ static u32 GetOpponentMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); @@ -631,7 +631,7 @@ static u32 GetOpponentMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP_BONUSES); size++; @@ -905,7 +905,7 @@ static void SetOpponentMonData(u8 monId) SetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gEnemyParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -944,7 +944,7 @@ static void SetOpponentMonData(u8 monId) SetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gEnemyParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index a007c7b30..12ffca381 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -403,7 +403,7 @@ static void HandleInputChooseTarget(void) do { if (--i < 0) - i = 4; // UB: array out of range + i = MAX_BATTLERS_COUNT; // UB: array out of range gMultiUsePlayerCursor = GetBattlerAtPosition(identities[i]); } while (gMultiUsePlayerCursor == gBattlersCount); @@ -704,7 +704,7 @@ static void HandleMoveSwitching(void) MoveSelectionDisplayMoveNames(); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) perMovePPBonuses[i] = (gBattleMons[gActiveBattler].ppBonuses & (3 << (i * 2))) >> (i * 2); totalPPBonuses = perMovePPBonuses[gMoveSelectionCursor[gActiveBattler]]; @@ -712,12 +712,12 @@ static void HandleMoveSwitching(void) perMovePPBonuses[gMultiUsePlayerCursor] = totalPPBonuses; totalPPBonuses = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) totalPPBonuses |= perMovePPBonuses[i] << (i * 2); gBattleMons[gActiveBattler].ppBonuses = totalPPBonuses; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { gBattleMons[gActiveBattler].moves[i] = moveInfo->moves[i]; gBattleMons[gActiveBattler].pp[i] = moveInfo->currentPp[i]; @@ -725,14 +725,14 @@ static void HandleMoveSwitching(void) if (!(gBattleMons[gActiveBattler].status2 & STATUS2_TRANSFORMED)) { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { moveStruct.moves[i] = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_MOVE1 + i); moveStruct.currentPp[i] = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_PP1 + i); } totalPPBonuses = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_PP_BONUSES); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) perMovePPBonuses[i] = (totalPPBonuses & (3 << (i * 2))) >> (i * 2); i = moveStruct.moves[gMoveSelectionCursor[gActiveBattler]]; @@ -748,10 +748,10 @@ static void HandleMoveSwitching(void) perMovePPBonuses[gMultiUsePlayerCursor] = totalPPBonuses; totalPPBonuses = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) totalPPBonuses |= perMovePPBonuses[i] << (i * 2); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_MOVE1 + i, &moveStruct.moves[i]); SetMonData(&gPlayerParty[gBattlerPartyIndexes[gActiveBattler]], MON_DATA_PP1 + i, &moveStruct.currentPp[i]); @@ -1446,7 +1446,7 @@ static void MoveSelectionDisplayMoveNames(void) struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleBufferA[gActiveBattler][4]); gNumberOfMovesToChoose = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { MoveSelectionDestroyCursorAt(i); StringCopy(gDisplayedStringBattle, gMoveNames[moveInfo->moves[i]]); @@ -1609,7 +1609,7 @@ static u32 CopyPlayerMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -1656,7 +1656,7 @@ static u32 CopyPlayerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -1676,7 +1676,7 @@ static u32 CopyPlayerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP_BONUSES); size++; @@ -1950,7 +1950,7 @@ static void SetPlayerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -1989,7 +1989,7 @@ static void SetPlayerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index 22018add4..ddb241b30 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -653,7 +653,7 @@ static u32 CopyPlayerPartnerMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -700,7 +700,7 @@ static u32 CopyPlayerPartnerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -720,7 +720,7 @@ static u32 CopyPlayerPartnerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP_BONUSES); size++; @@ -985,7 +985,7 @@ static void SetPlayerPartnerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -1024,7 +1024,7 @@ static void SetPlayerPartnerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 1cf780264..b1b271bac 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -564,7 +564,7 @@ static u32 CopyRecordedOpponentMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gEnemyParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); @@ -611,7 +611,7 @@ static u32 CopyRecordedOpponentMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); @@ -631,7 +631,7 @@ static u32 CopyRecordedOpponentMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gEnemyParty[monId], MON_DATA_PP_BONUSES); size++; @@ -896,7 +896,7 @@ static void SetRecordedOpponentMonData(u8 monId) SetMonData(&gEnemyParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gEnemyParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -935,7 +935,7 @@ static void SetRecordedOpponentMonData(u8 monId) SetMonData(&gEnemyParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gEnemyParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gEnemyParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index a788d6be3..301c1f009 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -547,7 +547,7 @@ static u32 CopyRecordedPlayerMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -594,7 +594,7 @@ static u32 CopyRecordedPlayerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -614,7 +614,7 @@ static u32 CopyRecordedPlayerMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP_BONUSES); size++; @@ -879,7 +879,7 @@ static void SetRecordedPlayerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -918,7 +918,7 @@ static void SetRecordedPlayerMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index c0b496e47..ac3604054 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -463,7 +463,7 @@ static u32 CopyWallyMonData(u8 monId, u8 *dst) case REQUEST_ALL_BATTLE: battleMon.species = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES); battleMon.item = GetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM); - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { battleMon.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); battleMon.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -510,7 +510,7 @@ static u32 CopyWallyMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_MOVES_PP_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) { moveData.moves[size] = GetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + size); moveData.pp[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); @@ -530,7 +530,7 @@ static u32 CopyWallyMonData(u8 monId, u8 *dst) size = 2; break; case REQUEST_PP_DATA_BATTLE: - for (size = 0; size < 4; size++) + for (size = 0; size < MAX_MON_MOVES; size++) dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP1 + size); dst[size] = GetMonData(&gPlayerParty[monId], MON_DATA_PP_BONUSES); size++; @@ -795,7 +795,7 @@ static void SetWallyMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_SPECIES, &battlePokemon->species); SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &battlePokemon->item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &battlePokemon->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &battlePokemon->pp[i]); @@ -834,7 +834,7 @@ static void SetWallyMonData(u8 monId) SetMonData(&gPlayerParty[monId], MON_DATA_HELD_ITEM, &gBattleBufferA[gActiveBattler][3]); break; case REQUEST_MOVES_PP_BATTLE: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(&gPlayerParty[monId], MON_DATA_MOVE1 + i, &moveData->moves[i]); SetMonData(&gPlayerParty[monId], MON_DATA_PP1 + i, &moveData->pp[i]); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 385c971b0..70a53f332 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -142,7 +142,7 @@ static void InitSinglePlayerBtlControllers(void) gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT; } - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; sub_81B8D64(0, 0); sub_81B8D64(1, 0); @@ -225,7 +225,7 @@ static void InitSinglePlayerBtlControllers(void) gBattlerControllerFuncs[3] = SetControllerToOpponent; gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT; - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { @@ -245,7 +245,7 @@ static void InitSinglePlayerBtlControllers(void) gBattlerControllerFuncs[3] = SetControllerToOpponent; gBattlerPositions[3] = 3; - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; sub_81B8D64(0, 0); sub_81B8D64(1, 0); @@ -431,7 +431,7 @@ static void InitLinkBtlControllers(void) gBattlerControllerFuncs[3] = SetControllerToLinkOpponent; gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT; - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; } else { @@ -447,7 +447,7 @@ static void InitLinkBtlControllers(void) gBattlerControllerFuncs[2] = SetControllerToLinkOpponent; gBattlerPositions[2] = B_POSITION_OPPONENT_RIGHT; - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; } } else if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) @@ -468,7 +468,7 @@ static void InitLinkBtlControllers(void) gBattlerControllerFuncs[3] = SetControllerToOpponent; gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT; - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; } else { @@ -484,7 +484,7 @@ static void InitLinkBtlControllers(void) gBattlerControllerFuncs[3] = SetControllerToLinkOpponent; gBattlerPositions[3] = B_POSITION_OPPONENT_RIGHT; - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; } sub_81B8D64(0, 0); @@ -574,7 +574,7 @@ static void InitLinkBtlControllers(void) } } - gBattlersCount = 4; + gBattlersCount = MAX_BATTLERS_COUNT; } } diff --git a/src/battle_dome.c b/src/battle_dome.c index 24e2cbfed..00ae84d09 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -2388,7 +2388,7 @@ static void sub_818E9CC(void) if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_0860D0EC[battleMode][lvlMode])) gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode] = 0; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); gTrainerBattleOpponent_A = 0; } @@ -2554,7 +2554,7 @@ static void InitDomeTrainers(void) for (i = 0; i < 3; i++) { gSaveBlock2Ptr->frontier.domeMonIds[0][i] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_SPECIES, NULL); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) gSaveBlock2Ptr->frontier.field_EFC[i].moves[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_MOVE1 + j, NULL); for (j = 0; j < 6; j++) gSaveBlock2Ptr->frontier.field_EFC[i].evs[j] = GetMonData(&gPlayerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_HP_EV + j, NULL); @@ -2814,7 +2814,7 @@ static void CreateDomeMon(u8 monPartyId, u16 tournamentTrainerId, u8 tournamentM gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonIds[tournamentTrainerId][tournamentMonId]].evSpread, otId); happiness = 0xFF; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonMoveSlot(&gEnemyParty[monPartyId], gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonIds[tournamentTrainerId][tournamentMonId]].moves[i], i); @@ -2889,7 +2889,7 @@ static s32 sub_818FCBC(u16 tournamentTrainerId, bool8 arg1) for (i = 0; i < 3; i++) { array[i] = 0; - for (moveId = 0; moveId < 4; moveId++) + for (moveId = 0; moveId < MAX_MON_MOVES; moveId++) { for (playerMonId = 0; playerMonId < 3; playerMonId++) { @@ -2917,7 +2917,7 @@ static s32 sub_818FDB8(u16 tournamentTrainerId, bool8 arg1) for (i = 0; i < 3; i++) { array[i] = 0; - for (moveId = 0; moveId < 4; moveId++) + for (moveId = 0; moveId < MAX_MON_MOVES; moveId++) { for (playerMonId = 0; playerMonId < 3; playerMonId++) { @@ -4848,7 +4848,7 @@ static void DisplayTrainerInfoOnCard(u8 flags, u8 trainerTournamentId) for (i = 0; i < 3; i++) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { for (k = 0; k < DOME_TOURNAMENT_TRAINERS_COUNT; k++) { @@ -5538,8 +5538,9 @@ static u16 GetWinningMove(s32 winnerTournamentId, s32 loserTournamentId, u8 roun // Calc move points of all 4 moves for all 3 pokemon hitting all 3 target mons. for (i = 0; i < 3; i++) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { + // TODO: Clean this up, looks like a different data structure moveScores[i * 4 + j] = 0; if (gSaveBlock2Ptr->frontier.domeTrainers[winnerTournamentId].trainerId == TRAINER_FRONTIER_BRAIN) moveIds[i * 4 + j] = GetFrontierBrainMonMove(i, j); @@ -5600,7 +5601,7 @@ static u16 GetWinningMove(s32 winnerTournamentId, s32 loserTournamentId, u8 roun goto LABEL; while (j != 0) { - for (j = 0, k = 0; k < 4 * 3; k++) + for (j = 0, k = 0; k < MAX_MON_MOVES * 3; k++) { if (bestScore < moveScores[k]) { @@ -5627,7 +5628,7 @@ static u16 GetWinningMove(s32 winnerTournamentId, s32 loserTournamentId, u8 roun moveScores[j] = 0; bestScore = 0; j = 0; - for (k = 0; k < 4 * 3; k++) + for (k = 0; k < MAX_MON_MOVES * 3; k++) j += moveScores[k]; } } @@ -6059,16 +6060,16 @@ static void sub_8194D68(void) s32 playerMonId = gSaveBlock2Ptr->frontier.selectedPartyMons[gSelectedOrderFromParty[i] - 1] - 1; s32 count; - for (moveSlot = 0; moveSlot < 4; moveSlot++) + for (moveSlot = 0; moveSlot < MAX_MON_MOVES; moveSlot++) { count = 0; - while (count < 4) + while (count < MAX_MON_MOVES) { if (GetMonData(&gSaveBlock1Ptr->playerParty[playerMonId], MON_DATA_MOVE1 + count, NULL) == GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + moveSlot, NULL)) break; count++; } - if (count == 4) + if (count == MAX_MON_MOVES) SetMonMoveSlot(&gPlayerParty[i], MOVE_SKETCH, moveSlot); } @@ -6321,7 +6322,7 @@ static void DecideRoundWinners(u8 roundId) // Calculate points for both trainers. for (monId1 = 0; monId1 < 3; monId1++) { - for (moveSlot = 0; moveSlot < 4; moveSlot++) + for (moveSlot = 0; moveSlot < MAX_MON_MOVES; moveSlot++) { for (monId2 = 0; monId2 < 3; monId2++) { @@ -6344,7 +6345,7 @@ static void DecideRoundWinners(u8 roundId) for (monId1 = 0; monId1 < 3; monId1++) { - for (moveSlot = 0; moveSlot < 4; moveSlot++) + for (moveSlot = 0; moveSlot < MAX_MON_MOVES; moveSlot++) { for (monId2 = 0; monId2 < 3; monId2++) { diff --git a/src/battle_factory.c b/src/battle_factory.c index 801b33ba7..0445d5dea 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -1,4 +1,5 @@ #include "global.h" +#include "battle.h" #include "battle_factory.h" #include "battle_factory_screen.h" #include "event_data.h" @@ -201,7 +202,7 @@ static void sub_81A5E94(void) for (i = 0; i < 3; i++) gUnknown_03006298[i] |= 0xFFFF; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); gTrainerBattleOpponent_A = 0; } @@ -433,7 +434,7 @@ static void sub_81A64C4(void) CalculateMonStats(&gPlayerParty[i]); friendship = 0; - for (k = 0; k < 4; k++) + for (k = 0; k < MAX_MON_MOVES; k++) SetMonMoveAvoidReturn(&gPlayerParty[i], gFacilityTrainerMons[monSetId].moves[k], k); SetMonData(&gPlayerParty[i], MON_DATA_FRIENDSHIP, &friendship); SetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); @@ -473,7 +474,7 @@ static void sub_81A64C4(void) } CalculateMonStats(&gEnemyParty[i]); - for (k = 0; k < 4; k++) + for (k = 0; k < MAX_MON_MOVES; k++) SetMonMoveAvoidReturn(&gEnemyParty[i], gFacilityTrainerMons[monSetId].moves[k], k); SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); SetMonData(&gEnemyParty[i], MON_DATA_ALT_ABILITY, &gSaveBlock2Ptr->frontier.field_E70[i + 3].abilityBit); @@ -623,7 +624,7 @@ static void sub_81A6AEC(void) for (i = 0; i < 3; i++) { u16 monSetId = gUnknown_03006298[i]; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { u8 id = GetStyleForMove(gFacilityTrainerMons[monSetId].moves[j]); stylePoints[id]++; @@ -756,7 +757,7 @@ void FillFactoryBrainParty(void) otId); friendship = 0; - for (k = 0; k < 4; k++) + for (k = 0; k < MAX_MON_MOVES; k++) SetMonMoveAvoidReturn(&gEnemyParty[i], gFacilityTrainerMons[monSetId].moves[k], k); SetMonData(&gEnemyParty[i], MON_DATA_FRIENDSHIP, &friendship); SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index 2571e7a92..7831ef750 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -1,4 +1,5 @@ #include "global.h" +#include "battle.h" #include "battle_factory_screen.h" #include "battle_factory.h" #include "sprite.h" @@ -1691,7 +1692,7 @@ static void CreateFrontierFactorySelectableMons(u8 firstMonId) gFacilityTrainerMons[monSetId].evSpread, otId); happiness = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) SetMonMoveAvoidReturn(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].moves[j], j); SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); @@ -1721,7 +1722,7 @@ static void CreateTentFactorySelectableMons(u8 firstMonId) gFacilityTrainerMons[monSetId].evSpread, otId); happiness = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) SetMonMoveAvoidReturn(&sFactorySelectScreen->mons[i + firstMonId].monData, gFacilityTrainerMons[monSetId].moves[j], j); SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_FRIENDSHIP, &happiness); SetMonData(&sFactorySelectScreen->mons[i + firstMonId].monData, MON_DATA_HELD_ITEM, &gBattleFrontierHeldItems[gFacilityTrainerMons[monSetId].itemTableId]); diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index 3654cf6d4..3ceaef983 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -138,7 +138,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) if (i == var1) percent = 2; - for (var2 = 0, i = 0; i < 4; i++) + for (var2 = 0, i = 0; i < MAX_MON_MOVES; i++) { if (moveInfo->moves[i] == MOVE_NONE) break; @@ -160,7 +160,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) { var1 = 0, var2 = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (sub_805D4A8(moveInfo->moves[i]) == 0 && !(gBitTable[i] & unusableMovesBits)) var1 += 0x1; @@ -181,7 +181,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) { do { - i = Random() % 4; + i = Random() % MAX_MON_MOVES; if (!(gBitTable[i] & unusableMovesBits)) chosenMoveId = i; } while (chosenMoveId == -1); @@ -197,7 +197,7 @@ u16 ChooseMoveAndTargetInBattlePalace(void) do { - i = Random() % 4; + i = Random() % MAX_MON_MOVES; if (!(gBitTable[i] & unusableMovesBits) && var2 == sub_805D4A8(moveInfo->moves[i])) chosenMoveId = i; } while (chosenMoveId == -1); @@ -682,7 +682,7 @@ void BattleLoadAllHealthBoxesGfxAtOnce(void) LoadCompressedSpriteSheet(&sSpriteSheets_DoublesPlayerHealthbox[1]); LoadCompressedSpriteSheet(&sSpriteSheets_DoublesOpponentHealthbox[0]); LoadCompressedSpriteSheet(&sSpriteSheets_DoublesOpponentHealthbox[1]); - numberOfBattlers = 4; + numberOfBattlers = MAX_BATTLERS_COUNT; } for (i = 0; i < numberOfBattlers; i++) LoadCompressedSpriteSheet(&sSpriteSheets_HealthBar[gBattlerPositions[i]]); diff --git a/src/battle_interface.c b/src/battle_interface.c index 4a8422091..0eb494db4 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1753,7 +1753,7 @@ static void sub_8073E08(u8 taskId) if (--gTasks[taskId].tData15 < 0) return; - SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].data[15]) | ((16 - gTasks[taskId].data[15]) << 8)); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[15], 16 - gTasks[taskId].data[15])); } if (gTasks[taskId].tData15 == 0) gTasks[taskId].func = sub_8073E64; @@ -1806,7 +1806,7 @@ static void sub_8073F98(u8 taskId) if (--gTasks[taskId].tData15 >= 0) { - SetGpuReg(REG_OFFSET_BLDALPHA, (gTasks[taskId].tData15) | ((16 - gTasks[taskId].tData15) << 8)); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gTasks[taskId].data[15], 16 - gTasks[taskId].data[15])); } else if (gTasks[taskId].tData15 == -1) { diff --git a/src/battle_intro.c b/src/battle_intro.c index 736e35a87..21e83ed29 100644 --- a/src/battle_intro.c +++ b/src/battle_intro.c @@ -221,8 +221,8 @@ static void BattleIntroSlide1(u8 taskId) gScanlineEffect.state = 3; gTasks[taskId].data[0]++; CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -330,8 +330,8 @@ static void BattleIntroSlide2(u8 taskId) gScanlineEffect.state = 3; gTasks[taskId].data[0]++; CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -418,8 +418,8 @@ static void BattleIntroSlide3(u8 taskId) gScanlineEffect.state = 3; gTasks[taskId].data[0]++; CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -499,8 +499,8 @@ static void BattleIntroSlideLink(u8 taskId) { gScanlineEffect.state = 3; gTasks[taskId].data[0]++; - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); } @@ -567,8 +567,8 @@ static void BattleIntroSlidePartner(u8 taskId) { CpuFill32(0, (void *)BG_SCREEN_ADDR(28), BG_SCREEN_SIZE * 4); SetGpuReg(REG_OFFSET_DISPCNT, GetGpuReg(REG_OFFSET_DISPCNT) & ~DISPCNT_WIN1_ON); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); SetGpuReg(REG_OFFSET_BG1CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(28) | BGCNT_TXT256x512); SetGpuReg(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_16COLOR | BGCNT_SCREENBASE(30) | BGCNT_TXT512x256); gScanlineEffect.state = 3; diff --git a/src/battle_main.c b/src/battle_main.c index 150c563e2..df1828d18 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2005,7 +2005,7 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir fixedIV = partyData[i].iv * 31 / 255; CreateMon(&party[i], partyData[i].species, partyData[i].lvl, fixedIV, TRUE, personalityValue, 2, 0); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonData(&party[i], MON_DATA_MOVE1 + j, &partyData[i].moves[j]); SetMonData(&party[i], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); @@ -2039,7 +2039,7 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir SetMonData(&party[i], MON_DATA_HELD_ITEM, &partyData[i].heldItem); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonData(&party[i], MON_DATA_MOVE1 + j, &partyData[i].moves[j]); SetMonData(&party[i], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); diff --git a/src/battle_message.c b/src/battle_message.c index f283d959c..112ab9630 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2857,7 +2857,7 @@ static void ChooseMoveUsedParticle(u8* textBuff) s32 counter = 0; u32 i = 0; - while (counter != 4) + while (counter != MAX_MON_MOVES) { if (sGrammarMoveUsedTable[i] == 0) counter++; @@ -2869,7 +2869,7 @@ static void ChooseMoveUsedParticle(u8* textBuff) { if (counter <= 2) StringCopy(textBuff, sText_SpaceIs); // is - else if (counter <= 4) + else if (counter <= MAX_MON_MOVES) StringCopy(textBuff, sText_ApostropheS); // 's } } @@ -2900,7 +2900,7 @@ static void ChooseTypeOfMoveUsedString(u8* dst) while (*dst != EOS) dst++; - while (counter != 4) + while (counter != MAX_MON_MOVES) { if (sGrammarMoveUsedTable[i] == MOVE_NONE) counter++; diff --git a/src/battle_palace.c b/src/battle_palace.c index 4033712b6..fb8cc0729 100644 --- a/src/battle_palace.c +++ b/src/battle_palace.c @@ -69,7 +69,7 @@ static void sub_8195980(void) if (!(gSaveBlock2Ptr->frontier.field_CDC & gUnknown_0860DE98[battleMode][lvlMode])) gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode] = 0; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); gTrainerBattleOpponent_A = 0; } diff --git a/src/battle_pike.c b/src/battle_pike.c index 303146f6a..a4b429bd5 100644 --- a/src/battle_pike.c +++ b/src/battle_pike.c @@ -793,7 +793,7 @@ static void HealMon(struct Pokemon *mon) SetMonData(mon, MON_DATA_HP, data); ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u16 move = GetMonData(mon, MON_DATA_MOVE1 + i); data[0] = CalculatePPWithBonus(move, ppBonuses, i); @@ -1137,7 +1137,7 @@ bool32 TryGenerateBattlePikeWildMon(bool8 checkKeenEyeIntimidate) else abilityBit = 0; SetMonData(&gEnemyParty[0], MON_DATA_ALT_ABILITY, &abilityBit); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) SetMonMoveSlot(&gEnemyParty[0], wildMons[headerId][pikeMonId].moves[i], i); CalculateMonStats(&gEnemyParty[0]); @@ -1285,7 +1285,7 @@ static void TryHealMons(u8 healCount) else { u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { u16 move = GetMonData(mon, MON_DATA_MOVE1 + j); max = CalculatePPWithBonus(move, ppBonuses, j); @@ -1546,7 +1546,7 @@ static void sub_81A86C0(void) if (curr >= max && pokemon_ailments_get_primary(GetMonData(mon, MON_DATA_STATUS)) == 0) { u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { u16 move = GetMonData(mon, MON_DATA_MOVE1 + j); max = CalculatePPWithBonus(move, ppBonuses, j); diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 244e61d17..2f0d35feb 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1177,14 +1177,14 @@ static void sub_81A9834(void) { if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_SPECIES, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_SPECIES, NULL)) { - for (k = 0; k < 4; k++) + for (k = 0; k < MAX_MON_MOVES; k++) { - for (l = 0; l < 4; l++) + for (l = 0; l < MAX_MON_MOVES; l++) { if (GetMonData(&gSaveBlock1Ptr->playerParty[id], MON_DATA_MOVE1 + l, NULL) == GetMonData(&gPlayerParty[j], MON_DATA_MOVE1 + k, NULL)) break; } - if (l == 4) + if (l == MAX_MON_MOVES) SetMonMoveSlot(&gPlayerParty[j], MOVE_SKETCH, k); } gSaveBlock1Ptr->playerParty[id] = gPlayerParty[j]; @@ -1202,8 +1202,8 @@ static u8 sub_81A9998(s32 *arg0, u8 arg1, u8 arg2) { s32 i, j; u8 ret = 0; - u16 *map = gUnknown_03005DC0.map; - map += gUnknown_03005DC0.width * 7 + 7; + u16 *map = gBackupMapLayout.map; + map += gBackupMapLayout.width * 7 + 7; for (i = 0; i < 32; map += 47, i++) { @@ -1360,7 +1360,7 @@ void GenerateBattlePyramidWildMon(void) break; } - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) SetMonMoveSlot(&gEnemyParty[0], wildMons[id].moves[i], i); if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[lvl] >= 140) // BUG: Reading outside the array as lvl was used for mon level instead of frontier lvl mode. @@ -1493,11 +1493,11 @@ void sub_81AA078(u16 *mapArg, u8 arg1) const struct MapLayout *mapLayout = gMapLayouts[allocated[i] + 0x169]; const u16 *layoutMap = mapLayout->map; - gUnknown_03005DC0.map = mapArg; - gUnknown_03005DC0.width = mapLayout->width * 4 + 15; - gUnknown_03005DC0.height = mapLayout->height * 4 + 14; + gBackupMapLayout.map = mapArg; + gBackupMapLayout.width = mapLayout->width * 4 + 15; + gBackupMapLayout.height = mapLayout->height * 4 + 14; map = mapArg; - heightAdd = (((i / 4 * mapLayout->height) + 7) * (gUnknown_03005DC0.width)); + heightAdd = (((i / 4 * mapLayout->height) + 7) * (gBackupMapLayout.width)); widthAdd = ((i % 4 * mapLayout->width) + 7); map += heightAdd + widthAdd; for (j = 0; j < mapLayout->height; j++) diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 12f631155..50baf48fd 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -365,7 +365,7 @@ static void sub_81C4F44(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); gFieldCallback2 = hm_add_c3_without_phase_2; sub_81C4F98(3, CB2_ReturnToField); DestroyTask(taskId); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c71043958..2490d6e13 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -4599,12 +4599,12 @@ static void atk49_moveend(void) *choicedMoveAtk = gChosenMove; LOOP: { - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gBattlerAttacker].moves[i] == *choicedMoveAtk) break; } - if (i == 4) + if (i == MAX_MON_MOVES) *choicedMoveAtk = 0; gBattleScripting.atk49_state++; @@ -5957,7 +5957,7 @@ static void atk5E(void) { s32 i; struct BattlePokemon *bufferPoke = (struct BattlePokemon*) &gBattleBufferB[gActiveBattler][4]; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { gBattleMons[gActiveBattler].moves[i] = bufferPoke->moves[i]; gBattleMons[gActiveBattler].pp[i] = bufferPoke->pp[i]; @@ -6237,7 +6237,7 @@ static void atk6C_drawlvlupbox(void) { case 1: gBattle_BG2_Y = 0x60; - SetBgAttribute(2, BG_CTRL_ATTR_MOSAIC, 0); + SetBgAttribute(2, BG_ATTR_PRIORITY, 0); ShowBg(2); sub_804F17C(); gBattleScripting.atk6C_state = 2; @@ -6249,8 +6249,8 @@ static void atk6C_drawlvlupbox(void) case 3: gBattle_BG1_X = 0; gBattle_BG1_Y = 0x100; - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 1); - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, 0); + SetBgAttribute(0, BG_ATTR_PRIORITY, 1); + SetBgAttribute(1, BG_ATTR_PRIORITY, 0); ShowBg(0); ShowBg(1); HandleBattleWindow(0x12, 7, 0x1D, 0x13, WINDOW_x80); @@ -6296,7 +6296,7 @@ static void atk6C_drawlvlupbox(void) ClearWindowTilemap(13); CopyWindowToVram(13, 1); - SetBgAttribute(2, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(2, BG_ATTR_PRIORITY, 2); ShowBg(2); gBattleScripting.atk6C_state = 10; @@ -6305,8 +6305,8 @@ static void atk6C_drawlvlupbox(void) case 10: if (!IsDma3ManagerBusyWithBgCopy()) { - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 0); - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, 1); + SetBgAttribute(0, BG_ATTR_PRIORITY, 0); + SetBgAttribute(1, BG_ATTR_PRIORITY, 1); ShowBg(0); ShowBg(1); gBattlescriptCurrInstr++; @@ -6652,12 +6652,12 @@ static void atk76_various(void) choicedMove = &gBattleStruct->choicedMove[gActiveBattler]; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gActiveBattler].moves[i] == *choicedMove) break; } - if (i == 4) + if (i == MAX_MON_MOVES) *choicedMove = 0; } break; @@ -7633,7 +7633,7 @@ static void atk90_tryconversiontypechange(void) // randomly changes user's type u8 moveChecked; u8 moveType; - while (validMoves < 4) + while (validMoves < MAX_MON_MOVES) { if (gBattleMons[gBattlerAttacker].moves[validMoves] == 0) break; @@ -8031,7 +8031,7 @@ static void atk9B_transformdataexecution(void) for (i = 0; i < offsetof(struct BattlePokemon, pp); i++) battleMonAttacker[i] = battleMonTarget[i]; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMoves[gBattleMons[gBattlerAttacker].moves[i]].pp < 5) gBattleMons[gBattlerAttacker].pp[i] = gBattleMoves[gBattleMons[gBattlerAttacker].moves[i]].pp; @@ -8097,13 +8097,13 @@ static void atk9D_mimicattackcopy(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gBattlerAttacker].moves[i] == gLastMoves[gBattlerTarget]) break; } - if (i == 4) + if (i == MAX_MON_MOVES) { gBattleMons[gBattlerAttacker].moves[gCurrMovePos] = gLastMoves[gBattlerTarget]; if (gBattleMoves[gLastMoves[gBattlerTarget]].pp < 5) @@ -8134,7 +8134,7 @@ static void atk9E_metronome(void) if (gCurrentMove >= MOVES_COUNT) continue; - for (i = 0; i < 4; i++); // ? + for (i = 0; i < MAX_MON_MOVES; i++); // ? i = -1; while (1) @@ -8225,13 +8225,13 @@ static void atkA3_disablelastusedattack(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) break; } if (gDisableStructs[gBattlerTarget].disabledMove == 0 - && i != 4 && gBattleMons[gBattlerTarget].pp[i] != 0) + && i != MAX_MON_MOVES && gBattleMons[gBattlerTarget].pp[i] != 0) { PREPARE_MOVE_BUFFER(gBattleTextBuff1, gBattleMons[gBattlerTarget].moves[i]) @@ -8250,7 +8250,7 @@ static void atkA4_trysetencore(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gBattlerTarget].moves[i] == gLastMoves[gBattlerTarget]) break; @@ -8382,7 +8382,7 @@ static void atkA8_copymovepermanently(void) // sketch { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gBattlerAttacker].moves[i] == MOVE_SKETCH) continue; @@ -8390,7 +8390,7 @@ static void atkA8_copymovepermanently(void) // sketch break; } - if (i != 4) + if (i != MAX_MON_MOVES) { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); } @@ -8402,7 +8402,7 @@ static void atkA8_copymovepermanently(void) // sketch gBattleMons[gBattlerAttacker].pp[gCurrMovePos] = gBattleMoves[gLastPrintedMoves[gBattlerTarget]].pp; gActiveBattler = gBattlerAttacker; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { movePpData.moves[i] = gBattleMons[gBattlerAttacker].moves[i]; movePpData.pp[i] = gBattleMons[gBattlerAttacker].pp[i]; @@ -8470,7 +8470,7 @@ static void atkA9_trychoosesleeptalkmove(void) s32 i; u8 unusableMovesBits = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (IsInvalidForSleepTalkOrAssist(gBattleMons[gBattlerAttacker].moves[i]) || gBattleMons[gBattlerAttacker].moves[i] == MOVE_FOCUS_PUNCH @@ -8550,13 +8550,13 @@ static void atkAD_tryspiteppreduce(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gLastMoves[gBattlerTarget] == gBattleMons[gBattlerTarget].moves[i]) break; } - if (i != 4 && gBattleMons[gBattlerTarget].pp[i] > 1) + if (i != MAX_MON_MOVES && gBattleMons[gBattlerTarget].pp[i] > 1) { s32 ppToDeduct = (Random() & 3) + 2; if (gBattleMons[gBattlerTarget].pp[i] < ppToDeduct) @@ -9626,19 +9626,19 @@ static void atkDB_tryimprision(void) if (sideAttacker != GetBattlerSide(battlerId)) { s32 attackerMoveId; - for (attackerMoveId = 0; attackerMoveId < 4; attackerMoveId++) + for (attackerMoveId = 0; attackerMoveId < MAX_MON_MOVES; attackerMoveId++) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[gBattlerAttacker].moves[attackerMoveId] == gBattleMons[battlerId].moves[i] && gBattleMons[gBattlerAttacker].moves[attackerMoveId] != MOVE_NONE) break; } - if (i != 4) + if (i != MAX_MON_MOVES) break; } - if (attackerMoveId != 4) + if (attackerMoveId != MAX_MON_MOVES) { gStatuses3[gBattlerAttacker] |= STATUS3_IMPRISONED_OTHERS; gBattlescriptCurrInstr += 5; @@ -9702,7 +9702,7 @@ static void atkDE_asistattackselect(void) if (GetMonData(&party[monId], MON_DATA_SPECIES2) == SPECIES_EGG) continue; - for (moveId = 0; moveId < 4; moveId++) + for (moveId = 0; moveId < MAX_MON_MOVES; moveId++) { s32 i = 0; u16 move = GetMonData(&party[monId], MON_DATA_MOVE1 + moveId); @@ -10138,7 +10138,7 @@ static void atkEF_handleballthrow(void) ballMultiplier = 10; break; case ITEM_DIVE_BALL: - if (Overworld_GetMapTypeOfSaveblockLocation() == MAP_TYPE_UNDERWATER) + if (GetCurrentMapType() == MAP_TYPE_UNDERWATER) ballMultiplier = 35; else ballMultiplier = 10; diff --git a/src/battle_setup.c b/src/battle_setup.c index 56bed77c8..21386016f 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -40,6 +40,7 @@ #include "fldeff.h" #include "fldeff_misc.h" #include "field_control_avatar.h" +#include "mirage_tower.h" #include "constants/map_types.h" #include "constants/battle_frontier.h" @@ -341,14 +342,14 @@ static void Task_BattleStart(u8 taskId) if (!FldEffPoison_IsActive()) // is poison not active? { BattleTransition_StartOnField(tTransition); - sub_81BE72C(); + ClearMirageTowerPulseBlendEffect(); tState++; // go to case 1. } break; case 1: if (IsBattleTransitionDone() == TRUE) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_InitBattle); RestartWildEncounterImmunitySteps(); ClearPoisonStepCounter(); diff --git a/src/battle_tent.c b/src/battle_tent.c index c358deaa5..de4d9d374 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -100,7 +100,7 @@ static void sub_81B99D4(void) gSaveBlock2Ptr->frontier.field_CA8 = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } static void sub_81B9A28(void) @@ -162,7 +162,7 @@ static void sub_81B9BA0(void) gSaveBlock2Ptr->frontier.field_CA8 = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } static void sub_81B9BF4(void) @@ -217,7 +217,7 @@ static void sub_81B9D28(void) gSaveBlock2Ptr->frontier.field_CA8 = 0; gSaveBlock2Ptr->frontier.curChallengeBattleNum = 0; gSaveBlock2Ptr->frontier.field_CA9_a = FALSE; - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } static void sub_81B9D7C(void) diff --git a/src/battle_tower.c b/src/battle_tower.c index 78d4c5a9b..9e546b0c8 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1163,7 +1163,7 @@ static void sub_8161F94(void) gSaveBlock2Ptr->frontier.towerWinStreaks[battleMode][lvlMode] = 0; ValidateBattleTowerRecordChecksums(); - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); gTrainerBattleOpponent_A = 0; } @@ -1973,7 +1973,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) friendship = 255; // Give the chosen pokemon its specified moves. - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonMoveSlot(&gEnemyParty[i + firstMonId], gFacilityTrainerMons[monSetId].moves[j], j); if (gFacilityTrainerMons[monSetId].moves[j] == MOVE_FRUSTRATION) @@ -2012,7 +2012,7 @@ static void Unused_CreateApprenticeMons(u16 trainerId, u8 firstMonId) { CreateMonWithEVSpread(&gEnemyParty[firstMonId + i], apprentice->party[i].species, level, fixedIV, 8); friendship = 0xFF; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (apprentice->party[i].moves[j] == MOVE_FRUSTRATION) friendship = 0; @@ -2102,7 +2102,7 @@ static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId) otID); friendship = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) SetMonMoveAvoidReturn(&gEnemyParty[firstMonId + i], gFacilityTrainerMons[monSetId].moves[j], j); SetMonData(&gEnemyParty[firstMonId + i], MON_DATA_FRIENDSHIP, &friendship); @@ -2130,7 +2130,7 @@ static void FillFactoryTentTrainerParty(u16 trainerId, u8 firstMonId) otID); friendship = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonMoveAvoidReturn(&gEnemyParty[firstMonId + i], gFacilityTrainerMons[monSetId].moves[j], j); if (gFacilityTrainerMons[monSetId].moves[j] == MOVE_FRUSTRATION) @@ -3193,7 +3193,7 @@ static void FillPartnerParty(u16 trainerId) TRUE, STEVEN_OTID); for (j = 0; j < 6; j++) SetMonData(&gPlayerParty[3 + i], MON_DATA_HP_EV + j, &sStevenMons[i].evs[j]); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) SetMonMoveSlot(&gPlayerParty[3 + i], sStevenMons[i].moves[j], j); SetMonData(&gPlayerParty[3 + i], MON_DATA_OT_NAME, gTrainers[TRAINER_STEVEN].trainerName); j = MALE; @@ -3222,7 +3222,7 @@ static void FillPartnerParty(u16 trainerId) gFacilityTrainerMons[monSetId].evSpread, otID); friendship = 0xFF; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonMoveSlot(&gPlayerParty[3 + i], gFacilityTrainerMons[monSetId].moves[j], j); if (gFacilityTrainerMons[monSetId].moves[j] == MOVE_FRUSTRATION) @@ -3647,7 +3647,7 @@ static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) friendship = 255; // Give the chosen pokemon its specified moves. - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonMoveSlot(&gEnemyParty[i + firstMonId], gFacilityTrainerMons[monSetId].moves[j], j); if (gFacilityTrainerMons[monSetId].moves[j] == MOVE_FRUSTRATION) diff --git a/src/battle_tv.c b/src/battle_tv.c index 487b6baac..d3ca9b61f 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -746,7 +746,7 @@ void TryPutLinkBattleTvShowOnAir(void) species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL); if (species != SPECIES_NONE && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG, NULL)) { - for (sum = 0, j = 0; j < 4; j++) + for (sum = 0, j = 0; j < MAX_MON_MOVES; j++) sum += movePoints->points[0][i * 4 + j]; if (playerBestSum < sum) @@ -760,7 +760,7 @@ void TryPutLinkBattleTvShowOnAir(void) species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES, NULL); if (species != SPECIES_NONE && !GetMonData(&gEnemyParty[i], MON_DATA_IS_EGG, NULL)) { - for (sum = 0, j = 0; j < 4; j++) + for (sum = 0, j = 0; j < MAX_MON_MOVES; j++) sum += movePoints->points[1][i * 4 + j]; if (opponentBestSum == sum) @@ -781,7 +781,7 @@ void TryPutLinkBattleTvShowOnAir(void) } } - for (sum = 0, i = 0, j = 0; j < 4; j++) + for (sum = 0, i = 0, j = 0; j < MAX_MON_MOVES; j++) { if (sum < movePoints->points[0][playerBestMonId * 4 + j]) { @@ -1422,7 +1422,7 @@ static void TrySetBattleSeminarShow(void) dmgByMove[gMoveSelectionCursor[gBattlerAttacker]] = gBattleMoveDamage; currMoveSaved = gCurrentMove; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { gCurrentMove = gBattleMons[gBattlerAttacker].moves[i]; powerOverride = 0; @@ -1446,7 +1446,7 @@ static void TrySetBattleSeminarShow(void) } } - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (i != gMoveSelectionCursor[gBattlerAttacker] && dmgByMove[i] > dmgByMove[gMoveSelectionCursor[gBattlerAttacker]]) { @@ -1458,7 +1458,7 @@ static void TrySetBattleSeminarShow(void) else bestMoveId = 1; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (i != gMoveSelectionCursor[gBattlerAttacker] && dmgByMove[i] > dmgByMove[bestMoveId]) bestMoveId = i; @@ -1551,7 +1551,7 @@ u8 GetBattlerMoveSlotId(u8 battlerId, u16 moveId) i = 0; while (1) { - if (i >= 4) + if (i >= MAX_MON_MOVES) break; if (GetMonData(&party[gBattlerPartyIndexes[battlerId]], MON_DATA_MOVE1 + i, NULL) == moveId) break; diff --git a/src/battle_util.c b/src/battle_util.c index 2ddd4f550..5d8e42482 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -85,13 +85,13 @@ void PressurePPLose(u8 defender, u8 attacker, u16 move) if (gBattleMons[defender].ability != ABILITY_PRESSURE) return; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[attacker].moves[i] == move) break; } - if (i == 4) // mons don't share any moves + if (i == MAX_MON_MOVES) // mons don't share any moves return; if (gBattleMons[attacker].pp[i] != 0) @@ -116,12 +116,12 @@ void PressurePPLoseOnUsingImprision(u8 attacker) { if (atkSide != GetBattlerSide(i) && gBattleMons[i].ability == ABILITY_PRESSURE) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (gBattleMons[attacker].moves[j] == MOVE_IMPRISON) break; } - if (j != 4) + if (j != MAX_MON_MOVES) { imprisionPos = j; if (gBattleMons[attacker].pp[j] != 0) @@ -149,12 +149,12 @@ void PressurePPLoseOnUsingPerishSong(u8 attacker) { if (gBattleMons[i].ability == ABILITY_PRESSURE && i != attacker) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (gBattleMons[attacker].moves[j] == MOVE_PERISH_SONG) break; } - if (j != 4) + if (j != MAX_MON_MOVES) { perishSongPos = j; if (gBattleMons[attacker].pp[j] != 0) @@ -163,7 +163,7 @@ void PressurePPLoseOnUsingPerishSong(u8 attacker) } } - if (perishSongPos != 4 + if (perishSongPos != MAX_MON_MOVES && !(gBattleMons[attacker].status2 & STATUS2_TRANSFORMED) && !(gDisableStructs[attacker].unk18_b & gBitTable[perishSongPos])) { @@ -426,7 +426,7 @@ u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u8 check) gPotentialItemEffectBattler = battlerId; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[battlerId].moves[i] == 0 && check & MOVE_LIMITATION_ZEROMOVE) unusableMoves |= gBitTable[i]; @@ -477,12 +477,12 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) if (battlerSide != GetBattlerSide(i) && gStatuses3[i] & STATUS3_IMPRISONED_OTHERS) { s32 j; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (move == gBattleMons[i].moves[j]) break; } - if (j < 4) + if (j < MAX_MON_MOVES) imprisionedMoves++; } } @@ -1021,12 +1021,12 @@ u8 DoBattlerEndTurnEffects(void) if (gDisableStructs[gActiveBattler].disableTimer != 0) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gDisableStructs[gActiveBattler].disabledMove == gBattleMons[gActiveBattler].moves[i]) break; } - if (i == 4) // pokemon does not have the disabled move anymore + if (i == MAX_MON_MOVES) // pokemon does not have the disabled move anymore { gDisableStructs[gActiveBattler].disabledMove = 0; gDisableStructs[gActiveBattler].disableTimer = 0; @@ -2661,7 +2661,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) mon = &gPlayerParty[gBattlerPartyIndexes[battlerId]]; else mon = &gEnemyParty[gBattlerPartyIndexes[battlerId]]; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { move = GetMonData(mon, MON_DATA_MOVE1 + i); changedPP = GetMonData(mon, MON_DATA_PP1 + i); @@ -2669,7 +2669,7 @@ u8 ItemBattleEffects(u8 caseID, u8 battlerId, bool8 moveTurn) if (move && changedPP == 0) break; } - if (i != 4) + if (i != MAX_MON_MOVES) { u8 maxPP = CalculatePPWithBonus(move, ppBonuses, i); if (changedPP + battlerHoldEffectParam > maxPP) diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c index d87509e10..3631c083a 100644 --- a/src/berry_fix_program.c +++ b/src/berry_fix_program.c @@ -67,7 +67,7 @@ static const u16 sUnknown_08618138[] = { 0x7fff, 0x7fff, 0x318c, 0x675a, 0x043c, 0x3aff, 0x0664, 0x4bd2, 0x6546, 0x7b14, 0x7fff, 0x318c, - 0x675a, 0x0000, 0x0000, 0x0000 + 0x675a, 0, 0, 0 }; static const u8 sUnknown_08618158[] = {10, 11, 12}; @@ -124,7 +124,7 @@ void CB2_InitBerryFixProgram(void) ResetSpriteData(); ResetTasks(); ScanlineEffect_Stop(); - SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); + SetGpuReg(REG_OFFSET_DISPCNT, 0); berry_fix_mb_manager = AllocZeroed(0x50); berry_fix_mb_manager->state = 0; berry_fix_mb_manager->unk1 = 6; @@ -203,13 +203,13 @@ static void berry_fix_gpu_set(void) { s32 width, left; - SetGpuReg(REG_OFFSET_BG0CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG1CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG0HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG0VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BLDCNT, 0x0000); + SetGpuReg(REG_OFFSET_BG0CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); DmaFill32(3, 0, VRAM, VRAM_SIZE); DmaFill32(3, 0, OAM, OAM_SIZE); @@ -77,15 +77,27 @@ void ResetBgControlStructs(void) void Unused_ResetBgControlStruct(u8 bg) { - if (IsInvalidBg(bg) == FALSE) + if (!IsInvalidBg(bg)) { sGpuBgConfigs.configs[bg] = sZeroedBgControlStruct; } } -void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound) +enum { - if (IsInvalidBg(bg) == FALSE) + BG_CTRL_ATTR_VISIBLE = 1, + BG_CTRL_ATTR_CHARBASEINDEX = 2, + BG_CTRL_ATTR_MAPBASEINDEX = 3, + BG_CTRL_ATTR_SCREENSIZE = 4, + BG_CTRL_ATTR_PALETTEMODE = 5, + BG_CTRL_ATTR_PRIORITY = 6, + BG_CTRL_ATTR_MOSAIC = 7, + BG_CTRL_ATTR_WRAPAROUND = 8, +}; + +static void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound) +{ + if (!IsInvalidBg(bg)) { if (charBaseIndex != 0xFF) { @@ -129,9 +141,9 @@ void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenS } } -u16 GetBgControlAttribute(u8 bg, u8 attributeId) +static u16 GetBgControlAttribute(u8 bg, u8 attributeId) { - if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE) + if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) { switch (attributeId) { @@ -162,7 +174,7 @@ u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode) u16 offset; s8 cursor; - if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE) + if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) { switch (mode) { @@ -198,7 +210,7 @@ end: static void ShowBgInternal(u8 bg) { u16 value; - if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE) + if (!IsInvalidBg(bg) && sGpuBgConfigs.configs[bg].visible) { value = sGpuBgConfigs.configs[bg].priority | (sGpuBgConfigs.configs[bg].charBaseIndex << 2) | @@ -217,7 +229,7 @@ static void ShowBgInternal(u8 bg) static void HideBgInternal(u8 bg) { - if (IsInvalidBg(bg) == FALSE) + if (!IsInvalidBg(bg)) { sGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8)); sGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS; @@ -226,12 +238,12 @@ static void HideBgInternal(u8 bg) static void SyncBgVisibilityAndMode(void) { - SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | sGpuBgConfigs.bgVisibilityAndMode); + SetGpuReg(REG_OFFSET_DISPCNT, (GetGpuReg(REG_OFFSET_DISPCNT) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | sGpuBgConfigs.bgVisibilityAndMode); } void SetTextModeAndHideBgs(void) { - SetGpuReg(0, GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS); + SetGpuReg(REG_OFFSET_DISPCNT, GetGpuReg(REG_OFFSET_DISPCNT) & ~DISPCNT_ALL_BG_AND_MODE_BITS); } static void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) @@ -312,7 +324,8 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT for (i = 0; i < numTemplates; i++) { bg = templates[i].bg; - if (bg < 4) { + if (bg < 4) + { SetBgControlAttributes(bg, templates[i].charBaseIndex, templates[i].mapBaseIndex, @@ -396,9 +409,7 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset) u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset) { - u8 cursor; - - cursor = LoadBgVram(bg, src, size, destOffset * 2, DISPCNT_MODE_2); + u8 cursor = LoadBgVram(bg, src, size, destOffset * 2, DISPCNT_MODE_2); if (cursor == 0xFF) { @@ -412,12 +423,11 @@ u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset) u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset) { - u16 paletteOffset; s8 cursor; - if (IsInvalidBg32(bg) == FALSE) + if (!IsInvalidBg32(bg)) { - paletteOffset = (sGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2); + u16 paletteOffset = (sGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2); cursor = RequestDma3Copy(src, (void*)(paletteOffset + BG_PLTT), size, 0); if (cursor == -1) @@ -437,20 +447,16 @@ u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset) bool8 IsDma3ManagerBusyWithBgCopy(void) { - u8 mod; - u8 div; - s8 reqSpace; - int i; for (i = 0; i < 0x80; i++) { - div = i / 0x20; - mod = i % 0x20; + u8 div = i / 0x20; + u8 mod = i % 0x20; - if ((sDmaBusyBitfield[div] & (1 << mod)) != FALSE) + if ((sDmaBusyBitfield[div] & (1 << mod))) { - reqSpace = CheckForSpaceForDma3Request(i); + s8 reqSpace = CheckForSpaceForDma3Request(i); if (reqSpace == -1) { return TRUE; @@ -479,25 +485,25 @@ void SetBgAttribute(u8 bg, u8 attributeId, u8 value) { switch (attributeId) { - case 1: + case BG_ATTR_CHARBASEINDEX: SetBgControlAttributes(bg, value, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); break; - case 2: + case BG_ATTR_MAPBASEINDEX: SetBgControlAttributes(bg, 0xFF, value, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); break; - case 3: + case BG_ATTR_SCREENSIZE: SetBgControlAttributes(bg, 0xFF, 0xFF, value, 0xFF, 0xFF, 0xFF, 0xFF); break; - case 4: + case BG_ATTR_PALETTEMODE: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, value, 0xFF, 0xFF, 0xFF); break; - case 7: + case BG_ATTR_PRIORITY: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, value, 0xFF, 0xFF); break; - case 5: + case BG_ATTR_MOSAIC: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, value, 0xFF); break; - case 6: + case BG_ATTR_WRAPAROUND: SetBgControlAttributes(bg, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, value); break; } @@ -507,21 +513,21 @@ u16 GetBgAttribute(u8 bg, u8 attributeId) { switch (attributeId) { - case 1: + case BG_ATTR_CHARBASEINDEX: return GetBgControlAttribute(bg, BG_CTRL_ATTR_CHARBASEINDEX); - case 2: + case BG_ATTR_MAPBASEINDEX: return GetBgControlAttribute(bg, BG_CTRL_ATTR_MAPBASEINDEX); - case 3: + case BG_ATTR_SCREENSIZE: return GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); - case 4: + case BG_ATTR_PALETTEMODE: return GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE); - case 7: + case BG_ATTR_PRIORITY: return GetBgControlAttribute(bg, BG_CTRL_ATTR_PRIORITY); - case 5: + case BG_ATTR_MOSAIC: return GetBgControlAttribute(bg, BG_CTRL_ATTR_MOSAIC); - case 6: + case BG_ATTR_WRAPAROUND: return GetBgControlAttribute(bg, BG_CTRL_ATTR_WRAPAROUND); - case 8: + case BG_ATTR_METRIC: switch (GetBgType(bg)) { case 0: @@ -531,9 +537,9 @@ u16 GetBgAttribute(u8 bg, u8 attributeId) default: return 0; } - case 9: + case BG_ATTR_TYPE: return GetBgType(bg); - case 10: + case BG_ATTR_BASETILE: return sGpuBgConfigs2[bg].baseTile; default: return -1; @@ -546,7 +552,7 @@ s32 ChangeBgX(u8 bg, s32 value, u8 op) u16 temp1; u16 temp2; - if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { return -1; } @@ -612,9 +618,9 @@ s32 ChangeBgX(u8 bg, s32 value, u8 op) s32 GetBgX(u8 bg) { - if (IsInvalidBg32(bg) != FALSE) + if (IsInvalidBg32(bg)) return -1; - else if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return -1; else return sGpuBgConfigs2[bg].bg_x; @@ -626,7 +632,7 @@ s32 ChangeBgY(u8 bg, s32 value, u8 op) u16 temp1; u16 temp2; - if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { return -1; } @@ -696,7 +702,7 @@ s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) u16 temp1; u16 temp2; - if (IsInvalidBg32(bg) != FALSE || GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { return -1; } @@ -763,9 +769,9 @@ s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) s32 GetBgY(u8 bg) { - if (IsInvalidBg32(bg) != FALSE) + if (IsInvalidBg32(bg)) return -1; - else if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return -1; else return sGpuBgConfigs2[bg].bg_y; @@ -849,7 +855,7 @@ u8 Unused_AdjustBgMosaic(u8 a1, u8 a2) void SetBgTilemapBuffer(u8 bg, void *tilemap) { - if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0) + if (!IsInvalidBg32(bg) && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { sGpuBgConfigs2[bg].tilemap = tilemap; } @@ -857,7 +863,7 @@ void SetBgTilemapBuffer(u8 bg, void *tilemap) void UnsetBgTilemapBuffer(u8 bg) { - if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0) + if (!IsInvalidBg32(bg) && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { sGpuBgConfigs2[bg].tilemap = NULL; } @@ -865,9 +871,9 @@ void UnsetBgTilemapBuffer(u8 bg) void* GetBgTilemapBuffer(u8 bg) { - if (IsInvalidBg32(bg) != FALSE) + if (IsInvalidBg32(bg)) return NULL; - else if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return NULL; else return sGpuBgConfigs2[bg].tilemap; @@ -875,7 +881,7 @@ void* GetBgTilemapBuffer(u8 bg) void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset) { - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { if (mode != 0) CpuCopy16(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode); @@ -888,7 +894,7 @@ void CopyBgTilemapBufferToVram(u8 bg) { u16 sizeToLoad; - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { switch (GetBgType(bg)) { @@ -908,12 +914,12 @@ void CopyBgTilemapBufferToVram(u8 bg) void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 width, u8 height) { - const void* srcCopy; + const void *srcCopy; u16 destX16; u16 destY16; u16 mode; - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { switch (GetBgType(bg)) { @@ -997,29 +1003,29 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u16 y16; u16 mode; - if (IsInvalidBg32(bg) == FALSE && IsTileMapOutsideWram(bg) == FALSE) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { switch (GetBgType(bg)) { - case 0: - for (y16 = y; y16 < (y + height); y16++) + case 0: + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) { - for (x16 = x; x16 < (x + width); x16++) - { - ((u16*)sGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum; - } + ((u16*)sGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum; } - break; - case 1: - mode = GetBgMetricAffineMode(bg, 0x1); - for (y16 = y; y16 < (y + height); y16++) + } + break; + case 1: + mode = GetBgMetricAffineMode(bg, 0x1); + for (y16 = y; y16 < (y + height); y16++) + { + for (x16 = x; x16 < (x + width); x16++) { - for (x16 = x; x16 < (x + width); x16++) - { - ((u8*)sGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum; - } + ((u8*)sGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum; } - break; + } + break; } } } @@ -1071,12 +1077,12 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) { - u8 attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + u8 screenSize = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); switch (whichMetric) { case 0: - switch (attribute) + switch (screenSize) { case 0: return 1; @@ -1088,7 +1094,7 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) } break; case 1: - switch (attribute) + switch (screenSize) { case 0: return 1; @@ -1101,7 +1107,7 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) } break; case 2: - switch (attribute) + switch (screenSize) { case 0: case 1: @@ -1117,12 +1123,12 @@ u16 GetBgMetricTextMode(u8 bg, u8 whichMetric) u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric) { - u8 attribute = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); + u8 screenSize = GetBgControlAttribute(bg, BG_CTRL_ATTR_SCREENSIZE); switch (whichMetric) { case 0: - switch (attribute) + switch (screenSize) { case 0: return 0x1; @@ -1136,7 +1142,7 @@ u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric) break; case 1: case 2: - return 0x10 << attribute; + return 0x10 << screenSize; } return 0; } diff --git a/src/cable_club.c b/src/cable_club.c index fd5094ec7..784426d53 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -845,7 +845,7 @@ static void sub_80B32B4(u8 taskId) PlayMapChosenOrBattleBGM(MUS_BATTLE20); sub_80B3260(gSpecialVar_0x8004); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); gTrainerBattleOpponent_A = 0x800; SetMainCallback2(CB2_InitBattle); gMain.savedCallback = sub_80B360C; @@ -911,7 +911,7 @@ static void sub_80B33BC(u8 taskId) gLinkPlayers[0].linkType = 0x2211; sub_80B3260(gSpecialVar_0x8004); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); gTrainerBattleOpponent_A = 0x800; SetMainCallback2(CB2_InitBattle); gMain.savedCallback = sub_80B360C; @@ -1008,7 +1008,7 @@ void sub_80B36EC(void) LoadPlayerParty(); SavePlayerBag(); } - copy_saved_warp2_bank_and_enter_x_to_warp1(0x7F); + SetWarpDestinationToDynamicWarp(0x7F); } void sub_80B371C(void) diff --git a/src/clock.c b/src/clock.c index 2d4da92ab..d52fde22e 100644 --- a/src/clock.c +++ b/src/clock.c @@ -12,17 +12,9 @@ #include "overworld.h" #include "wallclock.h" -// static types - -// static declarations - static void UpdatePerDay(struct Time *localTime); static void UpdatePerMinute(struct Time *localTime); -// rodata - -// text - static void InitTimeBasedEvents(void) { FlagSet(FLAG_SYS_CLOCK_SET); diff --git a/src/contest.c b/src/contest.c index a14ac1326..949be7941 100644 --- a/src/contest.c +++ b/src/contest.c @@ -270,7 +270,7 @@ void LoadContestBgAfterMoveAnim(void) CopyBgTilemapBufferToVram(3); LoadCompressedPalette(gUnknown_08C16E90, 0, 0x200); sub_80D782C(); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u32 var = 5 + i; @@ -284,7 +284,7 @@ void sub_80D779C(void) ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, gUnknown_08587F34, ARRAY_COUNT(gUnknown_08587F34)); - SetBgAttribute(3, BG_CTRL_ATTR_PRIORITY, 1); + SetBgAttribute(3, BG_ATTR_WRAPAROUND, 1); for (i = 0; i < 4; i++) { SetBgTilemapBuffer(i, gContestResources->field_24[i]); @@ -746,7 +746,7 @@ void sub_80D8490(u8 taskId) gBattle_BG0_Y = 0xA0; gBattle_BG2_Y = 0xA0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u16 move = gContestMons[gContestPlayerMonIndex].moves[i]; u8 *r5 = sp8; @@ -781,7 +781,7 @@ void sub_80D8610(u8 taskId) u8 numMoves = 0; s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gContestMons[gContestPlayerMonIndex].moves[i] != MOVE_NONE) numMoves++; diff --git a/src/contest_ai.c b/src/contest_ai.c index 1342ea102..97e8c8f29 100644 --- a/src/contest_ai.c +++ b/src/contest_ai.c @@ -1,4 +1,5 @@ #include "global.h" +#include "battle.h" #include "contest.h" #include "random.h" #include "contest_ai.h" @@ -807,14 +808,14 @@ static void ContestAICmd_check_move_has_highest_appeal(void) u16 move = gContestMons[eContestAI->contestantId].moves[eContestAI->unk4]; u8 appeal = gContestEffects[gContestMoves[move].effect].appeal; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u16 newMove = gContestMons[eContestAI->contestantId].moves[i]; if (newMove != 0 && appeal < gContestEffects[gContestMoves[newMove].effect].appeal) break; } - if (i == 4) + if (i == MAX_MON_MOVES) eContestAI->scriptResult = TRUE; else eContestAI->scriptResult = FALSE; @@ -838,14 +839,14 @@ static void ContestAICmd_unk_2F(void) u16 move = gContestMons[eContestAI->contestantId].moves[eContestAI->unk4]; u8 jam = gContestEffects[gContestMoves[move].effect].jam; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u16 newMove = gContestMons[eContestAI->contestantId].moves[i]; if (newMove != 0 && jam < gContestEffects[gContestMoves[newMove].effect].jam) break; } - if (i == 4) + if (i == MAX_MON_MOVES) eContestAI->scriptResult = TRUE; else eContestAI->scriptResult = FALSE; @@ -1019,7 +1020,7 @@ static void ContestAICmd_check_combo_starter(void) int i; u16 move = gContestMons[eContestAI->contestantId].moves[eContestAI->unk4]; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gContestMons[eContestAI->contestantId].moves[i]) { @@ -1065,7 +1066,7 @@ static void ContestAICmd_check_combo_finisher(void) int i; u16 move = gContestMons[eContestAI->contestantId].moves[eContestAI->unk4]; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gContestMons[eContestAI->contestantId].moves[i]) { @@ -1677,7 +1678,7 @@ static void ContestAICmd_check_for_exciting_move(void) int result = 0; int i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (gContestMons[eContestAI->contestantId].moves[i]) { @@ -1719,7 +1720,7 @@ static void ContestAICmd_unk_85(void) int i; u16 arg = T1_READ_16(gAIScriptPtr + 1); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u16 move = gContestMons[eContestAI->contestantId].moves[i]; if (move == arg) diff --git a/src/contest_painting_effects.c b/src/contest_painting_effects.c new file mode 100644 index 000000000..187a0f196 --- /dev/null +++ b/src/contest_painting_effects.c @@ -0,0 +1,771 @@ +#include "global.h" +#include "contest_painting_effects.h" +#include "contest_painting.h" +#include "constants/rgb.h" + +extern u8 gUnknown_03006164; +extern u16 (*gUnknown_03006168)[][32]; +extern u8 gUnknown_0300616C; +extern u8 gUnknown_03006170; +extern u8 gUnknown_03006174; +extern u8 gUnknown_03006178; +extern u8 gUnknown_0300617C; +extern u8 gUnknown_03006180; + +// this file's functions +void sub_8125230(void); +void sub_81252E8(void); +void sub_81254E0(void); +void sub_8125630(void); +void sub_8125448(void); +void sub_81257F8(void); +void sub_81258A0(void); +void sub_81256C8(void); +void sub_8125250(void); +void sub_81253A4(u8); +void sub_81250B8(u8); +void sub_8125170(u8); +void sub_8125954(u16); +u16 ConvertColorToGrayscale(u16*); +u16 sub_8125E18(u16*, u16*, u16*); +u16 ConvertCoolColor(u16*, u8); +u16 ConvertToBlackOrWhite(u16*); +u16 sub_8125C98(u16*, u16*); +u16 InvertColor(u16*); +u16 sub_8125F38(u16*, u16*, u16*); +u16 sub_8125CF4(u16*, u16*); +u16 GetCoolColorFromPersonality(u8); + +void sub_8124F2C(struct Unk030061A0 *info) +{ + gUnknown_03006168 = info->var_4; + gUnknown_0300617C = info->var_1F; + gUnknown_03006164 = info->var_19; + gUnknown_03006178 = info->var_1A; + gUnknown_03006174 = info->var_1B; + gUnknown_0300616C = info->var_1C; + gUnknown_03006180 = info->var_1D; + gUnknown_03006170 = info->var_1E; + switch (info->var_0) + { + case 2: + sub_8125230(); + break; + case 8: + sub_81252E8(); + break; + case 9: + sub_81254E0(); + sub_81253A4(gUnknown_0300617C); + break; + case 10: + sub_81254E0(); + sub_8125630(); + sub_8125448(); + case 31: + sub_8125630(); + break; + case 11: + sub_81254E0(); + sub_81257F8(); + sub_81257F8(); + sub_81258A0(); + sub_8125448(); + break; + case 13: + sub_81256C8(); + break; + case 30: + sub_81254E0(); + break; + case 32: + sub_81257F8(); + break; + case 33: + sub_81258A0(); + break; + case 6: + sub_8125250(); + sub_81250B8(3); + break; + case 36: + sub_81254E0(); + sub_81257F8(); + sub_81258A0(); + sub_8125448(); + sub_81252E8(); + sub_81252E8(); + sub_81250B8(2); + sub_8125170(4); + break; + } +} + +void sub_81250B8(u8 a0) // it changes palette someway somehow... .__. +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16* var2 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16* pal = &var2[gUnknown_03006164]; + for (j = 0; j < gUnknown_03006174; j++, pal++) + { + if (!(0x8000 & *pal)) + { + u8 val = (31 & *pal); + val += a0; + if (val > 31) + val = 31; + + *pal = RGB2(val, val, val); + } + } + } +} + +void sub_8125170(u8 a0) +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16* var2 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16* pal = &var2[gUnknown_03006164]; + for (j = 0; j < gUnknown_03006174; j++, pal++) + { + if (!(0x8000 & *pal)) + { + u8 val = (31 & *pal); + if (val > 31 - a0) + val = 31 - (a0 >> 1); + + *pal = RGB2(val, val, val); + } + } + } +} + +void sub_8125230(void) +{ + u32 i; + for (i = 0; i < 3200; i++) + sub_8125954(i); +} + +void sub_8125250(void) +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16* var2 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16* color = &var2[gUnknown_03006164]; + for (j = 0; j < gUnknown_03006174; j++, color++) + { + if (!(0x8000 & *color)) + { + *color = ConvertColorToGrayscale(color); + } + } + } +} + +void sub_81252E8(void) +{ + u8 i, j; + + for (i = 0; i < gUnknown_03006174; i++) + { + u16* var0 = &(*gUnknown_03006168)[0][gUnknown_03006178 * gUnknown_03006180]; + u16* palette = &var0[gUnknown_03006164 + i]; + u16 color = *palette; + + j = 1; + palette += gUnknown_03006180; + while (j < gUnknown_0300616C - 1) + { + if (!(0x8000 & *palette)) + { + *palette = sub_8125E18(&color, palette, palette + gUnknown_03006180); + color = *palette; + } + + j++; + palette += gUnknown_03006180; + } + } +} + +void sub_81253A4(u8 arg0) +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16* var0 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16* color = &var0[gUnknown_03006164]; + for (j = 0; j < gUnknown_03006174; j++, color++) + { + if (!(0x8000 & *color)) + { + *color = ConvertCoolColor(color, arg0); + } + } + } +} + +void sub_8125448(void) +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16* var0 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16* color = &var0[gUnknown_03006164]; + for (j = 0; j < gUnknown_03006174; j++, color++) + { + if (!(0x8000 & *color)) + { + *color = ConvertToBlackOrWhite(color); + } + } + } +} + +void sub_81254E0(void) +{ + u8 i, j; + u16 *palette; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16 *var0 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + palette = &var0[gUnknown_03006164]; + *palette = sub_8125C98(palette, palette + 1); + for (j = 1, palette = palette + 1; j < gUnknown_03006174 - 1; j++, palette++) + { + *palette = sub_8125C98(palette, palette + 1); + *palette = sub_8125C98(palette, palette - 1); + } + + *palette = sub_8125C98(palette, palette - 1); + } + + for (j = 0; j < gUnknown_03006174; j++) + { + u16 *var0 = &(*gUnknown_03006168)[0][gUnknown_03006178 * gUnknown_03006180]; + palette = &var0[gUnknown_03006164 + j]; + *palette = sub_8125C98(palette, palette + gUnknown_03006180); + for (i = 1, palette = palette + gUnknown_03006180; i < gUnknown_0300616C - 1; i++, palette += gUnknown_03006180) + { + *palette = sub_8125C98(palette, palette + gUnknown_03006180); + *palette = sub_8125C98(palette, palette - gUnknown_03006180); + } + + *palette = sub_8125C98(palette, palette - gUnknown_03006180); + } +} + +void sub_8125630(void) +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16 *var0 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16 *color = &var0[gUnknown_03006164]; + for (j = 0; j < gUnknown_03006174; j++, color++) + { + if (!(0x8000 & *color)) + { + *color = InvertColor(color); + } + } + } +} + +void sub_81256C8(void) +{ + u8 i, j; + u16 *palette; + u16 color; + + palette = (*gUnknown_03006168)[0]; + for (i = 0; i < 64; i++) + { + for (j = 0; j < 64; j++, palette++) + { + if (!(0x8000 & *palette)) + { + *palette = InvertColor(palette); + } + } + } + + for (j = 0; j < 64; j++) + { + palette = &(*gUnknown_03006168)[0][j]; + color = *palette; + *palette = 0x8000; + for (i = 1, palette += 64; i < 63; i++, palette += 64) + { + if (!(0x8000 & *palette)) + { + *palette = sub_8125F38(&color, palette, palette + 64); + color = *palette; + } + } + + *palette = 0x8000; + palette = &(*gUnknown_03006168)[0][j]; + color = *palette; + *palette = 0x8000; + for (i = 1, palette += 64; i < 63; i++, palette += 64) + { + if (!(0x8000 & *palette)) + { + *palette = sub_8125F38(&color, palette, palette + 64); + color = *palette; + } + } + + *palette = 0x8000; + } + + palette = (*gUnknown_03006168)[0]; + for (i = 0; i < 64; i++) + { + for (j = 0; j < 64; j++, palette++) + { + if (!(0x8000 & *palette)) + { + *palette = InvertColor(palette); + } + } + } +} + +void sub_81257F8(void) +{ + u8 i, j; + + for (i = 0; i < gUnknown_0300616C; i++) + { + u16 *var0 = &(*gUnknown_03006168)[0][(gUnknown_03006178 + i) * gUnknown_03006180]; + u16 *palette = &var0[gUnknown_03006164]; + u16 color = *palette; + for (j = 1, palette++; j < gUnknown_03006174 - 1; j++, palette++) + { + if (!(0x8000 & *palette)) + { + *palette = sub_8125CF4(&color, palette); + color = *palette; + } + } + } +} + +void sub_81258A0(void) +{ + u8 i, j; + + for (i = 0; i < gUnknown_03006174; i++) + { + u16* var0 = &(*gUnknown_03006168)[0][gUnknown_03006178 * gUnknown_03006180]; + u16* palette = &var0[gUnknown_03006164 + i]; + u16 color = *palette; + for (j = 1, palette += gUnknown_03006180; j < gUnknown_0300616C - 1; j++, palette += gUnknown_03006180) + { + if (!(0x8000 & *palette)) + { + *palette = sub_8125CF4(&color, palette); + color = *palette; + } + } + } +} + +struct Unk8125954 +{ + u8 unk0; + u8 unk1; + u16 unk2; +}; + +extern const u8 gUnknown_085A1F94[][3]; + +void sub_8125954(u16 arg0) +{ + u8 i; + u8 r5, r9; + struct Unk8125954 unkStruct[6]; + + unkStruct[0].unk0 = gUnknown_085A1F94[arg0][0]; + unkStruct[0].unk1 = gUnknown_085A1F94[arg0][1]; + unkStruct[0].unk2 = (gUnknown_085A1F94[arg0][2] >> 3) & 7; + + r9 = (gUnknown_085A1F94[arg0][2] >> 1) & 3; + r5 = gUnknown_085A1F94[arg0][2] & 1; + for (i = 1; i < unkStruct[0].unk2; i++) + { + if (!r5) + { + unkStruct[i].unk0 = unkStruct[0].unk0 - i; + unkStruct[i].unk1 = unkStruct[0].unk1 + i; + } + else + { + unkStruct[i].unk0 = unkStruct[0].unk0 + 1; + unkStruct[i].unk1 = unkStruct[0].unk1 - 1; + } + + if (unkStruct[i].unk0 > 63 || unkStruct[i].unk1 > 63) + { + unkStruct[0].unk2 = i - 1; + break; + } + + unkStruct[i].unk2 = unkStruct[0].unk2 - i; + } + + for (i = 0; i < unkStruct[0].unk2; i++) + { + u16 *pal = &(*gUnknown_03006168)[unkStruct[i].unk1 * 2][unkStruct[i].unk0]; + + if (!(0x8000 & *pal)) + { + u16 r = (*pal) & 0x1F; + u16 g = (*pal >> 5) & 0x1F; + u16 b = (*pal >> 10) & 0x1F; + + switch (r9) + { + case 0: + case 1: + switch (((gUnknown_085A1F94[arg0][2] >> 3) & 7) % 3) + { + case 0: + if (r >= unkStruct[i].unk2) + r -= unkStruct[i].unk2; + else + r = 0; + break; + case 1: + if (g >= unkStruct[i].unk2) + g -= unkStruct[i].unk2; + else + g = 0; + break; + case 2: + if (b >= unkStruct[i].unk2) + b -= unkStruct[i].unk2; + else + b = 0; + break; + } + break; + case 2: + case 3: + r += unkStruct[i].unk2; + g += unkStruct[i].unk2; + b += unkStruct[i].unk2; + if (r > 31) + r = 31; + if (g > 31) + g = 31; + if (b > 31) + b = 31; + break; + } + + *pal = RGB2(r, g, b); + } + } +} + +u16 ConvertColorToGrayscale(u16 *color) +{ + s32 clr = *color; + s32 r = clr & 0x1F; + s32 g = (clr >> 5) & 0x1F; + s32 b = (clr >> 10) & 0x1F; + s32 gray = (r * Q_8_8(0.3) + g * Q_8_8(0.59) + b * Q_8_8(0.1133)) >> 8; + return RGB2(gray, gray, gray); +} + +// The dark colors are the colored edges of the Cool painting effect. +// Everything else is white. +u16 ConvertCoolColor(u16 *color, u8 personality) +{ + u16 red = *color & 0x1F; + u16 green = (*color >> 5) & 0x1F; + u16 blue = (*color >> 10) & 0x1F; + + if (red < 17 && green < 17 && blue < 17) + return GetCoolColorFromPersonality(personality); + else + return RGB_WHITE; +} + +// Based on the given value, which comes from the first 8 bits of +// the mon's personality value, return a color. +u16 GetCoolColorFromPersonality(u8 personality) +{ + u16 red = 0; + u16 green = 0; + u16 blue = 0; + u8 strength = (personality / 6) % 3; + u8 colorType = personality % 6; + + switch (colorType) + { + case 0: + // Teal color + green = 21 - strength; + blue = green; + red = 0; + break; + case 1: + // Yellow color + blue = 0; + red = 21 - strength; + green = red; + break; + case 2: + // Purple color + blue = 21 - strength; + green = 0; + red = blue; + break; + case 3: + // Red color + blue = 0; + green = 0; + red = 23 - strength; + break; + case 4: + // Blue color + blue = 23 - strength; + green = 0; + red = 0; + break; + case 5: + // Green color + blue = 0; + green = 23 - strength; + red = 0; + break; + } + + return RGB2(red, green, blue); +} + +u16 ConvertToBlackOrWhite(u16 *color) +{ + u16 red = *color & 0x1F; + u16 green = (*color >> 5) & 0x1F; + u16 blue = (*color >> 10) & 0x1F; + + if (red < 17 && green < 17 && blue < 17) + return RGB_BLACK; + else + return RGB_WHITE; +} + +u16 sub_8125C98(u16 *colorA, u16 *colorB) +{ + if (*colorA) + { + if (*colorA & 0x8000) + return 0x8000; + if (*colorB & 0x8000) + return RGB_BLACK; + + return *colorA; + } + + return RGB_BLACK; +} + +u16 InvertColor(u16 *color) +{ + u16 red = *color & 0x1F; + u16 green = (*color >> 5) & 0x1F; + u16 blue = (*color >> 10) & 0x1F; + + red = 31 - red; + green = 31 - green; + blue = 31 - blue; + + return RGB2(red, green, blue); +} + +u16 sub_8125CF4(u16 *a0, u16 *a1) +{ + u16 sp0[2][3]; + u16 spC[3]; + u8 r4; + u16 r2; + u16 r, g, b; + + if (*a0 == *a1) + return *a1; + + sp0[0][0] = (*a0 >> 0) & 0x1F; + sp0[0][1] = (*a0 >> 5) & 0x1F; + sp0[0][2] = (*a0 >> 10) & 0x1F; + sp0[1][0] = (*a1 >> 0) & 0x1F; + sp0[1][1] = (*a1 >> 5) & 0x1F; + sp0[1][2] = (*a1 >> 10) & 0x1F; + + if (sp0[0][0] > 25 && sp0[0][1] > 25 && sp0[0][2] > 25) + return *a1; + if (sp0[1][0] > 25 && sp0[1][1] > 25 && sp0[1][2] > 25) + return *a1; + + for (r4 = 0; r4 < 3; r4++) + { + if (sp0[0][r4] > sp0[1][r4]) + spC[r4] = sp0[0][r4] - sp0[1][r4]; + else + spC[r4] = sp0[1][r4] - sp0[0][r4]; + } + + if (spC[0] >= spC[1]) + { + if (spC[0] >= spC[2]) + r2 = spC[0]; + else if (spC[1] >= spC[2]) + r2 = spC[1]; + else + r2 = spC[2]; + } + else + { + if (spC[1] >= spC[2]) + r2 = spC[1]; + else if (spC[2] >= spC[0]) + r2 = spC[2]; + else + r2 = spC[0]; + } + + r = (sp0[1][0] * (31 - r2 / 2)) / 31; + g = (sp0[1][1] * (31 - r2 / 2)) / 31; + b = (sp0[1][2] * (31 - r2 / 2)) / 31; + return RGB2(r, g, b); +} + +u16 sub_8125E18(u16 * a0, u16 * a1, u16 * a2) +{ + u16 red, green, blue; + u16 avg0, avg1, avg2; + u16 diff1, diff2; + u32 minimum; + u16 factor; + + if (*a0 == *a1 && *a2 == *a1) + return *a1; + + red = (*a1 >> 0) & 0x1F; + green = (*a1 >> 5) & 0x1F; + blue = (*a1 >> 10) & 0x1F; + + avg0 = (((*a0 >> 0) & 0x1F) + ((*a0 >> 5) & 0x1F) + ((*a0 >> 10) & 0x1F)) / 3; + avg1 = (((*a1 >> 0) & 0x1F) + ((*a1 >> 5) & 0x1F) + ((*a1 >> 10) & 0x1F)) / 3; + avg2 = (((*a2 >> 0) & 0x1F) + ((*a2 >> 5) & 0x1F) + ((*a2 >> 10) & 0x1F)) / 3; + + if (avg0 == avg1 && avg2 == avg1) + return *a1; + + if (avg0 > avg1) + diff1 = avg0 - avg1; + else + diff1 = avg1 - avg0; + + if (avg2 > avg1) + diff2 = avg2 - avg1; + else + diff2 = avg1 - avg2; + + if (diff1 >= diff2) + minimum = diff1; + else + minimum = diff2; + + factor = 31 - minimum / 2; + red = red * factor / 31; + green = green * factor / 31; + blue = blue * factor / 31; + return RGB2(red, green, blue); +} + +u16 sub_8125F38(u16 *a0, u16 *a1, u16 *a2) +{ + u16 red, green, blue; + u16 avg0, avg1, avg2; + u16 diff1, diff2; + u32 minimum; + u16 factor; + + if (*a0 == *a1 && *a2 == *a1) + return *a1; + + red = (*a1 >> 0) & 0x1F; + green = (*a1 >> 5) & 0x1F; + blue = (*a1 >> 10) & 0x1F; + + avg0 = (((*a0 >> 0) & 0x1F) + ((*a0 >> 5) & 0x1F) + ((*a0 >> 10) & 0x1F)) / 3; + avg1 = (((*a1 >> 0) & 0x1F) + ((*a1 >> 5) & 0x1F) + ((*a1 >> 10) & 0x1F)) / 3; + avg2 = (((*a2 >> 0) & 0x1F) + ((*a2 >> 5) & 0x1F) + ((*a2 >> 10) & 0x1F)) / 3; + + if (avg0 == avg1 && avg2 == avg1) + return *a1; + + if (avg0 > avg1) + diff1 = avg0 - avg1; + else + diff1 = avg1 - avg0; + + if (avg2 > avg1) + diff2 = avg2 - avg1; + else + diff2 = avg1 - avg2; + + if (diff1 >= diff2) + minimum = diff1; + else + minimum = diff2; + + factor = 31 - minimum; + red = red * factor / 31; + green = green * factor / 31; + blue = blue * factor / 31; + return RGB2(red, green, blue); +} + +/* +void sub_8126058(struct Unk030061A0 *arg0) +{ + u16 i, j, k; + u8 r5 = arg0->var_1D >> 3; + u8 var_24 = arg0->var_1E >> 3; + u16 (*var_2C)[][32] = arg0->var_4; + u32 var_28 = arg0->var_10; + + if (arg0->var_16 == 2) + { + for (i = 0; i < var_24; i++) + { + for (j = 0; j < r5; j++) + { + for (k = 0; k < 8; k++) + { + (*var_2C)[][]; + } + } + } + } +} +*/ diff --git a/src/credits.c b/src/credits.c index 5e52e5fb7..3639d36e4 100644 --- a/src/credits.c +++ b/src/credits.c @@ -2219,8 +2219,8 @@ static void sub_8177050(struct Sprite *sprite) } else { - SetGpuReg(REG_OFFSET_BLDCNT, 0xF40); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 0)); sprite->oam.objMode = 1; sprite->data[3] = 16; sprite->data[0] += 1; diff --git a/src/dark.c b/src/dark.c index efa6e9498..ecd466da8 100644 --- a/src/dark.c +++ b/src/dark.c @@ -357,22 +357,22 @@ void sub_8113A90(struct Sprite *sprite) switch (gBattleAnimArgs[1]) { case 0: - sprite->pos1.x = sub_80A861C(battler, 5) - 8; - sprite->pos1.y = sub_80A861C(battler, 2) + 8; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_RIGHT) - 8; + sprite->pos1.y = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_TOP) + 8; break; case 1: - sprite->pos1.x = sub_80A861C(battler, 5) - 14; - sprite->pos1.y = sub_80A861C(battler, 2) + 16; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_RIGHT) - 14; + sprite->pos1.y = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_TOP) + 16; break; case 2: - sprite->pos1.x = sub_80A861C(battler, 4) + 8; - sprite->pos1.y = sub_80A861C(battler, 2) + 8; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_LEFT) + 8; + sprite->pos1.y = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_TOP) + 8; StartSpriteAffineAnim(sprite, 1); xOffset = -20; break; case 3: - sprite->pos1.x = sub_80A861C(battler, 4) + 14; - sprite->pos1.y = sub_80A861C(battler, 2) + 16; + sprite->pos1.x = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_LEFT) + 14; + sprite->pos1.y = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_TOP) + 16; StartSpriteAffineAnim(sprite, 1); xOffset = -20; break; @@ -403,7 +403,7 @@ void sub_8113BAC(u8 taskId) struct Task *task = &gTasks[taskId]; task->data[7] = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_Y) + 31; - task->data[6] = sub_80A861C(gBattleAnimAttacker, 2) - 7; + task->data[6] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_TOP) - 7; task->data[5] = task->data[7]; task->data[4] = task->data[6]; task->data[13] = (task->data[7] - task->data[6]) << 8; @@ -576,7 +576,7 @@ void sub_8113E78(u8 taskId) break; case 2: task->data[7] = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y) + 31; - task->data[6] = sub_80A861C(gBattleAnimTarget, 2) - 7; + task->data[6] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_TOP) - 7; task->data[13] = (task->data[7] - task->data[6]) << 8; x = GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X); task->data[14] = x - 4; diff --git a/src/daycare.c b/src/daycare.c index 26fa0251e..6bdbd987e 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -636,7 +636,7 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru u16 i, j; numSharedParentMoves = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { sHatchedEggMotherMoves[i] = 0; sHatchedEggFatherMoves[i] = 0; @@ -648,7 +648,7 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru sHatchedEggLevelUpMoves[i] = 0; numLevelUpMoves = GetLevelUpMovesBySpecies(GetMonData(egg, MON_DATA_SPECIES), sHatchedEggLevelUpMoves); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { sHatchedEggFatherMoves[i] = GetBoxMonData(father, MON_DATA_MOVE1 + i); sHatchedEggMotherMoves[i] = GetBoxMonData(mother, MON_DATA_MOVE1 + i); @@ -656,7 +656,7 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru numEggMoves = GetEggMoves(egg, sHatchedEggEggMoves); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFatherMoves[i] != MOVE_NONE) { @@ -675,7 +675,7 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru break; } } - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFatherMoves[i] != MOVE_NONE) { @@ -689,18 +689,18 @@ static void BuildEggMoveset(struct Pokemon *egg, struct BoxPokemon *father, stru } } } - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFatherMoves[i] == MOVE_NONE) break; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (sHatchedEggFatherMoves[i] == sHatchedEggMotherMoves[j] && sHatchedEggFatherMoves[i] != MOVE_NONE) sHatchedEggFinalMoves[numSharedParentMoves++] = sHatchedEggFatherMoves[i]; } } - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (sHatchedEggFinalMoves[i] == MOVE_NONE) break; diff --git a/src/decompress.c b/src/decompress.c index ed2f7a0bb..949b96990 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -66,7 +66,7 @@ void LoadCompressedSpritePaletteOverrideBuffer(const struct CompressedSpritePale void DecompressPicFromTable(const struct CompressedSpriteSheet *src, void* buffer, s32 species) { - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) LZ77UnCompWram(gMonFrontPicTable[0].data, buffer); else LZ77UnCompWram(src->data, buffer); @@ -102,7 +102,7 @@ void LoadSpecialPokePic(const struct CompressedSpriteSheet *src, void *dest, s32 else LZ77UnCompWram(gMonFrontPicTable[i].data, dest); } - else if (species > SPECIES_EGG) // is species unknown? draw the ? icon + else if (species > NUM_SPECIES) // is species unknown? draw the ? icon LZ77UnCompWram(gMonFrontPicTable[0].data, dest); else LZ77UnCompWram(src->data, dest); @@ -499,7 +499,7 @@ bool8 LoadCompressedSpritePaletteUsingHeap(const struct CompressedSpritePalette void DecompressPicFromTable_2(const struct CompressedSpriteSheet *src, void* buffer, s32 species) // a copy of DecompressPicFromTable { - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) LZ77UnCompWram(gMonFrontPicTable[0].data, buffer); else LZ77UnCompWram(src->data, buffer); @@ -523,7 +523,7 @@ void LoadSpecialPokePic_2(const struct CompressedSpriteSheet *src, void *dest, s else LZ77UnCompWram(gMonFrontPicTable[i].data, dest); } - else if (species > SPECIES_EGG) // is species unknown? draw the ? icon + else if (species > NUM_SPECIES) // is species unknown? draw the ? icon LZ77UnCompWram(gMonFrontPicTable[0].data, dest); else LZ77UnCompWram(src->data, dest); @@ -546,7 +546,7 @@ void HandleLoadSpecialPokePic_2(const struct CompressedSpriteSheet *src, void *d void DecompressPicFromTable_DontHandleDeoxys(const struct CompressedSpriteSheet *src, void* buffer, s32 species) { - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) LZ77UnCompWram(gMonFrontPicTable[0].data, buffer); else LZ77UnCompWram(src->data, buffer); @@ -581,7 +581,7 @@ void LoadSpecialPokePic_DontHandleDeoxys(const struct CompressedSpriteSheet *src else LZ77UnCompWram(gMonFrontPicTable[i].data, dest); } - else if (species > SPECIES_EGG) // is species unknown? draw the ? icon + else if (species > NUM_SPECIES) // is species unknown? draw the ? icon LZ77UnCompWram(gMonFrontPicTable[0].data, dest); else LZ77UnCompWram(src->data, dest); diff --git a/src/decoration.c b/src/decoration.c index addca6954..438f2cbd1 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1131,7 +1131,7 @@ void sub_8127ACC(u8 taskId) void sub_8127B04(u8 taskId) { DrawWholeMapView(); - Overworld_SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, gTasks[taskId].data[3], gTasks[taskId].data[4]); + SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, gTasks[taskId].data[3], gTasks[taskId].data[4]); WarpIntoMap(); } diff --git a/src/dragon.c b/src/dragon.c index 68577988e..4a2ac1c51 100644 --- a/src/dragon.c +++ b/src/dragon.c @@ -274,8 +274,8 @@ void sub_8113250(struct Sprite *sprite) sprite->data[4] = 0; sprite->data[5] = 1; sprite->data[6] = gBattleAnimArgs[0]; - r5 = sub_80A861C(gBattlerAttacker, 0); - r0 = sub_80A861C(gBattlerAttacker, 1); + r5 = GetBattlerSpriteCoordAttr(gBattlerAttacker, BATTLER_COORD_ATTR_HEIGHT); + r0 = GetBattlerSpriteCoordAttr(gBattlerAttacker, BATTLER_COORD_ATTR_WIDTH); if (r5 > r0) sprite->data[7] = r5 / 2; else diff --git a/src/easy_chat.c b/src/easy_chat.c index c4bc02e42..c84895df5 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -364,7 +364,7 @@ void easy_chat_input_maybe(void) default: return; } - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_811A20C(gSpecialVar_0x8004, words, CB2_ReturnToFieldContinueScript, sizeParam); } @@ -383,7 +383,7 @@ static void sub_811A7E4(void) { lilycoveLady = &gSaveBlock1Ptr->lilycoveLady; lilycoveLady->quiz.unk_016 = -1; - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_811A8F0(); } return; diff --git a/src/egg_hatch.c b/src/egg_hatch.c index eb7772a3c..e1d94889a 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -375,7 +375,7 @@ static void AddHatchedMonToParty(u8 id) caughtLvl = 0; SetMonData(mon, MON_DATA_MET_LEVEL, &caughtLvl); - mapNameID = sav1_map_get_name(); + mapNameID = GetCurrentRegionMapSectionId(); SetMonData(mon, MON_DATA_MET_LOCATION, &mapNameID); MonRestorePP(mon); @@ -467,7 +467,7 @@ static void Task_EggHatch(u8 taskID) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_EggHatch_0); gFieldCallback = sub_80AF168; DestroyTask(taskID); @@ -498,7 +498,7 @@ static void CB2_EggHatch_0(void) ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(1, BG_ATTR_PRIORITY, 2); SetBgTilemapBuffer(1, Alloc(0x1000)); SetBgTilemapBuffer(0, Alloc(0x2000)); diff --git a/src/event_obj_lock.c b/src/event_obj_lock.c index 8c324ea82..566b4931d 100644 --- a/src/event_obj_lock.c +++ b/src/event_obj_lock.c @@ -6,6 +6,7 @@ #include "script_movement.h" #include "task.h" #include "trainer_see.h" +#include "constants/event_objects.h" bool8 walkrun_is_standing_still(void) { @@ -89,20 +90,20 @@ void LockSelectedEventObject(void) void ScriptUnfreezeEventObjects(void) { - u8 objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + u8 playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); } void sub_8098524(void) { - u8 objectId; + u8 playerObjectId; if (gEventObjects[gSelectedEventObject].active) EventObjectClearHeldMovementIfFinished(&gEventObjects[gSelectedEventObject]); - objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); } diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ffa8f53c9..7cee717bf 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -6420,7 +6420,7 @@ bool8 MovementAction_FacePlayer_Step0(struct EventObject *eventObject, struct Sp { u8 playerObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(0xFF, 0, 0, &playerObjectId)) + if (!TryGetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0, &playerObjectId)) { FaceDirection(eventObject, sprite, GetDirectionToFace(eventObject->currentCoords.x, eventObject->currentCoords.y, gEventObjects[playerObjectId].currentCoords.x, gEventObjects[playerObjectId].currentCoords.y)); } @@ -6432,7 +6432,7 @@ bool8 MovementAction_FaceAwayPlayer_Step0(struct EventObject *eventObject, struc { u8 playerObjectId; - if (!TryGetEventObjectIdByLocalIdAndMap(0xFF, 0, 0, &playerObjectId)) + if (!TryGetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0, &playerObjectId)) { FaceDirection(eventObject, sprite, GetOppositeDirection(GetDirectionToFace(eventObject->currentCoords.x, eventObject->currentCoords.y, gEventObjects[playerObjectId].currentCoords.x, gEventObjects[playerObjectId].currentCoords.y))); } diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 1dc0f11e4..c97e2d10f 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -1476,20 +1476,20 @@ static void InitMovingBackgroundTask(bool8 isLink) if (!isLink) { - SetGpuReg(REG_OFFSET_BLDCNT, 0x442); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG2); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(8, 8)); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG2_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); - SetBgAttribute(innerBgId, BG_CTRL_ATTR_MOSAIC, 2); - SetBgAttribute(outerBgId, BG_CTRL_ATTR_MOSAIC, 2); + SetBgAttribute(innerBgId, BG_ATTR_PRIORITY, 2); + SetBgAttribute(outerBgId, BG_ATTR_PRIORITY, 2); ShowBg(1); ShowBg(2); } else { - SetGpuReg(REG_OFFSET_BLDCNT, 0x842); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG3); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(8, 8)); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG3_ON | DISPCNT_BG1_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); } @@ -1526,8 +1526,8 @@ static void sub_8140174(void) gBattle_BG1_X = 0; gBattle_BG1_Y = 0; gBattle_BG2_X = 0; - SetBgAttribute(1, BG_CTRL_ATTR_MOSAIC, sub_80391E0(1, 5)); - SetBgAttribute(2, BG_CTRL_ATTR_MOSAIC, sub_80391E0(2, 5)); + SetBgAttribute(1, BG_ATTR_PRIORITY, sub_80391E0(1, 5)); + SetBgAttribute(2, BG_ATTR_PRIORITY, sub_80391E0(2, 5)); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG3_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP); Free(sEvoMovingBgPtr); } diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 3774ef2b3..e6a859c84 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -27,7 +27,9 @@ #include "trainer_see.h" #include "wild_encounter.h" #include "constants/bg_event_constants.h" +#include "constants/event_objects.h" #include "constants/map_types.h" +#include "constants/maps.h" #include "constants/songs.h" extern bool32 sub_8196034(void); @@ -50,12 +52,12 @@ static bool32 TrySetupDiveDownScript(void); static bool32 TrySetupDiveEmergeScript(void); static bool8 TryStartStepBasedScript(struct MapPosition *, u16, u16); static bool8 CheckStandardWildEncounter(u16); -static bool8 mapheader_run_first_tag2_script_list_match_conditionally(struct MapPosition *, u16, u8); +static bool8 TryArrowWarp(struct MapPosition *, u16, u8); static bool8 IsWarpMetatileBehavior(u16); static bool8 IsArrowWarpMetatileBehavior(u16, u8); static s8 GetWarpEventAtMapPosition(struct MapHeader *, struct MapPosition *); -static void sub_809CEB0(struct MapHeader *, s8, struct MapPosition *); -static bool8 map_warp_consider_2_to_inside(struct MapPosition *, u16, u8); +static void SetupWarp(struct MapHeader *, s8, struct MapPosition *); +static bool8 TryDoorWarp(struct MapPosition *, u16, u8); static s8 GetWarpEventAtPosition(struct MapHeader *, u16, u16, u8); static u8 *GetCoordEventScriptAtPosition(struct MapHeader *, u16, u16, u8); static struct BgEvent *GetBackgroundEventAtPosition(struct MapHeader *, u16, u16, u8); @@ -72,8 +74,8 @@ void FieldClearPlayerInput(struct FieldInput *input) input->checkStandardWildEncounter = FALSE; input->pressedStartButton = FALSE; input->pressedSelectButton = FALSE; - input->input_field_0_4 = FALSE; - input->input_field_0_5 = FALSE; + input->heldDirection = FALSE; + input->heldDirection2 = FALSE; input->tookStep = FALSE; input->pressedBButton = FALSE; input->input_field_1_0 = FALSE; @@ -105,8 +107,8 @@ void FieldGetPlayerInput(struct FieldInput *input, u16 newKeys, u16 heldKeys) if (heldKeys & (DPAD_UP | DPAD_DOWN | DPAD_LEFT | DPAD_RIGHT)) { - input->input_field_0_4 = TRUE; - input->input_field_0_5 = TRUE; + input->heldDirection = TRUE; + input->heldDirection2 = TRUE; } } @@ -152,15 +154,15 @@ int ProcessPlayerFieldInput(struct FieldInput *input) if (input->tookStep) { IncrementGameStat(GAME_STAT_STEPS); - increment_var_x4026_on_birth_island_modulo_100(); + IncrementBirthIslandRockStepCount(); if (TryStartStepBasedScript(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; } if (input->checkStandardWildEncounter && CheckStandardWildEncounter(metatileBehavior) == TRUE) return TRUE; - if (input->input_field_0_4 && input->dpadDirection == playerDirection) + if (input->heldDirection && input->dpadDirection == playerDirection) { - if (mapheader_run_first_tag2_script_list_match_conditionally(&position, metatileBehavior, playerDirection) == TRUE) + if (TryArrowWarp(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; } @@ -169,9 +171,9 @@ int ProcessPlayerFieldInput(struct FieldInput *input) if (input->pressedAButton && TryStartInteractionScript(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; - if (input->input_field_0_5 && input->dpadDirection == playerDirection) + if (input->heldDirection2 && input->dpadDirection == playerDirection) { - if (map_warp_consider_2_to_inside(&position, metatileBehavior, playerDirection) == TRUE) + if (TryDoorWarp(&position, metatileBehavior, playerDirection) == TRUE) return TRUE; } if (input->pressedAButton && TrySetupDiveDownScript() == TRUE) @@ -265,7 +267,7 @@ const u8 *GetInteractedLinkPlayerScript(struct MapPosition *position, u8 metatil else eventObjectId = GetEventObjectIdByXYZ(position->x + gDirectionToVectors[direction].x, position->y + gDirectionToVectors[direction].y, position->height); - if (eventObjectId == 16 || gEventObjects[eventObjectId].localId == 0xFF) + if (eventObjectId == EVENT_OBJECTS_COUNT || gEventObjects[eventObjectId].localId == EVENT_OBJ_ID_PLAYER) return NULL; for (i = 0; i < 4; i++) @@ -286,14 +288,14 @@ static const u8 *GetInteractedEventObjectScript(struct MapPosition *position, u8 const u8 *script; eventObjectId = GetEventObjectIdByXYZ(position->x, position->y, position->height); - if (eventObjectId == 16 || gEventObjects[eventObjectId].localId == 0xFF) + if (eventObjectId == EVENT_OBJECTS_COUNT || gEventObjects[eventObjectId].localId == EVENT_OBJ_ID_PLAYER) { if (MetatileBehavior_IsCounter(metatileBehavior) != TRUE) return NULL; // Look for an event object on the other side of the counter. eventObjectId = GetEventObjectIdByXYZ(position->x + gDirectionToVectors[direction].x, position->y + gDirectionToVectors[direction].y, position->height); - if (eventObjectId == 16 || gEventObjects[eventObjectId].localId == 0xFF) + if (eventObjectId == EVENT_OBJECTS_COUNT || gEventObjects[eventObjectId].localId == EVENT_OBJ_ID_PLAYER) return NULL; } @@ -302,13 +304,10 @@ static const u8 *GetInteractedEventObjectScript(struct MapPosition *position, u8 gSpecialVar_Facing = direction; if (InTrainerHill() == TRUE) - { script = sub_81D62AC(); - } else - { script = GetEventObjectScriptPointerByEventObjectId(eventObjectId); - } + script = GetRamScript(gSpecialVar_LastTalked, script); return script; } @@ -379,7 +378,7 @@ static const u8 *GetInteractedMetatileScript(struct MapPosition *position, u8 me if (MetatileBehavior_IsCableBoxResults1(metatileBehavior) == TRUE) return EventScript_CableBoxResults; if (MetatileBehavior_IsPokeblockFeeder(metatileBehavior) == TRUE) - return EventScript_2A4BAC; + return EventScript_PokeBlockFeeder; if (MetatileBehavior_IsTrickHousePuzzleDoor(metatileBehavior) == TRUE) return Route110_TrickHouseEntrance_EventScript_26A22A; if (MetatileBehavior_IsRegionMap(metatileBehavior) == TRUE) @@ -685,15 +684,15 @@ static bool8 CheckStandardWildEncounter(u16 metatileBehavior) return FALSE; } -static bool8 mapheader_run_first_tag2_script_list_match_conditionally(struct MapPosition *position, u16 metatileBehavior, u8 direction) +static bool8 TryArrowWarp(struct MapPosition *position, u16 metatileBehavior, u8 direction) { s8 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE && warpEventId != -1) { StoreInitialPlayerAvatarState(); - sub_809CEB0(&gMapHeader, warpEventId, position); - sub_80AF734(); + SetupWarp(&gMapHeader, warpEventId, position); + DoWarp(); return TRUE; } return FALSE; @@ -706,7 +705,7 @@ static bool8 TryStartWarpEventScript(struct MapPosition *position, u16 metatileB if (warpEventId != -1 && IsWarpMetatileBehavior(metatileBehavior) == TRUE) { StoreInitialPlayerAvatarState(); - sub_809CEB0(&gMapHeader, warpEventId, position); + SetupWarp(&gMapHeader, warpEventId, position); if (MetatileBehavior_IsEscalator(metatileBehavior) == TRUE) { sub_80AF80C(metatileBehavior); @@ -742,7 +741,7 @@ static bool8 TryStartWarpEventScript(struct MapPosition *position, u16 metatileB sub_80AF87C(); return TRUE; } - sub_80AF734(); + DoWarp(); return TRUE; } return FALSE; @@ -785,7 +784,7 @@ static s8 GetWarpEventAtMapPosition(struct MapHeader *mapHeader, struct MapPosit return GetWarpEventAtPosition(mapHeader, position->x - 7, position->y - 7, position->height); } -static void sub_809CEB0(struct MapHeader *unused, s8 warpEventId, struct MapPosition *position) +static void SetupWarp(struct MapHeader *unused, s8 warpEventId, struct MapPosition *position) { const struct WarpEvent *warpEvent; @@ -818,23 +817,23 @@ static void sub_809CEB0(struct MapHeader *unused, s8 warpEventId, struct MapPosi warpEvent = &gMapHeader.events->warps[warpEventId]; } - if (warpEvent->mapNum == 0x7F) + if (warpEvent->mapNum == MAP_NUM(NONE)) { - copy_saved_warp2_bank_and_enter_x_to_warp1(warpEvent->warpId); + SetWarpDestinationToDynamicWarp(warpEvent->warpId); } else { const struct MapHeader *mapHeader; - warp1_set_2(warpEvent->mapGroup, warpEvent->mapNum, warpEvent->warpId); - sub_8084D5C(position->x, position->y); + SetWarpDestinationToMapWarp(warpEvent->mapGroup, warpEvent->mapNum, warpEvent->warpId); + UpdateEscapeWarp(position->x, position->y); mapHeader = Overworld_GetMapHeaderByGroupAndId(warpEvent->mapGroup, warpEvent->mapNum); - if (mapHeader->events->warps[warpEvent->warpId].mapNum == 0x7F) - saved_warp2_set(mapHeader->events->warps[warpEventId].warpId, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, warpEventId); + if (mapHeader->events->warps[warpEvent->warpId].mapNum == MAP_NUM(NONE)) + SetDynamicWarp(mapHeader->events->warps[warpEventId].warpId, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, warpEventId); } } -static bool8 map_warp_consider_2_to_inside(struct MapPosition *position, u16 metatileBehavior, u8 direction) +static bool8 TryDoorWarp(struct MapPosition *position, u16 metatileBehavior, u8 direction) { s8 warpEventId; @@ -842,17 +841,18 @@ static bool8 map_warp_consider_2_to_inside(struct MapPosition *position, u16 met { if (MetatileBehavior_IsOpenSecretBaseDoor(metatileBehavior) == TRUE) { - sub_80E9668(position, gMapHeader.events); + WarpIntoSecretBase(position, gMapHeader.events); return TRUE; } + if (MetatileBehavior_IsWarpDoor(metatileBehavior) == TRUE) { warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); if (warpEventId != -1 && IsWarpMetatileBehavior(metatileBehavior) == TRUE) { StoreInitialPlayerAvatarState(); - sub_809CEB0(&gMapHeader, warpEventId, position); - sub_80AF7D0(); + SetupWarp(&gMapHeader, warpEventId, position); + DoDoorWarp(); return TRUE; } } @@ -947,7 +947,7 @@ bool8 dive_warp(struct MapPosition *position, u16 metatileBehavior) if (SetDiveWarpEmerge(position->x - 7, position->y - 7)) { StoreInitialPlayerAvatarState(); - sp13E_warp_to_last_warp(); + DoDiveWarp(); PlaySE(SE_W291); return TRUE; } @@ -957,7 +957,7 @@ bool8 dive_warp(struct MapPosition *position, u16 metatileBehavior) if (SetDiveWarpDive(position->x - 7, position->y - 7)) { StoreInitialPlayerAvatarState(); - sp13E_warp_to_last_warp(); + DoDiveWarp(); PlaySE(SE_W291); return TRUE; } @@ -1002,6 +1002,6 @@ int SetCableClubWarp(void) GetPlayerMovementDirection(); //unnecessary GetPlayerPosition(&position); MapGridGetMetatileBehaviorAt(position.x, position.y); //unnecessary - sub_809CEB0(&gMapHeader, GetWarpEventAtMapPosition(&gMapHeader, &position), &position); + SetupWarp(&gMapHeader, GetWarpEventAtMapPosition(&gMapHeader, &position), &position); return 0; } diff --git a/src/field_effect.c b/src/field_effect.c index 4e6f81484..badf57b16 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -12,6 +12,7 @@ #include "fldeff.h" #include "gpu_regs.h" #include "main.h" +#include "mirage_tower.h" #include "menu.h" #include "metatile_behavior.h" #include "overworld.h" @@ -229,7 +230,7 @@ static void sub_80B9A60(struct Task *); static void sub_80B9BE8(u8 taskId); static void sub_80B9DB8(struct Sprite* sprite); -static void sub_80B9EDC(u8 taskId); +static void Fldeff_MoveDeoxysRock_Step(u8 taskId); // Static RAM declarations @@ -2170,7 +2171,7 @@ static void EscapeRopeFieldEffect_Step1(struct Task *task) if (task->data[14] == 0 && !gPaletteFade.active && BGMusicStopped() == TRUE) { SetEventObjectDirection(eventObject, task->data[15]); - sub_8084E14(); + SetWarpDestinationToEscapeWarp(); WarpIntoMap(); gFieldCallback = mapldr_080859D4; SetMainCallback2(CB2_LoadMap); @@ -2325,13 +2326,13 @@ static void TeleportFieldEffectTask4(struct Task *task) { if (task->data[5] == FALSE) { - sub_81BE72C(); + ClearMirageTowerPulseBlendEffect(); task->data[5] = TRUE; } if (BGMusicStopped() == TRUE) { - Overworld_SetWarpDestToLastHealLoc(); + SetWarpDestinationToLastHealLocation(); WarpIntoMap(); SetMainCallback2(CB2_LoadMap); gFieldCallback = mapldr_08085D88; @@ -2442,7 +2443,7 @@ static void sub_80B8410(struct Task *task) bool8 FldEff_FieldMoveShowMon(void) { u8 taskId; - if (is_map_type_1_2_3_5_or_6(Overworld_GetMapTypeOfSaveblockLocation()) == TRUE) + if (is_map_type_1_2_3_5_or_6(GetCurrentMapType()) == TRUE) { taskId = CreateTask(sub_80B8554, 0xff); } else @@ -3643,7 +3644,7 @@ static void sub_80B9DB8(struct Sprite* sprite) DestroySprite(sprite); } -bool8 sub_80B9E28(struct Sprite* sprite) +bool8 Fldeff_MoveDeoxysRock(struct Sprite* sprite) { u8 eventObjectIdBuffer; if (!TryGetEventObjectIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2], &eventObjectIdBuffer)) @@ -3657,7 +3658,7 @@ bool8 sub_80B9E28(struct Sprite* sprite) xPos = (gFieldEffectArguments[3] - xPos) * 16; yPos = (gFieldEffectArguments[4] - yPos) * 16; ShiftEventObjectCoords(object, gFieldEffectArguments[3] + 7, gFieldEffectArguments[4] + 7); - taskId = CreateTask(sub_80B9EDC, 0x50); + taskId = CreateTask(Fldeff_MoveDeoxysRock_Step, 0x50); gTasks[taskId].data[1] = object->spriteId; gTasks[taskId].data[2] = gSprites[object->spriteId].pos1.x + xPos; gTasks[taskId].data[3] = gSprites[object->spriteId].pos1.y + yPos; @@ -3667,7 +3668,7 @@ bool8 sub_80B9E28(struct Sprite* sprite) return FALSE; } -static void sub_80B9EDC(u8 taskId) +static void Fldeff_MoveDeoxysRock_Step(u8 taskId) { // BUG: Possible divide by zero s16 *data = gTasks[taskId].data; diff --git a/src/field_message_box.c b/src/field_message_box.c index 46da9e9e5..5e23b5f6b 100755 --- a/src/field_message_box.c +++ b/src/field_message_box.c @@ -8,21 +8,21 @@ extern bool32 sub_8196094(void); extern void sub_8196080(u8*); -EWRAM_DATA u8 gUnknown_020375BC = 0; +static EWRAM_DATA u8 sFieldMessageBoxMode = 0; -void textbox_fdecode_auto_and_task_add(u8*, int); -void textbox_auto_and_task_add(void); +static void textbox_fdecode_auto_and_task_add(u8*, bool32); +static void textbox_auto_and_task_add(void); -void sub_8098128(void) +void InitFieldMessageBox(void) { - gUnknown_020375BC = 0; + sFieldMessageBoxMode = 0; gTextFlags.canABSpeedUpPrint = 0; gTextFlags.useAlternateDownArrow = 0; gTextFlags.autoScroll = 0; gTextFlags.forceMidTextSpeed = 0; } -void sub_8098154(u8 taskId) +static void sub_8098154(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -39,18 +39,18 @@ void sub_8098154(u8 taskId) case 2: if (RunTextPrintersAndIsPrinter0Active() != 1) { - gUnknown_020375BC = 0; + sFieldMessageBoxMode = 0; DestroyTask(taskId); } } } -void task_add_textbox(void) +static void task_add_textbox(void) { CreateTask(sub_8098154, 0x50); } -void task_del_textbox(void) +static void task_del_textbox(void) { u8 taskId = FindTaskIdByFunc(sub_8098154); if (taskId != 0xFF) @@ -59,10 +59,10 @@ void task_del_textbox(void) bool8 ShowFieldMessage(u8 *str) { - if (gUnknown_020375BC != 0) + if (sFieldMessageBoxMode != 0) return FALSE; textbox_fdecode_auto_and_task_add(str, 1); - gUnknown_020375BC = 2; + sFieldMessageBoxMode = 2; return TRUE; } @@ -70,57 +70,57 @@ void sub_8098214(u8 taskId) { if (!sub_8196094()) { - gUnknown_020375BC = 0; + sFieldMessageBoxMode = 0; DestroyTask(taskId); } } bool8 sub_8098238(u8 *str) { - if (gUnknown_020375BC != 0) + if (sFieldMessageBoxMode != 0) return FALSE; StringExpandPlaceholders(gStringVar4, str); CreateTask(sub_8098214, 0); sub_8196080(str); - gUnknown_020375BC = 2; + sFieldMessageBoxMode = 2; return TRUE; } bool8 ShowFieldAutoScrollMessage(u8 *str) { - if (gUnknown_020375BC != 0) + if (sFieldMessageBoxMode != 0) return FALSE; - gUnknown_020375BC = 3; + sFieldMessageBoxMode = 3; textbox_fdecode_auto_and_task_add(str, 0); return TRUE; } bool8 sub_80982A0(u8 *str) { - gUnknown_020375BC = 3; + sFieldMessageBoxMode = 3; textbox_fdecode_auto_and_task_add(str, 1); return TRUE; } bool8 sub_80982B8(void) { - if (gUnknown_020375BC != 0) + if (sFieldMessageBoxMode != 0) return FALSE; - gUnknown_020375BC = 2; + sFieldMessageBoxMode = 2; textbox_auto_and_task_add(); return TRUE; } -void textbox_fdecode_auto_and_task_add(u8* str, int a) +static void textbox_fdecode_auto_and_task_add(u8* str, bool32 allowSkippingDelayWithButtonPress) { StringExpandPlaceholders(gStringVar4, str); - AddTextPrinterForMessage(a); + AddTextPrinterForMessage(allowSkippingDelayWithButtonPress); task_add_textbox(); } -void textbox_auto_and_task_add(void) +static void textbox_auto_and_task_add(void) { - AddTextPrinterForMessage(1); + AddTextPrinterForMessage(TRUE); task_add_textbox(); } @@ -128,17 +128,17 @@ void HideFieldMessageBox(void) { task_del_textbox(); sub_8197434(0, 1); - gUnknown_020375BC = 0; + sFieldMessageBoxMode = 0; } u8 GetFieldMessageBoxMode(void) { - return gUnknown_020375BC; + return sFieldMessageBoxMode; } bool8 IsFieldMessageBoxHidden(void) { - if (gUnknown_020375BC == 0) + if (sFieldMessageBoxMode == 0) return TRUE; return FALSE; } @@ -147,11 +147,11 @@ void sub_8098358(void) { task_del_textbox(); NewMenuHelpers_DrawStdWindowFrame(0, 1); - gUnknown_020375BC = 0; + sFieldMessageBoxMode = 0; } void sub_8098374(void) { task_del_textbox(); - gUnknown_020375BC = 0; + sFieldMessageBoxMode = 0; } diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index f14ac8329..7423216a4 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -723,7 +723,7 @@ static bool8 sub_808B1BC(s16 x, s16 y, u8 direction) { if ((gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_SURFING) && MapGridGetZCoordAt(x, y) == 3 - && GetEventObjectIdByXYZ(x, y, 3) == 16) + && GetEventObjectIdByXYZ(x, y, 3) == EVENT_OBJECTS_COUNT) { sub_808C750(direction); return TRUE; @@ -791,12 +791,9 @@ bool8 IsPlayerCollidingWithFarawayIslandMew(u8 direction) playerY = object->currentCoords.y; MoveCoords(direction, &playerX, &playerY); - mewObjectId = GetEventObjectIdByLocalIdAndMap(1, 0x39, 0x1A); - - if (mewObjectId == 16) - { + mewObjectId = GetEventObjectIdByLocalIdAndMap(1, MAP_NUM(FARAWAY_ISLAND_INTERIOR), MAP_GROUP(FARAWAY_ISLAND_INTERIOR)); + if (mewObjectId == EVENT_OBJECTS_COUNT) return FALSE; - } object = &gEventObjects[mewObjectId]; mewPrevX = object->previousCoords.x; @@ -1389,7 +1386,7 @@ void InitPlayerAvatar(s16 x, s16 y, u8 direction, u8 gender) u8 eventObjectId; struct EventObject *eventObject; - playerEventObjTemplate.localId = 0xFF; + playerEventObjTemplate.localId = EVENT_OBJ_ID_PLAYER; playerEventObjTemplate.graphicsId = GetPlayerAvatarGraphicsIdByStateIdAndGender(PLAYER_AVATAR_STATE_NORMAL, gender); playerEventObjTemplate.x = x - 7; playerEventObjTemplate.y = y - 7; diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index e05c2cc2a..b9e9272d4 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -17,6 +17,7 @@ #include "load_save.h" #include "main.h" #include "menu.h" +#include "mirage_tower.h" #include "event_obj_lock.h" #include "metatile_behavior.h" #include "palette.h" @@ -34,7 +35,6 @@ extern bool32 sub_81D6534(void); extern bool8 walkrun_is_standing_still(void); extern void ScriptUnfreezeEventObjects(void); -extern void sub_81BE72C(void); extern void sub_80FB768(void); extern void sub_808D194(void); extern void sub_808D1C8(void); @@ -89,7 +89,7 @@ static void palette_bg_faded_fill_black(void) void pal_fill_for_maplights(void) { u8 previousMapType = GetLastUsedWarpMapType(); - switch (GetMapPairFadeFromType(previousMapType, Overworld_GetMapTypeOfSaveblockLocation())) + switch (GetMapPairFadeFromType(previousMapType, GetCurrentMapType())) { case 0: palette_bg_faded_fill_black(); @@ -115,7 +115,7 @@ void pal_fill_black(void) void WarpFadeScreen(void) { - u8 currentMapType = Overworld_GetMapTypeOfSaveblockLocation(); + u8 currentMapType = GetCurrentMapType(); switch (GetMapPairFadeToType(currentMapType, GetDestinationWarpMapHeader()->mapType)) { case 0: @@ -498,7 +498,7 @@ static bool32 sub_80AF71C(void) return FALSE; } -void sub_80AF734(void) +void DoWarp(void) { ScriptContext2_Enable(); TryFadeOutOldMapMusic(); @@ -509,7 +509,7 @@ void sub_80AF734(void) CreateTask(sub_80AFA0C, 10); } -void sp13E_warp_to_last_warp(void) +void DoDiveWarp(void) { ScriptContext2_Enable(); TryFadeOutOldMapMusic(); @@ -529,16 +529,16 @@ void sub_80AF79C(void) CreateTask(sub_80AFA0C, 10); } -void sub_80AF7D0(void) +void DoDoorWarp(void) { ScriptContext2_Enable(); gFieldCallback = mapldr_default; CreateTask(sub_80AFA88, 10); } -void sp13F_fall_to_last_warp(void) +void DoFallWarp(void) { - sp13E_warp_to_last_warp(); + DoDiveWarp(); gFieldCallback = sub_80B6B68; } @@ -673,7 +673,7 @@ static void sub_80AFA0C(u8 taskId) { if (task->data[1] == 0) { - sub_81BE72C(); + ClearMirageTowerPulseBlendEffect(); task->data[1] = 1; } if (BGMusicStopped()) diff --git a/src/field_special_scene.c b/src/field_special_scene.c index 1cabf63d6..579188f36 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -1,7 +1,12 @@ #include "global.h" #include "event_data.h" #include "event_object_movement.h" +#include "field_camera.h" +#include "field_screen_effect.h" +#include "field_specials.h" +#include "fieldmap.h" #include "main.h" +#include "overworld.h" #include "palette.h" #include "script.h" #include "script_movement.h" @@ -13,14 +18,6 @@ #define SECONDS(value) ((signed) (60.0 * value + 0.5)) -extern u8 GetSSTidalLocation(s8 *, s8 *, s16 *, s16 *); // should be in field_specials.h -extern void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); -extern bool32 CountSSTidalStep(u16); -extern void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); -extern void sp13E_warp_to_last_warp(void); -extern void saved_warp2_set(int unused, s8 mapGroup, s8 mapNum, s8 warpId); -extern void sub_80AF8B8(void); - // porthole states enum { @@ -30,20 +27,13 @@ enum EXIT_PORTHOLE, }; -extern void SetCameraPanning(s16 x, s16 y); -extern void SetCameraPanningCallback(void ( *callback)()); -extern void InstallCameraPanAheadCallback(); -extern void pal_fill_black(void); -extern void MapGridSetMetatileIdAt(s32 x, s32 y, u16 metatileId); -extern void DrawWholeMapView(); - //. rodata static const s8 gTruckCamera_HorizontalTable[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, -1, -1, -1, 0}; const u8 gUnknown_0858E8AB[] = {0x18, 0xFE}; const u8 gUnknown_0858E8AD[] = {0x17, 0xFE}; // .text -void Task_Truck3(u8); +static void Task_Truck3(u8); s16 GetTruckCameraBobbingY(int a1) { @@ -121,7 +111,7 @@ void Task_Truck2(u8 taskId) } } -void Task_Truck3(u8 taskId) +static void Task_Truck3(u8 taskId) { s16 *data = gTasks[taskId].data; s16 cameraXpan; @@ -256,7 +246,7 @@ bool8 sub_80FB59C(void) } else { - Overworld_SetWarpDestination(mapGroup, mapNum, -1, x, y); + SetWarpDestination(mapGroup, mapNum, -1, x, y); return TRUE; } } @@ -312,8 +302,8 @@ void Task_HandlePorthole(u8 taskId) case EXIT_PORTHOLE: // exit porthole. FlagClear(0x4001); FlagClear(0x4000); - copy_saved_warp2_bank_and_enter_x_to_warp1(0); - sp13E_warp_to_last_warp(); + SetWarpDestinationToDynamicWarp(0); + DoDiveWarp(); DestroyTask(taskId); break; } @@ -349,7 +339,7 @@ void sub_80FB7A4(void) FlagSet(FLAG_SYS_CRUISE_MODE); FlagSet(0x4001); FlagSet(0x4000); - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); sub_80FB59C(); sub_80AF8B8(); } diff --git a/src/field_specials.c b/src/field_specials.c index 3a1d8a556..5883e0245 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -47,6 +47,7 @@ #include "constants/event_objects.h" #include "constants/field_effects.h" #include "constants/items.h" +#include "constants/map_types.h" #include "constants/maps.h" #include "constants/songs.h" #include "constants/species.h" @@ -115,9 +116,9 @@ static void sub_813A738(u8 taskId); static void sub_813A600(u8 taskId); static void sub_813A664(u8 taskId); static void sub_813ABD4(u16 a0); -static void task_deoxys_sound(u8 taskId); -static void sub_813B0B4(u8 a0); -static void sub_813B160(u8 taskId); +static void Task_DeoxysRockInteraction(u8 taskId); +static void ChangeDeoxysRockLevel(u8 a0); +static void WaitForDeoxysRockMovement(u8 taskId); static void sub_813B57C(u8 taskId); static void sub_813B824(u8 taskId); static void _fwalk(u8 taskId); @@ -391,11 +392,11 @@ bool32 sub_8138120(void) { switch (gMapHeader.mapType) { - case 1: - case 2: - case 3: - case 6: - if (++(*GetVarPointer(VAR_0x40F3)) < 0xA) + case MAP_TYPE_TOWN: + case MAP_TYPE_CITY: + case MAP_TYPE_ROUTE: + case MAP_TYPE_6: + if (++(*GetVarPointer(VAR_0x40F3)) < 10) { return FALSE; } @@ -945,11 +946,11 @@ void CableCarWarp(void) { if (gSpecialVar_0x8004 != 0) { - Overworld_SetWarpDestination(MAP_GROUP(ROUTE112_CABLE_CAR_STATION), MAP_NUM(ROUTE112_CABLE_CAR_STATION), -1, 6, 4); + SetWarpDestination(MAP_GROUP(ROUTE112_CABLE_CAR_STATION), MAP_NUM(ROUTE112_CABLE_CAR_STATION), -1, 6, 4); } else { - Overworld_SetWarpDestination(MAP_GROUP(MT_CHIMNEY_CABLE_CAR_STATION), MAP_NUM(MT_CHIMNEY_CABLE_CAR_STATION), -1, 6, 4); + SetWarpDestination(MAP_GROUP(MT_CHIMNEY_CABLE_CAR_STATION), MAP_NUM(MT_CHIMNEY_CABLE_CAR_STATION), -1, 6, 4); } } @@ -1725,7 +1726,7 @@ const u16 gUnknown_085B2C06[][3] = void SetDepartmentStoreFloorVar(void) { u8 deptStoreFloor; - switch (gSaveBlock1Ptr->warp2.mapNum) + switch (gSaveBlock1Ptr->dynamicWarp.mapNum) { case MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_1F): deptStoreFloor = 4; @@ -1757,9 +1758,9 @@ u16 sub_81399F4(void) gUnknown_0203AB60 = 0; gUnknown_0203AB62 = 0; - if (gSaveBlock1Ptr->warp2.mapGroup == 13) + if (gSaveBlock1Ptr->dynamicWarp.mapGroup == MAP_GROUP(LILYCOVE_CITY_DEPARTMENT_STORE_1F)) { - switch (gSaveBlock1Ptr->warp2.mapNum) + switch (gSaveBlock1Ptr->dynamicWarp.mapNum) { case MAP_NUM(LILYCOVE_CITY_DEPARTMENT_STORE_5F): gUnknown_0203AB60 = 0; @@ -3233,12 +3234,12 @@ void sub_813AF48(void) } } -void sub_813AFC8(void) +void DoDeoxysRockInteraction(void) { - CreateTask(task_deoxys_sound, 8); + CreateTask(Task_DeoxysRockInteraction, 8); } -static const u16 gUnknown_085B3280[][16] = { +static const u16 sDeoxysRockPalettes[][16] = { INCBIN_U16("graphics/misc/deoxys1.gbapal"), INCBIN_U16("graphics/misc/deoxys2.gbapal"), INCBIN_U16("graphics/misc/deoxys3.gbapal"), @@ -3252,25 +3253,25 @@ static const u16 gUnknown_085B3280[][16] = { INCBIN_U16("graphics/misc/deoxys11.gbapal"), }; -static const u8 gUnknown_085B33E0[][2] = { - { 0x0f, 0x0c }, - { 0x0b, 0x0e }, - { 0x0f, 0x08 }, - { 0x13, 0x0e }, - { 0x0c, 0x0b }, - { 0x12, 0x0b }, - { 0x0f, 0x0e }, - { 0x0b, 0x0e }, - { 0x13, 0x0e }, - { 0x0f, 0x0f }, - { 0x0f, 0x0a }, +static const u8 sDeoxysRockCoords[][2] = { + { 15, 12 }, + { 11, 14 }, + { 15, 8 }, + { 19, 14 }, + { 12, 11 }, + { 18, 11 }, + { 15, 14 }, + { 11, 14 }, + { 19, 14 }, + { 15, 15 }, + { 15, 10 }, }; -static void task_deoxys_sound(u8 taskId) +static void Task_DeoxysRockInteraction(u8 taskId) { - static const u8 gUnknown_085B33F6[] = { 0x04, 0x08, 0x08, 0x08, 0x04, 0x04, 0x04, 0x06, 0x03, 0x03 }; + static const u8 sStoneMaxStepCounts[] = { 4, 8, 8, 8, 4, 4, 4, 6, 3, 3 }; - if (FlagGet(FLAG_0x8D4) == TRUE) + if (FlagGet(FLAG_DEOXYS_ROCK_COMPLETE) == TRUE) { gSpecialVar_Result = 3; EnableBothScriptContexts(); @@ -3278,100 +3279,92 @@ static void task_deoxys_sound(u8 taskId) } else { - u16 temp1 = VarGet(VAR_0x4035); - u16 temp2 = VarGet(VAR_0x4034); + u16 rockLevel = VarGet(VAR_DEOXYS_ROCK_LEVEL); + u16 stepCount = VarGet(VAR_DEOXYS_ROCK_STEP_COUNT); - VarSet(VAR_0x4034, 0); - if (temp1 != 0 && gUnknown_085B33F6[temp1 - 1] < temp2) + VarSet(VAR_DEOXYS_ROCK_STEP_COUNT, 0); + if (rockLevel != 0 && sStoneMaxStepCounts[rockLevel - 1] < stepCount) { - sub_813B0B4(0); - VarSet(VAR_0x4035, 0); + // Player failed to take the shortest path to the stone, so it resets. + ChangeDeoxysRockLevel(0); + VarSet(VAR_DEOXYS_ROCK_LEVEL, 0); gSpecialVar_Result = 0; DestroyTask(taskId); } - else if (temp1 == 10) + else if (rockLevel == 10) { - FlagSet(FLAG_0x8D4); + FlagSet(FLAG_DEOXYS_ROCK_COMPLETE); gSpecialVar_Result = 2; EnableBothScriptContexts(); DestroyTask(taskId); } else { - temp1++; - sub_813B0B4(temp1); - VarSet(VAR_0x4035, temp1); + rockLevel++; + ChangeDeoxysRockLevel(rockLevel); + VarSet(VAR_DEOXYS_ROCK_LEVEL, rockLevel); gSpecialVar_Result = 1; DestroyTask(taskId); } } } -static void sub_813B0B4(u8 a0) +static void ChangeDeoxysRockLevel(u8 rockLevel) { u8 eventObjectId; - LoadPalette(&gUnknown_085B3280[a0], 0x1A0, 8); + LoadPalette(&sDeoxysRockPalettes[rockLevel], 0x1A0, 8); TryGetEventObjectIdByLocalIdAndMap(1, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &eventObjectId); - if (a0 == 0) - { + if (rockLevel == 0) PlaySE(SE_W109); - } else - { PlaySE(SE_RG_DEOMOV); - } - - CreateTask(sub_813B160, 8); + CreateTask(WaitForDeoxysRockMovement, 8); gFieldEffectArguments[0] = 1; gFieldEffectArguments[1] = 58; gFieldEffectArguments[2] = 26; - gFieldEffectArguments[3] = gUnknown_085B33E0[a0][0]; - gFieldEffectArguments[4] = gUnknown_085B33E0[a0][1]; + gFieldEffectArguments[3] = sDeoxysRockCoords[rockLevel][0]; + gFieldEffectArguments[4] = sDeoxysRockCoords[rockLevel][1]; - if (a0 == 0) - { + if (rockLevel == 0) gFieldEffectArguments[5] = 60; - } else - { gFieldEffectArguments[5] = 5; - } - FieldEffectStart(FLDEFF_66); - Overworld_SetEventObjTemplateCoords(1, gUnknown_085B33E0[a0][0], gUnknown_085B33E0[a0][1]); + FieldEffectStart(FLDEFF_MOVE_DEOXYS_ROCK); + Overworld_SetEventObjTemplateCoords(1, sDeoxysRockCoords[rockLevel][0], sDeoxysRockCoords[rockLevel][1]); } -static void sub_813B160(u8 taskId) +static void WaitForDeoxysRockMovement(u8 taskId) { - if (FieldEffectActiveListContains(FLDEFF_66) == FALSE) + if (FieldEffectActiveListContains(FLDEFF_MOVE_DEOXYS_ROCK) == FALSE) { EnableBothScriptContexts(); DestroyTask(taskId); } } -void increment_var_x4026_on_birth_island_modulo_100(void) +void IncrementBirthIslandRockStepCount(void) { - u16 var = VarGet(VAR_0x4034); + u16 var = VarGet(VAR_DEOXYS_ROCK_STEP_COUNT); if (gSaveBlock1Ptr->location.mapNum == MAP_NUM(BIRTH_ISLAND_EXTERIOR) && gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(BIRTH_ISLAND_EXTERIOR)) { var++; if (var > 99) { - VarSet(VAR_0x4034, 0); + VarSet(VAR_DEOXYS_ROCK_STEP_COUNT, 0); } else { - VarSet(VAR_0x4034, var); + VarSet(VAR_DEOXYS_ROCK_STEP_COUNT, var); } } } void sub_813B1D0(void) { - LoadPalette(&gUnknown_085B3280[(u8)VarGet(VAR_0x4035)], 0x1A0, 8); + LoadPalette(&sDeoxysRockPalettes[(u8)VarGet(VAR_DEOXYS_ROCK_LEVEL)], 0x1A0, 8); BlendPalettes(0x04000000, 16, 0); } @@ -3813,7 +3806,7 @@ void sub_813B9A0(void) { if (gSaveBlock1Ptr->lastHealLocation.mapGroup == MAP_GROUP(DEWFORD_TOWN) && gSaveBlock1Ptr->lastHealLocation.mapNum == MAP_NUM(DEWFORD_TOWN)) { - Overworld_SetHealLocationWarp(3); + SetLastHealLocationWarp(3); } } diff --git a/src/fieldmap.c b/src/fieldmap.c index abdddb373..d2ff34b1c 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -5,6 +5,7 @@ #include "fldeff_misc.h" #include "frontier_util.h" #include "menu.h" +#include "mirage_tower.h" #include "overworld.h" #include "palette.h" #include "pokenav.h" @@ -23,84 +24,94 @@ struct ConnectionFlags u8 east:1; }; -EWRAM_DATA static u16 gUnknown_02032318[0x2800] = {0}; +EWRAM_DATA static u16 gBackupMapData[MAX_MAP_DATA_SIZE] = {0}; EWRAM_DATA struct MapHeader gMapHeader = {0}; EWRAM_DATA struct Camera gCamera = {0}; -EWRAM_DATA static struct ConnectionFlags gUnknown_02037340 = {0}; +EWRAM_DATA static struct ConnectionFlags gMapConnectionFlags = {0}; EWRAM_DATA static u32 sFiller_02037344 = 0; // without this, the next file won't align properly -struct BackupMapLayout gUnknown_03005DC0; +struct BackupMapLayout gBackupMapLayout; static const struct ConnectionFlags sDummyConnectionFlags = {0}; +static void InitMapLayoutData(struct MapHeader *mapHeader); +static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height); +static void FillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +static void FillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +static void FillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +static void FillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset); +static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader); +static void LoadSavedMapView(void); +static bool8 SkipCopyingMetatileFromSavedMap(u16* mapMetatilePtr, u16 mapWidth, u8 yMode); + struct MapHeader const *const mapconnection_get_mapheader(struct MapConnection *connection) { return Overworld_GetMapHeaderByGroupAndId(connection->mapGroup, connection->mapNum); } -void not_trainer_hill_battle_pyramid(void) +void InitMap(void) { - mapheader_copy_mapdata_with_padding(&gMapHeader); + InitMapLayoutData(&gMapHeader); sub_80E8EE0(gMapHeader.events); mapheader_run_script_with_tag_x1(); } -void sub_8087D74(void) +void InitMapFromSavedGame(void) { - mapheader_copy_mapdata_with_padding(&gMapHeader); + InitMapLayoutData(&gMapHeader); sub_80E9238(0); sub_80E8EE0(gMapHeader.events); - mapdata_from_sav2(); + LoadSavedMapView(); mapheader_run_script_with_tag_x1(); - UpdateTVScreensOnMap(gUnknown_03005DC0.width, gUnknown_03005DC0.height); + UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height); } -void battle_pyramid_map_load_related(u8 a0) +void InitBattlePyramidMap(u8 a0) { - CpuFastFill(0x03ff03ff, gUnknown_02032318, sizeof(gUnknown_02032318)); - sub_81AA078(gUnknown_02032318, a0); + CpuFastFill(0x03ff03ff, gBackupMapData, sizeof(gBackupMapData)); + sub_81AA078(gBackupMapData, a0); } -void trainer_hill_map_load_related(void) +void InitTrainerHillMap(void) { - CpuFastFill(0x03ff03ff, gUnknown_02032318, sizeof(gUnknown_02032318)); - sub_81D5FB4(gUnknown_02032318); + CpuFastFill(0x03ff03ff, gBackupMapData, sizeof(gBackupMapData)); + sub_81D5FB4(gBackupMapData); } -void mapheader_copy_mapdata_with_padding(struct MapHeader *mapHeader) +static void InitMapLayoutData(struct MapHeader *mapHeader) { struct MapLayout const *mapLayout; int width; int height; mapLayout = mapHeader->mapLayout; - CpuFastFill16(0x03ff, gUnknown_02032318, sizeof(gUnknown_02032318)); - gUnknown_03005DC0.map = gUnknown_02032318; + CpuFastFill16(0x03ff, gBackupMapData, sizeof(gBackupMapData)); + gBackupMapLayout.map = gBackupMapData; width = mapLayout->width + 15; - gUnknown_03005DC0.width = width; + gBackupMapLayout.width = width; height = mapLayout->height + 14; - gUnknown_03005DC0.height = height; - if (width * height <= 0x2800) + gBackupMapLayout.height = height; + if (width * height <= MAX_MAP_DATA_SIZE) { - map_copy_with_padding(mapLayout->map, mapLayout->width, mapLayout->height); - mapheader_copy_mapdata_of_adjacent_maps(mapHeader); + InitBackupMapLayoutData(mapLayout->map, mapLayout->width, mapLayout->height); + InitBackupMapLayoutConnections(mapHeader); } } -void map_copy_with_padding(u16 *map, u16 width, u16 height) +static void InitBackupMapLayoutData(u16 *map, u16 width, u16 height) { u16 *dest; int y; - dest = gUnknown_03005DC0.map; - dest += gUnknown_03005DC0.width * 7 + 7; + dest = gBackupMapLayout.map; + dest += gBackupMapLayout.width * 7 + 7; for (y = 0; y < height; y++) { CpuCopy16(map, dest, width * 2); - dest += width + 0xf; + dest += width + 15; map += width; } } -void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader) +static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader) { int count; struct MapConnection *connection; @@ -110,56 +121,54 @@ void mapheader_copy_mapdata_of_adjacent_maps(struct MapHeader *mapHeader) { count = mapHeader->connections->count; connection = mapHeader->connections->connections; - - gUnknown_02037340 = sDummyConnectionFlags; + gMapConnectionFlags = sDummyConnectionFlags; for (i = 0; i < count; i++, connection++) { struct MapHeader const *cMap = mapconnection_get_mapheader(connection); u32 offset = connection->offset; - switch (connection->direction) { case CONNECTION_SOUTH: - fillSouthConnection(mapHeader, cMap, offset); - gUnknown_02037340.south = 1; + FillSouthConnection(mapHeader, cMap, offset); + gMapConnectionFlags.south = 1; break; case CONNECTION_NORTH: - fillNorthConnection(mapHeader, cMap, offset); - gUnknown_02037340.north = 1; + FillNorthConnection(mapHeader, cMap, offset); + gMapConnectionFlags.north = 1; break; case CONNECTION_WEST: - fillWestConnection(mapHeader, cMap, offset); - gUnknown_02037340.west = 1; + FillWestConnection(mapHeader, cMap, offset); + gMapConnectionFlags.west = 1; break; case CONNECTION_EAST: - fillEastConnection(mapHeader, cMap, offset); - gUnknown_02037340.east = 1; + FillEastConnection(mapHeader, cMap, offset); + gMapConnectionFlags.east = 1; break; } } } } -void sub_8087F54(int x, int y, struct MapHeader const *mapHeader, int x2, int y2, int width, int height) +static void sub_8087F54(int x, int y, struct MapHeader const *connectedMapHeader, int x2, int y2, int width, int height) { int i; u16 *src; u16 *dest; int mapWidth; - mapWidth = mapHeader->mapLayout->width; - src = &mapHeader->mapLayout->map[mapWidth * y2 + x2]; - dest = &gUnknown_03005DC0.map[gUnknown_03005DC0.width * y + x]; + mapWidth = connectedMapHeader->mapLayout->width; + src = &connectedMapHeader->mapLayout->map[mapWidth * y2 + x2]; + dest = &gBackupMapLayout.map[gBackupMapLayout.width * y + x]; for (i = 0; i < height; i++) { CpuCopy16(src, dest, width * 2); - dest += gUnknown_03005DC0.width; + dest += gBackupMapLayout.width; src += mapWidth; } } -void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +static void FillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) { int x, y; int x2; @@ -175,26 +184,26 @@ void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader con { x2 = -x; x += cWidth; - if (x < gUnknown_03005DC0.width) + if (x < gBackupMapLayout.width) { width = x; } else { - width = gUnknown_03005DC0.width; + width = gBackupMapLayout.width; } x = 0; } else { x2 = 0; - if (x + cWidth < gUnknown_03005DC0.width) + if (x + cWidth < gBackupMapLayout.width) { width = cWidth; } else { - width = gUnknown_03005DC0.width - x; + width = gBackupMapLayout.width - x; } } @@ -206,7 +215,7 @@ void fillSouthConnection(struct MapHeader const *mapHeader, struct MapHeader con } } -void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +static void FillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) { int x; int x2, y2; @@ -223,26 +232,26 @@ void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader con { x2 = -x; x += cWidth; - if (x < gUnknown_03005DC0.width) + if (x < gBackupMapLayout.width) { width = x; } else { - width = gUnknown_03005DC0.width; + width = gBackupMapLayout.width; } x = 0; } else { x2 = 0; - if (x + cWidth < gUnknown_03005DC0.width) + if (x + cWidth < gBackupMapLayout.width) { width = cWidth; } else { - width = gUnknown_03005DC0.width - x; + width = gBackupMapLayout.width - x; } } @@ -255,7 +264,7 @@ void fillNorthConnection(struct MapHeader const *mapHeader, struct MapHeader con } } -void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +static void FillWestConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) { int y; int x2, y2; @@ -270,26 +279,26 @@ void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader cons if (y < 0) { y2 = -y; - if (y + cHeight < gUnknown_03005DC0.height) + if (y + cHeight < gBackupMapLayout.height) { height = y + cHeight; } else { - height = gUnknown_03005DC0.height; + height = gBackupMapLayout.height; } y = 0; } else { y2 = 0; - if (y + cHeight < gUnknown_03005DC0.height) + if (y + cHeight < gBackupMapLayout.height) { height = cHeight; } else { - height = gUnknown_03005DC0.height - y; + height = gBackupMapLayout.height - y; } } @@ -301,7 +310,7 @@ void fillWestConnection(struct MapHeader const *mapHeader, struct MapHeader cons } } -void fillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) +static void FillEastConnection(struct MapHeader const *mapHeader, struct MapHeader const *connectedMapHeader, s32 offset) { int x, y; int y2; @@ -315,26 +324,26 @@ void fillEastConnection(struct MapHeader const *mapHeader, struct MapHeader cons if (y < 0) { y2 = -y; - if (y + cHeight < gUnknown_03005DC0.height) + if (y + cHeight < gBackupMapLayout.height) { height = y + cHeight; } else { - height = gUnknown_03005DC0.height; + height = gBackupMapLayout.height; } y = 0; } else { y2 = 0; - if (y + cHeight < gUnknown_03005DC0.height) + if (y + cHeight < gBackupMapLayout.height) { height = cHeight; } else { - height = gUnknown_03005DC0.height - y; + height = gBackupMapLayout.height - y; } } @@ -363,10 +372,10 @@ u8 MapGridGetZCoordAt(int x, int y) int i; u16 *border; - if (x >= 0 && x < gUnknown_03005DC0.width - && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width + && y >= 0 && y < gBackupMapLayout.height) { - block = gUnknown_03005DC0.map[x + gUnknown_03005DC0.width * y]; + block = gBackupMapLayout.map[x + gBackupMapLayout.width * y]; } else { @@ -391,10 +400,10 @@ u8 MapGridIsImpassableAt(int x, int y) int i; u16 *border; - if (x >= 0 && x < gUnknown_03005DC0.width - && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width + && y >= 0 && y < gBackupMapLayout.height) { - block = gUnknown_03005DC0.map[x + gUnknown_03005DC0.width * y]; + block = gBackupMapLayout.map[x + gBackupMapLayout.width * y]; } else { @@ -420,10 +429,10 @@ u32 MapGridGetMetatileIdAt(int x, int y) u16 *border; u16 block2; - if (x >= 0 && x < gUnknown_03005DC0.width - && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width + && y >= 0 && y < gBackupMapLayout.height) { - block = gUnknown_03005DC0.map[x + gUnknown_03005DC0.width * y]; + block = gBackupMapLayout.map[x + gBackupMapLayout.width * y]; } else { @@ -461,22 +470,22 @@ u8 MapGridGetMetatileLayerTypeAt(int x, int y) void MapGridSetMetatileIdAt(int x, int y, u16 metatile) { int i; - if (x >= 0 && x < gUnknown_03005DC0.width - && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width + && y >= 0 && y < gBackupMapLayout.height) { - i = x + y * gUnknown_03005DC0.width; - gUnknown_03005DC0.map[i] = (gUnknown_03005DC0.map[i] & 0xf000) | (metatile & 0xfff); + i = x + y * gBackupMapLayout.width; + gBackupMapLayout.map[i] = (gBackupMapLayout.map[i] & 0xf000) | (metatile & 0xfff); } } void MapGridSetMetatileEntryAt(int x, int y, u16 metatile) { int i; - if (x >= 0 && x < gUnknown_03005DC0.width - && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width + && y >= 0 && y < gBackupMapLayout.height) { - i = x + gUnknown_03005DC0.width * y; - gUnknown_03005DC0.map[i] = metatile; + i = x + gBackupMapLayout.width * y; + gBackupMapLayout.map[i] = metatile; } } @@ -506,76 +515,75 @@ void save_serialize_map(void) u16 *mapView; int width; mapView = gSaveBlock1Ptr->mapView; - width = gUnknown_03005DC0.width; + width = gBackupMapLayout.width; x = gSaveBlock1Ptr->pos.x; y = gSaveBlock1Ptr->pos.y; for (i = y; i < y + 14; i++) { for (j = x; j < x + 15; j++) { - *mapView++ = gUnknown_02032318[width * i + j]; + *mapView++ = gBackupMapData[width * i + j]; } } } -int sub_8088438(void) +static bool32 SavedMapViewIsEmpty(void) { u16 i; - u32 r2; - r2 = 0; + u32 marker = 0; + + // BUG: This loop extends past the bounds of the mapView array. Its size is only 0x100. for (i = 0; i < 0x200; i++) - { - r2 |= gSaveBlock1Ptr->mapView[i]; - } - if (r2 == 0) - { - return 1; - } - return 0; + marker |= gSaveBlock1Ptr->mapView[i]; + + if (marker == 0) + return TRUE; + else + return FALSE; } -void sav2_mapdata_clear(void) +static void ClearSavedMapView(void) { CpuFill16(0, gSaveBlock1Ptr->mapView, sizeof(gSaveBlock1Ptr->mapView)); } -void mapdata_from_sav2(void) +static void LoadSavedMapView(void) { - u8 a0; + u8 yMode; int i, j; int x, y; u16 *mapView; int width; mapView = gSaveBlock1Ptr->mapView; - if (!sub_8088438()) + if (!SavedMapViewIsEmpty()) { - width = gUnknown_03005DC0.width; + width = gBackupMapLayout.width; x = gSaveBlock1Ptr->pos.x; y = gSaveBlock1Ptr->pos.y; for (i = y; i < y + 14; i++) { if (i == y && i != 0) - a0 = 0; + yMode = 0; else if (i == y + 13 && i != gMapHeader.mapLayout->height - 1) - a0 = 1; + yMode = 1; else - a0 = -1; + yMode = 0xFF; for (j = x; j < x + 15; j++) { - if (!sub_8088BF0(&gUnknown_02032318[j + width * i], width, a0)) - gUnknown_02032318[j + width * i] = *mapView; + if (!SkipCopyingMetatileFromSavedMap(&gBackupMapData[j + width * i], width, yMode)) + gBackupMapData[j + width * i] = *mapView; mapView++; } } for (j = x; j < x + 15; j++) { if (y != 0) - sub_80D423C(j, y - 1); + FixLongGrassMetatilesWindowTop(j, y - 1); if (i < gMapHeader.mapLayout->height - 1) - sub_80D42B8(j, y + 13); + FixLongGrassMetatilesWindowBottom(j, y + 13); } - sav2_mapdata_clear(); + ClearSavedMapView(); } } @@ -591,7 +599,7 @@ void sub_80885C4(u8 a1) int x, y; int i, j; mapView = gSaveBlock1Ptr->mapView; - width = gUnknown_03005DC0.width; + width = gBackupMapLayout.width; r9 = 0; r8 = 0; x0 = gSaveBlock1Ptr->pos.x; @@ -626,13 +634,13 @@ void sub_80885C4(u8 a1) desti = width * (y + y0); srci = (y + r8) * 15 + r9; src = &mapView[srci + i]; - dest = &gUnknown_02032318[x0 + desti + j]; + dest = &gBackupMapData[x0 + desti + j]; *dest = *src; i++; j++; } } - sav2_mapdata_clear(); + ClearSavedMapView(); } int GetMapBorderIdAt(int x, int y) @@ -640,12 +648,12 @@ int GetMapBorderIdAt(int x, int y) struct MapLayout const *mapLayout; u16 block, block2; int i, j; - if (x >= 0 && x < gUnknown_03005DC0.width - && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width + && y >= 0 && y < gBackupMapLayout.height) { - i = gUnknown_03005DC0.width; + i = gBackupMapLayout.width; i *= y; - block = gUnknown_03005DC0.map[x + i]; + block = gBackupMapLayout.map[x + i]; if (block == 0x3ff) { goto fail; @@ -667,9 +675,9 @@ fail: return -1; success: - if (x >= (gUnknown_03005DC0.width - 8)) + if (x >= (gBackupMapLayout.width - 8)) { - if (!gUnknown_02037340.east) + if (!gMapConnectionFlags.east) { return -1; } @@ -677,15 +685,15 @@ success: } else if (x < 7) { - if (!gUnknown_02037340.west) + if (!gMapConnectionFlags.west) { return -1; } return CONNECTION_WEST; } - else if (y >= (gUnknown_03005DC0.height - 7)) + else if (y >= (gBackupMapLayout.height - 7)) { - if (!gUnknown_02037340.south) + if (!gMapConnectionFlags.south) { return -1; } @@ -693,7 +701,7 @@ success: } else if (y < 7) { - if (!gUnknown_02037340.north) + if (!gMapConnectionFlags.north) { return -1; } @@ -762,7 +770,7 @@ bool8 CameraMove(int x, int y) else { save_serialize_map(); - sub_81BE72C(); + ClearMirageTowerPulseBlendEffect(); old_x = gSaveBlock1Ptr->pos.x; old_y = gSaveBlock1Ptr->pos.y; connection = sub_8088950(direction, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y); @@ -890,13 +898,13 @@ void sub_8088B3C(u16 x, u16 y) gSaveBlock1Ptr->pos.y = y - 7; } -void sav1_camera_get_focus_coords(u16 *x, u16 *y) +void GetCameraFocusCoords(u16 *x, u16 *y) { *x = gSaveBlock1Ptr->pos.x + 7; *y = gSaveBlock1Ptr->pos.y + 7; } -void SetCameraCoords(u16 x, u16 y) +void SetPlayerCoords(u16 x, u16 y) { gSaveBlock1Ptr->pos.x = x; gSaveBlock1Ptr->pos.y = y; @@ -910,26 +918,26 @@ void GetCameraCoords(u16 *x, u16 *y) void sub_8088B94(int x, int y, int a2) { - if (x >= 0 && x < gUnknown_03005DC0.width && y >= 0 && y < gUnknown_03005DC0.height) + if (x >= 0 && x < gBackupMapLayout.width && y >= 0 && y < gBackupMapLayout.height) { if (a2 != 0) - gUnknown_03005DC0.map[x + gUnknown_03005DC0.width * y] |= 0xC00; + gBackupMapLayout.map[x + gBackupMapLayout.width * y] |= 0xC00; else - gUnknown_03005DC0.map[x + gUnknown_03005DC0.width * y] &= 0xF3FF; + gBackupMapLayout.map[x + gBackupMapLayout.width * y] &= 0xF3FF; } } -bool8 sub_8088BF0(u16* a0, u16 a1, u8 a2) +static bool8 SkipCopyingMetatileFromSavedMap(u16* mapMetatilePtr, u16 mapWidth, u8 yMode) { - if (a2 == 0xFF) + if (yMode == 0xFF) return FALSE; - if (a2 == 0) - a0 -= a1; + if (yMode == 0) + mapMetatilePtr -= mapWidth; else - a0 += a1; + mapMetatilePtr += mapWidth; - if (sub_80FADE4(*a0 & 0x3FF, a2) == 1) + if (sub_80FADE4(*mapMetatilePtr & 0x3FF, yMode) == 1) return TRUE; return FALSE; } diff --git a/src/fight.c b/src/fight.c index b7ca2e87a..c924effae 100644 --- a/src/fight.c +++ b/src/fight.c @@ -486,8 +486,8 @@ void sub_810CF30(struct Sprite *sprite) sprite->pos1.x = GetBattlerSpriteCoord(battler, 2); sprite->pos1.y = GetBattlerSpriteCoord(battler, 3); - xMod = sub_80A861C(battler, 1) / 2; - yMod = sub_80A861C(battler, 0) / 4; + xMod = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_WIDTH) / 2; + yMod = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_HEIGHT) / 4; x = Random2() % xMod; y = Random2() % yMod; diff --git a/src/fldeff_cut.c b/src/fldeff_cut.c index 60887a5cc..348a1f46c 100644 --- a/src/fldeff_cut.c +++ b/src/fldeff_cut.c @@ -624,7 +624,7 @@ static void CutGrassSpriteCallbackEnd(struct Sprite *sprite) ScriptContext1_SetupScript(FarawayIsland_Interior_EventScript_267EDB); } -void sub_80D423C(s16 x, s16 y) +void FixLongGrassMetatilesWindowTop(s16 x, s16 y) { u8 metatileBehavior = MapGridGetMetatileBehaviorAt(x, y); if (MetatileBehavior_IsLongGrass_Duplicate(metatileBehavior)) @@ -647,7 +647,7 @@ void sub_80D423C(s16 x, s16 y) } } -void sub_80D42B8(s16 x, s16 y) +void FixLongGrassMetatilesWindowBottom(s16 x, s16 y) { if (MapGridGetMetatileIdAt(x, y) == METATILE_ID_GRASS) { diff --git a/src/fldeff_flash.c b/src/fldeff_flash.c index 69d198c84..f3bd76cbf 100644 --- a/src/fldeff_flash.c +++ b/src/fldeff_flash.c @@ -156,7 +156,7 @@ static bool8 sub_8137304(void) { u8 i; u8 v0 = GetLastUsedWarpMapType(); - u8 v1 = Overworld_GetMapTypeOfSaveblockLocation(); + u8 v1 = GetCurrentMapType(); for (i = 0; gUnknown_085B27C8[i].unk0; i++) { diff --git a/src/fldeff_groundshake.c b/src/fldeff_groundshake.c deleted file mode 100644 index bfd583981..000000000 --- a/src/fldeff_groundshake.c +++ /dev/null @@ -1,322 +0,0 @@ -#include "global.h" -#include "event_data.h" -#include "event_object_movement.h" -#include "field_camera.h" -#include "fldeff.h" -#include "alloc.h" -#include "random.h" -#include "roulette_util.h" -#include "script.h" -#include "sound.h" -#include "sprite.h" -#include "task.h" -#include "constants/flags.h" -#include "constants/maps.h" -#include "constants/songs.h" - -// structures -struct Struct203CF18 { - u8 taskId; - struct InnerStruct203CF18 unk4; -}; //size = 0xC8 - -// extern data -extern const struct SpriteSheet gUnknown_08617D94[]; -extern const s16 gUnknown_08617D64[][3]; - -// static functions -static void sub_81BE808(u8 taskId); -static void sub_81BE900(u8 taskId); -static void sub_81BE968(void); -static void sub_81BE9C0(u8 taskId); -static void sub_81BEA00(u8 taskId); -static void sub_81BEA20(void); -static void sub_81BEAD8(struct Sprite* sprite); - -// rodata -const struct InnerStruct203CF18_3 gUnknown_08617E18 = { - .unk0 = 0x433b, - .unk2 = 0x61, - .unk4 = 0x0F, - .unk5 = 0x05, - .unk6 = 0xFF, - .unk7_0 = 0xB, - .unk7_4 = 0x1, - .unk7_6 = 0, - .unk7_7 = 1, -}; - -static const union AnimCmd gSpriteAnim_8617E20[] = -{ - ANIMCMD_FRAME(0, 12), - ANIMCMD_JUMP(0), -}; - -static const union AnimCmd *const gSpriteAnimTable_8617E28[] = -{ - gSpriteAnim_8617E20, -}; - -static const struct OamData gUnknown_08617E2C = -{ - .y = 0, - .affineMode = 0, - .objMode = 0, - .mosaic = 0, - .bpp = 0, - .shape = 0, - .x = 0, - .matrixNum = 0, - .size = 0, - .tileNum = 0, - .priority = 0, - .paletteNum = 0, - .affineParam = 0, -}; - -static const struct SpriteTemplate gUnknown_08617E34 = { - .tileTag = 0x0FA0, - .paletteTag = 0xFFFF, - .oam = &gUnknown_08617E2C, - .anims = gSpriteAnimTable_8617E28, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_81BEAD8 -}; - -static const union AnimCmd gSpriteAnim_8617E4C[] = -{ - ANIMCMD_FRAME(0, 12), - ANIMCMD_JUMP(0), -}; - -static const union AnimCmd *const gSpriteAnim_8617E54[] = -{ - gSpriteAnim_8617E4C, -}; - -static const struct OamData gSpriteAnim_8617E58 = -{ - .y = 0, - .affineMode = 0, - .objMode = 0, - .mosaic = 0, - .bpp = 0, - .shape = 0, - .x = 0, - .matrixNum = 0, - .size = 1, - .tileNum = 0, - .priority = 0, - .paletteNum = 0, - .affineParam = 0, -}; - -static const struct SpriteTemplate gUnknown_08617E60 = { - .tileTag = 0x0FA0, - .paletteTag = 0xFFFF, - .oam = &gSpriteAnim_8617E58, - .anims = gSpriteAnim_8617E54, - .images = NULL, - .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_81BEAD8 -}; - -// ewram -EWRAM_DATA struct Struct203CF18 *gUnknown_0203CF18 = NULL; - -// text -bool8 sub_81BE66C(void) -{ - if (!(gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE111) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE111))) - return FALSE; - else - return FlagGet(FLAG_0x14E); -} - -static void sub_81BE698(u8 taskId) -{ - sub_8151E50(&(gUnknown_0203CF18->unk4)); -} - -void sub_81BE6AC(void) -{ - gUnknown_0203CF18 = NULL; -} - -void sub_81BE6B8(void) -{ - if (gUnknown_0203CF18 != NULL) - { - gUnknown_0203CF18 = NULL; - return; - } - - if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(ROUTE111) || gSaveBlock1Ptr->location.mapNum != MAP_NUM(ROUTE111) || !FlagGet(FLAG_0x14E)) - return; - - gUnknown_0203CF18 = (struct Struct203CF18 *)AllocZeroed(sizeof(struct Struct203CF18)); - sub_8151B3C(&(gUnknown_0203CF18->unk4)); - sub_8151B68(&(gUnknown_0203CF18->unk4), &gUnknown_08617E18); - sub_8151CA8(&(gUnknown_0203CF18->unk4), 1, 1); - gUnknown_0203CF18->taskId = CreateTask(sub_81BE698, 0xFF); -} - -void sub_81BE72C(void) -{ - if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(ROUTE111) || gSaveBlock1Ptr->location.mapNum != MAP_NUM(ROUTE111) - || !FlagGet(FLAG_0x14E) || gUnknown_0203CF18 == NULL) - return; - - if( FuncIsActiveTask(sub_81BE698)) - DestroyTask(gUnknown_0203CF18->taskId); - - sub_8151D28(&(gUnknown_0203CF18->unk4), 1, 1); - sub_8151C50(&(gUnknown_0203CF18->unk4), 1, 1); - Free(gUnknown_0203CF18); - gUnknown_0203CF18 = NULL; -} - -void sub_81BE79C(void) -{ - u16 rand; - bool8 chance; - - if (VarGet(VAR_0x40CB) != 0) - { - FlagClear(FLAG_0x14E); - return; - } - rand = Random(); - chance = rand & 1; - if (FlagGet(FLAG_0x09D) == TRUE) - chance = TRUE; - if (chance) - { - FlagSet(FLAG_0x14E); - sub_81BE6B8(); - return; - } - FlagClear(FLAG_0x14E); -} - -void sub_81BE7F4(void) -{ - CreateTask(sub_81BE808, 0x8); -} - -static void sub_81BE808(u8 taskId) -{ - u8 eventObjectIdBuffer; - struct EventObject *fieldEventObject; - struct EventObject *playerAvatarEventObject; - - TryGetEventObjectIdByLocalIdAndMap(0x2D, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &eventObjectIdBuffer); - fieldEventObject = &(gEventObjects[eventObjectIdBuffer]); - gSprites[fieldEventObject->spriteId].pos2.y += 4; - playerAvatarEventObject = &(gEventObjects[gPlayerAvatar.eventObjectId]); - - if((gSprites[fieldEventObject->spriteId].pos1.y + gSprites[fieldEventObject->spriteId].pos2.y) >= - (gSprites[playerAvatarEventObject->spriteId].pos1.y + gSprites[playerAvatarEventObject->spriteId].pos2.y)) - { - DestroyTask(taskId); - EnableBothScriptContexts(); - } -} - -static void sp136_strengh_sound(u8 a, u8 b, u8 c, u8 d) -{ - u8 taskId; - - taskId = CreateTask(sub_81BE900, 0x9); - gTasks[taskId].data[0] = b; - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[2] = c; - gTasks[taskId].data[3] = d; - gTasks[taskId].data[4] = a; - SetCameraPanningCallback(NULL); - PlaySE(SE_W070); -} - -static void sub_81BE900(u8 taskId) -{ - s16 *data = gTasks[taskId].data; - - data[1]++; - if ((data[1] % data[3]) == 0) - { - data[1] = 0; - data[2]--; - data[0] = -data[0]; - data[4] = -data[4]; - SetCameraPanning(data[0], data[4]); - if (!data[2]) - { - sub_81BE968(); - DestroyTask(taskId); - InstallCameraPanAheadCallback(); - } - } -} - -static void sub_81BE968(void) -{ - u8 taskId = FindTaskIdByFunc(sub_81BE9C0); - if (taskId != 0xFF) - gTasks[taskId].data[0]++; -} - -void sub_81BE994(void) -{ - LoadSpriteSheets(gUnknown_08617D94); - sub_81BEA20(); - CreateTask(sub_81BE9C0, 0x8); - sp136_strengh_sound(2, 1, 16, 3); -} - -static void sub_81BE9C0(u8 taskId) -{ - u16 *data = gTasks[taskId].data; - - if (++data[1] == 1000 || data[0] == 17) - gTasks[taskId].func = sub_81BEA00; -} - -static void sub_81BEA00(u8 taskId) -{ - FreeSpriteTilesByTag(4000); - DestroyTask(taskId); - EnableBothScriptContexts(); -} - -static void sub_81BEA20(void) -{ - u8 i; - u8 spriteId; - - for (i = 0; i < 8; i++) - { - spriteId = CreateSprite(&gUnknown_08617E60, gUnknown_08617D64[i][0] + 120, gUnknown_08617D64[i][1], 8); - gSprites[spriteId].oam.priority = 0; - gSprites[spriteId].oam.paletteNum = 0; - gSprites[spriteId].data[0] = i; - } - for (i = 0; i < 8; i++) - { - spriteId = CreateSprite(&gUnknown_08617E34, gUnknown_08617D64[i][0] + 115, gUnknown_08617D64[i][1] - 3, 8); - gSprites[spriteId].oam.priority = 0; - gSprites[spriteId].oam.paletteNum = 0; - gSprites[spriteId].data[0] = i; - } -} - -static void sub_81BEAD8(struct Sprite* sprite) -{ - sprite->data[1] += 2; - sprite->pos2.y = (sprite->data[1] / 2); - if (((sprite->pos1.y) + (sprite->pos2.y)) > gUnknown_08617D64[sprite->data[0]][2]) - { - DestroySprite(sprite); - sub_81BE968(); - } -} diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index 9d77383ae..df4576a7f 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -376,7 +376,7 @@ static void sub_80F9C90(u8 taskId) task->data[7] = GetGpuReg(REG_OFFSET_BLDCNT); task->data[8] = GetGpuReg(REG_OFFSET_BLDY); - SetGpuReg(REG_OFFSET_BLDCNT, 0xBF); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_ALL | BLDCNT_EFFECT_LIGHTEN); SetGpuReg(REG_OFFSET_BLDY, 0x10); break; @@ -452,7 +452,7 @@ static void sub_80F9DFC(u8 taskId) { task->data[5] = 0x50; task->data[6] = 0x51; - SetGpuReg(REG_OFFSET_BLDCNT, 0xBF); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_ALL | BLDCNT_EFFECT_LIGHTEN); SetGpuReg(REG_OFFSET_BLDY, 0x10); } SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(task->data[5], task->data[6])); @@ -1166,23 +1166,23 @@ void GetShieldToyTVDecorationInfo(void) } } -bool8 sub_80FADE4(u16 arg0, u8 arg1) +bool8 sub_80FADE4(u16 metatileId, u8 arg1) { if (!CurrentMapIsSecretBase()) return FALSE; if (!arg1) { - if (arg0 == 0x285 || arg0 == 0x286) + if (metatileId == 0x285 || metatileId == 0x286) return TRUE; - if (arg0 == 0x237) + if (metatileId == 0x237) return TRUE; } else { - if (arg0 == 0x28d) + if (metatileId == 0x28d) return TRUE; - if (arg0 == 0x23F) + if (metatileId == 0x23F) return TRUE; } diff --git a/src/fldeff_sweetscent.c b/src/fldeff_sweetscent.c index 2363e8162..a187353ff 100644 --- a/src/fldeff_sweetscent.c +++ b/src/fldeff_sweetscent.c @@ -6,6 +6,7 @@ #include "field_screen_effect.h" #include "field_weather.h" #include "fldeff.h" +#include "mirage_tower.h" #include "palette.h" #include "party_menu.h" #include "script.h" @@ -63,7 +64,7 @@ static void TrySweetScentEncounter(u8 taskId) { if (!gPaletteFade.active) { - sub_81BE72C(); + ClearMirageTowerPulseBlendEffect(); BlendPalettes(0x00000040, 8, RGB_RED); if (gTasks[taskId].data[0] == 64) { @@ -76,7 +77,7 @@ static void TrySweetScentEncounter(u8 taskId) { gTasks[taskId].func = FailSweetScentEncounter; BeginNormalPaletteFade(~(1 << (gSprites[GetPlayerAvatarObjectId()].oam.paletteNum + 16)), 4, 8, 0, RGB_RED); - sub_81BE6B8(); + TryStartMirageTowerPulseBlendEffect(); } } else diff --git a/src/fossil_specials.c b/src/fossil_specials.c deleted file mode 100644 index dfdb999a9..000000000 --- a/src/fossil_specials.c +++ /dev/null @@ -1,561 +0,0 @@ -#include "global.h" -#include "constants/flags.h" -#include "constants/songs.h" -#include "bg.h" -#include "event_data.h" -#include "field_camera.h" -#include "event_object_movement.h" -#include "fieldmap.h" -#include "global.fieldmap.h" -#include "gpu_regs.h" -#include "alloc.h" -#include "menu.h" -#include "random.h" -#include "script.h" -#include "sound.h" -#include "sprite.h" -#include "task.h" -#include "window.h" - -#define MIRAGE_TOWER_GFX_LENGTH (32 + sizeof(gMirageTower_Gfx)) -#define MIRAGE_TOWER_PALETTE_LENGTH 0x800 -#define ROOT_FOSSIL_GFX_LENGTH sizeof(gRootFossil_Gfx) -#define ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH 0x100 - -struct Struct8617DA4 -{ - u8 x; - u8 y; - u16 tileId; -}; - -struct Struct203CF10 -{ - u8 *buffer; - u8 currIndex; -}; - -struct DynamicSpriteFrameImage -{ - u8 *data; - u16 size; -}; - -struct Struct203CF0C -{ - u8 *frameImageTiles; - struct DynamicSpriteFrameImage *frameImage; - u8 spriteId; - u16 *unkC; - u16 unk10; -}; - -// static functions -static void sub_81BED50(u8 taskId); -static void sub_81BEBF4(u8 taskId); -static void sub_81BF028(u8 taskId); -static void sub_81BF248(struct Sprite *); -static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e); - -// .rodata -static const u8 gUnknown_08617274[32] = {0}; -static const u8 gMirageTower_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower.4bpp"); -static const u16 gUnknown_08617B94[] = INCBIN_U16("graphics/misc/mirage_tower.bin"); -static const u16 gRootFossil_Pal[] = INCBIN_U16("graphics/misc/fossil.gbapal"); -static const u8 gRootFossil_Gfx[] = INCBIN_U8("graphics/misc/fossil.4bpp"); -static const u8 gMirageTowerCrumbles_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower_crumbles.4bpp"); -static const u16 gMirageTowerCrumbles_Palette[] = INCBIN_U16("graphics/misc/mirage_tower_crumbles.gbapal"); - -const s16 gUnknown_08617D64[][3] = -{ - { 0, 10, 65}, - { 17, 3, 50}, - {-12, 0, 75}, - { 10, 15, 90}, - { 7, 8, 65}, - {-18, 5, 75}, - { 22, -10, 55}, - {-24, -4, 65}, -}; - -const struct SpriteSheet gUnknown_08617D94[] = -{ - {gMirageTowerCrumbles_Gfx, 0x0080, 0x0fa0}, - {NULL} -}; - -static const struct Struct8617DA4 gUnknown_08617DA4[] = -{ - {0x12, 0x35, 0x251}, - {0x13, 0x35, 0x251}, - {0x14, 0x35, 0x251}, - {0x12, 0x36, 0x251}, - {0x13, 0x36, 0x251}, - {0x14, 0x36, 0x251}, - {0x12, 0x37, 0x251}, - {0x13, 0x37, 0x251}, - {0x14, 0x37, 0x251}, - {0x12, 0x38, 0x251}, - {0x13, 0x38, 0x251}, - {0x14, 0x38, 0x251}, - {0x12, 0x39, 0x259}, - {0x13, 0x39, 0x259}, - {0x14, 0x39, 0x259}, - {0x12, 0x3A, 0x121}, - {0x13, 0x3A, 0x121}, - {0x14, 0x3A, 0x121}, -}; - -static const union AnimCmd gSpriteAnim_8617DEC[] = -{ - ANIMCMD_FRAME(0, 1), - ANIMCMD_END, -}; - -static const struct OamData gOamData_8617DF4 = -{ - .y = 0, - .affineMode = 0, - .objMode = 0, - .mosaic = 0, - .bpp = 0, - .shape = 0, - .x = 0, - .matrixNum = 0, - .size = 1, - .tileNum = 0, - .priority = 0, - .paletteNum = 3, - .affineParam = 0, -}; - -static const union AnimCmd *const gSpriteAnimTable_8617DFC[] = -{ - gSpriteAnim_8617DEC, -}; - -static const struct SpriteTemplate gUnknown_08617E00 = -{ - 0xFFFF, 0xFFFF, &gOamData_8617DF4, gSpriteAnimTable_8617DFC, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy -}; - -// EWRAM -EWRAM_DATA static u8* sUnknown_0203CF04 = NULL; -EWRAM_DATA static u8* sUnknown_0203CF08 = NULL; -EWRAM_DATA static struct Struct203CF0C *sUnknown_0203CF0C = NULL; -EWRAM_DATA static struct Struct203CF10 *sUnknown_0203CF10 = NULL; -EWRAM_DATA static u16 *sUnknown_0203CF14 = NULL; - -// IWRAM bss -IWRAM_DATA static u16 gUnknown_030012A8[8]; - -// text -void sub_81BEB24(void) -{ - u8 i; - for (i = 0; i < (sizeof(gUnknown_08617DA4)/sizeof(gUnknown_08617DA4[0])); i++) - MapGridSetMetatileIdAt(gUnknown_08617DA4[i].x + 7, gUnknown_08617DA4[i].y + 7, gUnknown_08617DA4[i].tileId); - DrawWholeMapView(); -} - -void sub_81BEB54(void) -{ - CreateTask(sub_81BED50, 9); -} - -void sub_81BEB68(void) -{ - CreateTask(sub_81BEBF4, 9); -} - -void sub_81BEB7C(void) -{ - CreateTask(sub_81BF028, 9); -} - -void sub_81BEB90(void) -{ - SetGpuReg(REG_OFFSET_BG0HOFS, sUnknown_0203CF14[0]); - SetGpuReg(REG_OFFSET_BG0VOFS, sUnknown_0203CF14[1]); -} - -void sub_81BEBB4(u8 taskId) -{ - if (!(gTasks[taskId].data[0])) - { - sUnknown_0203CF14[0] = -sUnknown_0203CF14[0]; - gTasks[taskId].data[0] = 2; - sub_81BEB90(); - } - else - { - gTasks[taskId].data[0]--; - } -} - -static void sub_81BEBF4(u8 taskId) -{ - u8 zero; - - switch (gTasks[taskId].data[0]) - { - case 0: - FreeAllWindowBuffers(); - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 2); - gTasks[taskId].data[0]++; - break; - case 1: - sUnknown_0203CF04 = (u8 *)AllocZeroed(MIRAGE_TOWER_GFX_LENGTH); - sUnknown_0203CF08 = (u8 *)AllocZeroed(MIRAGE_TOWER_PALETTE_LENGTH); - ChangeBgX(0, 0, 0); - ChangeBgY(0, 0, 0); - gTasks[taskId].data[0]++; - break; - case 2: - CpuSet(gUnknown_08617274, sUnknown_0203CF04, MIRAGE_TOWER_GFX_LENGTH / 2); - LoadBgTiles(0, sUnknown_0203CF04, MIRAGE_TOWER_GFX_LENGTH, 0); - gTasks[taskId].data[0]++; - break; - case 3: - SetBgTilemapBuffer(0, sUnknown_0203CF08); - CopyToBgTilemapBufferRect_ChangePalette(0, &gUnknown_08617B94, 12, 29, 6, 12, 17); - CopyBgTilemapBufferToVram(0); - gTasks[taskId].data[0]++; - break; - case 4: - ShowBg(0); - gTasks[taskId].data[0]++; - break; - case 5: - sub_81BEB24(); - gTasks[taskId].data[0]++; - break; - case 6: - sUnknown_0203CF14 = Alloc(4); - zero = 0; - sUnknown_0203CF14[0] = 2; - sUnknown_0203CF14[1] = zero; - CreateTask(sub_81BEBB4, 0xA); - DestroyTask(taskId); - EnableBothScriptContexts(); - break; - } -} - -#define OUTER_BUFFER_LENGTH 0x60 -#define INNER_BUFFER_LENGTH 0x30 -static void sub_81BED50(u8 taskId) -{ - u8 anotherTaskId, j; - u16 i; - u8 index; - - switch (gTasks[taskId].data[0]) - { - case 1: - sUnknown_0203CF10 = AllocZeroed(OUTER_BUFFER_LENGTH * sizeof(struct Struct203CF10)); - break; - case 3: - if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1)) - { - if (gTasks[taskId].data[1] > 1) - { - index = gTasks[taskId].data[3]; - sUnknown_0203CF10[index].buffer = Alloc(INNER_BUFFER_LENGTH); - for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++) - sUnknown_0203CF10[index].buffer[i] = i; - for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++) - { - u16 rand1, rand2, temp; - - rand1 = Random() % 0x30; - rand2 = Random() % 0x30; - SWAP(sUnknown_0203CF10[index].buffer[rand2], sUnknown_0203CF10[index].buffer[rand1], temp); - } - if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1)) - gTasks[taskId].data[3]++; - gTasks[taskId].data[1] = 0; - } - gTasks[taskId].data[1]++; - } - index = gTasks[taskId].data[3]; - for (i = (u8)(gTasks[taskId].data[2]); i < index; i++) - { - for (j = 0; j < 1; j++) - { - sub_81BF2B8(sUnknown_0203CF04, - ((((OUTER_BUFFER_LENGTH - 1) - i) * INNER_BUFFER_LENGTH) + sUnknown_0203CF10[i].buffer[(sUnknown_0203CF10[i].currIndex)++]), - 0, INNER_BUFFER_LENGTH, 1); - } - if (sUnknown_0203CF10[i].currIndex > (INNER_BUFFER_LENGTH - 1)) - { - FREE_AND_SET_NULL(sUnknown_0203CF10[i].buffer); - gTasks[taskId].data[2]++; - if ((i % 2) == 1) - sUnknown_0203CF14[1]--; - } - } - LoadBgTiles(0, sUnknown_0203CF04, MIRAGE_TOWER_GFX_LENGTH, 0); - if (sUnknown_0203CF10[OUTER_BUFFER_LENGTH - 1].currIndex > (INNER_BUFFER_LENGTH - 1)) - break; - return; - case 4: - UnsetBgTilemapBuffer(0); - anotherTaskId = FindTaskIdByFunc(sub_81BEBB4); - if (anotherTaskId != 0xFF) - DestroyTask(anotherTaskId); - sUnknown_0203CF14[1] = sUnknown_0203CF14[0] = 0; - sub_81BEB90(); - break; - case 5: - FREE_AND_SET_NULL(sUnknown_0203CF14); - FREE_AND_SET_NULL(sUnknown_0203CF10); - FREE_AND_SET_NULL(sUnknown_0203CF04); - FREE_AND_SET_NULL(sUnknown_0203CF08); - break; - case 6: - SetGpuRegBits(REG_OFFSET_BG2CNT, 0x2); - SetGpuRegBits(REG_OFFSET_BG0CNT, 0x0); - SetBgAttribute(0, BG_CTRL_ATTR_MOSAIC, 0); - sub_81971D0(); - break; - case 7: - ShowBg(0); - break; - case 8: - DestroyTask(taskId); - EnableBothScriptContexts(); - break; - } - gTasks[taskId].data[0]++; -} - -static void sub_81BF028(u8 taskId) -{ - u16 i; - u8 *buffer; - - switch (gTasks[taskId].data[0]) - { - case 1: - sUnknown_0203CF0C = AllocZeroed(sizeof(*sUnknown_0203CF0C)); - sUnknown_0203CF0C->frameImageTiles = AllocZeroed(ROOT_FOSSIL_GFX_LENGTH); - sUnknown_0203CF0C->frameImage = AllocZeroed(sizeof(*sUnknown_0203CF0C->frameImage)); - sUnknown_0203CF0C->unkC = AllocZeroed(ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16)); - sUnknown_0203CF0C->unk10 = 0; - break; - case 2: - buffer = sUnknown_0203CF0C->frameImageTiles; - for (i = 0; i < ROOT_FOSSIL_GFX_LENGTH; i++, buffer++) - *buffer = gRootFossil_Gfx[i]; - break; - case 3: - sUnknown_0203CF0C->frameImage->data = sUnknown_0203CF0C->frameImageTiles; - sUnknown_0203CF0C->frameImage->size = ROOT_FOSSIL_GFX_LENGTH; - break; - case 4: - { - struct SpriteTemplate fossilTemplate; - - fossilTemplate = gUnknown_08617E00; - fossilTemplate.images = (struct SpriteFrameImage *)(sUnknown_0203CF0C->frameImage); - sUnknown_0203CF0C->spriteId = CreateSprite(&fossilTemplate, 128, -16, 1); - gSprites[sUnknown_0203CF0C->spriteId].centerToCornerVecX = 0; - gSprites[sUnknown_0203CF0C->spriteId].data[0] = gSprites[sUnknown_0203CF0C->spriteId].pos1.x; - gSprites[sUnknown_0203CF0C->spriteId].data[1] = 1; - } - case 5: - for (i = 0; i < ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH; i++) - sUnknown_0203CF0C->unkC[i] = i; - break; - case 6: - for (i = 0; i < (ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16)); i++) - { - u16 rand1, rand2, temp; - - rand1 = Random() % 0x100; - rand2 = Random() % 0x100; - SWAP(sUnknown_0203CF0C->unkC[rand2], sUnknown_0203CF0C->unkC[rand1], temp); - } - gSprites[sUnknown_0203CF0C->spriteId].callback = sub_81BF248; - break; - case 7: - if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) - return; - DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]); - FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);; - FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage); - FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles); - FREE_AND_SET_NULL(sUnknown_0203CF0C); - break; - case 8: - EnableBothScriptContexts(); - break; - } - - gTasks[taskId].data[0]++; -} - -static void sub_81BF248(struct Sprite *sprite) -{ - if (sUnknown_0203CF0C->unk10 >= (ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH)) - { - sprite->callback = SpriteCallbackDummy; - } - else if (sprite->pos1.y >= 0x60) - { - u8 i; - for (i = 0; i < 2; i++) - { - sub_81BF2B8(sUnknown_0203CF0C->frameImageTiles, sUnknown_0203CF0C->unkC[sUnknown_0203CF0C->unk10++], 0, 16, 0); - } - StartSpriteAnim(sprite, 0); - } - else - { - sprite->pos1.y++; - } -} - -#ifdef NONMATCHING -static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) -{ - u8 r5, r4, r0, r2; - u16 var; - - r4 = r5 = b / d; - gUnknown_030012A8[0] = r4; - - r0 = r2 = b % d; - gUnknown_030012A8[1] = r2; - - r4 &= 7; - r2 &= 7; - gUnknown_030012A8[2] = r4; - gUnknown_030012A8[3] = r2; - - r0 /= 8; - r5 /= 8; - gUnknown_030012A8[4] = r0; - gUnknown_030012A8[5] = r5; - - var = ((d / 8) * (r5 * 64)) + (r0 * 64); - gUnknown_030012A8[6] = var; - - var += (r4 * 8) + r2; - gUnknown_030012A8[7] = var; - - // This part is non-matching. 99% sure it IS functionally equivalent, though. - b = (b & 1) ^ 1; - c = (c << ((b) << 2)) | (15 << ((b ^ 1) << 2)); - - a[(var / 2) + (e * 32)] &= c; -} - -#else -NAKED -static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - sub sp, 0x8\n\ - str r0, [sp]\n\ - mov r10, r1\n\ - adds r6, r2, 0\n\ - mov r8, r3\n\ - ldr r0, [sp, 0x28]\n\ - mov r9, r0\n\ - lsls r1, 16\n\ - lsrs r1, 16\n\ - mov r10, r1\n\ - lsls r6, 24\n\ - lsrs r6, 24\n\ - mov r0, r8\n\ - lsls r0, 24\n\ - mov r8, r0\n\ - lsrs r7, r0, 24\n\ - mov r1, r9\n\ - lsls r1, 24\n\ - lsrs r1, 24\n\ - mov r9, r1\n\ - mov r0, r10\n\ - adds r1, r7, 0\n\ - bl __divsi3\n\ - adds r5, r0, 0\n\ - lsls r5, 24\n\ - lsrs r4, r5, 24\n\ - ldr r3, =gUnknown_030012A8\n\ - strh r4, [r3]\n\ - mov r0, r10\n\ - adds r1, r7, 0\n\ - str r3, [sp, 0x4]\n\ - bl __modsi3\n\ - lsls r0, 24\n\ - lsrs r2, r0, 24\n\ - ldr r3, [sp, 0x4]\n\ - strh r2, [r3, 0x2]\n\ - movs r1, 0x7\n\ - ands r4, r1\n\ - ands r2, r1\n\ - strh r4, [r3, 0x4]\n\ - strh r2, [r3, 0x6]\n\ - lsrs r0, 27\n\ - lsrs r5, 27\n\ - strh r0, [r3, 0x8]\n\ - strh r5, [r3, 0xA]\n\ - mov r1, r8\n\ - lsrs r1, 27\n\ - lsls r1, 6\n\ - mov r8, r1\n\ - mov r1, r8\n\ - muls r1, r5\n\ - lsls r0, 6\n\ - adds r1, r0\n\ - lsls r1, 16\n\ - lsrs r1, 16\n\ - strh r1, [r3, 0xC]\n\ - lsls r4, 3\n\ - adds r4, r2\n\ - adds r1, r4\n\ - lsls r4, r1, 16\n\ - lsrs r4, 17\n\ - strh r1, [r3, 0xE]\n\ - movs r1, 0x1\n\ - mov r0, r10\n\ - ands r1, r0\n\ - movs r2, 0x1\n\ - eors r1, r2\n\ - lsls r0, r1, 2\n\ - lsls r6, r0\n\ - eors r1, r2\n\ - lsls r1, 2\n\ - movs r0, 0xF\n\ - lsls r0, r1\n\ - orrs r6, r0\n\ - lsls r6, 24\n\ - lsrs r6, 24\n\ - mov r1, r9\n\ - lsls r1, 5\n\ - mov r9, r1\n\ - add r9, r4\n\ - ldr r1, [sp]\n\ - add r1, r9\n\ - ldrb r0, [r1]\n\ - ands r6, r0\n\ - strb r6, [r1]\n\ - add sp, 0x8\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .pool\n\ - "); -} -#endif // NONMATCHING diff --git a/src/frontier_util.c b/src/frontier_util.c index 2fc58241a..40b1edbe3 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -2185,15 +2185,15 @@ static void sub_81A447C(void) u16 monId = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; if (monId < PARTY_SIZE) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { - for (k = 0; k < 4; k++) + for (k = 0; k < MAX_MON_MOVES; k++) { if (GetMonData(&gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1], MON_DATA_MOVE1 + k, NULL) == GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + j, NULL)) break; } - if (k == 4) + if (k == MAX_MON_MOVES) SetMonMoveSlot(&gPlayerParty[i], MOVE_SKETCH, j); } gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1] = gPlayerParty[i]; @@ -2407,9 +2407,9 @@ void sub_81A4C30(void) i = gPlayerPartyCount; LoadPlayerParty(); - sub_8076D5C(); + SetContinueGameWarpStatusToDynamicWarp(); TrySavingData(SAVE_LINK); - sav2_gender2_inplace_and_xFE(); + ClearContinueGameWarpStatus2(); gPlayerPartyCount = i; for (i = 0; i < PARTY_SIZE; i++) @@ -2511,7 +2511,7 @@ void CreateFrontierBrainPokemon(void) for (j = 0; j < NUM_STATS; j++) SetMonData(&gEnemyParty[monPartyId], MON_DATA_HP_EV + j, &sFrontierBrainsMons[facility][symbol][i].evs[j]); friendship = 0xFF; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonMoveSlot(&gEnemyParty[monPartyId], sFrontierBrainsMons[facility][symbol][i].moves[j], j); if (sFrontierBrainsMons[facility][symbol][i].moves[j] == MOVE_FRUSTRATION) diff --git a/src/ghost.c b/src/ghost.c index a755783b7..d26a4d1cb 100644 --- a/src/ghost.c +++ b/src/ghost.c @@ -800,7 +800,7 @@ void sub_81123C4(u8 taskId) task->data[10] = gBattleAnimArgs[0]; baseX = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); - baseY = sub_80A861C(gBattleAnimAttacker, 3); + baseY = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_BOTTOM); if (!IsContest()) { for (battler = 0; battler < 4; battler++) @@ -813,7 +813,7 @@ void sub_81123C4(u8 taskId) if (spriteId != MAX_SPRITES) { x = GetBattlerSpriteCoord(battler, 2); - y = sub_80A861C(battler, 3); + y = GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_BOTTOM); gSprites[spriteId].data[0] = baseX << 4; gSprites[spriteId].data[1] = baseY << 4; gSprites[spriteId].data[2] = ((x - baseX) << 4) / gBattleAnimArgs[1]; @@ -1168,7 +1168,7 @@ void sub_8112C6C(u8 taskId) task->data[1] = 16; task->data[9] = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); task->data[10] = GetBattlerYCoordWithElevation(gBattleAnimAttacker); - task->data[11] = (sub_80A861C(gBattleAnimAttacker, 1) / 2) + 8; + task->data[11] = (GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_WIDTH) / 2) + 8; task->data[7] = 0; task->data[5] = GetBattlerSpriteBGPriority(gBattleAnimAttacker); task->data[6] = GetBattlerSpriteSubpriority(gBattleAnimAttacker) - 2; diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index b973798f6..3f217b782 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -355,8 +355,8 @@ static bool8 InitHallOfFameScreen(void) gMain.state++; break; case 2: - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F42); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x710); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 7)); SetGpuReg(REG_OFFSET_BLDY, 0); sub_8174FAC(); sHofGfxPtr->state = 0; @@ -817,8 +817,8 @@ void CB2_DoHallOfFamePC(void) { u8 taskId, i; - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F42); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x710); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 7)); SetGpuReg(REG_OFFSET_BLDY, 0); taskId = CreateTask(Task_HofPC_CopySaveData, 0); @@ -1299,7 +1299,7 @@ static bool8 sub_8175024(void) CopyBgTilemapBufferToVram(3); break; case 3: - sub_81971D0(); + InitStandardTextBoxWindows(); sub_8197200(); break; case 4: @@ -1599,12 +1599,12 @@ bool8 GenerateHailParticle(u8 a, u8 b, u8 taskId, u8 c) switch (unk) { case 0: - battlerX -= sub_80A861C(battler, 1) / 6; - battlerY -= sub_80A861C(battler, 0) / 6; + battlerX -= GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_WIDTH) / 6; + battlerY -= GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_HEIGHT) / 6; break; case 1: - battlerX += sub_80A861C(battler, 1) / 6; - battlerY += sub_80A861C(battler, 0) / 6; + battlerX += GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_WIDTH) / 6; + battlerY += GetBattlerSpriteCoordAttr(battler, BATTLER_COORD_ATTR_HEIGHT) / 6; break; } } @@ -1692,7 +1692,7 @@ bool8 GenerateHailParticle(u8 a, u8 b, u8 taskId, u8 c) _0810CA60:\n\ adds r0, r5, 0\n\ movs r1, 0x1\n\ - bl sub_80A861C\n\ + bl GetBattlerSpriteCoordAttr\n\ lsls r0, 16\n\ asrs r0, 16\n\ movs r1, 0x6\n\ @@ -1704,7 +1704,7 @@ _0810CA60:\n\ lsrs r7, r1, 16\n\ adds r0, r5, 0\n\ movs r1, 0\n\ - bl sub_80A861C\n\ + bl GetBattlerSpriteCoordAttr\n\ lsls r0, 16\n\ asrs r0, 16\n\ movs r1, 0x6\n\ @@ -1716,7 +1716,7 @@ _0810CA60:\n\ _0810CA96:\n\ adds r0, r5, 0\n\ movs r1, 0x1\n\ - bl sub_80A861C\n\ + bl GetBattlerSpriteCoordAttr\n\ lsls r0, 16\n\ asrs r0, 16\n\ movs r1, 0x6\n\ @@ -1728,7 +1728,7 @@ _0810CA96:\n\ lsrs r7, r1, 16\n\ adds r0, r5, 0\n\ movs r1, 0\n\ - bl sub_80A861C\n\ + bl GetBattlerSpriteCoordAttr\n\ lsls r0, 16\n\ asrs r0, 16\n\ movs r1, 0x6\n\ diff --git a/src/item_use.c b/src/item_use.c index f82071a17..91fdc81c8 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -32,6 +32,7 @@ #include "task.h" #include "text.h" #include "constants/bg_event_constants.h" +#include "constants/event_objects.h" #include "constants/flags.h" #include "constants/items.h" #include "constants/songs.h" @@ -570,15 +571,15 @@ u8 sub_80FD9B0(s16 itemX, s16 itemY) void sub_80FDA24(u8 direction) { - EventObjectClearHeldMovementIfFinished(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]); - EventObjectClearHeldMovement(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]); - UnfreezeEventObject(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]); + EventObjectClearHeldMovementIfFinished(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]); + EventObjectClearHeldMovement(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]); + UnfreezeEventObject(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]); PlayerTurnInPlace(direction); } void sub_80FDA94(u8 taskId) { - if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE) + if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]) == TRUE) DisplayItemMessageOnField(taskId, gText_ItemFinderNearby, sub_80FD5CC); } @@ -586,7 +587,7 @@ void sub_80FDADC(u8 taskId) { s16 *data = gTasks[taskId].data; - if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE + if (EventObjectCheckHeldMovementStatus(&gEventObjects[GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0)]) == TRUE || data[2] == FALSE) { sub_80FDA24(gUnknown_085920E4[data[5]]); @@ -627,7 +628,7 @@ void sub_80FDC00(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); OpenPokeblockCase(0, CB2_ReturnToField); DestroyTask(taskId); } diff --git a/src/load_save.c b/src/load_save.c index 963626428..a7593d007 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -1,13 +1,14 @@ #include "global.h" -#include "gba/flash_internal.h" +#include "alloc.h" +#include "item.h" #include "load_save.h" #include "main.h" +#include "overworld.h" #include "pokemon.h" #include "pokemon_storage_system.h" #include "random.h" -#include "alloc.h" -#include "item.h" -#include "overworld.h" +#include "save_location.h" +#include "gba/flash_internal.h" #include "decoration_inventory.h" static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); @@ -136,30 +137,30 @@ void MoveSaveBlocks_ResetHeap(void) gSaveBlock2Ptr->encryptionKey = encryptionKey; } -u32 GetSecretBase2Field_9(void) +u32 UseContinueGameWarp(void) { - return gSaveBlock2Ptr->specialSaveWarp & 1; + return gSaveBlock2Ptr->specialSaveWarpFlags & CONTINUE_GAME_WARP; } -void ClearSecretBase2Field_9(void) +void ClearContinueGameWarpStatus(void) { - gSaveBlock2Ptr->specialSaveWarp &= ~1; + gSaveBlock2Ptr->specialSaveWarpFlags &= ~CONTINUE_GAME_WARP; } -void SetSecretBase2Field_9(void) +void SetContinueGameWarpStatus(void) { - gSaveBlock2Ptr->specialSaveWarp |= 1; + gSaveBlock2Ptr->specialSaveWarpFlags |= CONTINUE_GAME_WARP; } -void sub_8076D5C(void) +void SetContinueGameWarpStatusToDynamicWarp(void) { - sub_8084FAC(0); - gSaveBlock2Ptr->specialSaveWarp |= 1; + SetContinueGameWarpToDynamicWarp(0); + gSaveBlock2Ptr->specialSaveWarpFlags |= CONTINUE_GAME_WARP; } -void sav2_gender2_inplace_and_xFE(void) +void ClearContinueGameWarpStatus2(void) { - gSaveBlock2Ptr->specialSaveWarp &= ~1; + gSaveBlock2Ptr->specialSaveWarpFlags &= ~CONTINUE_GAME_WARP; } void SavePlayerParty(void) diff --git a/src/mail.c b/src/mail.c index 7b096ed00..45e96e85e 100644 --- a/src/mail.c +++ b/src/mail.c @@ -170,29 +170,29 @@ static const u16 sUnknown_0859F2B0[][2] = { static const struct MailGraphics sUnknown_0859F2B8[] = { { - gMailPalette_Orange, gMailTiles_Orange, gMailTilemap_Orange, 0x02c0, 0x0000, 0x294a, 0x6739 + gMailPalette_Orange, gMailTiles_Orange, gMailTilemap_Orange, 0x02c0, 0, 0x294a, 0x6739 }, { - gMailPalette_Harbor, gMailTiles_Harbor, gMailTilemap_Harbor, 0x02e0, 0x0000, 0x7fff, 0x4631 + gMailPalette_Harbor, gMailTiles_Harbor, gMailTilemap_Harbor, 0x02e0, 0, 0x7fff, 0x4631 }, { - gMailPalette_Glitter, gMailTiles_Glitter, gMailTilemap_Glitter, 0x0400, 0x0000, 0x294a, 0x6739 + gMailPalette_Glitter, gMailTiles_Glitter, gMailTilemap_Glitter, 0x0400, 0, 0x294a, 0x6739 }, { - gMailPalette_Mech, gMailTiles_Mech, gMailTilemap_Mech, 0x01e0, 0x0000, 0x7fff, 0x4631 + gMailPalette_Mech, gMailTiles_Mech, gMailTilemap_Mech, 0x01e0, 0, 0x7fff, 0x4631 }, { - gMailPalette_Wood, gMailTiles_Wood, gMailTilemap_Wood, 0x02e0, 0x0000, 0x7fff, 0x4631 + gMailPalette_Wood, gMailTiles_Wood, gMailTilemap_Wood, 0x02e0, 0, 0x7fff, 0x4631 }, { - gMailPalette_Wave, gMailTiles_Wave, gMailTilemap_Wave, 0x0300, 0x0000, 0x294a, 0x6739 + gMailPalette_Wave, gMailTiles_Wave, gMailTilemap_Wave, 0x0300, 0, 0x294a, 0x6739 }, { - gMailPalette_Bead, gMailTiles_Bead, gMailTilemap_Bead, 0x0140, 0x0000, 0x7fff, 0x4631 + gMailPalette_Bead, gMailTiles_Bead, gMailTilemap_Bead, 0x0140, 0, 0x7fff, 0x4631 }, { - gMailPalette_Shadow, gMailTiles_Shadow, gMailTilemap_Shadow, 0x0300, 0x0000, 0x7fff, 0x4631 + gMailPalette_Shadow, gMailTiles_Shadow, gMailTilemap_Shadow, 0x0300, 0, 0x7fff, 0x4631 }, { - gMailPalette_Tropic, gMailTiles_Tropic, gMailTilemap_Tropic, 0x0220, 0x0000, 0x294a, 0x6739 + gMailPalette_Tropic, gMailTiles_Tropic, gMailTilemap_Tropic, 0x0220, 0, 0x294a, 0x6739 }, { - gMailPalette_Dream, gMailTiles_Dream, gMailTilemap_Dream, 0x0340, 0x0000, 0x294a, 0x6739 + gMailPalette_Dream, gMailTiles_Dream, gMailTilemap_Dream, 0x0340, 0, 0x294a, 0x6739 }, { - gMailPalette_Fab, gMailTiles_Fab, gMailTilemap_Fab, 0x02a0, 0x0000, 0x294a, 0x6739 + gMailPalette_Fab, gMailTiles_Fab, gMailTilemap_Fab, 0x02a0, 0, 0x294a, 0x6739 }, { - gMailPalette_Retro, gMailTiles_Retro, gMailTilemap_Retro, 0x0520, 0x0000, 0x294a, 0x6739 + gMailPalette_Retro, gMailTiles_Retro, gMailTilemap_Retro, 0x0520, 0, 0x294a, 0x6739 } }; @@ -306,7 +306,7 @@ static bool8 MailReadBuildGraphics(void) case 0: SetVBlankCallback(NULL); ScanlineEffect_Stop(); - SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); + SetGpuReg(REG_OFFSET_DISPCNT, 0); break; case 1: CpuFill16(0, (void *)OAM, OAM_SIZE); @@ -323,16 +323,16 @@ static bool8 MailReadBuildGraphics(void) case 5: FreeAllSpritePalettes(); reset_temp_tile_data_buffers(); - SetGpuReg(REG_OFFSET_BG0HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG0VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG1VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG2VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG2HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG3HOFS, 0x0000); - SetGpuReg(REG_OFFSET_BG3VOFS, 0x0000); - SetGpuReg(REG_OFFSET_BLDCNT, 0x0000); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x0000); + SetGpuReg(REG_OFFSET_BG0HOFS, 0); + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG1HOFS, 0); + SetGpuReg(REG_OFFSET_BG1VOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG2HOFS, 0); + SetGpuReg(REG_OFFSET_BG3HOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); break; case 6: ResetBgsAndClearDma3BusyFlags(0); diff --git a/src/menu.c b/src/menu.c index e0e5eb4eb..f1b35b42e 100644 --- a/src/menu.c +++ b/src/menu.c @@ -48,8 +48,8 @@ struct Menu bool8 APressMuted; }; -static EWRAM_DATA u8 gStartMenuWindowId = 0; -static EWRAM_DATA u8 gUnknown_0203CD8D = 0; +static EWRAM_DATA u8 sStartMenuWindowId = 0; +static EWRAM_DATA u8 sMapNamePopupWindowId = 0; static EWRAM_DATA struct Menu gUnknown_0203CD90 = {0}; static EWRAM_DATA u16 gUnknown_0203CD9C = 0; static EWRAM_DATA u8 gUnknown_0203CD9E = 0; @@ -63,7 +63,7 @@ static EWRAM_DATA void *gUnknown_0203CDAC[0x20] = {NULL}; const u16 gUnknown_0860F074[] = INCBIN_U16("graphics/interface/860F074.gbapal"); static const u8 gUnknown_0860F094[] = { 8, 4, 1 }; -static const struct WindowTemplate gUnknown_0860F098[] = +static const struct WindowTemplate sStandardTextBox_WindowTemplates[] = { { .bg = 0, @@ -77,7 +77,7 @@ static const struct WindowTemplate gUnknown_0860F098[] = DUMMY_WIN_TEMPLATE }; -static const struct WindowTemplate gUnknown_0860F0A8 = +static const struct WindowTemplate sYesNo_WindowTemplates = { .bg = 0, .tilemapLeft = 21, @@ -137,14 +137,14 @@ extern u8 sub_8199134(s8, s8); extern void sub_8198C78(void); extern void task_free_buf_after_copying_tile_data_to_vram(u8 taskId); -void sub_81971D0(void) +void InitStandardTextBoxWindows(void) { - InitWindows(gUnknown_0860F098); - gStartMenuWindowId = 0xFF; - gUnknown_0203CD8D = 0xFF; + InitWindows(sStandardTextBox_WindowTemplates); + sStartMenuWindowId = 0xFF; + sMapNamePopupWindowId = 0xFF; } -void sub_81971F4(void) +void FreeAllOverworldWindowBuffers(void) { FreeAllWindowBuffers(); } @@ -460,12 +460,12 @@ void DisplayItemMessageOnField(u8 taskId, const u8 *string, TaskFunc callback) void DisplayYesNoMenu(void) { - CreateYesNoMenu(&gUnknown_0860F0A8, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, 0); + CreateYesNoMenu(&sYesNo_WindowTemplates, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, 0); } void sub_8197948(u8 initialCursorPos) { - CreateYesNoMenu(&gUnknown_0860F0A8, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, initialCursorPos); + CreateYesNoMenu(&sYesNo_WindowTemplates, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, initialCursorPos); } u32 GetPlayerTextSpeed(void) @@ -486,22 +486,22 @@ u8 GetPlayerTextSpeedDelay(void) u8 sub_81979C4(u8 a1) { - if (gStartMenuWindowId == 0xFF) - gStartMenuWindowId = sub_8198AA4(0, 0x16, 1, 7, (a1 * 2) + 2, 0xF, 0x139); - return gStartMenuWindowId; + if (sStartMenuWindowId == 0xFF) + sStartMenuWindowId = sub_8198AA4(0, 0x16, 1, 7, (a1 * 2) + 2, 0xF, 0x139); + return sStartMenuWindowId; } u8 GetStartMenuWindowId(void) { - return gStartMenuWindowId; + return sStartMenuWindowId; } void RemoveStartMenuWindow(void) { - if (gStartMenuWindowId != 0xFF) + if (sStartMenuWindowId != 0xFF) { - RemoveWindow(gStartMenuWindowId); - gStartMenuWindowId = 0xFF; + RemoveWindow(sStartMenuWindowId); + sStartMenuWindowId = 0xFF; } } @@ -517,22 +517,22 @@ u16 sub_8197A38(void) u8 AddMapNamePopUpWindow(void) { - if (gUnknown_0203CD8D == 0xFF) - gUnknown_0203CD8D = sub_8198AA4(0, 1, 1, 10, 3, 14, 0x107); - return gUnknown_0203CD8D; + if (sMapNamePopupWindowId == 0xFF) + sMapNamePopupWindowId = sub_8198AA4(0, 1, 1, 10, 3, 14, 0x107); + return sMapNamePopupWindowId; } u8 GetMapNamePopUpWindowId(void) { - return gUnknown_0203CD8D; + return sMapNamePopupWindowId; } void RemoveMapNamePopUpWindow(void) { - if (gUnknown_0203CD8D != 0xFF) + if (sMapNamePopupWindowId != 0xFF) { - RemoveWindow(gUnknown_0203CD8D); - gUnknown_0203CD8D = 0xFF; + RemoveWindow(sMapNamePopupWindowId); + sMapNamePopupWindowId = 0xFF; } } @@ -1934,8 +1934,8 @@ void sub_8199D98(void) void sub_8199DF0(u32 bg, u8 a1, int a2, int a3) { - int temp = (!GetBgAttribute(bg, 4)) ? 0x20 : 0x40; - void *addr = (void *)((GetBgAttribute(bg, 1) * 0x4000) + (GetBgAttribute(bg, 10) + a2) * temp); + int temp = (!GetBgAttribute(bg, BG_ATTR_PALETTEMODE)) ? 0x20 : 0x40; + void *addr = (void *)((GetBgAttribute(bg, BG_ATTR_CHARBASEINDEX) * 0x4000) + (GetBgAttribute(bg, BG_ATTR_BASETILE) + a2) * temp); RequestDma3Fill(a1 << 24 | a1 << 16 | a1 << 8 | a1, addr + VRAM, a3 * temp, 1); } diff --git a/src/mirage_tower.c b/src/mirage_tower.c new file mode 100644 index 000000000..a8dd5d9de --- /dev/null +++ b/src/mirage_tower.c @@ -0,0 +1,868 @@ +#include "global.h" +#include "alloc.h" +#include "bg.h" +#include "event_data.h" +#include "event_object_movement.h" +#include "field_camera.h" +#include "fieldmap.h" +#include "gpu_regs.h" +#include "menu.h" +#include "random.h" +#include "roulette_util.h" +#include "script.h" +#include "sound.h" +#include "sprite.h" +#include "task.h" +#include "window.h" +#include "constants/flags.h" +#include "constants/maps.h" +#include "constants/rgb.h" +#include "constants/songs.h" + +struct MirageTowerPulseBlend { + u8 taskId; + struct PulseBlend pulseBlend; +}; + +struct MetatileCoords +{ + u8 x; + u8 y; + u16 metatileId; +}; + +struct BgRegOffsets +{ + u16 bgHOFS; + u16 bgVOFS; +}; + +struct Struct203CF10 +{ + u8 *buffer; + u8 currIndex; +}; + +struct DynamicSpriteFrameImage +{ + u8 *data; + u16 size; +}; + +struct Struct203CF0C +{ + u8 *frameImageTiles; + struct DynamicSpriteFrameImage *frameImage; + u8 spriteId; + u16 *unkC; + u16 unk10; +}; + +#define MIRAGE_TOWER_GFX_LENGTH (sizeof(sBlankTile_Gfx) + sizeof(sMirageTower_Gfx)) +#define ROOT_FOSSIL_GFX_LENGTH sizeof(sRootFossil_Gfx) +#define ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH 0x100 + +// extern data +extern const struct SpriteSheet gMirageTowerCeilingCrumbleSpriteSheets[]; +extern const s16 sCeilingCrumblePositions[][3]; + +// static functions +static void PlayerDescendMirageTower(u8 taskId); +static void DoScreenShake(u8 taskId); +static void IncrementCeilingCrumbleFinishedCount(void); +static void WaitCeilingCrumble(u8 taskId); +static void FinishCeilingCrumbleTask(u8 taskId); +static void CreateCeilingCrumbleSprites(void); +static void MoveCeilingCrumbleSprite(struct Sprite* sprite); +static void DoMirageTowerDisintegration(u8 taskId); +static void InitMirageTowerShake(u8 taskId); +static void DoFossilFallAndSink(u8 taskId); +static void sub_81BF248(struct Sprite *); +static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e); + +// rodata +static const u8 sBlankTile_Gfx[32] = {0}; +static const u8 sMirageTower_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower.4bpp"); +static const u16 sMirageTowerTilemap[] = INCBIN_U16("graphics/misc/mirage_tower.bin"); +static const u16 sRootFossil_Pal[] = INCBIN_U16("graphics/misc/fossil.gbapal"); +static const u8 sRootFossil_Gfx[] = INCBIN_U8("graphics/misc/fossil.4bpp"); +static const u8 sMirageTowerCrumbles_Gfx[] = INCBIN_U8("graphics/misc/mirage_tower_crumbles.4bpp"); +static const u16 sMirageTowerCrumbles_Palette[] = INCBIN_U16("graphics/misc/mirage_tower_crumbles.gbapal"); + +const s16 sCeilingCrumblePositions[][3] = +{ + { 0, 10, 65}, + { 17, 3, 50}, + {-12, 0, 75}, + { 10, 15, 90}, + { 7, 8, 65}, + {-18, 5, 75}, + { 22, -10, 55}, + {-24, -4, 65}, +}; + +const struct SpriteSheet gMirageTowerCeilingCrumbleSpriteSheets[] = +{ + {sMirageTowerCrumbles_Gfx, 0x0080, 4000}, + {NULL} +}; + +static const struct MetatileCoords sInvisibleMirageTowerMetatiles[] = +{ + {18, 53, 0x251}, + {19, 53, 0x251}, + {20, 53, 0x251}, + {18, 54, 0x251}, + {19, 54, 0x251}, + {20, 54, 0x251}, + {18, 55, 0x251}, + {19, 55, 0x251}, + {20, 55, 0x251}, + {18, 56, 0x251}, + {19, 56, 0x251}, + {20, 56, 0x251}, + {18, 57, 0x259}, + {19, 57, 0x259}, + {20, 57, 0x259}, + {18, 58, 0x121}, + {19, 58, 0x121}, + {20, 58, 0x121}, +}; + +static const union AnimCmd gSpriteAnim_8617DEC[] = +{ + ANIMCMD_FRAME(0, 1), + ANIMCMD_END, +}; + +static const struct OamData gOamData_8617DF4 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 1, + .tileNum = 0, + .priority = 0, + .paletteNum = 3, + .affineParam = 0, +}; + +static const union AnimCmd *const gSpriteAnimTable_8617DFC[] = +{ + gSpriteAnim_8617DEC, +}; + +static const struct SpriteTemplate gUnknown_08617E00 = +{ + 0xFFFF, 0xFFFF, &gOamData_8617DF4, gSpriteAnimTable_8617DFC, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy +}; + +const struct PulseBlendSettings gMirageTowerPulseBlendSettings = { + .blendColor = RGB(27, 25, 16), + .paletteOffset = 0x61, + .numColors = 15, + .delay = 5, + .numFadeCycles = -1, + .maxBlendCoeff = 11, + .fadeType = 1, + .restorePaletteOnUnload = FALSE, + .unk7_7 = 1, +}; + +static const union AnimCmd sCeilingCrumble2AnimCmd[] = +{ + ANIMCMD_FRAME(0, 12), + ANIMCMD_JUMP(0), +}; + +static const union AnimCmd *const sCeilingCrumble2AnimCmds[] = +{ + sCeilingCrumble2AnimCmd, +}; + +static const struct OamData sCeilingCrumble2OamData = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = 0, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .x = 0, + .matrixNum = 0, + .size = 0, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0, +}; + +static const struct SpriteTemplate sCeilingCrumbleSpriteTemplate2 = { + .tileTag = 4000, + .paletteTag = 0xFFFF, + .oam = &sCeilingCrumble2OamData, + .anims = sCeilingCrumble2AnimCmds, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = MoveCeilingCrumbleSprite +}; + +static const union AnimCmd sCeilingCrumble1AnimCmd[] = +{ + ANIMCMD_FRAME(0, 12), + ANIMCMD_JUMP(0), +}; + +static const union AnimCmd *const sCeilingCrumble1AnimCmds[] = +{ + sCeilingCrumble1AnimCmd, +}; + +static const struct OamData sCeilingCrumble1OamData = +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = 0, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .x = 0, + .matrixNum = 0, + .size = 1, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0, +}; + +static const struct SpriteTemplate sCeilingCrumbleSpriteTemplate1 = { + .tileTag = 4000, + .paletteTag = 0xFFFF, + .oam = &sCeilingCrumble1OamData, + .anims = sCeilingCrumble1AnimCmds, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = MoveCeilingCrumbleSprite +}; + +EWRAM_DATA static u8* sMirageTowerGfxBuffer = NULL; +EWRAM_DATA static u8* sMirageTowerTilemapBuffer = NULL; +EWRAM_DATA static struct Struct203CF0C *sUnknown_0203CF0C = NULL; +EWRAM_DATA static struct Struct203CF10 *sUnknown_0203CF10 = NULL; +EWRAM_DATA static struct BgRegOffsets *sBgShakeOffsets = NULL; +EWRAM_DATA struct MirageTowerPulseBlend *sMirageTowerPulseBlend = NULL; + +IWRAM_DATA static u16 gUnknown_030012A8[8]; + +bool8 IsMirageTowerVisible(void) +{ + if (!(gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE111) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE111))) + return FALSE; + return FlagGet(FLAG_MIRAGE_TOWER_VISIBLE); +} + +static void UpdateMirageTowerPulseBlend(u8 taskId) +{ + UpdatePulseBlend(&sMirageTowerPulseBlend->pulseBlend); +} + +void ClearMirageTowerPulseBlend(void) +{ + sMirageTowerPulseBlend = NULL; +} + +void TryStartMirageTowerPulseBlendEffect(void) +{ + if (sMirageTowerPulseBlend) + { + sMirageTowerPulseBlend = NULL; + return; + } + + if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(ROUTE111) + || gSaveBlock1Ptr->location.mapNum != MAP_NUM(ROUTE111) + || !FlagGet(FLAG_MIRAGE_TOWER_VISIBLE)) + return; + + sMirageTowerPulseBlend = AllocZeroed(sizeof(*sMirageTowerPulseBlend)); + InitPulseBlend(&sMirageTowerPulseBlend->pulseBlend); + InitPulseBlendPaletteSettings(&sMirageTowerPulseBlend->pulseBlend, &gMirageTowerPulseBlendSettings); + MarkUsedPulseBlendPalettes(&sMirageTowerPulseBlend->pulseBlend, 0x1, TRUE); + sMirageTowerPulseBlend->taskId = CreateTask(UpdateMirageTowerPulseBlend, 0xFF); +} + +void ClearMirageTowerPulseBlendEffect(void) +{ + if (gSaveBlock1Ptr->location.mapGroup != MAP_GROUP(ROUTE111) + || gSaveBlock1Ptr->location.mapNum != MAP_NUM(ROUTE111) + || !FlagGet(FLAG_MIRAGE_TOWER_VISIBLE) + || sMirageTowerPulseBlend == NULL) + return; + + if (FuncIsActiveTask(UpdateMirageTowerPulseBlend)) + DestroyTask(sMirageTowerPulseBlend->taskId); + + UnmarkUsedPulseBlendPalettes(&sMirageTowerPulseBlend->pulseBlend, 0x1, TRUE); + UnloadUsedPulseBlendPalettes(&sMirageTowerPulseBlend->pulseBlend, 0x1, TRUE); + FREE_AND_SET_NULL(sMirageTowerPulseBlend); +} + +void SetMirageTowerVisibility(void) +{ + u16 rand; + bool8 visible; + + if (VarGet(VAR_0x40CB)) + { + FlagClear(FLAG_MIRAGE_TOWER_VISIBLE); + return; + } + + rand = Random(); + visible = rand & 1; + if (FlagGet(FLAG_FORCE_MIRAGE_TOWER_VISIBLE) == TRUE) + visible = TRUE; + + if (visible) + { + FlagSet(FLAG_MIRAGE_TOWER_VISIBLE); + TryStartMirageTowerPulseBlendEffect(); + return; + } + + FlagClear(FLAG_MIRAGE_TOWER_VISIBLE); +} + +void StartPlayerDescendMirageTower(void) +{ + CreateTask(PlayerDescendMirageTower, 8); +} + +static void PlayerDescendMirageTower(u8 taskId) +{ + u8 eventObjectId; + struct EventObject *fakePlayerEventObject; + struct EventObject *playerEventObject; + + TryGetEventObjectIdByLocalIdAndMap(45, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &eventObjectId); + fakePlayerEventObject = &gEventObjects[eventObjectId]; + gSprites[fakePlayerEventObject->spriteId].pos2.y += 4; + playerEventObject = &gEventObjects[gPlayerAvatar.eventObjectId]; + if ((gSprites[fakePlayerEventObject->spriteId].pos1.y + gSprites[fakePlayerEventObject->spriteId].pos2.y) >= + (gSprites[playerEventObject->spriteId].pos1.y + gSprites[playerEventObject->spriteId].pos2.y)) + { + DestroyTask(taskId); + EnableBothScriptContexts(); + } +} + +static void StartScreenShake(u8 yShakeOffset, u8 xShakeOffset, u8 numShakes, u8 shakeDelay) +{ + u8 taskId = CreateTask(DoScreenShake, 9); + gTasks[taskId].data[0] = xShakeOffset; + gTasks[taskId].data[1] = 0; + gTasks[taskId].data[2] = numShakes; + gTasks[taskId].data[3] = shakeDelay; + gTasks[taskId].data[4] = yShakeOffset; + SetCameraPanningCallback(NULL); + PlaySE(SE_W070); +} + +static void DoScreenShake(u8 taskId) +{ + s16 *data; + + data = gTasks[taskId].data; + data[1]++; + if (data[1] % data[3] == 0) + { + data[1] = 0; + data[2]--; + data[0] = -data[0]; + data[4] = -data[4]; + SetCameraPanning(data[0], data[4]); + if (data[2] == 0) + { + IncrementCeilingCrumbleFinishedCount(); + DestroyTask(taskId); + InstallCameraPanAheadCallback(); + } + } +} + +static void IncrementCeilingCrumbleFinishedCount(void) +{ + u8 taskId = FindTaskIdByFunc(WaitCeilingCrumble); + if (taskId != 0xFF) + gTasks[taskId].data[0]++; +} + +void DoMirageTowerCeilingCrumble(void) +{ + LoadSpriteSheets(gMirageTowerCeilingCrumbleSpriteSheets); + CreateCeilingCrumbleSprites(); + CreateTask(WaitCeilingCrumble, 8); + StartScreenShake(2, 1, 16, 3); +} + +static void WaitCeilingCrumble(u8 taskId) +{ + u16 *data = gTasks[taskId].data; + data[1]++; + // Either wait 1000 frames, or until all 16 crumble sprites and the one screen-shake task are completed. + if (data[1] == 1000 || data[0] == 17) + gTasks[taskId].func = FinishCeilingCrumbleTask; +} + +static void FinishCeilingCrumbleTask(u8 taskId) +{ + FreeSpriteTilesByTag(4000); + DestroyTask(taskId); + EnableBothScriptContexts(); +} + +static void CreateCeilingCrumbleSprites(void) +{ + u8 i; + u8 spriteId; + + for (i = 0; i < 8; i++) + { + spriteId = CreateSprite(&sCeilingCrumbleSpriteTemplate1, sCeilingCrumblePositions[i][0] + 120, sCeilingCrumblePositions[i][1], 8); + gSprites[spriteId].oam.priority = 0; + gSprites[spriteId].oam.paletteNum = 0; + gSprites[spriteId].data[0] = i; + } + for (i = 0; i < 8; i++) + { + spriteId = CreateSprite(&sCeilingCrumbleSpriteTemplate2, sCeilingCrumblePositions[i][0] + 115, sCeilingCrumblePositions[i][1] - 3, 8); + gSprites[spriteId].oam.priority = 0; + gSprites[spriteId].oam.paletteNum = 0; + gSprites[spriteId].data[0] = i; + } +} + +static void MoveCeilingCrumbleSprite(struct Sprite* sprite) +{ + sprite->data[1] += 2; + sprite->pos2.y = sprite->data[1] / 2; + if(((sprite->pos1.y) + (sprite->pos2.y)) > sCeilingCrumblePositions[sprite->data[0]][2]) + { + DestroySprite(sprite); + IncrementCeilingCrumbleFinishedCount(); + } +} + +static void SetInvisibleMirageTowerMetatiles(void) +{ + u8 i; + for (i = 0; i < ARRAY_COUNT(sInvisibleMirageTowerMetatiles); i++) + MapGridSetMetatileIdAt(sInvisibleMirageTowerMetatiles[i].x + 7, sInvisibleMirageTowerMetatiles[i].y + 7, sInvisibleMirageTowerMetatiles[i].metatileId); + DrawWholeMapView(); +} + +void StartMirageTowerDisintegration(void) +{ + CreateTask(DoMirageTowerDisintegration, 9); +} + +void StartMirageTowerShake(void) +{ + CreateTask(InitMirageTowerShake, 9); +} + +void StartMirageTowerFossilFallAndSink(void) +{ + CreateTask(DoFossilFallAndSink, 9); +} + +static void SetBgShakeOffsets(void) +{ + SetGpuReg(REG_OFFSET_BG0HOFS, sBgShakeOffsets->bgHOFS); + SetGpuReg(REG_OFFSET_BG0VOFS, sBgShakeOffsets->bgVOFS); +} + +static void UpdateBgShake(u8 taskId) +{ + if (!gTasks[taskId].data[0]) + { + sBgShakeOffsets->bgHOFS = -sBgShakeOffsets->bgHOFS; + gTasks[taskId].data[0] = 2; + SetBgShakeOffsets(); + } + else + { + gTasks[taskId].data[0]--; + } +} + +static void InitMirageTowerShake(u8 taskId) +{ + u8 zero; + + switch (gTasks[taskId].data[0]) + { + case 0: + FreeAllWindowBuffers(); + SetBgAttribute(0, BG_ATTR_PRIORITY, 2); + gTasks[taskId].data[0]++; + break; + case 1: + sMirageTowerGfxBuffer = (u8 *)AllocZeroed(MIRAGE_TOWER_GFX_LENGTH); + sMirageTowerTilemapBuffer = (u8 *)AllocZeroed(BG_SCREEN_SIZE); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + gTasks[taskId].data[0]++; + break; + case 2: + CpuSet(sBlankTile_Gfx, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH / 2); + LoadBgTiles(0, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH, 0); + gTasks[taskId].data[0]++; + break; + case 3: + SetBgTilemapBuffer(0, sMirageTowerTilemapBuffer); + CopyToBgTilemapBufferRect_ChangePalette(0, &sMirageTowerTilemap, 12, 29, 6, 12, 17); + CopyBgTilemapBufferToVram(0); + gTasks[taskId].data[0]++; + break; + case 4: + ShowBg(0); + gTasks[taskId].data[0]++; + break; + case 5: + SetInvisibleMirageTowerMetatiles(); + gTasks[taskId].data[0]++; + break; + case 6: + sBgShakeOffsets = Alloc(sizeof(*sBgShakeOffsets)); + zero = 0; + sBgShakeOffsets->bgHOFS = 2; + sBgShakeOffsets->bgVOFS = zero; + CreateTask(UpdateBgShake, 10); + DestroyTask(taskId); + EnableBothScriptContexts(); + break; + } +} + +#define OUTER_BUFFER_LENGTH 0x60 +#define INNER_BUFFER_LENGTH 0x30 +static void DoMirageTowerDisintegration(u8 taskId) +{ + u8 bgShakeTaskId, j; + u16 i; + u8 index; + + switch (gTasks[taskId].data[0]) + { + case 1: + sUnknown_0203CF10 = AllocZeroed(OUTER_BUFFER_LENGTH * sizeof(struct Struct203CF10)); + break; + case 3: + if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1)) + { + if (gTasks[taskId].data[1] > 1) + { + index = gTasks[taskId].data[3]; + sUnknown_0203CF10[index].buffer = Alloc(INNER_BUFFER_LENGTH); + for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++) + sUnknown_0203CF10[index].buffer[i] = i; + for (i = 0; i <= (INNER_BUFFER_LENGTH - 1); i++) + { + u16 rand1, rand2, temp; + + rand1 = Random() % 0x30; + rand2 = Random() % 0x30; + SWAP(sUnknown_0203CF10[index].buffer[rand2], sUnknown_0203CF10[index].buffer[rand1], temp); + } + if (gTasks[taskId].data[3] <= (OUTER_BUFFER_LENGTH - 1)) + gTasks[taskId].data[3]++; + gTasks[taskId].data[1] = 0; + } + gTasks[taskId].data[1]++; + } + index = gTasks[taskId].data[3]; + for (i = (u8)(gTasks[taskId].data[2]); i < index; i++) + { + for (j = 0; j < 1; j++) + { + sub_81BF2B8(sMirageTowerGfxBuffer, + ((((OUTER_BUFFER_LENGTH - 1) - i) * INNER_BUFFER_LENGTH) + sUnknown_0203CF10[i].buffer[(sUnknown_0203CF10[i].currIndex)++]), + 0, INNER_BUFFER_LENGTH, 1); + } + if (sUnknown_0203CF10[i].currIndex > (INNER_BUFFER_LENGTH - 1)) + { + FREE_AND_SET_NULL(sUnknown_0203CF10[i].buffer); + gTasks[taskId].data[2]++; + if ((i % 2) == 1) + sBgShakeOffsets->bgVOFS--; + } + } + LoadBgTiles(0, sMirageTowerGfxBuffer, MIRAGE_TOWER_GFX_LENGTH, 0); + if (sUnknown_0203CF10[OUTER_BUFFER_LENGTH - 1].currIndex > (INNER_BUFFER_LENGTH - 1)) + break; + return; + case 4: + UnsetBgTilemapBuffer(0); + bgShakeTaskId = FindTaskIdByFunc(UpdateBgShake); + if (bgShakeTaskId != 0xFF) + DestroyTask(bgShakeTaskId); + sBgShakeOffsets->bgVOFS = sBgShakeOffsets->bgHOFS = 0; + SetBgShakeOffsets(); + break; + case 5: + FREE_AND_SET_NULL(sBgShakeOffsets); + FREE_AND_SET_NULL(sUnknown_0203CF10); + FREE_AND_SET_NULL(sMirageTowerGfxBuffer); + FREE_AND_SET_NULL(sMirageTowerTilemapBuffer); + break; + case 6: + SetGpuRegBits(REG_OFFSET_BG2CNT, BGCNT_PRIORITY(2)); + SetGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(0)); + SetBgAttribute(0, BG_ATTR_PRIORITY, 0); + InitStandardTextBoxWindows(); + break; + case 7: + ShowBg(0); + break; + case 8: + DestroyTask(taskId); + EnableBothScriptContexts(); + break; + } + gTasks[taskId].data[0]++; +} + +static void DoFossilFallAndSink(u8 taskId) +{ + u16 i; + u8 *buffer; + + switch (gTasks[taskId].data[0]) + { + case 1: + sUnknown_0203CF0C = AllocZeroed(sizeof(*sUnknown_0203CF0C)); + sUnknown_0203CF0C->frameImageTiles = AllocZeroed(ROOT_FOSSIL_GFX_LENGTH); + sUnknown_0203CF0C->frameImage = AllocZeroed(sizeof(*sUnknown_0203CF0C->frameImage)); + sUnknown_0203CF0C->unkC = AllocZeroed(ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16)); + sUnknown_0203CF0C->unk10 = 0; + break; + case 2: + buffer = sUnknown_0203CF0C->frameImageTiles; + for (i = 0; i < ROOT_FOSSIL_GFX_LENGTH; i++, buffer++) + *buffer = sRootFossil_Gfx[i]; + break; + case 3: + sUnknown_0203CF0C->frameImage->data = sUnknown_0203CF0C->frameImageTiles; + sUnknown_0203CF0C->frameImage->size = ROOT_FOSSIL_GFX_LENGTH; + break; + case 4: + { + struct SpriteTemplate fossilTemplate; + + fossilTemplate = gUnknown_08617E00; + fossilTemplate.images = (struct SpriteFrameImage *)(sUnknown_0203CF0C->frameImage); + sUnknown_0203CF0C->spriteId = CreateSprite(&fossilTemplate, 128, -16, 1); + gSprites[sUnknown_0203CF0C->spriteId].centerToCornerVecX = 0; + gSprites[sUnknown_0203CF0C->spriteId].data[0] = gSprites[sUnknown_0203CF0C->spriteId].pos1.x; + gSprites[sUnknown_0203CF0C->spriteId].data[1] = 1; + } + case 5: + for (i = 0; i < ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH; i++) + sUnknown_0203CF0C->unkC[i] = i; + break; + case 6: + for (i = 0; i < (ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH * sizeof(u16)); i++) + { + u16 rand1, rand2, temp; + + rand1 = Random() % 0x100; + rand2 = Random() % 0x100; + SWAP(sUnknown_0203CF0C->unkC[rand2], sUnknown_0203CF0C->unkC[rand1], temp); + } + gSprites[sUnknown_0203CF0C->spriteId].callback = sub_81BF248; + break; + case 7: + if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) + return; + DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]); + FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);; + FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage); + FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles); + FREE_AND_SET_NULL(sUnknown_0203CF0C); + break; + case 8: + EnableBothScriptContexts(); + break; + } + + gTasks[taskId].data[0]++; +} + +static void sub_81BF248(struct Sprite *sprite) +{ + if (sUnknown_0203CF0C->unk10 >= (ROOT_FOSSIL_GFX_RANDOMIZER_LENGTH)) + { + sprite->callback = SpriteCallbackDummy; + } + else if (sprite->pos1.y >= 96) + { + u8 i; + for (i = 0; i < 2; i++) + sub_81BF2B8(sUnknown_0203CF0C->frameImageTiles, sUnknown_0203CF0C->unkC[sUnknown_0203CF0C->unk10++], 0, 16, 0); + + StartSpriteAnim(sprite, 0); + } + else + { + sprite->pos1.y++; + } +} + +#ifdef NONMATCHING +static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) +{ + u8 r5, r4, r0, r2; + u16 var; + + r4 = r5 = b / d; + gUnknown_030012A8[0] = r4; + + r0 = r2 = b % d; + gUnknown_030012A8[1] = r2; + + r4 &= 7; + r2 &= 7; + gUnknown_030012A8[2] = r4; + gUnknown_030012A8[3] = r2; + + r0 /= 8; + r5 /= 8; + gUnknown_030012A8[4] = r0; + gUnknown_030012A8[5] = r5; + + var = ((d / 8) * (r5 * 64)) + (r0 * 64); + gUnknown_030012A8[6] = var; + + var += (r4 * 8) + r2; + gUnknown_030012A8[7] = var; + + // This part is non-matching. 99% sure it IS functionally equivalent, though. + b = (b & 1) ^ 1; + c = (c << ((b) << 2)) | (15 << ((b ^ 1) << 2)); + + a[(var / 2) + (e * 32)] &= c; +} + +#else +NAKED +static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) +{ + asm_unified("\n\ + push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x8\n\ + str r0, [sp]\n\ + mov r10, r1\n\ + adds r6, r2, 0\n\ + mov r8, r3\n\ + ldr r0, [sp, 0x28]\n\ + mov r9, r0\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + mov r10, r1\n\ + lsls r6, 24\n\ + lsrs r6, 24\n\ + mov r0, r8\n\ + lsls r0, 24\n\ + mov r8, r0\n\ + lsrs r7, r0, 24\n\ + mov r1, r9\n\ + lsls r1, 24\n\ + lsrs r1, 24\n\ + mov r9, r1\n\ + mov r0, r10\n\ + adds r1, r7, 0\n\ + bl __divsi3\n\ + adds r5, r0, 0\n\ + lsls r5, 24\n\ + lsrs r4, r5, 24\n\ + ldr r3, =gUnknown_030012A8\n\ + strh r4, [r3]\n\ + mov r0, r10\n\ + adds r1, r7, 0\n\ + str r3, [sp, 0x4]\n\ + bl __modsi3\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + ldr r3, [sp, 0x4]\n\ + strh r2, [r3, 0x2]\n\ + movs r1, 0x7\n\ + ands r4, r1\n\ + ands r2, r1\n\ + strh r4, [r3, 0x4]\n\ + strh r2, [r3, 0x6]\n\ + lsrs r0, 27\n\ + lsrs r5, 27\n\ + strh r0, [r3, 0x8]\n\ + strh r5, [r3, 0xA]\n\ + mov r1, r8\n\ + lsrs r1, 27\n\ + lsls r1, 6\n\ + mov r8, r1\n\ + mov r1, r8\n\ + muls r1, r5\n\ + lsls r0, 6\n\ + adds r1, r0\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + strh r1, [r3, 0xC]\n\ + lsls r4, 3\n\ + adds r4, r2\n\ + adds r1, r4\n\ + lsls r4, r1, 16\n\ + lsrs r4, 17\n\ + strh r1, [r3, 0xE]\n\ + movs r1, 0x1\n\ + mov r0, r10\n\ + ands r1, r0\n\ + movs r2, 0x1\n\ + eors r1, r2\n\ + lsls r0, r1, 2\n\ + lsls r6, r0\n\ + eors r1, r2\n\ + lsls r1, 2\n\ + movs r0, 0xF\n\ + lsls r0, r1\n\ + orrs r6, r0\n\ + lsls r6, 24\n\ + lsrs r6, 24\n\ + mov r1, r9\n\ + lsls r1, 5\n\ + mov r9, r1\n\ + add r9, r4\n\ + ldr r1, [sp]\n\ + add r1, r9\n\ + ldrb r0, [r1]\n\ + ands r6, r0\n\ + strb r6, [r1]\n\ + add sp, 0x8\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + "); +} +#endif // NONMATCHING diff --git a/src/mossdeep_gym.c b/src/mossdeep_gym.c index 07920fe4c..d8adbe0c6 100644 --- a/src/mossdeep_gym.c +++ b/src/mossdeep_gym.c @@ -5,6 +5,7 @@ #include "mossdeep_gym.h" #include "script_movement.h" #include "constants/event_object_movement_constants.h" +#include "constants/event_objects.h" // Movement scripts. extern const u8 gUnknown_08612698[]; @@ -52,7 +53,7 @@ void FinishMossdeepGymTiles(void) if (gUnknown_0203CE50 != NULL) FREE_AND_SET_NULL(gUnknown_0203CE50); - id = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); + id = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); EventObjectClearHeldMovementIfFinished(&gEventObjects[id]); sub_80D338C(); } diff --git a/src/naming_screen.c b/src/naming_screen.c index e6d146b85..c310ceb9f 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -362,7 +362,7 @@ static void NamingScreen_InitBGs(void) ChangeBgX(3, 0, 0); ChangeBgY(3, 0, 0); - sub_81971D0(); + InitStandardTextBoxWindows(); sub_8197200(); for (i = 0; i < 5; i++) diff --git a/src/new_game.c b/src/new_game.c index 4804b28f3..8ecd48bc7 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -27,6 +27,7 @@ #include "pokedex.h" #include "apprentice.h" #include "frontier_util.h" +#include "constants/maps.h" extern u16 gSaveFileStatus; extern u8 gUnknown_030060B0; @@ -135,7 +136,7 @@ static void ClearFrontierRecord(void) static void WarpToTruck(void) { - Overworld_SetWarpDestination(25, 40, -1, -1, -1); // inside of truck + SetWarpDestination(MAP_GROUP(INSIDE_OF_TRUCK), MAP_NUM(INSIDE_OF_TRUCK), -1, -1, -1); WarpIntoMap(); } @@ -168,7 +169,7 @@ void NewGameInitData(void) ClearFrontierRecord(); ClearSav1(); ClearMailData(); - gSaveBlock2Ptr->specialSaveWarp = 0; + gSaveBlock2Ptr->specialSaveWarpFlags = 0; gSaveBlock2Ptr->field_A8 = 0; InitPlayerTrainerId(); PlayTimeCounter_Reset(); diff --git a/src/overworld.c b/src/overworld.c index 27bd0425a..ef424cff8 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -31,6 +31,7 @@ #include "map_name_popup.h" #include "menu.h" #include "metatile_behavior.h" +#include "mirage_tower.h" #include "money.h" #include "new_game.h" #include "palette.h" @@ -56,8 +57,10 @@ #include "constants/abilities.h" #include "constants/map_types.h" #include "constants/maps.h" +#include "constants/region_map_sections.h" #include "constants/songs.h" #include "constants/species.h" +#include "constants/weather.h" // event scripts extern const u8 EventScript_WhiteOut[]; @@ -99,7 +102,6 @@ extern void ApplyNewEncryptionKeyToWord(u32 *word, u32 newKey); extern void mapheader_run_script_with_tag_x5(void); extern void ResetFieldTasksArgs(void); extern void sub_80A0A2C(void); -extern void not_trainer_hill_battle_pyramid(void); extern void apply_map_tileset2_palette(const struct MapLayout *); extern void copy_map_tileset2_to_vram_2(const struct MapLayout *); extern void RestartWildEncounterImmunitySteps(void); @@ -112,9 +114,7 @@ extern void sub_81AA1D8(void); extern void c2_change_map(void); extern void sub_81D5DF8(void); extern void sub_80EB218(void); -extern void sub_81BE72C(void); extern void sub_80AF3C8(void); -extern void sub_81971F4(void); extern void sub_808B578(void); extern void sub_80AF314(void); extern void sub_80AF214(void); @@ -125,17 +125,12 @@ extern void sub_80AF168(void); extern void sub_80AF3C8(void); extern void ExecuteTruckSequence(void); extern void sub_80A0A38(void); -extern void trainer_hill_map_load_related(void); -extern void sub_8087D74(void); -extern void battle_pyramid_map_load_related(u8); extern void WriteFlashScanlineEffectBuffer(u8); -extern void sub_80E9238(u8); extern void sub_81AA2F8(void); extern void sub_8195E10(void); extern void sub_80EDB44(void); extern void sub_81D64C0(void); -extern void sub_81BE6AC(void); -extern void sub_8098128(void); +extern void InitFieldMessageBox(void); extern void copy_map_tileset1_to_vram(const struct MapLayout *); extern void copy_map_tileset2_to_vram(const struct MapLayout *); extern void FieldUpdateBgTilemapScroll(void); @@ -146,11 +141,9 @@ extern bool8 warp0_in_pokecenter(void); extern void ResetAllPicSprites(void); extern void FieldEffectActiveListClear(void); extern void SetUpFieldTasks(void); -extern void sub_81BE6B8(void); extern void ShowStartMenu(void); extern void sub_80AEE84(void); extern void mapldr_default(void); -extern void sub_8088B3C(u16, u16); extern bool32 sub_800F0B8(void); extern bool32 sub_8009F3C(void); extern void sub_8010198(void); @@ -341,7 +334,7 @@ const struct UCoords32 gDirectionToVectors[] = }, }; -static const struct BgTemplate gUnknown_08339DAC[] = +static const struct BgTemplate sOverworldBgTemplates[] = { { .bg = 0, @@ -435,7 +428,7 @@ void DoWhiteOut(void) SetMoney(&gSaveBlock1Ptr->money, GetMoney(&gSaveBlock1Ptr->money) / 2); HealPlayerParty(); Overworld_ResetStateAfterWhiteOut(); - Overworld_SetWarpDestToLastHealLoc(); + SetWarpDestinationToLastHealLocation(); WarpIntoMap(); } @@ -617,7 +610,7 @@ void ApplyCurrentWarp(void) gFixedHoleWarp = sDummyWarpData; } -void set_warp2_warp3_to_neg_1(void) +static void ClearDiveAndHoleWarps(void) { gFixedDiveWarp = sDummyWarpData; gFixedHoleWarp = sDummyWarpData; @@ -698,68 +691,66 @@ void WarpIntoMap(void) SetPlayerCoordsFromWarp(); } -void Overworld_SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +void SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { SetWarpData(&sWarpDestination, mapGroup, mapNum, warpId, x, y); } -void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpId) +void SetWarpDestinationToMapWarp(s8 mapGroup, s8 mapNum, s8 warpId) { - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, -1, -1); + SetWarpDestination(mapGroup, mapNum, warpId, -1, -1); } -void saved_warp2_set(s32 unused, s8 mapGroup, s8 mapNum, s8 warpId) +void SetDynamicWarp(s32 unused, s8 mapGroup, s8 mapNum, s8 warpId) { - SetWarpData(&gSaveBlock1Ptr->warp2, mapGroup, mapNum, warpId, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y); + SetWarpData(&gSaveBlock1Ptr->dynamicWarp, mapGroup, mapNum, warpId, gSaveBlock1Ptr->pos.x, gSaveBlock1Ptr->pos.y); } -void saved_warp2_set_2(s32 unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +void SetDynamicWarpWithCoords(s32 unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - SetWarpData(&gSaveBlock1Ptr->warp2, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gSaveBlock1Ptr->dynamicWarp, mapGroup, mapNum, warpId, x, y); } -void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused) +void SetWarpDestinationToDynamicWarp(u8 unusedWarpId) { - sWarpDestination = gSaveBlock1Ptr->warp2; + sWarpDestination = gSaveBlock1Ptr->dynamicWarp; } -void sub_8084CCC(u8 a1) +void SetWarpDestinationToHealLocation(u8 healLocationId) { - const struct HealLocation *warp = GetHealLocation(a1); - + const struct HealLocation *warp = GetHealLocation(healLocationId); if (warp) - Overworld_SetWarpDestination(warp->group, warp->map, -1, warp->x, warp->y); + SetWarpDestination(warp->group, warp->map, -1, warp->x, warp->y); } -void Overworld_SetWarpDestToLastHealLoc(void) +void SetWarpDestinationToLastHealLocation(void) { sWarpDestination = gSaveBlock1Ptr->lastHealLocation; } -void Overworld_SetHealLocationWarp(u8 healLocationId) +void SetLastHealLocationWarp(u8 healLocationId) { const struct HealLocation *healLocation = GetHealLocation(healLocationId); - - if (healLocation != NULL) + if (healLocation) SetWarpData(&gSaveBlock1Ptr->lastHealLocation, healLocation->group, healLocation->map, -1, healLocation->x, healLocation->y); } -void sub_8084D5C(s16 a1, s16 a2) +void UpdateEscapeWarp(s16 x, s16 y) { - u8 currMapType = Overworld_GetMapTypeOfSaveblockLocation(); + u8 currMapType = GetCurrentMapType(); u8 destMapType = GetMapTypeByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum); if (is_map_type_1_2_3_5_or_6(currMapType) && is_map_type_1_2_3_5_or_6(destMapType) != TRUE) - sub_8084DD4(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, a1 - 7, a2 - 6); + SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x - 7, y - 6); } -void sub_8084DD4(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +void SetEscapeWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - SetWarpData(&gSaveBlock1Ptr->warp4, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gSaveBlock1Ptr->escapeWarp, mapGroup, mapNum, warpId, x, y); } -void sub_8084E14(void) +void SetWarpDestinationToEscapeWarp(void) { - sWarpDestination = gSaveBlock1Ptr->warp4; + sWarpDestination = gSaveBlock1Ptr->escapeWarp; } void SetFixedDiveWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) @@ -767,7 +758,7 @@ void SetFixedDiveWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) SetWarpData(&gFixedDiveWarp, mapGroup, mapNum, warpId, x, y); } -static void SetFixedDiveWarpAsDestination(void) +static void SetWarpDestinationToDiveWarp(void) { sWarpDestination = gFixedDiveWarp; } @@ -777,34 +768,34 @@ void SetFixedHoleWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) SetWarpData(&gFixedHoleWarp, mapGroup, mapNum, warpId, x, y); } -void SetFixedHoleWarpAsDestination(s16 x, s16 y) +void SetWarpDestinationToFixedHoleWarp(s16 x, s16 y) { if (IsDummyWarp(&gFixedHoleWarp) == TRUE) sWarpDestination = gLastUsedWarp; else - Overworld_SetWarpDestination(gFixedHoleWarp.mapGroup, gFixedHoleWarp.mapNum, -1, x, y); + SetWarpDestination(gFixedHoleWarp.mapGroup, gFixedHoleWarp.mapNum, -1, x, y); } -void warp1_set_to_sav1w(void) +static void SetWarpDestinationToContinueGameWarp(void) { - sWarpDestination = gSaveBlock1Ptr->warp1; + sWarpDestination = gSaveBlock1Ptr->continueGameWarp; } -void sub_8084F2C(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +void SetContinueGameWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - SetWarpData(&gSaveBlock1Ptr->warp1, mapGroup, mapNum, warpId, x, y); + SetWarpData(&gSaveBlock1Ptr->continueGameWarp, mapGroup, mapNum, warpId, x, y); } -void sub_8084F6C(u8 a1) +void SetContinueGameWarpToHealLocation(u8 healLocationId) { - const struct HealLocation *warp = GetHealLocation(a1); + const struct HealLocation *warp = GetHealLocation(healLocationId); if (warp) - SetWarpData(&gSaveBlock1Ptr->warp1, warp->group, warp->map, -1, warp->x, warp->y); + SetWarpData(&gSaveBlock1Ptr->continueGameWarp, warp->group, warp->map, -1, warp->x, warp->y); } -void sub_8084FAC(int unused) +void SetContinueGameWarpToDynamicWarp(int unused) { - gSaveBlock1Ptr->warp1 = gSaveBlock1Ptr->warp2; + gSaveBlock1Ptr->continueGameWarp = gSaveBlock1Ptr->dynamicWarp; } const struct MapConnection *GetMapConnection(u8 dir) @@ -829,14 +820,14 @@ static bool8 SetDiveWarp(u8 dir, u16 x, u16 y) if (connection != NULL) { - Overworld_SetWarpDestination(connection->mapGroup, connection->mapNum, -1, x, y); + SetWarpDestination(connection->mapGroup, connection->mapNum, -1, x, y); } else { mapheader_run_script_with_tag_x6(); if (IsDummyWarp(&gFixedDiveWarp)) return FALSE; - SetFixedDiveWarpAsDestination(); + SetWarpDestinationToDiveWarp(); } return TRUE; } @@ -855,7 +846,7 @@ void mliX_load_map(u8 mapGroup, u8 mapNum) { s32 paletteIndex; - Overworld_SetWarpDestination(mapGroup, mapNum, -1, -1, -1); + SetWarpDestination(mapGroup, mapNum, -1, -1, -1); if (gMapHeader.regionMapSectionId != 0x3A) sub_8085810(); @@ -873,7 +864,7 @@ void mliX_load_map(u8 mapGroup, u8 mapNum) SetDefaultFlashLevel(); Overworld_ClearSavedMusic(); mapheader_run_script_with_tag_x3(); - not_trainer_hill_battle_pyramid(); + InitMap(); copy_map_tileset2_to_vram_2(gMapHeader.mapLayout); apply_map_tileset2_palette(gMapHeader.mapLayout); @@ -887,7 +878,7 @@ void mliX_load_map(u8 mapGroup, u8 mapNum) ResetFieldTasksArgs(); mapheader_run_script_with_tag_x5(); - if (gMapHeader.regionMapSectionId != 0x3A || gMapHeader.regionMapSectionId != sLastMapSectionId) + if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER || gMapHeader.regionMapSectionId != sLastMapSectionId) ShowMapNamePopup(); } @@ -928,15 +919,15 @@ static void mli0_load_map(u32 a1) UpdateLocationHistoryForRoamer(); RoamerMoveToOtherLocationSet(); if (gMapHeader.mapLayoutId == 0x169) - battle_pyramid_map_load_related(0); + InitBattlePyramidMap(0); else if (InTrainerHill()) - trainer_hill_map_load_related(); + InitTrainerHillMap(); else - not_trainer_hill_battle_pyramid(); + InitMap(); if (a1 != 1 && indoors) { - UpdateTVScreensOnMap(gUnknown_03005DC0.width, gUnknown_03005DC0.height); + UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height); sub_80E9238(1); } } @@ -966,7 +957,7 @@ void StoreInitialPlayerAvatarState(void) static struct InitialPlayerAvatarState *GetInitialPlayerAvatarState(void) { struct InitialPlayerAvatarState playerStruct; - u8 mapType = Overworld_GetMapTypeOfSaveblockLocation(); + u8 mapType = GetCurrentMapType(); u16 metatileBehavior = GetCenterScreenMetatileBehavior(); u8 transitionFlags = GetAdjustedInitialTransitionFlags(&gInitialPlayerAvatarState, metatileBehavior, mapType); playerStruct.transitionFlags = transitionFlags; @@ -1053,7 +1044,7 @@ u8 Overworld_GetFlashLevel(void) return gSaveBlock1Ptr->flashLevel; } -void sub_8085524(u16 mapLayoutId) +void SetCurrentMapLayout(u16 mapLayoutId) { gSaveBlock1Ptr->mapLayoutId = mapLayoutId; gMapHeader.mapLayout = GetMapLayout(); @@ -1162,11 +1153,11 @@ u16 GetCurrLocationDefaultMusic(void) // Play the desert music only when the sandstorm is active on Route 111. if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(ROUTE111) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(ROUTE111) - && GetSav1Weather() == 8) + && GetSav1Weather() == WEATHER_SANDSTORM) return MUS_ASHROAD; music = GetLocationMusic(&gSaveBlock1Ptr->location); - if (music != 0x7FFF) + if (music != MUS_ROUTE_118) { return music; } @@ -1182,7 +1173,7 @@ u16 GetCurrLocationDefaultMusic(void) u16 GetWarpDestinationMusic(void) { u16 music = GetLocationMusic(&sWarpDestination); - if (music != 0x7FFF) + if (music != MUS_ROUTE_118) { return music; } @@ -1209,7 +1200,7 @@ void Overworld_PlaySpecialMapMusic(void) { if (gSaveBlock1Ptr->savedMusic) music = gSaveBlock1Ptr->savedMusic; - else if (Overworld_GetMapTypeOfSaveblockLocation() == MAP_TYPE_UNDERWATER) + else if (GetCurrentMapType() == MAP_TYPE_UNDERWATER) music = MUS_DEEPDEEP; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) music = MUS_NAMINORI; @@ -1287,8 +1278,8 @@ void TryFadeOutOldMapMusic(void) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SOOTOPOLIS_CITY) && sWarpDestination.mapGroup == MAP_GROUP(SOOTOPOLIS_CITY) && sWarpDestination.mapNum == MAP_NUM(SOOTOPOLIS_CITY) - && sWarpDestination.x == 0x1D - && sWarpDestination.y == 0x35) + && sWarpDestination.x == 29 + && sWarpDestination.y == 53) return; FadeOutMapMusic(GetMapMusicFadeoutSpeed()); } @@ -1390,7 +1381,7 @@ u8 GetMapTypeByWarpData(struct WarpData *warp) return GetMapTypeByGroupAndId(warp->mapGroup, warp->mapNum); } -u8 Overworld_GetMapTypeOfSaveblockLocation(void) +u8 GetCurrentMapType(void) { return GetMapTypeByWarpData(&gSaveBlock1Ptr->location); } @@ -1432,12 +1423,12 @@ bool8 Overworld_MapTypeIsIndoors(u8 mapType) return FALSE; } -u8 sav1_saved_warp2_map_get_name(void) +u8 GetSavedWarpRegionMapSectionId(void) { - return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->warp2.mapGroup, gSaveBlock1Ptr->warp2.mapNum)->regionMapSectionId; + return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->dynamicWarp.mapGroup, gSaveBlock1Ptr->dynamicWarp.mapNum)->regionMapSectionId; } -u8 sav1_map_get_name(void) +u8 GetCurrentRegionMapSectionId(void) { return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum)->regionMapSectionId; } @@ -1447,30 +1438,30 @@ u8 GetCurrentMapBattleScene(void) return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum)->battleType; } -static void overworld_bg_setup(void) +static void InitOverworldBgs(void) { - InitBgsFromTemplates(0, gUnknown_08339DAC, ARRAY_COUNT(gUnknown_08339DAC)); - SetBgAttribute(1, BG_CTRL_ATTR_PALETTEMODE, 1); - SetBgAttribute(2, BG_CTRL_ATTR_PALETTEMODE, 1); - SetBgAttribute(3, BG_CTRL_ATTR_PALETTEMODE, 1); - gBGTilemapBuffers2 = AllocZeroed(0x800); - gBGTilemapBuffers1 = AllocZeroed(0x800); - gBGTilemapBuffers3 = AllocZeroed(0x800); + InitBgsFromTemplates(0, sOverworldBgTemplates, ARRAY_COUNT(sOverworldBgTemplates)); + SetBgAttribute(1, BG_ATTR_MOSAIC, 1); + SetBgAttribute(2, BG_ATTR_MOSAIC, 1); + SetBgAttribute(3, BG_ATTR_MOSAIC, 1); + gBGTilemapBuffers2 = AllocZeroed(BG_SCREEN_SIZE); + gBGTilemapBuffers1 = AllocZeroed(BG_SCREEN_SIZE); + gBGTilemapBuffers3 = AllocZeroed(BG_SCREEN_SIZE); SetBgTilemapBuffer(1, gBGTilemapBuffers2); SetBgTilemapBuffer(2, gBGTilemapBuffers1); SetBgTilemapBuffer(3, gBGTilemapBuffers3); - sub_81971D0(); + InitStandardTextBoxWindows(); } -void overworld_free_bg_tilemaps(void) +void CleanupOverworldWindowsAndTilemaps(void) { - sub_81BE72C(); - sub_81971F4(); - if (gBGTilemapBuffers3 != NULL) + ClearMirageTowerPulseBlendEffect(); + FreeAllOverworldWindowBuffers(); + if (gBGTilemapBuffers3) FREE_AND_SET_NULL(gBGTilemapBuffers3); - if (gBGTilemapBuffers1 != NULL) + if (gBGTilemapBuffers1) FREE_AND_SET_NULL(gBGTilemapBuffers1); - if (gBGTilemapBuffers2 != NULL) + if (gBGTilemapBuffers2) FREE_AND_SET_NULL(gBGTilemapBuffers2); } @@ -1764,7 +1755,7 @@ void CB2_ContinueSavedGame(void) sub_81A3908(); LoadSaveblockMapHeader(); - set_warp2_warp3_to_neg_1(); + ClearDiveAndHoleWarps(); trainerHillMapId = GetCurrentTrainerHillMapId(); if (gMapHeader.mapLayoutId == 0x169) sub_81AA2F8(); @@ -1777,20 +1768,20 @@ void CB2_ContinueSavedGame(void) DoTimeBasedEvents(); sub_8084788(); if (gMapHeader.mapLayoutId == 0x169) - battle_pyramid_map_load_related(1); + InitBattlePyramidMap(1); else if (trainerHillMapId != 0) - trainer_hill_map_load_related(); + InitTrainerHillMap(); else - sub_8087D74(); + InitMapFromSavedGame(); PlayTimeCounter_Start(); ScriptContext1_Init(); ScriptContext2_Disable(); sub_8195E10(); - if (GetSecretBase2Field_9() == 1) + if (UseContinueGameWarp() == TRUE) { - ClearSecretBase2Field_9(); - warp1_set_to_sav1w(); + ClearContinueGameWarpStatus(); + SetWarpDestinationToContinueGameWarp(); WarpIntoMap(); sub_80EDB44(); SetMainCallback2(CB2_LoadMap); @@ -1863,7 +1854,7 @@ static bool32 map_loading_iteration_3(u8 *state) switch (*state) { case 0: - overworld_bg_setup(); + InitOverworldBgs(); ScriptContext1_Init(); ScriptContext2_Disable(); sub_80867C8(); @@ -2121,7 +2112,7 @@ static void do_load_map_stuff_loop(u8 *state) static void sub_80867C8(void) { - sub_81BE6AC(); + ClearMirageTowerPulseBlend(); MoveSaveBlocks_ResetHeap(); } @@ -2149,8 +2140,8 @@ static void InitOverworldGraphicsRegisters(void) clear_scheduled_bg_copies_to_vram(); reset_temp_tile_data_buffers(); SetGpuReg(REG_OFFSET_MOSAIC, 0); - SetGpuReg(REG_OFFSET_WININ, 0x1F1F); - SetGpuReg(REG_OFFSET_WINOUT, 0x101); + SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ); + SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WINOBJ_BG0); SetGpuReg(REG_OFFSET_WIN0H, 0xFF); SetGpuReg(REG_OFFSET_WIN0V, 0xFF); SetGpuReg(REG_OFFSET_WIN1H, 0xFFFF); @@ -2158,7 +2149,7 @@ static void InitOverworldGraphicsRegisters(void) SetGpuReg(REG_OFFSET_BLDCNT, gUnknown_82EC7C4[1] | gUnknown_82EC7C4[2] | gUnknown_82EC7C4[3] | BLDCNT_TGT2_OBJ | BLDCNT_EFFECT_BLEND); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(13, 7)); - overworld_bg_setup(); + InitOverworldBgs(); schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(2); schedule_bg_copy_tilemap_to_vram(3); @@ -2176,7 +2167,7 @@ static void InitOverworldGraphicsRegisters(void) ShowBg(1); ShowBg(2); ShowBg(3); - sub_8098128(); + InitFieldMessageBox(); } static void sub_8086988(u32 a1) @@ -2199,7 +2190,7 @@ static void sub_8086988(u32 a1) if (!a1) SetUpFieldTasks(); mapheader_run_script_with_tag_x5(); - sub_81BE6B8(); + TryStartMirageTowerPulseBlendEffect(); } static void sub_80869DC(void) @@ -2219,7 +2210,7 @@ static void mli4_mapscripts_and_other(void) gTotalCameraPixelOffsetX = 0; gTotalCameraPixelOffsetY = 0; ResetEventObjects(); - sav1_camera_get_focus_coords(&x, &y); + GetCameraFocusCoords(&x, &y); player = GetInitialPlayerAvatarState(); InitPlayerAvatar(x, y, player->direction, gSaveBlock2Ptr->playerGender); SetPlayerAvatarTransitionFlags(player->transitionFlags); @@ -2254,7 +2245,7 @@ static void sub_8086AC8(void) static void sub_8086AE4(void) { u16 x, y; - sav1_camera_get_focus_coords(&x, &y); + GetCameraFocusCoords(&x, &y); sub_8088B3C(x + gUnknown_03005DB4, y); } @@ -2263,7 +2254,7 @@ static void sub_8086B14(void) u16 i; u16 x, y; - sav1_camera_get_focus_coords(&x, &y); + GetCameraFocusCoords(&x, &y); x -= gUnknown_03005DB4; for (i = 0; i < gFieldLinkPlayerCount; i++) diff --git a/src/party_menu.c b/src/party_menu.c index 34c67c474..00432e6db 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -4721,7 +4721,7 @@ static void CursorCb_FieldMove(u8 taskId) gUnknown_0203CEC4->data[0] = fieldMove; break; case FIELD_MOVE_DIG: - mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->warp4.mapGroup, gSaveBlock1Ptr->warp4.mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->escapeWarp.mapGroup, gSaveBlock1Ptr->escapeWarp.mapNum); sub_81245DC(gStringVar1, mapHeader->regionMapSectionId); StringExpandPlaceholders(gStringVar4, gText_EscapeFromHere); sub_81B5674(taskId); @@ -7249,7 +7249,7 @@ static void sub_81B9424(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); InitPartyMenu(2, 0, 11, 0, 0, sub_81B1370, sub_81B9470); DestroyTask(taskId); } @@ -7276,7 +7276,7 @@ static void sub_81B94D0(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); InitPartyMenu(3, 0, 11, 0, 0, sub_81B1370, sub_81B9390); DestroyTask(taskId); } @@ -7293,7 +7293,7 @@ static void sub_81B953C(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); InitPartyMenu(7, 0, 11, 0, 0, sub_81B1370, sub_81B9588); DestroyTask(taskId); } @@ -7336,7 +7336,7 @@ static void sub_81B9640(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); InitPartyMenu(12, 0, 0, 0, 0, sub_81B1370, sub_81B9390); DestroyTask(taskId); } diff --git a/src/player_pc.c b/src/player_pc.c index b7380cee3..474cecaf5 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -491,7 +491,7 @@ static void Task_ItemStorage_Deposit(u8 taskId) { if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_81AAC14(); DestroyTask(taskId); } @@ -723,7 +723,7 @@ static void Mailbox_FadeAndReadMail(u8 taskId) if (!gPaletteFade.active) { sub_81D1EC0(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); ReadMail(&(gSaveBlock1Ptr->mail[playerPCItemPageInfo.itemsAbove + 6 + playerPCItemPageInfo.cursorPos]), Mailbox_ReturnToFieldFromReadMail, TRUE); DestroyTask(taskId); } @@ -823,7 +823,7 @@ static void Mailbox_DoGiveMailPokeMenu(u8 taskId) if (!gPaletteFade.active) { sub_81D1EC0(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_81B8448(); DestroyTask(taskId); } diff --git a/src/pokeball.c b/src/pokeball.c index baa165649..1938d888d 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -1170,7 +1170,7 @@ static void sub_80768F0(struct Sprite *sprite) sprite->callback = SpriteCallbackDummy; } -static void DestroySpriteAndFreeResources_(struct Sprite *sprite) +static void Unref_DestroySpriteAndFreeResources(struct Sprite *sprite) { DestroySpriteAndFreeResources(sprite); } diff --git a/src/pokedex_area_screen.c b/src/pokedex_area_screen.c index 30a127c71..a268b5382 100755 --- a/src/pokedex_area_screen.c +++ b/src/pokedex_area_screen.c @@ -533,7 +533,7 @@ static void Task_PokedexAreaScreen_0(u8 taskId) HideBg(0); break; case 1: - SetBgAttribute(3, BG_CTRL_ATTR_VISIBLE, 3); + SetBgAttribute(3, BG_ATTR_CHARBASEINDEX, 3); sub_81C4D70(&sUnknown_085B4018); StringFill(sPokedexAreaScreen->charBuffer, CHAR_SPACE, 16); break; @@ -628,8 +628,8 @@ static void Task_PokedexAreaScreen_1(u8 taskId) static void sub_813D6B4(void) { - SetBgAttribute(3, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(3, BG_CTRL_ATTR_SCREENSIZE, 0); + SetBgAttribute(3, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(3, BG_ATTR_PALETTEMODE, 0); } static void CreateAreaMarkerSprites(void) diff --git a/src/pokemon.c b/src/pokemon.c index 7c4103855..580216b2c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -931,7 +931,7 @@ const u16 gSpeciesToNationalPokedexNum[] = // Assigns all species to the Nationa SPECIES_TO_NATIONAL(CHIMECHO), }; -const u16 gHoennToNationalOrder[] = // Assigns Hoenn Dex Pokémon (Using National Dex Index) +const u16 gHoennToNationalOrder[] = // Assigns Hoenn Dex Pokémon (Using National Dex Index) { HOENN_TO_NATIONAL(TREECKO), HOENN_TO_NATIONAL(GROVYLE), @@ -1135,7 +1135,7 @@ const u16 gHoennToNationalOrder[] = // Assigns Hoenn Dex Pokémon (Using National HOENN_TO_NATIONAL(RAYQUAZA), HOENN_TO_NATIONAL(JIRACHI), HOENN_TO_NATIONAL(DEOXYS), - HOENN_TO_NATIONAL(BULBASAUR), // Pokémon from here onwards are UNSEEN in the HoennDex. + HOENN_TO_NATIONAL(BULBASAUR), // Pokémon from here onwards are UNSEEN in the HoennDex. HOENN_TO_NATIONAL(IVYSAUR), HOENN_TO_NATIONAL(VENUSAUR), HOENN_TO_NATIONAL(CHARMANDER), @@ -2588,7 +2588,7 @@ void CreateBoxMon(struct BoxPokemon *boxMon, u16 species, u8 level, u8 fixedIV, SetBoxMonData(boxMon, MON_DATA_SPECIES, &species); SetBoxMonData(boxMon, MON_DATA_EXP, &gExperienceTables[gBaseStats[species].growthRate][level]); SetBoxMonData(boxMon, MON_DATA_FRIENDSHIP, &gBaseStats[species].friendship); - value = sav1_map_get_name(); + value = GetCurrentRegionMapSectionId(); SetBoxMonData(boxMon, MON_DATA_MET_LOCATION, &value); SetBoxMonData(boxMon, MON_DATA_MET_LEVEL, &level); SetBoxMonData(boxMon, MON_DATA_MET_GAME, &gGameVersion); @@ -2754,7 +2754,7 @@ void sub_806819C(struct Pokemon *mon, struct BattleTowerPokemon *src) CreateMon(mon, src->species, src->level, 0, 1, src->personality, 1, src->otId); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) SetMonMoveSlot(mon, src->moves[i], i); SetMonData(mon, MON_DATA_PP_BONUSES, &src->ppBonuses); @@ -2816,7 +2816,7 @@ void sub_8068338(struct Pokemon *mon, struct BattleTowerPokemon *src, bool8 lvl5 CreateMon(mon, src->species, level, 0, 1, src->personality, 1, src->otId); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) SetMonMoveSlot(mon, src->moves[i], i); SetMonData(mon, MON_DATA_PP_BONUSES, &src->ppBonuses); @@ -2880,7 +2880,7 @@ void CreateApprenticeMon(struct Pokemon *mon, const struct Apprentice *src, u8 m otId); SetMonData(mon, MON_DATA_HELD_ITEM, &src->party[monId].item); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) SetMonMoveSlot(mon, src->party[monId].moves[i], i); evAmount = MAX_TOTAL_EVS / NUM_STATS; @@ -2940,7 +2940,7 @@ void sub_80686FC(struct Pokemon *mon, struct BattleTowerPokemon *dest) dest->heldItem = heldItem; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) dest->moves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, NULL); dest->level = GetMonData(mon, MON_DATA_LEVEL, NULL); @@ -3266,7 +3266,7 @@ u16 GiveMoveToMon(struct Pokemon *mon, u16 move) u16 GiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { u16 existingMove = GetBoxMonData(boxMon, MON_DATA_MOVE1 + i, NULL); if (!existingMove) @@ -3285,7 +3285,7 @@ u16 GiveMoveToBattleMon(struct BattlePokemon *mon, u16 move) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (!mon->moves[i]) { @@ -3388,7 +3388,7 @@ void DeleteFirstMoveAndGiveMoveToMon(struct Pokemon *mon, u16 move) moves[3] = move; pp[3] = gBattleMoves[move].pp; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetMonData(mon, MON_DATA_MOVE1 + i, &moves[i]); SetMonData(mon, MON_DATA_PP1 + i, &pp[i]); @@ -3415,7 +3415,7 @@ void DeleteFirstMoveAndGiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move) moves[3] = move; pp[3] = gBattleMoves[move].pp; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { SetBoxMonData(boxMon, MON_DATA_MOVE1 + i, &moves[i]); SetBoxMonData(boxMon, MON_DATA_PP1 + i, &pp[i]); @@ -4849,7 +4849,7 @@ void CreateSecretBaseEnemyParty(struct SecretBaseRecord *secretBaseRecord) for (j = 0; j < 6; j++) SetMonData(&gEnemyParty[i], MON_DATA_HP_EV + j, &gBattleResources->secretBase->party.EVs[i]); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonData(&gEnemyParty[i], MON_DATA_MOVE1 + j, &gBattleResources->secretBase->party.moves[i * 4 + j]); SetMonData(&gEnemyParty[i], MON_DATA_PP1 + j, &gBattleMoves[gBattleResources->secretBase->party.moves[i * 4 + j]].pp); @@ -4938,7 +4938,7 @@ void CopyPlayerPartyMonToBattleData(u8 battlerId, u8 partyIndex) gBattleMons[battlerId].species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); gBattleMons[battlerId].item = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HELD_ITEM, NULL); - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { gBattleMons[battlerId].moves[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE1 + i, NULL); gBattleMons[battlerId].pp[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP1 + i, NULL); @@ -5457,7 +5457,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov { if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == 11) friendship++; - if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == sav1_map_get_name()) + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == GetCurrentRegionMapSectionId()) friendship++; } if (friendship < 0) @@ -5483,7 +5483,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov { if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == 11) friendship++; - if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == sav1_map_get_name()) + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == GetCurrentRegionMapSectionId()) friendship++; } if (friendship < 0) @@ -5508,7 +5508,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov { if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == 11) friendship++; - if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == sav1_map_get_name()) + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == GetCurrentRegionMapSectionId()) friendship++; } if (friendship < 0) @@ -6156,7 +6156,7 @@ void AdjustFriendship(struct Pokemon *mon, u8 event) { if (GetMonData(mon, MON_DATA_POKEBALL, 0) == ITEM_LUXURY_BALL) friendship++; - if (GetMonData(mon, MON_DATA_MET_LOCATION, 0) == sav1_map_get_name()) + if (GetMonData(mon, MON_DATA_MET_LOCATION, 0) == GetCurrentRegionMapSectionId()) friendship++; } if (friendship < 0) @@ -6480,7 +6480,7 @@ u8 GetMoveRelearnerMoves(struct Pokemon *mon, u16 *moves) u8 level = GetMonData(mon, MON_DATA_LEVEL, 0); int i, j, k; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, 0); for (i = 0; i < 20; i++) @@ -6494,10 +6494,10 @@ u8 GetMoveRelearnerMoves(struct Pokemon *mon, u16 *moves) if (moveLevel <= (level << 9)) { - for (j = 0; j < 4 && learnedMoves[j] != (gLevelUpLearnsets[species][i] & 0x1FF); j++) + for (j = 0; j < MAX_MON_MOVES && learnedMoves[j] != (gLevelUpLearnsets[species][i] & 0x1FF); j++) ; - if (j == 4) + if (j == MAX_MON_MOVES) { for (k = 0; k < numMoves && moves[k] != (gLevelUpLearnsets[species][i] & 0x1FF); k++) ; @@ -6534,7 +6534,7 @@ u8 GetNumberOfRelearnableMoves(struct Pokemon *mon) if (species == SPECIES_EGG) return 0; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) learnedMoves[i] = GetMonData(mon, MON_DATA_MOVE1 + i, 0); for (i = 0; i < 20; i++) @@ -6548,10 +6548,10 @@ u8 GetNumberOfRelearnableMoves(struct Pokemon *mon) if (moveLevel <= (level << 9)) { - for (j = 0; j < 4 && learnedMoves[j] != (gLevelUpLearnsets[species][i] & 0x1FF); j++) + for (j = 0; j < MAX_MON_MOVES && learnedMoves[j] != (gLevelUpLearnsets[species][i] & 0x1FF); j++) ; - if (j == 4) + if (j == MAX_MON_MOVES) { for (k = 0; k < numMoves && moves[k] != (gLevelUpLearnsets[species][i] & 0x1FF); k++) ; @@ -6701,7 +6701,7 @@ const u32 *GetFrontSpritePalFromSpeciesAndPersonality(u16 species, u32 otId, u32 { u32 shinyValue; - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) return gMonPaletteTable[0].data; shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality); @@ -6795,7 +6795,7 @@ void BoxMonRestorePP(struct BoxPokemon *boxMon) { int i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (GetBoxMonData(boxMon, MON_DATA_MOVE1 + i, 0)) { diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 36a7da0ee..bcbb60e21 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -1045,7 +1045,7 @@ u8 CreateMonIcon(u16 species, void (*callback)(struct Sprite *), s16 x, s16 y, u .paletteTag = POKE_ICON_BASE_PAL_TAG + gMonIconPaletteIndices[species], }; - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) iconTemplate.paletteTag = POKE_ICON_BASE_PAL_TAG; spriteId = CreateMonIconSprite(&iconTemplate, x, y, subpriority); @@ -1091,7 +1091,7 @@ u16 GetIconSpecies(u16 species, u32 personality) } else { - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) result = 260; else result = species; @@ -1149,7 +1149,7 @@ void LoadMonIconPalettes(void) void SafeLoadMonIconPalette(u16 species) { u8 palIndex; - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) species = 260; palIndex = gMonIconPaletteIndices[species]; if (IndexOfSpritePaletteTag(gMonIconPaletteTable[palIndex].tag) == 0xFF) @@ -1174,7 +1174,7 @@ void FreeMonIconPalettes(void) void SafeFreeMonIconPalette(u16 species) { u8 palIndex; - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) species = 260; palIndex = gMonIconPaletteIndices[species]; FreeSpritePaletteByTag(gMonIconPaletteTable[palIndex].tag); @@ -1207,7 +1207,7 @@ void sub_80D304C(u16 offset) s32 i; const struct SpritePalette* monIconPalettePtr; - if(offset <= 0xA0) + if (offset <= 0xA0) { monIconPalettePtr = gMonIconPaletteTable; for(i = 5; i >= 0; i--) @@ -1221,7 +1221,7 @@ void sub_80D304C(u16 offset) u8 GetValidMonIconPalIndex(u16 species) { - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) species = 260; return gMonIconPaletteIndices[species]; } @@ -1233,7 +1233,7 @@ u8 sub_80D30A0(u16 species) const u16* GetValidMonIconPalettePtr(u16 species) { - if (species > SPECIES_EGG) + if (species > NUM_SPECIES) species = 260; return gMonIconPaletteTable[gMonIconPaletteIndices[species]].data; } diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 7b1d8da7c..36ed78a54 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -1759,7 +1759,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) case 4: if (!gPaletteFade.active) { - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); Cb2_EnterPSS(task->data[2]); RemoveWindow(task->data[15]); DestroyTask(taskId); @@ -8826,7 +8826,7 @@ static bool8 sub_80D024C(void) FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); FillWindowPixelBuffer8Bit(sPSSData->field_2200, 0); sub_80D07B0(sMoveMonsPtr->fromRow, sMoveMonsPtr->fromColumn); - SetBgAttribute(0, 4, 1); + SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); PutWindowTilemap(sPSSData->field_2200); CopyWindowToVram8Bit(sPSSData->field_2200, 3); BlendPalettes(0x3F00, 8, RGB_WHITE); @@ -9246,7 +9246,7 @@ static void sub_80D0B5C(void) { ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); - SetBgAttribute(0, 4, 0); + SetBgAttribute(0, BG_ATTR_PALETTEMODE, 0); ClearGpuRegBits(REG_OFFSET_BG0CNT, BGCNT_256COLOR); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); CopyBgTilemapBufferToVram(0); @@ -9865,7 +9865,7 @@ static bool8 sub_80D184C(void) var = 0x15 - sPSSData->field_2236; for (i = 0; i < var; i++) { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, 10) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); } sub_80D19B4(var); @@ -9886,7 +9886,7 @@ static bool8 sub_80D18E4(void) var = 0x15 - sPSSData->field_2236; for (i = 0; i < var; i++) { - WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, 10) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); + WriteSequenceToBgTilemapBuffer(0, GetBgAttribute(0, BG_ATTR_BASETILE) + 0x14 + sPSSData->field_2236 + i, i, 13, 1, 7, 15, 21); } if (var >= 0) @@ -10423,7 +10423,7 @@ static const sUnkVars[][4] = static void sub_80D2644(u8 id, u8 bg, const void *arg2, u16 arg3, u16 arg4) { - u16 attribute1, attribute2; + u16 bgScreenSize, bgType; if (id >= gUnknown_02039D88) return; @@ -10434,11 +10434,11 @@ static void sub_80D2644(u8 id, u8 bg, const void *arg2, u16 arg3, u16 arg4) gUnknown_02039D84[id].field_24 = arg3; gUnknown_02039D84[id].field_26 = arg4; - attribute1 = GetBgAttribute(bg, 3); - attribute2 = GetBgAttribute(bg, 9); - gUnknown_02039D84[id].field_20 = sUnkVars[attribute2][attribute1].a; - gUnknown_02039D84[id].field_22 = sUnkVars[attribute2][attribute1].b; - if (attribute2 != 0) + bgScreenSize = GetBgAttribute(bg, BG_ATTR_SCREENSIZE); + bgType = GetBgAttribute(bg, BG_ATTR_TYPE); + gUnknown_02039D84[id].field_20 = sUnkVars[bgType][bgScreenSize].a; + gUnknown_02039D84[id].field_22 = sUnkVars[bgType][bgScreenSize].b; + if (bgType != 0) gUnknown_02039D84[id].field_2A = 1; else gUnknown_02039D84[id].field_2A = 2; diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index e6714e2a8..14d5aa9dc 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -311,7 +311,7 @@ static const struct UnkStruct_61CC04 gUnknown_0861CC10 = static const s8 gUnknown_0861CC1C[] = {0, 2, 3, 1, 4, 5}; static const struct WindowTemplate gUnknown_0861CC24[] = { - { + {//Text for Pokemon Info .bg = 0, .tilemapLeft = 0, .tilemapTop = 0, @@ -320,7 +320,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 1, }, - { + {//Text for Pokemon Skills .bg = 0, .tilemapLeft = 0, .tilemapTop = 0, @@ -329,7 +329,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 23, }, - { + {//Text for Battle Moves .bg = 0, .tilemapLeft = 0, .tilemapTop = 0, @@ -338,7 +338,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 45, }, - { + {//Text for Contest Moves .bg = 0, .tilemapLeft = 0, .tilemapTop = 0, @@ -347,7 +347,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 67, }, - { + { //Text on Pokemon Info: Button prompt: Cancel .bg = 0, .tilemapLeft = 22, .tilemapTop = 0, @@ -356,7 +356,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 7, .baseBlock = 89, }, - { + {//Info button found under moves .bg = 0, .tilemapLeft = 22, .tilemapTop = 0, @@ -365,7 +365,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 7, .baseBlock = 105, }, - { + {//Switch button under moves when viewing moves .bg = 0, .tilemapLeft = 22, .tilemapTop = 0, @@ -374,7 +374,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 7, .baseBlock = 121, }, - { + {//Unknown .bg = 0, .tilemapLeft = 11, .tilemapTop = 4, @@ -383,7 +383,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 137, }, - { + {//Unknown .bg = 0, .tilemapLeft = 11, .tilemapTop = 4, @@ -392,7 +392,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 137, }, - { + {//Type on pokemon info page .bg = 0, .tilemapLeft = 11, .tilemapTop = 6, @@ -401,7 +401,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 173, }, - { + {//HP, Attack and Defense text .bg = 0, .tilemapLeft = 10, .tilemapTop = 7, @@ -410,7 +410,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 209, }, - { + {//Sp. atk, Sp. Def and Speed texxt .bg = 0, .tilemapLeft = 22, .tilemapTop = 7, @@ -419,7 +419,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 245, }, - { + {//EXP and next lvl. .bg = 0, .tilemapLeft = 10, .tilemapTop = 14, @@ -428,7 +428,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 275, }, - { + {//Unknown .bg = 0, .tilemapLeft = 0, .tilemapTop = 18, @@ -437,7 +437,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 319, }, - { + {//move text: Power, Accuracy and their numeric values. .bg = 0, .tilemapLeft = 1, .tilemapTop = 15, @@ -446,7 +446,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 331, }, - { + {//contest text: appeal and jam .bg = 0, .tilemapLeft = 1, .tilemapTop = 15, @@ -455,7 +455,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 367, }, - { + {//Unknown .bg = 0, .tilemapLeft = 22, .tilemapTop = 4, @@ -464,7 +464,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 387, }, - { + {//No. .bg = 0, .tilemapLeft = 1, .tilemapTop = 2, @@ -473,7 +473,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 7, .baseBlock = 387, }, - { + {//Upper name .bg = 0, .tilemapLeft = 1, .tilemapTop = 12, @@ -482,7 +482,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = .paletteNum = 6, .baseBlock = 395, }, - { + {//Lower name .bg = 0, .tilemapLeft = 1, .tilemapTop = 14, @@ -495,7 +495,7 @@ static const struct WindowTemplate gUnknown_0861CC24[] = }; static const struct WindowTemplate gUnknown_0861CCCC[] = { - { + {//Original Trainer .bg = 0, .tilemapLeft = 11, .tilemapTop = 4, @@ -504,7 +504,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] = .paletteNum = 6, .baseBlock = 449, }, - { + {//ID numbers .bg = 0, .tilemapLeft = 22, .tilemapTop = 4, @@ -513,7 +513,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] = .paletteNum = 6, .baseBlock = 471, }, - { + {//Ability .bg = 0, .tilemapLeft = 11, .tilemapTop = 9, @@ -522,7 +522,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] = .paletteNum = 6, .baseBlock = 485, }, - { + {//Trainer Memo .bg = 0, .tilemapLeft = 11, .tilemapTop = 14, @@ -534,7 +534,7 @@ static const struct WindowTemplate gUnknown_0861CCCC[] = }; static const struct WindowTemplate gUnknown_0861CCEC[] = { - { + {//Held Item string .bg = 0, .tilemapLeft = 10, .tilemapTop = 4, @@ -543,7 +543,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] = .paletteNum = 6, .baseBlock = 449, }, - { + {//Ribbon string .bg = 0, .tilemapLeft = 20, .tilemapTop = 4, @@ -552,7 +552,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] = .paletteNum = 6, .baseBlock = 469, }, - { + {//Stat numbers left (HP, ATK & DEF) .bg = 0, .tilemapLeft = 16, .tilemapTop = 7, @@ -561,7 +561,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] = .paletteNum = 6, .baseBlock = 489, }, - { + {//Stat numbers right (SP.ATK, SP.DEF & SPEED) .bg = 0, .tilemapLeft = 27, .tilemapTop = 7, @@ -570,7 +570,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] = .paletteNum = 6, .baseBlock = 525, }, - { + {//Exp numbers .bg = 0, .tilemapLeft = 24, .tilemapTop = 14, @@ -582,7 +582,7 @@ static const struct WindowTemplate gUnknown_0861CCEC[] = }; static const struct WindowTemplate gUnknown_0861CD14[] = { - { + {//Move names? .bg = 0, .tilemapLeft = 15, .tilemapTop = 4, @@ -591,7 +591,7 @@ static const struct WindowTemplate gUnknown_0861CD14[] = .paletteNum = 6, .baseBlock = 449, }, - { + {//PP Numbers .bg = 0, .tilemapLeft = 24, .tilemapTop = 4, @@ -600,7 +600,7 @@ static const struct WindowTemplate gUnknown_0861CD14[] = .paletteNum = 8, .baseBlock = 539, }, - { + {//Move description text .bg = 0, .tilemapLeft = 10, .tilemapTop = 15, @@ -1315,7 +1315,7 @@ static bool8 ExtractMonDataToSummaryStruct(struct Pokemon *a) break; case 1: - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { sum->moves[i] = GetMonData(a, MON_DATA_MOVE1+i); sum->pp[i] = GetMonData(a, MON_DATA_PP1+i); @@ -1688,15 +1688,15 @@ static void sub_81C0B8C(u8 taskId) if (pssData->unk40C9 == 0) { data[1] = 1; - SetBgAttribute(1, 7, 1); - SetBgAttribute(2, 7, 2); + SetBgAttribute(1, BG_ATTR_PRIORITY, 1); + SetBgAttribute(2, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(1); } else { data[1] = 2; - SetBgAttribute(2, 7, 1); - SetBgAttribute(1, 7, 2); + SetBgAttribute(2, BG_ATTR_PRIORITY, 1); + SetBgAttribute(1, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(2); } ChangeBgX(data[1], 0, 0); @@ -1745,14 +1745,14 @@ static void sub_81C0D44(u8 taskId) s16 *data = gTasks[taskId].data; if (pssData->unk40C9 == 0) { - SetBgAttribute(1, 7, 1); - SetBgAttribute(2, 7, 2); + SetBgAttribute(1, BG_ATTR_PRIORITY, 1); + SetBgAttribute(2, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(2); } else { - SetBgAttribute(2, 7, 1); - SetBgAttribute(1, 7, 2); + SetBgAttribute(2, BG_ATTR_PRIORITY, 1); + SetBgAttribute(1, BG_ATTR_PRIORITY, 2); schedule_bg_copy_tilemap_to_vram(1); } if (pssData->currPageIndex > 1) @@ -1851,7 +1851,7 @@ static void sub_81C0F44(u8 taskId) static bool8 sub_81C1040(void) { u8 i; - for (i = 1; i < 4; i++) + for (i = 1; i < MAX_MON_MOVES; i++) { if (pssData->summary.moves[i] != 0) return TRUE; @@ -1867,14 +1867,14 @@ static void sub_81C1070(s16 *a, s8 b, u8 *c) PlaySE(SE_SELECT); moveIndex = *c; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { moveIndex += b; if (moveIndex > a[0]) moveIndex = 0; else if (moveIndex < 0) moveIndex = a[0]; - if (moveIndex == 4) + if (moveIndex == MAX_MON_MOVES) { move = pssData->newMove; break; @@ -3548,7 +3548,7 @@ static void PrintContestMoveDescription(u8 moveSlot) { u16 move; - if (moveSlot == 4) + if (moveSlot == MAX_MON_MOVES) move = pssData->newMove; else move = pssData->summary.moves[moveSlot]; @@ -3744,7 +3744,7 @@ static void sub_81C4420(void) { u8 i; struct PokeSummary *summary = &pssData->summary; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (summary->moves[i] != MOVE_NONE) SetMoveTypeSpritePosAndType(gBattleMoves[summary->moves[i]].type, 0x55, 0x20 + (i * 0x10), i + 3); @@ -3757,7 +3757,7 @@ static void sub_81C4484(void) { u8 i; struct PokeSummary *summary = &pssData->summary; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { if (summary->moves[i] != MOVE_NONE) SetMoveTypeSpritePosAndType(NUMBER_OF_MON_TYPES + gContestMoves[summary->moves[i]].contestCategory, 0x55, 0x20 + (i * 0x10), i + 3); diff --git a/src/post_battle_event_funcs.c b/src/post_battle_event_funcs.c index fe5e1089e..3cbf6ecd2 100644 --- a/src/post_battle_event_funcs.c +++ b/src/post_battle_event_funcs.c @@ -34,12 +34,12 @@ int GameClear(void) if (GetGameStat(GAME_STAT_FIRST_HOF_PLAY_TIME) == 0) SetGameStat(GAME_STAT_FIRST_HOF_PLAY_TIME, (gSaveBlock2Ptr->playTimeHours << 16) | (gSaveBlock2Ptr->playTimeMinutes << 8) | gSaveBlock2Ptr->playTimeSeconds); - SetSecretBase2Field_9(); + SetContinueGameWarpStatus(); if (gSaveBlock2Ptr->playerGender == MALE) - sub_8084F6C(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F); + SetContinueGameWarpToHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F); else - sub_8084F6C(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE_2F); + SetContinueGameWarpToHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE_2F); ribbonGet = FALSE; diff --git a/src/psychic.c b/src/psychic.c index 371c24ce8..5756fe97f 100644 --- a/src/psychic.c +++ b/src/psychic.c @@ -641,8 +641,8 @@ void sub_810F634(struct Sprite *sprite) void sub_810F6B0(struct Sprite *sprite) { - s16 x = sub_80A861C(gBattleAnimAttacker, 1) / 2; - s16 y = sub_80A861C(gBattleAnimAttacker, 0) / -2; + s16 x = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_WIDTH) / 2; + s16 y = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_HEIGHT) / -2; if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_OPPONENT) x = -x; @@ -753,8 +753,8 @@ void sub_810F940(u8 taskId) task->data[13] = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_X_2); task->data[14] = GetBattlerSpriteCoord(gBattleAnimAttacker, BATTLER_COORD_Y_PIC_OFFSET); - var0 = sub_80A861C(gBattleAnimAttacker, 1) / 3; - var1 = sub_80A861C(gBattleAnimAttacker, 0) / 3; + var0 = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_WIDTH) / 3; + var1 = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_HEIGHT) / 3; task->data[12] = var0 > var1 ? var0 : var1; SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_ALL | BLDCNT_EFFECT_BLEND); @@ -865,18 +865,18 @@ void sub_810FBF0(u8 taskId) if (gBattleAnimArgs[0] == 1) { task->data[10] = -10; - task->data[11] = sub_80A861C(gBattleAnimTarget, 5) - 8; - task->data[12] = sub_80A861C(gBattleAnimTarget, 2) + 8; - task->data[13] = sub_80A861C(gBattleAnimAttacker, 5) - 8; - task->data[14] = sub_80A861C(gBattleAnimAttacker, 2) + 8; + task->data[11] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_RIGHT) - 8; + task->data[12] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_TOP) + 8; + task->data[13] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_RIGHT) - 8; + task->data[14] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_TOP) + 8; } else { task->data[10] = 10; - task->data[11] = sub_80A861C(gBattleAnimAttacker, 4) + 8; - task->data[12] = sub_80A861C(gBattleAnimAttacker, 3) - 8; - task->data[13] = sub_80A861C(gBattleAnimTarget, 4) + 8; - task->data[14] = sub_80A861C(gBattleAnimTarget, 3) - 8; + task->data[11] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_LEFT) + 8; + task->data[12] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_BOTTOM) - 8; + task->data[13] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_LEFT) + 8; + task->data[14] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_BOTTOM) - 8; } } else @@ -884,18 +884,18 @@ void sub_810FBF0(u8 taskId) if (gBattleAnimArgs[0] == 1) { task->data[10] = -10; - task->data[11] = sub_80A861C(gBattleAnimTarget, 4) + 8; - task->data[12] = sub_80A861C(gBattleAnimTarget, 2) + 8; - task->data[13] = sub_80A861C(gBattleAnimAttacker, 4) + 8; - task->data[14] = sub_80A861C(gBattleAnimAttacker, 2) + 8; + task->data[11] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_LEFT) + 8; + task->data[12] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_TOP) + 8; + task->data[13] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_LEFT) + 8; + task->data[14] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_TOP) + 8; } else { task->data[10] = 10; - task->data[11] = sub_80A861C(gBattleAnimAttacker, 5) - 8; - task->data[12] = sub_80A861C(gBattleAnimAttacker, 3) - 8; - task->data[13] = sub_80A861C(gBattleAnimTarget, 5) - 8; - task->data[14] = sub_80A861C(gBattleAnimTarget, 3) - 8; + task->data[11] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_RIGHT) - 8; + task->data[12] = GetBattlerSpriteCoordAttr(gBattleAnimAttacker, BATTLER_COORD_ATTR_BOTTOM) - 8; + task->data[13] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_RIGHT) - 8; + task->data[14] = GetBattlerSpriteCoordAttr(gBattleAnimTarget, BATTLER_COORD_ATTR_BOTTOM) - 8; } } diff --git a/src/rayquaza_scene.c b/src/rayquaza_scene.c index 94d81e30f..00a73a0a2 100644 --- a/src/rayquaza_scene.c +++ b/src/rayquaza_scene.c @@ -1708,7 +1708,7 @@ static void sub_81D752C(u8 taskId) if (data[0] != 16) { data[0]++; - SetGpuReg(REG_OFFSET_BLDALPHA, (data[0] << 8) | (16 - data[0])); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16 - data[0], data[0])); } } @@ -1954,7 +1954,7 @@ static void Task_RayTakesFlightAnim(u8 taskId) sub_81D7E10(); sub_81D7E9C(); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_OBJ | BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x808); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(8, 8)); BlendPalettes(-1, 0x10, 0); SetVBlankCallback(VBlankCB_RayquazaScene); CreateTask(sub_81D81A4, 0); @@ -2153,7 +2153,7 @@ static void Task_RayDescendsAnim(u8 taskId) sub_81D82B0(); sub_81D8358(); SetGpuRegBits(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_EFFECT_BLEND); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x1000); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16)); BlendPalettes(-1, 0x10, 0); SetVBlankCallback(VBlankCB_RayquazaScene); sRayScene->field_2008 = 0; @@ -2509,7 +2509,7 @@ static void Task_RayChasesAwayAnim(u8 taskId) sub_81D68C8(); ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_BG2_ON); SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND); - SetGpuReg(REG_OFFSET_BLDALPHA, 0xE09); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(9, 14)); BlendPalettes(-1, 0x10, 0); SetVBlankCallback(VBlankCB_RayquazaScene); data[0] = 0; diff --git a/src/record_mixing.c b/src/record_mixing.c index 20e3ef577..189033685 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -741,711 +741,184 @@ static u8 sub_80E7B54(void) return gUnknown_03001160; } -#ifdef NONMATCHING static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) { - // r9 = which - u16 i; - u16 j; + u16 i, j; u8 linkPlayerCount; - u16 language; - u16 otNameLanguage; - u16 nicknameLanguage; - u32 version; - u8 dcMail1; - u8 dcMail2; - u8 r1_80e7b54; - struct DayCareMail *recordMixingMail; + u8 tableId; struct RecordMixingDayCareMail *_src; + u8 which0, which1; + void *ptr; u8 sp04[4]; u8 sp08[4]; - struct RecordMixingDayCareMail *sp0c[4]; // -> sp+48 - u8 sp1c[4][2]; // [][0] -> sp+4c, [][1] -> sp+50 + struct RecordMixingDayCareMail *sp0c[4]; + u8 sp1c[4][2]; u8 sp24[4][2]; - // sp+2c = src - // sp+30 = recordSize u8 sp34; u16 oldSeed; - bool32 anyRS; // sp+3c + bool32 anyRS; oldSeed = Random2(); SeedRng2(gLinkPlayers[0].trainerId); linkPlayerCount = GetLinkPlayerCount(); - for (i = 0; i < 4; i ++) + for (i = 0; i < 4; i++) { sp04[i] = 0xFF; sp08[i] = 0; sp1c[i][0] = 0; sp1c[i][1] = 0; } + anyRS = Link_AnyPartnersPlayingRubyOrSapphire(); - for (i = 0; i < GetLinkPlayerCount(); i ++) // r8 = i + for (i = 0; i < GetLinkPlayerCount(); i++) { - // sp+54 = linkPlayerCount << 16 - // sp+44 = which * recordSize - _src = (void *)src + i * recordSize; // r7 - language = gLinkPlayers[i].language; // r9 - version = (u8)gLinkPlayers[i].version; // sp+40 - for (j = 0; j < _src->unk_70; j ++) + u32 language, version; + + _src = (void *)src + i * recordSize; + language = gLinkPlayers[i].language; + version = gLinkPlayers[i].version & 0xFF; + for (j = 0; j < _src->numDaycareMons; j ++) { - // r10 = ~0x10 - recordMixingMail = &_src->unk_00[j]; - if (recordMixingMail->mail.itemId != ITEM_NONE) + u16 otNameLanguage, nicknameLanguage; + struct DayCareMail *recordMixingMail = &_src->mail[j]; + + if (!recordMixingMail->message.itemId) + continue; + + if (anyRS) { - if (anyRS) + if (StringLength(recordMixingMail->OT_name) <= 5) { - if (StringLength(recordMixingMail->OT_name) <= 5) - { - otNameLanguage = LANGUAGE_JAPANESE; - } - else - { - StripExtCtrlCodes(recordMixingMail->OT_name); - otNameLanguage = language; - } - if (recordMixingMail->monName[0] == EXT_CTRL_CODE_BEGIN && recordMixingMail->monName[1] == EXT_CTRL_CODE_JPN) - { - StripExtCtrlCodes(recordMixingMail->monName); - nicknameLanguage = LANGUAGE_JAPANESE; - } - else - { - nicknameLanguage = language; - } - if (version == VERSION_RUBY || version == VERSION_SAPPHIRE) - { - recordMixingMail->language_maybe = otNameLanguage; - recordMixingMail->unknown = nicknameLanguage; - } + otNameLanguage = LANGUAGE_JAPANESE; } - else if (language == LANGUAGE_JAPANESE) + else { - if (IsStringJapanese(recordMixingMail->OT_name)) - { - recordMixingMail->language_maybe = LANGUAGE_JAPANESE; - } - else - { - recordMixingMail->language_maybe = GAME_LANGUAGE; - } - if (IsStringJapanese(recordMixingMail->monName)) - { - recordMixingMail->unknown = LANGUAGE_JAPANESE; - } - else - { - recordMixingMail->unknown = GAME_LANGUAGE; - } + StripExtCtrlCodes(recordMixingMail->OT_name); + otNameLanguage = language; + } + + if (recordMixingMail->monName[0] == EXT_CTRL_CODE_BEGIN && recordMixingMail->monName[1] == EXT_CTRL_CODE_JPN) + { + StripExtCtrlCodes(recordMixingMail->monName); + nicknameLanguage = LANGUAGE_JAPANESE; + } + else + { + nicknameLanguage = language; + } + + if (version == VERSION_RUBY || version == VERSION_SAPPHIRE) + { + recordMixingMail->gameLanguage = otNameLanguage; + recordMixingMail->monLanguage = nicknameLanguage; } } + else if (language == LANGUAGE_JAPANESE) + { + if (IsStringJapanese(recordMixingMail->OT_name)) + recordMixingMail->gameLanguage = LANGUAGE_JAPANESE; + else + recordMixingMail->gameLanguage = GAME_LANGUAGE; + + if (IsStringJapanese(recordMixingMail->monName)) + recordMixingMail->monLanguage = LANGUAGE_JAPANESE; + else + recordMixingMail->monLanguage = GAME_LANGUAGE; + } } } + sp34 = 0; - for (i = 0; i < linkPlayerCount; i ++) + for (i = 0; i < linkPlayerCount; i++) { - _src = (void *)src + i * recordSize; // r7 - if (_src->unk_70 != 0) + _src = (void *)src + i * recordSize; + if (_src->numDaycareMons == 0) + continue; + + for (j = 0; j < _src->numDaycareMons; j ++) { - for (j = 0; j < _src->unk_70; j ++) - { - if (_src->unk_74[j] == 0) - { - sp1c[i][j] = 1; - } - } + if (!_src->holdsItem[j]) + sp1c[i][j] = 1; } } - i = 0; - for (j = 0; j < linkPlayerCount; j ++) + + j = 0; + for (i = 0; i < linkPlayerCount; i++) { - _src = (void *)src + j * recordSize; - if (sp1c[j][0] == TRUE || sp1c[j][1] == TRUE) - { - sp34 ++; - } - if (sp1c[j][0] == TRUE && sp1c[j][1] == FALSE) + _src = (void *)src + i * recordSize; + if (sp1c[i][0] == TRUE || sp1c[i][1] == TRUE) + sp34++; + + if (sp1c[i][0] == TRUE && sp1c[i][1] == FALSE) { - sp24[i][0] = j; - sp24[i][1] = 0; - i ++; + sp24[j][0] = i; + sp24[j][1] = 0; + j++; } - else if (sp1c[j][0] == FALSE && sp1c[j][1] == TRUE) + else if (sp1c[i][0] == FALSE && sp1c[i][1] == TRUE) { - sp24[i][0] = j; - sp24[i][1] = 0; - i ++; + sp24[j][0] = i; + sp24[j][1] = 1; + j++; } - else if (sp1c[j][0] == TRUE && sp1c[j][1] == TRUE) + else if (sp1c[i][0] == TRUE && sp1c[i][1] == TRUE) { - sp24[i][0] = j; - dcMail1 = sub_80E7A9C(&_src->unk_00[0]); - dcMail2 = sub_80E7A9C(&_src->unk_00[1]); - if (!dcMail1 && dcMail2) + u32 var1, var2; + + sp24[j][0] = i; + var1 = sub_80E7A9C(&_src->mail[0]); + var2 = sub_80E7A9C(&_src->mail[1]); + if (!var1 && var2) { - sp24[i][1] = 1; + register u8 one asm("r0") = 1; // boo, a fakematch + sp24[j][1] = one; } - else if ((dcMail1 && dcMail2) || (!dcMail1 && !dcMail2)) + else if ((var1 && var2) || (!var1 && !var2)) { - sp24[i][1] = Random2() % 2; + sp24[j][1] = Random2() % 2; } - else + else if (var1 && !var2) { - sp24[i][1] = 0; + sp24[j][1] = 0; } - i ++; + j++; } } - for (i = 0; i < 4; i ++) + + for (i = 0; i < 4; i++) { _src = &src[which * recordSize]; sp0c[i] = _src; } - r1_80e7b54 = sub_80E7B54() % 3; + + tableId = sub_80E7B54() % 3; switch (sp34) { - case 2: - sub_80E7AA4(src, recordSize, sp24, 0, 1); - break; - case 3: - sub_80E7AA4(src, recordSize, sp24, gUnknown_0858CFB8[r1_80e7b54][0], gUnknown_0858CFB8[r1_80e7b54][1]); - break; - case 4: - sub_80E7AA4(src, recordSize, sp24, gUnknown_0858CFBE[r1_80e7b54][0], gUnknown_0858CFBE[r1_80e7b54][1]); - sub_80E7AA4(src, recordSize, sp24, gUnknown_0858CFBE[r1_80e7b54][2], gUnknown_0858CFBE[r1_80e7b54][3]); - break; + case 2: + sub_80E7AA4(src, recordSize, sp24, 0, 1); + break; + case 3: + which0 = gUnknown_0858CFB8[tableId][0]; + which1 = gUnknown_0858CFB8[tableId][1]; + sub_80E7AA4(src, recordSize, sp24, which0, which1); + break; + case 4: + ptr = sp24; + which0 = gUnknown_0858CFBE[tableId][0]; + which1 = gUnknown_0858CFBE[tableId][1]; + sub_80E7AA4(src, recordSize, ptr, which0, which1); + which0 = gUnknown_0858CFBE[tableId][2]; + which1 = gUnknown_0858CFBE[tableId][3]; + sub_80E7AA4(src, recordSize, ptr, which0, which1); + break; } + _src = (void *)src + which * recordSize; - memcpy(&gSaveBlock1Ptr->daycare.mons[0].misc.mail, &_src->unk_00[0], sizeof(struct DayCareMail)); - memcpy(&gSaveBlock1Ptr->daycare.mons[1].misc.mail, &_src->unk_00[1], sizeof(struct DayCareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DayCareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DayCareMail)); SeedRng(oldSeed); } -#else -NAKED -static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) -{ - asm_unified("\tpush {r4-r7,lr}\n" - "\tmov r7, r10\n" - "\tmov r6, r9\n" - "\tmov r5, r8\n" - "\tpush {r5-r7}\n" - "\tsub sp, 0x58\n" - "\tstr r0, [sp, 0x2C]\n" - "\tstr r1, [sp, 0x30]\n" - "\tlsls r2, 24\n" - "\tlsrs r2, 24\n" - "\tmov r9, r2\n" - "\tbl Random2\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tstr r0, [sp, 0x38]\n" - "\tldr r0, =gLinkPlayers\n" - "\tldrh r0, [r0, 0x4]\n" - "\tbl SeedRng2\n" - "\tbl GetLinkPlayerCount\n" - "\tlsls r0, 24\n" - "\tlsrs r4, r0, 24\n" - "\tmovs r0, 0\n" - "\tmov r8, r0\n" - "\tmov r1, sp\n" - "\tadds r1, 0x1C\n" - "\tstr r1, [sp, 0x4C]\n" - "\tmov r2, sp\n" - "\tadds r2, 0x1D\n" - "\tstr r2, [sp, 0x50]\n" - "\tmov r3, sp\n" - "\tadds r3, 0xC\n" - "\tstr r3, [sp, 0x48]\n" - "\tmovs r7, 0xFF\n" - "\tadd r3, sp, 0x8\n" - "\tmovs r2, 0\n" - "\tadds r6, r1, 0\n" - "\tldr r5, [sp, 0x50]\n" - "_080E7BB0:\n" - "\tmov r1, sp\n" - "\tadd r1, r8\n" - "\tadds r1, 0x4\n" - "\tldrb r0, [r1]\n" - "\torrs r0, r7\n" - "\tstrb r0, [r1]\n" - "\tmov r1, r8\n" - "\tadds r0, r3, r1\n" - "\tstrb r2, [r0]\n" - "\tlsls r1, 1\n" - "\tadds r0, r6, r1\n" - "\tstrb r2, [r0]\n" - "\tadds r1, r5, r1\n" - "\tstrb r2, [r1]\n" - "\tmov r0, r8\n" - "\tadds r0, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tmov r8, r0\n" - "\tcmp r0, 0x3\n" - "\tbls _080E7BB0\n" - "\tbl Link_AnyPartnersPlayingRubyOrSapphire\n" - "\tstr r0, [sp, 0x3C]\n" - "\tmovs r2, 0\n" - "\tmov r8, r2\n" - "\tlsls r4, 16\n" - "\tstr r4, [sp, 0x54]\n" - "\tldr r0, [sp, 0x30]\n" - "\tmov r3, r9\n" - "\tmuls r3, r0\n" - "\tstr r3, [sp, 0x44]\n" - "\tb _080E7D04\n" - "\t.pool\n" - "_080E7BF8:\n" - "\tldr r1, [sp, 0x30]\n" - "\tmov r0, r8\n" - "\tmuls r0, r1\n" - "\tldr r2, [sp, 0x2C]\n" - "\tadds r7, r2, r0\n" - "\tldr r1, =gLinkPlayers\n" - "\tmov r3, r8\n" - "\tlsls r0, r3, 3\n" - "\tsubs r0, r3\n" - "\tlsls r0, 2\n" - "\tadds r0, r1\n" - "\tldrh r1, [r0, 0x1A]\n" - "\tmov r9, r1\n" - "\tldrb r0, [r0]\n" - "\tstr r0, [sp, 0x40]\n" - "\tmovs r6, 0\n" - "\tldr r0, [r7, 0x70]\n" - "\tcmp r6, r0\n" - "\tbcs _080E7CFA\n" - "\tmovs r2, 0x10\n" - "\tnegs r2, r2\n" - "\tmov r10, r2\n" - "_080E7C24:\n" - "\tlsls r0, r6, 3\n" - "\tsubs r0, r6\n" - "\tlsls r0, 3\n" - "\tadds r5, r7, r0\n" - "\tldrh r0, [r5, 0x20]\n" - "\tcmp r0, 0\n" - "\tbeq _080E7CEE\n" - "\tldr r3, [sp, 0x3C]\n" - "\tcmp r3, 0\n" - "\tbeq _080E7C9A\n" - "\tadds r4, r5, 0\n" - "\tadds r4, 0x24\n" - "\tadds r0, r4, 0\n" - "\tbl StringLength\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tcmp r0, 0x5\n" - "\tbhi _080E7C54\n" - "\tmovs r4, 0x1\n" - "\tb _080E7C5C\n" - "\t.pool\n" - "_080E7C54:\n" - "\tadds r0, r4, 0\n" - "\tbl StripExtCtrlCodes\n" - "\tmov r4, r9\n" - "_080E7C5C:\n" - "\tldrh r1, [r5, 0x2C]\n" - "\tldr r0, =0x000015fc\n" - "\tcmp r1, r0\n" - "\tbne _080E7C74\n" - "\tadds r0, r5, 0\n" - "\tadds r0, 0x2C\n" - "\tbl StripExtCtrlCodes\n" - "\tmovs r1, 0x1\n" - "\tb _080E7C76\n" - "\t.pool\n" - "_080E7C74:\n" - "\tmov r1, r9\n" - "_080E7C76:\n" - "\tldr r0, [sp, 0x40]\n" - "\tsubs r0, 0x1\n" - "\tcmp r0, 0x1\n" - "\tbhi _080E7CEE\n" - "\tadds r2, r5, 0\n" - "\tadds r2, 0x37\n" - "\tmovs r0, 0xF\n" - "\tands r4, r0\n" - "\tldrb r0, [r2]\n" - "\tmov r3, r10\n" - "\tands r0, r3\n" - "\torrs r0, r4\n" - "\tlsls r1, 4\n" - "\tmovs r3, 0xF\n" - "\tands r0, r3\n" - "\torrs r0, r1\n" - "\tstrb r0, [r2]\n" - "\tb _080E7CEE\n" - "_080E7C9A:\n" - "\tmov r0, r9\n" - "\tcmp r0, 0x1\n" - "\tbne _080E7CEE\n" - "\tadds r0, r5, 0\n" - "\tadds r0, 0x24\n" - "\tbl IsStringJapanese\n" - "\tcmp r0, 0\n" - "\tbeq _080E7CBA\n" - "\tadds r0, r5, 0\n" - "\tadds r0, 0x37\n" - "\tldrb r1, [r0]\n" - "\tmov r2, r10\n" - "\tands r1, r2\n" - "\tmovs r2, 0x1\n" - "\tb _080E7CC6\n" - "_080E7CBA:\n" - "\tadds r0, r5, 0\n" - "\tadds r0, 0x37\n" - "\tldrb r1, [r0]\n" - "\tmov r3, r10\n" - "\tands r1, r3\n" - "\tmovs r2, 0x2\n" - "_080E7CC6:\n" - "\torrs r1, r2\n" - "\tstrb r1, [r0]\n" - "\tadds r4, r0, 0\n" - "\tadds r0, r5, 0\n" - "\tadds r0, 0x2C\n" - "\tbl IsStringJapanese\n" - "\tcmp r0, 0\n" - "\tbeq _080E7CE2\n" - "\tldrb r0, [r4]\n" - "\tmovs r1, 0xF\n" - "\tands r1, r0\n" - "\tmovs r0, 0x10\n" - "\tb _080E7CEA\n" - "_080E7CE2:\n" - "\tldrb r0, [r4]\n" - "\tmovs r1, 0xF\n" - "\tands r1, r0\n" - "\tmovs r0, 0x20\n" - "_080E7CEA:\n" - "\torrs r1, r0\n" - "\tstrb r1, [r4]\n" - "_080E7CEE:\n" - "\tadds r0, r6, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r6, r0, 16\n" - "\tldr r0, [r7, 0x70]\n" - "\tcmp r6, r0\n" - "\tbcc _080E7C24\n" - "_080E7CFA:\n" - "\tmov r0, r8\n" - "\tadds r0, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tmov r8, r0\n" - "_080E7D04:\n" - "\tbl GetLinkPlayerCount\n" - "\tlsls r0, 24\n" - "\tlsrs r0, 24\n" - "\tcmp r8, r0\n" - "\tbcs _080E7D12\n" - "\tb _080E7BF8\n" - "_080E7D12:\n" - "\tmovs r0, 0\n" - "\tstr r0, [sp, 0x34]\n" - "\tmov r8, r0\n" - "\tldr r1, [sp, 0x54]\n" - "\tlsrs r0, r1, 16\n" - "\tldr r2, [sp, 0x34]\n" - "\tcmp r2, r0\n" - "\tbcs _080E7D70\n" - "\tadds r5, r0, 0\n" - "_080E7D24:\n" - "\tldr r3, [sp, 0x30]\n" - "\tmov r0, r8\n" - "\tmuls r0, r3\n" - "\tldr r1, [sp, 0x2C]\n" - "\tadds r7, r1, r0\n" - "\tldr r0, [r7, 0x70]\n" - "\tcmp r0, 0\n" - "\tbeq _080E7D62\n" - "\tmovs r6, 0\n" - "\tcmp r6, r0\n" - "\tbcs _080E7D62\n" - "\tadds r3, r7, 0\n" - "\tadds r3, 0x74\n" - "\tldr r2, [sp, 0x4C]\n" - "\tmov r0, r8\n" - "\tlsls r1, r0, 1\n" - "\tmovs r4, 0x1\n" - "_080E7D46:\n" - "\tlsls r0, r6, 1\n" - "\tadds r0, r3, r0\n" - "\tldrh r0, [r0]\n" - "\tcmp r0, 0\n" - "\tbne _080E7D56\n" - "\tadds r0, r6, r1\n" - "\tadds r0, r2, r0\n" - "\tstrb r4, [r0]\n" - "_080E7D56:\n" - "\tadds r0, r6, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r6, r0, 16\n" - "\tldr r0, [r7, 0x70]\n" - "\tcmp r6, r0\n" - "\tbcc _080E7D46\n" - "_080E7D62:\n" - "\tmov r0, r8\n" - "\tadds r0, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tmov r8, r0\n" - "\tcmp r8, r5\n" - "\tbcc _080E7D24\n" - "_080E7D70:\n" - "\tmovs r6, 0\n" - "\tmov r8, r6\n" - "\tldr r1, [sp, 0x54]\n" - "\tcmp r1, 0\n" - "\tbeq _080E7E64\n" - "\tadd r2, sp, 0x24\n" - "\tmov r10, r2\n" - "\tmovs r3, 0x25\n" - "\tadd r3, sp\n" - "\tmov r9, r3\n" - "_080E7D84:\n" - "\tldr r1, [sp, 0x30]\n" - "\tmov r0, r8\n" - "\tmuls r0, r1\n" - "\tldr r2, [sp, 0x2C]\n" - "\tadds r7, r2, r0\n" - "\tmov r3, r8\n" - "\tlsls r1, r3, 1\n" - "\tldr r2, [sp, 0x4C]\n" - "\tadds r0, r2, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0x1\n" - "\tbeq _080E7DA6\n" - "\tldr r3, [sp, 0x50]\n" - "\tadds r0, r3, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0x1\n" - "\tbne _080E7DB0\n" - "_080E7DA6:\n" - "\tldr r0, [sp, 0x34]\n" - "\tadds r0, 0x1\n" - "\tlsls r0, 24\n" - "\tlsrs r0, 24\n" - "\tstr r0, [sp, 0x34]\n" - "_080E7DB0:\n" - "\tldr r2, [sp, 0x4C]\n" - "\tadds r0, r2, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0x1\n" - "\tbne _080E7DD4\n" - "\tldr r3, [sp, 0x50]\n" - "\tadds r0, r3, r1\n" - "\tldrb r2, [r0]\n" - "\tcmp r2, 0\n" - "\tbne _080E7DD4\n" - "_080E7DC4:\n" - "\tlsls r1, r6, 1\n" - "\tmov r3, r10\n" - "\tadds r0, r3, r1\n" - "\tmov r3, r8\n" - "\tstrb r3, [r0]\n" - "\tadd r1, r9\n" - "\tstrb r2, [r1]\n" - "\tb _080E7E4E\n" - "_080E7DD4:\n" - "\tldr r2, [sp, 0x4C]\n" - "\tadds r0, r2, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0\n" - "\tbne _080E7DE8\n" - "\tldr r3, [sp, 0x50]\n" - "\tadds r0, r3, r1\n" - "\tldrb r2, [r0]\n" - "\tcmp r2, 0x1\n" - "\tbeq _080E7DC4\n" - "_080E7DE8:\n" - "\tldr r2, [sp, 0x4C]\n" - "\tadds r0, r2, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0x1\n" - "\tbne _080E7E54\n" - "\tldr r3, [sp, 0x50]\n" - "\tadds r0, r3, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0x1\n" - "\tbne _080E7E54\n" - "\tlsls r5, r6, 1\n" - "\tmov r1, r10\n" - "\tadds r0, r1, r5\n" - "\tmov r2, r8\n" - "\tstrb r2, [r0]\n" - "\tadds r0, r7, 0\n" - "\tbl sub_80E7A9C\n" - "\tadds r4, r0, 0\n" - "\tlsls r4, 24\n" - "\tlsrs r4, 24\n" - "\tadds r0, r7, 0\n" - "\tadds r0, 0x38\n" - "\tbl sub_80E7A9C\n" - "\tlsls r0, 24\n" - "\tlsrs r1, r0, 24\n" - "\tcmp r4, 0\n" - "\tbne _080E7E30\n" - "\tcmp r1, 0\n" - "\tbeq _080E7E34\n" - "\tmov r3, r9\n" - "\tadds r1, r3, r5\n" - "\tmovs r0, 0x1\n" - "\tstrb r0, [r1]\n" - "\tb _080E7E4E\n" - "_080E7E30:\n" - "\tcmp r1, 0\n" - "\tbeq _080E7E48\n" - "_080E7E34:\n" - "\tbl Random2\n" - "\tmov r1, r9\n" - "\tadds r2, r1, r5\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tmovs r1, 0x1\n" - "\tands r0, r1\n" - "\tstrb r0, [r2]\n" - "\tb _080E7E4E\n" - "_080E7E48:\n" - "\tmov r2, r9\n" - "\tadds r0, r2, r5\n" - "\tstrb r1, [r0]\n" - "_080E7E4E:\n" - "\tadds r0, r6, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r6, r0, 16\n" - "_080E7E54:\n" - "\tmov r0, r8\n" - "\tadds r0, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r3, r0, 16\n" - "\tmov r8, r3\n" - "\tldr r1, [sp, 0x54]\n" - "\tcmp r0, r1\n" - "\tbcc _080E7D84\n" - "_080E7E64:\n" - "\tmovs r2, 0\n" - "\tmov r8, r2\n" - "\tldr r3, [sp, 0x44]\n" - "\tlsls r0, r3, 4\n" - "\tsubs r0, r3\n" - "\tlsls r0, 3\n" - "\tldr r1, [sp, 0x2C]\n" - "\tadds r7, r1, r0\n" - "\tldr r1, [sp, 0x48]\n" - "_080E7E76:\n" - "\tmov r2, r8\n" - "\tlsls r0, r2, 2\n" - "\tadds r0, r1, r0\n" - "\tstr r7, [r0]\n" - "\tmov r0, r8\n" - "\tadds r0, 0x1\n" - "\tlsls r0, 16\n" - "\tlsrs r0, 16\n" - "\tmov r8, r0\n" - "\tcmp r0, 0x3\n" - "\tbls _080E7E76\n" - "\tbl sub_80E7B54\n" - "\tlsls r0, 24\n" - "\tlsrs r0, 24\n" - "\tmovs r1, 0x3\n" - "\tbl __umodsi3\n" - "\tlsls r0, 24\n" - "\tlsrs r1, r0, 24\n" - "\tldr r3, [sp, 0x34]\n" - "\tcmp r3, 0x3\n" - "\tbeq _080E7EC8\n" - "\tcmp r3, 0x3\n" - "\tbgt _080E7EAE\n" - "\tcmp r3, 0x2\n" - "\tbeq _080E7EB6\n" - "\tb _080E7F1C\n" - "_080E7EAE:\n" - "\tldr r0, [sp, 0x34]\n" - "\tcmp r0, 0x4\n" - "\tbeq _080E7EE8\n" - "\tb _080E7F1C\n" - "_080E7EB6:\n" - "\tadd r2, sp, 0x24\n" - "\tmovs r0, 0x1\n" - "\tstr r0, [sp]\n" - "\tldr r0, [sp, 0x2C]\n" - "\tldr r1, [sp, 0x30]\n" - "\tmovs r3, 0\n" - "\tbl sub_80E7AA4\n" - "\tb _080E7F1C\n" - "_080E7EC8:\n" - "\tldr r0, =gUnknown_0858CFB8\n" - "\tlsls r1, 1\n" - "\tadds r2, r1, r0\n" - "\tldrb r3, [r2]\n" - "\tadds r0, 0x1\n" - "\tadds r1, r0\n" - "\tldrb r0, [r1]\n" - "\tadd r2, sp, 0x24\n" - "\tstr r0, [sp]\n" - "\tldr r0, [sp, 0x2C]\n" - "\tldr r1, [sp, 0x30]\n" - "\tbl sub_80E7AA4\n" - "\tb _080E7F1C\n" - "\t.pool\n" - "_080E7EE8:\n" - "\tadd r6, sp, 0x24\n" - "\tldr r4, =gUnknown_0858CFBE\n" - "\tlsls r5, r1, 2\n" - "\tadds r0, r5, r4\n" - "\tldrb r3, [r0]\n" - "\tadds r0, r4, 0x1\n" - "\tadds r0, r5, r0\n" - "\tldrb r0, [r0]\n" - "\tstr r0, [sp]\n" - "\tldr r0, [sp, 0x2C]\n" - "\tldr r1, [sp, 0x30]\n" - "\tadds r2, r6, 0\n" - "\tbl sub_80E7AA4\n" - "\tadds r0, r4, 0x2\n" - "\tadds r0, r5, r0\n" - "\tldrb r3, [r0]\n" - "\tadds r4, 0x3\n" - "\tadds r5, r4\n" - "\tldrb r0, [r5]\n" - "\tstr r0, [sp]\n" - "\tldr r0, [sp, 0x2C]\n" - "\tldr r1, [sp, 0x30]\n" - "\tadds r2, r6, 0\n" - "\tbl sub_80E7AA4\n" - "_080E7F1C:\n" - "\tldr r1, [sp, 0x2C]\n" - "\tldr r2, [sp, 0x44]\n" - "\tadds r7, r1, r2\n" - "\tldr r4, =gSaveBlock1Ptr\n" - "\tldr r0, [r4]\n" - "\tmovs r3, 0xC2\n" - "\tlsls r3, 6\n" - "\tadds r0, r3\n" - "\tadds r1, r7, 0\n" - "\tmovs r2, 0x38\n" - "\tbl memcpy\n" - "\tldr r0, [r4]\n" - "\tldr r1, =0x0000310c\n" - "\tadds r0, r1\n" - "\tadds r1, r7, 0\n" - "\tadds r1, 0x38\n" - "\tmovs r2, 0x38\n" - "\tbl memcpy\n" - "\tldr r0, [sp, 0x38]\n" - "\tbl SeedRng\n" - "\tadd sp, 0x58\n" - "\tpop {r3-r5}\n" - "\tmov r8, r3\n" - "\tmov r9, r4\n" - "\tmov r10, r5\n" - "\tpop {r4-r7}\n" - "\tpop {r0}\n" - "\tbx r0\n" - "\t.pool"); -} -#endif // NONMATCHING + static void ReceiveGiftItem(u16 *item, u8 which) { @@ -1481,14 +954,14 @@ static void sub_80E7FF8(u8 taskId) task->data[0] = 6; break; case 2: - sub_8076D5C(); + SetContinueGameWarpStatusToDynamicWarp(); sub_8153430(); task->data[0] ++; break; case 3: if (sub_8153474()) { - sav2_gender2_inplace_and_xFE(); + ClearContinueGameWarpStatus2(); task->data[0] = 4; task->data[1] = 0; } diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 81935b7c6..03823dd45 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -718,7 +718,7 @@ void RecordedBattle_CopyBattlerMoves(void) if (sUnknown_0203C7AC == 2) return; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_MON_MOVES; i++) { sPlayerMonMoves[gActiveBattler / 2][i] = gBattleMons[gActiveBattler].moves[i]; } @@ -739,17 +739,17 @@ void sub_818603C(u8 arg0) { if (arg0 == 1) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { if (gBattleMons[battlerId].moves[j] != sPlayerMonMoves[battlerId / 2][j]) break; } - if (j != 4) // player's mon's move has been changed + if (j != MAX_MON_MOVES) // player's mon's move has been changed { RecordedBattle_SetBattlerAction(battlerId, ACTION_MOVE_CHANGE); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { - for (k = 0; k < 4; k++) + for (k = 0; k < MAX_MON_MOVES; k++) { if (gBattleMons[battlerId].moves[j] == sPlayerMonMoves[battlerId / 2][k]) { @@ -772,11 +772,11 @@ void sub_818603C(u8 arg0) u8 var; RecordedBattle_GetBattlerAction(battlerId); - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { ppBonuses[j] = ((gBattleMons[battlerId].ppBonuses & ((3 << (j << 1)))) >> (j << 1)); } - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { array1[j] = RecordedBattle_GetBattlerAction(battlerId); movePp.moves[j] = gBattleMons[battlerId].moves[array1[j]]; @@ -784,14 +784,14 @@ void sub_818603C(u8 arg0) array3[j] = ppBonuses[array1[j]]; array2[j] = (gDisableStructs[battlerId].unk18_b & gBitTable[j]) >> j; } - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { gBattleMons[battlerId].moves[j] = movePp.moves[j]; gBattleMons[battlerId].pp[j] = movePp.pp[j]; } gBattleMons[battlerId].ppBonuses = 0; gDisableStructs[battlerId].unk18_b = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { gBattleMons[battlerId].ppBonuses |= (array3[j]) << (j << 1); gDisableStructs[battlerId].unk18_b |= (array2[j]) << (j); @@ -799,23 +799,23 @@ void sub_818603C(u8 arg0) if (!(gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED)) { - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { ppBonuses[j] = ((GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_PP_BONUSES, NULL) & ((3 << (j << 1)))) >> (j << 1)); } - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { movePp.moves[j] = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_MOVE1 + array1[j], NULL); movePp.pp[j] = GetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_PP1 + array1[j], NULL); array3[j] = ppBonuses[array1[j]]; } - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { SetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_MOVE1 + j, &movePp.moves[j]); SetMonData(&gPlayerParty[gBattlerPartyIndexes[battlerId]], MON_DATA_PP1 + j, &movePp.pp[j]); } var = 0; - for (j = 0; j < 4; j++) + for (j = 0; j < MAX_MON_MOVES; j++) { var |= (array3[j]) << (j << 1); } diff --git a/src/region_map.c b/src/region_map.c index 4caf3147a..ff0c19167 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -25,6 +25,7 @@ #include "constants/region_map_sections.h" #include "heal_location.h" #include "constants/heal_locations.h" +#include "constants/map_types.h" #define MAP_WIDTH 28 #define MAP_HEIGHT 15 @@ -427,82 +428,82 @@ bool8 sub_8122DB0(void) { switch (gRegionMap->initStep) { - case 0: - if (gRegionMap->bgManaged) - { - decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_GfxLZ, 0, 0, 0); - } - else - { - LZ77UnCompVram(sRegionMapBkgnd_GfxLZ, (u16 *)BG_CHAR_ADDR(2)); - } - break; - case 1: - if (gRegionMap->bgManaged) - { - if (!free_temp_tile_data_buffers_if_possible()) - { - decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_TilemapLZ, 0, 0, 1); - } - } - else - { - LZ77UnCompVram(sRegionMapBkgnd_TilemapLZ, (u16 *)BG_SCREEN_ADDR(28)); - } - break; - case 2: + case 0: + if (gRegionMap->bgManaged) + { + decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_GfxLZ, 0, 0, 0); + } + else + { + LZ77UnCompVram(sRegionMapBkgnd_GfxLZ, (u16 *)BG_CHAR_ADDR(2)); + } + break; + case 1: + if (gRegionMap->bgManaged) + { if (!free_temp_tile_data_buffers_if_possible()) { - LoadPalette(sRegionMapBkgnd_Pal, 0x70, 0x60); - } - break; - case 3: - LZ77UnCompWram(sRegionMapCursorSmallGfxLZ, gRegionMap->cursorSmallImage); - break; - case 4: - LZ77UnCompWram(sRegionMapCursorLargeGfxLZ, gRegionMap->cursorLargeImage); - break; - case 5: - RegionMap_InitializeStateBasedOnPlayerLocation(); - gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX; - gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY; - gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId); - gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId); - GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16); - break; - case 6: - if (gRegionMap->zoomed == FALSE) - { - CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0); - } - else - { - gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34; - gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44; - gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX; - gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY; - CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0); + decompress_and_copy_tile_data_to_vram(gRegionMap->bgNum, sRegionMapBkgnd_TilemapLZ, 0, 0, 1); } - break; - case 7: - RegionMap_GetPositionOfCursorWithinMapSection(); - UpdateRegionMapVideoRegs(); - gRegionMap->cursorSprite = NULL; - gRegionMap->playerIconSprite = NULL; - gRegionMap->cursorMovementFrameCounter = 0; - gRegionMap->blinkPlayerIcon = FALSE; - if (gRegionMap->bgManaged) - { - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_MAPBASEINDEX, 2); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_VISIBLE, gRegionMap->charBaseIdx); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_CHARBASEINDEX, gRegionMap->mapBaseIdx); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_PRIORITY, 1); - SetBgAttribute(gRegionMap->bgNum, BG_CTRL_ATTR_SCREENSIZE, 1); - } - gRegionMap->initStep++; - return FALSE; - default: - return FALSE; + } + else + { + LZ77UnCompVram(sRegionMapBkgnd_TilemapLZ, (u16 *)BG_SCREEN_ADDR(28)); + } + break; + case 2: + if (!free_temp_tile_data_buffers_if_possible()) + { + LoadPalette(sRegionMapBkgnd_Pal, 0x70, 0x60); + } + break; + case 3: + LZ77UnCompWram(sRegionMapCursorSmallGfxLZ, gRegionMap->cursorSmallImage); + break; + case 4: + LZ77UnCompWram(sRegionMapCursorLargeGfxLZ, gRegionMap->cursorLargeImage); + break; + case 5: + RegionMap_InitializeStateBasedOnPlayerLocation(); + gRegionMap->playerIconSpritePosX = gRegionMap->cursorPosX; + gRegionMap->playerIconSpritePosY = gRegionMap->cursorPosY; + gRegionMap->mapSecId = CorrectSpecialMapSecId_Internal(gRegionMap->mapSecId); + gRegionMap->iconDrawType = get_flagnr_blue_points(gRegionMap->mapSecId); + GetMapName(gRegionMap->mapSecName, gRegionMap->mapSecId, 16); + break; + case 6: + if (gRegionMap->zoomed == FALSE) + { + CalcZoomScrollParams(0, 0, 0, 0, 0x100, 0x100, 0); + } + else + { + gRegionMap->scrollX = gRegionMap->cursorPosX * 8 - 0x34; + gRegionMap->scrollY = gRegionMap->cursorPosY * 8 - 0x44; + gRegionMap->zoomedCursorPosX = gRegionMap->cursorPosX; + gRegionMap->zoomedCursorPosY = gRegionMap->cursorPosY; + CalcZoomScrollParams(gRegionMap->scrollX, gRegionMap->scrollY, 0x38, 0x48, 0x80, 0x80, 0); + } + break; + case 7: + RegionMap_GetPositionOfCursorWithinMapSection(); + UpdateRegionMapVideoRegs(); + gRegionMap->cursorSprite = NULL; + gRegionMap->playerIconSprite = NULL; + gRegionMap->cursorMovementFrameCounter = 0; + gRegionMap->blinkPlayerIcon = FALSE; + if (gRegionMap->bgManaged) + { + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_SCREENSIZE, 2); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_CHARBASEINDEX, gRegionMap->charBaseIdx); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_MAPBASEINDEX, gRegionMap->mapBaseIdx); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_WRAPAROUND, 1); + SetBgAttribute(gRegionMap->bgNum, BG_ATTR_PALETTEMODE, 1); + } + gRegionMap->initStep++; + return FALSE; + default: + return FALSE; } gRegionMap->initStep++; return TRUE; @@ -864,7 +865,7 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) u16 y; u16 dimensionScale; u16 xOnMap; - struct WarpData *storedWarp; + struct WarpData *warp; if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SS_TIDAL_CORRIDOR) && (gSaveBlock1Ptr->location.mapNum == MAP_NUM(SS_TIDAL_CORRIDOR) @@ -878,11 +879,11 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) switch (GetMapTypeByGroupAndId(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum)) { default: - case 1: - case 2: - case 3: - case 5: - case 6: + case MAP_TYPE_TOWN: + case MAP_TYPE_CITY: + case MAP_TYPE_ROUTE: + case MAP_TYPE_UNDERWATER: + case MAP_TYPE_6: gRegionMap->mapSecId = gMapHeader.regionMapSectionId; gRegionMap->playerIsInCave = FALSE; mapWidth = gMapHeader.mapLayout->width; @@ -894,17 +895,17 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) gRegionMap->playerIsInCave = TRUE; } break; - case 4: - case 7: + case MAP_TYPE_UNDERGROUND: + case MAP_TYPE_7: if (gMapHeader.flags & 0x02) { - mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->warp4.mapGroup, gSaveBlock1Ptr->warp4.mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->escapeWarp.mapGroup, gSaveBlock1Ptr->escapeWarp.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; gRegionMap->playerIsInCave = TRUE; mapWidth = mapHeader->mapLayout->width; mapHeight = mapHeader->mapLayout->height; - x = gSaveBlock1Ptr->warp4.x; - y = gSaveBlock1Ptr->warp4.y; + x = gSaveBlock1Ptr->escapeWarp.x; + y = gSaveBlock1Ptr->escapeWarp.y; } else { @@ -916,27 +917,26 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) y = 1; } break; - case 9: - mapHeader = Overworld_GetMapHeaderByGroupAndId((u16)gSaveBlock1Ptr->warp2.mapGroup, (u16)gSaveBlock1Ptr->warp2.mapNum); + case MAP_TYPE_SECRET_BASE: + mapHeader = Overworld_GetMapHeaderByGroupAndId((u16)gSaveBlock1Ptr->dynamicWarp.mapGroup, (u16)gSaveBlock1Ptr->dynamicWarp.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; gRegionMap->playerIsInCave = TRUE; mapWidth = mapHeader->mapLayout->width; mapHeight = mapHeader->mapLayout->height; - x = gSaveBlock1Ptr->warp2.x; - y = gSaveBlock1Ptr->warp2.y; + x = gSaveBlock1Ptr->dynamicWarp.x; + y = gSaveBlock1Ptr->dynamicWarp.y; break; - case 8: - + case MAP_TYPE_INDOOR: gRegionMap->mapSecId = gMapHeader.regionMapSectionId; if (gRegionMap->mapSecId != MAPSEC_DYNAMIC) { - storedWarp = &gSaveBlock1Ptr->warp4; - mapHeader = Overworld_GetMapHeaderByGroupAndId(storedWarp->mapGroup, storedWarp->mapNum); + warp = &gSaveBlock1Ptr->escapeWarp; + mapHeader = Overworld_GetMapHeaderByGroupAndId(warp->mapGroup, warp->mapNum); } else { - storedWarp = &gSaveBlock1Ptr->warp2; - mapHeader = Overworld_GetMapHeaderByGroupAndId(storedWarp->mapGroup, storedWarp->mapNum); + warp = &gSaveBlock1Ptr->dynamicWarp; + mapHeader = Overworld_GetMapHeaderByGroupAndId(warp->mapGroup, warp->mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; } if (RegionMap_IsPlayerInCave(gRegionMap->mapSecId)) @@ -949,8 +949,8 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) } mapWidth = mapHeader->mapLayout->width; mapHeight = mapHeader->mapLayout->height; - x = storedWarp->x; - y = storedWarp->y; + x = warp->x; + y = warp->y; break; } @@ -1902,25 +1902,25 @@ static void sub_8124E0C(void) switch (sFlyMap->regionMap.mapSecId) { case MAPSEC_SOUTHERN_ISLAND: - sub_8084CCC(HEAL_LOCATION_SOUTHERN_ISLAND_EXTERIOR); + SetWarpDestinationToHealLocation(HEAL_LOCATION_SOUTHERN_ISLAND_EXTERIOR); break; case MAPSEC_BATTLE_FRONTIER: - sub_8084CCC(HEAL_LOCATION_BATTLE_FRONTIER_OUTSIDE_EAST); + SetWarpDestinationToHealLocation(HEAL_LOCATION_BATTLE_FRONTIER_OUTSIDE_EAST); break; case MAPSEC_LITTLEROOT_TOWN: - sub_8084CCC(gSaveBlock2Ptr->playerGender == MALE ? HEAL_LOCATION_LITTLEROOT_TOWN_1 : HEAL_LOCATION_LITTLEROOT_TOWN_2); + SetWarpDestinationToHealLocation(gSaveBlock2Ptr->playerGender == MALE ? HEAL_LOCATION_LITTLEROOT_TOWN_1 : HEAL_LOCATION_LITTLEROOT_TOWN_2); break; case MAPSEC_EVER_GRANDE_CITY: - sub_8084CCC(FlagGet(FLAG_LANDMARK_POKEMON_LEAGUE) && sFlyMap->regionMap.posWithinMapSec == 0 ? HEAL_LOCATION_EVER_GRANDE_CITY_2 : HEAL_LOCATION_EVER_GRANDE_CITY_1); + SetWarpDestinationToHealLocation(FlagGet(FLAG_LANDMARK_POKEMON_LEAGUE) && sFlyMap->regionMap.posWithinMapSec == 0 ? HEAL_LOCATION_EVER_GRANDE_CITY_2 : HEAL_LOCATION_EVER_GRANDE_CITY_1); break; default: if (sMapHealLocations[sFlyMap->regionMap.mapSecId][2] != 0) { - sub_8084CCC(sMapHealLocations[sFlyMap->regionMap.mapSecId][2]); + SetWarpDestinationToHealLocation(sMapHealLocations[sFlyMap->regionMap.mapSecId][2]); } else { - warp1_set_2(sMapHealLocations[sFlyMap->regionMap.mapSecId][0], sMapHealLocations[sFlyMap->regionMap.mapSecId][1], -1); + SetWarpDestinationToMapWarp(sMapHealLocations[sFlyMap->regionMap.mapSecId][0], sMapHealLocations[sFlyMap->regionMap.mapSecId][1], -1); } break; } diff --git a/src/reshow_battle_screen.c b/src/reshow_battle_screen.c index 06d2af5b7..1b17c372c 100644 --- a/src/reshow_battle_screen.c +++ b/src/reshow_battle_screen.c @@ -50,8 +50,8 @@ static void CB2_ReshowBattleScreenAfterMenu(void) case 0: ScanlineEffect_Clear(); BattleInitBgsAndWindows(); - SetBgAttribute(1, BG_CTRL_ATTR_VISIBLE, 0); - SetBgAttribute(2, BG_CTRL_ATTR_VISIBLE, 0); + SetBgAttribute(1, BG_ATTR_CHARBASEINDEX, 0); + SetBgAttribute(2, BG_ATTR_CHARBASEINDEX, 0); ShowBg(0); ShowBg(1); ShowBg(2); diff --git a/src/rom_8011DC0.c b/src/rom_8011DC0.c index 7363265ab..813d143d2 100644 --- a/src/rom_8011DC0.c +++ b/src/rom_8011DC0.c @@ -1315,7 +1315,7 @@ u32 sub_8013B8C(struct UnkStruct_Group *arg0, s32 id) if (gUnknown_02022C2C == 4 && structPtr->unk.field_0.unk_00.unk_01_2 != 3) { - if (!(gSaveBlock2Ptr->specialSaveWarp & 0x80)) + if (!(gSaveBlock2Ptr->specialSaveWarpFlags & 0x80)) return 1; else if (structPtr->unk.field_0.unk_00.unk_00_7) return 0; @@ -1633,8 +1633,8 @@ void sub_8014210(u16 battleFlags) void sub_8014290(u16 arg0, u16 x, u16 y) { VarSet(VAR_0x4087, arg0); - Overworld_SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); - saved_warp2_set_2(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); + SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); + SetDynamicWarpWithCoords(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x, y); WarpIntoMap(); } @@ -1645,7 +1645,7 @@ void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 arg4) gFieldLinkPlayerCount = GetLinkPlayerCount(); gUnknown_03005DB4 = GetMultiplayerId(); SetCableClubWarp(); - Overworld_SetWarpDestination(mapGroup, mapNum, -1, x, y); + SetWarpDestination(mapGroup, mapNum, -1, x, y); WarpIntoMap(); } @@ -1697,12 +1697,12 @@ void sub_801440C(u8 taskId) { case 65: case 81: - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); gMain.savedCallback = sub_801AC54; sub_81B8518(3); break; case 1: - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_80143E4(gBlockSendBuffer, TRUE); HealPlayerParty(); SavePlayerParty(); @@ -1711,7 +1711,7 @@ void sub_801440C(u8 taskId) SetMainCallback2(sub_8014384); break; case 2: - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); HealPlayerParty(); SavePlayerParty(); LoadPlayerBag(); @@ -1720,7 +1720,7 @@ void sub_801440C(u8 taskId) SetMainCallback2(sub_8014384); break; case 3: - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); HealPlayerParty(); SavePlayerParty(); LoadPlayerBag(); @@ -1730,18 +1730,18 @@ void sub_801440C(u8 taskId) break; case 4: sub_80143E4(gBlockSendBuffer, TRUE); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_8014304(MAP_GROUP(TRADE_CENTER), MAP_NUM(TRADE_CENTER), 5, 8, 3); SetMainCallback2(sub_8014384); break; case 15: sub_80143E4(gBlockSendBuffer, TRUE); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); sub_8014304(MAP_GROUP(RECORD_CORNER), MAP_NUM(RECORD_CORNER), 8, 9, 4); SetMainCallback2(sub_8014384); break; case 68: - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); CreateTask(sub_8013F90, 0); break; case 5: diff --git a/src/roulette_util.c b/src/roulette_util.c index a197cfa09..c556a4af5 100755 --- a/src/roulette_util.c +++ b/src/roulette_util.c @@ -206,463 +206,227 @@ void sub_8151A9C(struct UnkStruct0 *r0, u16 r1) } } -void sub_8151B3C(struct InnerStruct203CF18 *arg0) +void InitPulseBlend(struct PulseBlend *pulseBlend) { u8 i = 0; - arg0->unk0 = 0; - memset(&arg0->unk4, 0, sizeof(arg0->unk4)); + pulseBlend->usedPulseBlendPalettes = 0; + memset(&pulseBlend->pulseBlendPalettes, 0, sizeof(pulseBlend->pulseBlendPalettes)); for (; i < 16; i++) - { - arg0->unk4[i].unk0 = i; - } + pulseBlend->pulseBlendPalettes[i].paletteSelector = i; } -int sub_8151B68(struct InnerStruct203CF18 *arg0, const struct InnerStruct203CF18_3 *arg1) +int InitPulseBlendPaletteSettings(struct PulseBlend *pulseBlend, const struct PulseBlendSettings *settings) { u8 i = 0; - struct InnerStruct203CF18_2 *r4 = NULL; + struct PulseBlendPalette *pulseBlendPalette = NULL; - if (!arg0->unk4[0].unk1_7) + if (!pulseBlend->pulseBlendPalettes[0].inUse) { - r4 = &arg0->unk4[0]; + pulseBlendPalette = &pulseBlend->pulseBlendPalettes[0]; } else { while (++i < 16) { - if (!arg0->unk4[i].unk1_7) + if (!pulseBlend->pulseBlendPalettes[i].inUse) { - r4 = &arg0->unk4[i]; + pulseBlendPalette = &pulseBlend->pulseBlendPalettes[i]; break; } } } - if (r4 == 0) + if (pulseBlendPalette == NULL) return 0xFF; - r4->unk1_0 = 0; - r4->unk1_4 = 0; - r4->unk1_6 = 1; - r4->unk1_7 = 1; - r4->unk2 = 0; - r4->unk3 = 0; - memcpy(&r4->unk4, arg1, sizeof(*arg1)); + pulseBlendPalette->blendCoeff = 0; + pulseBlendPalette->fadeDirection = 0; + pulseBlendPalette->available = 1; + pulseBlendPalette->inUse = 1; + pulseBlendPalette->delayCounter = 0; + pulseBlendPalette->fadeCycleCounter = 0; + memcpy(&pulseBlendPalette->pulseBlendSettings, settings, sizeof(*settings)); return i; } -void sub_8151BD4(struct InnerStruct203CF18_2 *arg0) +static void ClearPulseBlendPalettesSettings(struct PulseBlendPalette *pulseBlendPalette) { u16 i; - if (!arg0->unk1_6 && arg0->unk4.unk7_6) + if (!pulseBlendPalette->available && pulseBlendPalette->pulseBlendSettings.restorePaletteOnUnload) { - for (i = arg0->unk4.unk2; i < arg0->unk4.unk2 + arg0->unk4.unk4; i++) + for (i = pulseBlendPalette->pulseBlendSettings.paletteOffset; i < pulseBlendPalette->pulseBlendSettings.paletteOffset + pulseBlendPalette->pulseBlendSettings.numColors; i++) gPlttBufferFaded[i] = gPlttBufferUnfaded[i]; } - memset(&arg0->unk4, 0, sizeof(arg0->unk4)); - arg0->unk1_0 = 0; - arg0->unk1_4 = 0; - arg0->unk1_5 = 0; - arg0->unk1_6 = 1; - arg0->unk1_7 = 0; - arg0->unk3 = 0; - arg0->unk2 = 0; + memset(&pulseBlendPalette->pulseBlendSettings, 0, sizeof(pulseBlendPalette->pulseBlendSettings)); + pulseBlendPalette->blendCoeff = 0; + pulseBlendPalette->fadeDirection = 0; + pulseBlendPalette->unk1_5 = 0; + pulseBlendPalette->available = 1; + pulseBlendPalette->inUse = 0; + pulseBlendPalette->fadeCycleCounter = 0; + pulseBlendPalette->delayCounter = 0; } -void sub_8151C50(struct InnerStruct203CF18 *arg0, u16 arg1, u8 arg2) +void UnloadUsedPulseBlendPalettes(struct PulseBlend *pulseBlend, u16 pulseBlendPaletteSelector, u8 multiSelection) { u16 i = 0; - if (!arg2) + if (!multiSelection) { - sub_8151BD4(&arg0->unk4[arg1 & 0xF]); + ClearPulseBlendPalettesSettings(&pulseBlend->pulseBlendPalettes[pulseBlendPaletteSelector & 0xF]); } else { for (i = 0; i < 16; i++) { - if ((arg1 & 1) && arg0->unk4[i].unk1_7) - sub_8151BD4(&arg0->unk4[i]); + if ((pulseBlendPaletteSelector & 1) && pulseBlend->pulseBlendPalettes[i].inUse) + ClearPulseBlendPalettesSettings(&pulseBlend->pulseBlendPalettes[i]); - arg1 >>= 1; + pulseBlendPaletteSelector >>= 1; } } } -// there seems to be a temp var involved inside the first if block -void sub_8151CA8(struct InnerStruct203CF18 *arg0, u16 arg1, u8 arg2) +void MarkUsedPulseBlendPalettes(struct PulseBlend *pulseBlend, u16 pulseBlendPaletteSelector, u8 multiSelection) { u8 i = 0; - if (!arg2) + if (!multiSelection) { - i = arg1 & 0xF; - arg0->unk4[i].unk1_6 = 0; - arg0->unk0 |= 1 << i; + i = pulseBlendPaletteSelector & 0xF; + pulseBlend->pulseBlendPalettes[i].available = 0; + pulseBlend->usedPulseBlendPalettes |= 1 << i; } else { for (i = 0; i < 16; i++) { - if (!(arg1 & 1) || !arg0->unk4[i].unk1_7 || !arg0->unk4[i].unk1_6) + if (!(pulseBlendPaletteSelector & 1) || !pulseBlend->pulseBlendPalettes[i].inUse || !pulseBlend->pulseBlendPalettes[i].available) { - arg1 <<= 1; + pulseBlendPaletteSelector <<= 1; } else { - arg0->unk4[i].unk1_6 = 0; - arg0->unk0 |= 1 << i; + pulseBlend->pulseBlendPalettes[i].available = 0; + pulseBlend->usedPulseBlendPalettes |= 1 << i; } } } } -void sub_8151D28(struct InnerStruct203CF18 *arg0, u16 arg1, u8 arg2) +void UnmarkUsedPulseBlendPalettes(struct PulseBlend *pulseBlend, u16 pulseBlendPaletteSelector, u8 multiSelection) { u16 i; - struct InnerStruct203CF18_2 *var0; + struct PulseBlendPalette *pulseBlendPalette; u8 j = 0; - if (!arg2) + if (!multiSelection) { - var0 = &arg0->unk4[arg1 & 0xF]; - if (!var0->unk1_6 && var0->unk1_7) + pulseBlendPalette = &pulseBlend->pulseBlendPalettes[pulseBlendPaletteSelector & 0xF]; + if (!pulseBlendPalette->available && pulseBlendPalette->inUse) { - if (var0->unk4.unk7_6) + if (pulseBlendPalette->pulseBlendSettings.restorePaletteOnUnload) { - for (i = var0->unk4.unk2; i < var0->unk4.unk2 + var0->unk4.unk4; i++) + for (i = pulseBlendPalette->pulseBlendSettings.paletteOffset; i < pulseBlendPalette->pulseBlendSettings.paletteOffset + pulseBlendPalette->pulseBlendSettings.numColors; i++) gPlttBufferFaded[i] = gPlttBufferUnfaded[i]; } - var0->unk1_6 = 1; - arg0->unk0 &= ~(1 << j); + pulseBlendPalette->available = 1; + pulseBlend->usedPulseBlendPalettes &= ~(1 << j); } } else { for (j = 0; j < 16; j++) { - var0 = &arg0->unk4[j]; - if (!(arg1 & 1) || var0->unk1_6 || !var0->unk1_7) + pulseBlendPalette = &pulseBlend->pulseBlendPalettes[j]; + if (!(pulseBlendPaletteSelector & 1) || pulseBlendPalette->available || !pulseBlendPalette->inUse) { - arg1 <<= 1; + pulseBlendPaletteSelector <<= 1; } else { - if (var0->unk4.unk7_6) + if (pulseBlendPalette->pulseBlendSettings.restorePaletteOnUnload) { - for (i = var0->unk4.unk2; i < var0->unk4.unk2 + var0->unk4.unk4; i++) + for (i = pulseBlendPalette->pulseBlendSettings.paletteOffset; i < pulseBlendPalette->pulseBlendSettings.paletteOffset + pulseBlendPalette->pulseBlendSettings.numColors; i++) gPlttBufferFaded[i] = gPlttBufferUnfaded[i]; } - var0->unk1_6 = 1; - arg0->unk0 &= ~(1 << j); + pulseBlendPalette->available = 1; + pulseBlend->usedPulseBlendPalettes &= ~(1 << j); } } } } -#ifdef NONMATCHING -void sub_8151E50(struct InnerStruct203CF18 *arg0) +void UpdatePulseBlend(struct PulseBlend *pulseBlend) { - struct InnerStruct203CF18_2 *var0; + struct PulseBlendPalette *pulseBlendPalette; u8 i = 0; - if (arg0->unk0) + if (pulseBlend->usedPulseBlendPalettes) { for (i = 0; i < 16; i++) { - var0 = &arg0->unk4[i]; - if ((!var0->unk1_6 && var0->unk1_7) && (!gPaletteFade.active || !var0->unk4.unk7_7)) + pulseBlendPalette = &pulseBlend->pulseBlendPalettes[i]; + if ((!pulseBlendPalette->available && pulseBlendPalette->inUse) && (!gPaletteFade.active || !pulseBlendPalette->pulseBlendSettings.unk7_7)) { - if (--var0->unk2 == 0xFF) + if (--pulseBlendPalette->delayCounter == 0xFF) { - var0->unk2 = var0->unk4.unk5; - BlendPalette(var0->unk4.unk2, var0->unk4.unk4, var0->unk1_0, var0->unk4.unk0); - switch (var0->unk4.unk7_4) + pulseBlendPalette->delayCounter = pulseBlendPalette->pulseBlendSettings.delay; + BlendPalette(pulseBlendPalette->pulseBlendSettings.paletteOffset, pulseBlendPalette->pulseBlendSettings.numColors, pulseBlendPalette->blendCoeff, pulseBlendPalette->pulseBlendSettings.blendColor); + switch (pulseBlendPalette->pulseBlendSettings.fadeType) { - case 0: - if (var0->unk1_0++ == var0->unk4.unk7_0) + case 0: // Fade all the way to the max blend amount, then wrap around + // BUG: This comparison will never be true for maxBlendCoeff values that are >= 8. This is because + // maxBlendCoeff is a signed 4-bit field, but blendCoeff is an unsigned 4-bit field. This code is never + // reached, anyway, so the bug is not observable in vanilla gameplay. + if (pulseBlendPalette->blendCoeff++ == pulseBlendPalette->pulseBlendSettings.maxBlendCoeff) { - var0->unk3++; - var0->unk1_0 = 0; + pulseBlendPalette->fadeCycleCounter++; + pulseBlendPalette->blendCoeff = 0; } break; - case 1: - if (var0->unk1_4) + case 1: // Fade in and out + if (pulseBlendPalette->fadeDirection) { - if (--var0->unk1_0 == 0) + if (--pulseBlendPalette->blendCoeff == 0) { - var0->unk3++; - var0->unk1_4 ^= 1; + pulseBlendPalette->fadeCycleCounter++; + pulseBlendPalette->fadeDirection ^= 1; } } else { - if (var0->unk1_0++ == var0->unk4.unk7_0 - 1) + u8 max = (pulseBlendPalette->pulseBlendSettings.maxBlendCoeff - 1) & 0xF; + if (pulseBlendPalette->blendCoeff++ == max) { - var0->unk3++; - var0->unk1_4 ^= 1; + pulseBlendPalette->fadeCycleCounter++; + pulseBlendPalette->fadeDirection ^= 1; } } break; - case 2: - if (var0->unk1_4) - var0->unk1_0 = 0; + case 2: // Flip back and forth + if (pulseBlendPalette->fadeDirection) + pulseBlendPalette->blendCoeff = 0; else - var0->unk1_0 = var0->unk4.unk7_0; + pulseBlendPalette->blendCoeff = pulseBlendPalette->pulseBlendSettings.maxBlendCoeff & 0xF; - var0->unk1_4 ^= 1; - var0->unk3++; + pulseBlendPalette->fadeDirection ^= 1; + pulseBlendPalette->fadeCycleCounter++; break; } - if (var0->unk4.unk6 != 0xFF && var0->unk3 == 0xFF) - sub_8151D28(arg0, var0->unk0, 0); + if (pulseBlendPalette->pulseBlendSettings.numFadeCycles != 0xFF + && pulseBlendPalette->fadeCycleCounter == pulseBlendPalette->pulseBlendSettings.numFadeCycles) + UnmarkUsedPulseBlendPalettes(pulseBlend, pulseBlendPalette->paletteSelector, FALSE); } } } } } -#else -NAKED -void sub_8151E50(struct InnerStruct203CF18 *arg0) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - sub sp, 0x4\n\ - str r0, [sp]\n\ - movs r0, 0\n\ - mov r10, r0\n\ - ldr r1, [sp]\n\ - ldrh r0, [r1]\n\ - cmp r0, 0\n\ - bne _08151E6C\n\ - b _08151FF6\n\ -_08151E6C:\n\ - movs r2, 0xF\n\ - mov r9, r2\n\ - movs r3, 0x10\n\ - negs r3, r3\n\ - mov r8, r3\n\ - movs r7, 0x1\n\ -_08151E78:\n\ - mov r5, r10\n\ - lsls r0, r5, 1\n\ - add r0, r10\n\ - lsls r0, 2\n\ - adds r0, 0x4\n\ - ldr r1, [sp]\n\ - adds r4, r1, r0\n\ - ldrb r2, [r4, 0x1]\n\ - movs r3, 0xC0\n\ - ands r3, r2\n\ - cmp r3, 0x80\n\ - beq _08151E92\n\ - b _08151FE6\n\ -_08151E92:\n\ - ldr r0, =gPaletteFade\n\ - ldrb r1, [r0, 0x7]\n\ - adds r0, r3, 0\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _08151EA8\n\ - ldrb r0, [r4, 0xB]\n\ - ands r3, r0\n\ - cmp r3, 0\n\ - beq _08151EA8\n\ - b _08151FE6\n\ -_08151EA8:\n\ - ldrb r0, [r4, 0x2]\n\ - subs r0, 0x1\n\ - strb r0, [r4, 0x2]\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - cmp r0, 0xFF\n\ - beq _08151EB8\n\ - b _08151FE6\n\ -_08151EB8:\n\ - ldrb r0, [r4, 0x9]\n\ - strb r0, [r4, 0x2]\n\ - ldrh r0, [r4, 0x6]\n\ - ldrb r1, [r4, 0x8]\n\ - lsls r2, 28\n\ - lsrs r2, 28\n\ - ldrh r3, [r4, 0x4]\n\ - bl BlendPalette\n\ - ldrb r5, [r4, 0xB]\n\ - lsls r0, r5, 26\n\ - asrs r0, 30\n\ - cmp r0, 0x1\n\ - beq _08151F16\n\ - cmp r0, 0x1\n\ - bgt _08151EE4\n\ - cmp r0, 0\n\ - beq _08151EEA\n\ - b _08151FD0\n\ - .pool\n\ -_08151EE4:\n\ - cmp r0, 0x2\n\ - beq _08151F92\n\ - b _08151FD0\n\ -_08151EEA:\n\ - ldrb r2, [r4, 0x1]\n\ - lsls r1, r2, 28\n\ - lsrs r0, r1, 28\n\ - adds r0, 0x1\n\ - mov r3, r9\n\ - ands r0, r3\n\ - mov r6, r8\n\ - adds r3, r6, 0\n\ - ands r3, r2\n\ - orrs r3, r0\n\ - strb r3, [r4, 0x1]\n\ - lsrs r1, 28\n\ - lsls r0, r5, 28\n\ - asrs r0, 28\n\ - cmp r1, r0\n\ - bne _08151FD0\n\ - ldrb r0, [r4, 0x3]\n\ - adds r0, 0x1\n\ - strb r0, [r4, 0x3]\n\ - ands r3, r6\n\ - strb r3, [r4, 0x1]\n\ - b _08151FD0\n\ -_08151F16:\n\ - ldrb r3, [r4, 0x1]\n\ - movs r0, 0x10\n\ - ands r0, r3\n\ - cmp r0, 0\n\ - beq _08151F54\n\ - lsls r0, r3, 28\n\ - lsrs r0, 28\n\ - subs r0, 0x1\n\ - mov r5, r9\n\ - ands r0, r5\n\ - mov r2, r8\n\ - ands r2, r3\n\ - orrs r2, r0\n\ - strb r2, [r4, 0x1]\n\ - cmp r0, 0\n\ - bne _08151FD0\n\ - ldrb r0, [r4, 0x3]\n\ - adds r0, 0x1\n\ - strb r0, [r4, 0x3]\n\ - lsls r0, r2, 27\n\ - lsrs r0, 31\n\ - eors r0, r7\n\ - ands r0, r7\n\ - lsls r0, 4\n\ - movs r3, 0x11\n\ - negs r3, r3\n\ - adds r1, r3, 0\n\ - ands r2, r1\n\ - orrs r2, r0\n\ - strb r2, [r4, 0x1]\n\ - b _08151FD0\n\ -_08151F54:\n\ - lsls r0, r5, 28\n\ - asrs r0, 28\n\ - subs r0, 0x1\n\ - mov r5, r9\n\ - ands r0, r5\n\ - lsls r2, r3, 28\n\ - lsrs r1, r2, 28\n\ - adds r1, 0x1\n\ - ands r1, r5\n\ - mov r5, r8\n\ - ands r3, r5\n\ - orrs r3, r1\n\ - strb r3, [r4, 0x1]\n\ - lsrs r2, 28\n\ - cmp r2, r0\n\ - bne _08151FD0\n\ - ldrb r0, [r4, 0x3]\n\ - adds r0, 0x1\n\ - strb r0, [r4, 0x3]\n\ - lsls r0, r3, 27\n\ - lsrs r0, 31\n\ - eors r0, r7\n\ - ands r0, r7\n\ - lsls r0, 4\n\ - movs r2, 0x11\n\ - negs r2, r2\n\ - adds r1, r2, 0\n\ - ands r3, r1\n\ - orrs r3, r0\n\ - strb r3, [r4, 0x1]\n\ - b _08151FD0\n\ -_08151F92:\n\ - ldrb r2, [r4, 0x1]\n\ - movs r0, 0x10\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _08151FA2\n\ - mov r0, r8\n\ - ands r0, r2\n\ - b _08151FB0\n\ -_08151FA2:\n\ - lsls r1, r5, 28\n\ - asrs r1, 28\n\ - mov r3, r9\n\ - ands r1, r3\n\ - mov r0, r8\n\ - ands r0, r2\n\ - orrs r0, r1\n\ -_08151FB0:\n\ - strb r0, [r4, 0x1]\n\ - ldrb r2, [r4, 0x1]\n\ - lsls r0, r2, 27\n\ - lsrs r0, 31\n\ - eors r0, r7\n\ - ands r0, r7\n\ - lsls r0, 4\n\ - movs r5, 0x11\n\ - negs r5, r5\n\ - adds r1, r5, 0\n\ - ands r2, r1\n\ - orrs r2, r0\n\ - strb r2, [r4, 0x1]\n\ - ldrb r0, [r4, 0x3]\n\ - adds r0, 0x1\n\ - strb r0, [r4, 0x3]\n\ -_08151FD0:\n\ - ldrb r1, [r4, 0xA]\n\ - cmp r1, 0xFF\n\ - beq _08151FE6\n\ - ldrb r0, [r4, 0x3]\n\ - cmp r0, r1\n\ - bne _08151FE6\n\ - ldrb r1, [r4]\n\ - ldr r0, [sp]\n\ - movs r2, 0\n\ - bl sub_8151D28\n\ -_08151FE6:\n\ - mov r0, r10\n\ - adds r0, 0x1\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - mov r10, r0\n\ - cmp r0, 0xF\n\ - bhi _08151FF6\n\ - b _08151E78\n\ -_08151FF6:\n\ - add sp, 0x4\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0"); -} -#endif // NONMATCHING void sub_8152008(u16 *dest, u16 src, u8 left, u8 top, u8 width, u8 height) { diff --git a/src/save.c b/src/save.c index e8f4a96da..cfbe5b848 100644 --- a/src/save.c +++ b/src/save.c @@ -923,7 +923,7 @@ void sub_8153688(u8 taskId) break; case 3: if (taskData[2] == 0) - sub_8076D5C(); + SetContinueGameWarpStatusToDynamicWarp(); sub_8153380(); taskData[0] = 4; break; @@ -946,7 +946,7 @@ void sub_8153688(u8 taskId) break; case 7: if (taskData[2] == 0) - sav2_gender2_inplace_and_xFE(); + ClearContinueGameWarpStatus2(); sub_800ADF8(); taskData[0] = 8; break; diff --git a/src/save_location.c b/src/save_location.c index d49afa736..2443b3161 100644 --- a/src/save_location.c +++ b/src/save_location.c @@ -2,11 +2,6 @@ #include "save_location.h" #include "constants/maps.h" -// specialSaveWarp flags -#define POKECENTER_SAVEWARP (1 << 1) -#define LOBBY_SAVEWARP (1 << 2) -#define UNK_SPECIAL_SAVE_WARP_FLAG_3 (1 << 3) - static bool32 IsCurMapInLocationList(const u16 *list) { s32 i; @@ -94,26 +89,26 @@ static bool32 sub_81AFCEC(void) static void TrySetPokeCenterWarpStatus(void) { if (IsCurMapPokeCenter() == FALSE) - gSaveBlock2Ptr->specialSaveWarp &= ~(POKECENTER_SAVEWARP); + gSaveBlock2Ptr->specialSaveWarpFlags &= ~(POKECENTER_SAVEWARP); else - gSaveBlock2Ptr->specialSaveWarp |= POKECENTER_SAVEWARP; + gSaveBlock2Ptr->specialSaveWarpFlags |= POKECENTER_SAVEWARP; } static void TrySetReloadWarpStatus(void) { if (!IsCurMapReloadLocation()) - gSaveBlock2Ptr->specialSaveWarp &= ~(LOBBY_SAVEWARP); + gSaveBlock2Ptr->specialSaveWarpFlags &= ~(LOBBY_SAVEWARP); else - gSaveBlock2Ptr->specialSaveWarp |= LOBBY_SAVEWARP; + gSaveBlock2Ptr->specialSaveWarpFlags |= LOBBY_SAVEWARP; } // this function definitely sets a warp status, but because the list is empty, it's unknown what this does yet. static void sub_81AFD5C(void) { if (!sub_81AFCEC()) - gSaveBlock2Ptr->specialSaveWarp &= ~(UNK_SPECIAL_SAVE_WARP_FLAG_3); + gSaveBlock2Ptr->specialSaveWarpFlags &= ~(UNK_SPECIAL_SAVE_WARP_FLAG_3); else - gSaveBlock2Ptr->specialSaveWarp |= UNK_SPECIAL_SAVE_WARP_FLAG_3; + gSaveBlock2Ptr->specialSaveWarpFlags |= UNK_SPECIAL_SAVE_WARP_FLAG_3; } void TrySetMapSaveWarpStatus(void) @@ -136,5 +131,5 @@ void sub_81AFDA0(void) void sub_81AFDD0(void) { - gSaveBlock2Ptr->specialSaveWarp |= 0x80; + gSaveBlock2Ptr->specialSaveWarpFlags |= 0x80; } diff --git a/src/scrcmd.c b/src/scrcmd.c index c00cc68d1..837259a7f 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -49,6 +49,7 @@ #include "trainer_see.h" #include "tv.h" #include "window.h" +#include "constants/event_objects.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(void); @@ -734,7 +735,7 @@ bool8 ScrCmd_setmaplayoutindex(struct ScriptContext *ctx) { u16 value = VarGet(ScriptReadHalfword(ctx)); - sub_8085524(value); + SetCurrentMapLayout(value); return FALSE; } @@ -746,8 +747,8 @@ bool8 ScrCmd_warp(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); - sub_80AF734(); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); + DoWarp(); ResetInitialPlayerAvatarState(); return TRUE; } @@ -760,8 +761,8 @@ bool8 ScrCmd_warpsilent(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); - sp13E_warp_to_last_warp(); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); + DoDiveWarp(); ResetInitialPlayerAvatarState(); return TRUE; } @@ -774,8 +775,8 @@ bool8 ScrCmd_warpdoor(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); - sub_80AF7D0(); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); + DoDoorWarp(); ResetInitialPlayerAvatarState(); return TRUE; } @@ -789,10 +790,10 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) PlayerGetDestCoords(&x, &y); if (mapGroup == 0xFF && mapNum == 0xFF) - SetFixedHoleWarpAsDestination(x - 7, y - 7); + SetWarpDestinationToFixedHoleWarp(x - 7, y - 7); else - Overworld_SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7); - sp13F_fall_to_last_warp(); + SetWarpDestination(mapGroup, mapNum, -1, x - 7, y - 7); + DoFallWarp(); ResetInitialPlayerAvatarState(); return TRUE; } @@ -805,7 +806,7 @@ bool8 ScrCmd_warpteleport(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_80AF848(); ResetInitialPlayerAvatarState(); return TRUE; @@ -819,7 +820,7 @@ bool8 ScrCmd_warpD7(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_80AF87C(); ResetInitialPlayerAvatarState(); return TRUE; @@ -833,7 +834,7 @@ bool8 ScrCmd_setwarp(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); return FALSE; } @@ -845,7 +846,7 @@ bool8 ScrCmd_setdynamicwarp(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - saved_warp2_set_2(0, mapGroup, mapNum, warpId, x, y); + SetDynamicWarpWithCoords(0, mapGroup, mapNum, warpId, x, y); return FALSE; } @@ -881,7 +882,7 @@ bool8 ScrCmd_setescapewarp(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - sub_8084DD4(mapGroup, mapNum, warpId, x, y); + SetEscapeWarp(mapGroup, mapNum, warpId, x, y); return FALSE; } @@ -1238,11 +1239,11 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx) bool8 ScrCmd_releaseall(struct ScriptContext *ctx) { - u8 objectId; + u8 playerObjectId; HideFieldMessageBox(); - objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); return FALSE; @@ -1250,13 +1251,13 @@ bool8 ScrCmd_releaseall(struct ScriptContext *ctx) bool8 ScrCmd_release(struct ScriptContext *ctx) { - u8 objectId; + u8 playerObjectId; HideFieldMessageBox(); if (gEventObjects[gSelectedEventObject].active) EventObjectClearHeldMovementIfFinished(&gEventObjects[gSelectedEventObject]); - objectId = GetEventObjectIdByLocalIdAndMap(0xFF, 0, 0); - EventObjectClearHeldMovementIfFinished(&gEventObjects[objectId]); + playerObjectId = GetEventObjectIdByLocalIdAndMap(EVENT_OBJ_ID_PLAYER, 0, 0); + EventObjectClearHeldMovementIfFinished(&gEventObjects[playerObjectId]); sub_80D338C(); UnfreezeEventObjects(); return FALSE; @@ -1997,7 +1998,7 @@ bool8 ScrCmd_setrespawn(struct ScriptContext *ctx) { u16 healLocationId = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetHealLocationWarp(healLocationId); + SetLastHealLocationWarp(healLocationId); return FALSE; } @@ -2234,7 +2235,7 @@ bool8 ScrCmd_warpD1(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_808D074(GetPlayerFacingDirection()); sub_80B0244(); ResetInitialPlayerAvatarState(); @@ -2288,7 +2289,7 @@ bool8 ScrCmd_warpE0(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); - Overworld_SetWarpDestination(mapGroup, mapNum, warpId, x, y); + SetWarpDestination(mapGroup, mapNum, warpId, x, y); sub_80AF79C(); ResetInitialPlayerAvatarState(); return TRUE; diff --git a/src/script_pokemon_util_80F87D8.c b/src/script_pokemon_util_80F87D8.c index b65557fe7..15e91ac98 100755 --- a/src/script_pokemon_util_80F87D8.c +++ b/src/script_pokemon_util_80F87D8.c @@ -528,7 +528,7 @@ void HealPlayerParty(void) ppBonuses = GetMonData(&gPlayerParty[i], MON_DATA_PP_BONUSES); // restore PP. - for(j = 0; j < 4; j++) + for(j = 0; j < MAX_MON_MOVES; j++) { arg[0] = CalculatePPWithBonus(GetMonData(&gPlayerParty[i], MON_DATA_MOVE1 + j), ppBonuses, j); SetMonData(&gPlayerParty[i], MON_DATA_PP1 + j, arg); diff --git a/src/secret_base.c b/src/secret_base.c index 7e7b10a9a..1f3f9b46a 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -366,7 +366,7 @@ void sub_80E8F9C(void) s8 idx; idx = sCurSecretBaseId / 10 * 4; - warp1_set_2(MAP_GROUP(SECRET_BASE_RED_CAVE1), gUnknown_0858CFE8[idx], gUnknown_0858CFE8[idx + 1]); + SetWarpDestinationToMapWarp(MAP_GROUP(SECRET_BASE_RED_CAVE1), gUnknown_0858CFE8[idx], gUnknown_0858CFE8[idx + 1]); } void sub_80E8FD0(u8 taskId) @@ -400,7 +400,7 @@ void sub_80E9068(void) { CreateTask(sub_80E8FD0, 0); FadeScreen(1, 0); - saved_warp2_set(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); + SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1); } bool8 sub_80E909C(void) @@ -445,7 +445,7 @@ void sub_80E916C(u8 taskId) if (!gPaletteFade.active) { idx = sCurSecretBaseId / 10 * 4; - Overworld_SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, gUnknown_0858CFE8[idx + 2], gUnknown_0858CFE8[idx + 3]); + SetWarpDestination(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, gUnknown_0858CFE8[idx + 2], gUnknown_0858CFE8[idx + 3]); WarpIntoMap(); gFieldCallback = sub_80E9108; SetMainCallback2(CB2_LoadMap); @@ -610,7 +610,7 @@ void sub_80E9608(const struct MapPosition *position, const struct MapEvents *eve } } -void sub_80E9668(const struct MapPosition *position, const struct MapEvents *events) +void WarpIntoSecretBase(const struct MapPosition *position, const struct MapEvents *events) { sub_80E9608(position, events); sub_80E8B6C(); @@ -643,7 +643,7 @@ void sub_80E96A4(u8 taskId) } break; case 2: - copy_saved_warp2_bank_and_enter_x_to_warp1(0x7e); + SetWarpDestinationToDynamicWarp(0x7e); WarpIntoMap(); gFieldCallback = mapldr_default; SetMainCallback2(CB2_LoadMap); diff --git a/src/start_menu.c b/src/start_menu.c index ad7b4b6cc..0f608b1d2 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -623,7 +623,7 @@ static bool8 StartMenuPokedexCallback(void) IncrementGameStat(GAME_STAT_CHECKED_POKEDEX); PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_Pokedex); return TRUE; @@ -638,7 +638,7 @@ static bool8 StartMenuPokemonCallback(void) { PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_PartyMenuFromStartMenu); // Display party menu return TRUE; @@ -653,7 +653,7 @@ static bool8 StartMenuBagCallback(void) { PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_BagMenuFromStartMenu); // Display bag menu return TRUE; @@ -668,7 +668,7 @@ static bool8 StartMenuPokeNavCallback(void) { PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_PokeNav); // Display PokeNav return TRUE; @@ -683,7 +683,7 @@ static bool8 StartMenuPlayerNameCallback(void) { PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); if (is_c1_link_related_active() || InUnionRoom()) { @@ -722,7 +722,7 @@ static bool8 StartMenuOptionCallback(void) { PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_InitOptionMenu); // Display option menu gMain.savedCallback = CB2_ReturnToFieldWithOpenMenu; @@ -754,7 +754,7 @@ static bool8 StartMenuLinkModePlayerNameCallback(void) if (!gPaletteFade.active) { PlayRainSoundEffect(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); TrainerCard_ShowLinkCard(gUnknown_03005DB4, CB2_ReturnToFieldWithOpenMenu); return TRUE; @@ -784,7 +784,7 @@ static bool8 StartMenuBattlePyramidBagCallback(void) { PlayRainSoundEffect(); RemoveExtraStartMenuWindows(); - overworld_free_bg_tilemaps(); + CleanupOverworldWindowsAndTilemaps(); SetMainCallback2(CB2_PyramidBagMenuFromStartMenu); return TRUE; @@ -1285,14 +1285,14 @@ static void sub_80A0550(u8 taskId) } break; case 1: - sub_8076D5C(); + SetContinueGameWarpStatusToDynamicWarp(); sub_8153430(); *step = 2; break; case 2: if (sub_8153474()) { - sav2_gender2_inplace_and_xFE(); + ClearContinueGameWarpStatus2(); *step = 3; gSoftResetDisabled = 0; } diff --git a/src/starter_choose.c b/src/starter_choose.c index afa3fabbf..2d4a1b1e1 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -425,7 +425,7 @@ void CB2_ChooseStarter(void) SetGpuReg(REG_OFFSET_WINOUT, 0x1F); SetGpuReg(REG_OFFSET_WIN0H, 0); SetGpuReg(REG_OFFSET_WIN0V, 0); - SetGpuReg(REG_OFFSET_BLDCNT, 0xFE); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_TGT1_BG2 | BLDCNT_TGT1_BG3 | BLDCNT_TGT1_OBJ | BLDCNT_TGT1_BD | BLDCNT_EFFECT_DARKEN); SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDY, 7); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); diff --git a/src/title_screen.c b/src/title_screen.c index c6e9aa26f..48571ff96 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -553,7 +553,7 @@ void CB2_InitTitleScreen(void) SetGpuReg(REG_OFFSET_WIN1V, 0); SetGpuReg(REG_OFFSET_WININ, 0x1F1F); SetGpuReg(REG_OFFSET_WINOUT, 0x3F1F); - SetGpuReg(REG_OFFSET_BLDCNT, 0x84); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG2 | BLDCNT_EFFECT_LIGHTEN); SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDY, 0xC); SetGpuReg(REG_OFFSET_BG0CNT, BGCNT_PRIORITY(3) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(26) | BGCNT_16COLOR | BGCNT_TXT256x256); @@ -615,8 +615,8 @@ static void Task_TitleScreenPhase1(u8 taskId) SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG2_ON | DISPCNT_OBJ_ON); SetGpuReg(REG_OFFSET_WININ, 0); SetGpuReg(REG_OFFSET_WINOUT, 0); - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F50); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x10); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_OBJ | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 0)); SetGpuReg(REG_OFFSET_BLDY, 0); // Create left side of version banner @@ -652,8 +652,8 @@ static void Task_TitleScreenPhase2(u8 taskId) else { gTasks[taskId].tSkipToNext = TRUE; - SetGpuReg(REG_OFFSET_BLDCNT, 0x2142); - SetGpuReg(REG_OFFSET_BLDALPHA, 0xF06); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BD); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(6, 15)); SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP diff --git a/src/trade.c b/src/trade.c index 9f29c2d69..ccdd43986 100644 --- a/src/trade.c +++ b/src/trade.c @@ -5986,7 +5986,7 @@ static void sub_807EB50(void) { sub_801B990(2, gLinkPlayers[GetMultiplayerId() ^ 1].trainerId); } - sub_8076D5C(); + SetContinueGameWarpStatusToDynamicWarp(); sub_8153380(); gMain.state++; gUnknown_020322A0->timer = 0; @@ -6000,7 +6000,7 @@ static void sub_807EB50(void) case 52: if (sub_81533AC()) { - sav2_gender2_inplace_and_xFE(); + ClearContinueGameWarpStatus2(); gMain.state = 4; } else @@ -862,13 +862,13 @@ void SetTVMetatilesOnMap(int width, int height, u16 tileId) void TurnOffTVScreen(void) { - SetTVMetatilesOnMap(gUnknown_03005DC0.width, gUnknown_03005DC0.height, 0x0002); + SetTVMetatilesOnMap(gBackupMapLayout.width, gBackupMapLayout.height, 0x0002); DrawWholeMapView(); } void TurnOnTVScreen(void) { - SetTVMetatilesOnMap(gUnknown_03005DC0.width, gUnknown_03005DC0.height, 0x0003); + SetTVMetatilesOnMap(gBackupMapLayout.width, gBackupMapLayout.height, 0x0003); DrawWholeMapView(); } diff --git a/src/unk_pokedex_area_screen_helper.c b/src/unk_pokedex_area_screen_helper.c index 67fd52cb5..0041d628c 100644 --- a/src/unk_pokedex_area_screen_helper.c +++ b/src/unk_pokedex_area_screen_helper.c @@ -22,21 +22,21 @@ void sub_81C4D70(const struct UnkStruct_1C4D70 *template) if (unk == 0) { - SetBgAttribute(template->bg, BG_CTRL_ATTR_WRAPAROUND, 0); + SetBgAttribute(template->bg, BG_ATTR_METRIC, 0); decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861D1A0, 0, template->unk2, unk); sub_8199D3C(decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861DEF4, 0, 0, 1), template->unk2, 32, 32, unk); } else { - SetBgAttribute(template->bg, BG_CTRL_ATTR_WRAPAROUND, 2); - SetBgAttribute(template->bg, 9, 1); + SetBgAttribute(template->bg, BG_ATTR_METRIC, 2); + SetBgAttribute(template->bg, BG_ATTR_TYPE, 1); decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861E208, 0, template->unk2, 0); sub_8199D3C(decompress_and_copy_tile_data_to_vram(template->bg, gUnknown_0861EF64, 0, 0, 1), template->unk2, 64, 64, 1); } ChangeBgX(template->bg, 0, 0); ChangeBgY(template->bg, 0, 0); - SetBgAttribute(template->bg, BG_CTRL_ATTR_SCREENSIZE, 1); + SetBgAttribute(template->bg, BG_ATTR_PALETTEMODE, 1); CpuCopy32(gUnknown_0861D140, &gPlttBufferUnfaded[0x70], 0x60); *gUnknown_0203CF28 = template->bg; } diff --git a/src/unk_transition.c b/src/unk_transition.c index 7346e06ab..d56998b5b 100644 --- a/src/unk_transition.c +++ b/src/unk_transition.c @@ -337,8 +337,8 @@ static bool8 sub_81DAACC(struct Task *task) else { sub_81DA700(); - SetGpuReg(REG_OFFSET_BLDCNT, 0x3F41); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x1000); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16)); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgY(0, 0x500, 2); @@ -368,11 +368,11 @@ static bool8 sub_81DAB4C(struct Task *task) } else { - u16 var; + u16 blnd; task->data[2]++; - var = task->data[2]; - SetGpuReg(REG_OFFSET_BLDALPHA, (var) | ((16 - var) << 8)); + blnd = task->data[2]; + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(blnd, 16 - blnd)); } return FALSE; diff --git a/src/wallclock.c b/src/wallclock.c index 58704c8a3..546750ba6 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -585,11 +585,11 @@ static void WallClockVblankCallback(void) static void LoadWallClockGraphics(void) { SetVBlankCallback(NULL); - SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); - SetGpuReg(REG_OFFSET_BG3CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG2CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG1CNT, 0x0000); - SetGpuReg(REG_OFFSET_BG0CNT, 0x0000); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + SetGpuReg(REG_OFFSET_BG3CNT, 0); + SetGpuReg(REG_OFFSET_BG2CNT, 0); + SetGpuReg(REG_OFFSET_BG1CNT, 0); + SetGpuReg(REG_OFFSET_BG0CNT, 0); ChangeBgX(0, 0, 0); ChangeBgY(0, 0, 0); ChangeBgX(1, 0, 0); @@ -633,9 +633,9 @@ static void WallClockInit(void) EnableInterrupts(INTR_FLAG_VBLANK); SetVBlankCallback(WallClockVblankCallback); SetMainCallback2(WallClockMainCallback); - SetGpuReg(REG_OFFSET_BLDCNT, 0x0000); - SetGpuReg(REG_OFFSET_BLDALPHA, 0x0000); - SetGpuReg(REG_OFFSET_BLDY, 0x0000); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + SetGpuReg(REG_OFFSET_BLDY, 0); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON); ShowBg(0); ShowBg(2); diff --git a/src/window.c b/src/window.c index aa1df3a12..3da529178 100644 --- a/src/window.c +++ b/src/window.c @@ -63,7 +63,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) if (gUnknown_03002F70[bgLayer] == NULL) { - attrib = GetBgAttribute(bgLayer, 0x8); + attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attrib != 0xFFFF) { @@ -141,7 +141,7 @@ u16 AddWindow(const struct WindowTemplate *template) if (gUnknown_03002F70[bgLayer] == NULL) { - attrib = GetBgAttribute(bgLayer, 0x8); + attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attrib != 0xFFFF) { @@ -328,7 +328,7 @@ void PutWindowTilemap(u8 windowId) WriteSequenceToBgTilemapBuffer( windowLocal.window.bg, - GetBgAttribute(windowLocal.window.bg, 0xA) + windowLocal.window.baseBlock, + GetBgAttribute(windowLocal.window.bg, BG_ATTR_BASETILE) + windowLocal.window.baseBlock, windowLocal.window.tilemapLeft, windowLocal.window.tilemapTop, windowLocal.window.width, @@ -340,7 +340,7 @@ void PutWindowTilemap(u8 windowId) void PutWindowRectTilemapOverridePalette(u8 windowId, u8 x, u8 y, u8 width, u8 height, u8 palette) { struct Window windowLocal = gWindows[windowId]; - u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, 0xA); + u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, BG_ATTR_BASETILE); int i; for (i = 0; i < height; ++i) @@ -376,7 +376,7 @@ void ClearWindowTilemap(u8 windowId) void PutWindowRectTilemap(u8 windowId, u8 x, u8 y, u8 width, u8 height) { struct Window windowLocal = gWindows[windowId]; - u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, 0xA); + u16 currentRow = windowLocal.window.baseBlock + (y * windowLocal.window.width) + x + GetBgAttribute(windowLocal.window.bg, BG_ATTR_BASETILE); int i; for (i = 0; i < height; ++i) @@ -617,7 +617,7 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) bgLayer = template->bg; if (gUnknown_03002F70[bgLayer] == 0) { - u16 attribute = GetBgAttribute(bgLayer, 8); + u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attribute != 0xFFFF) { s32 i; |