; 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
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
dw STR_LUMBER
; converts from UI cursor position
- ; to building type
+ ; to building state
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:
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:
game_mode: .adv st_size
+ ; cursor state
+cursor_state: .adv st_size
+
; actors
; actors are state machines
; they get updated once a frame
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