diff options
Diffstat (limited to 'src')
35 files changed, 1289 insertions, 548 deletions
diff --git a/src/battle/anim/guard.c b/src/battle/anim/guard.c index ab093eab1..254160109 100644 --- a/src/battle/anim/guard.c +++ b/src/battle/anim/guard.c @@ -1,4 +1,5 @@ #include "global.h" +#include "battle.h" #include "battle_anim.h" #include "rom_8077ABC.h" @@ -12,7 +13,7 @@ extern u16 gBattleTypeFlags; void sub_80D3014(struct Sprite *sprite) { - if ((gBattleTypeFlags & 1) && IsAnimBankSpriteVisible(gAnimBankAttacker ^ 2)) + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && IsAnimBankSpriteVisible(gAnimBankAttacker ^ 2)) { sub_807A3FC(gAnimBankAttacker, 0, &sprite->pos1.x, &sprite->pos1.y); sprite->pos1.y += 40; diff --git a/src/battle/battle_2.c b/src/battle/battle_2.c index b00c35312..2ad2adb04 100644 --- a/src/battle/battle_2.c +++ b/src/battle/battle_2.c @@ -396,7 +396,7 @@ void sub_800EC9C(void) case 0: if (gBattleTypeFlags & BATTLE_TYPE_LINK) { - if (gReceivedRemoteLinkPlayers != 0 && sub_8007ECC()) + if (gReceivedRemoteLinkPlayers != 0 && IsLinkTaskFinished()) { gBattleStruct->unk0 = 1; gBattleStruct->unk1 = 1; @@ -464,7 +464,7 @@ void sub_800EC9C(void) } break; case 2: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), gPlayerParty, sizeof(*gPlayerParty) * 2); gBattleCommunication[0]++; @@ -479,7 +479,7 @@ void sub_800EC9C(void) } break; case 4: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 2, sizeof(*gPlayerParty) * 2); gBattleCommunication[0]++; @@ -494,7 +494,7 @@ void sub_800EC9C(void) } break; case 6: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 4, sizeof(*gPlayerParty) * 2); gBattleCommunication[0]++; @@ -579,7 +579,7 @@ void sub_800F104(void) switch (gBattleCommunication[0]) { case 0: - if (gReceivedRemoteLinkPlayers != 0 && sub_8007ECC()) + if (gReceivedRemoteLinkPlayers != 0 && IsLinkTaskFinished()) { sub_800F02C(); SendBlock(bitmask_all_link_players_but_self(), gSharedMem, 0x60); @@ -639,7 +639,7 @@ void sub_800F298(void) switch (gBattleCommunication[0]) { case 0: - if (gReceivedRemoteLinkPlayers != 0 && sub_8007ECC()) + if (gReceivedRemoteLinkPlayers != 0 && IsLinkTaskFinished()) { gBattleStruct->unk0 = 1; gBattleStruct->unk1 = 1; @@ -732,7 +732,7 @@ void sub_800F298(void) break; case 2: step_2: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), ewram1D000, sizeof(struct Pokemon) * 2); gBattleCommunication[0]++; @@ -795,7 +795,7 @@ void sub_800F298(void) } break; case 4: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { SendBlock(bitmask_all_link_players_but_self(), ewram1D000 + 2, sizeof(struct Pokemon)); gBattleCommunication[0]++; diff --git a/src/battle/battle_transition.c b/src/battle/battle_transition.c index f7cdc0694..a94974b27 100644 --- a/src/battle/battle_transition.c +++ b/src/battle/battle_transition.c @@ -6,6 +6,7 @@ #include "palette.h" #include "trig.h" #include "field_effect.h" +#include "field_weather.h" #include "random.h" #include "sprite.h" #include "sound.h" @@ -15,7 +16,6 @@ #include "ewram.h" #include "scanline_effect.h" -void sub_807DE10(void); void ScanlineEffect_Clear(void); extern const struct OamData gFieldOamData_32x32; @@ -567,7 +567,7 @@ static void Task_BattleTransitionMain(u8 taskID) static bool8 Transition_Phase1(struct Task* task) { - sub_807DE10(); + SetWeatherScreenFadeOut(); CpuCopy32(gPlttBufferFaded, gPlttBufferUnfaded, 0x400); if (sPhase1_Tasks[task->tTransitionID] != NULL) { diff --git a/src/battle/battle_util.c b/src/battle/battle_util.c index f93664593..87b6952ff 100644 --- a/src/battle/battle_util.c +++ b/src/battle/battle_util.c @@ -4,6 +4,7 @@ #include "data2.h" #include "event_data.h" #include "ewram.h" +#include "field_weather.h" #include "item.h" #include "link.h" #include "pokemon.h" @@ -85,7 +86,6 @@ u8 CountTrailingZeroBits(u32 a); u8 GetMoveTarget(u16 move, u8 useMoveTarget); u8 sub_803FC34(u8 bank); u16 sub_803FBFC(u8 a); -u8 weather_get_current(void); void RecordAbilityBattle(u8 bank, u8 ability); void RecordItemBattle(u8 bank, u8 holdEffect); s8 GetPokeFlavourRelation(u32 pid, u8 flavor); @@ -1747,7 +1747,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) { case 0xFF: //weather from overworld //_08018586 - switch (weather_get_current()) + switch (GetCurrentWeather()) { case WEATHER_RAIN_LIGHT: case WEATHER_RAIN_MED: @@ -1781,7 +1781,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) } if (effect) { - gBattleCommunication[MULTISTRING_CHOOSER] = weather_get_current(); + gBattleCommunication[MULTISTRING_CHOOSER] = GetCurrentWeather(); BattleScriptPushCursorAndCallback(BattleScript_OverworldWeatherStarts); } break; diff --git a/src/battle/contest_link_80C857C.c b/src/battle/contest_link_80C857C.c index 616a72d27..4fb236294 100644 --- a/src/battle/contest_link_80C857C.c +++ b/src/battle/contest_link_80C857C.c @@ -1,9 +1,728 @@ #include "global.h" +#include "ewram.h" +#include "random.h" +#include "task.h" +#include "contest.h" +#include "text.h" +#include "string_util.h" #include "link.h" +static void sub_80C8644(u8 taskId); +static void sub_80C8660(u8 taskId); +#if GERMAN +static void de_sub_80C9274(bool32 arg0); +static void de_sub_80C9294(bool32 arg0); +#endif + +static void SendBlockToAllOpponents(const void *data, u16 size) +{ + memcpy(eContestLinkSendBuffer, data, size); + SendBlock(bitmask_all_link_players_but_self(), eContestLinkSendBuffer, size); +} + +static bool8 HasPlayerReceivedBlock(u8 who) +{ + u8 flag = 1 << who; + if (!(GetBlockReceivedStatus() & flag)) + return FALSE; + ResetBlockReceivedFlag(flag); + return TRUE; +} + +static bool8 HaveAllPlayersReceivedBlock(void) +{ + int i; + + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + if (!((GetBlockReceivedStatus() >> i) & 1)) + return FALSE; + } + ResetBlockReceivedFlags(); + return TRUE; +} + +void sub_80C8604(u8 taskId) +{ +#if ENGLISH + u8 i; + + for (i = 0; i < 4; i++) + gBlockRecvBuffer[i][0] = 0xff; +#endif + gTasks[taskId].data[0] = 0; + gTasks[taskId].func = sub_80C8644; +} + +static void sub_80C8644(u8 taskId) +{ + gTasks[taskId].func = sub_80C8660; +} + +static void sub_80C8660(u8 taskId) +{ + if (gReceivedRemoteLinkPlayers) + { + gContestPlayerMonIndex = GetMultiplayerId(); + if (GetLinkPlayerCount() == MAX_LINK_PLAYERS) + { + gIsLinkContest = TRUE; + SwitchTaskToFollowupFunc(taskId); + } + } +} + +#ifdef NONMATCHING +u8 sub_80C86A0(const u8 *string) +{ + u8 language = GAME_LANGUAGE; + if (string[0] == EXT_CTRL_CODE_BEGIN && string[1] == 0x15) + return language; + if (StringLength(string) > 5) + return language; + for (; *string != EOS; string++) + { + if (!((*string >= CHAR_A && *string <= CHAR_z) || + (*string >= CHAR_0 + 0 && *string <= CHAR_0 + 9) || + *string == CHAR_SPACE || + *string == CHAR_PERIOD || + *string == CHAR_COMMA || + *string == 0xAB || + *string == CHAR_QUESTION_MARK || + *string == CHAR_MALE || + *string == CHAR_FEMALE || + *string == CHAR_SLASH || + *string == CHAR_HYPHEN || + *string == CHAR_ELLIPSIS || + *string == 0xB1 || + *string == 0xB2 || + *string == 0xB3 || + *string == 0xB1 + )) + { + language = LANGUAGE_JAPANESE; + break; + } + } + return language; +} +#else +__attribute__((naked)) u8 sub_80C86A0(const u8 *string) +{ + asm_unified("\tpush {r4,r5,lr}\n" + "\tadds r4, r0, 0\n" + ".ifdef ENGLISH\n" + "\tmovs r5, 0x2\n" + ".else\n" + "\tmovs r5, 0x5\n" + ".endif\n" + "\tldrb r0, [r4]\n" + "\tcmp r0, 0xFC\n" + "\tbne _080C86B6\n" + "\tldrb r0, [r4, 0x1]\n" + "\tcmp r0, 0x15\n" + "\tbne _080C86B6\n" + ".ifdef ENGLISH\n" + "\tmovs r0, 0x2\n" + ".else\n" + "\tmovs r0, 0x5\n" + ".endif\n" + "\tb _080C872C\n" + "_080C86B6:\n" + "\tadds r0, r4, 0\n" + "\tbl StringLength\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tcmp r0, 0x5\n" + "\tbhi _080C872A\n" + "\tldrb r0, [r4]\n" + "\tcmp r0, 0xFF\n" + "\tbeq _080C872A\n" + "_080C86CA:\n" + "\tldrb r1, [r4]\n" + "\tadds r0, r1, 0\n" + "\tadds r0, 0x45\n" + "\tlsls r0, 24\n" + "\tlsrs r0, 24\n" + "\tcmp r0, 0x33\n" + "\tbls _080C871E\n" + "\tadds r0, r1, 0\n" + "\tadds r0, 0x5F\n" + "\tlsls r0, 24\n" + "\tlsrs r0, 24\n" + "\tcmp r0, 0x9\n" + "\tbls _080C871E\n" + "\tadds r0, r1, 0\n" + "\tcmp r0, 0\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xAD\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB8\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xAB\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xAC\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB5\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB6\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xBA\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xAE\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB0\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB1\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB2\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB3\n" + "\tbeq _080C871E\n" + "\tcmp r0, 0xB1\n" + "\tbne _080C8728\n" + "_080C871E:\n" + "\tadds r4, 0x1\n" + "\tldrb r0, [r4]\n" + "\tcmp r0, 0xFF\n" + "\tbne _080C86CA\n" + "\tb _080C872A\n" + "_080C8728:\n" + "\tmovs r5, 0x1\n" + "_080C872A:\n" + "\tadds r0, r5, 0\n" + "_080C872C:\n" + "\tpop {r4,r5}\n" + "\tpop {r1}\n" + "\tbx r1"); +} +#endif + +void sub_80C8734(u8 taskId) +{ + int i; + u8 *name; + + switch (gTasks[taskId].data[0]) { +#if ENGLISH + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; +#elif GERMAN + case 8: +#endif + case 0: + if (GetMultiplayerId() == 0) { + if (IsLinkTaskFinished()) { +#if ENGLISH + memcpy(gBlockSendBuffer, gContestMons + gContestPlayerMonIndex, sizeof(struct ContestPokemon)); + sub_8007E9C(2); + gTasks[taskId].data[0]++; +#elif GERMAN + if (gTasks[taskId].data[0] == 0) + { + gTasks[taskId].data[0] = 3; + } + else + { + memcpy(gBlockSendBuffer, gContestMons + gContestPlayerMonIndex, sizeof(struct ContestPokemon)); + de_sub_80C9274(FALSE); + sub_8007E9C(2); + gTasks[taskId].data[0] = 1; + } +#endif + } + } + else + { + memcpy(gBlockSendBuffer, gContestMons + gContestPlayerMonIndex, sizeof(struct ContestPokemon)); +#if GERMAN + de_sub_80C9294(FALSE); +#endif + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + memcpy(gContestMons + i, gBlockRecvBuffer[i], sizeof(struct ContestPokemon)); + name = gContestMons[i].nickname; + if (gLinkPlayers[i].language == LANGUAGE_JAPANESE) + { + ConvertInternationalString(name, sub_80C86A0(name)); + } + else if (name[10] == EXT_CTRL_CODE_BEGIN) + { + ConvertInternationalString(name, LANGUAGE_JAPANESE); + } else + { + name[5] = name[10]; + name[10] = EOS; + } + name = gContestMons[i].trainerName; + if (gLinkPlayers[i].language == LANGUAGE_JAPANESE) + { + name[7] = EOS; + name[6] = name[4]; + name[5] = name[3]; + name[4] = name[2]; + name[3] = name[1]; + name[2] = name[0]; + name[1] = 0x15; + name[0] = EXT_CTRL_CODE_BEGIN; + } + else + { + name[5] = name[7]; + name[7] = EOS; + } + } + gTasks[taskId].data[0]++; + } + break; +#if GERMAN + case 2: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + default: + gTasks[taskId].data[0]++; + break; +#endif + } +} + +void sub_80C88AC(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + case 0: + if (GetMultiplayerId() == 0) + { + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(&gRngValue, sizeof(u32)); + gTasks[taskId].data[0]++; + } + } + else + { + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HasPlayerReceivedBlock(0)) + { + memcpy(&gRngValue, gBlockRecvBuffer[0], sizeof(u32)); + memcpy(&gContestRngValue, gBlockRecvBuffer[0], sizeof(u32)); + gTasks[taskId].data[0]++; + } + break; + } +} + +void sub_80C8938(u8 taskId) +{ + int i; + + switch (gTasks[taskId].data[0]) + { +#if ENGLISH + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; +#elif GERMAN + case 8: +#endif + case 0: + gBlockSendBuffer[0] = gTasks[taskId].data[9]; + if (GetMultiplayerId() == 0) + { + if (IsLinkTaskFinished()) + { +#if ENGLISH + sub_8007E9C(2); + gTasks[taskId].data[0]++; +#elif GERMAN + if (gTasks[taskId].data[0] == 0) + { + gTasks[taskId].data[0] = 3; + } + else + { + de_sub_80C9274(TRUE); + sub_8007E9C(2); + gTasks[taskId].data[0] = 1; + } +#endif + } + } + else + { +#if GERMAN + de_sub_80C9294(TRUE); +#endif + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + gTasks[taskId].data[i + 1] = gBlockRecvBuffer[i][0]; + } + gTasks[taskId].data[0]++; + } + break; +#if GERMAN + case 2: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + default: + gTasks[taskId].data[0]++; + break; +#endif + } +} + +void sub_80C89DC(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + case 0: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(&gContestPlayerMonIndex, sizeof(u8)); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + gTasks[taskId].data[0]++; + } + break; + } +} + +void sub_80C8A38(u8 taskId) +{ + int i; + + switch (gTasks[taskId].data[0]) + { + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + case 0: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(&sContestantStatus[gContestPlayerMonIndex].currMove, sizeof(u16)); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + *&sContestantStatus[i].currMove = gBlockRecvBuffer[i][0]; + } + gTasks[taskId].data[0]++; + } + break; + } +} + +void sub_80C8AD0(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + case 0: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gUnknown_02038678, sizeof gUnknown_02038678); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gUnknown_02038678, gBlockRecvBuffer[gUnknown_0203869B], sizeof gUnknown_02038678); + gTasks[taskId].data[0]++; + } + break; + case 2: + case 5: + case 8: + case 11: + if (gTasks[taskId].data[1]++ > 10) + { + gTasks[taskId].data[1] = 0; + gTasks[taskId].data[0]++; + } + break; + case 3: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gUnknown_02038680, sizeof gUnknown_02038680); + gTasks[taskId].data[0]++; + } + break; + case 4: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gUnknown_02038680, gBlockRecvBuffer[gUnknown_0203869B], sizeof gUnknown_02038680); + gTasks[taskId].data[0]++; + } + break; + case 6: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gUnknown_02038688, sizeof gUnknown_02038688); + gTasks[taskId].data[0]++; + } + break; + case 7: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gUnknown_02038688, gBlockRecvBuffer[gUnknown_0203869B], sizeof gUnknown_02038688); + gTasks[taskId].data[0]++; + } + break; + case 9: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gContestFinalStandings, sizeof gContestFinalStandings); + gTasks[taskId].data[0]++; + } + break; + case 10: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gContestFinalStandings, gBlockRecvBuffer[gUnknown_0203869B], sizeof gContestFinalStandings); + gTasks[taskId].data[0]++; + } + break; + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + } +} + +void sub_80C8C80(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + case 0: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(sContestantStatus, 4 * sizeof(struct ContestantStatus)); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(sContestantStatus, gBlockRecvBuffer[gUnknown_0203869B], 4 * sizeof(struct ContestantStatus)); + gTasks[taskId].data[0]++; + } + break; + case 2: + case 5: + case 8: + case 11: + if (gTasks[taskId].data[1]++ > 10) + { + gTasks[taskId].data[1] = 0; + gTasks[taskId].data[0]++; + } + break; + case 3: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(&shared192D0, sizeof shared192D0); + gTasks[taskId].data[0]++; + } + break; + case 4: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(&shared192D0, gBlockRecvBuffer[gUnknown_0203869B], sizeof shared192D0); + gTasks[taskId].data[0]++; + } + break; + case 6: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(&shared19328, sizeof shared19328); + gTasks[taskId].data[0]++; + } + break; + case 7: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(&shared19328, gBlockRecvBuffer[gUnknown_0203869B], sizeof shared19328); + gTasks[taskId].data[0]++; + } + break; + case 9: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gUnknown_02038696, sizeof gUnknown_02038696); + gTasks[taskId].data[0]++; + } + break; + case 10: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gUnknown_02038696, gBlockRecvBuffer[gUnknown_0203869B], sizeof gUnknown_02038696); + gTasks[taskId].data[0]++; + } + break; + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + } +} + +void sub_80C8E1C(u8 taskId) +{ + int i; + + switch (gTasks[taskId].data[0]) + { +#if ENGLISH + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; +#elif GERMAN + case 8: +#endif + case 0: + gBlockSendBuffer[0] = 0x64; + if (GetMultiplayerId() == 0) + { + if (IsLinkTaskFinished()) + { +#if ENGLISH + sub_8007E9C(2); + gTasks[taskId].data[0]++; +#elif GERMAN + if (gTasks[taskId].data[0] == 0) + { + gTasks[taskId].data[0] = 3; + } + else + { + de_sub_80C9274(FALSE); + sub_8007E9C(2); + gTasks[taskId].data[0] = 1; + } +#endif + } + } + else + { +#if GERMAN + de_sub_80C9294(FALSE); +#endif + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + gTasks[taskId].data[5 + i] = gBlockRecvBuffer[i][0]; + } + gTasks[taskId].data[0]++; + } + break; +#if GERMAN + case 2: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + default: + gTasks[taskId].data[0]++; + break; +#endif + } +} + +void sub_80C8EBC(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + case 0: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gUnknown_02038670, sizeof gUnknown_02038670); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gUnknown_02038670, gBlockRecvBuffer[gUnknown_0203869B], sizeof gUnknown_02038670); + gTasks[taskId].data[0]++; + } + break; + } +} + +void sub_80C8F34(u8 taskId) +{ + switch (gTasks[taskId].data[0]) + { + default: + gTasks[taskId].data[0] = 0; + SwitchTaskToFollowupFunc(taskId); + break; + case 0: + if (IsLinkTaskFinished()) + { + SendBlockToAllOpponents(gUnknown_02038696, sizeof gUnknown_02038696); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (HaveAllPlayersReceivedBlock()) + { + memcpy(gUnknown_02038696, gBlockRecvBuffer[gUnknown_0203869B], sizeof gUnknown_02038696); + gTasks[taskId].data[0]++; + } + break; + } +} + #if GERMAN -void de_sub_80C9274(bool32 arg0) +static void de_sub_80C9274(bool32 arg0) { if (deUnkValue2 == 1) { @@ -14,7 +733,7 @@ void de_sub_80C9274(bool32 arg0) } } -void de_sub_80C9294(bool32 arg0) +static void de_sub_80C9294(bool32 arg0) { if (deUnkValue2 == 1) { diff --git a/src/contest.c b/src/contest.c index 93d1a8efc..ce29d80b0 100644 --- a/src/contest.c +++ b/src/contest.c @@ -59,7 +59,7 @@ extern u16 gBattle_BG0_Y; extern u16 gBattle_BG0_X; extern u16 gBattle_BG1_X; extern u16 gBattle_WIN0H; -extern u32 gUnknown_03005D28; // saved RNG value +extern u32 gContestRngValue; // saved RNG value extern struct SpriteTemplate gUnknown_02024E8C; @@ -495,7 +495,7 @@ void sub_80AB6B4(u8 taskId) GetMultiplayerId(); // unused return value DestroyTask(taskId); gTasks[sContest.mainTaskId].func = sub_80AB960; - gRngValue = gUnknown_03005D28; + gRngValue = gContestRngValue; } } @@ -1812,7 +1812,7 @@ void sub_80ADDA4(u8 taskId) sub_80AF668(); sub_80AF138(); sub_80BE23C(sContestantStatus[gContestPlayerMonIndex].prevMove); - gUnknown_03005D28 = gRngValue; + gContestRngValue = gRngValue; StringExpandPlaceholders(gStringVar4, gUnknown_083CB02C); Text_InitWindow8002EB0(&gMenuWindow, gStringVar4, 776, 1, 15); gTasks[taskId].data[2] = 0; diff --git a/src/contest_ai.c b/src/contest_ai.c index 66b387270..1e249083b 100644 --- a/src/contest_ai.c +++ b/src/contest_ai.c @@ -8,7 +8,6 @@ extern u8 AreMovesContestCombo(u16, u16); extern bool8 sub_80B214C(u8); extern bool8 Contest_IsMonsTurnDisabled(u8); -extern s16 gUnknown_02038670[]; extern u16 gSpecialVar_ContestCategory; extern u8 *gAIScriptPtr; diff --git a/src/debug/matsuda_debug_menu.c b/src/debug/matsuda_debug_menu.c index da1937adb..efd952ef7 100644 --- a/src/debug/matsuda_debug_menu.c +++ b/src/debug/matsuda_debug_menu.c @@ -18,14 +18,7 @@ #include "ewram.h" extern u8 gUnknown_0203856C; -extern s16 gUnknown_02038670[]; -extern s16 gUnknown_02038678[]; -extern s16 gUnknown_02038680[]; -extern u8 gContestFinalStandings[]; extern u8 gUnknown_02038694; -extern u8 gIsLinkContest; -extern u8 gUnknown_0203869B; -extern u8 gContestPlayerMonIndex; extern u16 gSpecialVar_ContestCategory; extern u16 gSpecialVar_ContestRank; @@ -40,8 +33,6 @@ extern u16 gBattle_BG3_Y; extern u8 (*gMenuCallback)(void); -extern bool8 gReceivedRemoteLinkPlayers; - static bool8 sub_80A9B78(void); static void sub_80A9BE4(u8 taskId); static void sub_80A9C98(u8); diff --git a/src/engine/cable_club.c b/src/engine/cable_club.c index 44d832e2b..e7c504c7b 100644 --- a/src/engine/cable_club.c +++ b/src/engine/cable_club.c @@ -676,7 +676,7 @@ static void sub_808382C(u8 taskId) switch (task->data[0]) { case 0: - fade_screen(1, 0); + FadeScreen(1, 0); gLinkType = 0x2211; ClearLinkCallback_2(); task->data[0]++; @@ -812,7 +812,7 @@ static void sub_8083AAC(u8 taskId) { case 0: ScriptContext2_Enable(); - fade_screen(1, 0); + FadeScreen(1, 0); ClearLinkCallback_2(); task->data[0]++; break; diff --git a/src/engine/link.c b/src/engine/link.c index ec94295d7..33037b817 100644 --- a/src/engine/link.c +++ b/src/engine/link.c @@ -898,14 +898,9 @@ bool8 sub_8007E9C(u8 a1) } } -bool8 sub_8007ECC(void) +bool8 IsLinkTaskFinished(void) { - u8 retVal = FALSE; - - if (!gLinkCallback) - retVal = TRUE; - - return retVal; + return gLinkCallback == NULL; } u8 GetBlockReceivedStatus(void) diff --git a/src/engine/time_events.c b/src/engine/time_events.c index 3e3054aa3..4bd732788 100644 --- a/src/engine/time_events.c +++ b/src/engine/time_events.c @@ -93,7 +93,7 @@ void UpdateShoalTideFlag(void) static void Task_WaitWeather(u8 taskId) { - if (sub_807DDFC()) + if (IsWeatherChangeComplete()) { EnableBothScriptContexts(); DestroyTask(taskId); diff --git a/src/engine/trade.c b/src/engine/trade.c index 4dc27ea6f..4bd39c4ef 100644 --- a/src/engine/trade.c +++ b/src/engine/trade.c @@ -1711,7 +1711,7 @@ static bool8 sub_8048D44(void) gUnknown_03004824->unk_0075 ++; break; case 1: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { if (GetBlockReceivedStatus() == 0) { @@ -2210,7 +2210,7 @@ static void sub_8049A20(void) { sub_804AADC(3, 1); gUnknown_03004824->linkData[0] = 0xbbbb; - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { Trade_SendData(gUnknown_03004824); } @@ -2239,7 +2239,7 @@ static void sub_8049AC0(void) else { sub_804AADC(3, 1); - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { gUnknown_03004824->linkData[0] = 0xbbcc; Trade_SendData(gUnknown_03004824); @@ -4632,7 +4632,7 @@ static void sub_804BB78(void) switch (gUnknown_03004828->unk_00bd) { case 1: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { Trade_SendData(gUnknown_03004828); gUnknown_03004828->unk_00bd ++; @@ -5534,13 +5534,13 @@ static void sub_804DC88(void) gMain.state = 101; gUnknown_03004828->unk_00c0 = 0; } - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { gMain.state = 2; } break; case 101: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { gMain.state = 2; } @@ -5592,7 +5592,7 @@ static void sub_804DC88(void) gMain.state = 42; break; case 42: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { sub_8125E04(); gSoftResetDisabled = FALSE; @@ -5607,7 +5607,7 @@ static void sub_804DC88(void) } break; case 6: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { BeginNormalPaletteFade(-1, 0, 0, 16, 0); gMain.state ++; diff --git a/src/field/choose_party.c b/src/field/choose_party.c index 3ba04e489..18d26f007 100644 --- a/src/field/choose_party.c +++ b/src/field/choose_party.c @@ -930,7 +930,7 @@ void sub_81231AC(void) static void sub_81231C4(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { DestroyTask(taskId); ScriptContext2_Disable(); diff --git a/src/field/coord_event_weather.c b/src/field/coord_event_weather.c index db4e9c161..60b87fa30 100644 --- a/src/field/coord_event_weather.c +++ b/src/field/coord_event_weather.c @@ -34,7 +34,7 @@ static const struct CoordEventWeather sCoordEventWeatherFuncs[] = { COORD_EVENT_WEATHER_FOG_2, CoordEventWeather_DiagonalFog }, { COORD_EVENT_WEATHER_ASH, CoordEventWeather_Ash }, { COORD_EVENT_WEATHER_SANDSTORM, CoordEventWeather_Sandstorm }, - { COORD_EVENT_WEATHER_DARK, CoordEventWeather_Dark }, + { COORD_EVENT_WEATHER_SHADE, CoordEventWeather_Dark }, { COORD_EVENT_WEATHER_DROUGHT, CoordEventWeather_Drought }, { COORD_EVENT_WEATHER_ROUTE119_CYCLE, CoordEventWeather_Route119Cycle }, { COORD_EVENT_WEATHER_ROUTE123_CYCLE, CoordEventWeather_Route123Cycle }, @@ -87,7 +87,7 @@ static void CoordEventWeather_Sandstorm(void) static void CoordEventWeather_Dark(void) { - SetWeather(WEATHER_DARK); + SetWeather(WEATHER_SHADE); } static void CoordEventWeather_Drought(void) diff --git a/src/field/decoration.c b/src/field/decoration.c index e1604cfa1..0e7fa5f41 100644 --- a/src/field/decoration.c +++ b/src/field/decoration.c @@ -2239,7 +2239,7 @@ void sub_80FF5BC(u8 taskId) { if (sub_80FF58C() == TRUE) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_80FF6AC; } else @@ -2289,7 +2289,7 @@ void sub_80FF6AC(u8 taskId) gTasks[taskId].data[2] = 2; break; case 2: - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].data[12] = 0; sub_810065C(taskId); @@ -3193,7 +3193,7 @@ void sub_810026C(u8 taskId) void sub_810028C(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = c1_overworld_prev_quest; } @@ -3222,7 +3222,7 @@ void c1_overworld_prev_quest(u8 taskId) void sub_8100334(u8 taskId) { - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].func = sub_80FE948; } @@ -3629,7 +3629,7 @@ void sub_8100A0C(u8 taskId) { if (sub_8100D38(taskId) == 1) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8100E70; } else @@ -3735,7 +3735,7 @@ void sub_8100C88(u8 taskId) gTasks[taskId].data[2] = 3; break; case 3: - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].data[13] = -1; DisplayItemMessageOnField(taskId, gSecretBaseText_DecorReturned, sub_81010F0, 0); @@ -3800,7 +3800,7 @@ void sub_8100E70(u8 taskId) data[2] = 2; break; case 2: - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { data[12] = 1; sub_8100EEC(taskId); @@ -4138,7 +4138,7 @@ void sub_8101518(u8 taskId) void sub_810153C(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8100C88; } @@ -4157,7 +4157,7 @@ void sub_8101590(u8 taskId) void sub_81015B0(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_81015E0; } @@ -4184,7 +4184,7 @@ void sub_81015E0(u8 taskId) void sub_8101648(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].func = Task_DecorationPCProcessMenuInput; } diff --git a/src/field/field_control_avatar.c b/src/field/field_control_avatar.c index c156df035..bf96c724f 100644 --- a/src/field/field_control_avatar.c +++ b/src/field/field_control_avatar.c @@ -767,20 +767,19 @@ static u8 *trigger_activate(struct CoordEvent *coordEvent) return NULL; } -static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 x, u16 y, u8 d) +static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) { s32 i; struct CoordEvent *coordEvents = mapHeader->events->coordEvents; u8 coordEventCount = mapHeader->events->coordEventCount; - u8 *script; for (i = 0; i < coordEventCount; i++) { if ((u16)coordEvents[i].x == x && (u16)coordEvents[i].y == y) { - if (coordEvents[i].unk4 == d || coordEvents[i].unk4 == 0) + if (coordEvents[i].elevation == elevation || coordEvents[i].elevation == 0) { - script = trigger_activate(&coordEvents[i]); + u8 *script = trigger_activate(&coordEvents[i]); if (script != NULL) return script; } diff --git a/src/field/field_effect.c b/src/field/field_effect.c index 384da4bd2..deddf790e 100644 --- a/src/field/field_effect.c +++ b/src/field/field_effect.c @@ -405,7 +405,7 @@ void FieldEffectScript_LoadFadedPalette(u8 **script) { struct SpritePalette *palette = (struct SpritePalette *)FieldEffectScript_ReadWord(script); LoadSpritePalette(palette); - sub_807D78C(IndexOfSpritePaletteTag(palette->tag)); + UpdateSpritePaletteWithWeather(IndexOfSpritePaletteTag(palette->tag)); (*script) += 4; } @@ -541,7 +541,7 @@ u8 CreateMonSprite_PicBox(u16 species, s16 x, s16 y, u8 subpriority) LoadCompressedObjectPalette(&gMonPaletteTable[species]); GetMonSpriteTemplate_803C56C(species, 3); gUnknown_02024E8C.paletteTag = gMonPaletteTable[0].tag; - sub_807DE38(IndexOfSpritePaletteTag(gMonPaletteTable[0].tag) + 0x10); + PreservePaletteInWeather(IndexOfSpritePaletteTag(gMonPaletteTable[0].tag) + 0x10); return CreateSprite(&gUnknown_02024E8C, x, y, subpriority); } @@ -554,13 +554,13 @@ u8 CreateMonSprite_FieldMove(u16 species, u32 d, u32 g, s16 x, s16 y, u8 subprio LoadCompressedObjectPalette(spritePalette); GetMonSpriteTemplate_803C56C(species, 3); gUnknown_02024E8C.paletteTag = spritePalette->tag; - sub_807DE38(IndexOfSpritePaletteTag(spritePalette->tag) + 0x10); + PreservePaletteInWeather(IndexOfSpritePaletteTag(spritePalette->tag) + 0x10); return CreateSprite(&gUnknown_02024E8C, x, y, subpriority); } void FreeResourcesAndDestroySprite(struct Sprite *sprite) { - sub_807DE68(); + ResetPreservedPalettesInWeather(); FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(sprite->oam.paletteNum)); if (sprite->oam.affineMode != 0) { @@ -1089,7 +1089,7 @@ void task00_8084310(u8 taskId) task = &gTasks[taskId]; if (!task->data[0]) { - if (!sub_807D770()) + if (!IsWeatherNotFadingIn()) { return; } @@ -1189,7 +1189,7 @@ bool8 sub_80867AC(struct Task *task) // gUnknown_0839F2CC[0] bool8 sub_8086854(struct Task *task) // gUnknown_0839F2CC[1] { - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { task->data[0]++; } @@ -1811,7 +1811,7 @@ bool8 sub_80874CC(struct Task *task, struct MapObject *mapObject, struct Sprite bool8 sub_80874FC(struct Task *task, struct MapObject *mapObject, struct Sprite *sprite) { - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { gFieldEffectArguments[0] = mapObject->coords2.x; gFieldEffectArguments[1] = mapObject->coords2.y; @@ -2044,7 +2044,7 @@ void sub_8087A74(u8 taskId) void sub_8087AA4(struct Task *task) { - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { task->data[0]++; task->data[15] = player_get_direction_lower_nybble(); @@ -2197,7 +2197,7 @@ void sub_8087E4C(struct Task *task) { struct Sprite *sprite; s16 centerToCornerVecY; - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { sprite = &gSprites[gPlayerAvatar.spriteId]; centerToCornerVecY = -(sprite->centerToCornerVecY << 1); diff --git a/src/field/field_effect_helpers.c b/src/field/field_effect_helpers.c index 3e1fb1c13..2889ee954 100644 --- a/src/field/field_effect_helpers.c +++ b/src/field/field_effect_helpers.c @@ -93,7 +93,7 @@ static void npc_pal_op_B(struct MapObject *mapObject, u8 paletteNum) { pal_patch_for_npc(npc_paltag_by_palslot(paletteNum), paletteNum); } - sub_807D78C(paletteNum); + UpdateSpritePaletteWithWeather(paletteNum); } } @@ -105,7 +105,7 @@ static void npc_pal_op_A(struct MapObject *mapObject, u8 paletteNum) if (graphicsInfo->paletteTag2 != 0x11ff) { pal_patch_for_npc(graphicsInfo->paletteTag2, paletteNum); - sub_807D78C(paletteNum); + UpdateSpritePaletteWithWeather(paletteNum); } } diff --git a/src/field/field_fadetransition.c b/src/field/field_fadetransition.c index 4350f7960..f0e7517e5 100644 --- a/src/field/field_fadetransition.c +++ b/src/field/field_fadetransition.c @@ -43,18 +43,18 @@ void pal_fill_for_map_transition(void) switch (fade_type_for_given_maplight_pair(map_light, Overworld_GetMapTypeOfSaveblockLocation())) { case 0: - fade_screen(0, 0); + FadeScreen(0, 0); palette_bg_fill_black(); break; case 1: - fade_screen(2, 0); + FadeScreen(2, 0); palette_bg_fill_white(); } } void pal_fill_black(void) { - fade_screen(0, 0); + FadeScreen(0, 0); palette_bg_fill_black(); } @@ -64,10 +64,10 @@ void fade_8080918(void) switch (sub_810CDB8(light_level, warp1_get_mapheader()->mapType)) { case 0: - fade_screen(1, 0); + FadeScreen(1, 0); break; case 1: - fade_screen(3, 0); + FadeScreen(3, 0); } } @@ -145,7 +145,7 @@ void sub_8080A5C(u8 taskId) task->data[0]++; break; case 1: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { pal_fill_for_map_transition(); task->data[0]++; @@ -365,7 +365,7 @@ bool32 sub_8080E64(void) bool32 sub_8080E70(void) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) return TRUE; else return FALSE; @@ -482,7 +482,7 @@ void sub_8081050(u8 taskId) { case 0: ClearLinkCallback_2(); - fade_screen(1, 0); + FadeScreen(1, 0); sub_8053FF8(); PlaySE(SE_KAIDAN); data[0]++; diff --git a/src/field/field_weather.c b/src/field/field_weather.c index 3053c58cb..ceb23b629 100644 --- a/src/field/field_weather.c +++ b/src/field/field_weather.c @@ -13,7 +13,13 @@ #include "trig.h" #include "ewram.h" -#define MACRO1(a) ((((a) >> 1) & 0xF) | (((a) >> 2) & 0xF0) | (((a) >> 3) & 0xF00)) +#define MACRO1(color) ((((color) >> 1) & 0xF) | (((color) >> 2) & 0xF0) | (((color) >> 3) & 0xF00)) + +enum { + GAMMA_NONE, + GAMMA_NORMAL, + GAMMA_ALT, +}; struct RGBColor { @@ -24,7 +30,7 @@ struct RGBColor struct WeatherPaletteData { - u16 data[0][0x1000]; // unknown length + u16 gammaShiftColors[8][0x1000]; // 0x1000 is the number of bytes that make up all palettes. }; struct WeatherCallbacks @@ -36,10 +42,10 @@ struct WeatherCallbacks }; EWRAM_DATA struct Weather gWeather = {0}; -EWRAM_DATA u8 gUnknown_0202FF38[32] = {0}; +EWRAM_DATA u8 gFieldEffectPaletteGammaTypes[32] = {0}; EWRAM_DATA u16 gUnknown_0202FF58 = {0}; -static const u8 *gUnknown_030006DC; +static const u8 *sPaletteGammaTypes; const u8 DroughtPaletteData_0[] = INCBIN_U8("graphics/weather/drought0.bin.lz"); const u8 DroughtPaletteData_1[] = INCBIN_U8("graphics/weather/drought1.bin.lz"); @@ -56,7 +62,7 @@ static const u8 *const sCompressedDroughtPalettes[] = DroughtPaletteData_3, DroughtPaletteData_4, DroughtPaletteData_5, - gSharedMem, + (u8*)eDroughtPaletteData.gammaShiftColors, }; // This is a pointer to gWeather. All code in this file accesses gWeather directly, @@ -65,6 +71,18 @@ static const u8 *const sCompressedDroughtPalettes[] = // this file produces the same result as accessing gWeather directly. struct Weather *const gWeatherPtr = &gWeather; +static bool8 LightenSpritePaletteInFog(u8); +static void BuildGammaShiftTables(void); +static void UpdateWeatherGammaShift(void); +static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex); +static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor); +static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor); +static void ApplyFogBlend(u8 blendCoeff, u16 blendColor); +static bool8 FadeInScreen_RainShowShade(void); +static bool8 FadeInScreen_Drought(void); +static bool8 FadeInScreen_Fog1(void); +static void FadeInScreenWithWeather(void); +static void DoNothing(void); void None_Init(void); void None_Main(void); bool8 None_Finish(void); @@ -108,10 +126,10 @@ void Fog1_InitVars(void); void Fog1_Main(void); void Fog1_InitAll(void); bool8 Fog1_Finish(void); -void Weather11_InitVars(void); -void Weather11_Main(void); -void Weather11_InitAll(void); -bool8 Weather11_Finish(void); +void Shade_InitVars(void); +void Shade_Main(void); +void Shade_InitAll(void); +bool8 Shade_Finish(void); void Drought_InitVars(void); void Drought_Main(void); void Drought_InitAll(void); @@ -130,7 +148,7 @@ static const struct WeatherCallbacks sWeatherFuncs[] = {None_Init, None_Main, None_Init, None_Finish}, {Clouds_InitVars, Clouds_Main, Clouds_InitAll, Clouds_Finish}, {Weather2_InitVars, Weather2_Main, Weather2_InitAll, Weather2_Finish}, - {LightRain_InitVars, LightRain_Main, LightRain_InitAll, LightRain_Finish}, // light rain + {LightRain_InitVars, LightRain_Main, LightRain_InitAll, LightRain_Finish}, {Snow_InitVars, Snow_Main, Snow_InitAll, Snow_Finish}, {MedRain_InitVars, Rain_Main, MedRain_InitAll, Rain_Finish}, {Fog1_InitVars, Fog1_Main, Fog1_InitAll, Fog1_Finish}, @@ -138,54 +156,58 @@ static const struct WeatherCallbacks sWeatherFuncs[] = {Sandstorm_InitVars, Sandstorm_Main, Sandstorm_InitAll, Sandstorm_Finish}, {Fog2_InitVars, Fog2_Main, Fog2_InitAll, Fog2_Finish}, {Fog1_InitVars, Fog1_Main, Fog1_InitAll, Fog1_Finish}, - {Weather11_InitVars, Weather11_Main, Weather11_InitAll, Weather11_Finish}, + {Shade_InitVars, Shade_Main, Shade_InitAll, Shade_Finish}, {Drought_InitVars, Drought_Main, Drought_InitAll, Drought_Finish}, {HeavyRain_InitVars, Rain_Main, HeavyRain_InitAll, Rain_Finish}, {Bubbles_InitVars, Bubbles_Main, Bubbles_InitAll, Bubbles_Finish}, }; -void (*const gUnknown_083970B8[])(void) = +void (*const gWeatherPalStateFuncs[])(void) = { - sub_807CC24, - sub_807CCAC, - nullsub_39, - nullsub_39, + UpdateWeatherGammaShift, // WEATHER_PAL_STATE_CHANGING_WEATHER + FadeInScreenWithWeather, // WEATHER_PAL_STATE_SCREEN_FADING_IN + DoNothing, // WEATHER_PAL_STATE_SCREEN_FADING_OUT + DoNothing, // WEATHER_PAL_STATE_IDLE }; -const u8 gUnknown_083970C8[] = +// This table specifies which of the gamma shift tables should be +// applied to each of the background and sprite palettes. +static const u8 sBasePaletteGammaTypes[32] = { - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 0, - 0, - 2, - 1, - 2, - 2, - 2, - 2, - 1, - 1, - 1, - 1, - 2, - 1, - 1, - 1, - 1, - 1, + // background palettes + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NONE, + GAMMA_NONE, + // sprite palettes + GAMMA_ALT, + GAMMA_NORMAL, + GAMMA_ALT, + GAMMA_ALT, + GAMMA_ALT, + GAMMA_ALT, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_ALT, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, }; const u16 gUnknown_083970E8[] = INCBIN_U16("graphics/weather/0.gbapal"); @@ -193,13 +215,14 @@ const u16 gUnknown_083970E8[] = INCBIN_U16("graphics/weather/0.gbapal"); void StartWeather(void) { u8 index; + if (!FuncIsActiveTask(Task_WeatherMain)) { index = AllocSpritePalette(0x1200); CpuCopy32(gUnknown_083970E8, &gPlttBufferUnfaded[0x100 + index * 16], 32); - sub_807CB10(); - gWeatherPtr->unknown_6D5 = index; - gWeatherPtr->unknown_6D4 = AllocSpritePalette(0x1201); + BuildGammaShiftTables(); + gWeatherPtr->altGammaSpritePalIndex = index; + gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(0x1201); gWeatherPtr->rainSpriteCount = 0; gWeatherPtr->unknown_6D8 = 0; gWeatherPtr->cloudSpritesCreated = 0; @@ -210,49 +233,53 @@ void StartWeather(void) gWeatherPtr->sandstormSprites1Created = 0; gWeatherPtr->sandstormSprites2Created = 0; gWeatherPtr->unknown_72E = 0; - gWeatherPtr->unknown_6FA = 0; + gWeatherPtr->lightenedFogSpritePalsCount = 0; Weather_SetBlendCoeffs(16, 0); gWeatherPtr->currWeather = 0; - gWeatherPtr->unknown_6C6 = 3; - gWeatherPtr->unknown_6C8 = 0; - gWeatherPtr->unknown_6D3 = 1; - gWeatherPtr->unknown_6C9 = CreateTask(Task_WeatherInit, 80); + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; + gWeatherPtr->readyForInit = FALSE; + gWeatherPtr->weatherChangeComplete = TRUE; + gWeatherPtr->taskId = CreateTask(Task_WeatherInit, 80); } } -void DoWeatherEffect(u8 effect) +void ChangeWeather(u8 weather) { - if (effect != WEATHER_RAIN_LIGHT && effect != WEATHER_RAIN_MED && effect != WEATHER_RAIN_HEAVY) + if (weather != WEATHER_RAIN_LIGHT && weather != WEATHER_RAIN_MED && weather != WEATHER_RAIN_HEAVY) { PlayRainSoundEffect(); } - if (gWeatherPtr->nextWeather != effect && gWeatherPtr->currWeather == effect) + + if (gWeatherPtr->nextWeather != weather && gWeatherPtr->currWeather == weather) { - sWeatherFuncs[effect].initVars(); + sWeatherFuncs[weather].initVars(); } - gWeatherPtr->unknown_6D3 = 0; - gWeatherPtr->nextWeather = effect; + + gWeatherPtr->weatherChangeComplete = FALSE; + gWeatherPtr->nextWeather = weather; gWeatherPtr->finishStep = 0; } -void sub_807C988(u8 effect) +void sub_807C988(u8 weather) { PlayRainSoundEffect(); - gWeatherPtr->currWeather = effect; - gWeatherPtr->nextWeather = effect; + gWeatherPtr->currWeather = weather; + gWeatherPtr->nextWeather = weather; } -void sub_807C9B4(u8 effect) +void sub_807C9B4(u8 weather) { PlayRainSoundEffect(); - gWeatherPtr->currWeather = effect; - gWeatherPtr->nextWeather = effect; - gWeatherPtr->unknown_6C8 = 1; + gWeatherPtr->currWeather = weather; + gWeatherPtr->nextWeather = weather; + gWeatherPtr->readyForInit = TRUE; } void Task_WeatherInit(u8 taskId) { - if (gWeatherPtr->unknown_6C8) + // Waits until it's ok to initialize weather. + // When the screen fades in, this is set to TRUE. + if (gWeatherPtr->readyForInit) { sWeatherFuncs[gWeatherPtr->currWeather].initAll(); gTasks[taskId].func = Task_WeatherMain; @@ -265,24 +292,26 @@ void Task_WeatherMain(u8 taskId) { if (!sWeatherFuncs[gWeatherPtr->currWeather].finish()) { + // Finished cleaning up previous weather. Now transition to next weather. sWeatherFuncs[gWeatherPtr->nextWeather].initVars(); - gWeatherPtr->unknown_6C3 = 0; - gWeatherPtr->unknown_6C6 = 0; + gWeatherPtr->gammaStepFrameCounter = 0; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER; gWeatherPtr->currWeather = gWeatherPtr->nextWeather; - gWeatherPtr->unknown_6D3 = 1; + gWeatherPtr->weatherChangeComplete = TRUE; } } else { sWeatherFuncs[gWeatherPtr->currWeather].main(); } - gUnknown_083970B8[gWeatherPtr->unknown_6C6](); + + gWeatherPalStateFuncs[gWeatherPtr->palProcessingState](); } void None_Init(void) { - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 0; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 0; } void None_Main(void) @@ -294,7 +323,10 @@ u8 None_Finish(void) return 0; } -void sub_807CB10(void) +// Builds two tables that contain gamma shifts for palette colors. +// It's unclear why the two tables aren't declared as const arrays, since +// this function always builds the same two tables. +static void BuildGammaShiftTables(void) { u16 v0; u8 (*v1)[32]; @@ -307,15 +339,15 @@ void sub_807CB10(void) u16 v11; s16 dunno; - gUnknown_030006DC = gUnknown_083970C8; + sPaletteGammaTypes = sBasePaletteGammaTypes; for (v0 = 0; v0 <= 1; v0++) { if (v0 == 0) - v1 = gWeatherPtr->unknown_200; + v1 = gWeatherPtr->gammaShifts; else - v1 = gWeatherPtr->unk460; + v1 = gWeatherPtr->altGammaShifts; - for (v2 = 0; (u16)v2 <= 0x1f; v2++) + for (v2 = 0; v2 < 32; v2++) { v4 = v2 << 8; if (v0 == 0) @@ -334,88 +366,86 @@ void sub_807CB10(void) v10 += 0xf; } v11 = v10 >> 4; - if (v2 <= 0xb) + if (v2 < 12) { - for (; v6 <= 0x12; v6++) + for (; v6 < 19; v6++) { v4 += v11; dunno = v4 - v9; if (dunno > 0) - { v4 -= (dunno + ((u16)dunno >> 15)) >> 1; - } v1[v6][v2] = v4 >> 8; if (v1[v6][v2] > 0x1f) - { v1[v6][v2] = 0x1f; - } } } else { - for (; v6 <= 0x12; v6++) + for (; v6 < 19; v6++) { v4 += v11; v1[v6][v2] = v4 >> 8; if (v1[v6][v2] > 0x1f) - { v1[v6][v2] = 0x1f; - } } } } } } -void sub_807CC24(void) +// When the weather is changing, it gradually updates the palettes +// towards the desired gamma shift. +static void UpdateWeatherGammaShift(void) { - if (gWeatherPtr->unknown_6C0 == gWeatherPtr->unknown_6C1) + if (gWeatherPtr->gammaIndex == gWeatherPtr->gammaTargetIndex) { - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } else { - if (++gWeatherPtr->unknown_6C3 >= gWeatherPtr->unknown_6C2) + if (++gWeatherPtr->gammaStepFrameCounter >= gWeatherPtr->gammaStepDelay) { - gWeatherPtr->unknown_6C3 = 0; - if (gWeatherPtr->unknown_6C0 < gWeatherPtr->unknown_6C1) - gWeatherPtr->unknown_6C0++; + gWeatherPtr->gammaStepFrameCounter = 0; + if (gWeatherPtr->gammaIndex < gWeatherPtr->gammaTargetIndex) + gWeatherPtr->gammaIndex++; else - gWeatherPtr->unknown_6C0--; - sub_807CEBC(0, 0x20, gWeatherPtr->unknown_6C0); + gWeatherPtr->gammaIndex--; + + ApplyGammaShift(0, 32, gWeatherPtr->gammaIndex); } } } -void sub_807CCAC(void) +static void FadeInScreenWithWeather(void) { if (++gWeatherPtr->unknown_6CB > 1) gWeatherPtr->unknown_6CA = 0; + switch (gWeatherPtr->currWeather) { case WEATHER_RAIN_LIGHT: case WEATHER_RAIN_MED: case WEATHER_RAIN_HEAVY: case WEATHER_SNOW: - case WEATHER_DARK: - if (sub_807CDC4() == 0) + case WEATHER_SHADE: + if (FadeInScreen_RainShowShade() == FALSE) { - gWeatherPtr->unknown_6C0 = 3; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = 3; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; case WEATHER_DROUGHT: - if (sub_807CE24() == 0) + if (FadeInScreen_Drought() == FALSE) { - gWeatherPtr->unknown_6C0 = -6; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = -6; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; case WEATHER_FOG_1: - if (sub_807CE7C() == 0) + if (FadeInScreen_Fog1() == FALSE) { - gWeatherPtr->unknown_6C0 = 0; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = 0; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; case WEATHER_ASH: @@ -425,71 +455,78 @@ void sub_807CCAC(void) default: if (!gPaletteFade.active) { - gWeatherPtr->unknown_6C0 = gWeatherPtr->unknown_6C1; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = gWeatherPtr->gammaTargetIndex; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; } } -u8 sub_807CDC4(void) +bool8 FadeInScreen_RainShowShade(void) { - if (gWeatherPtr->unknown_6C7 == 0x10) - return 0; - if (++gWeatherPtr->unknown_6C7 >= 0x10) + if (gWeatherPtr->fadeScreenCounter == 16) + return FALSE; + + if (++gWeatherPtr->fadeScreenCounter >= 16) { - sub_807CEBC(0, 0x20, 3); - gWeatherPtr->unknown_6C7 = 0x10; - return 0; + ApplyGammaShift(0, 32, 3); + gWeatherPtr->fadeScreenCounter = 16; + return FALSE; } - sub_807D1BC(0, 0x20, 3, 0x10 - gWeatherPtr->unknown_6C7, gWeatherPtr->unknown_6C4); - return 1; + + ApplyGammaShiftWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); + return TRUE; } -u8 sub_807CE24(void) +bool8 FadeInScreen_Drought(void) { - if (gWeatherPtr->unknown_6C7 == 0x10) - return 0; - if (++gWeatherPtr->unknown_6C7 >= 0x10) + if (gWeatherPtr->fadeScreenCounter == 16) + return FALSE; + + if (++gWeatherPtr->fadeScreenCounter >= 16) { - sub_807CEBC(0, 0x20, -6); - gWeatherPtr->unknown_6C7 = 0x10; - return 0; + ApplyGammaShift(0, 32, -6); + gWeatherPtr->fadeScreenCounter = 16; + return FALSE; } - sub_807D304(-6, 0x10 - gWeatherPtr->unknown_6C7, gWeatherPtr->unknown_6C4); - return 1; -} -u8 sub_807CE7C(void) -{ - if (gWeatherPtr->unknown_6C7 == 0x10) - return 0; - ++gWeatherPtr->unknown_6C7; - sub_807D424(0x10 - gWeatherPtr->unknown_6C7, gWeatherPtr->unknown_6C4); - return 1; + ApplyDroughtGammaShiftWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); + return TRUE; } -void nullsub_39(void) +bool8 FadeInScreen_Fog1(void) { + if (gWeatherPtr->fadeScreenCounter == 16) + return FALSE; + + gWeatherPtr->fadeScreenCounter++; + ApplyFogBlend(16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); + return TRUE; } -void sub_807CEBC(u8 a, u8 b, s8 c) +static void DoNothing(void) +{ } + +static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex) { - u16 r4; + u16 curPalIndex; u16 palOffset; - u8 *r6; + u8 *gammaTable; u16 i; - if (c > 0) + if (gammaIndex > 0) { - c = c - 1; - palOffset = a * 16; - b += a; - r4 = a; - while (r4 < b) + gammaIndex--; + palOffset = startPalIndex * 16; + numPalettes += startPalIndex; + curPalIndex = startPalIndex; + + // Loop through the speficied palette range and apply necessary gamma shifts to the colors. + while (curPalIndex < numPalettes) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { + // No palette change. CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); palOffset += 16; } @@ -497,25 +534,27 @@ void sub_807CEBC(u8 a, u8 b, s8 c) { u8 r, g, b; - if (gUnknown_030006DC[r4] == 2 || r4 - 16 == gWeatherPtr->unknown_6D5) - r6 = gWeatherPtr->unk460[c]; + if (sPaletteGammaTypes[curPalIndex] == GAMMA_ALT || curPalIndex - 16 == gWeatherPtr->altGammaSpritePalIndex) + gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; else - r6 = gWeatherPtr->unknown_200[c]; - if (r4 == 16 || r4 > 0x1B) + gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; + + if (curPalIndex == 16 || curPalIndex > 27) { for (i = 0; i < 16; i++) { - if (gPlttBufferUnfaded[palOffset] == 0x2D9F) + if (gPlttBufferUnfaded[palOffset] == RGB(31, 12, 11)) { + // Skip gamma shift for this specific color. (Why?) palOffset++; } else { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; - - r = r6[color.r]; - g = r6[color.g]; - b = r6[color.b]; + // Apply gamma shift to the original color. + struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; + r = gammaTable[baseColor.r]; + g = gammaTable[baseColor.g]; + b = gammaTable[baseColor.b]; gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; } } @@ -524,39 +563,45 @@ void sub_807CEBC(u8 a, u8 b, s8 c) { for (i = 0; i < 16; i++) { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; - - r = r6[color.r]; - g = r6[color.g]; - b = r6[color.b]; + // Apply gamma shift to the original color. + struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; + r = gammaTable[baseColor.r]; + g = gammaTable[baseColor.g]; + b = gammaTable[baseColor.b]; gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; } } } - r4++; + + curPalIndex++; } } - else if (c < 0) + else if (gammaIndex < 0) { - c = -c - 1; - palOffset = a * 16; - b += a; - r4 = a; - while (r4 < b) + // A negative gammIndex value means that the blending will come from the special Drought weather's palette tables. + gammaIndex = -gammaIndex - 1; + palOffset = startPalIndex * 16; + numPalettes += startPalIndex; + curPalIndex = startPalIndex; + + while (curPalIndex < numPalettes) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { + // No palette change. CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); palOffset += 16; } else { - if (r4 == 16 || r4 > 0x1B) + if (curPalIndex == 16 || curPalIndex > 27) { for (i = 0; i < 16; i++) { - if (gPlttBufferUnfaded[palOffset] != 0x2D9F) - gPlttBufferFaded[palOffset] = eWeatherPaletteData.data[c][MACRO1(gPlttBufferUnfaded[palOffset])]; + // Skip gamma shift for this specific color. (Why?) + if (gPlttBufferUnfaded[palOffset] != RGB(31, 12, 11)) + gPlttBufferFaded[palOffset] = eDroughtPaletteData.gammaShiftColors[gammaIndex][MACRO1(gPlttBufferUnfaded[palOffset])]; + palOffset++; } } @@ -564,93 +609,100 @@ void sub_807CEBC(u8 a, u8 b, s8 c) { for (i = 0; i < 16; i++) { - gPlttBufferFaded[palOffset] = eWeatherPaletteData.data[c][MACRO1(gPlttBufferUnfaded[palOffset])]; + gPlttBufferFaded[palOffset] = eDroughtPaletteData.gammaShiftColors[gammaIndex][MACRO1(gPlttBufferUnfaded[palOffset])]; palOffset++; } } } - r4++; + + curPalIndex++; } } else { - CpuFastCopy(gPlttBufferUnfaded + a * 16, gPlttBufferFaded + a * 16, b * 16 * sizeof(u16)); + // No palette blending. + CpuFastCopy(gPlttBufferUnfaded + startPalIndex * 16, gPlttBufferFaded + startPalIndex * 16, numPalettes * 16 * sizeof(u16)); } } -void sub_807D1BC(u8 a1, u8 a2, s8 c, u8 d, u16 e) +static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor) { u16 palOffset; - u16 r4; + u16 curPalIndex; u16 i; - struct RGBColor color = *(struct RGBColor *)&e; - u8 r_ = color.r; - u8 g_ = color.g; - u8 b_ = color.b; - - palOffset = a1 * 16; - a2 += a1; - c = c - 1; - r4 = a1; - while (r4 < a2) + struct RGBColor color = *(struct RGBColor *)&blendColor; + u8 rBlend = color.r; + u8 gBlend = color.g; + u8 bBlend = color.b; + + palOffset = startPalIndex * 16; + numPalettes += startPalIndex; + gammaIndex--; + curPalIndex = startPalIndex; + + while (curPalIndex < numPalettes) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { - BlendPalette(palOffset, 16, d, e); + // No gamma shift. Simply blend the colors. + BlendPalette(palOffset, 16, blendCoeff, blendColor); palOffset += 16; } else { - u8 *r5; + u8 *gammaTable; - if (gUnknown_030006DC[r4] == 1) - r5 = gWeatherPtr->unknown_200[c]; + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NORMAL) + gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; else - r5 = gWeatherPtr->unk460[c]; + gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; for (i = 0; i < 16; i++) { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; - u8 r = r5[color.r]; - u8 g = r5[color.g]; - u8 b = r5[color.b]; - - r += ((r_ - r) * d) >> 4; - g += ((g_ - g) * d) >> 4; - b += ((b_ - b) * d) >> 4; + struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; + u8 r = gammaTable[baseColor.r]; + u8 g = gammaTable[baseColor.g]; + u8 b = gammaTable[baseColor.b]; + + // Apply gamma shift and target blend color to the original color. + r += ((rBlend - r) * blendCoeff) >> 4; + g += ((gBlend - g) * blendCoeff) >> 4; + b += ((bBlend - b) * blendCoeff) >> 4; gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; } } - r4++; + + curPalIndex++; } } -void sub_807D304(s8 a, u8 coeff, u16 c) +void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor) { struct RGBColor color; - u8 r_; - u8 g_; - u8 b_; - u16 r4; + u8 rBlend; + u8 gBlend; + u8 bBlend; + u16 curPalIndex; u16 palOffset; - u16 r12; + u16 i; - a = -a - 1; - color = *(struct RGBColor *)&c; - r_ = color.r; - g_ = color.g; - b_ = color.b; + gammaIndex = -gammaIndex - 1; + color = *(struct RGBColor *)&blendColor; + rBlend = color.r; + gBlend = color.g; + bBlend = color.b; palOffset = 0; - for (r4 = 0; r4 < 32; r4++) + for (curPalIndex = 0; curPalIndex < 32; curPalIndex++) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { - BlendPalette(palOffset, 16, coeff, c); + // No gamma shift. Simply blend the colors. + BlendPalette(palOffset, 16, blendCoeff, blendColor); palOffset += 16; } else { - for (r12 = 0; r12 < 16; r12++) + for (i = 0; i < 16; i++) { u32 offset; struct RGBColor color1; @@ -664,14 +716,14 @@ void sub_807D304(s8 a, u8 coeff, u16 c) b1 = color1.b; offset = ((b1 & 0x1E) << 7) | ((g1 & 0x1E) << 3) | ((r1 & 0x1E) >> 1); - color2 = *(struct RGBColor *)&eWeatherPaletteData.data[a][offset]; + color2 = *(struct RGBColor *)&eDroughtPaletteData.gammaShiftColors[gammaIndex][offset]; r2 = color2.r; g2 = color2.g; b2 = color2.b; - r2 += ((r_ - r2) * coeff) >> 4; - g2 += ((g_ - g2) * coeff) >> 4; - b2 += ((b_ - b2) * coeff) >> 4; + r2 += ((rBlend - r2) * blendCoeff) >> 4; + g2 += ((gBlend - g2) * blendCoeff) >> 4; + b2 += ((bBlend - b2) * blendCoeff) >> 4; gPlttBufferFaded[palOffset++] = (b2 << 10) | (g2 << 5) | r2; } @@ -679,33 +731,30 @@ void sub_807D304(s8 a, u8 coeff, u16 c) } } -bool8 sub_807D574(u8); - -void sub_807D424(u8 a, u16 b) +void ApplyFogBlend(u8 blendCoeff, u16 blendColor) { struct RGBColor color; - u8 r_; - u8 g_; - u8 b_; - u16 r4; - - BlendPalette(0, 0x100, a, b); - color = *(struct RGBColor *)&b; - r_ = color.r; - g_ = color.g; - b_ = color.b; - - r4 = 16; - while (r4 < 32) + u8 rBlend; + u8 gBlend; + u8 bBlend; + u16 curPalIndex; + + BlendPalette(0, 0x100, blendCoeff, blendColor); + color = *(struct RGBColor *)&blendColor; + rBlend = color.r; + gBlend = color.g; + bBlend = color.b; + + for (curPalIndex = 16; curPalIndex < 32; curPalIndex++) { - if (sub_807D574(r4)) + if (LightenSpritePaletteInFog(curPalIndex)) { - u16 r12 = (r4 + 1) * 16; - u16 r6 = r4 * 16; + u16 palEnd = (curPalIndex + 1) * 16; + u16 palOffset = curPalIndex * 16; - while (r6 < r12) + while (palOffset < palEnd) { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[r6]; + struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; u8 r = color.r; u8 g = color.g; u8 b = color.b; @@ -714,88 +763,88 @@ void sub_807D424(u8 a, u16 b) g += ((31 - g) * 3) >> 2; b += ((28 - b) * 3) >> 2; - r += ((r_ - r) * a) >> 4; - g += ((g_ - g) * a) >> 4; - b += ((b_ - b) * a) >> 4; + r += ((rBlend - r) * blendCoeff) >> 4; + g += ((gBlend - g) * blendCoeff) >> 4; + b += ((bBlend - b) * blendCoeff) >> 4; - gPlttBufferFaded[r6] = (b << 10) | (g << 5) | r; - r6++; + gPlttBufferFaded[palOffset] = (b << 10) | (g << 5) | r; + palOffset++; } } else { - BlendPalette(r4 * 16, 16, a, b); + BlendPalette(curPalIndex * 16, 16, blendCoeff, blendColor); } - r4++; } } -void sub_807D540(u8 a) +static void MarkFogSpritePalToLighten(u8 paletteIndex) { - if (gWeatherPtr->unknown_6FA < 6) + if (gWeatherPtr->lightenedFogSpritePalsCount < 6) { - gWeatherPtr->unknown_6F4[gWeatherPtr->unknown_6FA] = a; - gWeatherPtr->unknown_6FA++; + gWeatherPtr->lightenedFogSpritePals[gWeatherPtr->lightenedFogSpritePalsCount] = paletteIndex; + gWeatherPtr->lightenedFogSpritePalsCount++; } } -bool8 sub_807D574(u8 a) +static bool8 LightenSpritePaletteInFog(u8 paletteIndex) { u16 i; - for (i = 0; i < gWeatherPtr->unknown_6FA; i++) + for (i = 0; i < gWeatherPtr->lightenedFogSpritePalsCount; i++) { - if (gWeatherPtr->unknown_6F4[i] == a) + if (gWeatherPtr->lightenedFogSpritePals[i] == paletteIndex) return TRUE; } + return FALSE; } -void sub_807D5BC(s8 a) +void sub_807D5BC(s8 gammaIndex) { - if (gWeatherPtr->unknown_6C6 == 3) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) { - sub_807CEBC(0, 32, a); - gWeatherPtr->unknown_6C0 = a; + ApplyGammaShift(0, 32, gammaIndex); + gWeatherPtr->gammaIndex = gammaIndex; } } -void sub_807D5F0(u8 a, u8 b, u8 c) +void sub_807D5F0(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay) { - if (gWeatherPtr->unknown_6C6 == 3) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) { - gWeatherPtr->unknown_6C6 = 0; - gWeatherPtr->unknown_6C0 = a; - gWeatherPtr->unknown_6C1 = b; - gWeatherPtr->unknown_6C3 = 0; - gWeatherPtr->unknown_6C2 = c; - sub_807D5BC(a); + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER; + gWeatherPtr->gammaIndex = gammaIndex; + gWeatherPtr->gammaTargetIndex = gammaTargetIndex; + gWeatherPtr->gammaStepFrameCounter = 0; + gWeatherPtr->gammaStepDelay = gammaStepDelay; + sub_807D5BC(gammaIndex); } } -void fade_screen(u8 a, u8 delay) +void FadeScreen(u8 mode, u8 delay) { u32 fadeColor; - u32 r1; - u32 r2; + bool8 fadeOut; + bool8 useWeatherPal; - switch (a) + switch (mode) { - case 0: + case FADE_FROM_BLACK: fadeColor = 0; - r1 = 0; + fadeOut = FALSE; break; - case 2: + case FADE_FROM_WHITE: fadeColor = 0xFFFF; - r1 = 0; + fadeOut = FALSE; break; - case 1: + case FADE_TO_BLACK: fadeColor = 0; - r1 = 1; + fadeOut = TRUE; break; - case 3: + case FADE_TO_WHITE: fadeColor = 0xFFFF; - r1 = 1; + fadeOut = TRUE; break; default: return; @@ -808,145 +857,149 @@ void fade_screen(u8 a, u8 delay) case WEATHER_RAIN_HEAVY: case WEATHER_SNOW: case WEATHER_FOG_1: - case WEATHER_DARK: + case WEATHER_SHADE: case WEATHER_DROUGHT: - r2 = 1; + useWeatherPal = TRUE; break; default: - r2 = 0; + useWeatherPal = FALSE; break; } - if (r1 != 0) + if (fadeOut) { - if (r2 != 0) + if (useWeatherPal) CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, 0x400); + BeginNormalPaletteFade(0xFFFFFFFF, delay, 0, 16, fadeColor); - gWeatherPtr->unknown_6C6 = 2; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_OUT; } else { - gWeatherPtr->unknown_6C4 = fadeColor; - if (r2 != 0) - gWeatherPtr->unknown_6C7 = 0; + gWeatherPtr->fadeDestColor = fadeColor; + if (useWeatherPal) + gWeatherPtr->fadeScreenCounter = 0; else BeginNormalPaletteFade(0xFFFFFFFF, delay, 16, 0, fadeColor); - gWeatherPtr->unknown_6C6 = 1; + + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_IN; gWeatherPtr->unknown_6CA = 1; gWeatherPtr->unknown_6CB = 0; Weather_SetBlendCoeffs(gWeatherPtr->currBlendEVA, gWeatherPtr->currBlendEVB); - gWeatherPtr->unknown_6C8 = 1; + gWeatherPtr->readyForInit = TRUE; } } -bool8 sub_807D770(void) +bool8 IsWeatherNotFadingIn(void) { - return (gWeatherPtr->unknown_6C6 != 1); + return (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_IN); } -void sub_807D78C(u8 a) +void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex) { - u16 r4 = 16 + a; + u16 paletteIndex = 16 + spritePaletteIndex; u16 i; - switch (gWeatherPtr->unknown_6C6) + switch (gWeatherPtr->palProcessingState) { - case 1: + case WEATHER_PAL_STATE_SCREEN_FADING_IN: if (gWeatherPtr->unknown_6CA != 0) { if (gWeatherPtr->currWeather == WEATHER_FOG_1) - sub_807D540(r4); - r4 *= 16; + MarkFogSpritePalToLighten(paletteIndex); + paletteIndex *= 16; for (i = 0; i < 16; i++) - gPlttBufferFaded[r4 + i] = gWeatherPtr->unknown_6C4; + gPlttBufferFaded[paletteIndex + i] = gWeatherPtr->fadeDestColor; } break; - case 2: - r4 *= 16; - CpuFastCopy(gPlttBufferFaded + r4, gPlttBufferUnfaded + r4, 32); - BlendPalette(r4, 16, gPaletteFade.y, gPaletteFade.blendColor); + case WEATHER_PAL_STATE_SCREEN_FADING_OUT: + paletteIndex *= 16; + CpuFastCopy(gPlttBufferFaded + paletteIndex, gPlttBufferUnfaded + paletteIndex, 32); + BlendPalette(paletteIndex, 16, gPaletteFade.y, gPaletteFade.blendColor); break; + // WEATHER_PAL_STATE_CHANGING_WEATHER + // WEATHER_PAL_STATE_CHANGING_IDLE default: if (gWeatherPtr->currWeather != WEATHER_FOG_1) { - sub_807CEBC(r4, 1, gWeatherPtr->unknown_6C0); + ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); } else { - r4 *= 16; - BlendPalette(r4, 16, 12, 0x73FC); + paletteIndex *= 16; + BlendPalette(paletteIndex, 16, 12, 0x73FC); } break; } } -void sub_807D874(u8 a) +void ApplyWeatherGammaShiftToPal(u8 paletteIndex) { - sub_807CEBC(a, 1, gWeatherPtr->unknown_6C0); + ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); } u8 unref_sub_807D894(void) { - if (gWeatherPtr->unknown_6C6 == 1) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_SCREEN_FADING_IN) return gWeatherPtr->unknown_6CA; else return 0; } -void sub_807D8C0(const u16 *palette) +void LoadCustomWeatherSpritePalette(const u16 *palette) { - LoadPalette(palette, 0x100 + gWeatherPtr->unknown_6D4 * 16, 32); - sub_807D78C(gWeatherPtr->unknown_6D4); + LoadPalette(palette, 0x100 + gWeatherPtr->weatherPicSpritePalIndex * 16, 32); + UpdateSpritePaletteWithWeather(gWeatherPtr->weatherPicSpritePalIndex); } -void sub_807D8F0(u8 *a, u8 *b) +static void LoadDroughtWeatherPalette(u8 *gammaIndexPtr, u8 *b) { - u8 r4 = *a; + u8 gammaIndex = *gammaIndexPtr; u16 i; - if (r4 < 7) + if (gammaIndex < 7) { - r4--; - LZ77UnCompWram(sCompressedDroughtPalettes[r4], eWeatherPaletteData.data[r4]); - if (r4 == 0) + gammaIndex--; + LZ77UnCompWram(sCompressedDroughtPalettes[gammaIndex], eDroughtPaletteData.gammaShiftColors[gammaIndex]); + if (gammaIndex == 0) { - eWeatherPaletteData.data[r4][0] = 0x421; + eDroughtPaletteData.gammaShiftColors[gammaIndex][0] = RGB(1, 1, 1); for (i = 1; i < 0x1000; i++) - eWeatherPaletteData.data[r4][i] += eWeatherPaletteData.data[r4][i - 1]; + eDroughtPaletteData.gammaShiftColors[gammaIndex][i] += eDroughtPaletteData.gammaShiftColors[gammaIndex][i - 1]; } else { for (i = 0; i < 0x1000; i++) - eWeatherPaletteData.data[r4][i] += eWeatherPaletteData.data[r4 - 1][i]; + eDroughtPaletteData.gammaShiftColors[gammaIndex][i] += eDroughtPaletteData.gammaShiftColors[gammaIndex - 1][i]; } - if (++(*a) == 7) + if (++(*gammaIndexPtr) == 7) { - *a = 32; + *gammaIndexPtr = 32; *b = 32; } } } -void sub_807D9A8(void) +void ResetDroughtWeatherPaletteLoading(void) { - gWeatherPtr->unknown_74D = 1; - gWeatherPtr->unknown_74E = 1; + gWeatherPtr->loadDroughtPalsIndex = 1; + gWeatherPtr->loadDroughtPalsOffset = 1; } -bool8 sub_807D9C8(void) +bool8 LoadDroughtWeatherPalettes(void) { - if (gWeatherPtr->unknown_74D < 32) + if (gWeatherPtr->loadDroughtPalsIndex < 32) { - sub_807D8F0(&gWeatherPtr->unknown_74D, &gWeatherPtr->unknown_74E); - if (gWeatherPtr->unknown_74D < 32) + LoadDroughtWeatherPalette(&gWeatherPtr->loadDroughtPalsIndex, &gWeatherPtr->loadDroughtPalsOffset); + if (gWeatherPtr->loadDroughtPalsIndex < 32) return TRUE; } return FALSE; } -void sub_807DA04(s8 a) +void sub_807DA04(s8 gammaIndex) { - sub_807D5BC(-a - 1); + sub_807D5BC(-gammaIndex - 1); } void sub_807DA14(void) @@ -1008,8 +1061,8 @@ void Weather_SetTargetBlendCoeffs(u8 eva, u8 evb, int delay) gWeatherPtr->targetBlendEVA = eva; gWeatherPtr->targetBlendEVB = evb; gWeatherPtr->blendDelay = delay; - gWeatherPtr->unknown_739 = 0; - gWeatherPtr->unknown_738 = 0; + gWeatherPtr->blendFrameCounter = 0; + gWeatherPtr->blendUpdateCounter = 0; } bool8 Weather_UpdateBlend(void) @@ -1018,13 +1071,13 @@ bool8 Weather_UpdateBlend(void) && gWeatherPtr->currBlendEVB == gWeatherPtr->targetBlendEVB) return TRUE; - if (++gWeatherPtr->unknown_739 > gWeatherPtr->blendDelay) + if (++gWeatherPtr->blendFrameCounter > gWeatherPtr->blendDelay) { - gWeatherPtr->unknown_739 = 0; - gWeatherPtr->unknown_738++; + gWeatherPtr->blendFrameCounter = 0; + gWeatherPtr->blendUpdateCounter++; // Update currBlendEVA and currBlendEVB on alternate frames - if (gWeatherPtr->unknown_738 & 1) + if (gWeatherPtr->blendUpdateCounter & 1) { if (gWeatherPtr->currBlendEVA < gWeatherPtr->targetBlendEVA) gWeatherPtr->currBlendEVA++; @@ -1054,48 +1107,48 @@ void unref_sub_807DCB4(u8 a) switch (a) { case 1: - SetWeather(1); + SetWeather(WEATHER_CLOUDS); break; case 2: - SetWeather(2); + SetWeather(WEATHER_SUNNY); break; case 3: - SetWeather(3); + SetWeather(WEATHER_RAIN_LIGHT); break; case 4: - SetWeather(4); + SetWeather(WEATHER_SNOW); break; case 5: - SetWeather(5); + SetWeather(WEATHER_RAIN_MED); break; case 6: - SetWeather(6); + SetWeather(WEATHER_FOG_1); break; case 7: - SetWeather(9); + SetWeather(WEATHER_FOG_2); break; case 8: - SetWeather(7); + SetWeather(WEATHER_ASH); break; case 9: - SetWeather(8); + SetWeather(WEATHER_SANDSTORM); break; case 10: - SetWeather(11); + SetWeather(WEATHER_SHADE); break; } } -u8 weather_get_current(void) +u8 GetCurrentWeather(void) { return gWeatherPtr->currWeather; } -void SetRainStrengthFromSoundEffect(u16 sndEff) +void SetRainStrengthFromSoundEffect(u16 soundEffect) { - if (gWeatherPtr->unknown_6C6 != 2) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT) { - switch (sndEff) + switch (soundEffect) { case SE_T_KOAME: gWeatherPtr->rainStrength = 0; @@ -1109,7 +1162,8 @@ void SetRainStrengthFromSoundEffect(u16 sndEff) default: return; } - PlaySE(sndEff); + + PlaySE(soundEffect); } } @@ -1133,29 +1187,29 @@ void PlayRainSoundEffect(void) } } -u8 sub_807DDFC(void) +u8 IsWeatherChangeComplete(void) { - return gWeatherPtr->unknown_6D3; + return gWeatherPtr->weatherChangeComplete; } -void sub_807DE10(void) +void SetWeatherScreenFadeOut(void) { - gWeatherPtr->unknown_6C6 = 2; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_OUT; } void unref_sub_807DE24(void) { - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } -void sub_807DE38(u8 a) +void PreservePaletteInWeather(u8 preservedPalIndex) { - CpuCopy16(gUnknown_083970C8, gUnknown_0202FF38, 32); - gUnknown_0202FF38[a] = 0; - gUnknown_030006DC = gUnknown_0202FF38; + CpuCopy16(sBasePaletteGammaTypes, gFieldEffectPaletteGammaTypes, 32); + gFieldEffectPaletteGammaTypes[preservedPalIndex] = GAMMA_NONE; + sPaletteGammaTypes = gFieldEffectPaletteGammaTypes; } -void sub_807DE68(void) +void ResetPreservedPalettesInWeather(void) { - gUnknown_030006DC = gUnknown_083970C8; + sPaletteGammaTypes = sBasePaletteGammaTypes; } diff --git a/src/field/field_weather_effects.c b/src/field/field_weather_effects.c index b7b5d85c7..09d98b7b1 100644 --- a/src/field/field_weather_effects.c +++ b/src/field/field_weather_effects.c @@ -74,10 +74,7 @@ static const struct SpriteTemplate sCloudSpriteTemplate = .callback = sub_807E0F4, }; -extern void sub_807D5BC(s8 a); -extern void sub_807D8C0(const u16 *palette); -extern void sub_807D9A8(void); -extern bool8 sub_807D9C8(void); +extern void sub_807D5BC(s8 gammaIndex); extern void sub_807DA14(void); extern void sub_807DA4C(void); extern void Weather_SetTargetBlendCoeffs(u8 a, u8 b, int c); @@ -91,8 +88,8 @@ extern void sub_807D5F0(u8 a, u8 b, u8 c); void Clouds_InitVars(void) { - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->initStep = 0; if (gWeatherPtr->cloudSpritesCreated == FALSE) @@ -159,8 +156,8 @@ bool8 Clouds_Finish(void) void Weather2_InitVars(void) { - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; } void Weather2_InitAll(void) @@ -184,7 +181,7 @@ void CreateCloudSprites(void) if (gWeatherPtr->cloudSpritesCreated == TRUE) return; LoadSpriteSheet(&sCloudSpriteSheet); - sub_807D8C0(gUnknown_08397108); + LoadCustomWeatherSpritePalette(gUnknown_08397108); for (i = 0; i < 3; i++) { u8 spriteId = CreateSprite(&sCloudSpriteTemplate, 0, 0, 0xFF); @@ -236,8 +233,8 @@ void Drought_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 0; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 0; } void Drought_Main(void); @@ -254,15 +251,15 @@ void Drought_Main(void) switch (gWeatherPtr->initStep) { case 0: - if (gWeatherPtr->unknown_6C6 != 0) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_CHANGING_WEATHER) gWeatherPtr->initStep++; break; case 1: - sub_807D9A8(); + ResetDroughtWeatherPaletteLoading(); gWeatherPtr->initStep++; break; case 2: - if (sub_807D9C8() == FALSE) + if (LoadDroughtWeatherPalettes() == FALSE) gWeatherPtr->initStep++; break; case 3: @@ -368,8 +365,8 @@ void LightRain_InitVars(void) gWeatherPtr->unknown_6DB = 8; gWeatherPtr->unknown_6DC = 0; gWeatherPtr->unknown_6D9 = 10; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; SetRainStrengthFromSoundEffect(SE_T_KOAME); } @@ -885,8 +882,8 @@ void Snow_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->unknown_6E5 = 16; gWeatherPtr->unknown_6E0 = 0; } @@ -1074,8 +1071,8 @@ void MedRain_InitVars(void) gWeatherPtr->unknown_6DB = 4; gWeatherPtr->unknown_6DC = 0; gWeatherPtr->unknown_6D9 = 16; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment gWeatherPtr->unknown_6ED = 0; SetRainStrengthFromSoundEffect(SE_T_AME); @@ -1102,8 +1099,8 @@ void HeavyRain_InitVars(void) gWeatherPtr->unknown_6DB = 4; gWeatherPtr->unknown_6DC = 1; gWeatherPtr->unknown_6D9 = 24; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment SetRainStrengthFromSoundEffect(SE_T_OOAME); } @@ -1139,7 +1136,7 @@ void Rain_Main(void) gWeatherPtr->initStep++; break; case 3: - if (gWeatherPtr->unknown_6C6 == 0) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_CHANGING_WEATHER) break; gWeatherPtr->initStep = 6; break; @@ -1213,7 +1210,7 @@ void Rain_Main(void) gWeatherPtr->initStep++; break; case 14: - if (gWeatherPtr->unknown_6C6 != 3) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_IDLE) break; gWeatherPtr->unknown_6EA = 1; gWeatherPtr->initStep = 4; @@ -1296,8 +1293,8 @@ void Fog1_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; if (gWeatherPtr->fog1SpritesCreated == 0) { gWeatherPtr->unknown_6F0 = 0; @@ -1446,8 +1443,8 @@ void Ash_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->unknown_6FE = 20; if (!gWeatherPtr->ashSpritesCreated) { @@ -1634,8 +1631,8 @@ void Fog2_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = 0; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->unknown_6F0 = 0; gWeatherPtr->unknown_6F2 = 1; if (gWeatherPtr->fog2SpritesCreated == 0) @@ -1835,8 +1832,8 @@ void Sandstorm_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = 0; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; if (gWeatherPtr->sandstormSprites1Created == 0) { gWeatherPtr->unknown_704 = gWeatherPtr->unknown_708 = 0; @@ -2015,7 +2012,7 @@ void CreateSandstormSprites_1(void) if (!gWeatherPtr->sandstormSprites1Created) { LoadSpriteSheet(&sSandstormSpriteSheet); - sub_807D8C0(gUnknown_08397128); + LoadCustomWeatherSpritePalette(gUnknown_08397128); for (i = 0; i < 20; i++) { u8 spriteId = CreateSpriteAtEnd(&sSandstormSpriteTemplate, 0, (i / 5) * 64, 1); @@ -2113,26 +2110,26 @@ void SandstormSpriteCallback3(struct Sprite *sprite) } //------------------------------------------------------------------------------ -// Weather 11 +// Shade //------------------------------------------------------------------------------ -void Weather11_InitVars(void) +void Shade_InitVars(void) { gWeatherPtr->initStep = 0; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; } -void Weather11_InitAll(void) +void Shade_InitAll(void) { - Weather11_InitVars(); + Shade_InitVars(); } -void Weather11_Main(void) +void Shade_Main(void) { } -bool8 Weather11_Finish(void) +bool8 Shade_Finish(void) { return FALSE; } @@ -2322,7 +2319,7 @@ void SetSav1WeatherFromCurrMapHeader(void) void SetWeather(u32 weather) { SetSav1Weather(weather); - DoWeatherEffect(GetSav1Weather()); + ChangeWeather(GetSav1Weather()); } void SetWeather_Unused(u32 weather) @@ -2333,7 +2330,7 @@ void SetWeather_Unused(u32 weather) void DoCurrentWeather(void) { - DoWeatherEffect(GetSav1Weather()); + ChangeWeather(GetSav1Weather()); } void sub_8080750(void) diff --git a/src/field/item_menu.c b/src/field/item_menu.c index 28b360e78..d0c3f598b 100644 --- a/src/field/item_menu.c +++ b/src/field/item_menu.c @@ -47,7 +47,7 @@ extern void sub_808B5B4(); extern u8 sub_80F92F4(); extern void sub_80C9C7C(u8); extern void pal_fill_black(void); -extern bool8 sub_807D770(void); +extern bool8 IsWeatherNotFadingIn(void); extern u8 sub_80F931C(); extern void sub_808A3F8(u8); extern void Shop_FadeReturnToMartMenu(void); @@ -2699,7 +2699,7 @@ void ExecuteItemUseFromBlackPalette(void) static void Task_CallItemUseOnFieldCallback(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) gFieldItemUseCallback(taskId); } diff --git a/src/field/item_use.c b/src/field/item_use.c index a5b091f0a..a0fbb13b2 100644 --- a/src/field/item_use.c +++ b/src/field/item_use.c @@ -99,7 +99,7 @@ void ItemMenu_ConfirmNormalFade(u8 var) void ItemMenu_ConfirmComplexFade(u8 var) { ExecuteSwitchToOverworldFromItemUse(var); - fade_screen(1, 0); + FadeScreen(1, 0); } void SetUpItemUseOnFieldCallback(u8 taskId) diff --git a/src/field/overworld.c b/src/field/overworld.c index cff67d02e..dcfa72cbb 100644 --- a/src/field/overworld.c +++ b/src/field/overworld.c @@ -588,7 +588,7 @@ bool8 sub_80538D0(u16 x, u16 y) void sub_80538F0(u8 mapGroup, u8 mapNum) { - s32 i; + s32 paletteIndex; Overworld_SetWarpDestination(mapGroup, mapNum, -1, -1, -1); sub_8053F0C(); @@ -609,8 +609,8 @@ void sub_80538F0(u8 mapGroup, u8 mapNum) sub_8056D38(gMapHeader.mapData); apply_map_tileset2_palette(gMapHeader.mapData); - for (i = 6; i < 12; i++) - sub_807D874(i); + for (paletteIndex = 6; paletteIndex < 12; paletteIndex++) + ApplyWeatherGammaShiftToPal(paletteIndex); sub_8072ED0(); UpdateLocationHistoryForRoamer(); diff --git a/src/field/player_pc.c b/src/field/player_pc.c index 3719b7c7a..27427ecaa 100644 --- a/src/field/player_pc.c +++ b/src/field/player_pc.c @@ -29,7 +29,7 @@ extern void DestroyVerticalScrollIndicator(u8); extern void PauseVerticalScrollIndicator(u8); extern void LoadScrollIndicatorPalette(void); extern void ClearMailStruct(struct MailStruct *); -extern u8 sub_807D770(void); +extern u8 IsWeatherNotFadingIn(void); extern void sub_808B020(void); extern void ClearVerticalScrollIndicatorPalettes(void); @@ -357,12 +357,12 @@ static void Task_ItemStorage_Deposit(u8 taskId) static void ItemStorage_Deposit(u8 taskId) { TASK.FUNC = Task_ItemStorage_Deposit; - fade_screen(1, 0); + FadeScreen(1, 0); } static void ItemStorage_HandleReturnToProcessInput(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) TASK.FUNC = ItemStorageMenuProcessInput; } @@ -1196,7 +1196,7 @@ static void Mailbox_MailOptionsProcessInput(u8 taskId) static void Mailbox_DoMailRead(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); TASK.FUNC = Mailbox_FadeAndReadMail; } @@ -1211,7 +1211,7 @@ static void Mailbox_FadeAndReadMail(u8 taskId) static void Mailbox_HandleReturnToProcessInput(u8 taskId) // Mailbox_HandleReturnToProcessInput { - if(sub_807D770() == TRUE) // is black fade finished? why not gPaletteFade.active? + if (IsWeatherNotFadingIn() == TRUE) // is black fade finished? why not gPaletteFade.active? TASK.FUNC = Mailbox_ProcessInput; } @@ -1280,7 +1280,7 @@ static void Mailbox_Give(u8 taskId) Mailbox_NoPokemonForMail(taskId); // cannot be reached normally else { - fade_screen(1, 0); + FadeScreen(1, 0); TASK.FUNC = Mailbox_DoGiveMailPokeMenu; } } diff --git a/src/field/scrcmd.c b/src/field/scrcmd.c index fd5620a76..44863edb2 100644 --- a/src/field/scrcmd.c +++ b/src/field/scrcmd.c @@ -625,7 +625,7 @@ bool8 IsPaletteNotActive(void) bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) { - fade_screen(ScriptReadByte(ctx), 0); + FadeScreen(ScriptReadByte(ctx), 0); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } @@ -635,7 +635,7 @@ bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx) u8 duration = ScriptReadByte(ctx); u8 delay = ScriptReadByte(ctx); - fade_screen(duration, delay); + FadeScreen(duration, delay); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } diff --git a/src/field/secret_base.c b/src/field/secret_base.c index 134aebbc6..2d02de004 100644 --- a/src/field/secret_base.c +++ b/src/field/secret_base.c @@ -348,7 +348,7 @@ void sub_80BBA48(u8 taskid) void sub_80BBAF0(void) { CreateTask(sub_80BBA48, 0); - fade_screen(1, 0); + FadeScreen(1, 0); saved_warp2_set(0, gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1); } @@ -362,7 +362,7 @@ bool8 sub_80BBB24(void) void sub_80BBB50(u8 taskid) { FieldObjectTurn(&(gMapObjects[gPlayerAvatar.mapObjectId]), 2); - if (sub_807D770() == 1) { + if (IsWeatherNotFadingIn() == 1) { EnableBothScriptContexts(); DestroyTask(taskid); } @@ -397,7 +397,7 @@ void sub_80BBC78(void) { u8 taskid = CreateTask(sub_80BBBEC, 0); gTasks[taskid].data[0] = 0; - fade_screen(1, 0); + FadeScreen(1, 0); } bool8 CurrentMapIsSecretBase(void) @@ -534,7 +534,7 @@ void sub_80BC074(u8 taskid) void sub_80BC0F8(void) { CreateTask(sub_80BC074, 0); - fade_screen(1, 0); + FadeScreen(1, 0); } void sub_80BC114(void) { diff --git a/src/field/shop.c b/src/field/shop.c index 65be76b81..a87c859b7 100644 --- a/src/field/shop.c +++ b/src/field/shop.c @@ -173,7 +173,7 @@ static void Task_HandleShopMenuBuy(u8 taskId) gTasks[taskId].data[8] = (u32)BuyMenuDrawGraphics >> 16; gTasks[taskId].data[9] = (u32)BuyMenuDrawGraphics; gTasks[taskId].func = Shop_FadeAndRunBuySellCallback; - fade_screen(1, 0); + FadeScreen(1, 0); } static void Task_HandleShopMenuSell(u8 taskId) @@ -181,7 +181,7 @@ static void Task_HandleShopMenuSell(u8 taskId) gTasks[taskId].data[8] = (u32)ItemMenu_LoadSellMenu >> 16; gTasks[taskId].data[9] = (u32)ItemMenu_LoadSellMenu; gTasks[taskId].func = Shop_FadeAndRunBuySellCallback; - fade_screen(1, 0); + FadeScreen(1, 0); } static void Task_HandleShopMenuQuit(u8 taskId) @@ -213,7 +213,7 @@ static void ReturnToShopMenuAfterExitingSellMenu(u8 taskId) static void Task_ReturnToMartMenu(u8 taskId) { - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == 1) { if (gMartInfo.martType == MART_TYPE_2) DisplayItemMessageOnField(taskId, gOtherText_CanIHelpYou, ReturnToShopMenuAfterExitingSellMenu, 0); diff --git a/src/field/start_menu.c b/src/field/start_menu.c index 43b0c29c2..161b5d6a0 100644 --- a/src/field/start_menu.c +++ b/src/field/start_menu.c @@ -328,7 +328,7 @@ static u8 StartMenu_InputProcessCallback(void) if (gMenuCallback != StartMenu_SaveCallback && gMenuCallback != StartMenu_ExitCallback && gMenuCallback != StartMenu_RetireCallback) - fade_screen(1, 0); + FadeScreen(1, 0); return 0; } if (gMain.newKeys & (START_BUTTON | B_BUTTON)) diff --git a/src/field/tv.c b/src/field/tv.c index 79c4716cb..786320eba 100644 --- a/src/field/tv.c +++ b/src/field/tv.c @@ -47,8 +47,6 @@ struct UnkTvStruct s8 var0; }; -extern u8 gUnknown_0300430A[11]; - struct OutbreakPokemon { /*0x00*/ u16 species; diff --git a/src/pokemon/pokemon_menu.c b/src/pokemon/pokemon_menu.c index a41e197f2..c0cae9353 100644 --- a/src/pokemon/pokemon_menu.c +++ b/src/pokemon/pokemon_menu.c @@ -786,7 +786,7 @@ void FieldCallback_Teleport(void) static void sub_808ABA8(u8 taskID) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { gFieldEffectArguments[0] = GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_SPECIES); gUnknown_03005CE4(); diff --git a/src/rom3.c b/src/rom3.c index 713713162..000de8356 100644 --- a/src/rom3.c +++ b/src/rom3.c @@ -463,7 +463,7 @@ void sub_800C1A8(u8 taskId) } break; case 4: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { var = (ewram14004arr(0, gTasks[taskId].data[15]) | (ewram14004arr(1, gTasks[taskId].data[15]) << 8)); gTasks[taskId].data[13] = 1; diff --git a/src/scene/berry_blender.c b/src/scene/berry_blender.c index 7567899ae..2cb68ccf1 100644 --- a/src/scene/berry_blender.c +++ b/src/scene/berry_blender.c @@ -1163,7 +1163,7 @@ static void sub_804E9F8(void) gBerryBlenderData->framesToWait = 0; break; case 9: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { ResetBlockReceivedFlags(); if (GetMultiplayerId() == 0) @@ -1215,7 +1215,7 @@ static void sub_804E9F8(void) } break; case 13: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { gBerryBlenderData->field_0++; sub_8051414(&gBerryBlenderData->field_168); @@ -1257,7 +1257,7 @@ static void sub_804E9F8(void) gBerryBlenderData->field_0++; break; case 20: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { sub_8007E24(); gBerryBlenderData->field_0++; @@ -2506,7 +2506,7 @@ static void sub_8050954(void) case 3: if (/*multiplayerID != 0*/ GetMultiplayerId() != 0) gBerryBlenderData->field_6F++; - else if (sub_8007ECC()) + else if (IsLinkTaskFinished()) { gBerryBlenderData->field_1BC = gBerryBlenderData->gameFrameTime; gBerryBlenderData->field_1C0 = gBerryBlenderData->max_RPM; @@ -2646,7 +2646,7 @@ bool8 sub_8050CE8(void) gBerryBlenderData->framesToWait = 0; break; case 1: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { gBerryBlenderData->field_1C4++; gSoftResetDisabled = TRUE; @@ -2665,7 +2665,7 @@ bool8 sub_8050CE8(void) } break; case 4: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { if (sub_8125E6C()) gBerryBlenderData->field_1C4 = 5; @@ -2752,7 +2752,7 @@ static void sub_8050E30(void) gBerryBlenderData->field_6F++; break; case 6: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { gBerryBlenderData->framesToWait = 0; gBerryBlenderData->field_6F++; @@ -2771,7 +2771,7 @@ static void sub_8050E30(void) sub_80084A4(); break; case 9: - if (sub_8007ECC()) + if (IsLinkTaskFinished()) { BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); gBerryBlenderData->field_6F++; diff --git a/src/scene/cable_car.c b/src/scene/cable_car.c index 2e596883f..2f2a03a2f 100644 --- a/src/scene/cable_car.c +++ b/src/scene/cable_car.c @@ -18,6 +18,7 @@ #include "event_data.h" #include "cable_car_util.h" #include "constants/map_objects.h" +#include "constants/weather.h" // Static type declarations @@ -328,7 +329,7 @@ static void sub_8123740(void) i = 0; sub_8123FBC(0); gSpriteCoordOffsetX = 0; - sub_807C9B4(0); + sub_807C9B4(WEATHER_NONE); for (; i < 20; i++) { gWeatherPtr->sprites.s2.ashSprites[i] = NULL; @@ -357,7 +358,7 @@ static void sub_8123878(u8 taskId) case 0: if (sCableCarPtr->unk_0006 == sCableCarPtr->unk_0004) { - DoWeatherEffect(sCableCarPtr->unk_0002); + ChangeWeather(sCableCarPtr->unk_0002); sCableCarPtr->unk_0001 = 1; } break; @@ -769,7 +770,7 @@ static void LoadSprites(void) gSprites[spriteId].data[1] = 0x63; sCableCarPtr->unk_0002 = 7; sCableCarPtr->unk_0004 = 0x15e; - sub_807C9B4(2); + sub_807C9B4(WEATHER_SUNNY); break; case 1: CableCarUtil_CopyWrapped(sCableCarPtr->unk_00fc, eCableCar2->mtChimneyTilemap + 0x24, 0x18, 0x1a, 0x0c, 0x03); @@ -793,7 +794,7 @@ static void LoadSprites(void) gSprites[spriteId].data[1] = 0x41; sCableCarPtr->unk_0002 = 2; sCableCarPtr->unk_0004 = 0x109; - sub_807C9B4(7); + sub_807C9B4(WEATHER_ASH); break; } for (i = 0; i < 9; i++) diff --git a/src/script_pokemon_util_80C4BF0.c b/src/script_pokemon_util_80C4BF0.c index f991297ab..02e66d313 100644 --- a/src/script_pokemon_util_80C4BF0.c +++ b/src/script_pokemon_util_80C4BF0.c @@ -32,26 +32,13 @@ extern void sub_80C4698(u8 *, u8); extern struct SpriteTemplate gUnknown_02024E8C; -extern u8 gContestPlayerMonIndex; -extern u8 gIsLinkContest; -extern u8 gPlayerPartyCount; extern u8 gSelectedOrderFromParty[]; -extern u16 gSpecialVar_0x8004; -extern u16 gSpecialVar_0x8005; -extern u16 gSpecialVar_0x8006; - extern u16 gSpecialVar_ContestCategory; extern u16 gSpecialVar_ContestRank; -extern u16 gSpecialVar_Result; - -extern u32 gUnknown_03005D28; extern u8 gUnknown_02038694; extern u8 gUnknown_0203856C; -extern u8 gContestFinalStandings[]; -extern s16 gUnknown_02038670[]; -extern s16 gUnknown_02038678[]; void SetContestTrainerGfxIds(void) { @@ -373,8 +360,8 @@ void ScriptRandom(void) if(gIsLinkContest & 1) { - gUnknown_03005D28 = 1103515245 * gUnknown_03005D28 + 24691; - random = gUnknown_03005D28 >> 16; + gContestRngValue = 1103515245 * gContestRngValue + 24691; + random = gContestRngValue >> 16; scriptPtr = &gSpecialVar_Result; } else |