tiles: tiles now have an owner id
authorLukas Krickl <lukas@krickl.dev>
Tue, 4 Nov 2025 04:39:47 +0000 (05:39 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 4 Nov 2025 04:39:47 +0000 (05:39 +0100)
Reworked tile types to take tile owner into account
Reworked UI to take tile owner into account

src/defs.s
src/levels.s
src/macros.inc
src/tiles.s
src/ui.s
src/wram.s

index d9ff0c4f35321af27524871ed8272d3a3f1d80d0..59504d78e847fc55975a63b7975ba87fafc2b662 100644 (file)
 .de map_tiles, MAP_W * MAP_H
 .de map_size, 0
 
-       ; tile type struct
+       ; tile type enum
 .se 0
 .de TT_EMPTY, 1
-.de TT_PLAYER, 1
-.de TT_PLAYER_HIVE, 1
-.de TT_ENEMY, 1
-.de TT_ENEMY_HIVE, 1
+.de TT_USED, 1
+.de TT_HIVE, 1
 .de TT_FOOD, 1
 
+       ; tile index enum
+       ; order of tile defs in tiles.s
+.se 0
+.de TI_EMPTY, 1
+.de TI_PLAYER_USED, 1
+.de TI_PLAYER_HIVE, 1
+.de TI_ENEMY_USED, 1
+.de TI_ENEMY_HIVE, 1
+.de TI_FOOD, 1
+
+       ; owner enum
+.se 0
+.de TO_NULL, 1
+.de TO_PLAYER, 1
+.de TO_ENEMY, 1
+
        ; tile struct
 .se 0 
 .de t_type, 1
 .de t_flags, 1
+       ; owning actor
+.de t_owner, 1
        ; based on type
 .de t_resource, 1
        ; 2 bytes of custom state storage
index cd8bb8ddd99f05df05828ea66331ab0235bf97dc..4605f21cb7f9d589a5c2ff70acbe328003e884ed 100644 (file)
@@ -6,16 +6,16 @@ level_def_to_tile:
        dw tile_food
        
        ; tile grass
-.def int TGS = TT_EMPTY
+.def int TGS = TI_EMPTY
 
        ; tile player hive
-.def int TPH = TT_PLAYER_HIVE
+.def int TPH = TI_PLAYER_HIVE
 
        ; tile enemy hive
-.def int TEH = TT_ENEMY_HIVE
+.def int TEH = TI_ENEMY_HIVE
 
        ; tile food
-.def int TFD = TT_FOOD
+.def int TFD = TI_FOOD
 
        ; level definitions
        ; levels always have a header
index 0961802a2737113d7e2388cd9c855483b8a1a49e..8ed25f17a8bc90f3a791d39c8d2d3f82196b081f 100644 (file)
@@ -171,13 +171,14 @@ $1:
        ; inputs:
        ;               $1: type
        ;               $2: flags
-       ;               $3: resource count
-       ;               $4: tile gfx
+       ;               $3: tile owner
+       ;               $4: resource count
+       ;               $5: tile gfx
 #macro tiledef
-       .db $1, $2, $3
+       .db $1, $2, $3, $4
        ; p0 and state
        .db 0, 0 
-       .db $4
+       .db $5
 #endmacro
        
        ; defines a new actor
index 63b7d9ff7166db257f9b0cb9f76b75ad39ad1410..b87ac05384cbe423ccf6071777daeb3925c91440 100644 (file)
@@ -16,58 +16,47 @@ tile_update:
        ; for each tile
 tile_update_table:
        dw tile_update_empty
-       dw tile_update_player
-       dw tile_update_player_hive
-       dw tile_update_enemy
-       dw tile_update_enemy_hive
+       dw tile_update_used
+       dw tile_update_hive
        dw tile_update_food
 
 strz str_empty, "EMPTY    "
-strz str_player_hive, "YOUR HIVE    "
-strz str_enemy_hive, "HIVE     "
-strz str_player, "PLAYER    "
-strz str_enemy, "ENEMY    "
+strz str_hive, "HIVE    "
+strz str_used, "HILL    "
 strz str_food, "FOOD    "
 
        ; mapping of tile ids to 
        ; the tile names
 tile_str_table:
        dw str_empty
-       dw str_player
-       dw str_player_hive
-       dw str_enemy
-       dw str_enemy_hive
+       dw str_used
+       dw str_hive
        dw str_food
        
-
-       ; updates empty tile
+       ; gets the controlling actor of a tile
+       ; returns NULL if TO_NULL is set
        ; inputs:
        ;               de: tile
-tile_update_empty:
+tile_get_actor:
+       ; TODO:
        ret
-       
-       ; updates player controlled tile
-       ; inputs:
-       ;               de: tile
-tile_update_player:
-       ret
-       
-       ; updates player hive
+
+       ; updates empty tile
        ; inputs:
        ;               de: tile
-tile_update_player_hive:
+tile_update_empty:
        ret
        
-       ; updates enemy tile
+       ; updates controlled tile
        ; inputs:
        ;               de: tile
-tile_update_enemy:
+tile_update_used:
        ret
        
-       ; updates enemy hive
+       ; updates hive
        ; inputs:
        ;               de: tile
-tile_update_enemy_hive:
+tile_update_hive:
        ret
        
        ; updates food tile
@@ -77,7 +66,7 @@ tile_update_food:
        ret
        
        ; maps from tile ids 
-       ; to tile presets
+       ; to tile presets (tile index)
 tile_id_table:
        dw tile_grass
        dw tile_grass 
@@ -88,13 +77,13 @@ tile_id_table:
 
 
 tile_grass:
-       tiledef TT_EMPTY, 0, 0, GFX_GRASS
+       tiledef TT_EMPTY, 0, TO_NULL, 0, GFX_GRASS
 
 tile_player_hive:
-       tiledef TT_PLAYER_HIVE, 0, 0, GFX_PHIVE
+       tiledef TT_HIVE, 0, TO_PLAYER, 0, GFX_PHIVE
 
 tile_enemy_hive:
-       tiledef TT_ENEMY_HIVE, 0, 0, GFX_EHIVE
+       tiledef TT_HIVE, 0, TO_ENEMY, 0, GFX_EHIVE
 
 tile_food:
-       tiledef TT_FOOD, 0, 0, GFX_FOOD
+       tiledef TT_FOOD, 0, 0, TO_NULL, GFX_FOOD
index e6cd8b6b64a6473ad707ac40e3c81a9a1cbc6a15..f703abd32dbe613ed5e41fc89c47297d0d2ad15e 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -80,6 +80,8 @@ ui_draw_tile_name:
        ld a, [current_tile+1]
        ld l, a
 
+       push hl
+
        ld a, [hl] ; load type
        add a, a ; * 2 for offset
 
@@ -95,12 +97,38 @@ ui_draw_tile_name:
        ld a, b
        ld l, a
 
-       ld de, UI_TILE_NAME 
+       ld de, UI_TILE_NAME+2 
        call puts
 
        ld hl, ui_draw_nop
        call ui_request_draw
+       
+       ; draw owner
+       pop hl
+       ld de, t_owner
+       add hl, de
+       
+       ld a, [hl]
+       cp a, TO_NULL
+       jr nz, @not_null REL
+       
+       ld a, 0xF4 ; ' '
+       ld [UI_TILE_NAME], a
        ret
+@not_null:
+
+       cp a, TO_PLAYER
+       jr nz, @not_player REL
+       ld a, 0xE9 ; P 
+       ld [UI_TILE_NAME], a
+       ret
+@not_player:
+
+       ld a, 0xDE ; E
+       ld [UI_TILE_NAME], a
+       ret
+
+
 
        ; draws the entire UI
        ; only call during blank
index dda07201f4c2ad6601c18cb290cd8826c40cdf1c..9222cf90c0eb0f101865dd5763d264bb3afbc3ea 100644 (file)
@@ -78,6 +78,7 @@ map: .adv 2
        ; ptr to current tile to be updated
 tile_curr: .adv 2
 tiles: .adv t_size * MAP_TILES
+tiles_end: .adv 0
 
 
 ui_draw_routine: .adv 2