Skip to content

Commit

Permalink
Use constants for trade text indexes (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Mar 8, 2025
1 parent 9383d36 commit 147914d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions constants/script_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ DEF NUM_NPC_TRADES EQU const_value
const TRADE_DIALOGSET_CASUAL
const TRADE_DIALOGSET_EVOLUTION
const TRADE_DIALOGSET_HAPPY
DEF NUM_TRADE_DIALOGSETS EQU const_value

; OaksAideScript results
DEF OAKS_AIDE_BAG_FULL EQU $00
Expand Down
28 changes: 23 additions & 5 deletions engine/events/in_game_trades.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
; TradeTextPointers1-3 indexes
const_def
const TRADETEXT_WANNA_TRADE ; 0
const TRADETEXT_NO_TRADE ; 1
const TRADETEXT_WRONG_MON ; 2
const TRADETEXT_THANKS ; 3
const TRADETEXT_AFTER_TRADE ; 4
DEF NUM_TRADE_TEXTS EQU const_value

DoInGameTradeDialogue:
; trigger the trade offer/action specified by wWhichTrade
call SaveScreenTilesToBuffer2
Expand Down Expand Up @@ -42,14 +51,15 @@ DoInGameTradeDialogue:
predef FlagActionPredef
ld a, c
and a
ld a, $4
ld a, TRADETEXT_AFTER_TRADE
ld [wInGameTradeTextPointerTableIndex], a
jr nz, .printText
; if the trade hasn't been done yet
ASSERT TRADETEXT_WANNA_TRADE == 0
xor a
ld [wInGameTradeTextPointerTableIndex], a
call .printText
ld a, $1
ld a, TRADETEXT_NO_TRADE
ld [wInGameTradeTextPointerTableIndex], a
call YesNoChoice
ld a, [wCurrentMenuItem]
Expand Down Expand Up @@ -95,13 +105,13 @@ InGameTrade_DoTrade:
push af
call InGameTrade_RestoreScreen
pop af
ld a, $1
ld a, TRADETEXT_NO_TRADE
jp c, .tradeFailed ; jump if the player didn't select a pokemon
ld a, [wInGameTradeGiveMonSpecies]
ld b, a
ld a, [wCurPartySpecies]
cp b
ld a, $2
ld a, TRADETEXT_WRONG_MON
jr nz, .tradeFailed ; jump if the selected mon's species is not the required one
ld a, [wWhichPokemon]
ld hl, wPartyMon1Level
Expand Down Expand Up @@ -142,7 +152,7 @@ InGameTrade_DoTrade:
call InGameTrade_RestoreScreen
farcall RedrawMapView
and a
ld a, $3
ld a, TRADETEXT_THANKS
jr .tradeSucceeded
.tradeFailed
scf
Expand Down Expand Up @@ -234,30 +244,38 @@ InGameTrade_TrainerString:

InGameTradeTextPointers:
; entries correspond to TRADE_DIALOGSET_* constants
table_width 2
dw TradeTextPointers1
dw TradeTextPointers2
dw TradeTextPointers3
assert_table_length NUM_TRADE_DIALOGSETS

TradeTextPointers1:
table_width 2
dw WannaTrade1Text
dw NoTrade1Text
dw WrongMon1Text
dw Thanks1Text
dw AfterTrade1Text
assert_table_length NUM_TRADE_TEXTS

TradeTextPointers2:
table_width 2
dw WannaTrade2Text
dw NoTrade2Text
dw WrongMon2Text
dw Thanks2Text
dw AfterTrade2Text
assert_table_length NUM_TRADE_TEXTS

TradeTextPointers3:
table_width 2
dw WannaTrade3Text
dw NoTrade3Text
dw WrongMon3Text
dw Thanks3Text
dw AfterTrade3Text
assert_table_length NUM_TRADE_TEXTS

ConnectCableText:
text_far _ConnectCableText
Expand Down

0 comments on commit 147914d

Please sign in to comment.