diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index db304d94c..f1ba236bc 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -35,11 +35,12 @@ DEF NOON_HOUR EQU 12 ; 12 PM DEF MAX_DAYS EQU 36 * 7 ; 252 ; significant coins values -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 +DEF START_COINS EQU 100 +DEF MOM_COINS EQU 2300 +DEF MAX_COINS EQU 999999 +DEF MAX_LEVEL_COINS EQU 99999 +DEF MAX_DELTA_COINS_DIGITS EQU 5 +DEF MAX_CHIPS EQU 9999 ; link record DEF MAX_LINK_RECORD EQU 9999 diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index 337319949..8600a016b 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -8,12 +8,13 @@ DEF AUTO_INPUT EQU $ff ; wDisplaySecondarySprites const_def - const SECONDARYSPRITES_BOARD_MENU_F ; 0 - const SECONDARYSPRITES_DIE_ROLL_F ; 1 - const SECONDARYSPRITES_SPACES_LEFT_F ; 2 - const SECONDARYSPRITES_BRANCH_SPACE_F ; 3 - const SECONDARYSPRITES_VIEW_MAP_MODE_F ; 4 - const SECONDARYSPRITES_TALKER_EVENT_F ; 5 + const SECONDARYSPRITES_BOARD_MENU_F ; 0 + const SECONDARYSPRITES_DIE_ROLL_F ; 1 + const SECONDARYSPRITES_SPACES_LEFT_F ; 2 + const SECONDARYSPRITES_BRANCH_SPACE_F ; 3 + const SECONDARYSPRITES_VIEW_MAP_MODE_F ; 4 + const SECONDARYSPRITES_TALKER_EVENT_F ; 5 + const SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F ; 6 ; wCurDexMode:: const_def diff --git a/data/events/special_pointers.asm b/data/events/special_pointers.asm index 46db068b2..a26971633 100644 --- a/data/events/special_pointers.asm +++ b/data/events/special_pointers.asm @@ -113,6 +113,8 @@ SpecialsPointers:: add_special FadeOutMusic add_special Diploma add_special PrintDiploma + add_special PrintGainCoins + add_special PrintLoseCoins ; Crystal only add_special Reset ; bank 0 diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index 8e66fc0e9..1a641eee4 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -6,6 +6,7 @@ BlueSpaceScript:: scall LandedInRegularSpaceScript_BeforeSpaceEffect givecoins CUR_LEVEL_COINS, BLUE_RED_SPACE_COINS playsound SFX_TRANSACTION + special PrintGainCoins scall LandedInRegularSpaceScript_AfterSpaceEffect .not_landed end @@ -16,6 +17,7 @@ RedSpaceScript:: scall LandedInRegularSpaceScript_BeforeSpaceEffect takecoins CUR_LEVEL_COINS, BLUE_RED_SPACE_COINS playsound SFX_TRANSACTION + special PrintLoseCoins scall LandedInRegularSpaceScript_AfterSpaceEffect .not_landed end @@ -315,4 +317,43 @@ UnionSpaceScript:: call LoadCurSpaceData ret +PrintGainCoins: + ld hl, wStringBuffer1 + ld a, "" + ld [hli], a + ld a, "" + ld [hli], a + jr PrintGainOrLoseCoins + +PrintLoseCoins: + ld hl, wStringBuffer1 + ld a, "" + ld [hli], a + ld a, "" + ld [hli], a + ; fallthrough + +PrintGainOrLoseCoins: + push hl + ; fill string space with "@" to ensure that it is terminated with at least one "@" + ld a, "@" + ld c, MAX_DELTA_COINS_DIGITS + 1 +.loop + ld [hli], a + dec c + jr nz, .loop + pop hl +; copy coins amount string to wStringBuffer1 + $2 + ld de, hCoinsTemp + lb bc, 3 | 1 << 6, MAX_DELTA_COINS_DIGITS ; 3 bytes, left aligned, no leading zeros, 5 digits + call PrintNum + ld hl, wDisplaySecondarySprites + set SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F, [hl] + call UpdateActiveSprites + ld c, 45 ; 750 ms + call DelayFrames + ld hl, wDisplaySecondarySprites + res SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F, [hl] + ret + INCLUDE "engine/board/disabled_spaces.asm" diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 2350dedde..840ec7d65 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -3118,6 +3118,8 @@ InitSecondarySprites: call nz, InitViewMapModeSprites bit SECONDARYSPRITES_TALKER_EVENT_F, a call nz, InitTalkerEventSprites + bit SECONDARYSPRITES_GAIN_OR_LOSE_COINS_F, a + call nz, InitGainOrLoseCoinsSprites ret InitBoardMenuSprites: @@ -3374,6 +3376,8 @@ InitViewMapModeSprites: ret InitTalkerEventSprites: + push af + ; find the beginning of free space in OAM, and assure there's space for 8 objects ldh a, [hUsedSpriteIndex] cp (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (8 * SPRITEOAMSTRUCT_LENGTH) + 1 @@ -3406,4 +3410,74 @@ InitTalkerEventSprites: pop af ret +InitGainOrLoseCoinsSprites: + push af + +; print string at wStringBuffer1 as OAM +; get string length + ld hl, wStringBuffer1 + ld c, 0 +.get_length_loop + ld a, [hli] + cp "@" + jr z, .got_length + inc c + ld a, c + cp $2 + MAX_DELTA_COINS_DIGITS + 1 + jr nz, .get_length_loop + +.got_length + ld e, c +; find the beginning of free space in OAM, and assure there's space for c objects + ld a, (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) + 1 + sla c ; + sla c ; c *= SPRITEOAMSTRUCT_LENGTH + sub c + ld b, a ; b = (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (c * SPRITEOAMSTRUCT_LENGTH) + 1 + ldh a, [hUsedSpriteIndex] + cp b + jr nc, .oam_full + +; align OAM in the X axis according to the string length (e) + ld a, 10 * TILE_WIDTH + ld c, TILE_WIDTH / 2 +.x_coord_loop + sub c + dec e + jr nz, .x_coord_loop +; b = SPRITEOAMSTRUCT_XCOORD + ld b, a +; c = SPRITEOAMSTRUCT_YCOORD + ld c, 8 * TILE_WIDTH +; de = address within wShadowOAM + ld a, [hUsedSpriteIndex] + ld e, a + ld d, HIGH(wShadowOAM) + ld hl, wStringBuffer1 +.print_oam_loop + ld a, c + ld [de], a ; SPRITEOAMSTRUCT_YCOORD + inc de + ld a, b + ld [de], a ; SPRITEOAMSTRUCT_XCOORD + inc de + add 1 * TILE_WIDTH + ld b, a + ld a, [hli] + ld [de], a ; SPRITEOAMSTRUCT_TILE_ID + inc de + ld a, PAL_OW_MISC + ld [de], a ; SPRITEOAMSTRUCT_ATTRIBUTES + inc de + ld a, [hl] + cp "@" + jr nz, .print_oam_loop + + ld a, e + ld [hUsedSpriteIndex], a + +.oam_full + pop af + ret + INCLUDE "data/sprites/secondary_sprites.asm"