ld hl, act_sg
; no need to loop if a is 0
cp a, 0
- ret z
+ jr z, @done REL
ld de, act_sg_size * UNITS_MAX
; add sg size for every index offset
add hl, de
dec a
jr z, @loop REL
-
+@done:
push hl
pop bc ; we want return value in bc
ld a, [map_header+1]
or a, b
ret z
-
call act_sg_load_current_slot
+ ld hl, p0_units
+.rep i, UNITS_MAX, 1, call act_sg_store_single
+
ret
; stores data from a single actor into
; inputs:
; bc: act save game slot
; hl: actor
+ ; returns:
+ ; hl: next actor
+ ; bc: next slot
act_sg_store_single:
+ push hl
+ ; store flags
+ ld de, act_flags
+ add hl, de
+ ld a, [hl]
+ ld [bc], a
+ inc bc
+ pop hl
+
+ push hl
+
+ ; store y pos
+ ld de, act_pos_y
+ add hl, de
+ ld a, [hl+]
+ ld [bc], a
+ inc bc
+
+ ; store x pos
+ ld a, [hl]
+ ld [bc], a
+ inc bc
+
+ pop hl
+
+ ; store p0
+ push hl
+ ld de, act_p0
+ add hl, de
+ ld a, [hl]
+ ld [bc], a
+ inc bc
+ pop hl
+
+ ; advance to next actor
+ ld de, act_size
+ add hl, de
+
ret
; restores actor save game based on
; current map's seed offset
act_sg_restore:
call act_sg_load_current_slot
+ ; skip over player
+.rep i, act_sg_size, 1, inc bc
+ ld hl, p0_units+act_size
+.rep i, UNITS_MAX-1, 1, call act_sg_restore_single
+ ret
+
+ ; restores a single entry of actor data
+ ; skips restore if pos y is 0xFF
+ ; inputs:
+ ; bc: act save game slot
+ ; hl: actor
+ ; returns:
+ ; hl: next actor
+ ; bc: next slot
+act_sg_restore_single:
+ inc bc ; bc = position y
+ ld a, [bc]
+ dec bc
+ cp a, 0xFF
+ jp z, @skip ; skip if 0xFF
+
+ push hl
+ ; load flags
+ ld de, act_flags
+ add hl, de
+ ld a, [bc]
+ ld [hl], a
+ inc bc
+ pop hl
+
+ push hl
+ ; load positions
+ ld de, act_pos_y
+ add hl, de
+ ld a, [bc]
+ ld [hl+], a
+ inc bc
+
+ ld a, [bc]
+ ld [hl], a
+ inc bc
+
+ pop hl
+
+ push hl
+ ; load p0
+ ld de, act_p0
+ add hl, de
+
+ ld a, [bc]
+ ld [hl], a
+ inc bc
+
+ pop hl
+
+ ld de, act_size
+ add hl, de ; next actor
+ ret
+
+@skip:
+ ; move to next item and ret
+.rep i, act_sg_size, 1, inc bc
+ ld de, act_size
+ add hl, de
ret