diff --git a/asm/macros/event.inc b/asm/macros/event.inc index a4beb3527..5e5a2758d 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -274,15 +274,17 @@ .2byte \functionId .endm - @ Blocks script execution until a command or ASM code manually unblocks it. Generally used with specific commands and specials. If this command runs, and a subsequent command or piece of ASM does not unblock state, the script will remain blocked indefinitely (essentially a hang). + @ Blocks script execution until a command or ASM code manually unblocks it. Generally used with specific + @ commands and specials. If this command runs, and a subsequent command or piece of ASM does not unblock + @ state, the script will remain blocked indefinitely (essentially a hang). .macro waitstate .byte 0x27 .endm - @ Blocks script execution for time (frames? milliseconds?). - .macro delay time:req + @ Blocks script execution for frames. (Pokemon Emerald runs at just shy of 60 frames per second.) + .macro delay frames:req .byte 0x28 - .2byte \time + .2byte \frames .endm @ Sets a to 1. @@ -315,7 +317,8 @@ .byte 0x2d .endm - @ Sets the values of variables 0x8000, 0x8001, and 0x8002 to the current hour, minute, and second. In FRLG, this command sets those variables to zero. + @ Sets the values of variables 0x8000, 0x8001, and 0x8002 to the current hour, minute, and second. In FRLG, + @ this command sets those variables to zero. .macro gettime .byte 0x2e .endm @@ -378,7 +381,8 @@ .byte \speed .endm - @ Sends the player to Warp warp on Map bank.map. If the specified warp is 0xFF, then the player will instead be sent to (X, Y) on the map. + @ Sends the player to Warp warp on Map bank.map. If the specified warp is 0xFF, + @ then the player will instead be sent to (X, Y) on the map. .macro warp map:req, warp:req, X:req, Y:req .byte 0x39 map \map @@ -429,7 +433,8 @@ .2byte \Y .endm - @ Sets the warp destination that a warp to Warp 127 on Map 127.127 will connect to. Useful when a map has warps that need to go to script-controlled locations (i.e. elevators). + @ Sets the warp destination that a warp to Warp 127 on Map 127.127 will connect to. + @ Useful when a map has warps that need to go to script-controlled locations (i.e. elevators). .macro setdynamicwarp map:req, warp:req, X:req, Y:req .byte 0x3f map \map @@ -468,7 +473,8 @@ .byte 0x43 .endm - @ Attempts to add quantity of item index to the player's Bag. If the player has enough room, the item will be added and VAR_RESULT will be set to TRUE; otherwise, VAR_RESULT is set to FALSE. + @ Attempts to add quantity of item index to the player's Bag. If the player has enough room, the item will be added and + @ VAR_RESULT will be set to TRUE; otherwise, VAR_RESULT is set to FALSE. .macro additem index:req, quantity=1 .byte 0x44 .2byte \index @@ -482,21 +488,24 @@ .2byte \quantity .endm - @ Checks if the player has enough space in their Bag to hold quantity more of item index. Sets VAR_RESULT to TRUE if there is room, or FALSE is there is no room. + @ Checks if the player has enough space in their Bag to hold quantity more of item index. Sets VAR_RESULT to + @ TRUE if there is room, or FALSE is there is no room. .macro checkitemspace index:req, quantity:req .byte 0x46 .2byte \index .2byte \quantity .endm - @ Checks if the player has quantity or more of item index in their Bag. Sets VAR_RESULT to TRUE if the player has enough of the item, or FALSE if they have fewer than quantity of the item. + @ Checks if the player has quantity or more of item index in their Bag. Sets VAR_RESULT to TRUE if the player has + @ enough of the item, or FALSE if they have fewer than quantity of the item. .macro checkitem index:req, quantity:req .byte 0x47 .2byte \index .2byte \quantity .endm - @ Checks which Bag pocket the specified item belongs in, and writes the pocket value (POCKET_*) to VAR_RESULT. This script is used to show the name of the proper Bag pocket when the player receives an item via callstd (simplified to giveitem in XSE). + @ Checks which Bag pocket the specified item belongs in, and writes the pocket value (POCKET_*) to VAR_RESULT. + @ This script is used to show the name of the proper Bag pocket when the player receives an item via callstd (simplified to giveitem in XSE). .macro checkitemtype index:req .byte 0x48 .2byte \index @@ -534,7 +543,8 @@ .2byte \decoration .endm - @ Checks if the player has enough space in their PC to hold decoration. Sets VAR_RESULT to TRUE if there is room, or FALSE is there is no room. In FireRed, this command is a nop. (The argument is read, but not used for anything.) + @ Checks if the player has enough space in their PC to hold decoration. Sets VAR_RESULT to TRUE if there is room, or + @ FALSE is there is no room. In FireRed, this command is a nop. (The argument is read, but not used for anything.) .macro checkdecorspace decoration:req .byte 0x4e .2byte \decoration @@ -556,7 +566,10 @@ .endif .endm - @ Blocks script execution until the movements being applied to the specified (index) Object finish. If the specified Object is 0x0000, then the command will block script execution until all Objects affected by applymovement finish their movements. If the specified Object is not currently being manipulated with applymovement, then this command does nothing. + @ Blocks script execution until the movements being applied to the specified (index) Object finish. + @ If the specified Object is 0x0000, then the command will block script execution until all Objects + @ affected by applymovement finish their movements. If the specified Object is not currently being + @ manipulated with applymovement, then this command does nothing. @ If no map is specified, then the current map is used. .macro waitmovement index:req, map .ifb \map @@ -569,7 +582,9 @@ .endif .endm - @ Attempts to hide the specified (index) Object on the specified (map_group, map_num) map, by setting its visibility flag if it has a valid one. If the Object does not have a valid visibility flag, this command does nothing. + @ Attempts to hide the specified (index) Object on the specified (map_group, map_num) map, + @ by setting its visibility flag if it has a valid one. If the Object does not have a valid + @ visibility flag, this command does nothing. @ If no map is specified, then the current map is used. .macro removeobject index:req, map .ifb \map @@ -582,7 +597,8 @@ .endif .endm - @ Unsets the specified (index) Object's visibility flag on the specified (map_group, map_num) map if it has a valid one. If the Object does not have a valid visibility flag, this command does nothing. + @ Unsets the specified (index) Object's visibility flag on the specified (map_group, map_num) map if it has a valid one. + @ If the Object does not have a valid visibility flag, this command does nothing. @ If no map is specified, then the current map is used. .macro addobject index:req, map .ifb \map @@ -723,7 +739,8 @@ .endm - @ Starts a trainer battle using the battle information stored in RAM (usually by trainerbattle, which actually calls this command behind-the-scenes), and blocks script execution until the battle finishes. + @ Starts a trainer battle using the battle information stored in RAM (usually by trainerbattle, which actually calls this + @ command behind-the-scenes), and blocks script execution until the battle finishes. .macro trainerbattlebegin .byte 0x5d .endm @@ -763,7 +780,8 @@ .2byte \y .endm - @ Copies a live object event's xy position to its template, so that if the sprite goes off screen, it'll still be there when it comes back on screen. + @ Copies a live object event's xy position to its template, so that if the sprite goes off screen, + @ it'll still be there when it comes back on screen. .macro copyobjectxytoperm index:req .byte 0x64 .2byte \index @@ -775,12 +793,15 @@ .byte \byte .endm - @ If a standard message box (or its text) is being drawn on-screen, this command blocks script execution until the box and its text have been fully drawn. + @ If a standard message box (or its text) is being drawn on-screen, this command blocks script execution until the + @ box and its text have been fully drawn. .macro waitmessage .byte 0x66 .endm - @ Starts displaying a standard message box containing the specified text. If text is a pointer, then the string at that offset will be loaded and used. If text is script bank 0, then the value of script bank 0 will be treated as a pointer to the text. (You can use loadpointer to place a string pointer in a script bank.) + @ Starts displaying a standard message box containing the specified text. If text is a pointer, then the string at + @ that offset will be loaded and used. If text is script bank 0, then the value of script bank 0 will be treated as + @ a pointer to the text. (You can use loadpointer to place a string pointer in a script bank.) .macro message text:req .byte 0x67 .4byte \text @@ -816,14 +837,16 @@ .byte 0x6d .endm - @ Displays a YES/NO multichoice box at the specified coordinates, and blocks script execution until the user makes a selection. Their selection is stored in VAR_RESULT as NO (0) or YES (1). Pressing B is equivalent to answering NO + @ Displays a YES/NO multichoice box at the specified coordinates, and blocks script execution until the user makes a selection. + @ Their selection is stored in VAR_RESULT as NO (0) or YES (1). Pressing B is equivalent to answering NO .macro yesnobox x:req, y:req .byte 0x6e .byte \x .byte \y .endm - @ Displays a multichoice box from which the user can choose a selection, and blocks script execution until a selection is made. Lists of options are predefined (sMultichoiceLists) and the one to be used is specified with list. If b is set to a non-zero value, then the user will not be allowed to back out of the multichoice with the B button. + @ Displays a multichoice box from which the user can choose a selection, and blocks script execution until a selection is made. + @ Lists of options are predefined (sMultichoiceLists) and the one to be used is specified with list. If b is set to a non-zero value, then the user will not be allowed to back out of the multichoice with the B button. .macro multichoice x:req, y:req, list:req, b:req .byte 0x6f .byte \x @@ -832,7 +855,10 @@ .byte \b .endm - @ Displays a multichoice box from which the user can choose a selection, and blocks script execution until a selection is made. Lists of options are predefined (sMultichoiceLists) and the one to be used is specified with list. The default argument determines the initial position of the cursor when the box is first opened; it is zero-indexed, and if it is too large, it is treated as 0x00. If b is set to a non-zero value, then the user will not be allowed to back out of the multichoice with the B button. + @ Displays a multichoice box from which the user can choose a selection, and blocks script execution until a selection is made. + @ Lists of options are predefined (sMultichoiceLists) and the one to be used is specified with list. The default argument determines + @ the initial position of the cursor when the box is first opened; it is zero-indexed, and if it is too large, it is treated as 0x00. + @ If b is set to a non-zero value, then the user will not be allowed to back out of the multichoice with the B button. .macro multichoicedefault x:req, y:req, list:req, default:req, b:req .byte 0x70 .byte \x @@ -842,7 +868,9 @@ .byte \b .endm - @ Displays a multichoice box from which the user can choose a selection, and blocks script execution until a selection is made. Lists of options are predefined (sMultichoiceLists) and the one to be used is specified with list. The per_row argument determines how many list items will be shown on a single row of the box. + @ Displays a multichoice box from which the user can choose a selection, and blocks script execution until a selection is made. + @ Lists of options are predefined (sMultichoiceLists) and the one to be used is specified with list. + @ The per_row argument determines how many list items will be shown on a single row of the box. .macro multichoicegrid x:req, y:req, list:req, per_row:req, B:req .byte 0x71 .byte \x @@ -894,7 +922,9 @@ .byte \a .endm - @ Displays the string at pointer as braille text in a standard message box. The string must be formatted to use braille characters and needs to provide six extra starting characters that are skipped (in RS, these characters determined the box's size and position, but in Emerald these are calculated automatically). + @ Displays the string at pointer as braille text in a standard message box. The string must be formatted to use braille + @ characters and needs to provide six extra starting characters that are skipped (in RS, these characters determined the + @ box's size and position, but in Emerald these are calculated automatically). .macro braillemessage text:req .byte 0x78 .4byte \text @@ -923,7 +953,9 @@ .2byte \move .endm - @ Checks if at least one Pokemon in the player's party knows the specified (index) attack. If so, VAR_RESULT is set to the (zero-indexed) slot number of the first Pokemon that knows the move. If not, VAR_RESULT is set to PARTY_SIZE. VAR_0x8004 is also set to this Pokemon's species. + @ Checks if at least one Pokemon in the player's party knows the specified (index) attack. If so, VAR_RESULT is set to the + @ (zero-indexed) slot number of the first Pokemon that knows the move. If not, VAR_RESULT is set to PARTY_SIZE. + @ VAR_0x8004 is also set to this Pokemon's species. .macro checkpartymove index:req .byte 0x7c .2byte \index @@ -942,14 +974,16 @@ .byte \out .endm - @ Writes the nickname of the Pokemon in slot slot (zero-indexed) of the player's party to the specified buffer. If an empty or invalid slot is specified, ten spaces ("") are written to the buffer. + @ Writes the nickname of the Pokemon in slot slot (zero-indexed) of the player's party to the specified buffer. + @ If an empty or invalid slot is specified, ten spaces ("") are written to the buffer. .macro bufferpartymonnick out:req, slot:req .byte 0x7f .byte \out .2byte \slot .endm - @ Writes the name of the item at index item to the specified buffer. If the specified index is larger than the number of items in the game (0x176), the name of item 0 ("????????") is buffered instead. + @ Writes the name of the item at index item to the specified buffer. If the specified index is larger than + @ the number of items in the game (0x176), the name of item 0 ("????????") is buffered instead. .macro bufferitemname out:req, item:req .byte 0x80 .byte \out @@ -977,7 +1011,8 @@ .2byte \input .endm - @ Writes the standard string identified by index to the specified buffer. This command has no protections in place at all, so specifying an invalid standard string (e.x. 0x2B) can and usually will cause data corruption. + @ Writes the standard string identified by index to the specified buffer. This command has no protections in place at all, + @ so specifying an invalid standard string (e.x. 0x2B) can and usually will cause crashes or garbage characters. .macro bufferstdstring out:req, index:req .byte 0x84 .byte \out @@ -1063,7 +1098,8 @@ .byte \check .endm - @ If check is 0x00, this command will check if the player has money >= value; VAR_RESULT is set to TRUE if the player has enough money, or FALSE if they do not. + @ If check is 0x00, this command will check if the player has money >= value; VAR_RESULT is set to TRUE if the player + @ has enough money, or FALSE if they do not. .macro checkmoney value:req, check:req .byte 0x92 .4byte \value @@ -1291,7 +1327,8 @@ .2byte \count .endm - @ Prepares to start a wild battle against a species at Level level holding item. Running this command will not affect normal wild battles. You start the prepared battle with dowildbattle. + @ Prepares to start a wild battle against a species at Level level holding item. Running this command will not affect + @ normal wild battles. You start the prepared battle with dowildbattle. .macro setwildbattle species:req, level:req, item:req .byte 0xb6 .2byte \species @@ -1395,19 +1432,22 @@ .2byte \box .endm - @ Sets the color of the text in standard message boxes. 0x00 produces blue (male) text, 0x01 produces red (female) text, 0xFF resets the color to the default for the current OW's gender, and all other values produce black text. + @ Sets the color of the text in standard message boxes. 0x00 produces blue (male) text, 0x01 produces red (female) text, + @ 0xFF resets the color to the default for the current OW's gender, and all other values produce black text. .macro textcolor color:req .byte 0xc7 .byte \color .endm - @ The exact purpose of this command is unknown, but it is related to the blue help-text box that appears on the bottom of the screen when the Main Menu is opened. + @ The exact purpose of this command is unknown, but it is related to the blue help-text box that appears on the bottom + @ of the screen when the Main Menu is opened. .macro loadhelp pointer:req .byte 0xc8 .4byte \pointer .endm - @ The exact purpose of this command is unknown, but it is related to the blue help-text box that appears on the bottom of the screen when the Main Menu is opened. + @ The exact purpose of this command is unknown, but it is related to the blue help-text box that appears on the bottom of + @ the screen when the Main Menu is opened. .macro unloadhelp .byte 0xc9 .endm @@ -1435,13 +1475,15 @@ .2byte \slot .endm - @ Checks if the Pokemon in the specified slot of the player's party is obedient. If the Pokemon is disobedient, VAR_RESULT is TRUE. If the Pokemon is obedient (or if the specified slot is empty or invalid), VAR_RESULT is FALSE. + @ Checks if the Pokemon in the specified slot of the player's party is obedient. If the Pokemon is disobedient, + @ VAR_RESULT is TRUE. If the Pokemon is obedient (or if the specified slot is empty or invalid), VAR_RESULT is FALSE. .macro checkmonobedience slot:req .byte 0xce .2byte \slot .endm - @ Depending on factors I haven't managed to understand yet, this command may cause script execution to jump to the offset specified by the pointer at 0x020375C0. + @ Depending on factors I haven't managed to understand yet, this command may cause script execution to jump to the + @ offset specified by the pointer at 0x020375C0. .macro gotoram .byte 0xcf .endm @@ -1468,7 +1510,8 @@ .byte \location .endm - @ For the rotating tile puzzles in Mossdeep Gym/Trick House Room 7. Moves the objects on the colored puzzle specified by puzzleNumber one rotation + @ For the rotating tile puzzles in Mossdeep Gym/Trick House Room 7. Moves the objects on the colored puzzle + @ specified by puzzleNumber one rotation .macro moverotatingtileobjects puzzleNumber:req .byte 0xd3 .2byte \puzzleNumber @@ -1479,7 +1522,9 @@ .byte 0xd4 .endm - @ For the rotating tile puzzles in Mossdeep Gym/Trick House Room 7. Allocates memory for the puzzle objects. isTrickHouse is needed to determine which of the two maps the puzzle is on, in order to know where in the tileset the puzzle tiles start. In FireRed, this command is a nop. + @ For the rotating tile puzzles in Mossdeep Gym/Trick House Room 7. Allocates memory for the puzzle objects. + @ isTrickHouse is needed to determine which of the two maps the puzzle is on, in order to know where in the tileset + @ the puzzle tiles start. In FireRed, this command is a nop. .macro initrotatingtilepuzzle isTrickHouse:req .byte 0xd5 .2byte \isTrickHouse @@ -1551,7 +1596,10 @@ .2byte \word .endm - @ Writes the name of the specified (item) item to the specified buffer. If the specified item is a Berry (0x85 - 0xAE) or Poke Ball (0x4) and if the quantity is 2 or more, the buffered string will be pluralized ("IES" or "S" appended). If the specified item is the Enigma Berry, I have no idea what this command does (but testing showed no pluralization). If the specified index is larger than the number of items in the game (0x176), the name of item 0 ("????????") is buffered instead. + @ Writes the name of the specified (item) item to the specified buffer. If the specified item is a Berry (0x85 - 0xAE) or + @ Poke Ball (0x4) and if the quantity is 2 or more, the buffered string will be pluralized ("IES" or "S" appended). + @ If the specified item is the Enigma Berry, I have no idea what this command does (but testing showed no pluralization). + @ If the specified index is larger than the number of items in the game (0x176), the name of item 0 ("????????") is buffered instead. .macro bufferitemnameplural out:req, item:req, quantity:req .byte 0xe2 .byte \out diff --git a/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc index 25522f0c0..048c4fc80 100644 --- a/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleDomeBattleRoom/scripts.inc @@ -172,7 +172,7 @@ BattleFrontier_BattleDomeBattleRoom_EventScript_WonTourney:: @ 824BF62 BattleFrontier_BattleDomeBattleRoom_EventScript_WonLvOpenTourney:: @ 824BF96 msgbox BattleFrontier_BattleDomeBattleRoom_Text_PlayerIsLvOpenChamp, MSGBOX_DEFAULT BattleFrontier_BattleDomeBattleRoom_EventScript_CelebrateWin:: @ 824BF9E - special DoConfettiEffect + special DoDomeConfetti playse SE_W227B call BattleFrontier_BattleDomeBattleRoom_EventScript_AudienceLookAround delay 60 diff --git a/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc index 029009294..89eaeda50 100644 --- a/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerBattleRoom/scripts.inc @@ -45,7 +45,7 @@ BattleFrontier_BattleTowerBattleRoom_EventScript_OpponentEnter:: @ 8241BC3 BattleFrontier_BattleTower_EventScript_WarpToLobbyLost:: @ 8241C03 frontier_set FRONTIER_DATA_CHALLENGE_STATUS, CHALLENGE_STATUS_LOST tower_set TOWER_DATA_LVL_MODE - setvar VAR_0x8004, 3 + setvar VAR_0x8004, FANCOUNTER_USED_BATTLE_TOWER special Script_TryGainNewFanFromCounter goto BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobby @@ -134,7 +134,7 @@ BattleFrontier_BattleTowerBattleRoom_EventScript_ContinueChallenge:: @ 8241DDC BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobbyWon:: @ 8241DF6 frontier_set FRONTIER_DATA_CHALLENGE_STATUS, CHALLENGE_STATUS_WON tower_set TOWER_DATA_LVL_MODE - setvar VAR_0x8004, 3 + setvar VAR_0x8004, FANCOUNTER_USED_BATTLE_TOWER special Script_TryGainNewFanFromCounter goto BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobby diff --git a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc index 3c549a919..754384136 100644 --- a/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc +++ b/data/maps/BattleFrontier_BattleTowerMultiBattleRoom/scripts.inc @@ -103,7 +103,7 @@ BattleFrontier_BattleTowerMultiBattleRoom_EventScript_DoTowerBattle:: @ 8249069 BattleFrontier_BattleTowerMultiBattleRoom_EventScript_WarpToLobbyLost:: @ 824907E frontier_set FRONTIER_DATA_CHALLENGE_STATUS, CHALLENGE_STATUS_LOST tower_set TOWER_DATA_LVL_MODE - setvar VAR_0x8004, 3 + setvar VAR_0x8004, FANCOUNTER_USED_BATTLE_TOWER special Script_TryGainNewFanFromCounter goto BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobby @@ -208,7 +208,7 @@ BattleFrontier_BattleTowerMultiBattleRoom_EventScript_ContinueChallenge:: @ 8249 BattleFrontier_BattleTowerMultiBattleRoom_EventScript_WarpToLobbyWon:: @ 82492AF frontier_set FRONTIER_DATA_CHALLENGE_STATUS, CHALLENGE_STATUS_WON tower_set TOWER_DATA_LVL_MODE - setvar VAR_0x8004, 3 + setvar VAR_0x8004, FANCOUNTER_USED_BATTLE_TOWER special Script_TryGainNewFanFromCounter goto BattleFrontier_BattleTowerBattleRoom_EventScript_WarpToLobby diff --git a/data/maps/EverGrandeCity_DrakesRoom/scripts.inc b/data/maps/EverGrandeCity_DrakesRoom/scripts.inc index 2ae78caad..b9debf676 100644 --- a/data/maps/EverGrandeCity_DrakesRoom/scripts.inc +++ b/data/maps/EverGrandeCity_DrakesRoom/scripts.inc @@ -54,7 +54,7 @@ EverGrandeCity_DrakesRoom_EventScript_PostBattleSpeech:: @ 822871A end EverGrandeCity_DrakesRoom_EventScript_Defeated:: @ 8228724 - setvar VAR_0x8004, 0 + setvar VAR_0x8004, FANCOUNTER_DEFEATED_DRAKE special Script_TryGainNewFanFromCounter setflag FLAG_DEFEATED_ELITE_4_DRAKE call PokemonLeague_EliteFour_SetAdvanceToNextRoomMetatiles diff --git a/data/maps/LilycoveCity_ContestLobby/scripts.inc b/data/maps/LilycoveCity_ContestLobby/scripts.inc index af123388d..a3d232346 100644 --- a/data/maps/LilycoveCity_ContestLobby/scripts.inc +++ b/data/maps/LilycoveCity_ContestLobby/scripts.inc @@ -43,7 +43,7 @@ LilycoveCity_ContestLobby_EventScript_ContestArtist:: @ 821A264 msgbox LilycoveCity_ContestLobby_Text_YourPokemonSpurredMeToPaint, MSGBOX_DEFAULT lockall fadescreen FADE_TO_BLACK - showcontestwinner 0 + showcontestwinner CONTEST_WINNER_ARTIST lockall msgbox LilycoveCity_ContestLobby_Text_ShouldITakePaintingToMuseum, MSGBOX_YESNO compare VAR_RESULT, YES @@ -217,7 +217,7 @@ LilycoveCity_ContestLobby_EventScript_LinkContestArtist:: @ 821A436 msgbox LilycoveCity_ContestLobby_Text_YourPokemonSpurredMeToPaint, MSGBOX_DEFAULT lockall fadescreen FADE_TO_BLACK - showcontestwinner 0 + showcontestwinner CONTEST_WINNER_ARTIST msgbox LilycoveCity_ContestLobby_Text_ShouldITakePaintingToMuseum, MSGBOX_YESNO compare VAR_RESULT, YES goto_if_eq LilycoveCity_ContestLobby_EventScript_TakePaintingToMuseumLink @@ -505,42 +505,42 @@ LilycoveCity_ContestLobby_EventScript_NinjaBoy:: @ 821A735 LilycoveCity_ContestLobby_EventScript_ContestWinner1:: @ 821A73E lockall fadescreen FADE_TO_BLACK - showcontestwinner 1 + showcontestwinner CONTEST_WINNER_HALL_1 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner2:: @ 821A745 lockall fadescreen FADE_TO_BLACK - showcontestwinner 2 + showcontestwinner CONTEST_WINNER_HALL_2 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner3:: @ 821A74C lockall fadescreen FADE_TO_BLACK - showcontestwinner 3 + showcontestwinner CONTEST_WINNER_HALL_3 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner4:: @ 821A753 lockall fadescreen FADE_TO_BLACK - showcontestwinner 4 + showcontestwinner CONTEST_WINNER_HALL_4 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner5:: @ 821A75A lockall fadescreen FADE_TO_BLACK - showcontestwinner 5 + showcontestwinner CONTEST_WINNER_HALL_5 releaseall end LilycoveCity_ContestLobby_EventScript_ContestWinner6:: @ 821A761 lockall fadescreen FADE_TO_BLACK - showcontestwinner 6 + showcontestwinner CONTEST_WINNER_HALL_6 releaseall end diff --git a/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc b/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc index 5d45ed144..257bdd086 100644 --- a/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc +++ b/data/maps/LilycoveCity_LilycoveMuseum_2F/scripts.inc @@ -183,35 +183,35 @@ LilycoveCity_LilycoveMuseum_2F_EventScript_RichBoy:: @ 821999C LilycoveCity_LilycoveMuseum_2F_EventScript_ShowCoolPainting:: @ 82199A5 msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner 9 + showcontestwinner CONTEST_WINNER_MUSEUM_COOL releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowBeautyPainting:: @ 82199B3 msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner 10 + showcontestwinner CONTEST_WINNER_MUSEUM_BEAUTY releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowCutePainting:: @ 82199C1 msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner 11 + showcontestwinner CONTEST_WINNER_MUSEUM_CUTE releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowSmartPainting:: @ 82199CF msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner 12 + showcontestwinner CONTEST_WINNER_MUSEUM_SMART releaseall end LilycoveCity_LilycoveMuseum_2F_EventScript_ShowToughPainting:: @ 82199DD msgbox LilycoveCity_LilycoveMuseum_2F_Text_ItsPaintingOfPokemon, MSGBOX_SIGN fadescreen FADE_TO_BLACK - showcontestwinner 13 + showcontestwinner CONTEST_WINNER_MUSEUM_TOUGH releaseall end diff --git a/data/specials.inc b/data/specials.inc index d973a6a94..0f78f981f 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -498,7 +498,7 @@ gSpecials:: @ 81DBA64 def_special GetPCBoxToSendMon def_special ShouldShowBoxWasFullMessage def_special SetMatchCallRegisteredFlag - def_special DoConfettiEffect + def_special DoDomeConfetti def_special CreateAbnormalWeatherEvent def_special GetAbnormalWeatherMapNameAndType def_special GetMartEmployeeObjectEventId diff --git a/graphics/contest/clink_tilemap11.bin b/graphics/contest/results_screen.bin similarity index 100% rename from graphics/contest/clink_tilemap11.bin rename to graphics/contest/results_screen.bin diff --git a/graphics/contest/misc_2.pal b/graphics/contest/results_screen.pal similarity index 100% rename from graphics/contest/misc_2.pal rename to graphics/contest/results_screen.pal diff --git a/graphics/contest/misc_2.png b/graphics/contest/results_screen.png similarity index 100% rename from graphics/contest/misc_2.png rename to graphics/contest/results_screen.png diff --git a/graphics/contest/clink_tilemap7.bin b/graphics/contest/results_screen_beauty.bin similarity index 100% rename from graphics/contest/clink_tilemap7.bin rename to graphics/contest/results_screen_beauty.bin diff --git a/graphics/contest/clink_tilemap6.bin b/graphics/contest/results_screen_cool.bin similarity index 100% rename from graphics/contest/clink_tilemap6.bin rename to graphics/contest/results_screen_cool.bin diff --git a/graphics/contest/clink_tilemap8.bin b/graphics/contest/results_screen_cute.bin similarity index 100% rename from graphics/contest/clink_tilemap8.bin rename to graphics/contest/results_screen_cute.bin diff --git a/graphics/contest/clink_tilemap3.bin b/graphics/contest/results_screen_hyper.bin similarity index 100% rename from graphics/contest/clink_tilemap3.bin rename to graphics/contest/results_screen_hyper.bin diff --git a/graphics/contest/clink_tilemap5.bin b/graphics/contest/results_screen_link.bin similarity index 100% rename from graphics/contest/clink_tilemap5.bin rename to graphics/contest/results_screen_link.bin diff --git a/graphics/contest/clink_tilemap4.bin b/graphics/contest/results_screen_master.bin similarity index 100% rename from graphics/contest/clink_tilemap4.bin rename to graphics/contest/results_screen_master.bin diff --git a/graphics/contest/clink_tilemap1.bin b/graphics/contest/results_screen_normal.bin similarity index 100% rename from graphics/contest/clink_tilemap1.bin rename to graphics/contest/results_screen_normal.bin diff --git a/graphics/contest/clink_tilemap9.bin b/graphics/contest/results_screen_smart.bin similarity index 100% rename from graphics/contest/clink_tilemap9.bin rename to graphics/contest/results_screen_smart.bin diff --git a/graphics/contest/clink_tilemap2.bin b/graphics/contest/results_screen_super.bin similarity index 100% rename from graphics/contest/clink_tilemap2.bin rename to graphics/contest/results_screen_super.bin diff --git a/graphics/contest/clink_tilemap10.bin b/graphics/contest/results_screen_tough.bin similarity index 100% rename from graphics/contest/clink_tilemap10.bin rename to graphics/contest/results_screen_tough.bin diff --git a/include/battle_main.h b/include/battle_main.h index e04db17bb..217b10b39 100644 --- a/include/battle_main.h +++ b/include/battle_main.h @@ -57,15 +57,15 @@ u32 sub_80397C4(u32 setId, u32 tableId); void SpriteCb_WildMon(struct Sprite *sprite); void SpriteCallbackDummy_2(struct Sprite *sprite); void SpriteCB_FaintOpponentMon(struct Sprite *sprite); -void sub_8039AD8(struct Sprite *sprite); -void sub_8039B2C(struct Sprite *sprite); -void sub_8039B58(struct Sprite *sprite); +void SpriteCb_ShowAsMoveTarget(struct Sprite *sprite); +void SpriteCb_HideAsMoveTarget(struct Sprite *sprite); +void SpriteCb_OpponentMonFromBall(struct Sprite *sprite); void sub_8039BB4(struct Sprite *sprite); void sub_80105DC(struct Sprite *sprite); void sub_8039C00(struct Sprite *sprite); void DoBounceEffect(u8 battlerId, u8 b, s8 c, s8 d); void EndBounceEffect(u8 battlerId, bool8 b); -void sub_8039E44(struct Sprite *sprite); +void SpriteCb_PlayerMonFromBall(struct Sprite *sprite); void sub_8039E60(struct Sprite *sprite); void sub_8039E84(struct Sprite *sprite); void sub_8039E9C(struct Sprite *sprite); diff --git a/include/confetti_util.h b/include/confetti_util.h new file mode 100644 index 000000000..ecc05a220 --- /dev/null +++ b/include/confetti_util.h @@ -0,0 +1,33 @@ +#ifndef GUARD_CONFETTI_UTIL_H +#define GUARD_CONFETTI_UTIL_H + +struct ConfettiUtil +{ + struct OamData oam; + s16 x; + s16 y; + s16 xDelta; + s16 yDelta; + u16 tileTag; + u16 palTag; + u16 tileNum; + u8 id; + u8 filler; + u8 animNum; + u8 active:1; + u8 allowUpdates:1; + u8 dummied:1; + u8 priority:2; + s16 data[8]; + void (*callback)(struct ConfettiUtil *); +}; + +bool32 ConfettiUtil_Init(u8 count); +bool32 ConfettiUtil_Free(void); +bool32 ConfettiUtil_Update(void); +u8 ConfettiUtil_SetCallback(u8 id, void (*func)(struct ConfettiUtil *)); +u8 ConfettiUtil_SetData(u8 id, u8 dataArrayId, s16 dataValue); +u8 ConfettiUtil_AddNew(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 animNum, u8 priority); +u8 ConfettiUtil_Remove(u8 id); + +#endif // GUARD_CONFETTI_UTIL_H diff --git a/include/constants/contest.h b/include/constants/contest.h index 186c56e2b..2de2866a3 100644 --- a/include/constants/contest.h +++ b/include/constants/contest.h @@ -29,6 +29,23 @@ #define CONTEST_CATEGORY_TOUGH 4 #define CONTEST_CATEGORIES_COUNT 5 +#define CONTEST_WINNER_ARTIST 0 // Winner shown by the artist, painting not necessarily saved +#define CONTEST_WINNER_HALL_1 1 +#define CONTEST_WINNER_HALL_2 2 +#define CONTEST_WINNER_HALL_3 3 +#define CONTEST_WINNER_HALL_4 4 +#define CONTEST_WINNER_HALL_5 5 +#define CONTEST_WINNER_HALL_6 6 +#define NUM_CONTEST_HALL_WINNERS 6 +#define CONTEST_WINNER_7 7 +#define CONTEST_WINNER_8 8 +#define CONTEST_WINNER_MUSEUM_COOL 9 +#define CONTEST_WINNER_MUSEUM_BEAUTY 10 +#define CONTEST_WINNER_MUSEUM_CUTE 11 +#define CONTEST_WINNER_MUSEUM_SMART 12 +#define CONTEST_WINNER_MUSEUM_TOUGH 13 +// NUM_CONTEST_WINNERS in constants/global.h + #define CANT_ENTER_CONTEST 0 #define CAN_ENTER_CONTEST_EQUAL_RANK 1 #define CAN_ENTER_CONTEST_HIGH_RANK 2 diff --git a/include/constants/field_specials.h b/include/constants/field_specials.h index a2dc117e4..a01151378 100644 --- a/include/constants/field_specials.h +++ b/include/constants/field_specials.h @@ -75,4 +75,9 @@ #define FANCLUB_MEMBER7 14 #define FANCLUB_MEMBER8 15 +#define FANCOUNTER_DEFEATED_DRAKE 0 +#define FANCOUNTER_BATTLED_AT_BASE 1 +#define FANCOUNTER_FINISHED_CONTEST 2 +#define FANCOUNTER_USED_BATTLE_TOWER 3 + #endif // GUARD_CONSTANTS_FIELD_SPECIALS_H diff --git a/include/constants/flags.h b/include/constants/flags.h index 4dd18880f..a9c7abae1 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -1573,7 +1573,9 @@ #define FLAG_UNUSED_0x91F (SYSTEM_FLAGS + 0xBF) // Unused Flag // Daily Flags -#define DAILY_FLAGS_START 0x920 +// These flags are cleared once per day +// The start and end are byte-aligned because the flags are cleared in byte increments +#define DAILY_FLAGS_START (FLAG_UNUSED_0x91F + (8 - FLAG_UNUSED_0x91F % 8)) #define FLAG_UNUSED_0x920 (DAILY_FLAGS_START + 0x0) // Unused Flag #define FLAG_DAILY_CONTEST_LOBBY_RECEIVED_BERRY (DAILY_FLAGS_START + 0x1) #define FLAG_DAILY_SECRET_BASE (DAILY_FLAGS_START + 0x2) @@ -1639,7 +1641,9 @@ #define FLAG_UNUSED_0x95D (DAILY_FLAGS_START + 0x3D) // Unused Flag #define FLAG_UNUSED_0x95E (DAILY_FLAGS_START + 0x3E) // Unused Flag #define FLAG_UNUSED_0x95F (DAILY_FLAGS_START + 0x3F) // Unused Flag -#define DAILY_FLAGS_END FLAG_UNUSED_0x95F +#define DAILY_FLAGS_END (FLAG_UNUSED_0x95F + (7 - FLAG_UNUSED_0x95F % 8)) + +#define FLAGS_COUNT (DAILY_FLAGS_END + 1) // Special Flags (Stored in EWRAM (gSpecialFlags), not in the SaveBlock) #define SPECIAL_FLAGS_START 0x4000 diff --git a/include/constants/global.h b/include/constants/global.h index b86e29a29..98f15e7dc 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -34,8 +34,6 @@ #define POKEBLOCKS_COUNT 40 #define OBJECT_EVENTS_COUNT 16 #define BERRY_TREES_COUNT 128 -#define FLAGS_COUNT 300 -#define VARS_COUNT 256 #define MAIL_COUNT 16 #define SECRET_BASES_COUNT 20 #define TV_SHOWS_COUNT 25 @@ -52,6 +50,7 @@ #define APPRENTICE_COUNT 4 #define APPRENTICE_MAX_QUESTIONS 9 #define MAX_REMATCH_ENTRIES 100 // only REMATCH_TABLE_ENTRIES (78) are used +#define NUM_CONTEST_WINNERS 13 #define UNION_ROOM_KB_ROW_COUNT 10 #define PYRAMID_BAG_ITEMS_COUNT 10 diff --git a/include/constants/items.h b/include/constants/items.h index d795194cf..9496a4c61 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -17,6 +17,8 @@ #define ITEM_LUXURY_BALL 11 #define ITEM_PREMIER_BALL 12 +#define LAST_BALL ITEM_PREMIER_BALL + // Pokemon Items #define ITEM_POTION 13 #define ITEM_ANTIDOTE 14 diff --git a/include/constants/opponents.h b/include/constants/opponents.h index cd35cf6b7..c9cf9239d 100644 --- a/include/constants/opponents.h +++ b/include/constants/opponents.h @@ -859,6 +859,7 @@ // NOTE: Because each Trainer uses a flag to determine when they are defeated, there is only space for 9 additional trainers before trainer flag space overflows // More space can be made by shifting flags around in constants/flags.h or changing how trainer flags are handled +// MAX_TRAINERS_COUNT can be increased but will take up additional saveblock space #define TRAINERS_COUNT 855 #define MAX_TRAINERS_COUNT 864 diff --git a/include/constants/vars.h b/include/constants/vars.h index 4a38bde81..625c37aa9 100644 --- a/include/constants/vars.h +++ b/include/constants/vars.h @@ -274,6 +274,7 @@ #define VAR_UNUSED_0x40FF 0x40FF // Unused Var #define VARS_END 0x40FF +#define VARS_COUNT (VARS_END - VARS_START + 1) #define SPECIAL_VARS_START 0x8000 // special vars diff --git a/include/contest.h b/include/contest.h index 00c3191eb..a9b1db9ee 100644 --- a/include/contest.h +++ b/include/contest.h @@ -430,9 +430,9 @@ struct ContestResources extern struct ContestPokemon gContestMons[CONTESTANT_COUNT]; extern s16 gContestMonConditions[CONTESTANT_COUNT]; -extern s16 gUnknown_02039F08[CONTESTANT_COUNT]; +extern s16 gContestMonTotalPoints[CONTESTANT_COUNT]; extern s16 gUnknown_02039F10[CONTESTANT_COUNT]; -extern s16 gUnknown_02039F18[CONTESTANT_COUNT]; +extern s16 gContestMonRound2Points[CONTESTANT_COUNT]; extern u8 gContestFinalStandings[CONTESTANT_COUNT]; extern u8 gContestMonPartyIndex; extern u8 gContestPlayerMonIndex; @@ -448,7 +448,6 @@ extern u8 sContestBgCopyFlags; extern struct ContestWinner gCurContestWinner; extern u8 gUnknown_02039F5C; extern u8 gUnknown_02039F5D; - extern u32 gContestRngValue; // contest.c diff --git a/include/contest_link_80FC4F4.h b/include/contest_link.h similarity index 61% rename from include/contest_link_80FC4F4.h rename to include/contest_link.h index a3f118798..4344d55ad 100644 --- a/include/contest_link_80FC4F4.h +++ b/include/contest_link.h @@ -1,5 +1,5 @@ -#ifndef GUARD_CONTEST_LINK_80FC4F4_H -#define GUARD_CONTEST_LINK_80FC4F4_H +#ifndef GUARD_CONTEST_LINK_H +#define GUARD_CONTEST_LINK_H void sub_80FCC88(u8); void sub_80FCC88(u8); @@ -10,4 +10,4 @@ void sub_80FC804(u8); void sub_80FCE48(u8); void sub_80FC894(u8); -#endif //GUARD_CONTEST_LINK_80FC4F4_H +#endif //GUARD_CONTEST_LINK_H diff --git a/include/contest_link_80F57C4.h b/include/contest_util.h similarity index 52% rename from include/contest_link_80F57C4.h rename to include/contest_util.h index add3ae62f..c0d8df031 100644 --- a/include/contest_link_80F57C4.h +++ b/include/contest_util.h @@ -1,12 +1,12 @@ -#ifndef GUARD_CONTEST_LINK_80F57C4_H -#define GUARD_CONTEST_LINK_80F57C4_H +#ifndef GUARD_CONTEST_UTIL_H +#define GUARD_CONTEST_UTIL_H void BufferContestantTrainerName(void); void BufferContestantMonNickname(void); void StartContest(void); void BufferContestantMonSpecies(void); -void sub_80F8484(void); -void sub_80F84C4(u8); +void ShowContestResults(void); +void ContestLinkTransfer(u8); void sub_80FC998(u8 taskId); -#endif // GUARD_CONTEST_LINK_80F57C4_H +#endif // GUARD_CONTEST_UTIL_H diff --git a/include/event_data.h b/include/event_data.h index 53999320f..8b4510e39 100644 --- a/include/event_data.h +++ b/include/event_data.h @@ -1,9 +1,6 @@ #ifndef GUARD_EVENT_DATA_H #define GUARD_EVENT_DATA_H -#include "constants/flags.h" -#include "constants/vars.h" - void InitEventData(void); void ClearTempFieldEventData(void); void ClearDailyFlags(void); diff --git a/include/global.h b/include/global.h index cc1faa9f2..9612a25f0 100644 --- a/include/global.h +++ b/include/global.h @@ -6,6 +6,8 @@ #include "config.h" // we need to define config before gba headers as print stuff needs the functions nulled before defines. #include "gba/gba.h" #include "constants/global.h" +#include "constants/flags.h" +#include "constants/vars.h" // Prevent cross-jump optimization. #define BLOCK_CROSS_JUMP asm(""); @@ -109,6 +111,11 @@ f; \ }) +#define ROUND_BITS_TO_BYTES(numBits)(((numBits) / 8) + (((numBits) % 8) ? 1 : 0)) + +#define DEX_FLAGS_NO (ROUND_BITS_TO_BYTES(POKEMON_SLOTS_NUMBER)) +#define NUM_FLAG_BYTES (ROUND_BITS_TO_BYTES(FLAGS_COUNT)) + struct Coords8 { s8 x; @@ -153,8 +160,6 @@ struct Time /*0x04*/ s8 seconds; }; -#define DEX_FLAGS_NO ((POKEMON_SLOTS_NUMBER / 8) + ((POKEMON_SLOTS_NUMBER % 8) ? 1 : 0)) - struct Pokedex { /*0x00*/ u8 order; @@ -923,7 +928,7 @@ struct SaveBlock1 /*0x9CA*/ u8 trainerRematches[MAX_REMATCH_ENTRIES]; /*0xA30*/ struct ObjectEvent objectEvents[OBJECT_EVENTS_COUNT]; /*0xC70*/ struct ObjectEventTemplate objectEventTemplates[OBJECT_EVENT_TEMPLATES_COUNT]; - /*0x1270*/ u8 flags[FLAGS_COUNT]; + /*0x1270*/ u8 flags[NUM_FLAG_BYTES]; /*0x139C*/ u16 vars[VARS_COUNT]; /*0x159C*/ u32 gameStats[NUM_GAME_STATS]; /*0x169C*/ struct BerryTree berryTrees[BERRY_TREES_COUNT]; @@ -960,7 +965,7 @@ struct SaveBlock1 /*0x2E20*/ u8 additionalPhrases[8]; // bitfield for 33 additional phrases in easy chat system /*0x2E28*/ OldMan oldMan; /*0x2e64*/ struct EasyChatPair easyChatPairs[5]; //Dewford trend [0] and some other stuff - /*0x2e90*/ struct ContestWinner contestWinners[13]; // 0 - 5 used in contest hall, 6 - 7 unused?, 8 - 12 museum + /*0x2e90*/ struct ContestWinner contestWinners[NUM_CONTEST_WINNERS]; // see CONTEST_WINNER_* /*0x3030*/ struct DayCare daycare; /*0x3150*/ struct LinkBattleRecords linkBattleRecords; /*0x31A8*/ u8 giftRibbons[52]; diff --git a/include/graphics.h b/include/graphics.h index 6811b7620..8514d49bd 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4082,8 +4082,8 @@ extern const u8 gNamingScreenUnderscoreTiles[]; extern const u32 gUnknown_08D9BA44[]; -extern const u32 gContestConfetti_Gfx[]; -extern const u32 gContestConfetti_Pal[]; +extern const u32 gConfetti_Gfx[]; +extern const u32 gConfetti_Pal[]; extern const u32 gUnknown_08C093F0[]; extern const u32 gSubstituteDollTilemap[]; @@ -4927,23 +4927,23 @@ extern const u32 gRouletteCreditTiles[]; extern const u32 gRouletteNumbersTiles[]; extern const u32 gRouletteMultiplierTiles[]; -// Contest Link -extern const u32 gUnknown_08C19588[]; +// Contest util +extern const u32 gContestResults_Gfx[]; extern const u32 gUnknown_08C19EEC[]; extern const u32 gUnknown_08C1A000[]; extern const u32 gUnknown_08C1A12C[]; -extern const u32 gUnknown_08C1A2B4[]; -extern const u16 gUnknown_08DC6498[]; -extern const u16 gUnknown_08DC63F8[]; -extern const u16 gUnknown_08DC6420[]; -extern const u16 gUnknown_08DC6448[]; -extern const u16 gUnknown_08DC6470[]; -extern const u16 gUnknown_08DC64AC[]; -extern const u16 gUnknown_08DC64C0[]; -extern const u16 gUnknown_08DC64D4[]; -extern const u16 gUnknown_08DC64E8[]; -extern const u16 gUnknown_08DC64FC[]; -extern const u16 gUnknown_08DC6510[]; +extern const u32 gContestResults_Pal[]; +extern const u16 gLinkContestResults_Tilemap[]; +extern const u16 gNormalContestResults_Tilemap[]; +extern const u16 gSuperContestResults_Tilemap[]; +extern const u16 gHyperContestResults_Tilemap[]; +extern const u16 gMasterContestResults_Tilemap[]; +extern const u16 gCoolContestResults_Tilemap[]; +extern const u16 gBeautyContestResults_Tilemap[]; +extern const u16 gCuteContestResults_Tilemap[]; +extern const u16 gSmartContestResults_Tilemap[]; +extern const u16 gToughContestResults_Tilemap[]; +extern const u16 gContestResults_Tilemap[]; // Trainer Card. extern const u16 gHoennTrainerCard0Star_Pal[]; diff --git a/include/hall_of_fame.h b/include/hall_of_fame.h index a83fad2fc..f1f456713 100644 --- a/include/hall_of_fame.h +++ b/include/hall_of_fame.h @@ -4,7 +4,6 @@ void CB2_DoHallOfFameScreen(void); void CB2_DoHallOfFameScreenDontSaveData(void); void CB2_DoHallOfFamePC(void); -void DoConfettiEffect(void); // hof_pc.c void ReturnFromHallOfFamePC(void); diff --git a/include/item_menu.h b/include/item_menu.h index 9930ccd4f..edfb986f7 100644 --- a/include/item_menu.h +++ b/include/item_menu.h @@ -52,10 +52,7 @@ struct BagMenuStruct void (*exitCallback)(void); u8 tilemapBuffer[0x800]; u8 spriteId[12]; - u8 windowPointers[7]; - u8 unk817; - u8 unk818; - u8 unk819; + u8 windowPointers[10]; u8 itemOriginalLocation; u8 pocketSwitchDisabled:4; u8 itemIconSlot:2; diff --git a/include/rom_81520A8.h b/include/rom_81520A8.h deleted file mode 100644 index 2be12200f..000000000 --- a/include/rom_81520A8.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef GUARD_ROM_81520A8_H -#define GUARD_ROM_81520A8_H - -struct UnkStruct_81520A8 -{ - struct OamData oam; - s16 x; - s16 y; - s16 xDelta; - s16 yDelta; - u16 tileTag; - u16 palTag; - u16 tileNum; - u8 id; - u8 filler17; // Unused. - u8 unk18; - u8 unk19_0:1; - u8 unk19_1:1; - u8 unk19_2:1; - u8 priority:2; - s16 data[8]; - void (*callback)(struct UnkStruct_81520A8 *); -}; - -bool32 sub_81521C0(u8 count); -bool32 sub_8152254(void); -bool32 sub_81522D4(void); -u8 sub_8152438(u8 id, void (*func)(struct UnkStruct_81520A8 *)); -u8 sub_8152474(u8 id, u8 dataArrayId, s16 dataValue); -u8 sub_81524C4(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 arg5, u8 priority); -u8 sub_81525D0(u8 id); - -#endif // GUARD_ROM_81520A8_H diff --git a/include/strings.h b/include/strings.h index 1867f0ca4..67b238422 100644 --- a/include/strings.h +++ b/include/strings.h @@ -2494,7 +2494,7 @@ extern const u8 gText_CommunicationStandby[]; extern const u8 gText_AnnouncingResults[]; extern const u8 gText_PreliminaryResults[]; extern const u8 gText_Round2Results[]; -extern const u8 gText_Var1sVar2Won[]; +extern const u8 gText_ContestantsMonWon[]; // Trainer Card extern const u8 gText_LinkCableBattles[]; diff --git a/ld_script.txt b/ld_script.txt index fbfeea112..4fe9c4aa0 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -169,7 +169,7 @@ SECTIONS { src/record_mixing.o(.text); src/secret_base.o(.text); src/tv.o(.text); - src/contest_link_80F57C4.o(.text); + src/contest_util.o(.text); src/script_pokemon_util_80F87D8.o(.text); src/field_poison.o(.text); src/pokemon_size_record.o(.text); @@ -177,7 +177,7 @@ SECTIONS { src/field_special_scene.o(.text); src/rotating_gate.o(.text); src/safari_zone.o(.text); - src/contest_link_80FC4F4.o(.text); + src/contest_link.o(.text); src/item_use.o(.text); src/battle_anim_effects_1.o(.text); src/battle_anim_effects_2.o(.text); @@ -238,7 +238,7 @@ SECTIONS { src/cable_car.o(.text); src/math_util.o(.text); src/roulette_util.o(.text); - src/rom_81520A8.o(.text); + src/confetti_util.o(.text); src/save.o(.text); src/mystery_event_script.o(.text); src/field_effect_helpers.o(.text); @@ -329,7 +329,7 @@ SECTIONS { src/trainer_hill.o(.text); src/rayquaza_scene.o(.text); src/walda_phrase.o(.text); - src/contest_link_81D9DE4.o(.text); + src/contest_link_util.o(.text); src/gym_leader_rematch.o(.text); src/unk_transition.o(.text); src/international_string_util.o(.text); @@ -544,13 +544,13 @@ SECTIONS { src/record_mixing.o(.rodata); src/secret_base.o(.rodata); src/tv.o(.rodata); - src/contest_link_80F57C4.o(.rodata); + src/contest_util.o(.rodata); src/script_pokemon_util_80F87D8.o(.rodata); src/pokemon_size_record.o(.rodata) src/fldeff_misc.o(.rodata); src/field_special_scene.o(.rodata); src/rotating_gate.o(.rodata); - src/contest_link_80FC4F4.o(.rodata); + src/contest_link.o(.rodata); src/item_use.o(.rodata); src/battle_anim_effects_1.o(.rodata); src/battle_anim_effects_2.o(.rodata); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 6dd9cd2f4..fd18c3187 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -316,7 +316,7 @@ static void HandleInputChooseAction(void) if (gBattleBufferA[gActiveBattler][1] == B_ACTION_USE_ITEM) { // Add item to bag if it is a ball - if (itemId <= ITEM_PREMIER_BALL) + if (itemId <= LAST_BALL) AddBagItem(itemId, 1); else return; @@ -359,7 +359,7 @@ static void HandleInputChooseTarget(void) } while (i < gBattlersCount); } - if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == 2) + if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; @@ -367,7 +367,7 @@ static void HandleInputChooseTarget(void) if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; BtlController_EmitTwoReturnValues(1, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); PlayerBufferExecCompleted(); @@ -375,7 +375,7 @@ static void HandleInputChooseTarget(void) else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; gBattlerControllerFuncs[gActiveBattler] = HandleInputChooseMove; DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1); DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); @@ -384,7 +384,7 @@ static void HandleInputChooseTarget(void) else if (gMain.newKeys & (DPAD_LEFT | DPAD_UP)) { PlaySE(SE_SELECT); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; do { @@ -421,12 +421,12 @@ static void HandleInputChooseTarget(void) if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor]) i = 0; } while (i == 0); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039AD8; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } else if (gMain.newKeys & (DPAD_RIGHT | DPAD_DOWN)) { PlaySE(SE_SELECT); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039B2C; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; do { @@ -463,7 +463,7 @@ static void HandleInputChooseTarget(void) if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor]) i = 0; } while (i == 0); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039AD8; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } } @@ -536,7 +536,7 @@ static void HandleInputChooseMove(void) else gMultiUsePlayerCursor = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = sub_8039AD8; + gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } } else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) diff --git a/src/battle_main.c b/src/battle_main.c index dd31e12d5..42f0fb2ad 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -96,7 +96,7 @@ static void SpriteCb_WildMonShowHealthbox(struct Sprite *sprite); static void SpriteCb_WildMonAnimate(struct Sprite *sprite); static void sub_80398D0(struct Sprite *sprite); static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); -static void sub_8039AF4(struct Sprite *sprite); +static void SpriteCb_BlinkVisible(struct Sprite *sprite); static void SpriteCallbackDummy_3(struct Sprite *sprite); static void oac_poke_ally_(struct Sprite *sprite); static void SpecialStatusesClear(void); @@ -2798,31 +2798,31 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite) } } -void sub_8039AD8(struct Sprite *sprite) +// Used when selecting a move, which can hit multiple targets, in double battles. +void SpriteCb_ShowAsMoveTarget(struct Sprite *sprite) { sprite->data[3] = 8; sprite->data[4] = sprite->invisible; - sprite->callback = sub_8039AF4; + sprite->callback = SpriteCb_BlinkVisible; } -static void sub_8039AF4(struct Sprite *sprite) +static void SpriteCb_BlinkVisible(struct Sprite *sprite) { - sprite->data[3]--; - if (sprite->data[3] == 0) + if (--sprite->data[3] == 0) { sprite->invisible ^= 1; sprite->data[3] = 8; } } -void sub_8039B2C(struct Sprite *sprite) +void SpriteCb_HideAsMoveTarget(struct Sprite *sprite) { sprite->invisible = sprite->data[4]; sprite->data[4] = FALSE; sprite->callback = SpriteCallbackDummy_2; } -void sub_8039B58(struct Sprite *sprite) +void SpriteCb_OpponentMonFromBall(struct Sprite *sprite) { if (sprite->affineAnimEnded) { @@ -2965,7 +2965,7 @@ static void SpriteCB_BounceEffect(struct Sprite *sprite) #undef sBouncerSpriteId #undef sWhich -void sub_8039E44(struct Sprite *sprite) +void SpriteCb_PlayerMonFromBall(struct Sprite *sprite) { if (sprite->affineAnimEnded) BattleAnimateBackSprite(sprite, sprite->sSpeciesId); @@ -5547,7 +5547,7 @@ static void HandleAction_UseItem(void) ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); - if (gLastUsedItem <= ITEM_PREMIER_BALL) // is ball + if (gLastUsedItem <= LAST_BALL) // is ball { gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; } diff --git a/src/bike.c b/src/bike.c index 4d67cfdd5..5cdf066a9 100644 --- a/src/bike.c +++ b/src/bike.c @@ -7,7 +7,6 @@ #include "metatile_behavior.h" #include "overworld.h" #include "sound.h" -#include "constants/flags.h" #include "constants/map_types.h" #include "constants/songs.h" diff --git a/src/braille_puzzles.c b/src/braille_puzzles.c index a3862c716..5dee9dd4b 100644 --- a/src/braille_puzzles.c +++ b/src/braille_puzzles.c @@ -6,7 +6,6 @@ #include "sound.h" #include "task.h" #include "constants/field_effects.h" -#include "constants/flags.h" #include "constants/maps.h" #include "constants/songs.h" #include "constants/species.h" diff --git a/src/confetti_util.c b/src/confetti_util.c new file mode 100644 index 000000000..3bda3ab53 --- /dev/null +++ b/src/confetti_util.c @@ -0,0 +1,218 @@ +#include "global.h" +#include "confetti_util.h" +#include "malloc.h" +#include "main.h" +#include "digit_obj_util.h" + +static EWRAM_DATA struct +{ + u8 count; + struct ConfettiUtil *array; +} *sWork = NULL; + +static void sub_81520A8(void *dest, u16 value, u8 left, u8 top, u8 width, u8 height) // Unused. +{ + u8 i; + u8 j; + u8 x; + u8 y; + + for (i = 0, y = top; i < height; i++) + { + for (x = left, j = 0; j < width; j++) + { + *(u16 *)((dest) + (y * 64 + x * 2)) = value; + x = (x + 1) % 32; + } + y = (y + 1) % 32; + } +} + +static void sub_8152134(void *dest, const u16 *src, u8 left, u8 top, u8 width, u8 height) // Unused. +{ + u8 i; + u8 j; + u8 x; + u8 y; + const u16 *_src; + + for (i = 0, _src = src, y = top; i < height; i++) + { + for (x = left, j = 0; j < width; j++) + { + *(u16 *)((dest) + (y * 64 + x * 2)) = *(_src++); + x = (x + 1) % 32; + } + y = (y + 1) % 32; + } +} + +bool32 ConfettiUtil_Init(u8 count) +{ + u8 i = 0; + + if (count == 0) + return FALSE; + if (count > 64) + count = 64; + + sWork = AllocZeroed(sizeof(*sWork)); + if (sWork == NULL) + return FALSE; + sWork->array = AllocZeroed(count * sizeof(struct ConfettiUtil)); + if (sWork->array == NULL) + { + FREE_AND_SET_NULL(sWork); + return FALSE; + } + + sWork->count = count; + for (i = 0; i < count; i++) + { + memcpy(&sWork->array[i].oam, &gDummyOamData, sizeof(struct OamData)); + sWork->array[i].dummied = TRUE; + } + + return TRUE; +} + +bool32 ConfettiUtil_Free(void) +{ + u8 i = 0; + + if (sWork == NULL) + return FALSE; + + for (i = 0; i < sWork->count; i++) + memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); + + memset(sWork->array, 0, sWork->count * sizeof(struct ConfettiUtil)); + FREE_AND_SET_NULL(sWork->array); + memset(sWork, 0, sizeof(*sWork)); + FREE_AND_SET_NULL(sWork); + + return TRUE; +} + +bool32 ConfettiUtil_Update(void) +{ + u8 i = 0; + + if (sWork == NULL || sWork->array == NULL) + return FALSE; + + for (i = 0; i < sWork->count; i++) + { + if (sWork->array[i].active && sWork->array[i].allowUpdates) + { + if (sWork->array[i].callback != NULL) + sWork->array[i].callback(&sWork->array[i]); + + if (sWork->array[i].dummied) + { + memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); + } + else + { + sWork->array[i].oam.y = sWork->array[i].y + sWork->array[i].yDelta; + sWork->array[i].oam.x = sWork->array[i].x + sWork->array[i].xDelta; + sWork->array[i].oam.priority = sWork->array[i].priority; + sWork->array[i].oam.tileNum = sWork->array[i].tileNum; + memcpy(&gMain.oamBuffer[i + 64], &sWork->array[i], sizeof(struct OamData)); + } + } + } + + return TRUE; +} + +static bool32 SetAnimAndTileNum(struct ConfettiUtil *structPtr, u8 animNum) +{ + u16 tileStart; + + if (structPtr == NULL) + return FALSE; + + tileStart = GetSpriteTileStartByTag(structPtr->tileTag); + if (tileStart == 0xFFFF) + return FALSE; + + structPtr->animNum = animNum; + structPtr->tileNum = (GetTilesPerImage(structPtr->oam.shape, structPtr->oam.size) * animNum) + tileStart; + return TRUE; +} + +u8 ConfettiUtil_SetCallback(u8 id, void (*func)(struct ConfettiUtil *)) +{ + if (sWork == NULL || id >= sWork->count) + return 0xFF; + else if (!sWork->array[id].active) + return 0xFF; + + sWork->array[id].callback = func; + return id; +} + +u8 ConfettiUtil_SetData(u8 id, u8 dataArrayId, s16 dataValue) +{ + if (sWork == NULL || id >= sWork->count) + return 0xFF; + else if (!sWork->array[id].active || dataArrayId > ARRAY_COUNT(sWork->array[id].data) - 1) // - 1 b/c last slot is reserved for taskId + return 0xFF; + + sWork->array[id].data[dataArrayId] = dataValue; + return id; +} + +u8 ConfettiUtil_AddNew(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 animNum, u8 priority) +{ + struct ConfettiUtil *structPtr = NULL; + u8 i; + + if (sWork == NULL || oam == NULL) + return 0xFF; + + for (i = 0; i < sWork->count; i++) + { + if (!sWork->array[i].active) + { + structPtr = &sWork->array[i]; + memset(structPtr, 0, sizeof(*structPtr)); + structPtr->id = i; + structPtr->active = TRUE; + structPtr->allowUpdates = TRUE; + break; + } + } + + if (structPtr == NULL) + return 0xFF; + + memcpy(&structPtr->oam, oam, sizeof(*oam)); + structPtr->tileTag = tileTag; + structPtr->palTag = palTag; + structPtr->x = x; + structPtr->y = y; + structPtr->oam.paletteNum = IndexOfSpritePaletteTag(palTag); + if (priority < 4) + { + structPtr->priority = priority; + structPtr->oam.priority = priority; + } + SetAnimAndTileNum(structPtr, animNum); + + return structPtr->id; +} + +u8 ConfettiUtil_Remove(u8 id) +{ + if (sWork == NULL || !sWork->array[id].active) + return 0xFF; + + memset(&sWork->array[id], 0, sizeof(struct ConfettiUtil)); + sWork->array[id].oam.y = 160; + sWork->array[id].oam.x = 240; + sWork->array[id].dummied = TRUE; + memcpy(&gMain.oamBuffer[id + 64], &gDummyOamData, sizeof(struct OamData)); + return id; +} diff --git a/src/contest.c b/src/contest.c index 58628e35d..0b56569cb 100644 --- a/src/contest.c +++ b/src/contest.c @@ -7,7 +7,6 @@ #include "constants/moves.h" #include "constants/songs.h" #include "constants/species.h" -#include "constants/flags.h" #include "battle.h" #include "battle_anim.h" #include "contest.h" @@ -31,14 +30,14 @@ #include "tv.h" #include "scanline_effect.h" #include "util.h" -#include "contest_link_80F57C4.h" +#include "contest_util.h" #include "dma3.h" #include "battle_message.h" #include "event_scripts.h" #include "event_data.h" #include "strings.h" #include "contest_effect.h" -#include "contest_link_80FC4F4.h" +#include "contest_link.h" #include "script_pokemon_util_80F87D8.h" #include "international_string_util.h" #include "data.h" @@ -155,7 +154,7 @@ static void Contest_StartTextPrinter(const u8 *, u32); static void ContestBG_FillBoxWithIncrementingTile(u8, u16, u8, u8, u8, u8, u8, s16); static bool32 Contest_RunTextPrinters(void); static void Contest_SetBgCopyFlags(u32 flagIndex); -static void sub_80DBD18(void); +static void CalculateFinalScores(void); static void sub_80DD080(u8); static void sub_80DE9DC(u8); static void sub_80DCBE8(u8, u8); @@ -184,7 +183,7 @@ static void sub_80DC3AC(void); static bool8 sub_80DC3C4(void); static void ContestBG_FillBoxWithTile(u8, u16, u8, u8, u8, u8, u8); static void Contest_PrintTextToBg0WindowStd(u32, const u8 *); -static s16 sub_80DBD34(u8); +static s16 GetContestantRound2Points(u8); static void DetermineFinalStandings(void); static bool8 sub_80DBF30(s32, s32, struct UnknownContestStruct6 *); static void sub_80DC0F4(u8); @@ -221,9 +220,9 @@ static void SwapMoveDescAndContestTilemaps(void); // EWRAM vars. EWRAM_DATA struct ContestPokemon gContestMons[CONTESTANT_COUNT] = {0}; EWRAM_DATA s16 gContestMonConditions[CONTESTANT_COUNT] = {0}; -EWRAM_DATA s16 gUnknown_02039F08[CONTESTANT_COUNT] = {0}; +EWRAM_DATA s16 gContestMonTotalPoints[CONTESTANT_COUNT] = {0}; EWRAM_DATA s16 gUnknown_02039F10[CONTESTANT_COUNT] = {0}; -EWRAM_DATA s16 gUnknown_02039F18[CONTESTANT_COUNT] = {0}; +EWRAM_DATA s16 gContestMonRound2Points[CONTESTANT_COUNT] = {0}; EWRAM_DATA u8 gContestFinalStandings[CONTESTANT_COUNT] = {0}; EWRAM_DATA u8 gContestMonPartyIndex = 0; EWRAM_DATA u8 gContestPlayerMonIndex = 0; @@ -239,7 +238,7 @@ EWRAM_DATA u8 gHighestRibbonRank = 0; EWRAM_DATA struct ContestResources *gContestResources = NULL; EWRAM_DATA u8 sContestBgCopyFlags = 0; EWRAM_DATA struct ContestWinner gCurContestWinner = {0}; -EWRAM_DATA u8 gUnknown_02039F5C = 0; +EWRAM_DATA bool8 gUnknown_02039F5C = 0; EWRAM_DATA u8 gUnknown_02039F5D = 0; // IWRAM common vars. @@ -2490,7 +2489,7 @@ static void sub_80DA5E8(u8 taskId) gBattle_BG2_Y = 0; for (i = 0; i < CONTESTANT_COUNT; i++) gUnknown_02039F10[i] = eContestantStatus[i].pointTotal; - sub_80DBD18(); + CalculateFinalScores(); ContestClearGeneralTextWindow(); if (!(gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)) BravoTrainerPokemonProfile_BeforeInterview1(eContestantStatus[gContestPlayerMonIndex].prevMove); @@ -3367,22 +3366,22 @@ bool8 Contest_IsMonsTurnDisabled(u8 a) return FALSE; } -static void sub_80DBCE0(u8 contestant) +static void CalculateTotalPointsForContestant(u8 contestant) { - gUnknown_02039F18[contestant] = sub_80DBD34(contestant); - gUnknown_02039F08[contestant] = gContestMonConditions[contestant] + gUnknown_02039F18[contestant]; + gContestMonRound2Points[contestant] = GetContestantRound2Points(contestant); + gContestMonTotalPoints[contestant] = gContestMonConditions[contestant] + gContestMonRound2Points[contestant]; } -static void sub_80DBD18(void) +static void CalculateFinalScores(void) { s32 i; for (i = 0; i < CONTESTANT_COUNT; i++) - sub_80DBCE0(i); + CalculateTotalPointsForContestant(i); DetermineFinalStandings(); } -static s16 sub_80DBD34(u8 contestant) +static s16 GetContestantRound2Points(u8 contestant) { return gUnknown_02039F10[contestant] * 2; } @@ -3411,7 +3410,7 @@ static void DetermineFinalStandings(void) for (i = 0; i < CONTESTANT_COUNT; i++) { - sp8[i].unk0 = gUnknown_02039F08[i]; + sp8[i].unk0 = gContestMonTotalPoints[i]; sp8[i].unk4 = gContestMonConditions[i]; sp8[i].unk8 = randomOrdering[i]; sp8[i].unkC = i; @@ -5313,22 +5312,22 @@ bool8 sub_80DEDA8(u8 rank) } if (rank != 0xFE) { - u8 r4 = sub_80DEFA8(rank, 1); + u8 id = sub_80DEFA8(rank, 1); - gSaveBlock1Ptr->contestWinners[r4].personality = gContestMons[i].personality; - gSaveBlock1Ptr->contestWinners[r4].species = gContestMons[i].species; - gSaveBlock1Ptr->contestWinners[r4].trainerId = gContestMons[i].otId; - StringCopy(gSaveBlock1Ptr->contestWinners[r4].monName, gContestMons[i].nickname); - StringCopy(gSaveBlock1Ptr->contestWinners[r4].trainerName, gContestMons[i].trainerName); + gSaveBlock1Ptr->contestWinners[id].personality = gContestMons[i].personality; + gSaveBlock1Ptr->contestWinners[id].species = gContestMons[i].species; + gSaveBlock1Ptr->contestWinners[id].trainerId = gContestMons[i].otId; + StringCopy(gSaveBlock1Ptr->contestWinners[id].monName, gContestMons[i].nickname); + StringCopy(gSaveBlock1Ptr->contestWinners[id].trainerName, gContestMons[i].trainerName); if(gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) - gSaveBlock1Ptr->contestWinners[r4].contestRank = CONTEST_RANK_LINK; + gSaveBlock1Ptr->contestWinners[id].contestRank = CONTEST_RANK_LINK; else - gSaveBlock1Ptr->contestWinners[r4].contestRank = gSpecialVar_ContestRank; + gSaveBlock1Ptr->contestWinners[id].contestRank = gSpecialVar_ContestRank; if (rank != 0xFF) - gSaveBlock1Ptr->contestWinners[r4].contestCategory = gSpecialVar_ContestCategory; + gSaveBlock1Ptr->contestWinners[id].contestCategory = gSpecialVar_ContestCategory; else - gSaveBlock1Ptr->contestWinners[r4].contestCategory = r7; + gSaveBlock1Ptr->contestWinners[id].contestCategory = r7; } else { @@ -5354,24 +5353,24 @@ u8 sub_80DEFA8(u8 rank, u8 b) case CONTEST_RANK_MASTER: if (b != 0) { - for (i = 5; i >= 1; i--) + for (i = NUM_CONTEST_HALL_WINNERS - 1; i >= 1; i--) memcpy(&gSaveBlock1Ptr->contestWinners[i], &gSaveBlock1Ptr->contestWinners[i - 1], sizeof(struct ContestWinner)); } return 0; - default: // CONTEST_RANK_LINK + default: switch (gSpecialVar_ContestCategory) { case CONTEST_CATEGORY_COOL: - return 8; + return CONTEST_WINNER_MUSEUM_COOL - 1; case CONTEST_CATEGORY_BEAUTY: - return 9; + return CONTEST_WINNER_MUSEUM_BEAUTY - 1; case CONTEST_CATEGORY_CUTE: - return 10; + return CONTEST_WINNER_MUSEUM_CUTE - 1; case CONTEST_CATEGORY_SMART: - return 11; + return CONTEST_WINNER_MUSEUM_SMART - 1; case CONTEST_CATEGORY_TOUGH: default: - return 12; + return CONTEST_WINNER_MUSEUM_TOUGH - 1; } } } @@ -5471,7 +5470,7 @@ static void sub_80DF250(void) gContestResources->field_1c[r1].unkD |= 1; for (i = 0; i < CONTESTANT_COUNT; i++) { - if (i != var_38 && gUnknown_02039F08[var_38] - gUnknown_02039F08[i] <= 50) + if (i != var_38 && gContestMonTotalPoints[var_38] - gContestMonTotalPoints[i] <= 50) gContestResources->field_1c[i].unkD |= 4; if (!gContestResources->field_1c[i].unkE_2) @@ -5491,7 +5490,7 @@ static void sub_80DF250(void) { if (gContestMonConditions[i] > gContestMonConditions[j]) r12 = TRUE; - if (gUnknown_02039F18[i] > gUnknown_02039F18[j]) + if (gContestMonRound2Points[i] > gContestMonRound2Points[j]) r8 = TRUE; } if (!r12 && !r8) @@ -5582,7 +5581,7 @@ static void sub_80DF4F8(void) { if (gContestMonConditions[r7] < gContestMonConditions[i]) r9++; - if (gUnknown_02039F18[r7] < gUnknown_02039F18[i]) + if (gContestMonRound2Points[r7] < gContestMonRound2Points[i]) r10++; } diff --git a/src/contest_link_80FC4F4.c b/src/contest_link.c similarity index 96% rename from src/contest_link_80FC4F4.c rename to src/contest_link.c index 64591e00b..692c58603 100644 --- a/src/contest_link_80FC4F4.c +++ b/src/contest_link.c @@ -6,7 +6,7 @@ #include "pokemon.h" #include "random.h" #include "task.h" -#include "constants/flags.h" +#include "contest_link.h" static void sub_80FC5C0(u8); static void sub_80FC5DC(u8); @@ -296,14 +296,14 @@ void sub_80FCACC(u8 taskId) case 0: if (IsLinkTaskFinished()) { - if (sub_80FC4F4(gUnknown_02039F08, sizeof(gUnknown_02039F08)) == 1) + if (sub_80FC4F4(gContestMonTotalPoints, sizeof(gContestMonTotalPoints)) == 1) gTasks[taskId].data[0]++; } break; case 1: if (sub_80FC55C()) { - memcpy(gUnknown_02039F08, gBlockRecvBuffer[gUnknown_02039F2B], sizeof(gUnknown_02039F08)); + memcpy(gContestMonTotalPoints, gBlockRecvBuffer[gUnknown_02039F2B], sizeof(gContestMonTotalPoints)); gTasks[taskId].data[0]++; } break; @@ -334,14 +334,14 @@ void sub_80FCACC(u8 taskId) case 6: if (IsLinkTaskFinished()) { - if (sub_80FC4F4(gUnknown_02039F18, sizeof(gUnknown_02039F18)) == 1) + if (sub_80FC4F4(gContestMonRound2Points, sizeof(gContestMonRound2Points)) == 1) gTasks[taskId].data[0]++; } break; case 7: if (sub_80FC55C()) { - memcpy(gUnknown_02039F18, gBlockRecvBuffer[gUnknown_02039F2B], sizeof(gUnknown_02039F18)); + memcpy(gContestMonRound2Points, gBlockRecvBuffer[gUnknown_02039F2B], sizeof(gContestMonRound2Points)); gTasks[taskId].data[0]++; } break; diff --git a/src/contest_link_81D9DE4.c b/src/contest_link_util.c similarity index 100% rename from src/contest_link_81D9DE4.c rename to src/contest_link_util.c diff --git a/src/contest_painting.c b/src/contest_painting.c index 7f33cac09..5dd4a70a5 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -170,7 +170,7 @@ void SetContestWinnerForPainting(int contestWinnerId) u8 *ptr2 = &gUnknown_02039F5C; gCurContestWinner = gSaveBlock1Ptr->contestWinners[contestWinnerId - 1]; *ptr1 = contestWinnerId - 1; - *ptr2 = 0; + *ptr2 = FALSE; } void CB2_ContestPainting(void) @@ -281,7 +281,7 @@ static void InitContestPaintingWindow(void) ShowBg(1); } -static void PrintContestPaintingCaption(u8 contestType, u8 arg1) +static void PrintContestPaintingCaption(u8 contestType, bool8 arg1) { int x; u8 category; @@ -519,12 +519,14 @@ _081303F8:\n\ } #endif -static void LoadContestPaintingFrame(u8 contestWinnerId, u8 arg1) +#define VRAM_PICTURE_DATA(x, y) (((u16 *)(BG_SCREEN_ADDR(12)))[(y) * 32 + (x)]) + +static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 arg1) { u8 x, y; LoadPalette(gPictureFramePalettes, 0, 0x100); - if (arg1 == 1) + if (arg1 == TRUE) { switch (gContestPaintingWinner->contestCategory / 3) { @@ -550,8 +552,6 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, u8 arg1) break; } -#define VRAM_PICTURE_DATA(x, y) (((u16 *)(BG_SCREEN_ADDR(12)))[(y) * 32 + (x)]) - // Set the background for (y = 0; y < 20; y++) { @@ -569,8 +569,6 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, u8 arg1) // Re-set the entire top row to the first top frame part for (x = 0; x < 16; x++) VRAM_PICTURE_DATA(x + 7, 2) = (*gContestMonPixels)[2][7]; - -#undef VRAM_PICTURE_DATA } else if (contestWinnerId < 8) { @@ -605,6 +603,8 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, u8 arg1) } } +#undef VRAM_PICTURE_DATA + static void InitPaintingMonOamData(u8 contestWinnerId) { //Some hacks just to get the asm to match @@ -692,7 +692,7 @@ static void DoContestPaintingImageProcessing(u8 imageEffect) LoadPalette(gContestPaintingMonPalette, 0x100, 0x200); } -static void CreateContestPaintingPicture(u8 contestWinnerId, u8 arg1) +static void CreateContestPaintingPicture(u8 contestWinnerId, bool8 arg1) { AllocPaintingResources(); InitContestMonPixels(gContestPaintingWinner->species, 0); diff --git a/src/contest_link_80F57C4.c b/src/contest_util.c similarity index 57% rename from src/contest_link_80F57C4.c rename to src/contest_util.c index 0cecaed07..e82560a6e 100644 --- a/src/contest_link_80F57C4.c +++ b/src/contest_util.c @@ -4,8 +4,8 @@ #include "battle_gfx_sfx_util.h" #include "bg.h" #include "contest.h" -#include "contest_link_80F57C4.h" -#include "contest_link_80FC4F4.h" +#include "contest_util.h" +#include "contest_link.h" #include "data.h" #include "decompress.h" #include "dma3.h" @@ -36,101 +36,120 @@ #include "tv.h" #include "util.h" #include "window.h" +#include "constants/field_specials.h" #include "constants/game_stat.h" #include "constants/rgb.h" #include "constants/songs.h" #include "constants/tv.h" -#include "constants/vars.h" #include "contest.h" -struct ContestLinkUnk0 -{ - u8 unk0; - u8 unk1; - u8 taskId; - u8 unk3; - u8 unk4; - u8 unk5; - u8 unk6; - u8 unk7; - u8 spriteId; - u8 unk9; - u8 unkA; - s16 unkC[4]; - u8 unk14; - u8 filler15[0x3]; +enum { + SLIDING_TEXT_OFFSCREEN, + SLIDING_TEXT_ENTERING, + SLIDING_TEXT_ARRIVED, + SLIDING_TEXT_EXITING, }; -struct ContestLinkUnk14 -{ - int unk0; - int unk4; - u32 unk8; - u32 unkC; - u8 unk10; - u8 unk11; - u8 unk12; +enum { + SLIDING_MON_ENTERED = 1, + SLIDING_MON_EXITED, }; -struct ContestLink80F57C4 +#define GET_CONTEST_WINNER_ID(i) { for ((i) = 0; (i) < CONTESTANT_COUNT && gContestFinalStandings[(i)] != 0; (i)++); } + +#define TAG_CONFETTI 3017 + +#define MAX_BAR_LENGTH 87 + +struct ContestResultsInternal { - struct ContestLinkUnk0 *unk0; - struct ContestLinkUnk14 (*unk4)[4]; - u8 *unk8; - u8 *unkC[4]; - u8 *unk1C; + u8 slidingTextBoxSpriteId; + u8 linkTextBoxSpriteId; + u8 showResultsTaskId; + u8 highlightWinnerTaskId; + u8 slidingTextBoxState; + u8 numStandingsPrinted; + u8 winnerMonSlidingState; + u8 confettiCount; + u8 winnerMonSpriteId; + bool8 destroyConfetti; + bool8 pointsFlashing; + s16 unkC[CONTESTANT_COUNT]; + u8 numBarsUpdating; }; -EWRAM_DATA struct ContestLink80F57C4 *gUnknown_0203A034 = NULL; +struct ContestMonResults +{ + int relativePreliminaryPoints; + int relativeRound2Points; + u32 barLengthPreliminary; + u32 barLengthRound2; + bool8 lostPoints; + u8 numStars; + u8 numHearts; +}; -static void sub_80F6A9C(void); -static void sub_80F71C8(void); -u8 sub_80F7310(u8, u8); -s8 sub_80F7364(u8, u8); -static void sub_80F7ED0(int, u8 *, int); -static void sub_80F7DF4(void); +struct ContestResults +{ + struct ContestResultsInternal *data; + struct ContestMonResults (*monResults)[CONTESTANT_COUNT]; + u8 *unusedBg; // Allocated/freed, never used + u8 *tilemapBuffers[4]; + u8 *unused; // Allocated/freed, never used +}; + +static EWRAM_DATA struct ContestResults *sContestResults = NULL; + +static void LoadAllContestMonIconPalettes(void); +static void LoadContestResultsTilemaps(void); +static u8 GetNumPreliminaryPoints(u8, bool8); +static s8 GetNumRound2Points(u8, bool8); +static void AddContestTextPrinter(int, u8 *, int); +static void AllocContestResults(void); +static void FreeContestResults(void); static void LoadAllContestMonIcons(u8, u8); -static void sub_80F6DC0(void); -static void sub_80F6AE8(void); -static void sub_80F5CE4(u8); -static void sub_80F5C00(void); -static void sub_80F68B4(u8); -static void sub_80F7880(void); -static void sub_80F5C24(void); -static void sub_80F707C(const u8 *); -static void sub_80F5ED8(u8); +static void LoadContestResultSprites(void); +static void TryCreateWirelessSprites(void); +static void Task_StartShowContestResults(u8 taskId); +static void CB2_StartShowContestResults(void); +static void Task_ShowContestResults(u8); +static void CB2_ShowContestResults(void); +static void VBlankCB_ShowContestResults(void); +static void Task_SlideContestResultsBg(u8); +static void Task_WaitForLinkPartnersBeforeResults(u8); static void sub_80F5F14(u8); static void sub_80F5F30(u8); -static void sub_80F5F74(u8); -static void sub_80F7144(void); -static void sub_80F68F0(u8); -s32 sub_80F6B78(const u8 *, u8); -static void sub_80F6E9C(s16, u16, u16, u16); -static void sub_80F6058(u8); -static void sub_80F7A80(u8, u8); -void sub_80F7CA8(u8); -static void sub_80F6EF4(u16); -static void sub_80F60F0(u8); -static void sub_80F616C(u8); -static void sub_80F6204(u8); -static void sub_80F73DC(u8); -static void sub_80F74BC(u8); -static void sub_80F753C(u8); -static void sub_80F77E0(u8, u8); -static void sub_80F7824(u8); -static void sub_80F6404(u8); -static void sub_80F75A8(struct Sprite *); -static void sub_80F7670(u8); -static void sub_80F7620(struct Sprite *); -static void sub_80F66B4(u8); -static void sub_80F671C(u8); -static void sub_80F677C(u8); -static void sub_80F67C4(u8); -static void sub_80F6820(u8); -static void sub_80F7E64(void); -static void sub_80F6F68(struct Sprite *); -static void sub_80F7014(struct Sprite *); -static void sub_80F6FDC(struct Sprite *); +static void Task_AnnouncePreliminaryResults(u8); +static void Task_FlashStarsAndHearts(u8); +static void Task_ShowPreliminaryResults(u8); +static void Task_AnnounceRound2Results(u8); +static void Task_ShowRound2Results(u8); +static void Task_AnnounceWinner(u8); +static void Task_DrawFinalStandingNumber(u8); +static void Task_StartHighlightWinnersBox(u8); +static void Task_HighlightWinnersBox(u8); +static void Task_ShowWinnerMonBanner(u8); +static void Task_SetSeenWinnerMon(u8); +static void Task_TryDisconnectLinkPartners(u8); +static void Task_WaitForLinkPartnersDisconnect(u8); +static void Task_TrySetContestInterviewData(u8); +static void Task_EndShowContestResults(u8); +static void CalculateContestantsResultData(void); +static void ShowLinkResultsTextBox(const u8 *); +static void HideLinkResultsTextBox(void); +static s32 DrawResultsTextWindow(const u8 *, u8); +static void StartTextBoxSlideIn(s16, u16, u16, u16); +static void UpdateContestResultBars(bool8, u8); +static void Task_UpdateContestResultBar(u8); +static void StartTextBoxSlideOut(u16); +static void BounceMonIconInBox(u8, u8); +static void Task_BounceMonIconInBox(u8); +static void SpriteCB_WinnerMonSlideIn(struct Sprite *); +static void SpriteCB_WinnerMonSlideOut(struct Sprite *); +static void Task_CreateConfetti(u8); +static void SpriteCB_TextBoxSlideIn(struct Sprite *); +static void SpriteCB_TextBoxSlideOut(struct Sprite *); +static void SpriteCB_EndTextBoxSlideIn(struct Sprite *); static void sub_80F8508(u8); static void sub_80F8568(u8); static void sub_80F8584(u8); @@ -139,7 +158,7 @@ static void sub_80F85BC(u8); static void sub_80F86B8(u8); static void sub_80F878C(u8); static void sub_80F87B4(u8); -static void sub_80F7768(struct Sprite *sprite); +static void SpriteCB_Confetti(struct Sprite *sprite); static const u16 sUnknown_0858D6B0[] = INCBIN_U16("graphics/unknown/unknown_58D6B0.gbapal"); static const u8 sUnknown_0858D6D0[] = INCBIN_U8("graphics/unknown/unknown_58D6D0.4bpp"); @@ -191,7 +210,7 @@ static const struct SpritePalette sUnknown_0858D850 = .tag = 3009, }; -static const struct OamData sOamData_858D858 = +static const struct OamData sOamData_Confetti = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -208,32 +227,32 @@ static const struct OamData sOamData_858D858 = .affineParam = 0, }; -static const struct SpriteTemplate sSpriteTemplate_858D860 = +static const struct SpriteTemplate sSpriteTemplate_Confetti = { - .tileTag = 3017, - .paletteTag = 3017, - .oam = &sOamData_858D858, + .tileTag = TAG_CONFETTI, + .paletteTag = TAG_CONFETTI, + .oam = &sOamData_Confetti, .anims = gDummySpriteAnimTable, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_80F7768 + .callback = SpriteCB_Confetti }; -static const struct CompressedSpriteSheet sUnknown_0858D878 = +static const struct CompressedSpriteSheet sSpriteSheet_Confetti = { - .data = gContestConfetti_Gfx, + .data = gConfetti_Gfx, .size = 0x220, - .tag = 3017 + .tag = TAG_CONFETTI }; -static const struct CompressedSpritePalette sUnknown_0858D880 = +static const struct CompressedSpritePalette sSpritePalette_Confetti = { - .data = gContestConfetti_Pal, - .tag = 3017 + .data = gConfetti_Pal, + .tag = TAG_CONFETTI }; -static const struct BgTemplate sUnknown_0858D888[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 0, @@ -273,7 +292,7 @@ static const struct BgTemplate sUnknown_0858D888[] = } }; -static const struct WindowTemplate sUnknown_0858D898[] = +static const struct WindowTemplate sWindowTemplates[] = { { .bg = 1, @@ -353,17 +372,17 @@ static const struct SpriteSheet sUnknown_0858D8E0 = static const u8 sContestLinkTextColors[4] = {TEXT_COLOR_WHITE, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5}; -void sub_80F57C4(void) +static void InitContestResultsDisplay(void) { int i; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP); ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, sUnknown_0858D888, ARRAY_COUNT(sUnknown_0858D888)); - for (i = 0; i < 4; i++) - SetBgTilemapBuffer(i, gUnknown_0203A034->unkC[i]); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); + for (i = 0; i < (int)ARRAY_COUNT(sContestResults->tilemapBuffers); i++) + SetBgTilemapBuffer(i, sContestResults->tilemapBuffers[i]); - InitWindows(sUnknown_0858D898); + InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); SetGpuReg(REG_OFFSET_MOSAIC, 0); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ | WININ_WIN1_CLR); @@ -398,34 +417,35 @@ void sub_80F57C4(void) gBattle_WIN1V = 0; } -void sub_80F591C(void) +static void LoadContestResultsBgGfx(void) { int i, j; - s8 var0, var1; + s8 numStars, round2Points; u16 tile1, tile2; - LZDecompressVram(gUnknown_08C19588, (void *)BG_CHAR_ADDR(0)); + LZDecompressVram(gContestResults_Gfx, (void *)BG_CHAR_ADDR(0)); CopyToBgTilemapBuffer(3, gUnknown_08C1A12C, 0, 0); CopyToBgTilemapBuffer(2, gUnknown_08C1A000, 0, 0); CopyToBgTilemapBuffer(0, gUnknown_08C19EEC, 0, 0); - sub_80F71C8(); - LoadCompressedPalette(gUnknown_08C1A2B4, 0, 0x200); + LoadContestResultsTilemaps(); + LoadCompressedPalette(gContestResults_Pal, 0, 0x200); LoadPalette(sUnknown_0858D6B0, 0xF0, 0x20); - for (i = 0; i < 4; i++) + for (i = 0; i < CONTESTANT_COUNT; i++) { - var0 = sub_80F7310(i, 1); - var1 = sub_80F7364(i, 1); + numStars = GetNumPreliminaryPoints(i, TRUE); + round2Points = GetNumRound2Points(i, TRUE); for (j = 0; j < 10; j++) { tile1 = 0x60B2; - if (j < var0) + if (j < numStars) tile1 += 2; - if (j < abs(var1)) + // Abs of round2Points is number of hearts + if (j < abs(round2Points)) { tile2 = 0x60A4; - if (var1 < 0) + if (round2Points < 0) tile2 += 2; } else @@ -448,7 +468,7 @@ void sub_80F591C(void) ShowBg(3); } -static void sub_80F5A74(u8 monIndex) +static void LoadContestMonName(u8 monIndex) { struct ContestPokemon *mon = &gContestMons[monIndex]; u8 *str = gDisplayedStringBattle; @@ -456,58 +476,58 @@ static void sub_80F5A74(u8 monIndex) str = StringCopy(gDisplayedStringBattle, gText_ColorDarkGrey); StringCopy(str, mon->nickname); - sub_80F7ED0(monIndex, gDisplayedStringBattle, 0); + AddContestTextPrinter(monIndex, gDisplayedStringBattle, 0); StringCopy(str, gText_Slash); StringAppend(str, mon->trainerName); - sub_80F7ED0(monIndex, gDisplayedStringBattle, 50); + AddContestTextPrinter(monIndex, gDisplayedStringBattle, 50); } -void sub_80F5AE0(void) +static void LoadAllContestMonNames(void) { int i; for (i = 0; i < CONTESTANT_COUNT; i++) - sub_80F5A74(i); + LoadContestMonName(i); CopyBgTilemapBufferToVram(1); } -void sub_80F5B00(void) +static void CB2_StartShowContestResults(void) { - gPaletteFade.bufferTransferDisabled = 1; + gPaletteFade.bufferTransferDisabled = TRUE; SetVBlankCallback(NULL); - sub_80F7DF4(); - sub_80F57C4(); + AllocContestResults(); + InitContestResultsDisplay(); ScanlineEffect_Clear(); ResetPaletteFade(); ResetSpriteData(); ResetTasks(); FreeAllSpritePalettes(); - sub_80F591C(); - sub_80F6A9C(); - LoadAllContestMonIcons(0, 1); - sub_80F5AE0(); - memset(gUnknown_0203A034->unk0, 0, sizeof(*gUnknown_0203A034->unk0)); - memset(gUnknown_0203A034->unk4, 0, sizeof(*gUnknown_0203A034->unk4)); - sub_80F6DC0(); - sub_80F6AE8(); + LoadContestResultsBgGfx(); + LoadAllContestMonIconPalettes(); + LoadAllContestMonIcons(0, TRUE); + LoadAllContestMonNames(); + memset(sContestResults->data, 0, sizeof(*sContestResults->data)); + memset(sContestResults->monResults, 0, sizeof(*sContestResults->monResults)); + LoadContestResultSprites(); + TryCreateWirelessSprites(); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK); - gPaletteFade.bufferTransferDisabled = 0; - gUnknown_0203A034->unk0->taskId = CreateTask(sub_80F5CE4, 5); - SetMainCallback2(sub_80F5C00); + gPaletteFade.bufferTransferDisabled = FALSE; + sContestResults->data->showResultsTaskId = CreateTask(Task_ShowContestResults, 5); + SetMainCallback2(CB2_ShowContestResults); gBattle_WIN1H = 0x00F0; gBattle_WIN1V = 0x80A0; - CreateTask(sub_80F68B4, 20); - sub_80F7880(); + CreateTask(Task_SlideContestResultsBg, 20); + CalculateContestantsResultData(); if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS) - gPaletteFade.bufferTransferDisabled = 1; + gPaletteFade.bufferTransferDisabled = TRUE; else PlayBGM(MUS_CON_K); - SetVBlankCallback(sub_80F5C24); + SetVBlankCallback(VBlankCB_ShowContestResults); } -static void sub_80F5C00(void) +static void CB2_ShowContestResults(void) { AnimateSprites(); BuildOamBuffer(); @@ -517,7 +537,7 @@ static void sub_80F5C00(void) CopyBgTilemapBufferToVram(2); } -static void sub_80F5C24(void) +static void VBlankCB_ShowContestResults(void) { SetGpuReg(REG_OFFSET_BG0HOFS, gBattle_BG0_X); SetGpuReg(REG_OFFSET_BG0VOFS, gBattle_BG0_Y); @@ -537,29 +557,33 @@ static void sub_80F5C24(void) ScanlineEffect_InitHBlankDmaTransfer(); } -static void sub_80F5CE4(u8 taskId) +#define tState data[0] +#define tTimer data[1] +#define tCounter data[2] + +static void Task_ShowContestResults(u8 taskId) { u16 var; if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: SaveLinkContestResults(); if (gContestFinalStandings[gContestPlayerMonIndex] == 0) { IncrementGameStat(GAME_STAT_WON_LINK_CONTEST); - gSpecialVar_0x8005 = 8; + gSpecialVar_0x8005 = TVSHOW_CONTEST_LIVE_UPDATES; InterviewBefore(); - if (gSpecialVar_Result != 1) + if (gSpecialVar_Result != TRUE) InterviewAfter(); } - TryGainNewFanFromCounter(2); + TryGainNewFanFromCounter(FANCOUNTER_FINISHED_CONTEST); sub_80DEDA8(gSpecialVar_ContestRank); sub_80DEDA8(0xFE); - gUnknown_02039F5C = 1; + gUnknown_02039F5C = TRUE; gUnknown_02039F5D = sub_80DEFA8(0xFE, 0); var = VarGet(VAR_CONTEST_HALL_STATE); VarSet(VAR_CONTEST_HALL_STATE, 0); @@ -567,26 +591,26 @@ static void sub_80F5CE4(u8 taskId) TrySavingData(SAVE_LINK); ClearContinueGameWarpStatus2(); VarSet(VAR_CONTEST_HALL_STATE, var); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 1: - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; if (!(gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS)) - gTasks[taskId].data[0] = 100; + gTasks[taskId].tState = 100; break; case 2: if (IsLinkTaskFinished()) { sub_800ADF8(); - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } return; case 3: if (IsLinkTaskFinished() == TRUE) { PlayBGM(MUS_CON_K); - gPaletteFade.bufferTransferDisabled = 0; - gTasks[taskId].data[0]++; + gPaletteFade.bufferTransferDisabled = FALSE; + gTasks[taskId].tState++; break; } return; @@ -595,11 +619,11 @@ static void sub_80F5CE4(u8 taskId) if (!gPaletteFade.active) { - gTasks[taskId].data[0] = 0; + gTasks[taskId].tState = 0; if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) { - sub_80F707C(gText_CommunicationStandby); - gTasks[taskId].func = sub_80F5ED8; + ShowLinkResultsTextBox(gText_CommunicationStandby); + gTasks[taskId].func = Task_WaitForLinkPartnersBeforeResults; } else { @@ -609,15 +633,15 @@ static void sub_80F5CE4(u8 taskId) sub_80DEDA8(gSpecialVar_ContestRank); sub_80DEDA8(0xFE); - gUnknown_02039F5C = 1; + gUnknown_02039F5C = TRUE; gUnknown_02039F5D = sub_80DEFA8(0xFE, 0); - TryGainNewFanFromCounter(2); - gTasks[taskId].func = sub_80F5F74; + TryGainNewFanFromCounter(FANCOUNTER_FINISHED_CONTEST); + gTasks[taskId].func = Task_AnnouncePreliminaryResults; } } } -static void sub_80F5ED8(u8 taskId) +static void Task_WaitForLinkPartnersBeforeResults(u8 taskId) { if (gReceivedRemoteLinkPlayers) { @@ -636,194 +660,193 @@ static void sub_80F5F30(u8 taskId) if (IsLinkTaskFinished()) { DestroyTask(taskId); - gTasks[gUnknown_0203A034->unk0->taskId].func = sub_80F5F74; - sub_80F7144(); + gTasks[sContestResults->data->showResultsTaskId].func = Task_AnnouncePreliminaryResults; + HideLinkResultsTextBox(); } } -static void sub_80F5F74(u8 taskId) +static void Task_AnnouncePreliminaryResults(u8 taskId) { - s16 var0; + s16 x; - if (gTasks[taskId].data[0] == 0) + if (gTasks[taskId].tState == 0) { - CreateTask(sub_80F68F0, 20); - var0 = sub_80F6B78(gText_AnnouncingResults, gUnknown_0203A034->unk0->unk0); - sub_80F6E9C(var0, 144, 120, 1088); - gTasks[taskId].data[0]++; + CreateTask(Task_FlashStarsAndHearts, 20); + x = DrawResultsTextWindow(gText_AnnouncingResults, sContestResults->data->slidingTextBoxSpriteId); + StartTextBoxSlideIn(x, 144, 120, 1088); + gTasks[taskId].tState++; } - else if (gTasks[taskId].data[0] == 1) + else if (gTasks[taskId].tState == 1) { - if (gUnknown_0203A034->unk0->unk4 == 0) + // Wait for "Announcing Results" text to leave + if (sContestResults->data->slidingTextBoxState == SLIDING_TEXT_OFFSCREEN) { - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[0]++; + gTasks[taskId].tTimer = 0; + gTasks[taskId].tState++; } } - else if (gTasks[taskId].data[0] == 2) + else if (gTasks[taskId].tState == 2) { - if (++gTasks[taskId].data[1] == 21) + if (++gTasks[taskId].tTimer == 21) { - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[0]++; + gTasks[taskId].tTimer = 0; + gTasks[taskId].tState++; } } - else if (gTasks[taskId].data[0] == 3) + else if (gTasks[taskId].tState == 3) { - var0 = sub_80F6B78(gText_PreliminaryResults, gUnknown_0203A034->unk0->unk0); - sub_80F6E9C(var0, 144, -1, 1088); - gTasks[taskId].data[0]++; + x = DrawResultsTextWindow(gText_PreliminaryResults, sContestResults->data->slidingTextBoxSpriteId); + StartTextBoxSlideIn(x, 144, -1, 1088); + gTasks[taskId].tState++; } - else if (gTasks[taskId].data[0] == 4) + else if (gTasks[taskId].tState == 4) { - if (gUnknown_0203A034->unk0->unk4 == 2) + if (sContestResults->data->slidingTextBoxState == SLIDING_TEXT_ARRIVED) { - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = sub_80F6058; + gTasks[taskId].tState = 0; + gTasks[taskId].func = Task_ShowPreliminaryResults; } } } -static void sub_80F6058(u8 taskId) +static void Task_ShowPreliminaryResults(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: - if (!gUnknown_0203A034->unk0->unkA) + if (!sContestResults->data->pointsFlashing) { - sub_80F7A80(0, gTasks[taskId].data[2]++); - if (!gUnknown_0203A034->unk0->unk14) - gTasks[taskId].data[0] = 2; + UpdateContestResultBars(FALSE, gTasks[taskId].tCounter++); + if (sContestResults->data->numBarsUpdating == 0) + gTasks[taskId].tState = 2; else - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } break; case 1: - if (!gUnknown_0203A034->unk0->unk14) - gTasks[taskId].data[0] = 0; + if (sContestResults->data->numBarsUpdating == 0) + gTasks[taskId].tState = 0; break; case 2: - sub_80F6EF4(1088); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[2] = 0; - gTasks[taskId].func = sub_80F60F0; + StartTextBoxSlideOut(1088); + gTasks[taskId].tState = 0; + gTasks[taskId].tCounter = 0; + gTasks[taskId].func = Task_AnnounceRound2Results; break; } } -static void sub_80F60F0(u8 taskId) +static void Task_AnnounceRound2Results(u8 taskId) { - s16 var0; + s16 x; - if (gUnknown_0203A034->unk0->unk4 == 0) + if (sContestResults->data->slidingTextBoxState == SLIDING_TEXT_OFFSCREEN) { - if (++gTasks[taskId].data[1] == 21) + if (++gTasks[taskId].tTimer == 21) { - gTasks[taskId].data[1] = 0; - var0 = sub_80F6B78(gText_Round2Results, gUnknown_0203A034->unk0->unk0); - sub_80F6E9C(var0, 144, -1, 1088); + gTasks[taskId].tTimer = 0; + x = DrawResultsTextWindow(gText_Round2Results, sContestResults->data->slidingTextBoxSpriteId); + StartTextBoxSlideIn(x, 144, -1, 1088); } } - else if (gUnknown_0203A034->unk0->unk4 == 2) + else if (sContestResults->data->slidingTextBoxState == SLIDING_TEXT_ARRIVED) { - gTasks[taskId].func = sub_80F616C; + gTasks[taskId].func = Task_ShowRound2Results; } } -static void sub_80F616C(u8 taskId) +static void Task_ShowRound2Results(u8 taskId) { - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: - if (!gUnknown_0203A034->unk0->unkA) + if (!sContestResults->data->pointsFlashing) { - sub_80F7A80(1, gTasks[taskId].data[2]++); - if (!gUnknown_0203A034->unk0->unk14) - gTasks[taskId].data[0] = 2; + UpdateContestResultBars(TRUE, gTasks[taskId].tCounter++); + if (sContestResults->data->numBarsUpdating == 0) + gTasks[taskId].tState = 2; else - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } break; case 1: - if (!gUnknown_0203A034->unk0->unk14) - gTasks[taskId].data[0] = 0; + if (sContestResults->data->numBarsUpdating == 0) + gTasks[taskId].tState = 0; break; case 2: - sub_80F6EF4(1088); - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = sub_80F6204; + StartTextBoxSlideOut(1088); + gTasks[taskId].tState = 0; + gTasks[taskId].func = Task_AnnounceWinner; break; } } -static void sub_80F6204(u8 taskId) +// Task data for Task_DrawFinalStandingNumber +#define tFinalStanding data[0] +#define tMonIndex data[1] + +static void Task_AnnounceWinner(u8 taskId) { int i; - u8 newTaskId; - u8 buffer[100]; - s16 var0; - - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: - if (!gUnknown_0203A034->unk0->unk4) - gTasks[taskId].data[0]++; + if (sContestResults->data->slidingTextBoxState == SLIDING_TEXT_OFFSCREEN) + gTasks[taskId].tState++; break; case 1: - if (++gTasks[taskId].data[1] == 31) + if (++gTasks[taskId].tTimer == 31) { - gTasks[taskId].data[1] = 0; - gTasks[taskId].data[0]++; + gTasks[taskId].tTimer = 0; + gTasks[taskId].tState++; } break; case 2: for (i = 0; i < CONTESTANT_COUNT; i++) { - newTaskId = CreateTask(sub_80F73DC, 10); - gTasks[newTaskId].data[0] = gContestFinalStandings[i]; - gTasks[newTaskId].data[1] = i; + u8 newTaskId = CreateTask(Task_DrawFinalStandingNumber, 10); + gTasks[newTaskId].tFinalStanding = gContestFinalStandings[i]; + gTasks[newTaskId].tMonIndex = i; } - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; break; case 3: - if (gUnknown_0203A034->unk0->unk5 == 4) + if (sContestResults->data->numStandingsPrinted == CONTESTANT_COUNT) { - if (++gTasks[taskId].data[1] == 31) + if (++gTasks[taskId].tTimer == 31) { - gTasks[taskId].data[1] = 0; - CreateTask(sub_80F74BC, 10); - gTasks[taskId].data[0]++; - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; - - sub_80F77E0(i, 14); + gTasks[taskId].tTimer = 0; + CreateTask(Task_StartHighlightWinnersBox, 10); + gTasks[taskId].tState++; + GET_CONTEST_WINNER_ID(i); + BounceMonIconInBox(i, 14); } } break; case 4: - if (++gTasks[taskId].data[1] == 21) + if (++gTasks[taskId].tTimer == 21) { - gTasks[taskId].data[1] = 0; - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; - + u8 winnerTextBuffer[100]; + s16 x; + gTasks[taskId].tTimer = 0; + GET_CONTEST_WINNER_ID(i); StringCopy(gStringVar1, gContestMons[i].trainerName); sub_81DB5AC(gStringVar1); StringCopy(gStringVar2, gContestMons[i].nickname); - StringExpandPlaceholders(buffer, gText_Var1sVar2Won); - var0 = sub_80F6B78(buffer, gUnknown_0203A034->unk0->unk0); - sub_80F6E9C(var0, 144, -1, 1088); - gTasks[taskId].data[0]++; + StringExpandPlaceholders(winnerTextBuffer, gText_ContestantsMonWon); + x = DrawResultsTextWindow(winnerTextBuffer, sContestResults->data->slidingTextBoxSpriteId); + StartTextBoxSlideIn(x, 144, -1, 1088); + gTasks[taskId].tState++; } break; case 5: - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = sub_80F6404; + gTasks[taskId].tState = 0; + gTasks[taskId].func = Task_ShowWinnerMonBanner; break; } } -static void sub_80F6404(u8 taskId) +static void Task_ShowWinnerMonBanner(u8 taskId) { int i; u8 spriteId; @@ -832,14 +855,13 @@ static void sub_80F6404(u8 taskId) u32 personality; const struct CompressedSpritePalette *pokePal; - switch (gTasks[taskId].data[0]) + switch (gTasks[taskId].tState) { case 0: gBattle_WIN0H = 0x00F0; gBattle_WIN0V = 0x5050; - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; + GET_CONTEST_WINNER_ID(i); species = gContestMons[i].species; personality = gContestMons[i].personality; otId = gContestMons[i].otId; @@ -867,42 +889,42 @@ static void sub_80F6404(u8 taskId) spriteId = CreateSprite(&gMultiuseSpriteTemplate, 272, 80, 10); gSprites[spriteId].data[1] = species; gSprites[spriteId].oam.priority = 0; - gSprites[spriteId].callback = sub_80F75A8; - gUnknown_0203A034->unk0->spriteId = spriteId; - LoadCompressedSpriteSheet(&sUnknown_0858D878); - LoadCompressedSpritePalette(&sUnknown_0858D880); - CreateTask(sub_80F7670, 10); - gTasks[taskId].data[0]++; + gSprites[spriteId].callback = SpriteCB_WinnerMonSlideIn; + sContestResults->data->winnerMonSpriteId = spriteId; + LoadCompressedSpriteSheet(&sSpriteSheet_Confetti); + LoadCompressedSpritePalette(&sSpritePalette_Confetti); + CreateTask(Task_CreateConfetti, 10); + gTasks[taskId].tState++; break; case 1: if (++gTasks[taskId].data[3] == 1) { u8 counter; gTasks[taskId].data[3] = 0; - gTasks[taskId].data[2] += 2; - if (gTasks[taskId].data[2] > 32) - gTasks[taskId].data[2] = 32; + gTasks[taskId].tCounter += 2; + if (gTasks[taskId].tCounter > 32) + gTasks[taskId].tCounter = 32; - counter = gTasks[taskId].data[2]; + counter = gTasks[taskId].tCounter; gBattle_WIN0V = ((80 - counter) << 8) | (80 + counter); if (counter == 32) - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } break; case 2: - if (gUnknown_0203A034->unk0->unk6 == 1) - gTasks[taskId].data[0]++; + if (sContestResults->data->winnerMonSlidingState == SLIDING_MON_ENTERED) + gTasks[taskId].tState++; break; case 3: - if (++gTasks[taskId].data[1] == 121) + if (++gTasks[taskId].tTimer == 121) { - gTasks[taskId].data[1] = 0; - gSprites[gUnknown_0203A034->unk0->spriteId].callback = sub_80F7620; - gTasks[taskId].data[0]++; + gTasks[taskId].tTimer = 0; + gSprites[sContestResults->data->winnerMonSpriteId].callback = SpriteCB_WinnerMonSlideOut; + gTasks[taskId].tState++; } break; case 4: - if (gUnknown_0203A034->unk0->unk6 == 2) + if (sContestResults->data->winnerMonSlidingState == SLIDING_MON_EXITED) { u8 top = (gBattle_WIN0V >> 8); top += 2; @@ -911,25 +933,25 @@ static void sub_80F6404(u8 taskId) gBattle_WIN0V = (top << 8) | (160 - top); if (top == 80) - gTasks[taskId].data[0]++; + gTasks[taskId].tState++; } break; case 5: - if (gUnknown_0203A034->unk0->unk6 == 2) + if (sContestResults->data->winnerMonSlidingState == SLIDING_MON_EXITED) { - gUnknown_0203A034->unk0->unk9 = 1; - gTasks[taskId].data[0] = 0; - gTasks[taskId].func = sub_80F66B4; + sContestResults->data->destroyConfetti = TRUE; + gTasks[taskId].tState = 0; + gTasks[taskId].func = Task_SetSeenWinnerMon; } break; } } -static void sub_80F66B4(u8 taskId) +static void Task_SetSeenWinnerMon(u8 taskId) { int i, nationalDexNum; - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { if (!(gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)) { @@ -941,62 +963,62 @@ static void sub_80F66B4(u8 taskId) } gTasks[taskId].data[10] = 0; - gTasks[taskId].func = sub_80F671C; + gTasks[taskId].func = Task_TryDisconnectLinkPartners; } } -static void sub_80F671C(u8 taskId) +static void Task_TryDisconnectLinkPartners(u8 taskId) { if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) { if (!gTasks[taskId].data[10]) { - sub_80F707C(gText_CommunicationStandby); + ShowLinkResultsTextBox(gText_CommunicationStandby); sub_800AC34(); - gTasks[taskId].func = sub_80F677C; + gTasks[taskId].func = Task_WaitForLinkPartnersDisconnect; } } else { - gTasks[taskId].func = sub_80F67C4; + gTasks[taskId].func = Task_TrySetContestInterviewData; } } -static void sub_80F677C(u8 taskId) +static void Task_WaitForLinkPartnersDisconnect(u8 taskId) { if (!gReceivedRemoteLinkPlayers) { if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_WIRELESS) DestroyWirelessStatusIndicatorSprite(); - sub_80F7144(); - gTasks[taskId].func = sub_80F67C4; + HideLinkResultsTextBox(); + gTasks[taskId].func = Task_TrySetContestInterviewData; } } -static void sub_80F67C4(u8 taskId) +static void Task_TrySetContestInterviewData(u8 taskId) { if (!(gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK)) BravoTrainerPokemonProfile_BeforeInterview2(gContestFinalStandings[gContestPlayerMonIndex]); BeginHardwarePaletteFade(0xFF, 0, 0, 16, 0); - gTasks[taskId].func = sub_80F6820; + gTasks[taskId].func = Task_EndShowContestResults; } -static void sub_80F6820(u8 taskId) +static void Task_EndShowContestResults(u8 taskId) { if (!gPaletteFade.active) { - if (gTasks[taskId].data[1] == 0) + if (gTasks[taskId].tTimer == 0) { - DestroyTask(gUnknown_0203A034->unk0->unk3); + DestroyTask(sContestResults->data->highlightWinnerTaskId); BlendPalettes(0x0000FFFF, 16, RGB_BLACK); - gTasks[taskId].data[1]++; + gTasks[taskId].tTimer++; } - else if (gTasks[taskId].data[1] == 1) + else if (gTasks[taskId].tTimer == 1) { BlendPalettes(0xFFFF0000, 16, RGB_BLACK); - gTasks[taskId].data[1]++; + gTasks[taskId].tTimer++; } else { @@ -1005,12 +1027,16 @@ static void sub_80F6820(u8 taskId) DestroyTask(taskId); FreeAllWindowBuffers(); SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); - sub_80F7E64(); + FreeContestResults(); } } } -static void sub_80F68B4(u8 taskId) +#undef tState +#undef tTimer +#undef tCounter + +static void Task_SlideContestResultsBg(u8 taskId) { gBattle_BG3_X += 2; gBattle_BG3_Y += 1; @@ -1020,33 +1046,37 @@ static void sub_80F68B4(u8 taskId) gBattle_BG3_Y -= 255; } -static void sub_80F68F0(u8 taskId) +#define tDelay data[0] +#define tCoeff data[1] +#define tDecreasing data[2] + +static void Task_FlashStarsAndHearts(u8 taskId) { - if (++gTasks[taskId].data[0] == 2) + if (++gTasks[taskId].tDelay == 2) { - gTasks[taskId].data[0] = 0; - if (gTasks[taskId].data[2] == 0) - gTasks[taskId].data[1]++; + gTasks[taskId].tDelay = 0; + if (!gTasks[taskId].tDecreasing) + gTasks[taskId].tCoeff++; else - gTasks[taskId].data[1]--; + gTasks[taskId].tCoeff--; - if (gTasks[taskId].data[1] == 16) - gTasks[taskId].data[2] = 1; - else if (gTasks[taskId].data[1] == 0) - gTasks[taskId].data[2] = 0; + if (gTasks[taskId].tCoeff == 16) + gTasks[taskId].tDecreasing = TRUE; + else if (gTasks[taskId].tCoeff == 0) + gTasks[taskId].tDecreasing = FALSE; - BlendPalette(0x6B, 1, gTasks[taskId].data[1], RGB(30, 22, 11)); - BlendPalette(0x68, 1, gTasks[taskId].data[1], RGB_WHITE); - BlendPalette(0x6E, 1, gTasks[taskId].data[1], RGB(30, 29, 29)); + BlendPalette(0x6B, 1, gTasks[taskId].tCoeff, RGB(30, 22, 11)); + BlendPalette(0x68, 1, gTasks[taskId].tCoeff, RGB_WHITE); + BlendPalette(0x6E, 1, gTasks[taskId].tCoeff, RGB(30, 29, 29)); } - if (gTasks[taskId].data[1] == 0) - gUnknown_0203A034->unk0->unkA = 0; + if (gTasks[taskId].tCoeff == 0) + sContestResults->data->pointsFlashing = FALSE; else - gUnknown_0203A034->unk0->unkA = 1; + sContestResults->data->pointsFlashing = TRUE; } -void sub_80F69B8(u16 species, u8 monIndex, u8 srcOffset, u8 useDmaNow, u32 personality) +static void LoadContestMonIcon(u16 species, u8 monIndex, u8 srcOffset, u8 useDmaNow, u32 personality) { const u8 *iconPtr; u16 var0, var1, frameNum; @@ -1071,15 +1101,15 @@ void sub_80F69B8(u16 species, u8 monIndex, u8 srcOffset, u8 useDmaNow, u32 perso } } -static void LoadAllContestMonIcons(u8 srcOffset, u8 useDmaNow) +static void LoadAllContestMonIcons(u8 srcOffset, bool8 useDmaNow) { int i; for (i = 0; i < CONTESTANT_COUNT; i++) - sub_80F69B8(gContestMons[i].species, i, srcOffset, useDmaNow, gContestMons[i].personality); + LoadContestMonIcon(gContestMons[i].species, i, srcOffset, useDmaNow, gContestMons[i].personality); } -static void sub_80F6A9C(void) +static void LoadAllContestMonIconPalettes(void) { int i, species; @@ -1090,7 +1120,7 @@ static void sub_80F6A9C(void) } } -static void sub_80F6AE8(void) +static void TryCreateWirelessSprites(void) { u16 sheet; u8 spriteId; @@ -1111,7 +1141,7 @@ static void sub_80F6AE8(void) // src are placed on different stack positions. #ifdef NONMATCHING -s32 sub_80F6B78(const u8 *text, u8 spriteId) +static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) { u8 *windowTilesPtr; u16 windowId; @@ -1176,7 +1206,7 @@ s32 sub_80F6B78(const u8 *text, u8 spriteId) #else NAKED -s32 sub_80F6B78(const u8 *text, u8 spriteId) +static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) { asm_unified("\n\ push {r4-r7,lr}\n\ @@ -1451,18 +1481,18 @@ _080F6D3E:\n\ } #endif // NONMATCHING -static void sub_80F6DC0(void) +static void LoadContestResultSprites(void) { int i; struct SpriteTemplate template; - u8 spriteIds[8]; + u8 spriteIds[ARRAY_COUNT(sUnknown_0858D810)]; template = sSpriteTemplate_858D7F8; for (i = 0; i < (int)ARRAY_COUNT(sUnknown_0858D810); i++) LoadSpriteSheet(&sUnknown_0858D810[i]); LoadSpritePalette(&sUnknown_0858D850); - for (i = 0; i < 8; i++) + for (i = 0; i < (int)ARRAY_COUNT(sUnknown_0858D810); i++) { spriteIds[i] = CreateSprite(&template, 272, 144, 10); template.tileTag++; @@ -1476,60 +1506,68 @@ static void sub_80F6DC0(void) gSprites[spriteIds[4]].data[1] = spriteIds[6]; gSprites[spriteIds[4]].data[2] = spriteIds[7]; - gUnknown_0203A034->unk0->unk0 = spriteIds[0]; - gUnknown_0203A034->unk0->unk4 = 0; - gUnknown_0203A034->unk0->unk1 = spriteIds[4]; - sub_80F7144(); + sContestResults->data->slidingTextBoxSpriteId = spriteIds[0]; + sContestResults->data->slidingTextBoxState = SLIDING_TEXT_OFFSCREEN; + sContestResults->data->linkTextBoxSpriteId = spriteIds[4]; + HideLinkResultsTextBox(); } -static void sub_80F6E9C(s16 arg0, u16 y, u16 arg2, u16 arg3) +#define sTargetX data[4] +#define sSlideOutTimer data[5] +#define sSlideIncrement data[6] +#define sDistance data[7] + +// If slideOutTimer is -1, it will not automatically slide out +static void StartTextBoxSlideIn(s16 x, u16 y, u16 slideOutTimer, u16 slideIncrement) { - struct Sprite *sprite = &gSprites[gUnknown_0203A034->unk0->unk0]; + struct Sprite *sprite = &gSprites[sContestResults->data->slidingTextBoxSpriteId]; sprite->pos1.x = 272; sprite->pos1.y = y; sprite->pos2.x = 0; sprite->pos2.y = 0; - sprite->data[4] = arg0 + 32; - sprite->data[5] = arg2; - sprite->data[6] = arg3; - sprite->data[7] = 0; - sprite->callback = sub_80F6F68; - gUnknown_0203A034->unk0->unk4 = 1; + sprite->sTargetX = x + 32; + sprite->sSlideOutTimer = slideOutTimer; + sprite->sSlideIncrement = slideIncrement; + sprite->sDistance = 0; + sprite->callback = SpriteCB_TextBoxSlideIn; + sContestResults->data->slidingTextBoxState = SLIDING_TEXT_ENTERING; } -static void sub_80F6EF4(u16 arg0) +static void StartTextBoxSlideOut(u16 slideIncrement) { - struct Sprite *sprite = &gSprites[gUnknown_0203A034->unk0->unk0]; + struct Sprite *sprite = &gSprites[sContestResults->data->slidingTextBoxSpriteId]; sprite->pos1.x += sprite->pos2.x; sprite->pos1.y += sprite->pos2.y; sprite->pos2.y = 0; sprite->pos2.x = 0; - sprite->data[6] = arg0; - sprite->data[7] = 0; - sprite->callback = sub_80F7014; - gUnknown_0203A034->unk0->unk4 = 3; + sprite->sSlideIncrement = slideIncrement; + sprite->sDistance = 0; + sprite->callback = SpriteCB_TextBoxSlideOut; + sContestResults->data->slidingTextBoxState = SLIDING_TEXT_EXITING; } -static void sub_80F6F40(struct Sprite *sprite) +static void EndTextBoxSlideOut(struct Sprite *sprite) { sprite->pos1.x = 272; sprite->pos1.y = 144; sprite->pos2.y = 0; sprite->pos2.x = 0; sprite->callback = SpriteCallbackDummy; - gUnknown_0203A034->unk0->unk4 = 0; + sContestResults->data->slidingTextBoxState = SLIDING_TEXT_OFFSCREEN; } -static void sub_80F6F68(struct Sprite *sprite) +static void SpriteCB_TextBoxSlideIn(struct Sprite *sprite) { int i; - s16 delta = sprite->data[7] + sprite->data[6]; + s16 delta = sprite->sDistance + sprite->sSlideIncrement; sprite->pos1.x -= delta >> 8; - sprite->data[7] += sprite->data[6]; - sprite->data[7] &= 0xFF; - if (sprite->pos1.x < sprite->data[4]) - sprite->pos1.x = sprite->data[4]; + sprite->sDistance += sprite->sSlideIncrement; + sprite->sDistance &= 0xFF; + + // Prevent overshooting target + if (sprite->pos1.x < sprite->sTargetX) + sprite->pos1.x = sprite->sTargetX; for (i = 0; i < 3; i++) { @@ -1537,29 +1575,29 @@ static void sub_80F6F68(struct Sprite *sprite) sprite2->pos1.x = sprite->pos1.x + sprite->pos2.x + (i + 1) * 64; } - if (sprite->pos1.x == sprite->data[4]) - sprite->callback = sub_80F6FDC; + if (sprite->pos1.x == sprite->sTargetX) + sprite->callback = SpriteCB_EndTextBoxSlideIn; } -static void sub_80F6FDC(struct Sprite *sprite) +static void SpriteCB_EndTextBoxSlideIn(struct Sprite *sprite) { - gUnknown_0203A034->unk0->unk4 = 2; - if ((u16)sprite->data[5] != 0xFFFF) + sContestResults->data->slidingTextBoxState = SLIDING_TEXT_ARRIVED; + if ((u16)sprite->sSlideOutTimer != 0xFFFF) { - if (--sprite->data[5] == -1) - sub_80F6EF4(sprite->data[6]); + if (--sprite->sSlideOutTimer == -1) + StartTextBoxSlideOut(sprite->sSlideIncrement); } } -static void sub_80F7014(struct Sprite *sprite) +static void SpriteCB_TextBoxSlideOut(struct Sprite *sprite) { int i; s16 delta; - delta = sprite->data[7] + sprite->data[6]; + delta = sprite->sDistance + sprite->sSlideIncrement; sprite->pos1.x -= delta >> 8; - sprite->data[7] += sprite->data[6]; - sprite->data[7] &= 0xFF; + sprite->sDistance += sprite->sSlideIncrement; + sprite->sDistance &= 0xFF; for (i = 0; i < 3; i++) { struct Sprite *sprite2 = &gSprites[sprite->data[i]]; @@ -1567,25 +1605,25 @@ static void sub_80F7014(struct Sprite *sprite) } if (sprite->pos1.x + sprite->pos2.x < -224) - sub_80F6F40(sprite); + EndTextBoxSlideOut(sprite); } -static void sub_80F707C(const u8 *text) +static void ShowLinkResultsTextBox(const u8 *text) { int i; u16 x; struct Sprite *sprite; - x = sub_80F6B78(text, gUnknown_0203A034->unk0->unk1); - sprite = &gSprites[gUnknown_0203A034->unk0->unk1]; + x = DrawResultsTextWindow(text, sContestResults->data->linkTextBoxSpriteId); + sprite = &gSprites[sContestResults->data->linkTextBoxSpriteId]; sprite->pos1.x = x + 32; sprite->pos1.y = 80; - sprite->invisible = 0; + sprite->invisible = FALSE; for (i = 0; i < 3; i++) { gSprites[sprite->data[i]].pos1.x = sprite->pos1.x + sprite->pos2.x + (i + 1) * 64; gSprites[sprite->data[i]].pos1.y = sprite->pos1.y; - gSprites[sprite->data[i]].invisible = 0; + gSprites[sprite->data[i]].invisible = FALSE; } gBattle_WIN0H = 0x00F0; @@ -1594,15 +1632,15 @@ static void sub_80F707C(const u8 *text) | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR); } -static void sub_80F7144(void) +static void HideLinkResultsTextBox(void) { int i; struct Sprite *sprite; - sprite = &gSprites[gUnknown_0203A034->unk0->unk1]; - sprite->invisible = 1; + sprite = &gSprites[sContestResults->data->linkTextBoxSpriteId]; + sprite->invisible = TRUE; for (i = 0; i < 3; i++) - gSprites[sprite->data[i]].invisible = 1; + gSprites[sprite->data[i]].invisible = TRUE; gBattle_WIN0H = 0; gBattle_WIN0V = 0; @@ -1612,7 +1650,7 @@ static void sub_80F7144(void) | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ | WININ_WIN1_CLR); } -static void sub_80F71C8(void) +static void LoadContestResultsTilemaps(void) { u8 palette; int x, y; @@ -1621,147 +1659,153 @@ static void sub_80F71C8(void) y = 1; if (gLinkContestFlags & LINK_CONTEST_FLAG_IS_LINK) { - CopyToBgTilemapBufferRect(2, gUnknown_08DC6498, 5, 1, 5, 2); + CopyToBgTilemapBufferRect(2, gLinkContestResults_Tilemap, 5, 1, 5, 2); x = 10; } else if (gSpecialVar_ContestRank == CONTEST_RANK_NORMAL) { - CopyToBgTilemapBufferRect(2, gUnknown_08DC63F8, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gNormalContestResults_Tilemap, 5, 1, 10, 2); x = 15; } else if (gSpecialVar_ContestRank == CONTEST_RANK_SUPER) { - CopyToBgTilemapBufferRect(2, gUnknown_08DC6420, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gSuperContestResults_Tilemap, 5, 1, 10, 2); x = 15; } else if (gSpecialVar_ContestRank == CONTEST_RANK_HYPER) { - CopyToBgTilemapBufferRect(2, gUnknown_08DC6448, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gHyperContestResults_Tilemap, 5, 1, 10, 2); x = 15; } else // CONTEST_RANK_MASTER { - CopyToBgTilemapBufferRect(2, gUnknown_08DC6470, 5, 1, 10, 2); + CopyToBgTilemapBufferRect(2, gMasterContestResults_Tilemap, 5, 1, 10, 2); x = 15; } if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_COOL) { palette = 0; - CopyToBgTilemapBufferRect(2, gUnknown_08DC64AC, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gCoolContestResults_Tilemap, x, y, 5, 2); } else if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_BEAUTY) { palette = 1; - CopyToBgTilemapBufferRect(2, gUnknown_08DC64C0, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gBeautyContestResults_Tilemap, x, y, 5, 2); } else if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_CUTE) { palette = 2; - CopyToBgTilemapBufferRect(2, gUnknown_08DC64D4, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gCuteContestResults_Tilemap, x, y, 5, 2); } else if (gSpecialVar_ContestCategory == CONTEST_CATEGORY_SMART) { palette = 3; - CopyToBgTilemapBufferRect(2, gUnknown_08DC64E8, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gSmartContestResults_Tilemap, x, y, 5, 2); } else // CONTEST_CATEGORY_TOUGH { palette = 4; - CopyToBgTilemapBufferRect(2, gUnknown_08DC64FC, x, y, 5, 2); + CopyToBgTilemapBufferRect(2, gToughContestResults_Tilemap, x, y, 5, 2); } x += 5; - CopyToBgTilemapBufferRect(2, gUnknown_08DC6510, x, y, 6, 2); - CopyToBgTilemapBufferRect_ChangePalette(2, gUnknown_0203A034->unkC[2], 0, 0, 32, 4, palette); + CopyToBgTilemapBufferRect(2, gContestResults_Tilemap, x, y, 6, 2); + CopyToBgTilemapBufferRect_ChangePalette(2, sContestResults->tilemapBuffers[2], 0, 0, 32, 4, palette); } -u8 sub_80F7310(u8 monIndex, u8 arg1) +// Represented on results board as stars +static u8 GetNumPreliminaryPoints(u8 monIndex, bool8 capPoints) { - u32 var0 = gContestMonConditions[monIndex] << 16; - u32 var1 = var0 / 0x3F; + u32 condition = gContestMonConditions[monIndex] << 16; + u32 numStars = condition / 0x3F; - if (var1 & 0xFFFF) - var1 += 0x10000; + if (numStars & 0xFFFF) + numStars += 0x10000; - var1 >>= 16; - if (var1 == 0 && var0) - var1 = 1; + numStars >>= 16; + if (numStars == 0 && condition) + numStars = 1; - if (arg1 && var1 > 10) - var1 = 10; + if (capPoints && numStars > 10) + numStars = 10; - return var1; + return numStars; } -s8 sub_80F7364(u8 arg0, u8 arg1) +// Represented on results board as hearts +static s8 GetNumRound2Points(u8 monIndex, bool8 capPoints) { - u32 r4, r2; - s16 val; - s8 ret; + u32 r4, numHearts; + s16 results; + s8 points; - val = gUnknown_02039F18[arg0]; - if (val < 0) - r4 = -val << 16; + results = gContestMonRound2Points[monIndex]; + if (results < 0) + r4 = -results << 16; else - r4 = val << 16; + r4 = results << 16; - r2 = r4 / 80; - if (r2 & 0xFFFF) - r2 += 0x10000; + numHearts = r4 / 80; + if (numHearts & 0xFFFF) + numHearts += 0x10000; - r2 >>= 16; - if (r2 == 0 && r4 != 0) - r2 = 1; + numHearts >>= 16; + if (numHearts == 0 && r4 != 0) + numHearts = 1; - if (arg1 != 0 && r2 > 10) - r2 = 10; + if (capPoints && numHearts > 10) + numHearts = 10; - if (gUnknown_02039F18[arg0] < 0) - ret = -r2; + if (gContestMonRound2Points[monIndex] < 0) + points = -numHearts; else - ret = r2; + points = numHearts; - return ret; + return points; } -static void sub_80F73DC(u8 taskId) +#define tState data[10] + +static void Task_DrawFinalStandingNumber(u8 taskId) { u16 firstTileNum; - if (gTasks[taskId].data[10] == 0) + if (gTasks[taskId].tState == 0) { - gTasks[taskId].data[11] = (3 - gTasks[taskId].data[0]) * 40; - gTasks[taskId].data[10]++; + gTasks[taskId].data[11] = (3 - gTasks[taskId].tFinalStanding) * 40; + gTasks[taskId].tState++; } - else if (gTasks[taskId].data[10] == 1) + else if (gTasks[taskId].tState == 1) { if (--gTasks[taskId].data[11] == -1) { - firstTileNum = gTasks[taskId].data[0] * 2 + 0x5043; - WriteSequenceToBgTilemapBuffer(2, firstTileNum, 1, gTasks[taskId].data[1] * 3 + 5, 2, 1, 17, 1); - WriteSequenceToBgTilemapBuffer(2, firstTileNum + 0x10, 1, gTasks[taskId].data[1] * 3 + 6, 2, 1, 17, 1); - gUnknown_0203A034->unk0->unk5++; + firstTileNum = gTasks[taskId].tFinalStanding * 2 + 0x5043; + WriteSequenceToBgTilemapBuffer(2, firstTileNum, 1, gTasks[taskId].tMonIndex * 3 + 5, 2, 1, 17, 1); + WriteSequenceToBgTilemapBuffer(2, firstTileNum + 0x10, 1, gTasks[taskId].tMonIndex * 3 + 6, 2, 1, 17, 1); + sContestResults->data->numStandingsPrinted++; DestroyTask(taskId); PlaySE(SE_JYUNI); } } } -static void sub_80F74BC(u8 taskId) +#undef tFinalStanding +#undef tMonIndex +#undef tState + +static void Task_StartHighlightWinnersBox(u8 taskId) { int i; - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; - - CopyToBgTilemapBufferRect_ChangePalette(2, i * 0xC0 + 0x100 + gUnknown_0203A034->unkC[2], 0, i * 3 + 4, 32, 3, 9); + GET_CONTEST_WINNER_ID(i); + CopyToBgTilemapBufferRect_ChangePalette(2, i * 0xC0 + 0x100 + sContestResults->tilemapBuffers[2], 0, i * 3 + 4, 32, 3, 9); gTasks[taskId].data[10] = i; gTasks[taskId].data[12] = 1; - gTasks[taskId].func = sub_80F753C; - gUnknown_0203A034->unk0->unk3 = taskId; + gTasks[taskId].func = Task_HighlightWinnersBox; + sContestResults->data->highlightWinnerTaskId = taskId; } -static void sub_80F753C(u8 taskId) +static void Task_HighlightWinnersBox(u8 taskId) { if (++gTasks[taskId].data[11] == 1) { @@ -1780,7 +1824,7 @@ static void sub_80F753C(u8 taskId) } } -static void sub_80F75A8(struct Sprite *sprite) +static void SpriteCB_WinnerMonSlideIn(struct Sprite *sprite) { if (sprite->data[0] < 10) { @@ -1803,12 +1847,12 @@ static void sub_80F75A8(struct Sprite *sprite) { sprite->callback = SpriteCallbackDummy; sprite->data[1] = 0; - gUnknown_0203A034->unk0->unk6 = 1; + sContestResults->data->winnerMonSlidingState = SLIDING_MON_ENTERED; } } } -static void sub_80F7620(struct Sprite *sprite) +static void SpriteCB_WinnerMonSlideOut(struct Sprite *sprite) { s16 delta = sprite->data[1] + 0x600; sprite->pos1.x -= delta >> 8; @@ -1817,32 +1861,32 @@ static void sub_80F7620(struct Sprite *sprite) if (sprite->pos1.x < -32) { sprite->callback = SpriteCallbackDummy; - sprite->invisible = 1; - gUnknown_0203A034->unk0->unk6 = 2; + sprite->invisible = TRUE; + sContestResults->data->winnerMonSlidingState = SLIDING_MON_EXITED; } } -static void sub_80F7670(u8 taskId) +static void Task_CreateConfetti(u8 taskId) { if (++gTasks[taskId].data[0] == 5) { gTasks[taskId].data[0] = 0; - if (gUnknown_0203A034->unk0->unk7 < 40) + if (sContestResults->data->confettiCount < 40) { - u8 spriteId = CreateSprite(&sSpriteTemplate_858D860, (Random() % 240) - 20, 44, 5); + u8 spriteId = CreateSprite(&sSpriteTemplate_Confetti, (Random() % 240) - 20, 44, 5); gSprites[spriteId].data[0] = Random() % 512; gSprites[spriteId].data[1] = (Random() % 24) + 16; gSprites[spriteId].data[2] = (Random() % 256) + 48; gSprites[spriteId].oam.tileNum += Random() % 17; - gUnknown_0203A034->unk0->unk7++; + sContestResults->data->confettiCount++; } } - if (gUnknown_0203A034->unk0->unk9) + if (sContestResults->data->destroyConfetti) DestroyTask(taskId); } -static void sub_80F7768(struct Sprite *sprite) +static void SpriteCB_Confetti(struct Sprite *sprite) { s16 delta; @@ -1854,219 +1898,235 @@ static void sub_80F7768(struct Sprite *sprite) sprite->data[4] &= 0xff; sprite->pos1.y++; - if (gUnknown_0203A034->unk0->unk9) - sprite->invisible = 1; + if (sContestResults->data->destroyConfetti) + sprite->invisible = TRUE; if (sprite->pos1.x > 248 || sprite->pos1.y > 116) { DestroySprite(sprite); - gUnknown_0203A034->unk0->unk7--; + sContestResults->data->confettiCount--; } } -static void sub_80F77E0(u8 monIndex, u8 numFrames) +#define tMonIndex data[0] +#define tNumFrames data[1] +#define tSpecies data[2] +#define tTimer data[10] +#define tBounced data[11] + +static void BounceMonIconInBox(u8 monIndex, u8 numFrames) { - u8 taskId = CreateTask(sub_80F7824, 8); - gTasks[taskId].data[0] = monIndex; - gTasks[taskId].data[1] = numFrames; - gTasks[taskId].data[2] = gContestMons[monIndex].species; + u8 taskId = CreateTask(Task_BounceMonIconInBox, 8); + gTasks[taskId].tMonIndex = monIndex; + gTasks[taskId].tNumFrames = numFrames; + gTasks[taskId].tSpecies = gContestMons[monIndex].species; } -static void sub_80F7824(u8 taskId) +static void Task_BounceMonIconInBox(u8 taskId) { - u8 monIndex = gTasks[taskId].data[0]; - if (gTasks[taskId].data[10]++ == gTasks[taskId].data[1]) + u8 monIndex = gTasks[taskId].tMonIndex; + if (gTasks[taskId].tTimer++ == gTasks[taskId].tNumFrames) { - gTasks[taskId].data[10] = 0; - sub_80F69B8(gTasks[taskId].data[2], monIndex, gTasks[taskId].data[11], FALSE, gContestMons[monIndex].personality); - gTasks[taskId].data[11] ^= 1; + gTasks[taskId].tTimer = 0; + LoadContestMonIcon(gTasks[taskId].tSpecies, monIndex, gTasks[taskId].tBounced, FALSE, gContestMons[monIndex].personality); + gTasks[taskId].tBounced ^= 1; } } -static void sub_80F7880(void) -{ - int i, r4; - u32 r1; - s16 r2; - s8 var; +#undef tMonIndex +#undef tNumFrames +#undef tSpecies +#undef tTimer +#undef tBounced - r2 = gUnknown_02039F08[0]; - for (i = 1; i < 4; i++) +static void CalculateContestantsResultData(void) +{ + int i, relativePoints; + u32 barLength; + s16 highestPoints; + s8 round2Points; + + highestPoints = gContestMonTotalPoints[0]; + for (i = 1; i < CONTESTANT_COUNT; i++) { - if (r2 < gUnknown_02039F08[i]) - r2 = gUnknown_02039F08[i]; + if (highestPoints < gContestMonTotalPoints[i]) + highestPoints = gContestMonTotalPoints[i]; } - if (r2 < 0) + if (highestPoints < 0) { - r2 = gUnknown_02039F08[0]; - for (i = 1; i < 4; i++) + highestPoints = gContestMonTotalPoints[0]; + for (i = 1; i < CONTESTANT_COUNT; i++) { - if (r2 > gUnknown_02039F08[i]) - r2 = gUnknown_02039F08[i]; + if (highestPoints > gContestMonTotalPoints[i]) + highestPoints = gContestMonTotalPoints[i]; } } for (i = 0; i < CONTESTANT_COUNT; i++) { - r4 = (gContestMonConditions[i] * 1000) / abs(r2); - if (r4 % 10 > 4) - r4 += 10; - (*gUnknown_0203A034->unk4)[i].unk0 = r4 / 10; + relativePoints = (gContestMonConditions[i] * 1000) / abs(highestPoints); + if (relativePoints % 10 > 4) + relativePoints += 10; + (*sContestResults->monResults)[i].relativePreliminaryPoints = relativePoints / 10; - r4 = (abs(gUnknown_02039F18[i]) * 1000) / abs(r2); - if (r4 % 10 > 4) - r4 += 10; - (*gUnknown_0203A034->unk4)[i].unk4 = r4 / 10; + relativePoints = (abs(gContestMonRound2Points[i]) * 1000) / abs(highestPoints); + if (relativePoints % 10 > 4) + relativePoints += 10; + (*sContestResults->monResults)[i].relativeRound2Points = relativePoints / 10; - if (gUnknown_02039F18[i] < 0) - (*gUnknown_0203A034->unk4)[i].unk10 = 1; + if (gContestMonRound2Points[i] < 0) + (*sContestResults->monResults)[i].lostPoints = TRUE; - r1 = ((*gUnknown_0203A034->unk4)[i].unk0 * 22528) / 100; - if ((r1 & 0xFF) > 0x7F) - r1 += 0x100; - (*gUnknown_0203A034->unk4)[i].unk8 = r1 >> 8; + barLength = ((*sContestResults->monResults)[i].relativePreliminaryPoints * 0x5800) / 100; + if ((barLength & 0xFF) > 0x7F) + barLength += 0x100; + (*sContestResults->monResults)[i].barLengthPreliminary = barLength >> 8; - r1 = ((*gUnknown_0203A034->unk4)[i].unk4 * 22528) / 100; - if ((r1 & 0xFF) > 0x7F) - r1 += 0x100; - (*gUnknown_0203A034->unk4)[i].unkC = r1 >> 8; + barLength = ((*sContestResults->monResults)[i].relativeRound2Points * 0x5800) / 100; + if ((barLength & 0xFF) > 0x7F) + barLength += 0x100; + (*sContestResults->monResults)[i].barLengthRound2 = barLength >> 8; - (*gUnknown_0203A034->unk4)[i].unk11 = sub_80F7310(i, 1); - var = sub_80F7364(i, 1); - (*gUnknown_0203A034->unk4)[i].unk12 = abs(var); + (*sContestResults->monResults)[i].numStars = GetNumPreliminaryPoints(i, TRUE); + round2Points = GetNumRound2Points(i, TRUE); + (*sContestResults->monResults)[i].numHearts = abs(round2Points); if (gContestFinalStandings[i]) { - s16 var1 = (*gUnknown_0203A034->unk4)[i].unk8; - s16 var2 = (*gUnknown_0203A034->unk4)[i].unkC; + s16 barLengthPreliminary = (*sContestResults->monResults)[i].barLengthPreliminary; + s16 barLengthRound2 = (*sContestResults->monResults)[i].barLengthRound2; - if ((*gUnknown_0203A034->unk4)[i].unk10) - var2 *= -1; + if ((*sContestResults->monResults)[i].lostPoints) + barLengthRound2 *= -1; - if (var1 + var2 == 88) + if (barLengthPreliminary + barLengthRound2 == MAX_BAR_LENGTH + 1) { - if (var2 > 0) - (*gUnknown_0203A034->unk4)[i].unkC--; - else if (var1 > 0) - (*gUnknown_0203A034->unk4)[i].unk8--; + if (barLengthRound2 > 0) + (*sContestResults->monResults)[i].barLengthRound2--; + else if (barLengthPreliminary > 0) + (*sContestResults->monResults)[i].barLengthPreliminary--; } } } } -static void sub_80F7A80(u8 arg0, u8 arg1) +#define tMonId data[0] +#define tTarget data[1] +#define tDecreasing data[2] + +static void UpdateContestResultBars(bool8 isRound2, u8 numUpdates) { int i, taskId; - u32 var0; - u8 sp8 = 0, spC = 0; + u32 target; + u8 numIncreasing = 0, numDecreasing = 0; - if (!arg0) + if (!isRound2) { - for (i = 0; i < 4; i++) + for (i = 0; i < CONTESTANT_COUNT; i++) { - u8 unk = (*gUnknown_0203A034->unk4)[i].unk11; - if (arg1 < unk) + u8 numStars = (*sContestResults->monResults)[i].numStars; + if (numUpdates < numStars) { - FillBgTilemapBufferRect_Palette0(1, 0x60B3, ((19 + unk) - arg1) - 1, i * 3 + 5, 1, 1); - taskId = CreateTask(sub_80F7CA8, 10); + FillBgTilemapBufferRect_Palette0(1, 0x60B3, ((19 + numStars) - numUpdates) - 1, i * 3 + 5, 1, 1); + taskId = CreateTask(Task_UpdateContestResultBar, 10); - var0 = (((*gUnknown_0203A034->unk4)[i].unk8 << 16) / (*gUnknown_0203A034->unk4)[i].unk11) * (arg1 + 1); - if ((var0 & 0xFFFF) > 0x7FFF) - var0 += 0x10000; + target = (((*sContestResults->monResults)[i].barLengthPreliminary << 16) / (*sContestResults->monResults)[i].numStars) * (numUpdates + 1); + if ((target & 0xFFFF) > 0x7FFF) + target += 0x10000; - gTasks[taskId].data[0] = i; - gTasks[taskId].data[1] = var0 >> 16; - gUnknown_0203A034->unk0->unk14++; - sp8++; + gTasks[taskId].tMonId = i; + gTasks[taskId].tTarget = target >> 16; + sContestResults->data->numBarsUpdating++; + numIncreasing++; } } } else { - for (i = 0; i < 4; i++) + for (i = 0; i < CONTESTANT_COUNT; i++) { - s8 unk = (*gUnknown_0203A034->unk4)[i].unk12; - u32 tile = (*gUnknown_0203A034->unk4)[i].unk10 ? 0x60A5 : 0x60A3; - if (arg1 < unk) + s8 numHearts = (*sContestResults->monResults)[i].numHearts; + u32 tile = (*sContestResults->monResults)[i].lostPoints ? 0x60A5 : 0x60A3; + if (numUpdates < numHearts) { - FillBgTilemapBufferRect_Palette0(1, tile, ((19 + unk) - arg1) - 1, i * 3 + 6, 1, 1); - taskId = CreateTask(sub_80F7CA8, 10); + FillBgTilemapBufferRect_Palette0(1, tile, ((19 + numHearts) - numUpdates) - 1, i * 3 + 6, 1, 1); + taskId = CreateTask(Task_UpdateContestResultBar, 10); - var0 = (((*gUnknown_0203A034->unk4)[i].unkC << 16) / (*gUnknown_0203A034->unk4)[i].unk12) * (arg1 + 1); - if ((var0 & 0xFFFF) > 0x7FFF) - var0 += 0x10000; + target = (((*sContestResults->monResults)[i].barLengthRound2 << 16) / (*sContestResults->monResults)[i].numHearts) * (numUpdates + 1); + if ((target & 0xFFFF) > 0x7FFF) + target += 0x10000; - gTasks[taskId].data[0] = i; - if ((*gUnknown_0203A034->unk4)[i].unk10) + gTasks[taskId].tMonId = i; + if ((*sContestResults->monResults)[i].lostPoints) { - gTasks[taskId].data[2] = 1; - spC++; + gTasks[taskId].tDecreasing = TRUE; + numDecreasing++; } else { - sp8++; + numIncreasing++; } - if ((*gUnknown_0203A034->unk4)[i].unk10) - gTasks[taskId].data[1] = -(var0 >> 16) + (*gUnknown_0203A034->unk4)[i].unk8 ; + if ((*sContestResults->monResults)[i].lostPoints) + gTasks[taskId].tTarget = -(target >> 16) + (*sContestResults->monResults)[i].barLengthPreliminary; else - gTasks[taskId].data[1] = (var0 >> 16) + (*gUnknown_0203A034->unk4)[i].unk8; + gTasks[taskId].tTarget = (target >> 16) + (*sContestResults->monResults)[i].barLengthPreliminary; - gUnknown_0203A034->unk0->unk14++; + sContestResults->data->numBarsUpdating++; } } } - if (spC) + if (numDecreasing) PlaySE(SE_BOO); - if (sp8) + if (numIncreasing) PlaySE(SE_PIN); } -void sub_80F7CA8(u8 taskId) +static void Task_UpdateContestResultBar(u8 taskId) { int i; - u8 var0; - u16 tileNum; - bool32 r4 = FALSE; - bool32 endTask = FALSE; - u8 r6 = gTasks[taskId].data[0]; - s16 r7 = gTasks[taskId].data[1]; - s16 r12 = gTasks[taskId].data[2]; + bool32 minMaxReached = FALSE; + bool32 targetReached = FALSE; + u8 monId = gTasks[taskId].tMonId; + s16 target = gTasks[taskId].tTarget; + s16 decreasing = gTasks[taskId].tDecreasing; - if (r12) + if (decreasing) { - if (gUnknown_0203A034->unk0->unkC[r6] <= 0) - r4 = TRUE; + if (sContestResults->data->unkC[monId] <= 0) + minMaxReached = TRUE; } else { - if (gUnknown_0203A034->unk0->unkC[r6] > 87) - r4 = TRUE; + if (sContestResults->data->unkC[monId] > MAX_BAR_LENGTH) + minMaxReached = TRUE; } - if (gUnknown_0203A034->unk0->unkC[r6] == r7) - endTask = TRUE; + if (sContestResults->data->unkC[monId] == target) + targetReached = TRUE; - if (!endTask) + if (!targetReached) { - if (r4) - gUnknown_0203A034->unk0->unkC[r6] = r7; - else if (r12) - gUnknown_0203A034->unk0->unkC[r6] = gUnknown_0203A034->unk0->unkC[r6] - 1; + if (minMaxReached) + sContestResults->data->unkC[monId] = target; + else if (decreasing) + sContestResults->data->unkC[monId] = sContestResults->data->unkC[monId] - 1; else - gUnknown_0203A034->unk0->unkC[r6] = gUnknown_0203A034->unk0->unkC[r6] + 1; + sContestResults->data->unkC[monId] = sContestResults->data->unkC[monId] + 1; } - if (!r4 && !endTask) + if (!minMaxReached && !targetReached) { + u8 var0; + u16 tileNum; for (i = 0; i < 11; i++) { - if (gUnknown_0203A034->unk0->unkC[r6] >= (i + 1) * 8) + if (sContestResults->data->unkC[monId] >= (i + 1) * 8) var0 = 8; - else if (gUnknown_0203A034->unk0->unkC[r6] >= i * 8) - var0 = gUnknown_0203A034->unk0->unkC[r6] % 8; + else if (sContestResults->data->unkC[monId] >= i * 8) + var0 = sContestResults->data->unkC[monId] % 8; else var0 = 0; @@ -2075,54 +2135,58 @@ void sub_80F7CA8(u8 taskId) else tileNum = 0x5057 + var0; - FillBgTilemapBufferRect_Palette0(2, tileNum, i + 7, r6 * 3 + 6, 1, 1); + FillBgTilemapBufferRect_Palette0(2, tileNum, i + 7, monId * 3 + 6, 1, 1); } } - if (endTask) + if (targetReached) { - gUnknown_0203A034->unk0->unk14--; + sContestResults->data->numBarsUpdating--; DestroyTask(taskId); } } -static void sub_80F7DF4(void) +#undef tMonId +#undef tTarget +#undef tDecreasing + +static void AllocContestResults(void) { - gUnknown_0203A034 = AllocZeroed(sizeof(*gUnknown_0203A034)); - gUnknown_0203A034->unk0 = AllocZeroed(sizeof(*gUnknown_0203A034->unk0)); - gUnknown_0203A034->unk4 = AllocZeroed(sizeof(*gUnknown_0203A034->unk4)); - gUnknown_0203A034->unk8 = AllocZeroed(BG_SCREEN_SIZE); - gUnknown_0203A034->unkC[0] = AllocZeroed(BG_SCREEN_SIZE); - gUnknown_0203A034->unkC[1] = AllocZeroed(BG_SCREEN_SIZE); - gUnknown_0203A034->unkC[2] = AllocZeroed(BG_SCREEN_SIZE); - gUnknown_0203A034->unkC[3] = AllocZeroed(BG_SCREEN_SIZE); - gUnknown_0203A034->unk1C = AllocZeroed(0x1000); + sContestResults = AllocZeroed(sizeof(*sContestResults)); + sContestResults->data = AllocZeroed(sizeof(*sContestResults->data)); + sContestResults->monResults = AllocZeroed(sizeof(*sContestResults->monResults)); + sContestResults->unusedBg = AllocZeroed(BG_SCREEN_SIZE); + sContestResults->tilemapBuffers[0] = AllocZeroed(BG_SCREEN_SIZE); + sContestResults->tilemapBuffers[1] = AllocZeroed(BG_SCREEN_SIZE); + sContestResults->tilemapBuffers[2] = AllocZeroed(BG_SCREEN_SIZE); + sContestResults->tilemapBuffers[3] = AllocZeroed(BG_SCREEN_SIZE); + sContestResults->unused = AllocZeroed(0x1000); AllocateMonSpritesGfx(); } -static void sub_80F7E64(void) +static void FreeContestResults(void) { - FREE_AND_SET_NULL(gUnknown_0203A034->unk0); - FREE_AND_SET_NULL(gUnknown_0203A034->unk4); - FREE_AND_SET_NULL(gUnknown_0203A034->unk8); - FREE_AND_SET_NULL(gUnknown_0203A034->unkC[0]); - FREE_AND_SET_NULL(gUnknown_0203A034->unkC[1]); - FREE_AND_SET_NULL(gUnknown_0203A034->unkC[2]); - FREE_AND_SET_NULL(gUnknown_0203A034->unkC[3]); - FREE_AND_SET_NULL(gUnknown_0203A034->unk1C); - FREE_AND_SET_NULL(gUnknown_0203A034); + FREE_AND_SET_NULL(sContestResults->data); + FREE_AND_SET_NULL(sContestResults->monResults); + FREE_AND_SET_NULL(sContestResults->unusedBg); + FREE_AND_SET_NULL(sContestResults->tilemapBuffers[0]); + FREE_AND_SET_NULL(sContestResults->tilemapBuffers[1]); + FREE_AND_SET_NULL(sContestResults->tilemapBuffers[2]); + FREE_AND_SET_NULL(sContestResults->tilemapBuffers[3]); + FREE_AND_SET_NULL(sContestResults->unused); + FREE_AND_SET_NULL(sContestResults); FreeMonSpritesGfx(); } -static void sub_80F7ED0(int windowId, u8 *str, int arg2) +static void AddContestTextPrinter(int windowId, u8 *str, int x) { struct TextPrinterTemplate textPrinter; textPrinter.currentChar = str; textPrinter.windowId = windowId; textPrinter.fontId = 7; - textPrinter.x = arg2; + textPrinter.x = x; textPrinter.y = 2; - textPrinter.currentX = arg2; + textPrinter.currentX = x; textPrinter.currentY = 2; textPrinter.letterSpacing = 0; textPrinter.lineSpacing = 0; @@ -2274,20 +2338,14 @@ void GetContestMonCondition(void) void GetContestWinnerId(void) { u8 i; - - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; - + GET_CONTEST_WINNER_ID(i); gSpecialVar_0x8005 = i; } void BufferContestWinnerTrainerName(void) { u8 i; - - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; - + GET_CONTEST_WINNER_ID(i); StringCopy(gStringVar3, gContestMons[i].trainerName); sub_81DB5AC(gStringVar3); } @@ -2295,10 +2353,7 @@ void BufferContestWinnerTrainerName(void) void BufferContestWinnerMonName(void) { u8 i; - - for (i = 0; i < CONTESTANT_COUNT && gContestFinalStandings[i] != 0; i++) - ; - + GET_CONTEST_WINNER_ID(i); StringCopy(gStringVar1, gContestMons[i].nickname); } @@ -2328,19 +2383,19 @@ void BufferContestantMonSpecies(void) gSpecialVar_0x8004 = gContestMons[gSpecialVar_0x8006].species; } -static void sub_80F8458(u8 taskId) +static void Task_StartShowContestResults(u8 taskId) { if (!gPaletteFade.active) { DestroyTask(taskId); - SetMainCallback2(sub_80F5B00); + SetMainCallback2(CB2_StartShowContestResults); } } -void sub_80F8484(void) +void ShowContestResults(void) { ScriptContext2_Enable(); - CreateTask(sub_80F8458, 10); + CreateTask(Task_StartShowContestResults, 10); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); } @@ -2349,7 +2404,7 @@ void GetContestPlayerId(void) gSpecialVar_0x8004 = gContestPlayerMonIndex; } -void sub_80F84C4(u8 taskId) +void ContestLinkTransfer(u8 taskId) { u8 newTaskId; ScriptContext2_Enable(); diff --git a/src/credits.c b/src/credits.c index dd1166d82..8fc8a1f88 100644 --- a/src/credits.c +++ b/src/credits.c @@ -20,7 +20,6 @@ #include "trig.h" #include "graphics.h" #include "pokedex.h" -#include "constants/vars.h" #include "event_data.h" #include "random.h" #include "constants/species.h" diff --git a/src/easy_chat.c b/src/easy_chat.c index 2a4c49213..44a7b90c1 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -29,7 +29,6 @@ #include "window.h" #include "constants/easy_chat.h" #include "constants/event_objects.h" -#include "constants/flags.h" #include "constants/lilycove_lady.h" #include "constants/mauville_old_man.h" #include "constants/songs.h" diff --git a/src/faraway_island.c b/src/faraway_island.c index c09dd1bfe..a17ae9394 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -7,10 +7,8 @@ #include "sprite.h" #include "constants/event_objects.h" #include "constants/field_effects.h" -#include "constants/flags.h" #include "constants/maps.h" #include "constants/metatile_behaviors.h" -#include "constants/vars.h" static u8 sub_81D4890(u8); static bool8 sub_81D4C14(struct ObjectEvent*, u8); diff --git a/src/field_door.c b/src/field_door.c index b4794349c..e81c3dc4b 100644 --- a/src/field_door.c +++ b/src/field_door.c @@ -5,7 +5,6 @@ #include "fieldmap.h" #include "metatile_behavior.h" #include "task.h" -#include "constants/flags.h" #include "constants/maps.h" #include "constants/songs.h" #include "constants/metatile_labels.h" diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index 37342f02d..88385896c 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -25,7 +25,6 @@ #include "constants/event_objects.h" #include "constants/event_object_movement.h" #include "constants/field_effects.h" -#include "constants/flags.h" #include "constants/items.h" #include "constants/maps.h" #include "constants/moves.h" diff --git a/src/field_special_scene.c b/src/field_special_scene.c index df45af097..bb8e8b1d9 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -17,7 +17,6 @@ #include "constants/event_object_movement.h" #include "constants/field_specials.h" #include "constants/songs.h" -#include "constants/vars.h" #include "constants/metatile_labels.h" #define SECONDS(value) ((signed) (60.0 * value + 0.5)) diff --git a/src/field_specials.c b/src/field_specials.c index e1d336d21..f9b8a7bd0 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -63,7 +63,6 @@ #include "constants/species.h" #include "constants/moves.h" #include "constants/party_menu.h" -#include "constants/vars.h" #include "constants/battle_frontier.h" #include "constants/weather.h" #include "constants/metatile_labels.h" @@ -4095,11 +4094,17 @@ void UpdateTrainerFanClubGameClear(void) } // If the player has < 3 fans, gain a new fan whenever the counter reaches 20+ -// Defeating Drake or participating in a Link Contest increments the counter by 2 +// Defeating Drake or participating in a Contest increments the counter by 2 // Participating at Battle Tower or in a Secret Base battle increments the counter by 1 u8 TryGainNewFanFromCounter(u8 incrementId) { - static const u8 sCounterIncrements[] = { 2, 1, 2, 1 }; + static const u8 sCounterIncrements[] = + { + [FANCOUNTER_DEFEATED_DRAKE] = 2, + [FANCOUNTER_BATTLED_AT_BASE] = 1, + [FANCOUNTER_FINISHED_CONTEST] = 2, + [FANCOUNTER_USED_BATTLE_TOWER] = 1 + }; if (VarGet(VAR_LILYCOVE_FAN_CLUB_STATE) == 2) { diff --git a/src/field_tasks.c b/src/field_tasks.c index de2884e49..49b6fbdd8 100644 --- a/src/field_tasks.c +++ b/src/field_tasks.c @@ -19,7 +19,6 @@ #include "constants/field_tasks.h" #include "constants/items.h" #include "constants/songs.h" -#include "constants/vars.h" #include "constants/metatile_labels.h" struct PacifidlogMetatileOffsets diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index ee4b31653..6db44d752 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -23,7 +23,6 @@ #include "constants/metatile_labels.h" #include "constants/songs.h" #include "constants/tv.h" -#include "constants/vars.h" EWRAM_DATA struct MapPosition gPlayerFacingPosition = {0}; diff --git a/src/graphics.c b/src/graphics.c index 8e9c472ce..b774c5ad2 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -471,13 +471,11 @@ const u8 gTiles_8C19450[] = INCBIN_U8("graphics/contest/heart.4bpp"); const u32 gUnknownGfx_C19470[] = INCBIN_U32("graphics/unknown/unknown_C19470.4bpp.lz"); const u32 gUnknownPal_C19470[] = INCBIN_U32("graphics/unknown/unknown_C19470.gbapal.lz"); -const u32 gUnknown_08C19588[] = INCBIN_U32("graphics/contest/misc_2.4bpp.lz"); - +const u32 gContestResults_Gfx[] = INCBIN_U32("graphics/contest/results_screen.4bpp.lz"); const u32 gUnknown_08C19EEC[] = INCBIN_U32("graphics/contest/misc_2_tilemap_1.bin.lz"); const u32 gUnknown_08C1A000[] = INCBIN_U32("graphics/contest/misc_2_tilemap_2.bin.lz"); const u32 gUnknown_08C1A12C[] = INCBIN_U32("graphics/contest/misc_2_tilemap_3.bin.lz"); - -const u32 gUnknown_08C1A2B4[] = INCBIN_U32("graphics/contest/misc_2.gbapal.lz"); +const u32 gContestResults_Pal[] = INCBIN_U32("graphics/contest/results_screen.gbapal.lz"); const u32 gBattleAnimSpriteGfx_Impact[] = INCBIN_U32("graphics/battle_anims/sprites/impact.4bpp.lz"); const u32 gBattleAnimSpritePal_Impact[] = INCBIN_U32("graphics/battle_anims/sprites/impact.gbapal.lz"); @@ -875,8 +873,8 @@ const u32 gSubstituteDollTilemap[] = INCBIN_U32("graphics/battle_anims/sprites/s const u32 gBattleAnimSpriteGfx_GreenStar[] = INCBIN_U32("graphics/battle_anims/sprites/green_star.4bpp.lz"); const u32 gBattleAnimSpritePal_GreenStar[] = INCBIN_U32("graphics/battle_anims/sprites/green_star.gbapal.lz"); -const u32 gContestConfetti_Gfx[] = INCBIN_U32("graphics/misc/confetti.4bpp.lz"); -const u32 gContestConfetti_Pal[] = INCBIN_U32("graphics/misc/confetti.gbapal.lz"); +const u32 gConfetti_Gfx[] = INCBIN_U32("graphics/misc/confetti.4bpp.lz"); +const u32 gConfetti_Pal[] = INCBIN_U32("graphics/misc/confetti.gbapal.lz"); const u32 gBattleAnimSpriteGfx_PinkCloud[] = INCBIN_U32("graphics/battle_anims/sprites/pink_cloud.4bpp.lz"); const u32 gBattleAnimSpritePal_PinkCloud[] = INCBIN_U32("graphics/battle_anims/sprites/pink_cloud.gbapal.lz"); @@ -1298,19 +1296,19 @@ const u8 gFireRedMenuElements_Gfx[] = INCBIN_U8("graphics/interface_fr/menu.4bpp const u8 gBagMenuHMIcon_Gfx[] = INCBIN_U8("graphics/interface/hm.4bpp"); -// contest link stuff, appears to be a set of tilemaps +// contest results screen -const u16 gUnknown_08DC63F8[] = INCBIN_U16("graphics/contest/clink_tilemap1.bin"); -const u16 gUnknown_08DC6420[] = INCBIN_U16("graphics/contest/clink_tilemap2.bin"); -const u16 gUnknown_08DC6448[] = INCBIN_U16("graphics/contest/clink_tilemap3.bin"); -const u16 gUnknown_08DC6470[] = INCBIN_U16("graphics/contest/clink_tilemap4.bin"); -const u16 gUnknown_08DC6498[] = INCBIN_U16("graphics/contest/clink_tilemap5.bin"); -const u16 gUnknown_08DC64AC[] = INCBIN_U16("graphics/contest/clink_tilemap6.bin"); -const u16 gUnknown_08DC64C0[] = INCBIN_U16("graphics/contest/clink_tilemap7.bin"); -const u16 gUnknown_08DC64D4[] = INCBIN_U16("graphics/contest/clink_tilemap8.bin"); -const u16 gUnknown_08DC64E8[] = INCBIN_U16("graphics/contest/clink_tilemap9.bin"); -const u16 gUnknown_08DC64FC[] = INCBIN_U16("graphics/contest/clink_tilemap10.bin"); -const u16 gUnknown_08DC6510[] = INCBIN_U16("graphics/contest/clink_tilemap11.bin"); +const u16 gNormalContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_normal.bin"); +const u16 gSuperContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_super.bin"); +const u16 gHyperContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_hyper.bin"); +const u16 gMasterContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_master.bin"); +const u16 gLinkContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_link.bin"); +const u16 gCoolContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_cool.bin"); +const u16 gBeautyContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_beauty.bin"); +const u16 gCuteContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_cute.bin"); +const u16 gSmartContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_smart.bin"); +const u16 gToughContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen_tough.bin"); +const u16 gContestResults_Tilemap[] = INCBIN_U16("graphics/contest/results_screen.bin"); // pokenav diff --git a/src/gym_leader_rematch.c b/src/gym_leader_rematch.c index 355ae5534..efe874894 100644 --- a/src/gym_leader_rematch.c +++ b/src/gym_leader_rematch.c @@ -1,5 +1,4 @@ #include "global.h" -#include "constants/flags.h" #include "random.h" #include "event_data.h" #include "battle_setup.h" diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index b4745ff4e..f4c971b0b 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -33,9 +33,12 @@ #include "fldeff_misc.h" #include "trainer_pokemon_sprites.h" #include "data.h" -#include "rom_81520A8.h" +#include "confetti_util.h" #include "constants/rgb.h" +#define HALL_OF_FAME_MAX_TEAMS 50 +#define TAG_CONFETTI 1001 + struct HallofFameMon { u32 tid; @@ -58,33 +61,31 @@ struct HofGfx u8 tilemap2[0x1000]; }; -static EWRAM_DATA u32 sUnknown_0203BCD4 = 0; +static EWRAM_DATA u32 sHofFadePalettes = 0; static EWRAM_DATA struct HallofFameTeam *sHofMonPtr = NULL; static EWRAM_DATA struct HofGfx *sHofGfxPtr = NULL; extern struct MusicPlayerInfo gMPlayInfo_BGM; -#define HALL_OF_FAME_MAX_TEAMS 50 - // this file's functions static void ClearVramOamPltt_LoadHofPal(void); -static void sub_8174F70(void); -static void sub_8174FAC(void); -static bool8 sub_81751FC(void); +static void LoadHofGfx(void); +static void InitHofBgs(void); +static bool8 CreateHofConfettiSprite(void); static void SetCallback2AfterHallOfFameDisplay(void); static bool8 sub_8175024(void); static void Task_Hof_InitMonData(u8 taskId); static void Task_Hof_InitTeamSaveData(u8 taskId); static void Task_Hof_SetMonDisplayTask(u8 taskId); static void Task_Hof_TrySaveData(u8 taskId); -static void Task_Hof_WaitForFrames(u8 taskId); +static void Task_Hof_WaitToDisplayMon(u8 taskId); static void Task_Hof_DisplayMon(u8 taskId); static void Task_Hof_PrintMonInfoAfterAnimating(u8 taskId); static void Task_Hof_TryDisplayAnotherMon(u8 taskId); static void Task_Hof_PaletteFadeAndPrintWelcomeText(u8 taskId); -static void sub_8173DC0(u8 taskId); -static void sub_8173EA4(u8 taskId); -static void sub_8173EE4(u8 taskId); +static void Task_Hof_DoConfetti(u8 taskId); +static void Task_Hof_WaitToDisplayPlayer(u8 taskId); +static void Task_Hof_DisplayPlayer(u8 taskId); static void Task_Hof_WaitAndPrintPlayerInfo(u8 taskId); static void Task_Hof_ExitOnKeyPressed(u8 taskId); static void Task_Hof_HandlePaletteOnExit(u8 taskId); @@ -101,8 +102,8 @@ static void SpriteCB_GetOnScreenAndAnimate(struct Sprite *sprite); static void HallOfFame_PrintMonInfo(struct HallofFameMon* currMon, u8 unused1, u8 unused2); static void HallOfFame_PrintWelcomeText(u8 unusedPossiblyWindowId, u8 unused2); static void HallOfFame_PrintPlayerInfo(u8 unused1, u8 unused2); -static void Task_DoConfettiEffect(u8 taskId); -static void sub_81751A4(struct Sprite* sprite); +static void Task_DoDomeConfetti(u8 taskId); +static void SpriteCB_HofConfetti(struct Sprite* sprite); // const rom data static const struct BgTemplate sHof_BgTemplates[] = @@ -143,15 +144,15 @@ static const u8 sPlayerInfoTextColors[4] = {TEXT_COLOR_TRANSPARENT, TEXT_COLOR_D static const u8 sUnused_085E538C[] = {4, 5, 0, 0}; -static const struct CompressedSpriteSheet sHallOfFame_ConfettiSpriteSheet[] = +static const struct CompressedSpriteSheet sSpriteSheet_Confetti[] = { - {gContestConfetti_Gfx, 0x220, 1001}, + {.data = gConfetti_Gfx, .size = 0x220, .tag = TAG_CONFETTI}, {}, }; -static const struct CompressedSpritePalette sHallOfFame_ConfettiSpritePalette[] = +static const struct CompressedSpritePalette sSpritePalette_Confetti[] = { - {gContestConfetti_Pal, 1001}, + {.data = gConfetti_Pal, .tag = TAG_CONFETTI}, {}, }; @@ -172,7 +173,7 @@ static const s16 sHallOfFame_MonHalfTeamPositions[PARTY_SIZE / 2][4] = {-86, 244, 184, 64} }; -static const struct OamData sOamData_85E53FC = +static const struct OamData sOamData_Confetti = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -189,126 +190,138 @@ static const struct OamData sOamData_85E53FC = .affineParam = 0, }; -static const union AnimCmd sSpriteAnim_85E5404[] = +static const union AnimCmd sAnim_PinkConfettiA[] = { ANIMCMD_FRAME(0, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E540C[] = +static const union AnimCmd sAnim_RedConfettiA[] = { ANIMCMD_FRAME(1, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5414[] = +static const union AnimCmd sAnim_BlueConfettiA[] = { ANIMCMD_FRAME(2, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E541C[] = +static const union AnimCmd sAnim_RedConfettiB[] = { ANIMCMD_FRAME(3, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5424[] = +static const union AnimCmd sAnim_BlueConfettiB[] = { ANIMCMD_FRAME(4, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E542C[] = +static const union AnimCmd sAnim_YellowConfettiA[] = { ANIMCMD_FRAME(5, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5434[] = +static const union AnimCmd sAnim_WhiteConfettiA[] = { ANIMCMD_FRAME(6, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E543C[] = +static const union AnimCmd sAnim_GreenConfettiA[] = { ANIMCMD_FRAME(7, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5444[] = +static const union AnimCmd sAnim_PinkConfettiB[] = { ANIMCMD_FRAME(8, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E544C[] = +static const union AnimCmd sAnim_BlueConfettiC[] = { ANIMCMD_FRAME(9, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5454[] = +static const union AnimCmd sAnim_YellowConfettiB[] = { ANIMCMD_FRAME(10, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E545C[] = +static const union AnimCmd sAnim_WhiteConfettiB[] = { ANIMCMD_FRAME(11, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5464[] = +static const union AnimCmd sAnim_GreenConfettiB[] = { ANIMCMD_FRAME(12, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E546C[] = +static const union AnimCmd sAnim_PinkConfettiC[] = { ANIMCMD_FRAME(13, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5474[] = +static const union AnimCmd sAnim_RedConfettiC[] = { ANIMCMD_FRAME(14, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E547C[] = +static const union AnimCmd sAnim_YellowConfettiC[] = { ANIMCMD_FRAME(15, 30), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_85E5484[] = +static const union AnimCmd sAnim_WhiteConfettiC[] = { ANIMCMD_FRAME(16, 30), ANIMCMD_END }; -static const union AnimCmd * const sSpriteAnimTable_85E548C[] = +static const union AnimCmd * const sAnims_Confetti[] = { - sSpriteAnim_85E5404, sSpriteAnim_85E540C, sSpriteAnim_85E5414, sSpriteAnim_85E541C, - sSpriteAnim_85E5424, sSpriteAnim_85E542C, sSpriteAnim_85E5434, sSpriteAnim_85E543C, - sSpriteAnim_85E5444, sSpriteAnim_85E544C, sSpriteAnim_85E5454, sSpriteAnim_85E545C, - sSpriteAnim_85E5464, sSpriteAnim_85E546C, sSpriteAnim_85E5474, sSpriteAnim_85E547C, - sSpriteAnim_85E5484 + sAnim_PinkConfettiA, + sAnim_RedConfettiA, + sAnim_BlueConfettiA, + sAnim_RedConfettiB, + sAnim_BlueConfettiB, + sAnim_YellowConfettiA, + sAnim_WhiteConfettiA, + sAnim_GreenConfettiA, + sAnim_PinkConfettiB, + sAnim_BlueConfettiC, + sAnim_YellowConfettiB, + sAnim_WhiteConfettiB, + sAnim_GreenConfettiB, + sAnim_PinkConfettiC, + sAnim_RedConfettiC, + sAnim_YellowConfettiC, + sAnim_WhiteConfettiC }; -static const struct SpriteTemplate sSpriteTemplate_85E54D0 = +static const struct SpriteTemplate sSpriteTemplate_HofConfetti = { - .tileTag = 1001, - .paletteTag = 1001, - .oam = &sOamData_85E53FC, - .anims = sSpriteAnimTable_85E548C, + .tileTag = TAG_CONFETTI, + .paletteTag = TAG_CONFETTI, + .oam = &sOamData_Confetti, + .anims = sAnims_Confetti, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, - .callback = sub_81751A4 + .callback = SpriteCB_HofConfetti }; static const u16 sHallOfFame_Pal[] = INCBIN_U16("graphics/misc/japanese_hof.gbapal"); @@ -317,10 +330,19 @@ static const u32 sHallOfFame_Gfx[] = INCBIN_U32("graphics/misc/japanese_hof.4bpp static const struct HallofFameMon sDummyFameMon = { - 0x3EA03EA, 0, 0, 0, {0} + .tid = 0x3EA03EA, + .personality = 0, + .species = SPECIES_NONE, + .lvl = 0, + .nick = {0} }; -static const u8 sUnused2[] = {2, 1, 3, 6, 4, 5, 0, 0}; +// Unused, order of party slots on Hall of Fame screen +static const u8 sHallOfFame_SlotOrder[] = { + 2, 1, 3, + 6, 4, 5, + 0, 0 +}; // code static void VBlankCB_HallOfFame(void) @@ -350,14 +372,14 @@ static bool8 InitHallOfFameScreen(void) gMain.state = 1; break; case 1: - sub_8174F70(); + LoadHofGfx(); gMain.state++; break; case 2: 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(); + InitHofBgs(); sHofGfxPtr->state = 0; gMain.state++; break; @@ -433,7 +455,7 @@ static void Task_Hof_InitMonData(u8 taskId) } else { - sHofMonPtr->mon[i].species = 0; + sHofMonPtr->mon[i].species = SPECIES_NONE; sHofMonPtr->mon[i].tid = 0; sHofMonPtr->mon[i].personality = 0; sHofMonPtr->mon[i].lvl = 0; @@ -441,7 +463,7 @@ static void Task_Hof_InitMonData(u8 taskId) } } - sUnknown_0203BCD4 = 0; + sHofFadePalettes = 0; gTasks[taskId].tDisplayedMonId = 0; gTasks[taskId].tPlayerSpriteID = 0xFF; @@ -514,12 +536,12 @@ static void Task_Hof_TrySaveData(u8 taskId) else { PlaySE(SE_SAVE); - gTasks[taskId].func = Task_Hof_WaitForFrames; + gTasks[taskId].func = Task_Hof_WaitToDisplayMon; gTasks[taskId].tFrameCount = 32; } } -static void Task_Hof_WaitForFrames(u8 taskId) +static void Task_Hof_WaitToDisplayMon(u8 taskId) { if (gTasks[taskId].tFrameCount) gTasks[taskId].tFrameCount--; @@ -539,32 +561,32 @@ static void Task_Hof_SetMonDisplayTask(u8 taskId) static void Task_Hof_DisplayMon(u8 taskId) { u8 spriteId; - s16 xPos, yPos, field4, field6; + s16 startX, startY, destX, destY; u16 currMonId = gTasks[taskId].tDisplayedMonId; struct HallofFameMon* currMon = &sHofMonPtr->mon[currMonId]; if (gTasks[taskId].tMonNumber > PARTY_SIZE / 2) { - xPos = sHallOfFame_MonFullTeamPositions[currMonId][0]; - yPos = sHallOfFame_MonFullTeamPositions[currMonId][1]; - field4 = sHallOfFame_MonFullTeamPositions[currMonId][2]; - field6 = sHallOfFame_MonFullTeamPositions[currMonId][3]; + startX = sHallOfFame_MonFullTeamPositions[currMonId][0]; + startY = sHallOfFame_MonFullTeamPositions[currMonId][1]; + destX = sHallOfFame_MonFullTeamPositions[currMonId][2]; + destY = sHallOfFame_MonFullTeamPositions[currMonId][3]; } else { - xPos = sHallOfFame_MonHalfTeamPositions[currMonId][0]; - yPos = sHallOfFame_MonHalfTeamPositions[currMonId][1]; - field4 = sHallOfFame_MonHalfTeamPositions[currMonId][2]; - field6 = sHallOfFame_MonHalfTeamPositions[currMonId][3]; + startX = sHallOfFame_MonHalfTeamPositions[currMonId][0]; + startY = sHallOfFame_MonHalfTeamPositions[currMonId][1]; + destX = sHallOfFame_MonHalfTeamPositions[currMonId][2]; + destY = sHallOfFame_MonHalfTeamPositions[currMonId][3]; } if (currMon->species == SPECIES_EGG) - field6 += 10; + destY += 10; - spriteId = CreatePicSprite2(currMon->species, currMon->tid, currMon->personality, 1, xPos, yPos, currMonId, 0xFFFF); - gSprites[spriteId].tDestinationX = field4; - gSprites[spriteId].tDestinationY = field6; + spriteId = CreatePicSprite2(currMon->species, currMon->tid, currMon->personality, 1, startX, startY, currMonId, 0xFFFF); + gSprites[spriteId].tDestinationX = destX; + gSprites[spriteId].tDestinationY = destY; gSprites[spriteId].data[0] = 0; gSprites[spriteId].tSpecies = currMon->species; gSprites[spriteId].callback = SpriteCB_GetOnScreenAndAnimate; @@ -599,11 +621,11 @@ static void Task_Hof_TryDisplayAnotherMon(u8 taskId) } else { - sUnknown_0203BCD4 |= (0x10000 << gSprites[gTasks[taskId].tMonSpriteId(currPokeID)].oam.paletteNum); - if (gTasks[taskId].tDisplayedMonId <= 4 && currMon[1].species != SPECIES_NONE) // there is another pokemon to display + sHofFadePalettes |= (0x10000 << gSprites[gTasks[taskId].tMonSpriteId(currPokeID)].oam.paletteNum); + if (gTasks[taskId].tDisplayedMonId < PARTY_SIZE - 1 && currMon[1].species != SPECIES_NONE) // there is another pokemon to display { gTasks[taskId].tDisplayedMonId++; - BeginNormalPaletteFade(sUnknown_0203BCD4, 0, 12, 12, RGB(16, 29, 24)); + BeginNormalPaletteFade(sHofFadePalettes, 0, 12, 12, RGB(16, 29, 24)); gSprites[gTasks[taskId].tMonSpriteId(currPokeID)].oam.priority = 1; gTasks[taskId].func = Task_Hof_DisplayMon; } @@ -628,16 +650,19 @@ static void Task_Hof_PaletteFadeAndPrintWelcomeText(u8 taskId) HallOfFame_PrintWelcomeText(0, 15); PlaySE(SE_DENDOU); gTasks[taskId].tFrameCount = 400; - gTasks[taskId].func = sub_8173DC0; + gTasks[taskId].func = Task_Hof_DoConfetti; } -static void sub_8173DC0(u8 taskId) +static void Task_Hof_DoConfetti(u8 taskId) { if (gTasks[taskId].tFrameCount != 0) { gTasks[taskId].tFrameCount--; + + // Create new confetti every 4th frame for the first 290 frames + // For the last 110 frames wait for the existing confetti to fall offscreen if ((gTasks[taskId].tFrameCount & 3) == 0 && gTasks[taskId].tFrameCount > 110) - sub_81751FC(); + CreateHofConfettiSprite(); } else { @@ -647,19 +672,19 @@ static void sub_8173DC0(u8 taskId) if (gTasks[taskId].tMonSpriteId(i) != 0xFF) gSprites[gTasks[taskId].tMonSpriteId(i)].oam.priority = 1; } - BeginNormalPaletteFade(sUnknown_0203BCD4, 0, 12, 12, RGB(16, 29, 24)); + BeginNormalPaletteFade(sHofFadePalettes, 0, 12, 12, RGB(16, 29, 24)); FillWindowPixelBuffer(0, PIXEL_FILL(0)); CopyWindowToVram(0, 3); gTasks[taskId].tFrameCount = 7; - gTasks[taskId].func = sub_8173EA4; + gTasks[taskId].func = Task_Hof_WaitToDisplayPlayer; } } -static void sub_8173EA4(u8 taskId) +static void Task_Hof_WaitToDisplayPlayer(u8 taskId) { if (gTasks[taskId].tFrameCount >= 16) { - gTasks[taskId].func = sub_8173EE4; + gTasks[taskId].func = Task_Hof_DisplayPlayer; } else { @@ -668,7 +693,7 @@ static void sub_8173EA4(u8 taskId) } } -static void sub_8173EE4(u8 taskId) +static void Task_Hof_DisplayPlayer(u8 taskId) { SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); ShowBg(0); @@ -784,14 +809,14 @@ void CB2_DoHallOfFamePC(void) gMain.state = 1; break; case 1: - sub_8174F70(); + LoadHofGfx(); gMain.state++; break; case 2: SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); SetGpuReg(REG_OFFSET_BLDY, 0); - sub_8174FAC(); + InitHofBgs(); gMain.state++; break; case 3: @@ -874,7 +899,7 @@ static void Task_HofPC_DrawSpritesPrintText(u8 taskId) savedTeams++; currMon = &savedTeams->mon[0]; - sUnknown_0203BCD4 = 0; + sHofFadePalettes = 0; gTasks[taskId].tCurrMonId = 0; gTasks[taskId].tMonNo = 0; @@ -949,8 +974,8 @@ static void Task_HofPC_PrintMonInfo(u8 taskId) currMonID = gTasks[taskId].tMonSpriteId(gTasks[taskId].tCurrMonId); gSprites[currMonID].oam.priority = 0; - sUnknown_0203BCD4 = (0x10000 << gSprites[currMonID].oam.paletteNum) ^ 0xFFFF0000; - BlendPalettesUnfaded(sUnknown_0203BCD4, 0xC, RGB(16, 29, 24)); + sHofFadePalettes = (0x10000 << gSprites[currMonID].oam.paletteNum) ^ 0xFFFF0000; + BlendPalettesUnfaded(sHofFadePalettes, 0xC, RGB(16, 29, 24)); currMon = &savedTeams->mon[gTasks[taskId].tCurrMonId]; if (currMon->species != SPECIES_EGG) @@ -972,7 +997,7 @@ static void Task_HofPC_HandleInput(u8 taskId) if (gTasks[taskId].tCurrTeamNo != 0) // prepare another team to view { gTasks[taskId].tCurrTeamNo--; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { u8 spriteId = gTasks[taskId].tMonSpriteId(i); if (spriteId != 0xFF) @@ -1250,7 +1275,7 @@ static void ClearVramOamPltt_LoadHofPal(void) LoadPalette(sHallOfFame_Pal, 0, 0x20); } -static void sub_8174F70(void) +static void LoadHofGfx(void) { ScanlineEffect_Stop(); ResetTasks(); @@ -1259,11 +1284,11 @@ static void sub_8174F70(void) ResetAllPicSprites(); FreeAllSpritePalettes(); gReservedSpritePaletteCount = 8; - LoadCompressedSpriteSheet(sHallOfFame_ConfettiSpriteSheet); - LoadCompressedSpritePalette(sHallOfFame_ConfettiSpritePalette); + LoadCompressedSpriteSheet(sSpriteSheet_Confetti); + LoadCompressedSpritePalette(sSpritePalette_Confetti); } -static void sub_8174FAC(void) +static void InitHofBgs(void) { ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sHof_BgTemplates, ARRAY_COUNT(sHof_BgTemplates)); @@ -1344,7 +1369,10 @@ static void SpriteCB_GetOnScreenAndAnimate(struct Sprite *sprite) #undef tDestinationY #undef tSpecies -static void sub_81751A4(struct Sprite* sprite) +#define sSineIdx data[0] +#define sExtraY data[1] + +static void SpriteCB_HofConfetti(struct Sprite* sprite) { if (sprite->pos2.y > 120) { @@ -1353,20 +1381,20 @@ static void sub_81751A4(struct Sprite* sprite) else { u16 rand; - u8 tableID; + u8 sineIdx; sprite->pos2.y++; - sprite->pos2.y += sprite->data[1]; + sprite->pos2.y += sprite->sExtraY; - tableID = sprite->data[0]; + sineIdx = sprite->sSineIdx; rand = (Random() % 4) + 8; - sprite->pos2.x = rand * gSineTable[tableID] / 256; + sprite->pos2.x = rand * gSineTable[sineIdx] / 256; - sprite->data[0] += 4; + sprite->sSineIdx += 4; } } -static bool8 sub_81751FC(void) +static bool8 CreateHofConfettiSprite(void) { u8 spriteID; struct Sprite* sprite; @@ -1374,110 +1402,136 @@ static bool8 sub_81751FC(void) s16 posX = Random() % 240; s16 posY = -(Random() % 8); - spriteID = CreateSprite(&sSpriteTemplate_85E54D0, posX, posY, 0); + spriteID = CreateSprite(&sSpriteTemplate_HofConfetti, posX, posY, 0); sprite = &gSprites[spriteID]; - StartSpriteAnim(sprite, Random() % 17); + StartSpriteAnim(sprite, Random() % ARRAY_COUNT(sAnims_Confetti)); + // 1/4 confetti sprites move an extra Y coord each frame if (Random() & 3) - sprite->data[1] = 0; + sprite->sExtraY = 0; else - sprite->data[1] = 1; + sprite->sExtraY = 1; return FALSE; } -// Used when a Battle Dome tourney is won -void DoConfettiEffect(void) +// The below confetti functions are used when a Battle Dome tourney is won +// For the Hall of Fame confetti see Task_Hof_DoConfetti +// The end result is essentially the same, just a very different way of handling it +#define tState data[0] +#define tTimer data[1] +#define tConfettiCount data[15] + +// Indexes into the data array of the struct ConfettiUtil +#define CONFETTI_SINE_IDX 0 +#define CONFETTI_EXTRA_Y 1 +#define CONFETTI_TASK_ID 7 + +void DoDomeConfetti(void) { u8 taskId; gSpecialVar_0x8004 = 180; - taskId = CreateTask(Task_DoConfettiEffect, 0); + taskId = CreateTask(Task_DoDomeConfetti, 0); if (taskId != 0xFF) { - gTasks[taskId].data[1] = gSpecialVar_0x8004; + gTasks[taskId].tTimer = gSpecialVar_0x8004; gSpecialVar_0x8005 = taskId; } } -static void StopConfettiEffect(void) +static void StopDomeConfetti(void) { u8 taskId; - if ((taskId = FindTaskIdByFunc(Task_DoConfettiEffect)) != 0xFF) + if ((taskId = FindTaskIdByFunc(Task_DoDomeConfetti)) != 0xFF) DestroyTask(taskId); - sub_8152254(); - FreeSpriteTilesByTag(0x3E9); - FreeSpritePaletteByTag(0x3E9); + ConfettiUtil_Free(); + FreeSpriteTilesByTag(TAG_CONFETTI); + FreeSpritePaletteByTag(TAG_CONFETTI); } -static void sub_81752F4(struct UnkStruct_81520A8 *structPtr) +static void UpdateDomeConfetti(struct ConfettiUtil *util) { - if (structPtr->yDelta > 110) + if (util->yDelta > 110) { - gTasks[structPtr->data[7]].data[15]--; - sub_81525D0(structPtr->id); + // Destroy confetti after it falls far enough + gTasks[util->data[CONFETTI_TASK_ID]].tConfettiCount--; + ConfettiUtil_Remove(util->id); } else { - u8 var; + // Move confetti down + u8 sineIdx; s32 rand; - structPtr->yDelta++; - structPtr->yDelta += structPtr->data[1]; + util->yDelta++; + util->yDelta += util->data[CONFETTI_EXTRA_Y]; - var = structPtr->data[0]; + sineIdx = util->data[CONFETTI_SINE_IDX]; rand = Random(); rand &= 3; rand += 8; - structPtr->xDelta = (rand) * ((gSineTable[var])) / 256; + util->xDelta = (rand) * ((gSineTable[sineIdx])) / 256; - structPtr->data[0] += 4; + util->data[CONFETTI_SINE_IDX] += 4; } } -static void Task_DoConfettiEffect(u8 taskId) +static void Task_DoDomeConfetti(u8 taskId) { - u32 var = 0; + u32 id = 0; u16 *data = gTasks[taskId].data; - switch (data[0]) + switch (tState) { case 0: - if (!sub_81521C0(0x40)) + if (!ConfettiUtil_Init(64)) { + // Init failed DestroyTask(taskId); - gSpecialVar_0x8004 = var; + gSpecialVar_0x8004 = 0; gSpecialVar_0x8005 = 0xFFFF; } - LoadCompressedSpriteSheet(sHallOfFame_ConfettiSpriteSheet); - LoadCompressedSpritePalette(sHallOfFame_ConfettiSpritePalette); - data[0]++; + LoadCompressedSpriteSheet(sSpriteSheet_Confetti); + LoadCompressedSpritePalette(sSpritePalette_Confetti); + tState++; break; case 1: - if (data[1] != 0 && data[1] % 3 == 0) + if (tTimer != 0 && tTimer % 3 == 0) { - var = sub_81524C4(&sOamData_85E53FC, 0x3E9, 0x3E9, Random() % 240, -(Random() % 8), Random() % 0x11, var); - if (var != 0xFF) + // Create new confetti every 3 frames + id = ConfettiUtil_AddNew(&sOamData_Confetti, + TAG_CONFETTI, + TAG_CONFETTI, + Random() % 240, + -(Random() % 8), + Random() % ARRAY_COUNT(sAnims_Confetti), + id); + if (id != 0xFF) { - sub_8152438(var, sub_81752F4); - if ((Random() & 3) == 0) - sub_8152474(var, 1, 1); - sub_8152474(var, 7, taskId); - data[15]++; + ConfettiUtil_SetCallback(id, UpdateDomeConfetti); + + // 1/4 of the confetti move an extra y coord every frame + if ((Random() % 4) == 0) + ConfettiUtil_SetData(id, CONFETTI_EXTRA_Y, 1); + + ConfettiUtil_SetData(id, CONFETTI_TASK_ID, taskId); + tConfettiCount++; } } - sub_81522D4(); - if (data[1] != 0) - data[1]--; - else if (data[15] == 0) - data[0] = 0xFF; + + ConfettiUtil_Update(); + if (tTimer != 0) + tTimer--; + else if (tConfettiCount == 0) + tState = 0xFF; break; case 0xFF: - StopConfettiEffect(); - gSpecialVar_0x8004 = var; + StopDomeConfetti(); + gSpecialVar_0x8004 = 0; gSpecialVar_0x8005 = 0xFFFF; break; } diff --git a/src/item_menu.c b/src/item_menu.c index 3b4331dcb..ae09ec7ed 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -1776,7 +1776,7 @@ void Task_ChooseHowManyToToss(u8 taskId) if (AdjustQuantityAccordingToDPadInput(&tItemCount, data[2]) == TRUE) { - PrintItemDepositAmount(gBagMenu->unk817, tItemCount); + PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); } else if (gMain.newKeys & A_BUTTON) { @@ -2050,7 +2050,7 @@ void Task_BuyHowManyDialogueHandleInput(u8 taskId) if (AdjustQuantityAccordingToDPadInput(&tItemCount, data[2]) == TRUE) { - PrintItemSoldAmount(gBagMenu->unk818, tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); + PrintItemSoldAmount(gBagMenu->windowPointers[8], tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); } else if (gMain.newKeys & A_BUTTON) { @@ -2094,7 +2094,7 @@ void sub_81AD8C8(u8 taskId) LoadBagItemListBuffers(gBagPositionStruct.pocket); data[0] = ListMenuInit(&gMultiuseListMenuTemplate, *scrollPos, *cursorPos); BagMenu_PrintCursor_(data[0], 2); - PrintMoneyAmountInMoneyBox(gBagMenu->unk819, GetMoney(&gSaveBlock1Ptr->money), 0); + PrintMoneyAmountInMoneyBox(gBagMenu->windowPointers[9], GetMoney(&gSaveBlock1Ptr->money), 0); gTasks[taskId].func = sub_81AD9C0; } @@ -2134,7 +2134,7 @@ void sub_81ADA7C(u8 taskId) if (AdjustQuantityAccordingToDPadInput(&tItemCount, data[2]) == TRUE) { - PrintItemDepositAmount(gBagMenu->unk817, tItemCount); + PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); } else if (gMain.newKeys & A_BUTTON) { diff --git a/src/item_use.c b/src/item_use.c index a90321a3b..70a0cf5ae 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -38,11 +38,9 @@ #include "text.h" #include "constants/event_bg.h" #include "constants/event_objects.h" -#include "constants/flags.h" #include "constants/item_effects.h" #include "constants/items.h" #include "constants/songs.h" -#include "constants/vars.h" static void SetUpItemUseCallback(u8 taskId); static void FieldCB_UseItemOnField(void); diff --git a/src/main.c b/src/main.c index 5249d11fa..454fefc5c 100644 --- a/src/main.c +++ b/src/main.c @@ -280,7 +280,7 @@ static void ReadKeys(void) gMain.heldKeys = gMain.heldKeysRaw; // Remap L to A if the L=A option is enabled. - if (gSaveBlock2Ptr->optionsButtonMode == 2) + if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) { if (gMain.newKeys & L_BUTTON) gMain.newKeys |= A_BUTTON; diff --git a/src/main_menu.c b/src/main_menu.c index 91931e581..781d7f85c 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -1,7 +1,6 @@ #include "global.h" #include "trainer_pokemon_sprites.h" #include "bg.h" -#include "constants/flags.h" #include "constants/rgb.h" #include "constants/songs.h" #include "constants/species.h" diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index dc5a0b335..bbf0f8972 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -3,7 +3,6 @@ #include "constants/songs.h" #include "constants/easy_chat.h" #include "constants/event_objects.h" -#include "constants/vars.h" #include "mauville_old_man.h" #include "event_data.h" #include "string_util.h" diff --git a/src/menu.c b/src/menu.c index c821ef7e0..ac2f7d85b 100644 --- a/src/menu.c +++ b/src/menu.c @@ -18,7 +18,6 @@ #include "task.h" #include "text_window.h" #include "window.h" -#include "constants/flags.h" #include "constants/songs.h" #define DLG_WINDOW_PALETTE_NUM 15 diff --git a/src/mirage_tower.c b/src/mirage_tower.c index f61f7b988..908f1e8ba 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -14,7 +14,6 @@ #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" diff --git a/src/naming_screen.c b/src/naming_screen.c index 83285d89d..ab38db745 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -13,7 +13,6 @@ #include "field_player_avatar.h" #include "event_object_movement.h" #include "event_data.h" -#include "constants/vars.h" #include "constants/songs.h" #include "pokemon_storage_system.h" #include "graphics.h" diff --git a/src/party_menu.c b/src/party_menu.c index 7d97b580e..b8a58e725 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -67,7 +67,6 @@ #include "constants/battle_frontier.h" #include "constants/easy_chat.h" #include "constants/field_effects.h" -#include "constants/flags.h" #include "constants/item_effects.h" #include "constants/items.h" #include "constants/maps.h" @@ -76,7 +75,6 @@ #include "constants/rgb.h" #include "constants/songs.h" #include "constants/species.h" -#include "constants/vars.h" #define PARTY_PAL_SELECTED (1 << 0) #define PARTY_PAL_FAINTED (1 << 1) diff --git a/src/pokeball.c b/src/pokeball.c index d473f9ba0..1a0561c33 100644 --- a/src/pokeball.c +++ b/src/pokeball.c @@ -798,9 +798,9 @@ static void SpriteCB_ReleaseMonFromBall(struct Sprite *sprite) StartSpriteAffineAnim(&gSprites[gBattlerSpriteIds[sprite->sBattler]], 1); if (GetBattlerSide(sprite->sBattler) == B_SIDE_OPPONENT) - gSprites[gBattlerSpriteIds[sprite->sBattler]].callback = sub_8039B58; + gSprites[gBattlerSpriteIds[sprite->sBattler]].callback = SpriteCb_OpponentMonFromBall; else - gSprites[gBattlerSpriteIds[sprite->sBattler]].callback = sub_8039E44; + gSprites[gBattlerSpriteIds[sprite->sBattler]].callback = SpriteCb_PlayerMonFromBall; AnimateSprite(&gSprites[gBattlerSpriteIds[sprite->sBattler]]); gSprites[gBattlerSpriteIds[sprite->sBattler]].data[1] = 0x1000; diff --git a/src/pokedex.c b/src/pokedex.c index d2e1a0666..0541f3f2e 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -4521,7 +4521,11 @@ static void UnusedPrintMonName(u8 windowId, const u8* name, u8 left, u8 top) ; for (i = 0; i < nameLength; i++) str[ARRAY_COUNT(str) - nameLength + i] = name[i]; +#ifdef UBFIX + str[ARRAY_COUNT(str) - 1] = EOS; +#else str[ARRAY_COUNT(str)] = EOS; +#endif PrintInfoSubMenuText(windowId, str, left, top); } diff --git a/src/pokedex_area_screen.c b/src/pokedex_area_screen.c index a2545cc1a..0232d4fc4 100755 --- a/src/pokedex_area_screen.c +++ b/src/pokedex_area_screen.c @@ -21,7 +21,6 @@ #include "constants/rgb.h" #include "constants/songs.h" #include "constants/species.h" -#include "constants/vars.h" #define AREA_SCREEN_WIDTH 32 #define AREA_SCREEN_HEIGHT 20 diff --git a/src/pokemon.c b/src/pokemon.c index a6128572f..329240f99 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3234,7 +3234,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de damage /= 2; } - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == 8 && CountAliveMonsInBattle(BATTLE_ALIVE_DEF_SIDE) == 2) + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == MOVE_TARGET_BOTH && CountAliveMonsInBattle(BATTLE_ALIVE_DEF_SIDE) == 2) damage /= 2; // moves always do at least 1 damage. @@ -3281,7 +3281,7 @@ s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *de damage /= 2; } - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == 8 && CountAliveMonsInBattle(BATTLE_ALIVE_DEF_SIDE) == 2) + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == MOVE_TARGET_BOTH && CountAliveMonsInBattle(BATTLE_ALIVE_DEF_SIDE) == 2) damage /= 2; // are effects of weather negated with cloud nine or air lock diff --git a/src/pokenav_match_call_1.c b/src/pokenav_match_call_1.c index ef1d5343f..1e4239bbc 100755 --- a/src/pokenav_match_call_1.c +++ b/src/pokenav_match_call_1.c @@ -12,7 +12,6 @@ #include "sound.h" #include "string_util.h" #include "strings.h" -#include "constants/flags.h" #include "constants/songs.h" struct Pokenav3Struct diff --git a/src/post_battle_event_funcs.c b/src/post_battle_event_funcs.c index 4fa5d1b21..07690960f 100644 --- a/src/post_battle_event_funcs.c +++ b/src/post_battle_event_funcs.c @@ -8,7 +8,6 @@ #include "script_pokemon_util_80F87D8.h" #include "tv.h" #include "constants/heal_locations.h" -#include "constants/flags.h" #include "constants/tv.h" int GameClear(void) diff --git a/src/region_map.c b/src/region_map.c index 5880ad216..de3b04cb2 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -9,7 +9,6 @@ #include "trig.h" #include "constants/maps.h" #include "overworld.h" -#include "constants/flags.h" #include "event_data.h" #include "secret_base.h" #include "string_util.h" diff --git a/src/rom_81520A8.c b/src/rom_81520A8.c deleted file mode 100644 index 8b10d44d0..000000000 --- a/src/rom_81520A8.c +++ /dev/null @@ -1,218 +0,0 @@ -#include "global.h" -#include "rom_81520A8.h" -#include "malloc.h" -#include "main.h" -#include "digit_obj_util.h" - -static EWRAM_DATA struct -{ - u8 count; - struct UnkStruct_81520A8 *unk4; -} *sUnknown_0203ABB8 = NULL; - -void sub_81520A8(void *dest, u16 value, u8 left, u8 top, u8 width, u8 height) // Unused. -{ - u8 i; - u8 j; - u8 x; - u8 y; - - for (i = 0, y = top; i < height; i++) - { - for (x = left, j = 0; j < width; j++) - { - *(u16 *)((dest) + (y * 64 + x * 2)) = value; - x = (x + 1) % 32; - } - y = (y + 1) % 32; - } -} - -void sub_8152134(void *dest, const u16 *src, u8 left, u8 top, u8 width, u8 height) // Unused. -{ - u8 i; - u8 j; - u8 x; - u8 y; - const u16 *_src; - - for (i = 0, _src = src, y = top; i < height; i++) - { - for (x = left, j = 0; j < width; j++) - { - *(u16 *)((dest) + (y * 64 + x * 2)) = *(_src++); - x = (x + 1) % 32; - } - y = (y + 1) % 32; - } -} - -bool32 sub_81521C0(u8 count) -{ - u8 i = 0; - - if (count == 0) - return FALSE; - if (count > 64) - count = 64; - - sUnknown_0203ABB8 = AllocZeroed(sizeof(*sUnknown_0203ABB8)); - if (sUnknown_0203ABB8 == NULL) - return FALSE; - sUnknown_0203ABB8->unk4 = AllocZeroed(count * sizeof(struct UnkStruct_81520A8)); - if (sUnknown_0203ABB8->unk4 == NULL) - { - FREE_AND_SET_NULL(sUnknown_0203ABB8); - return FALSE; - } - - sUnknown_0203ABB8->count = count; - for (i = 0; i < count; i++) - { - memcpy(&sUnknown_0203ABB8->unk4[i].oam, &gDummyOamData, sizeof(struct OamData)); - sUnknown_0203ABB8->unk4[i].unk19_2 = TRUE; - } - - return TRUE; -} - -bool32 sub_8152254(void) -{ - u8 i = 0; - - if (sUnknown_0203ABB8 == NULL) - return FALSE; - - for (i = 0; i < sUnknown_0203ABB8->count; i++) - memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); - - memset(sUnknown_0203ABB8->unk4, 0, sUnknown_0203ABB8->count * sizeof(struct UnkStruct_81520A8)); - FREE_AND_SET_NULL(sUnknown_0203ABB8->unk4); - memset(sUnknown_0203ABB8, 0, sizeof(*sUnknown_0203ABB8)); - FREE_AND_SET_NULL(sUnknown_0203ABB8); - - return TRUE; -} - -bool32 sub_81522D4(void) -{ - u8 i = 0; - - if (sUnknown_0203ABB8 == NULL || sUnknown_0203ABB8->unk4 == NULL) - return FALSE; - - for (i = 0; i < sUnknown_0203ABB8->count; i++) - { - if (sUnknown_0203ABB8->unk4[i].unk19_0 && sUnknown_0203ABB8->unk4[i].unk19_1) - { - if (sUnknown_0203ABB8->unk4[i].callback != NULL) - sUnknown_0203ABB8->unk4[i].callback(&sUnknown_0203ABB8->unk4[i]); - - if (sUnknown_0203ABB8->unk4[i].unk19_2) - { - memcpy(&gMain.oamBuffer[i + 64], &gDummyOamData, sizeof(struct OamData)); - } - else - { - sUnknown_0203ABB8->unk4[i].oam.y = sUnknown_0203ABB8->unk4[i].y + sUnknown_0203ABB8->unk4[i].yDelta; - sUnknown_0203ABB8->unk4[i].oam.x = sUnknown_0203ABB8->unk4[i].x + sUnknown_0203ABB8->unk4[i].xDelta; - sUnknown_0203ABB8->unk4[i].oam.priority = sUnknown_0203ABB8->unk4[i].priority; - sUnknown_0203ABB8->unk4[i].oam.tileNum = sUnknown_0203ABB8->unk4[i].tileNum; - memcpy(&gMain.oamBuffer[i + 64], &sUnknown_0203ABB8->unk4[i], sizeof(struct OamData)); - } - } - } - - return TRUE; -} - -static bool32 sub_81523F4(struct UnkStruct_81520A8 *structPtr, u8 arg1) -{ - u16 tileStart; - - if (structPtr == NULL) - return FALSE; - - tileStart = GetSpriteTileStartByTag(structPtr->tileTag); - if (tileStart == 0xFFFF) - return FALSE; - - structPtr->unk18 = arg1; - structPtr->tileNum = (GetTilesPerImage(structPtr->oam.shape, structPtr->oam.size) * arg1) + tileStart; - return TRUE; -} - -u8 sub_8152438(u8 id, void (*func)(struct UnkStruct_81520A8 *)) -{ - if (sUnknown_0203ABB8 == NULL || id >= sUnknown_0203ABB8->count) - return 0xFF; - else if (!sUnknown_0203ABB8->unk4[id].unk19_0) - return 0xFF; - - sUnknown_0203ABB8->unk4[id].callback = func; - return id; -} - -u8 sub_8152474(u8 id, u8 dataArrayId, s16 dataValue) -{ - if (sUnknown_0203ABB8 == NULL || id >= sUnknown_0203ABB8->count) - return 0xFF; - else if (!sUnknown_0203ABB8->unk4[id].unk19_0 || dataArrayId >= ARRAY_COUNT(sUnknown_0203ABB8->unk4[id].data)) - return 0xFF; - - sUnknown_0203ABB8->unk4[id].data[dataArrayId] = dataValue; - return id; -} - -u8 sub_81524C4(const struct OamData *oam, u16 tileTag, u16 palTag, s16 x, s16 y, u8 arg5, u8 priority) -{ - struct UnkStruct_81520A8 *structPtr = NULL; - u8 i; - - if (sUnknown_0203ABB8 == NULL || oam == NULL) - return 0xFF; - - for (i = 0; i < sUnknown_0203ABB8->count; i++) - { - if (!sUnknown_0203ABB8->unk4[i].unk19_0) - { - structPtr = &sUnknown_0203ABB8->unk4[i]; - memset(structPtr, 0, sizeof(*structPtr)); - structPtr->id = i; - structPtr->unk19_0 = TRUE; - structPtr->unk19_1 = TRUE; - break; - } - } - - if (structPtr == NULL) - return 0xFF; - - memcpy(&structPtr->oam, oam, sizeof(*oam)); - structPtr->tileTag = tileTag; - structPtr->palTag = palTag; - structPtr->x = x; - structPtr->y = y; - structPtr->oam.paletteNum = IndexOfSpritePaletteTag(palTag); - if (priority < 4) - { - structPtr->priority = priority; - structPtr->oam.priority = priority; - } - sub_81523F4(structPtr, arg5); - - return structPtr->id; -} - -u8 sub_81525D0(u8 id) -{ - if (sUnknown_0203ABB8 == NULL || !sUnknown_0203ABB8->unk4[id].unk19_0) - return 0xFF; - - memset(&sUnknown_0203ABB8->unk4[id], 0, sizeof(struct UnkStruct_81520A8)); - sUnknown_0203ABB8->unk4[id].oam.y = 160; - sUnknown_0203ABB8->unk4[id].oam.x = 240; - sUnknown_0203ABB8->unk4[id].unk19_2 = TRUE; - memcpy(&gMain.oamBuffer[id + 64], &gDummyOamData, sizeof(struct OamData)); - return id; -} diff --git a/src/scrcmd.c b/src/scrcmd.c index 188084cc3..224d7adb5 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -5,7 +5,7 @@ #include "clock.h" #include "coins.h" #include "contest.h" -#include "contest_link_80F57C4.h" +#include "contest_util.h" #include "contest_painting.h" #include "data.h" #include "decoration.h" @@ -1470,7 +1470,9 @@ bool8 ScrCmd_hidemonpic(struct ScriptContext *ctx) bool8 ScrCmd_showcontestwinner(struct ScriptContext *ctx) { u8 contestWinnerId = ScriptReadByte(ctx); - if (contestWinnerId) + + // Don't save artist's painting yet + if (contestWinnerId != CONTEST_WINNER_ARTIST) SetContestWinnerForPainting(contestWinnerId); ShowContestWinner(); @@ -1954,14 +1956,14 @@ bool8 ScrCmd_startcontest(struct ScriptContext *ctx) bool8 ScrCmd_showcontestresults(struct ScriptContext *ctx) { - sub_80F8484(); + ShowContestResults(); ScriptContext1_Stop(); return TRUE; } bool8 ScrCmd_contestlinktransfer(struct ScriptContext *ctx) { - sub_80F84C4(gSpecialVar_ContestCategory); + ContestLinkTransfer(gSpecialVar_ContestCategory); ScriptContext1_Stop(); return TRUE; } diff --git a/src/script_pokemon_util_80F87D8.c b/src/script_pokemon_util_80F87D8.c index 134004fd0..70f68b879 100755 --- a/src/script_pokemon_util_80F87D8.c +++ b/src/script_pokemon_util_80F87D8.c @@ -3,7 +3,7 @@ #include "battle_gfx_sfx_util.h" #include "berry.h" #include "contest.h" -#include "contest_link_80F57C4.h" +#include "contest_util.h" #include "contest_painting.h" #include "data.h" #include "daycare.h" @@ -30,7 +30,6 @@ #include "constants/items.h" #include "constants/species.h" #include "constants/tv.h" -#include "constants/vars.h" #include "constants/battle_frontier.h" extern const u16 gObjectEventPalette8[]; @@ -122,7 +121,7 @@ void ShouldReadyContestArtist(void) { if (gContestFinalStandings[gContestPlayerMonIndex] == 0 && gSpecialVar_ContestRank == CONTEST_RANK_MASTER - && gUnknown_02039F08[gContestPlayerMonIndex] >= 800) + && gContestMonTotalPoints[gContestPlayerMonIndex] >= 800) { gSpecialVar_0x8004 = TRUE; } @@ -304,7 +303,7 @@ u8 GiveMonArtistRibbon(void) if (!hasArtistRibbon && gContestFinalStandings[gContestPlayerMonIndex] == 0 && gSpecialVar_ContestRank == CONTEST_RANK_MASTER - && gUnknown_02039F08[gContestPlayerMonIndex] >= 800) + && gContestMonTotalPoints[gContestPlayerMonIndex] >= 800) { hasArtistRibbon = 1; SetMonData(&gPlayerParty[gContestMonPartyIndex], MON_DATA_ARTIST_RIBBON, &hasArtistRibbon); diff --git a/src/secret_base.c b/src/secret_base.c index 172568db6..83626710f 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -37,6 +37,7 @@ #include "constants/event_bg.h" #include "constants/decorations.h" #include "constants/event_objects.h" +#include "constants/field_specials.h" #include "constants/items.h" #include "constants/maps.h" #include "constants/map_types.h" @@ -1120,7 +1121,7 @@ const u8 *GetSecretBaseTrainerLoseText(void) void PrepSecretBaseBattleFlags(void) { - TryGainNewFanFromCounter(1); + TryGainNewFanFromCounter(FANCOUNTER_BATTLED_AT_BASE); gTrainerBattleOpponent_A = TRAINER_SECRET_BASE; gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_SECRET_BASE; } diff --git a/src/strings.c b/src/strings.c index f01ab8ec6..324e6098a 100644 --- a/src/strings.c +++ b/src/strings.c @@ -1236,7 +1236,7 @@ const u8 gText_BDot[] = _("B."); const u8 gText_AnnouncingResults[] = _("Announcing the results!"); const u8 gText_PreliminaryResults[] = _("The preliminary results!"); const u8 gText_Round2Results[] = _("Round 2 results!"); -const u8 gText_Var1sVar2Won[] = _("{STR_VAR_1}'s {STR_VAR_2} won!"); +const u8 gText_ContestantsMonWon[] = _("{STR_VAR_1}'s {STR_VAR_2} won!"); const u8 gText_CommunicationStandby[] = _("Communication standby…"); const u8 gText_ColorDarkGrey[] = _("{COLOR DARK_GREY}"); const u8 gText_ColorDynamic6WhiteDynamic5[] = _("{COLOR_HIGHLIGHT_SHADOW DYNAMIC_COLOR6 WHITE DYNAMIC_COLOR5}"); // Unused diff --git a/src/trainer_card.c b/src/trainer_card.c index fb92dc336..d625bc13e 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -27,7 +27,6 @@ #include "trainer_pokemon_sprites.h" #include "script_pokemon_util_80F87D8.h" #include "constants/songs.h" -#include "constants/flags.h" #include "constants/game_stat.h" #include "constants/battle_frontier.h" #include "constants/rgb.h" diff --git a/src/union_room_player_avatar.c b/src/union_room_player_avatar.c index cac789685..c012fd84d 100644 --- a/src/union_room_player_avatar.c +++ b/src/union_room_player_avatar.c @@ -8,7 +8,6 @@ #include "union_room.h" #include "constants/event_objects.h" #include "constants/event_object_movement.h" -#include "constants/flags.h" #define UR_SPRITE_START_ID (MAX_SPRITES - MAX_UNION_ROOM_PLAYERS) #define UR_PLAYER_SPRITE_ID(playerIdx, facingDir)(5 * playerIdx + facingDir) diff --git a/sym_ewram.txt b/sym_ewram.txt index a00b72468..88c4461cb 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -75,7 +75,7 @@ .include "src/record_mixing.o" .include "src/secret_base.o" .include "src/tv.o" - .include "src/contest_link_80F57C4.o" + .include "src/contest_util.o" .include "src/rotating_gate.o" .include "src/safari_zone.o" .include "src/item_use.o" @@ -104,7 +104,7 @@ .include "src/battle_transition.o" .include "src/battle_message.o" .include "src/cable_car.o" - .include "src/rom_81520A8.o" + .include "src/confetti_util.o" .include "src/save.o" .include "src/mystery_event_script.o" .include "src/move_relearner.o" diff --git a/tools/gbagfx/main.c b/tools/gbagfx/main.c index 61e93ea45..cf3031696 100644 --- a/tools/gbagfx/main.c +++ b/tools/gbagfx/main.c @@ -92,6 +92,7 @@ void HandleGbaToPngCommand(char *inputPath, char *outputPath, int argc, char **a options.width = 1; options.metatileWidth = 1; options.metatileHeight = 1; + options.tilemapFilePath = NULL; options.isAffineMap = false; for (int i = 3; i < argc; i++)