2018-10-11 09:37:19 +00:00
|
|
|
CheckTrainerBattle::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2017-12-23 03:50:28 +00:00
|
|
|
push af
|
|
|
|
|
2018-01-17 03:57:19 +00:00
|
|
|
call SwitchToMapScriptsBank
|
2018-10-11 09:37:19 +00:00
|
|
|
call _CheckTrainerBattle
|
2017-12-23 03:50:28 +00:00
|
|
|
|
|
|
|
pop bc
|
|
|
|
ld a, b
|
|
|
|
rst Bankswitch
|
|
|
|
ret
|
|
|
|
|
2018-10-11 09:37:19 +00:00
|
|
|
_CheckTrainerBattle::
|
2017-12-23 03:50:28 +00:00
|
|
|
; Check if any trainer on the map sees the player and wants to battle.
|
|
|
|
|
|
|
|
; Skip the player object.
|
|
|
|
ld a, 1
|
2020-06-16 19:49:32 +00:00
|
|
|
ld de, wMap1Object
|
2017-12-23 03:50:28 +00: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
|
|
|
|
|
|
|
|
; Is a trainer
|
|
|
|
ld hl, MAPOBJECT_COLOR
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
and $f
|
2018-10-11 09:37:19 +00:00
|
|
|
cp OBJECTTYPE_TRAINER
|
2017-12-23 03:50:28 +00:00
|
|
|
jr nz, .next
|
|
|
|
|
|
|
|
; 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
|
|
|
|
ld hl, MAPOBJECT_RANGE
|
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
cp b
|
|
|
|
jr c, .next
|
|
|
|
|
|
|
|
; And hasn't already been beaten
|
|
|
|
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]
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
ld a, c
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
and a
|
|
|
|
jr z, .startbattle
|
|
|
|
|
|
|
|
.next
|
|
|
|
pop de
|
2019-11-03 17:25:59 +00:00
|
|
|
ld hl, MAPOBJECT_LENGTH
|
2017-12-23 03:50:28 +00:00
|
|
|
add hl, de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
|
|
|
|
pop af
|
|
|
|
inc a
|
|
|
|
cp NUM_OBJECTS
|
|
|
|
jr nz, .loop
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.startbattle
|
|
|
|
pop de
|
|
|
|
pop af
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hLastTalked], a
|
2017-12-23 03:50:28 +00:00
|
|
|
ld a, b
|
2019-04-08 22:50:10 +00:00
|
|
|
ld [wSeenTrainerDistance], a
|
2017-12-23 03:50:28 +00:00
|
|
|
ld a, c
|
2019-04-08 22:50:10 +00:00
|
|
|
ld [wSeenTrainerDirection], a
|
2017-12-23 03:50:28 +00:00
|
|
|
jr LoadTrainer_continue
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
TalkToTrainer::
|
2017-12-23 03:50:28 +00:00
|
|
|
ld a, 1
|
2019-04-08 22:50:10 +00:00
|
|
|
ld [wSeenTrainerDistance], a
|
2017-12-23 03:50:28 +00:00
|
|
|
ld a, -1
|
2019-04-08 22:50:10 +00:00
|
|
|
ld [wSeenTrainerDirection], a
|
2017-12-23 03:50:28 +00:00
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
LoadTrainer_continue::
|
2018-01-17 03:57:19 +00:00
|
|
|
call GetMapScriptsBank
|
2019-04-08 22:50:10 +00:00
|
|
|
ld [wSeenTrainerBank], a
|
2017-12-23 03:50:28 +00:00
|
|
|
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hLastTalked]
|
2017-12-23 03:50:28 +00:00
|
|
|
call GetMapObject
|
|
|
|
|
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
|
|
|
add hl, bc
|
2019-04-08 22:50:10 +00:00
|
|
|
ld a, [wSeenTrainerBank]
|
2017-12-23 03:50:28 +00:00
|
|
|
call GetFarHalfword
|
2018-01-17 03:57:19 +00:00
|
|
|
ld de, wTempTrainer
|
|
|
|
ld bc, wTempTrainerEnd - wTempTrainer
|
2019-04-08 22:50:10 +00:00
|
|
|
ld a, [wSeenTrainerBank]
|
2017-12-23 03:50:28 +00:00
|
|
|
call FarCopyBytes
|
|
|
|
xor a
|
|
|
|
ld [wRunningTrainerBattleScript], a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FacingPlayerDistance_bc::
|
2017-12-23 03:50:28 +00:00
|
|
|
push de
|
|
|
|
call FacingPlayerDistance
|
|
|
|
ld b, d
|
|
|
|
ld c, e
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FacingPlayerDistance::
|
2017-12-23 03:50:28 +00:00
|
|
|
; Return carry if the sprite at bc is facing the player,
|
2019-04-08 22:50:10 +00:00
|
|
|
; its distance in d, and its direction in e.
|
2017-12-23 03:50:28 +00:00
|
|
|
|
|
|
|
ld hl, OBJECT_NEXT_MAP_X ; x
|
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
|
|
|
|
|
|
|
ld hl, OBJECT_NEXT_MAP_Y ; y
|
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingMapX]
|
2017-12-23 03:50:28 +00:00
|
|
|
cp d
|
|
|
|
jr z, .CheckY
|
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingMapY]
|
2017-12-23 03:50:28 +00:00
|
|
|
cp e
|
|
|
|
jr z, .CheckX
|
|
|
|
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.CheckY:
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingMapY]
|
2017-12-23 03:50:28 +00: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:
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingMapX]
|
2017-12-23 03:50:28 +00: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
|
|
|
|
|
2020-06-21 20:27:43 +00:00
|
|
|
CheckTrainerFlag:: ; unreferenced
|
2017-12-23 03:50:28 +00:00
|
|
|
push bc
|
|
|
|
ld hl, OBJECT_MAP_OBJECT_INDEX
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
call GetMapObject
|
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-17 03:57:19 +00:00
|
|
|
call GetMapScriptsBank
|
2017-12-23 03:50:28 +00:00
|
|
|
call GetFarHalfword
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
push de
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
pop de
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
PrintWinLossText::
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wBattleType]
|
2017-12-23 03:50:28 +00:00
|
|
|
cp BATTLETYPE_CANLOSE
|
2020-11-17 16:09:02 +00:00
|
|
|
; code was probably dummied out here
|
|
|
|
jr .canlose
|
2017-12-23 03:50:28 +00:00
|
|
|
|
2018-01-02 15:04:21 +00:00
|
|
|
; unused
|
2017-12-23 03:50:28 +00:00
|
|
|
ld hl, wWinTextPointer
|
|
|
|
jr .ok
|
|
|
|
|
|
|
|
.canlose
|
|
|
|
ld a, [wBattleResult]
|
|
|
|
ld hl, wWinTextPointer
|
2018-04-05 15:44:02 +00:00
|
|
|
and $f ; WIN?
|
2017-12-23 03:50:28 +00:00
|
|
|
jr z, .ok
|
|
|
|
ld hl, wLossTextPointer
|
|
|
|
|
|
|
|
.ok
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-17 03:57:19 +00:00
|
|
|
call GetMapScriptsBank
|
2017-12-23 03:50:28 +00:00
|
|
|
call FarPrintText
|
|
|
|
call WaitBGMap
|
|
|
|
call WaitPressAorB_BlinkCursor
|
|
|
|
ret
|