2023-11-28 04:59:36 -08:00
|
|
|
CheckTrainerBattleOrTalkerPrompt::
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hROMBank]
|
2017-12-22 19:50:28 -08:00
|
|
|
push af
|
|
|
|
|
2018-01-16 19:57:19 -08:00
|
|
|
call SwitchToMapScriptsBank
|
2023-11-28 04:59:36 -08:00
|
|
|
call _CheckTrainerBattleOrTalkerPrompt
|
2017-12-22 19:50:28 -08:00
|
|
|
|
|
|
|
pop bc
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
|
2023-11-28 04:59:36 -08:00
|
|
|
_CheckTrainerBattleOrTalkerPrompt::
|
|
|
|
; Check if any trainer or talker on the map sees the player and wants to battle or talk.
|
2017-12-22 19:50:28 -08:00
|
|
|
|
|
|
|
; Skip the player object.
|
|
|
|
ld a, 1
|
2023-12-15 04:43:42 -08:00
|
|
|
ld de, wMapObject1
|
2017-12-22 19:50:28 -08:00
|
|
|
|
|
|
|
.loop
|
|
|
|
|
|
|
|
; Start a battle if the object:
|
|
|
|
push af
|
|
|
|
push de
|
|
|
|
|
|
|
|
; Has a sprite
|
|
|
|
ld hl, MAPOBJECT_SPRITE
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .next
|
|
|
|
|
2023-11-28 04:59:36 -08:00
|
|
|
; Is a trainer or a talker
|
2023-01-03 19:16:08 -08:00
|
|
|
ld hl, MAPOBJECT_TYPE
|
2017-12-22 19:50:28 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
2023-01-03 19:16:08 -08:00
|
|
|
and MAPOBJECT_TYPE_MASK
|
2018-10-11 02:37:19 -07:00
|
|
|
cp OBJECTTYPE_TRAINER
|
2023-11-28 04:59:36 -08:00
|
|
|
jr z, .is_trainer
|
|
|
|
cp OBJECTTYPE_TALKER
|
2017-12-22 19:50:28 -08:00
|
|
|
jr nz, .next
|
2023-11-28 09:02:00 -08:00
|
|
|
; also set wSeenTrainerOrTalkerIsTalker accordingly (flag is only relevant if there's actually an event)
|
2023-11-28 04:59:36 -08:00
|
|
|
;.is_talker
|
|
|
|
ld a, TRUE
|
2023-11-28 09:02:00 -08:00
|
|
|
ld [wSeenTrainerOrTalkerIsTalker], a
|
2023-11-28 04:59:36 -08:00
|
|
|
jr .go
|
|
|
|
.is_trainer
|
|
|
|
xor a ; FALSE
|
2023-11-28 09:02:00 -08:00
|
|
|
ld [wSeenTrainerOrTalkerIsTalker], a
|
2023-11-28 04:59:36 -08:00
|
|
|
|
|
|
|
.go
|
2017-12-22 19:50:28 -08:00
|
|
|
; Is visible on the map
|
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
cp -1
|
|
|
|
jr z, .next
|
|
|
|
|
|
|
|
; Is facing the player...
|
|
|
|
call GetObjectStruct
|
|
|
|
call FacingPlayerDistance_bc
|
|
|
|
jr nc, .next
|
|
|
|
|
|
|
|
; ...within their sight range
|
2023-01-03 19:16:08 -08:00
|
|
|
ld hl, MAPOBJECT_SIGHT_RANGE
|
2017-12-22 19:50:28 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
cp b
|
|
|
|
jr c, .next
|
|
|
|
|
2023-11-28 09:02:00 -08:00
|
|
|
; And hasn't already been beaten if it's a trainer, or talked to if it's a talker,
|
|
|
|
; according to the scope of the flag of the trainer or talker event.
|
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
|
|
|
add hl, de
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl] ; de = wTempTrainerEventFlag = wTempTalkerEventFlag
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
ld a, c
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
and a
|
|
|
|
jr nz, .next
|
|
|
|
|
|
|
|
ld a, [wSeenTrainerOrTalkerIsTalker]
|
|
|
|
and a ; cp FALSE
|
|
|
|
jr z, .prepare_trainer_battle
|
2023-11-28 04:59:36 -08:00
|
|
|
|
2023-11-28 09:02:00 -08:00
|
|
|
;.prepare_talker_prompt
|
2023-11-28 04:59:36 -08:00
|
|
|
pop de
|
|
|
|
pop af
|
|
|
|
ldh [hLastTalked], a
|
|
|
|
ld a, b
|
|
|
|
ld [wSeenTrainerOrTalkerDistance], a
|
|
|
|
ld a, c
|
|
|
|
ld [wSeenTrainerOrTalkerDirection], a
|
|
|
|
call GetMapScriptsBank
|
|
|
|
ld [wSeenTrainerOrTalkerBank], a
|
|
|
|
|
|
|
|
ldh a, [hLastTalked]
|
|
|
|
call GetMapObject
|
|
|
|
|
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
|
|
|
add hl, bc
|
|
|
|
ld a, [wSeenTrainerOrTalkerBank]
|
|
|
|
call GetFarWord
|
|
|
|
ld de, wTempTalker
|
|
|
|
ld bc, wTempTalkerEnd - wTempTalker
|
|
|
|
ld a, [wSeenTrainerOrTalkerBank]
|
|
|
|
call FarCopyBytes
|
|
|
|
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2017-12-22 19:50:28 -08:00
|
|
|
.next
|
|
|
|
pop de
|
2019-11-03 09:25:59 -08:00
|
|
|
ld hl, MAPOBJECT_LENGTH
|
2017-12-22 19:50:28 -08:00
|
|
|
add hl, de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
|
|
|
|
pop af
|
|
|
|
inc a
|
|
|
|
cp NUM_OBJECTS
|
2023-11-28 04:59:36 -08:00
|
|
|
jp nz, .loop
|
2017-12-22 19:50:28 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2023-11-28 09:02:00 -08:00
|
|
|
.prepare_trainer_battle
|
2017-12-22 19:50:28 -08:00
|
|
|
pop de
|
|
|
|
pop af
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hLastTalked], a
|
2017-12-22 19:50:28 -08:00
|
|
|
ld a, b
|
2023-11-28 04:59:36 -08:00
|
|
|
ld [wSeenTrainerOrTalkerDistance], a
|
2017-12-22 19:50:28 -08:00
|
|
|
ld a, c
|
2023-11-28 04:59:36 -08:00
|
|
|
ld [wSeenTrainerOrTalkerDirection], a
|
2017-12-22 19:50:28 -08:00
|
|
|
jr LoadTrainer_continue
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TalkToTrainer::
|
2017-12-22 19:50:28 -08:00
|
|
|
ld a, 1
|
2023-11-28 04:59:36 -08:00
|
|
|
ld [wSeenTrainerOrTalkerDistance], a
|
2017-12-22 19:50:28 -08:00
|
|
|
ld a, -1
|
2023-11-28 04:59:36 -08:00
|
|
|
ld [wSeenTrainerOrTalkerDirection], a
|
2017-12-22 19:50:28 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LoadTrainer_continue::
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2023-11-28 04:59:36 -08:00
|
|
|
ld [wSeenTrainerOrTalkerBank], a
|
2017-12-22 19:50:28 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hLastTalked]
|
2017-12-22 19:50:28 -08:00
|
|
|
call GetMapObject
|
|
|
|
|
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
|
|
|
add hl, bc
|
2023-11-28 04:59:36 -08:00
|
|
|
ld a, [wSeenTrainerOrTalkerBank]
|
2021-01-09 12:16:05 -08:00
|
|
|
call GetFarWord
|
2018-01-16 19:57:19 -08:00
|
|
|
ld de, wTempTrainer
|
|
|
|
ld bc, wTempTrainerEnd - wTempTrainer
|
2023-11-28 04:59:36 -08:00
|
|
|
ld a, [wSeenTrainerOrTalkerBank]
|
2017-12-22 19:50:28 -08:00
|
|
|
call FarCopyBytes
|
|
|
|
xor a
|
|
|
|
ld [wRunningTrainerBattleScript], a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FacingPlayerDistance_bc::
|
2017-12-22 19:50:28 -08:00
|
|
|
push de
|
|
|
|
call FacingPlayerDistance
|
|
|
|
ld b, d
|
|
|
|
ld c, e
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FacingPlayerDistance::
|
2017-12-22 19:50:28 -08:00
|
|
|
; Return carry if the sprite at bc is facing the player,
|
2019-04-08 15:50:10 -07:00
|
|
|
; its distance in d, and its direction in e.
|
2017-12-22 19:50:28 -08:00
|
|
|
|
2022-09-12 06:15:44 -07:00
|
|
|
ld hl, OBJECT_MAP_X ; x
|
2017-12-22 19:50:28 -08:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
|
|
|
|
2022-09-12 06:15:44 -07:00
|
|
|
ld hl, OBJECT_MAP_Y ; y
|
2017-12-22 19:50:28 -08:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
|
|
|
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerMapX]
|
2017-12-22 19:50:28 -08:00
|
|
|
cp d
|
|
|
|
jr z, .CheckY
|
|
|
|
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerMapY]
|
2017-12-22 19:50:28 -08:00
|
|
|
cp e
|
|
|
|
jr z, .CheckX
|
|
|
|
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.CheckY:
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerMapY]
|
2017-12-22 19:50:28 -08:00
|
|
|
sub e
|
|
|
|
jr z, .NotFacing
|
|
|
|
jr nc, .Above
|
|
|
|
|
|
|
|
; Below
|
|
|
|
cpl
|
|
|
|
inc a
|
|
|
|
ld d, a
|
|
|
|
ld e, OW_UP
|
|
|
|
jr .CheckFacing
|
|
|
|
|
|
|
|
.Above:
|
|
|
|
ld d, a
|
|
|
|
ld e, OW_DOWN
|
|
|
|
jr .CheckFacing
|
|
|
|
|
|
|
|
.CheckX:
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerMapX]
|
2017-12-22 19:50:28 -08:00
|
|
|
sub d
|
|
|
|
jr z, .NotFacing
|
|
|
|
jr nc, .Left
|
|
|
|
|
|
|
|
; Right
|
|
|
|
cpl
|
|
|
|
inc a
|
|
|
|
ld d, a
|
|
|
|
ld e, OW_LEFT
|
|
|
|
jr .CheckFacing
|
|
|
|
|
|
|
|
.Left:
|
|
|
|
ld d, a
|
|
|
|
ld e, OW_RIGHT
|
|
|
|
|
|
|
|
.CheckFacing:
|
|
|
|
call GetSpriteDirection
|
|
|
|
cp e
|
|
|
|
jr nz, .NotFacing
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
.NotFacing:
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PrintWinLossText::
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wBattleType]
|
2017-12-22 19:50:28 -08:00
|
|
|
cp BATTLETYPE_CANLOSE
|
2020-11-17 08:09:02 -08:00
|
|
|
; code was probably dummied out here
|
|
|
|
jr .canlose
|
2017-12-22 19:50:28 -08:00
|
|
|
|
2018-01-02 07:04:21 -08:00
|
|
|
; unused
|
2017-12-22 19:50:28 -08:00
|
|
|
ld hl, wWinTextPointer
|
|
|
|
jr .ok
|
|
|
|
|
|
|
|
.canlose
|
|
|
|
ld a, [wBattleResult]
|
|
|
|
ld hl, wWinTextPointer
|
2018-04-05 08:44:02 -07:00
|
|
|
and $f ; WIN?
|
2017-12-22 19:50:28 -08:00
|
|
|
jr z, .ok
|
|
|
|
ld hl, wLossTextPointer
|
|
|
|
|
|
|
|
.ok
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2023-08-11 03:28:14 -07:00
|
|
|
call FarPrintText1bpp
|
2017-12-22 19:50:28 -08:00
|
|
|
call WaitBGMap
|
|
|
|
call WaitPressAorB_BlinkCursor
|
|
|
|
ret
|