mapgen: Added stub for placing random actors on a new map
authorLukas Krickl <lukas@krickl.dev>
Thu, 31 Jul 2025 19:49:43 +0000 (21:49 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 31 Jul 2025 19:49:43 +0000 (21:49 +0200)
src/map.s
src/mapgen.s
src/wram.s

index cf9de486f31f540a9f9687ffd5d838cd950ed1fa..ebd1d7b898d6028ad86ae1caa8b1288ec5d68a74 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -11,6 +11,12 @@ map_init:
   ; TODO: do not touch lcd or interrupts if 
   ; they were not enabled!
 map_load:
+       ; backup the map header
+       ld a, l
+       ld [map_header], a
+       ld a, h
+       ld [map_header+1], a
+
   ; disable interruts
   ; wait for next blank
   ; disable lcd
index 3e138fdb0de52b7fc7edb13ffcfbe4354ecc35a0..dfb75604137a97b1ba6d39d08113b2b1a4bca7b8 100644 (file)
@@ -29,6 +29,7 @@ mapgen_seed:
   ;   hl: writable decompressed tile array (e.g [map]) 
   ;       of size MAP_H * MAP_W
   ;   de: the seed used
+       ;       map_header: the current map header
   ; returns:
   ;   a == 0: room was unable to be placed
   ;   a == 1: room was placed
@@ -60,6 +61,8 @@ mapgen:
 
   call mapgen_place_special_room
 
+       call mapgen_place_actors
+
 
   ; restore seed
   pop bc
@@ -389,3 +392,18 @@ mapgen_fix_door_adjacent_to_collider:
        mapgen_fix_door_fixup c_size, RPRW      
 
        ret
+
+       ; places actors from a valid actor table
+       ; in the current map's header. This will overwrite the 
+       ; header loaded by map_load. Preserves player entry.
+       ; inputs:
+       ;               a loaded map
+       ;               [map_header] ptr
+mapgen_place_actors:
+       ; load map ptr
+       ld a, [map_header]
+       ld l, a
+       ld a, [map_header+1]
+       ld h, a
+
+       ret
index 795d53f58300041e9c6f519174ab833902d56e15..b0a88b077a9ddcda4f4241649f8fabb9c2090e57 100644 (file)
@@ -159,5 +159,7 @@ map_end:
 map_st: .adv st_size
   ; current exit table ptr
 map_exit_table: .adv 2
+       ; ptr to the last map header used
+map_header: .adv 2
 
 state_end: