state: cursor states are now also simply using a state machine
authorLukas Krickl <lukas@krickl.dev>
Tue, 1 Apr 2025 11:13:00 +0000 (13:13 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 1 Apr 2025 11:13:00 +0000 (13:13 +0200)
src/buildings.s
src/state.s
src/ui.s
src/wram.s

index 518a8e17d3c176f1bcc6972b91949be38935fdfc..a8d365b14b249baea81550f87510f50799b0d7e8 100644 (file)
@@ -2,5 +2,22 @@
   ; performs pre-checks and displays an error 
   ; if pre-conditions for building fail
   ; e.g. not enough resources, not enough space
+  ; executes cursor_state state machine update
 building_build:
   ret
+
+build_warehouse:
+  ldnull bc
+  ret
+
+build_road:
+  ldnull bc
+  ret
+
+build_farm:
+  ldnull bc
+  ret
+
+build_lumber:
+  ldnull bc
+  ret
index 749f1d274ae0dd558ae3bf50bd714da3a455f2ad..5ead5ca8fdde8206fb6951ec82d6969ea3a53e92 100644 (file)
@@ -102,3 +102,13 @@ st_update_pause:
 st_update_game_over:
   st_def 0x00, update_game_over, st_update_game_over
 
+; building states 
+
+st_build_warehouse:
+  st_def 0x00, build_warehouse, st_null 
+st_build_road:
+  st_def 0x00, build_road, st_null 
+st_build_farm:
+  st_def 0x00, build_farm, st_null 
+st_build_lumber:
+  st_def 0x00, build_lumber, st_null 
index 90a72b0847de783990f095f7351b9fcfa523f22b..4c1e15d13c706c49432d64ef46516e80f4c25da4 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -23,13 +23,12 @@ ui_cursor_label_table:
   dw STR_LUMBER
 
   ; converts from UI cursor position
-  ; to building typ
+  ; to building stat
 ui_to_building_selecction_table:
-  .db BT_WAREHOUSE
-  .db BT_ROAD
-  .db BT_FARM
-  .db BT_LUMBER
-
+  dw st_build_warehouse
+  dw st_build_road
+  dw st_build_farm
+  dw st_build_lumber
 
   ; inits UI
 ui_init:
@@ -160,14 +159,23 @@ ui_building_selector_inputs:
   input_just BTNA
   jr z, @not_a REL
     
-    ; load building to be built into building selector 
+    ; load building to be built into building selector state 
     ld a, [ui_cursor_pos]
+    sla a ; * 2 to get ptr offset  
     ld d, 0
     ld e, a
+
     ld hl, ui_to_building_selecction_table
     add hl, de ; hl = correct value 
+    ld a, [hl+]
+    ld e, a
     ld a, [hl]
-    ld [cursor_selected_building], a 
+    ld d, a ; de = source of state ptr
+    
+    ld hl, cursor_state
+    ld bc, st_size
+    call memcpy
+
     ld bc, st_ui_buildung_selector_exit
     ret
 @not_a:
index cc254c2b13604d00e0fbc37e1adc5297480d64ad..e9f6fa9b819e5b41bba02c869c9fef3fee873696 100644 (file)
@@ -16,6 +16,9 @@ ui_cursor_pos: .adv 1
 
 game_mode: .adv st_size
 
+  ; cursor state
+cursor_state: .adv st_size
+
   ; actors 
   ; actors are state machines
   ; they get updated once a frame
@@ -37,9 +40,6 @@ cursor_x: .adv 1
 cursor_move_y: .adv 1
 cursor_move_x: .adv 1
 
-  ; enum of type BT_
-cursor_selected_building: .adv 1
-
   ; +/-1 for each time the cursor moves
   ; allows us to move scroll when needed 
 scroll_move_y: .adv 1