shithub: pokecrystal

Download patch

ref: 7d6e82ef1c8c3eccdc630e85af1d687eaa612ad6
parent: b04f41da98c9457c1200fdfe1c49ab20af86e3fa
author: Rangi <[email protected]>
date: Wed Jan 31 16:16:57 EST 2018

NPC trade constants don't all just start with TRADE_

--- a/constants.asm
+++ b/constants.asm
@@ -33,7 +33,7 @@
 INCLUDE "constants/move_constants.asm"
 INCLUDE "constants/move_effect_constants.asm"
 INCLUDE "constants/music_constants.asm"
-INCLUDE "constants/npctrade_constants.asm"
+INCLUDE "constants/npc_trade_constants.asm"
 INCLUDE "constants/phone_constants.asm"
 INCLUDE "constants/pokemon_constants.asm"
 INCLUDE "constants/pokemon_data_constants.asm"
--- /dev/null
+++ b/constants/npc_trade_constants.asm
@@ -1,0 +1,44 @@
+	; npctrade struct members (see data/events/npc_trades.asm)
+NPCTRADE_DIALOG  EQU  0 ; db
+NPCTRADE_GIVEMON EQU  1 ; db
+NPCTRADE_GETMON  EQU  2 ; db
+NPCTRADE_NICK    EQU  3 ; ds MON_NAME_LENGTH
+NPCTRADE_DVS     EQU 14 ; dw
+NPCTRADE_ITEM    EQU 16 ; db
+NPCTRADE_OT_ID   EQU 17 ; dw
+NPCTRADE_OT_NAME EQU 19 ; ds NAME_LENGTH
+NPCTRADE_GENDER  EQU 30 ; db
+NPCTRADE_PADDING EQU 31 ; db
+
+; NPCTrades indexes (see data/events/npc_trades.asm)
+	const_def
+	const NPC_TRADE_MIKE   ; 0
+	const NPC_TRADE_KYLE   ; 1
+	const NPC_TRADE_TIM    ; 2
+	const NPC_TRADE_EMY    ; 3
+	const NPC_TRADE_CHRIS  ; 4
+	const NPC_TRADE_KIM    ; 5
+	const NPC_TRADE_FOREST ; 6
+
+; trade gender limits
+	const_def
+	const TRADE_GENDER_EITHER
+	const TRADE_GENDER_MALE
+	const TRADE_GENDER_FEMALE
+
+; TradeTexts indexes (see engine/events/npc_trade.asm)
+
+; trade dialogs
+	const_def
+	const TRADE_DIALOG_INTRO
+	const TRADE_DIALOG_CANCEL
+	const TRADE_DIALOG_WRONG
+	const TRADE_DIALOG_COMPLETE
+	const TRADE_DIALOG_AFTER
+
+; trade dialog sets
+	const_def
+	const TRADE_DIALOGSET_COLLECTOR
+	const TRADE_DIALOGSET_HAPPY
+	const TRADE_DIALOGSET_NEWBIE
+	const TRADE_DIALOGSET_GIRL
--- a/constants/npctrade_constants.asm
+++ /dev/null
@@ -1,43 +1,0 @@
-; npctrade struct members (see data/events/npc_trades.asm)
-TRADE_DIALOG  EQU 0
-TRADE_GIVEMON EQU 1
-TRADE_GETMON  EQU 2
-TRADE_NICK    EQU 3
-TRADE_DVS     EQU 14
-TRADE_ITEM    EQU 16
-TRADE_OT_ID   EQU 17
-TRADE_OT_NAME EQU 19
-TRADE_GENDER  EQU 30
-TRADE_PADDING EQU 31
-
-; NPCTrades indexes (see data/events/npc_trades.asm)
-	const_def
-	const NPCTRADE_MIKE   ; 0
-	const NPCTRADE_KYLE   ; 1
-	const NPCTRADE_TIM    ; 2
-	const NPCTRADE_EMY    ; 3
-	const NPCTRADE_CHRIS  ; 4
-	const NPCTRADE_KIM    ; 5
-	const NPCTRADE_FOREST ; 6
-
-; trade gender limits
-TRADE_EITHER_GENDER EQU 0
-TRADE_MALE_ONLY     EQU 1
-TRADE_FEMALE_ONLY   EQU 2
-
-; TradeTexts indexes (see engine/npctrade.asm)
-
-; trade dialogs
-	const_def
-	const TRADE_INTRO
-	const TRADE_CANCEL
-	const TRADE_WRONG
-	const TRADE_COMPLETE
-	const TRADE_AFTER
-
-; trade dialog sets
-	const_def
-	const TRADE_DIALOG_COLLECTOR
-	const TRADE_DIALOG_HAPPY
-	const TRADE_DIALOG_NEWBIE
-	const TRADE_DIALOG_GIRL
--- a/constants/script_constants.asm
+++ b/constants/script_constants.asm
@@ -91,6 +91,7 @@
 NUM_PLAYER_EVENTS EQU const_value
 
 
+; bg_event types
 ; TryBGEvent arguments (see engine/events.asm)
 	const_def
 	const BGEVENT_READ
--- a/data/events/npc_trades.asm
+++ b/data/events/npc_trades.asm
@@ -8,11 +8,11 @@
 
 NPCTrades: ; fce58
 ; entries correspond to NPCTRADE_* constants
-	npctrade TRADE_DIALOG_COLLECTOR, ABRA,       MACHOP,     "MUSCLE@@@@@", $37, $66, GOLD_BERRY,   37460, "MIKE@@@@@@@", TRADE_EITHER_GENDER
-	npctrade TRADE_DIALOG_COLLECTOR, BELLSPROUT, ONIX,       "ROCKY@@@@@@", $96, $66, BITTER_BERRY, 48926, "KYLE@@@@@@@", TRADE_EITHER_GENDER
-	npctrade TRADE_DIALOG_HAPPY,     KRABBY,     VOLTORB,    "VOLTY@@@@@@", $98, $88, PRZCUREBERRY, 29189, "TIM@@@@@@@@", TRADE_EITHER_GENDER
-	npctrade TRADE_DIALOG_GIRL,      DRAGONAIR,  DODRIO,     "DORIS@@@@@@", $77, $66, SMOKE_BALL,   00283, "EMY@@@@@@@@", TRADE_FEMALE_ONLY
-	npctrade TRADE_DIALOG_NEWBIE,    HAUNTER,    XATU,       "PAUL@@@@@@@", $96, $86, MYSTERYBERRY, 15616, "CHRIS@@@@@@", TRADE_EITHER_GENDER
-	npctrade TRADE_DIALOG_GIRL,      CHANSEY,    AERODACTYL, "AEROY@@@@@@", $96, $66, GOLD_BERRY,   26491, "KIM@@@@@@@@", TRADE_EITHER_GENDER
-	npctrade TRADE_DIALOG_COLLECTOR, DUGTRIO,    MAGNETON,   "MAGGIE@@@@@", $96, $66, METAL_COAT,   50082, "FOREST@@@@@", TRADE_EITHER_GENDER
+	npctrade TRADE_DIALOGSET_COLLECTOR, ABRA,       MACHOP,     "MUSCLE@@@@@", $37, $66, GOLD_BERRY,   37460, "MIKE@@@@@@@", TRADE_GENDER_EITHER
+	npctrade TRADE_DIALOGSET_COLLECTOR, BELLSPROUT, ONIX,       "ROCKY@@@@@@", $96, $66, BITTER_BERRY, 48926, "KYLE@@@@@@@", TRADE_GENDER_EITHER
+	npctrade TRADE_DIALOGSET_HAPPY,     KRABBY,     VOLTORB,    "VOLTY@@@@@@", $98, $88, PRZCUREBERRY, 29189, "TIM@@@@@@@@", TRADE_GENDER_EITHER
+	npctrade TRADE_DIALOGSET_GIRL,      DRAGONAIR,  DODRIO,     "DORIS@@@@@@", $77, $66, SMOKE_BALL,   00283, "EMY@@@@@@@@", TRADE_GENDER_FEMALE
+	npctrade TRADE_DIALOGSET_NEWBIE,    HAUNTER,    XATU,       "PAUL@@@@@@@", $96, $86, MYSTERYBERRY, 15616, "CHRIS@@@@@@", TRADE_GENDER_EITHER
+	npctrade TRADE_DIALOGSET_GIRL,      CHANSEY,    AERODACTYL, "AEROY@@@@@@", $96, $66, GOLD_BERRY,   26491, "KIM@@@@@@@@", TRADE_GENDER_EITHER
+	npctrade TRADE_DIALOGSET_COLLECTOR, DUGTRIO,    MAGNETON,   "MAGGIE@@@@@", $96, $66, METAL_COAT,   50082, "FOREST@@@@@", TRADE_GENDER_EITHER
 ; fcf38
--- /dev/null
+++ b/engine/events/npc_trade.asm
@@ -1,0 +1,586 @@
+NPCTrade:: ; fcba8
+	ld a, e
+	ld [wJumptableIndex], a
+	call Trade_GetDialog
+	ld b, CHECK_FLAG
+	call TradeFlagAction
+	ld a, TRADE_DIALOG_AFTER
+	jr nz, .done
+
+	ld a, TRADE_DIALOG_INTRO
+	call PrintTradeText
+
+	call YesNoBox
+	ld a, TRADE_DIALOG_CANCEL
+	jr c, .done
+
+; Select givemon from party
+	ld b, PARTYMENUACTION_GIVE_MON
+	farcall SelectTradeOrDayCareMon
+	ld a, TRADE_DIALOG_CANCEL
+	jr c, .done
+
+	ld e, NPCTRADE_GIVEMON
+	call GetTradeAttribute
+	ld a, [CurPartySpecies]
+	cp [hl]
+	ld a, TRADE_DIALOG_WRONG
+	jr nz, .done
+
+	call CheckTradeGender
+	ld a, TRADE_DIALOG_WRONG
+	jr c, .done
+
+	ld b, SET_FLAG
+	call TradeFlagAction
+
+	ld hl, ConnectLinkCableText
+	call PrintText
+
+	call DoNPCTrade
+	call .TradeAnimation
+	call GetTradeMonNames
+
+	ld hl, TradedForText
+	call PrintText
+
+	call RestartMapMusic
+
+	ld a, TRADE_DIALOG_COMPLETE
+
+.done
+	call PrintTradeText
+	ret
+; fcc07
+
+.TradeAnimation: ; fcc07
+	call DisableSpriteUpdates
+	ld a, [wJumptableIndex]
+	push af
+	ld a, [wcf64]
+	push af
+	predef TradeAnimation
+	pop af
+	ld [wcf64], a
+	pop af
+	ld [wJumptableIndex], a
+	call ReturnToMapWithSpeechTextbox
+	ret
+; fcc23
+
+CheckTradeGender: ; fcc23
+	xor a
+	ld [MonType], a
+
+	ld e, NPCTRADE_GENDER
+	call GetTradeAttribute
+	ld a, [hl]
+	and a ; TRADE_GENDER_EITHER
+	jr z, .matching
+	cp TRADE_GENDER_MALE
+	jr z, .check_male
+	; TRADE_GENDER_FEMALE
+	farcall GetGender
+	jr nz, .not_matching
+	jr .matching
+
+.check_male
+	farcall GetGender
+	jr z, .not_matching
+
+.matching
+	and a
+	ret
+
+.not_matching
+	scf
+	ret
+; fcc4a
+
+TradeFlagAction: ; fcc4a
+	ld hl, wTradeFlags
+	ld a, [wJumptableIndex]
+	ld c, a
+	predef SmallFarFlagAction
+	ld a, c
+	and a
+	ret
+; fcc59
+
+Trade_GetDialog: ; fcc59
+	ld e, NPCTRADE_DIALOG
+	call GetTradeAttribute
+	ld a, [hl]
+	ld [wcf64], a
+	ret
+; fcc63
+
+DoNPCTrade: ; fcc63
+	ld e, NPCTRADE_GIVEMON
+	call GetTradeAttribute
+	ld a, [hl]
+	ld [wPlayerTrademonSpecies], a
+
+	ld e, NPCTRADE_GETMON
+	call GetTradeAttribute
+	ld a, [hl]
+	ld [wOTTrademonSpecies], a
+
+	ld a, [wPlayerTrademonSpecies]
+	ld de, wPlayerTrademonSpeciesName
+	call GetTradeMonName
+	call CopyTradeName
+
+	ld a, [wOTTrademonSpecies]
+	ld de, wOTTrademonSpeciesName
+	call GetTradeMonName
+	call CopyTradeName
+
+	ld hl, PartyMonOT
+	ld bc, NAME_LENGTH
+	call Trade_GetAttributeOfCurrentPartymon
+	ld de, wPlayerTrademonOTName
+	call CopyTradeName
+
+	ld hl, PlayerName
+	ld de, wPlayerTrademonSenderName
+	call CopyTradeName
+
+	ld hl, PartyMon1ID
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfCurrentPartymon
+	ld de, wPlayerTrademonID
+	call Trade_CopyTwoBytes
+
+	ld hl, PartyMon1DVs
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfCurrentPartymon
+	ld de, wPlayerTrademonDVs
+	call Trade_CopyTwoBytes
+
+	ld hl, PartyMon1Species
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfCurrentPartymon
+	ld b, h
+	ld c, l
+	farcall GetCaughtGender
+	ld a, c
+	ld [wPlayerTrademonCaughtData], a
+
+	ld e, NPCTRADE_DIALOG
+	call GetTradeAttribute
+	ld a, [hl]
+	cp TRADE_DIALOGSET_GIRL
+	ld a, CAUGHT_BY_GIRL
+	jr c, .okay
+	ld a, CAUGHT_BY_BOY
+.okay
+	ld [wOTTrademonCaughtData], a
+
+	ld hl, PartyMon1Level
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfCurrentPartymon
+	ld a, [hl]
+	ld [CurPartyLevel], a
+	ld a, [wOTTrademonSpecies]
+	ld [CurPartySpecies], a
+	xor a
+	ld [MonType], a
+	ld [wPokemonWithdrawDepositParameter], a
+	callfar RemoveMonFromPartyOrBox
+	predef TryAddMonToParty
+
+	ld e, NPCTRADE_DIALOG
+	call GetTradeAttribute
+	ld a, [hl]
+	cp TRADE_DIALOG_COMPLETE
+	ld b, RESET_FLAG
+	jr c, .incomplete
+	ld b, SET_FLAG
+.incomplete
+	farcall SetGiftPartyMonCaughtData
+
+	ld e, NPCTRADE_NICK
+	call GetTradeAttribute
+	ld de, wOTTrademonNickname
+	call CopyTradeName
+
+	ld hl, PartyMonNicknames
+	ld bc, MON_NAME_LENGTH
+	call Trade_GetAttributeOfLastPartymon
+	ld hl, wOTTrademonNickname
+	call CopyTradeName
+
+	ld e, NPCTRADE_OT_NAME
+	call GetTradeAttribute
+	push hl
+	ld de, wOTTrademonOTName
+	call CopyTradeName
+	pop hl
+	ld de, wOTTrademonSenderName
+	call CopyTradeName
+
+	ld hl, PartyMonOT
+	ld bc, NAME_LENGTH
+	call Trade_GetAttributeOfLastPartymon
+	ld hl, wOTTrademonOTName
+	call CopyTradeName
+
+	ld e, NPCTRADE_DVS
+	call GetTradeAttribute
+	ld de, wOTTrademonDVs
+	call Trade_CopyTwoBytes
+
+	ld hl, PartyMon1DVs
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfLastPartymon
+	ld hl, wOTTrademonDVs
+	call Trade_CopyTwoBytes
+
+	ld e, NPCTRADE_OT_ID
+	call GetTradeAttribute
+	ld de, wOTTrademonID + 1
+	call Trade_CopyTwoBytesReverseEndian
+
+	ld hl, PartyMon1ID
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfLastPartymon
+	ld hl, wOTTrademonID
+	call Trade_CopyTwoBytes
+
+	ld e, NPCTRADE_ITEM
+	call GetTradeAttribute
+	push hl
+	ld hl, PartyMon1Item
+	ld bc, PARTYMON_STRUCT_LENGTH
+	call Trade_GetAttributeOfLastPartymon
+	pop hl
+	ld a, [hl]
+	ld [de], a
+
+	push af
+	push bc
+	push de
+	push hl
+	ld a, [CurPartyMon]
+	push af
+	ld a, [PartyCount]
+	dec a
+	ld [CurPartyMon], a
+	farcall ComputeNPCTrademonStats
+	pop af
+	ld [CurPartyMon], a
+	pop hl
+	pop de
+	pop bc
+	pop af
+	ret
+; fcdc2
+
+
+GetTradeAttribute: ; 0xfcdc2
+	ld d, 0
+	push de
+	ld a, [wJumptableIndex]
+	and $f
+	swap a
+	ld e, a
+	ld d, 0
+	ld hl, NPCTrades
+	add hl, de
+	add hl, de
+	pop de
+	add hl, de
+	ret
+; 0xfcdd7
+
+Trade_GetAttributeOfCurrentPartymon: ; fcdd7
+	ld a, [CurPartyMon]
+	call AddNTimes
+	ret
+; fcdde
+
+Trade_GetAttributeOfLastPartymon: ; fcdde
+	ld a, [PartyCount]
+	dec a
+	call AddNTimes
+	ld e, l
+	ld d, h
+	ret
+; fcde8
+
+GetTradeMonName: ; fcde8
+	push de
+	ld [wd265], a
+	call GetBasePokemonName
+	ld hl, StringBuffer1
+	pop de
+	ret
+; fcdf4
+
+CopyTradeName: ; fcdf4
+	ld bc, NAME_LENGTH
+	call CopyBytes
+	ret
+; fcdfb
+
+Unreferenced_Functionfcdfb: ; fcdfb
+	ld bc, 4
+	call CopyBytes
+	ld a, "@"
+	ld [de], a
+	ret
+; fce05
+
+Unreferenced_Functionfce05: ; fce05
+	ld bc, 3
+	call CopyBytes
+	ld a, "@"
+	ld [de], a
+	ret
+; fce0f
+
+Trade_CopyTwoBytes: ; fce0f
+	ld a, [hli]
+	ld [de], a
+	inc de
+	ld a, [hl]
+	ld [de], a
+	ret
+; fce15
+
+Trade_CopyTwoBytesReverseEndian: ; fce15
+	ld a, [hli]
+	ld [de], a
+	dec de
+	ld a, [hl]
+	ld [de], a
+	ret
+; fce1b
+
+GetTradeMonNames: ; fce1b
+	ld e, NPCTRADE_GETMON
+	call GetTradeAttribute
+	ld a, [hl]
+	call GetTradeMonName
+
+	ld de, StringBuffer2
+	call CopyTradeName
+
+	ld e, NPCTRADE_GIVEMON
+	call GetTradeAttribute
+	ld a, [hl]
+	call GetTradeMonName
+
+	ld de, wMonOrItemNameBuffer
+	call CopyTradeName
+
+	ld hl, StringBuffer1
+.loop
+	ld a, [hli]
+	cp "@"
+	jr nz, .loop
+
+	dec hl
+	push hl
+	ld e, NPCTRADE_GENDER
+	call GetTradeAttribute
+	ld a, [hl]
+	pop hl
+	and a ; TRADE_GENDER_EITHER
+	ret z
+	cp TRADE_GENDER_MALE
+	ld a, "♂"
+	jr z, .done
+	; TRADE_GENDER_FEMALE
+	ld a, "♀"
+.done
+	ld [hli], a
+	ld [hl], "@"
+	ret
+; fce58
+
+
+INCLUDE "data/events/npc_trades.asm"
+
+
+PrintTradeText: ; fcf38
+	push af
+	call GetTradeMonNames
+	pop af
+	ld bc, 2 * 4
+	ld hl, TradeTexts
+	call AddNTimes
+	ld a, [wcf64]
+	ld c, a
+	add hl, bc
+	add hl, bc
+	ld a, [hli]
+	ld h, [hl]
+	ld l, a
+	call PrintText
+	ret
+; fcf53
+
+TradeTexts: ; fcf53
+; entries correspond to TRADE_DIALOG_* × TRADE_DIALOGSET_* constants
+; TRADE_DIALOG_INTRO
+	dw TradeIntroText1
+	dw TradeIntroText2
+	dw TradeIntroText3
+	dw TradeIntroText4
+; TRADE_DIALOG_CANCEL
+	dw TradeCancelText1
+	dw TradeCancelText2
+	dw TradeCancelText3
+	dw TradeCancelText4
+; TRADE_DIALOG_WRONG
+	dw TradeWrongText1
+	dw TradeWrongText2
+	dw TradeWrongText3
+	dw TradeWrongText4
+; TRADE_DIALOG_COMPLETE
+	dw TradeCompleteText1
+	dw TradeCompleteText2
+	dw TradeCompleteText3
+	dw TradeCompleteText4
+; TRADE_DIALOG_AFTER
+	dw TradeAfterText1
+	dw TradeAfterText2
+	dw TradeAfterText3
+	dw TradeAfterText4
+; fcf7b
+
+
+ConnectLinkCableText: ; 0xfcf7b
+	; OK, connect the Game Link Cable.
+	text_jump UnknownText_0x1bd407
+	db "@"
+; 0xfcf80
+
+
+TradedForText: ; 0xfcf80
+	; traded givemon for getmon
+	text_jump UnknownText_0x1bd429
+	start_asm
+	ld de, MUSIC_NONE
+	call PlayMusic
+	call DelayFrame
+	ld hl, .done
+	ret
+
+.done
+	; sound_dex_fanfare_80_109
+	; interpret_data
+	text_jump UnknownText_0x1bd445
+	db "@"
+; 0xfcf97
+
+
+TradeIntroText1: ; 0xfcf97
+	; I collect #MON. Do you have @ ? Want to trade it for my @ ?
+	text_jump UnknownText_0x1bd449
+	db "@"
+; 0xfcf9c
+
+TradeCancelText1: ; 0xfcf9c
+	; You don't want to trade? Aww…
+	text_jump UnknownText_0x1bd48c
+	db "@"
+; 0xfcfa1
+
+TradeWrongText1: ; 0xfcfa1
+	; Huh? That's not @ .  What a letdown…
+	text_jump UnknownText_0x1bd4aa
+	db "@"
+; 0xfcfa6
+
+TradeCompleteText1: ; 0xfcfa6
+	; Yay! I got myself @ ! Thanks!
+	text_jump UnknownText_0x1bd4d2
+	db "@"
+; 0xfcfab
+
+TradeAfterText1: ; 0xfcfab
+	; Hi, how's my old @  doing?
+	text_jump UnknownText_0x1bd4f4
+	db "@"
+; 0xfcfb0
+
+
+TradeIntroText2:
+TradeIntroText3: ; 0xfcfb0
+	; Hi, I'm looking for this #MON. If you have @ , would you trade it for my @ ?
+	text_jump UnknownText_0x1bd512
+	db "@"
+; 0xfcfb5
+
+TradeCancelText2:
+TradeCancelText3: ; 0xfcfb5
+	; You don't have one either? Gee, that's really disappointing…
+	text_jump UnknownText_0x1bd565
+	db "@"
+; 0xfcfba
+
+TradeWrongText2:
+TradeWrongText3: ; 0xfcfba
+	; You don't have @ ? That's too bad, then.
+	text_jump UnknownText_0x1bd5a1
+	db "@"
+; 0xfcfbf
+
+TradeCompleteText2: ; 0xfcfbf
+	; Great! Thank you! I finally got @ .
+	text_jump UnknownText_0x1bd5cc
+	db "@"
+; 0xfcfc4
+
+TradeAfterText2: ; 0xfcfc4
+	; Hi! The @ you traded me is doing great!
+	text_jump UnknownText_0x1bd5f4
+	db "@"
+; 0xfcfc9
+
+
+TradeIntroText4: ; 0xfcfc9
+	; 's cute, but I don't have it. Do you have @ ? Want to trade it for my @ ?
+	text_jump UnknownText_0x1bd621
+	db "@"
+; 0xfcfce
+
+TradeCancelText4: ; 0xfcfce
+	; You don't want to trade? Oh, darn…
+	text_jump UnknownText_0x1bd673
+	db "@"
+; 0xfcfd3
+
+TradeWrongText4: ; 0xfcfd3
+	; That's not @ . Please trade with me if you get one.
+	text_jump UnknownText_0x1bd696
+	db "@"
+; 0xfcfd8
+
+TradeCompleteText4: ; 0xfcfd8
+	; Wow! Thank you! I always wanted @ !
+	text_jump UnknownText_0x1bd6cd
+	db "@"
+; 0xfcfdd
+
+TradeAfterText4: ; 0xfcfdd
+	; How is that @  I traded you doing? Your @ 's so cute!
+	text_jump UnknownText_0x1bd6f5
+	db "@"
+; 0xfcfe2
+
+
+TradeCompleteText3: ; 0xfcfe2
+	; Uh? What happened?
+	text_jump UnknownText_0x1bd731
+	db "@"
+; 0xfcfe7
+
+TradeAfterText3: ; 0xfcfe7
+	; Trading is so odd… I still have a lot to learn about it.
+	text_jump UnknownText_0x1bd745
+	db "@"
+; 0xfcfec
--- a/engine/npctrade.asm
+++ /dev/null
@@ -1,586 +1,0 @@
-NPCTrade:: ; fcba8
-	ld a, e
-	ld [wJumptableIndex], a
-	call Trade_GetDialog
-	ld b, CHECK_FLAG
-	call TradeFlagAction
-	ld a, TRADE_AFTER
-	jr nz, .done
-
-	ld a, TRADE_INTRO
-	call PrintTradeText
-
-	call YesNoBox
-	ld a, TRADE_CANCEL
-	jr c, .done
-
-; Select givemon from party
-	ld b, PARTYMENUACTION_GIVE_MON
-	farcall SelectTradeOrDayCareMon
-	ld a, TRADE_CANCEL
-	jr c, .done
-
-	ld e, TRADE_GIVEMON
-	call GetTradeAttribute
-	ld a, [CurPartySpecies]
-	cp [hl]
-	ld a, TRADE_WRONG
-	jr nz, .done
-
-	call CheckTradeGender
-	ld a, TRADE_WRONG
-	jr c, .done
-
-	ld b, SET_FLAG
-	call TradeFlagAction
-
-	ld hl, ConnectLinkCableText
-	call PrintText
-
-	call DoNPCTrade
-	call .TradeAnimation
-	call GetTradeMonNames
-
-	ld hl, TradedForText
-	call PrintText
-
-	call RestartMapMusic
-
-	ld a, TRADE_COMPLETE
-
-.done
-	call PrintTradeText
-	ret
-; fcc07
-
-.TradeAnimation: ; fcc07
-	call DisableSpriteUpdates
-	ld a, [wJumptableIndex]
-	push af
-	ld a, [wcf64]
-	push af
-	predef TradeAnimation
-	pop af
-	ld [wcf64], a
-	pop af
-	ld [wJumptableIndex], a
-	call ReturnToMapWithSpeechTextbox
-	ret
-; fcc23
-
-CheckTradeGender: ; fcc23
-	xor a
-	ld [MonType], a
-
-	ld e, TRADE_GENDER
-	call GetTradeAttribute
-	ld a, [hl]
-	and a ; TRADE_EITHER_GENDER
-	jr z, .matching
-	cp TRADE_MALE_ONLY
-	jr z, .check_male
-
-	farcall GetGender
-	jr nz, .not_matching
-	jr .matching
-
-.check_male
-	farcall GetGender
-	jr z, .not_matching
-
-.matching
-	and a
-	ret
-
-.not_matching
-	scf
-	ret
-; fcc4a
-
-TradeFlagAction: ; fcc4a
-	ld hl, wTradeFlags
-	ld a, [wJumptableIndex]
-	ld c, a
-	predef SmallFarFlagAction
-	ld a, c
-	and a
-	ret
-; fcc59
-
-Trade_GetDialog: ; fcc59
-	ld e, TRADE_DIALOG
-	call GetTradeAttribute
-	ld a, [hl]
-	ld [wcf64], a
-	ret
-; fcc63
-
-DoNPCTrade: ; fcc63
-	ld e, TRADE_GIVEMON
-	call GetTradeAttribute
-	ld a, [hl]
-	ld [wPlayerTrademonSpecies], a
-
-	ld e, TRADE_GETMON
-	call GetTradeAttribute
-	ld a, [hl]
-	ld [wOTTrademonSpecies], a
-
-	ld a, [wPlayerTrademonSpecies]
-	ld de, wPlayerTrademonSpeciesName
-	call GetTradeMonName
-	call CopyTradeName
-
-	ld a, [wOTTrademonSpecies]
-	ld de, wOTTrademonSpeciesName
-	call GetTradeMonName
-	call CopyTradeName
-
-	ld hl, PartyMonOT
-	ld bc, NAME_LENGTH
-	call Trade_GetAttributeOfCurrentPartymon
-	ld de, wPlayerTrademonOTName
-	call CopyTradeName
-
-	ld hl, PlayerName
-	ld de, wPlayerTrademonSenderName
-	call CopyTradeName
-
-	ld hl, PartyMon1ID
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfCurrentPartymon
-	ld de, wPlayerTrademonID
-	call Trade_CopyTwoBytes
-
-	ld hl, PartyMon1DVs
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfCurrentPartymon
-	ld de, wPlayerTrademonDVs
-	call Trade_CopyTwoBytes
-
-	ld hl, PartyMon1Species
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfCurrentPartymon
-	ld b, h
-	ld c, l
-	farcall GetCaughtGender
-	ld a, c
-	ld [wPlayerTrademonCaughtData], a
-
-	ld e, TRADE_DIALOG
-	call GetTradeAttribute
-	ld a, [hl]
-	cp TRADE_DIALOG_GIRL
-	ld a, CAUGHT_BY_GIRL
-	jr c, .okay
-	ld a, CAUGHT_BY_BOY
-.okay
-	ld [wOTTrademonCaughtData], a
-
-	ld hl, PartyMon1Level
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfCurrentPartymon
-	ld a, [hl]
-	ld [CurPartyLevel], a
-	ld a, [wOTTrademonSpecies]
-	ld [CurPartySpecies], a
-	xor a
-	ld [MonType], a
-	ld [wPokemonWithdrawDepositParameter], a
-	callfar RemoveMonFromPartyOrBox
-	predef TryAddMonToParty
-
-	ld e, TRADE_DIALOG
-	call GetTradeAttribute
-	ld a, [hl]
-	cp TRADE_COMPLETE
-	ld b, RESET_FLAG
-	jr c, .incomplete
-	ld b, SET_FLAG
-.incomplete
-	farcall SetGiftPartyMonCaughtData
-
-	ld e, TRADE_NICK
-	call GetTradeAttribute
-	ld de, wOTTrademonNickname
-	call CopyTradeName
-
-	ld hl, PartyMonNicknames
-	ld bc, MON_NAME_LENGTH
-	call Trade_GetAttributeOfLastPartymon
-	ld hl, wOTTrademonNickname
-	call CopyTradeName
-
-	ld e, TRADE_OT_NAME
-	call GetTradeAttribute
-	push hl
-	ld de, wOTTrademonOTName
-	call CopyTradeName
-	pop hl
-	ld de, wOTTrademonSenderName
-	call CopyTradeName
-
-	ld hl, PartyMonOT
-	ld bc, NAME_LENGTH
-	call Trade_GetAttributeOfLastPartymon
-	ld hl, wOTTrademonOTName
-	call CopyTradeName
-
-	ld e, TRADE_DVS
-	call GetTradeAttribute
-	ld de, wOTTrademonDVs
-	call Trade_CopyTwoBytes
-
-	ld hl, PartyMon1DVs
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfLastPartymon
-	ld hl, wOTTrademonDVs
-	call Trade_CopyTwoBytes
-
-	ld e, TRADE_OT_ID
-	call GetTradeAttribute
-	ld de, wOTTrademonID + 1
-	call Trade_CopyTwoBytesReverseEndian
-
-	ld hl, PartyMon1ID
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfLastPartymon
-	ld hl, wOTTrademonID
-	call Trade_CopyTwoBytes
-
-	ld e, TRADE_ITEM
-	call GetTradeAttribute
-	push hl
-	ld hl, PartyMon1Item
-	ld bc, PARTYMON_STRUCT_LENGTH
-	call Trade_GetAttributeOfLastPartymon
-	pop hl
-	ld a, [hl]
-	ld [de], a
-
-	push af
-	push bc
-	push de
-	push hl
-	ld a, [CurPartyMon]
-	push af
-	ld a, [PartyCount]
-	dec a
-	ld [CurPartyMon], a
-	farcall ComputeNPCTrademonStats
-	pop af
-	ld [CurPartyMon], a
-	pop hl
-	pop de
-	pop bc
-	pop af
-	ret
-; fcdc2
-
-
-GetTradeAttribute: ; 0xfcdc2
-	ld d, 0
-	push de
-	ld a, [wJumptableIndex]
-	and $f
-	swap a
-	ld e, a
-	ld d, 0
-	ld hl, NPCTrades
-	add hl, de
-	add hl, de
-	pop de
-	add hl, de
-	ret
-; 0xfcdd7
-
-Trade_GetAttributeOfCurrentPartymon: ; fcdd7
-	ld a, [CurPartyMon]
-	call AddNTimes
-	ret
-; fcdde
-
-Trade_GetAttributeOfLastPartymon: ; fcdde
-	ld a, [PartyCount]
-	dec a
-	call AddNTimes
-	ld e, l
-	ld d, h
-	ret
-; fcde8
-
-GetTradeMonName: ; fcde8
-	push de
-	ld [wd265], a
-	call GetBasePokemonName
-	ld hl, StringBuffer1
-	pop de
-	ret
-; fcdf4
-
-CopyTradeName: ; fcdf4
-	ld bc, NAME_LENGTH
-	call CopyBytes
-	ret
-; fcdfb
-
-Unreferenced_Functionfcdfb: ; fcdfb
-	ld bc, 4
-	call CopyBytes
-	ld a, "@"
-	ld [de], a
-	ret
-; fce05
-
-Unreferenced_Functionfce05: ; fce05
-	ld bc, 3
-	call CopyBytes
-	ld a, "@"
-	ld [de], a
-	ret
-; fce0f
-
-Trade_CopyTwoBytes: ; fce0f
-	ld a, [hli]
-	ld [de], a
-	inc de
-	ld a, [hl]
-	ld [de], a
-	ret
-; fce15
-
-Trade_CopyTwoBytesReverseEndian: ; fce15
-	ld a, [hli]
-	ld [de], a
-	dec de
-	ld a, [hl]
-	ld [de], a
-	ret
-; fce1b
-
-GetTradeMonNames: ; fce1b
-	ld e, TRADE_GETMON
-	call GetTradeAttribute
-	ld a, [hl]
-	call GetTradeMonName
-
-	ld de, StringBuffer2
-	call CopyTradeName
-
-	ld e, TRADE_GIVEMON
-	call GetTradeAttribute
-	ld a, [hl]
-	call GetTradeMonName
-
-	ld de, wMonOrItemNameBuffer
-	call CopyTradeName
-
-	ld hl, StringBuffer1
-.loop
-	ld a, [hli]
-	cp "@"
-	jr nz, .loop
-
-	dec hl
-	push hl
-	ld e, TRADE_GENDER
-	call GetTradeAttribute
-	ld a, [hl]
-	pop hl
-	and a
-	ret z
-
-	cp TRADE_MALE_ONLY
-	ld a, "♂"
-	jr z, .done
-	ld a, "♀"
-.done
-	ld [hli], a
-	ld [hl], "@"
-	ret
-; fce58
-
-
-INCLUDE "data/events/npc_trades.asm"
-
-
-PrintTradeText: ; fcf38
-	push af
-	call GetTradeMonNames
-	pop af
-	ld bc, 2 * 4
-	ld hl, TradeTexts
-	call AddNTimes
-	ld a, [wcf64]
-	ld c, a
-	add hl, bc
-	add hl, bc
-	ld a, [hli]
-	ld h, [hl]
-	ld l, a
-	call PrintText
-	ret
-; fcf53
-
-TradeTexts: ; fcf53
-; entries correspond to TRADE_* × TRADE_DIALOG_* constants
-; TRADE_INTRO
-	dw TradeIntroText1
-	dw TradeIntroText2
-	dw TradeIntroText3
-	dw TradeIntroText4
-; TRADE_CANCEL
-	dw TradeCancelText1
-	dw TradeCancelText2
-	dw TradeCancelText3
-	dw TradeCancelText4
-; TRADE_WRONG
-	dw TradeWrongText1
-	dw TradeWrongText2
-	dw TradeWrongText3
-	dw TradeWrongText4
-; TRADE_COMPLETE
-	dw TradeCompleteText1
-	dw TradeCompleteText2
-	dw TradeCompleteText3
-	dw TradeCompleteText4
-; TRADE_AFTER
-	dw TradeAfterText1
-	dw TradeAfterText2
-	dw TradeAfterText3
-	dw TradeAfterText4
-; fcf7b
-
-
-ConnectLinkCableText: ; 0xfcf7b
-	; OK, connect the Game Link Cable.
-	text_jump UnknownText_0x1bd407
-	db "@"
-; 0xfcf80
-
-
-TradedForText: ; 0xfcf80
-	; traded givemon for getmon
-	text_jump UnknownText_0x1bd429
-	start_asm
-	ld de, MUSIC_NONE
-	call PlayMusic
-	call DelayFrame
-	ld hl, .done
-	ret
-
-.done
-	; sound_dex_fanfare_80_109
-	; interpret_data
-	text_jump UnknownText_0x1bd445
-	db "@"
-; 0xfcf97
-
-
-TradeIntroText1: ; 0xfcf97
-	; I collect #MON. Do you have @ ? Want to trade it for my @ ?
-	text_jump UnknownText_0x1bd449
-	db "@"
-; 0xfcf9c
-
-TradeCancelText1: ; 0xfcf9c
-	; You don't want to trade? Aww…
-	text_jump UnknownText_0x1bd48c
-	db "@"
-; 0xfcfa1
-
-TradeWrongText1: ; 0xfcfa1
-	; Huh? That's not @ .  What a letdown…
-	text_jump UnknownText_0x1bd4aa
-	db "@"
-; 0xfcfa6
-
-TradeCompleteText1: ; 0xfcfa6
-	; Yay! I got myself @ ! Thanks!
-	text_jump UnknownText_0x1bd4d2
-	db "@"
-; 0xfcfab
-
-TradeAfterText1: ; 0xfcfab
-	; Hi, how's my old @  doing?
-	text_jump UnknownText_0x1bd4f4
-	db "@"
-; 0xfcfb0
-
-
-TradeIntroText2:
-TradeIntroText3: ; 0xfcfb0
-	; Hi, I'm looking for this #MON. If you have @ , would you trade it for my @ ?
-	text_jump UnknownText_0x1bd512
-	db "@"
-; 0xfcfb5
-
-TradeCancelText2:
-TradeCancelText3: ; 0xfcfb5
-	; You don't have one either? Gee, that's really disappointing…
-	text_jump UnknownText_0x1bd565
-	db "@"
-; 0xfcfba
-
-TradeWrongText2:
-TradeWrongText3: ; 0xfcfba
-	; You don't have @ ? That's too bad, then.
-	text_jump UnknownText_0x1bd5a1
-	db "@"
-; 0xfcfbf
-
-TradeCompleteText2: ; 0xfcfbf
-	; Great! Thank you! I finally got @ .
-	text_jump UnknownText_0x1bd5cc
-	db "@"
-; 0xfcfc4
-
-TradeAfterText2: ; 0xfcfc4
-	; Hi! The @ you traded me is doing great!
-	text_jump UnknownText_0x1bd5f4
-	db "@"
-; 0xfcfc9
-
-
-TradeIntroText4: ; 0xfcfc9
-	; 's cute, but I don't have it. Do you have @ ? Want to trade it for my @ ?
-	text_jump UnknownText_0x1bd621
-	db "@"
-; 0xfcfce
-
-TradeCancelText4: ; 0xfcfce
-	; You don't want to trade? Oh, darn…
-	text_jump UnknownText_0x1bd673
-	db "@"
-; 0xfcfd3
-
-TradeWrongText4: ; 0xfcfd3
-	; That's not @ . Please trade with me if you get one.
-	text_jump UnknownText_0x1bd696
-	db "@"
-; 0xfcfd8
-
-TradeCompleteText4: ; 0xfcfd8
-	; Wow! Thank you! I always wanted @ !
-	text_jump UnknownText_0x1bd6cd
-	db "@"
-; 0xfcfdd
-
-TradeAfterText4: ; 0xfcfdd
-	; How is that @  I traded you doing? Your @ 's so cute!
-	text_jump UnknownText_0x1bd6f5
-	db "@"
-; 0xfcfe2
-
-
-TradeCompleteText3: ; 0xfcfe2
-	; Uh? What happened?
-	text_jump UnknownText_0x1bd731
-	db "@"
-; 0xfcfe7
-
-TradeAfterText3: ; 0xfcfe7
-	; Trading is so odd… I still have a lot to learn about it.
-	text_jump UnknownText_0x1bd745
-	db "@"
-; 0xfcfec
--- a/main.asm
+++ b/main.asm
@@ -462,7 +462,7 @@
 SECTION "bank3F", ROMX
 
 INCLUDE "engine/tileset_anims.asm"
-INCLUDE "engine/npctrade.asm"
+INCLUDE "engine/events/npc_trade.asm"
 INCLUDE "engine/events/mom_phone.asm"
 
 
--- a/maps/BlackthornEmysHouse.asm
+++ b/maps/BlackthornEmysHouse.asm
@@ -9,7 +9,7 @@
 Emy:
 	faceplayer
 	opentext
-	trade NPCTRADE_EMY
+	trade NPC_TRADE_EMY
 	waitbutton
 	closetext
 	end
--- a/maps/BurnedTower1F.asm
+++ b/maps/BurnedTower1F.asm
@@ -281,18 +281,18 @@
 	db 14 ; warp events
 	warp_event 9, 15, 13, ECRUTEAK_CITY
 	warp_event 10, 15, 13, ECRUTEAK_CITY
-	warp_event 10, 9,  1, BURNED_TOWER_B1F
-	warp_event 5, 5,  1, BURNED_TOWER_B1F
-	warp_event 5, 6,  1, BURNED_TOWER_B1F
-	warp_event 4, 6,  1, BURNED_TOWER_B1F
-	warp_event 15, 4,  2, BURNED_TOWER_B1F
-	warp_event 15, 5,  2, BURNED_TOWER_B1F
-	warp_event 10, 7,  3, BURNED_TOWER_B1F
-	warp_event 5, 14,  4, BURNED_TOWER_B1F
-	warp_event 4, 14,  4, BURNED_TOWER_B1F
-	warp_event 14, 14,  5, BURNED_TOWER_B1F
-	warp_event 15, 14,  5, BURNED_TOWER_B1F
-	warp_event 7, 15,  6, BURNED_TOWER_B1F
+	warp_event 10, 9, 1, BURNED_TOWER_B1F
+	warp_event 5, 5, 1, BURNED_TOWER_B1F
+	warp_event 5, 6, 1, BURNED_TOWER_B1F
+	warp_event 4, 6, 1, BURNED_TOWER_B1F
+	warp_event 15, 4, 2, BURNED_TOWER_B1F
+	warp_event 15, 5, 2, BURNED_TOWER_B1F
+	warp_event 10, 7, 3, BURNED_TOWER_B1F
+	warp_event 5, 14, 4, BURNED_TOWER_B1F
+	warp_event 4, 14, 4, BURNED_TOWER_B1F
+	warp_event 14, 14, 5, BURNED_TOWER_B1F
+	warp_event 15, 14, 5, BURNED_TOWER_B1F
+	warp_event 7, 15, 6, BURNED_TOWER_B1F
 
 	db 1 ; coord events
 	coord_event 11, 9, 1, BurnedTowerRivalBattleScript
--- a/maps/GoldenrodDeptStore5F.asm
+++ b/maps/GoldenrodDeptStore5F.asm
@@ -124,7 +124,7 @@
 Mike:
 	faceplayer
 	opentext
-	trade NPCTRADE_MIKE
+	trade NPC_TRADE_MIKE
 	waitbutton
 	closetext
 	end
--- a/maps/OlivineTimsHouse.asm
+++ b/maps/OlivineTimsHouse.asm
@@ -9,7 +9,7 @@
 Tim:
 	faceplayer
 	opentext
-	trade NPCTRADE_TIM
+	trade NPC_TRADE_TIM
 	waitbutton
 	closetext
 	end
--- a/maps/PewterPokecenter1F.asm
+++ b/maps/PewterPokecenter1F.asm
@@ -30,7 +30,7 @@
 Chris:
 	faceplayer
 	opentext
-	trade NPCTRADE_CHRIS
+	trade NPC_TRADE_CHRIS
 	waitbutton
 	closetext
 	end
--- a/maps/PowerPlant.asm
+++ b/maps/PowerPlant.asm
@@ -189,7 +189,7 @@
 Forest:
 	faceplayer
 	opentext
-	trade NPCTRADE_FOREST
+	trade NPC_TRADE_FOREST
 	waitbutton
 	closetext
 	end
--- a/maps/Route14.asm
+++ b/maps/Route14.asm
@@ -12,7 +12,7 @@
 Kim:
 	faceplayer
 	opentext
-	trade NPCTRADE_KIM
+	trade NPC_TRADE_KIM
 	waitbutton
 	closetext
 	end
--- a/maps/VioletKylesHouse.asm
+++ b/maps/VioletKylesHouse.asm
@@ -13,7 +13,7 @@
 Kyle:
 	faceplayer
 	opentext
-	trade NPCTRADE_KYLE
+	trade NPC_TRADE_KYLE
 	waitbutton
 	closetext
 	end