From 28bd77763211e80cb63bd761ab669224deb8707f Mon Sep 17 00:00:00 2001 From: xCrystal Date: Sun, 24 Dec 2023 18:42:07 +0100 Subject: [PATCH] give/take coins action of blue/red space (#22) --- constants/map_data_constants.asm | 1 + constants/misc_constants.asm | 9 +++---- constants/script_constants.asm | 8 +++++-- data/maps/maps.asm | 18 +++++++------- engine/board/spaces.asm | 8 ++++--- engine/events/coins.asm | 21 ++++++++++++++-- engine/overworld/events.asm | 11 +++++++-- engine/overworld/scripting.asm | 41 ++++++++++++++++++++++++++++++-- ram/wram.asm | 4 ++++ 9 files changed, 98 insertions(+), 23 deletions(-) diff --git a/constants/map_data_constants.asm b/constants/map_data_constants.asm index a61c8222e..5a21d06dc 100644 --- a/constants/map_data_constants.asm +++ b/constants/map_data_constants.asm @@ -15,6 +15,7 @@ DEF MAP_LOCATION rb ; 5 DEF MAP_MUSIC rb ; 6 DEF MAP_PALETTE rb ; 7 DEF MAP_FISHGROUP rb ; 8 +DEF MAP_BASECOINS rb ; 9 DEF MAP_LENGTH EQU _RS ; map environments (wEnvironment) diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index 4f82fbbb2..db304d94c 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -35,10 +35,11 @@ DEF NOON_HOUR EQU 12 ; 12 PM DEF MAX_DAYS EQU 36 * 7 ; 252 ; significant coins values -DEF START_COINS EQU 3000 -DEF MOM_COINS EQU 2300 -DEF MAX_COINS EQU 999999 -DEF MAX_CHIPS EQU 9999 +DEF START_COINS EQU 100 +DEF MOM_COINS EQU 2300 +DEF MAX_COINS EQU 999999 +DEF MAX_LEVEL_COINS EQU 99999 +DEF MAX_CHIPS EQU 9999 ; link record DEF MAX_LINK_RECORD EQU 9999 diff --git a/constants/script_constants.asm b/constants/script_constants.asm index a2cde0fc6..660312528 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -13,8 +13,9 @@ DEF STRING_BUFFER_LENGTH EQU 19 ; checkcoins/takecoins accounts const_def - const YOUR_COINS ; 0 - const MOMS_COINS ; 1 + const YOUR_COINS ; 0 + const CUR_LEVEL_COINS ; 1 + const MOMS_COINS ; 2 ; checkcoins/checkchips return values const_def @@ -22,6 +23,9 @@ DEF STRING_BUFFER_LENGTH EQU 19 const HAVE_AMOUNT ; 1 const HAVE_LESS ; 2 +; givecoins/takecoins/checkcoins special amount values +DEF BLUE_RED_SPACE_COINS EQU $ffffff + ; checkpokemail return values const_def const POKEMAIL_WRONG_MAIL ; 0 diff --git a/data/maps/maps.asm b/data/maps/maps.asm index d80017965..cf54278f2 100644 --- a/data/maps/maps.asm +++ b/data/maps/maps.asm @@ -7,11 +7,13 @@ MACRO map ;\6: phone service flag: TRUE to prevent phone calls ;\7: time of day: a PALETTE_* constant ;\8: fishing group: a FISHGROUP_* constant +;\9: base coins: 8-bit value db BANK(\1_MapAttributes), \2, \3 dw \1_MapAttributes db \4, \5 dn \6, \7 db \8 + db \9 ENDM MapGroupPointers:: @@ -30,8 +32,8 @@ endc MapGroup_Level1: table_width MAP_LENGTH, MapGroup_Level1 - map Level1_Map1, TILESET_PLAYERS_ROOM, INDOOR_BUILDING, LANDMARK_LEVEL_1, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_DAY, FISHGROUP_SHORE -; map Level1_Map2, TILESET_CHAMPIONS_ROOM, INDOOR_CAVE, LANDMARK_LEVEL_2, MUSIC_GYM, TRUE, PALETTE_NITE | IN_DARKNESS, FISHGROUP_SHORE + map Level1_Map1, TILESET_PLAYERS_ROOM, INDOOR_BUILDING, LANDMARK_LEVEL_1, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_DAY, FISHGROUP_SHORE, 1 +; map Level1_Map2, TILESET_CHAMPIONS_ROOM, INDOOR_CAVE, LANDMARK_LEVEL_2, MUSIC_GYM, TRUE, PALETTE_NITE | IN_DARKNESS, FISHGROUP_SHORE, 1 assert_table_length NUM_LEVEL_1_MAPS ; MapGroup_Level2: @@ -42,27 +44,27 @@ MapGroup_Level1: if DEF(_DEBUG) MapGroup_DebugLevel1: table_width MAP_LENGTH, MapGroup_DebugLevel1 - map DebugLevel1_Map1, TILESET_PLAYERS_ROOM, INDOOR_BUILDING, LANDMARK_DEBUGLEVEL_1, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_DAY, FISHGROUP_SHORE + map DebugLevel1_Map1, TILESET_PLAYERS_ROOM, INDOOR_BUILDING, LANDMARK_DEBUGLEVEL_1, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_DAY, FISHGROUP_SHORE, 1 assert_table_length NUM_DEBUGLEVEL_1_MAPS MapGroup_DebugLevel2: table_width MAP_LENGTH, MapGroup_DebugLevel2 - map DebugLevel2_Map1, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE, FISHGROUP_SHORE - map DebugLevel2_Map2, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE, FISHGROUP_SHORE + map DebugLevel2_Map1, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE, FISHGROUP_SHORE, 2 + map DebugLevel2_Map2, TILESET_BOARD_DEBUG_2, INDOOR_CAVE, LANDMARK_DEBUGLEVEL_2, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_NITE, FISHGROUP_SHORE, 2 assert_table_length NUM_DEBUGLEVEL_2_MAPS MapGroup_DebugLevel3: table_width MAP_LENGTH, MapGroup_DebugLevel3 - map DebugLevel3_Map1, TILESET_FOREST, INDOOR_FOREST, LANDMARK_DEBUGLEVEL_3, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_AUTO, FISHGROUP_SHORE + map DebugLevel3_Map1, TILESET_FOREST, INDOOR_FOREST, LANDMARK_DEBUGLEVEL_3, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_AUTO, FISHGROUP_SHORE, 3 assert_table_length NUM_DEBUGLEVEL_3_MAPS MapGroup_DebugLevel4: table_width MAP_LENGTH, MapGroup_DebugLevel4 - map DebugLevel4_Map1, TILESET_BOARD_DEBUG_1, OUTDOOR_GRASSY, LANDMARK_DEBUGLEVEL_4, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_AUTO, FISHGROUP_SHORE + map DebugLevel4_Map1, TILESET_BOARD_DEBUG_1, OUTDOOR_GRASSY, LANDMARK_DEBUGLEVEL_4, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_AUTO, FISHGROUP_SHORE, 4 assert_table_length NUM_DEBUGLEVEL_4_MAPS MapGroup_DebugLevel5: table_width MAP_LENGTH, MapGroup_DebugLevel5 - map DebugLevel5_Map1, TILESET_BOARD_DEBUG_1, OUTDOOR_GRASSY, LANDMARK_DEBUGLEVEL_5, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_AUTO, FISHGROUP_SHORE + map DebugLevel5_Map1, TILESET_BOARD_DEBUG_1, OUTDOOR_GRASSY, LANDMARK_DEBUGLEVEL_5, MUSIC_NEW_BARK_TOWN, FALSE, PALETTE_AUTO, FISHGROUP_SHORE, 5 assert_table_length NUM_DEBUGLEVEL_5_MAPS endc \ No newline at end of file diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index 6d15077b4..8e66fc0e9 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -4,6 +4,8 @@ BlueSpaceScript:: scall ArriveToRegularSpaceScript iftrue .not_landed scall LandedInRegularSpaceScript_BeforeSpaceEffect + givecoins CUR_LEVEL_COINS, BLUE_RED_SPACE_COINS + playsound SFX_TRANSACTION scall LandedInRegularSpaceScript_AfterSpaceEffect .not_landed end @@ -12,6 +14,8 @@ RedSpaceScript:: scall ArriveToRegularSpaceScript iftrue .not_landed scall LandedInRegularSpaceScript_BeforeSpaceEffect + takecoins CUR_LEVEL_COINS, BLUE_RED_SPACE_COINS + playsound SFX_TRANSACTION scall LandedInRegularSpaceScript_AfterSpaceEffect .not_landed end @@ -77,9 +81,7 @@ EndSpaceScript:: GreySpaceScript:: scall ArriveToRegularSpaceScript iftrue .not_landed - wait 300 - turnobject PLAYER, DOWN - wait 100 + scall LandedInRegularSpaceScript_BeforeSpaceEffect scall LandedInRegularSpaceScript_AfterSpaceEffect .not_landed end diff --git a/engine/events/coins.asm b/engine/events/coins.asm index 85ba47878..14a11e169 100644 --- a/engine/events/coins.asm +++ b/engine/events/coins.asm @@ -1,12 +1,12 @@ GiveCoins:: ld a, 3 call AddCoins - ld bc, MaxCoins + call LoadMaxCoins_bc ld a, 3 call CompareCoins jr z, .not_maxed_out jr c, .not_maxed_out - ld hl, MaxCoins + call LoadMaxCoins_hl ld a, [hli] ld [de], a inc de @@ -22,9 +22,26 @@ GiveCoins:: and a ret +LoadMaxCoins_bc: + ld a, d + cp HIGH(wCurLevelCoins) + ld bc, MaxCurLevelCoins ; CUR_LEVEL_COINS + ret z + ld bc, MaxCoins ; YOUR_COINS or MOMS_COINS + ret + +LoadMaxCoins_hl: + call LoadMaxCoins_bc + ld h, b + ld l, c + ret + MaxCoins: dt MAX_COINS +MaxCurLevelCoins: + dt MAX_LEVEL_COINS + TakeCoins:: ld a, 3 call SubtractCoins diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 88e1db0cd..ffb2645a3 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -153,8 +153,15 @@ StartMap: ; initialize board state xor a - ld [wCurTurn], a - ld [wCurSpace], a + ld hl, wCurTurn + ld [hli], a ; wCurTurn + ld [hli], a ; wCurSpace + ld [hli], a ; wCurLevelCoins + ld [hli], a ; + ld [hli], a ; + ld [hli], a ; wCurLevelExp + ld [hli], a ; + ld [hl], a ; ; initialize overworld state ld hl, wNextWarp diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm index de1dd4d39..72250e964 100644 --- a/engine/overworld/scripting.asm +++ b/engine/overworld/scripting.asm @@ -1874,13 +1874,18 @@ GetCoinsAccount: and a ld de, wCoins ; YOUR_COINS ret z + dec a + ld de, wCurLevelCoins ; CUR_LEVEL_COINS + ret z ld de, wMomsCoins ; MOMS_COINS ret LoadCoinsAmountToMem: ld bc, hCoinsTemp - push bc call GetScriptByte + cp HIGH(BLUE_RED_SPACE_COINS) + jr z, .blue_red_space_coins + push bc ld [bc], a inc bc call GetScriptByte @@ -1891,6 +1896,38 @@ LoadCoinsAmountToMem: pop bc ret +.blue_red_space_coins + push de + call GetScriptByte + call GetScriptByte +; return [hCoinsTemp] = MAP_BASECOINS * [wDieRoll] + ld de, MAP_BASECOINS + call GetMapField + ld a, [wDieRoll] + dec a + ld e, a + ld a, c + ld b, 0 ; c = ba = MAP_BASECOINS + jr z, .go +.loop + add c + jr nc, .ok + inc b +.ok + dec e + jr nz, .loop +.go +; ba = MAP_BASECOINS * [wDieRoll] + ld hl, hCoinsTemp + 2 + ld [hld], a + ld a, b + ld [hld], a + xor a + ld [hl], a + ld bc, hCoinsTemp + pop de + ret + Script_givechips: call LoadChipAmountToMem farcall GiveChips @@ -1904,7 +1941,7 @@ Script_takechips: Script_checkchips: call LoadChipAmountToMem farcall CheckChips - jr CompareCoinsAction + jp CompareCoinsAction LoadChipAmountToMem: call GetScriptByte diff --git a/ram/wram.asm b/ram/wram.asm index ab0107677..fb71d26a8 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -2548,6 +2548,8 @@ wScreenSave:: ds SCREEN_META_WIDTH * SCREEN_META_HEIGHT wCurTurn:: db wCurSpace:: db +wCurLevelCoins:: ds 3 +wCurLevelExp:: ds 3 wCurSpaceStruct:: space_struct wCurSpace wCurSpaceStructEnd:: @@ -2646,6 +2648,8 @@ wMagikarpRecordHoldersName:: ds NAME_LENGTH wPokemonDataEnd:: wGameDataEnd:: +; requirement of GiveCoins + assert HIGH(wCoins) != HIGH(wCurLevelCoins) SECTION "Pic Animations", WRAMX