Files
pokecrystal-board/engine/overworld/spawn_points.asm

120 lines
2.0 KiB
NASM

INCLUDE "data/maps/spawn_points.asm"
EnterMapSpawnPoint:
push hl
push de
ld a, [wDefaultSpawnpoint]
cp SPAWN_N_A
jr z, .spawn_n_a
cp SPAWN_FROM_RAM
jr z, .spawn_from_ram
; either MAPSETUP_ENTERLEVEL or MAPSETUP_WARP
; loads the spawn point in wDefaultSpawnpoint
ld l, a
ld h, 0
add hl, hl
add hl, hl
ld de, SpawnPoints
add hl, de
ld a, [hli]
ld [wMapGroup], a
ld a, [hli]
ld [wMapNumber], a
ld a, [hli]
ld [wXCoord], a
ld a, [hli]
ld [wYCoord], a
pop de
pop hl
ret
.spawn_from_ram
; either MAPSETUP_EXITVIEWMAP or MAPSETUP_NEXTPLAYER
ld a, [wCurTurnPlayer]
ld hl, wPlayer1Location
ld bc, wPlayer2Location - wPlayer1Location
call AddNTimes
ld a, [hli]
ld [wMapGroup], a
ld a, [hli]
ld [wMapNumber], a
ld a, [hli]
ld [wYCoord], a
ld a, [hli]
ld [wXCoord], a
ldh a, [hMapEntryMethod]
cp MAPSETUP_NEXTPLAYER
jr nz, .next
ld a, [hl]
ld [wCurSpace], a
.next
ld a, [wCurTurnPlayer]
ld hl, wPlayer1State
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
ld [wPlayerState], a
.spawn_n_a
pop de
pop hl
ret
IsSpawnPoint:
; Checks if the map loaded in de is a spawn point. Returns carry if it's a spawn point.
ld hl, SpawnPoints
ld c, 0
.loop
ld a, [hl]
cp SPAWN_N_A
jr z, .nope
cp d
jr nz, .next
inc hl
ld a, [hld]
cp e
jr z, .yes
.next
push bc
ld bc, 4 ; length of a spawn table entry
add hl, bc
pop bc
inc c
jr .loop
.nope
and a
ret
.yes
scf
ret
InitializeAllPlayersSpawnPoints:
; used by MAPSETUP_ENTERLEVEL
; wMapGroup...wXCoord have been initialized by EnterMapSpawnPoint.
; wCurSpace and wPlayerState have been initialized by StartMap.
ld a, [wNumLevelPlayers]
ld c, a
ld hl, wPlayer1Location
ld de, wPlayer1State
.next_player
ld a, [wMapGroup]
ld [hli], a ; wPlayer*MapGroup
ld a, [wMapNumber]
ld [hli], a ; wPlayer*MapNumber
ld a, [wYCoord]
ld [hli], a ; wPlayer*YCoord
ld a, [wXCoord]
ld [hli], a ; wPlayer*XCoord
ld a, [wCurSpace]
ld [hli], a ; wPlayer*CurSpace
ld a, [wPlayerState]
ld [de], a
inc de ; wPlayer*State
dec c
jr nz, .next_player
ret