pokered/engine/in_game_trades.asm

331 lines
6.1 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
DoInGameTradeDialogue:
2014-05-22 22:13:20 +00:00
; trigger the trade offer/action specified by wWhichTrade
call SaveScreenTilesToBuffer2
ld hl,TradeMons
ld a,[wWhichTrade]
ld b,a
swap a
sub b
sub b
ld c,a
2015-02-07 10:43:08 +00:00
ld b,0
2014-05-22 22:13:20 +00:00
add hl,bc
ld a,[hli]
2015-02-07 10:43:08 +00:00
ld [wInGameTradeGiveMonSpecies],a
2014-05-22 22:13:20 +00:00
ld a,[hli]
2015-02-07 10:43:08 +00:00
ld [wInGameTradeReceiveMonSpecies],a
2014-05-22 22:13:20 +00:00
ld a,[hli]
push af
2015-02-07 10:43:08 +00:00
ld de,wInGameTradeMonNick
ld bc, NAME_LENGTH
2014-05-22 22:13:20 +00:00
call CopyData
pop af
ld l,a
2016-06-12 04:30:05 +00:00
ld h,0
ld de,InGameTradeTextPointers
2014-05-22 22:13:20 +00:00
add hl,hl
add hl,de
ld a,[hli]
2015-02-07 10:43:08 +00:00
ld [wInGameTradeTextPointerTablePointer],a
2014-05-22 22:13:20 +00:00
ld a,[hl]
2015-02-07 10:43:08 +00:00
ld [wInGameTradeTextPointerTablePointer + 1],a
ld a,[wInGameTradeGiveMonSpecies]
ld de,wInGameTradeGiveMonName
call InGameTrade_GetMonName
ld a,[wInGameTradeReceiveMonSpecies]
ld de,wInGameTradeReceiveMonName
call InGameTrade_GetMonName
ld hl,wCompletedInGameTradeFlags
2014-05-22 22:13:20 +00:00
ld a,[wWhichTrade]
ld c,a
2015-07-20 03:45:34 +00:00
ld b,FLAG_TEST
predef FlagActionPredef
2014-05-22 22:13:20 +00:00
ld a,c
and a
ld a,$4
2015-02-07 10:43:08 +00:00
ld [wInGameTradeTextPointerTableIndex],a
jr nz,.printText
; if the trade hasn't been done yet
2014-05-22 22:13:20 +00:00
xor a
2015-02-07 10:43:08 +00:00
ld [wInGameTradeTextPointerTableIndex],a
call .printText
2014-05-22 22:13:20 +00:00
ld a,$1
2015-02-07 10:43:08 +00:00
ld [wInGameTradeTextPointerTableIndex],a
2014-05-22 22:13:20 +00:00
call YesNoChoice
ld a,[wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
and a
2015-02-07 10:43:08 +00:00
jr nz,.printText
call InGameTrade_DoTrade
jr c,.printText
2014-05-22 22:13:20 +00:00
ld hl, TradedForText
call PrintText
2015-02-07 10:43:08 +00:00
.printText
ld hl,wInGameTradeTextPointerTableIndex
ld a,[hld] ; wInGameTradeTextPointerTableIndex
2014-05-22 22:13:20 +00:00
ld e,a
2015-02-07 10:43:08 +00:00
ld d,0
ld a,[hld] ; wInGameTradeTextPointerTablePointer + 1
ld l,[hl] ; wInGameTradeTextPointerTablePointer
2014-05-22 22:13:20 +00:00
ld h,a
add hl,de
add hl,de
ld a,[hli]
ld h,[hl]
ld l,a
jp PrintText
2015-02-07 10:43:08 +00:00
; copies name of species a to hl
2016-06-12 00:24:04 +00:00
InGameTrade_GetMonName:
2014-05-22 22:13:20 +00:00
push de
ld [wd11e],a
2014-05-22 22:13:20 +00:00
call GetMonName
ld hl,wcd6d
2014-05-22 22:13:20 +00:00
pop de
ld bc, NAME_LENGTH
2014-05-22 22:13:20 +00:00
jp CopyData
INCLUDE "data/trades.asm"
2016-06-12 00:24:04 +00:00
InGameTrade_DoTrade:
xor a ; NORMAL_PARTY_MENU
ld [wPartyMenuTypeOrMessageID],a
2014-05-22 22:13:20 +00:00
dec a
2014-09-13 07:50:56 +00:00
ld [wUpdateSpritesEnabled],a
2014-05-22 22:13:20 +00:00
call DisplayPartyMenu
push af
2015-02-07 10:43:08 +00:00
call InGameTrade_RestoreScreen
2014-05-22 22:13:20 +00:00
pop af
ld a,$1
2015-02-07 10:43:08 +00:00
jp c,.tradeFailed ; jump if the player didn't select a pokemon
ld a,[wInGameTradeGiveMonSpecies]
2014-05-22 22:13:20 +00:00
ld b,a
ld a,[wcf91]
2014-05-22 22:13:20 +00:00
cp b
ld a,$2
2015-02-07 10:43:08 +00:00
jr nz,.tradeFailed ; jump if the selected mon's species is not the required one
2014-05-22 22:13:20 +00:00
ld a,[wWhichPokemon]
ld hl,wPartyMon1Level
2015-08-05 21:20:29 +00:00
ld bc, wPartyMon2 - wPartyMon1
2014-05-22 22:13:20 +00:00
call AddNTimes
ld a,[hl]
2015-08-31 02:38:41 +00:00
ld [wCurEnemyLVL],a
2015-02-07 10:43:08 +00:00
ld hl,wCompletedInGameTradeFlags
2014-05-22 22:13:20 +00:00
ld a,[wWhichTrade]
ld c,a
2015-07-20 03:45:34 +00:00
ld b,FLAG_SET
predef FlagActionPredef
2014-05-22 22:13:20 +00:00
ld hl, ConnectCableText
call PrintText
ld a,[wWhichPokemon]
push af
2015-08-31 02:38:41 +00:00
ld a,[wCurEnemyLVL]
2014-05-22 22:13:20 +00:00
push af
call LoadHpBarAndStatusTilePatterns
2015-02-07 10:43:08 +00:00
call InGameTrade_PrepareTradeData
2015-03-14 22:25:21 +00:00
predef InternalClockTradeAnim
2014-05-22 22:13:20 +00:00
pop af
2015-08-31 02:38:41 +00:00
ld [wCurEnemyLVL],a
2014-05-22 22:13:20 +00:00
pop af
ld [wWhichPokemon],a
2015-02-07 10:43:08 +00:00
ld a,[wInGameTradeReceiveMonSpecies]
ld [wcf91],a
2014-05-22 22:13:20 +00:00
xor a
2015-07-16 03:04:58 +00:00
ld [wMonDataLocation],a ; not used
ld [wRemoveMonFromBox],a
2014-05-22 22:13:20 +00:00
call RemovePokemon
2015-07-16 03:04:58 +00:00
ld a,$80 ; prevent the player from naming the mon
ld [wMonDataLocation],a
call AddPartyMon
2015-02-07 10:43:08 +00:00
call InGameTrade_CopyDataToReceivedMon
2014-05-22 22:13:20 +00:00
callab EvolveTradeMon
call ClearScreen
2015-02-07 10:43:08 +00:00
call InGameTrade_RestoreScreen
2014-09-14 18:29:18 +00:00
callba RedrawMapView
2014-05-22 22:13:20 +00:00
and a
ld a,$3
2015-02-07 10:43:08 +00:00
jr .tradeSucceeded
.tradeFailed
2014-05-22 22:13:20 +00:00
scf
2015-02-07 10:43:08 +00:00
.tradeSucceeded
ld [wInGameTradeTextPointerTableIndex],a
2014-05-22 22:13:20 +00:00
ret
2016-06-12 00:24:04 +00:00
InGameTrade_RestoreScreen:
2014-05-22 22:13:20 +00:00
call GBPalWhiteOutWithDelay3
call RestoreScreenTilesAndReloadTilePatterns
2014-05-22 22:13:20 +00:00
call ReloadTilesetTilePatterns
call LoadScreenTilesFromBuffer2
call Delay3
call LoadGBPal
2015-02-07 10:43:08 +00:00
ld c, 10
2014-05-22 22:13:20 +00:00
call DelayFrames
2015-07-19 18:56:13 +00:00
jpba LoadWildData
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
InGameTrade_PrepareTradeData:
2015-02-07 10:43:08 +00:00
ld hl, wTradedPlayerMonSpecies
ld a, [wInGameTradeGiveMonSpecies]
ld [hli], a ; wTradedPlayerMonSpecies
ld a, [wInGameTradeReceiveMonSpecies]
ld [hl], a ; wTradedEnemyMonSpecies
ld hl, wPartyMonOT
ld bc, NAME_LENGTH
2015-02-07 10:43:08 +00:00
ld a, [wWhichPokemon]
2014-05-22 22:13:20 +00:00
call AddNTimes
2015-02-07 10:43:08 +00:00
ld de, wTradedPlayerMonOT
ld bc, NAME_LENGTH
2015-02-07 10:43:08 +00:00
call InGameTrade_CopyData
ld hl, InGameTrade_TrainerString
ld de, wTradedEnemyMonOT
2015-02-07 10:43:08 +00:00
call InGameTrade_CopyData
ld de, wLinkEnemyTrainerName
2015-02-07 10:43:08 +00:00
call InGameTrade_CopyData
ld hl, wPartyMon1OTID
ld bc, wPartyMon2 - wPartyMon1
ld a, [wWhichPokemon]
2014-05-22 22:13:20 +00:00
call AddNTimes
2015-02-07 10:43:08 +00:00
ld de, wTradedPlayerMonOTID
2014-05-22 22:13:20 +00:00
ld bc, $2
2015-02-07 10:43:08 +00:00
call InGameTrade_CopyData
call Random
ld hl, hRandomAdd
2015-02-07 10:43:08 +00:00
ld de, wTradedEnemyMonOTID
2014-05-22 22:13:20 +00:00
jp CopyData
2016-06-12 00:24:04 +00:00
InGameTrade_CopyData:
2014-05-22 22:13:20 +00:00
push hl
push bc
call CopyData
pop bc
pop hl
ret
2016-06-12 00:24:04 +00:00
InGameTrade_CopyDataToReceivedMon:
2015-02-07 10:43:08 +00:00
ld hl, wPartyMonNicks
ld bc, NAME_LENGTH
2015-02-07 10:43:08 +00:00
call InGameTrade_GetReceivedMonPointer
ld hl, wInGameTradeMonNick
ld bc, NAME_LENGTH
2014-05-22 22:13:20 +00:00
call CopyData
2015-02-07 10:43:08 +00:00
ld hl, wPartyMonOT
ld bc, NAME_LENGTH
2015-02-07 10:43:08 +00:00
call InGameTrade_GetReceivedMonPointer
ld hl, InGameTrade_TrainerString
ld bc, NAME_LENGTH
2014-05-22 22:13:20 +00:00
call CopyData
2015-02-07 10:43:08 +00:00
ld hl, wPartyMon1OTID
ld bc, wPartyMon2 - wPartyMon1
call InGameTrade_GetReceivedMonPointer
ld hl, wTradedEnemyMonOTID
2014-05-22 22:13:20 +00:00
ld bc, $2
jp CopyData
2015-02-07 10:43:08 +00:00
; the received mon's index is (partyCount - 1),
; so this adds bc to hl (partyCount - 1) times and moves the result to de
2016-06-12 00:24:04 +00:00
InGameTrade_GetReceivedMonPointer:
2015-02-07 10:43:08 +00:00
ld a, [wPartyCount]
2014-05-22 22:13:20 +00:00
dec a
call AddNTimes
ld e, l
ld d, h
ret
2016-06-12 00:24:04 +00:00
InGameTrade_TrainerString:
2014-05-22 22:13:20 +00:00
; "TRAINER@@@@@@@@@@"
db $5d, "@@@@@@@@@@"
2016-06-12 00:24:04 +00:00
InGameTradeTextPointers:
2014-05-22 22:13:20 +00:00
dw TradeTextPointers1
dw TradeTextPointers2
dw TradeTextPointers3
2016-06-12 00:24:04 +00:00
TradeTextPointers1:
2014-05-22 22:13:20 +00:00
dw WannaTrade1Text
dw NoTrade1Text
dw WrongMon1Text
dw Thanks1Text
dw AfterTrade1Text
2016-06-12 00:24:04 +00:00
TradeTextPointers2:
2014-05-22 22:13:20 +00:00
dw WannaTrade2Text
dw NoTrade2Text
dw WrongMon2Text
dw Thanks2Text
dw AfterTrade2Text
2016-06-12 00:24:04 +00:00
TradeTextPointers3:
2014-05-22 22:13:20 +00:00
dw WannaTrade3Text
dw NoTrade3Text
dw WrongMon3Text
dw Thanks3Text
dw AfterTrade3Text
2016-06-12 00:24:04 +00:00
ConnectCableText:
2014-05-22 22:13:20 +00:00
TX_FAR _ConnectCableText
db "@"
2016-06-12 00:24:04 +00:00
TradedForText:
2014-05-22 22:13:20 +00:00
TX_FAR _TradedForText
2016-07-18 06:17:03 +00:00
TX_SFX_KEY_ITEM
TX_DELAY
db "@"
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WannaTrade1Text:
2014-05-22 22:13:20 +00:00
TX_FAR _WannaTrade1Text
db "@"
2016-06-12 00:24:04 +00:00
NoTrade1Text:
2014-05-22 22:13:20 +00:00
TX_FAR _NoTrade1Text
db "@"
2016-06-12 00:24:04 +00:00
WrongMon1Text:
2014-05-22 22:13:20 +00:00
TX_FAR _WrongMon1Text
db "@"
2016-06-12 00:24:04 +00:00
Thanks1Text:
2014-05-22 22:13:20 +00:00
TX_FAR _Thanks1Text
db "@"
2016-06-12 00:24:04 +00:00
AfterTrade1Text:
2014-05-22 22:13:20 +00:00
TX_FAR _AfterTrade1Text
db "@"
2016-06-12 00:24:04 +00:00
WannaTrade2Text:
2014-05-22 22:13:20 +00:00
TX_FAR _WannaTrade2Text
db "@"
2016-06-12 00:24:04 +00:00
NoTrade2Text:
2014-05-22 22:13:20 +00:00
TX_FAR _NoTrade2Text
db "@"
2016-06-12 00:24:04 +00:00
WrongMon2Text:
2014-05-22 22:13:20 +00:00
TX_FAR _WrongMon2Text
db "@"
2016-06-12 00:24:04 +00:00
Thanks2Text:
2014-05-22 22:13:20 +00:00
TX_FAR _Thanks2Text
db "@"
2016-06-12 00:24:04 +00:00
AfterTrade2Text:
2014-05-22 22:13:20 +00:00
TX_FAR _AfterTrade2Text
db "@"
2016-06-12 00:24:04 +00:00
WannaTrade3Text:
2014-05-22 22:13:20 +00:00
TX_FAR _WannaTrade3Text
db "@"
2016-06-12 00:24:04 +00:00
NoTrade3Text:
2014-05-22 22:13:20 +00:00
TX_FAR _NoTrade3Text
db "@"
2016-06-12 00:24:04 +00:00
WrongMon3Text:
2014-05-22 22:13:20 +00:00
TX_FAR _WrongMon3Text
db "@"
2016-06-12 00:24:04 +00:00
Thanks3Text:
2014-05-22 22:13:20 +00:00
TX_FAR _Thanks3Text
db "@"
2016-06-12 00:24:04 +00:00
AfterTrade3Text:
2014-05-22 22:13:20 +00:00
TX_FAR _AfterTrade3Text
db "@"