st_def 0x00, unit_player_init, st_unit_idle
act_def ACT_T_DEMO_1, 0, 2, 2, 0
act_stat_def1 1, 1, 1, 1, 1
- act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1
+ act_stat_def2 1, 1, 1, 1, 1, 1, 1, 48
act_skill_def_empty
act_inventory_empty
act_equipment_empty
ret
#undefine scratch_loop_i
-#define TMP_MOVEMENT_SPEED scratch
; calculates movement speed based un the current unit
; inputs:
; de: unit
; returns:
- ; movement speed in sub-tiles in TMP_UNIT_MOVEMENT_SPEED
+ ; a: movement speed
unit_calc_movement_speed:
call stat_calc_speed
- ; movement speed is simply speed / 16
- div16 a
- cp a, 0
- jr nz, @not_zero_speed REL
- inc a
-@not_zero_speed:
- ld [TMP_MOVEMENT_SPEED], a
+ sla a ; * 2
ret
; performs a sub tile move
; inputs:
; de: actor
- ; $1: swap a/nop
- ; $2: add/sub
- ; $3: mask to apply to move speed (0xF0 or 0x0F)
- ; returns if sub-tile movement does not
- ; cause an over/underflow
+ ; hl: y/x position ptr
+ ; $1: subtile_y/x
+ ; $2: add/sub for sub tile calculation
+ ; $3: adc/sbc for tile calculation
+ ; carry bit is set if subtile position has a carry
; preserves:
; hl
#macro unit_sub_tile_move
push de
call unit_calc_movement_speed
+ ; a = movement speed
pop de
- ld hl, act_rt_subtile_pos
- add hl, de ; hl = subtile pos
-
- ld a, [TMP_MOVEMENT_SPEED]
ld b, a ; b = movement speed
- ld a, [hl]
- $1 ; swap
- and a, 0x0F ; mask bits we don't need
- $2 a, b ; sub/add
- ; test if overflow
- ld c, a ; need value again in a bit
- and a, 0xF0
- ; z flag is set if no overflow
- push af ; push flag on to stack for now
-
- ld a, c ; now cut off value
- and a, 0x0F ; mask it out in case of overflow
-
- $1 ; swap back
- ld b, a ; b = new position
- ld a, [hl] ; load value again
- and a, $3 ; mask off
- or a, b
- ld [hl], a ; store new value
-
- ; if we did not over/underflow
- ; exit now
- pop af ; get back flag result
+ ld hl, $1
+ add hl, de ; hl = subtile pos
+
+ ld a, [hl] ; load position
+ $2 a, b ; add or sub position
+ ld [hl], a ; store new sub-tile position
+
pop hl
- ret nz
+ ; now apply carry to real position
+ ld a, [hl]
+ sbc a, 0
+ ld [hl], a
#endmacro
; moves a unit up
pop de
ret z
- unit_sub_tile_move swap a, sub, 0xF0
-
- ld a, [hl]
- dec a
- ld [hl], a
-
+ unit_sub_tile_move act_rt_subtile_y, sub, sbc
ret
ld [hl], a
ret
-#undefine TMP_MOVEMENT_SPEED
; centers the current scroll on the selected unit
; snaps to corners of the map
st_def 0x00, unit_demo_1_init, st_unit_idle
act_def ACT_T_DEMO_1, 0, 3, 3, 0
act_stat_def1 1, 1, 1, 1, 1
- act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1
+ act_stat_def2 1, 1, 1, 1, 1, 1, 1, 32
act_skill_def_empty
act_inventory_empty
act_equipment_empty
st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update
act_def ACT_T_DEMO_1, 0, 4, 4, 0
act_stat_def1 1, 1, 1, 1, 1
- act_stat_def2 1, 1, 1, 1, 1, 1, 1, 1
+ act_stat_def2 1, 1, 1, 1, 1, 1, 1, 32
act_skill_def_empty
act_inventory_empty
act_equipment_empty