pokered/engine/events/in_game_trades.asm

330 lines
6.2 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
2014-05-22 22:13:20 +00:00
swap a
sub b
sub b
ld c, a
ld b, 0
add hl, bc
ld a, [hli]
ld [wInGameTradeGiveMonSpecies], a
ld a, [hli]
ld [wInGameTradeReceiveMonSpecies], a
ld a, [hli]
2014-05-22 22:13:20 +00:00
push af
ld de, wInGameTradeMonNick
ld bc, NAME_LENGTH
2014-05-22 22:13:20 +00:00
call CopyData
pop af
ld l, a
ld h, 0
ld de, InGameTradeTextPointers
add hl, hl
add hl, de
ld a, [hli]
ld [wInGameTradeTextPointerTablePointer], a
ld a, [hl]
ld [wInGameTradeTextPointerTablePointer + 1], a
ld a, [wInGameTradeGiveMonSpecies]
ld de, wInGameTradeGiveMonName
2015-02-07 10:43:08 +00:00
call InGameTrade_GetMonName
ld a, [wInGameTradeReceiveMonSpecies]
ld de, wInGameTradeReceiveMonName
2015-02-07 10:43:08 +00:00
call InGameTrade_GetMonName
ld hl, wCompletedInGameTradeFlags
ld a, [wWhichTrade]
ld c, a
ld b, FLAG_TEST
predef FlagActionPredef
ld a, c
2014-05-22 22:13:20 +00:00
and a
ld a, $4
ld [wInGameTradeTextPointerTableIndex], a
jr nz, .printText
2015-02-07 10:43:08 +00:00
; if the trade hasn't been done yet
2014-05-22 22:13:20 +00:00
xor a
ld [wInGameTradeTextPointerTableIndex], a
2015-02-07 10:43:08 +00:00
call .printText
ld a, $1
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
jr nz, .printText
2015-02-07 10:43:08 +00:00
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
ld e, a
ld d, 0
ld a, [hld] ; wInGameTradeTextPointerTablePointer + 1
ld l, [hl] ; wInGameTradeTextPointerTablePointer
ld h, a
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
2014-05-22 22:13:20 +00:00
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/events/trades.asm"
2014-05-22 22:13:20 +00:00
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
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
jp c, .tradeFailed ; jump if the player didn't select a pokemon
ld a, [wInGameTradeGiveMonSpecies]
ld b, a
ld a, [wcf91]
2014-05-22 22:13:20 +00:00
cp b
ld a, $2
jr nz, .tradeFailed ; jump if the selected mon's species is not the required one
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]
ld [wCurEnemyLVL], a
ld hl, wCompletedInGameTradeFlags
ld a, [wWhichTrade]
ld c, a
ld b, FLAG_SET
predef FlagActionPredef
2014-05-22 22:13:20 +00:00
ld hl, ConnectCableText
call PrintText
ld a, [wWhichPokemon]
2014-05-22 22:13:20 +00:00
push af
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
ld [wCurEnemyLVL], a
2014-05-22 22:13:20 +00:00
pop af
ld [wWhichPokemon], a
ld a, [wInGameTradeReceiveMonSpecies]
ld [wcf91], a
2014-05-22 22:13:20 +00:00
xor a
ld [wMonDataLocation], a ; not used
ld [wRemoveMonFromBox], a
2014-05-22 22:13:20 +00:00
call RemovePokemon
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
callfar EvolveTradeMon
2014-05-22 22:13:20 +00:00
call ClearScreen
2015-02-07 10:43:08 +00:00
call InGameTrade_RestoreScreen
farcall 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
farjp 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:
db "<TRAINER>@@@@@@@@@@"
2014-05-22 22:13:20 +00:00
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:
text_far _ConnectCableText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
TradedForText:
text_far _TradedForText
sound_get_key_item
text_pause
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WannaTrade1Text:
text_far _WannaTrade1Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
NoTrade1Text:
text_far _NoTrade1Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WrongMon1Text:
text_far _WrongMon1Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
Thanks1Text:
text_far _Thanks1Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
AfterTrade1Text:
text_far _AfterTrade1Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WannaTrade2Text:
text_far _WannaTrade2Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
NoTrade2Text:
text_far _NoTrade2Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WrongMon2Text:
text_far _WrongMon2Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
Thanks2Text:
text_far _Thanks2Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
AfterTrade2Text:
text_far _AfterTrade2Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WannaTrade3Text:
text_far _WannaTrade3Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
NoTrade3Text:
text_far _NoTrade3Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
WrongMon3Text:
text_far _WrongMon3Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
Thanks3Text:
text_far _Thanks3Text
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
AfterTrade3Text:
text_far _AfterTrade3Text
text_end