Added damage calculation to attack.
Fixed a bug in act_sg that caused the previous slot to be re-read by the wrong map.
This was fixed by storign the previous frame's player map cursor. This allows us to use the previous frame
as a save location and the current value as a restore location.
unit_action_attack_damage_calc:
; TODO: do real damage calculation here
; for now just delete the actor
-
+
+ push de
call unit_attack_get_attack_tile
call unit_find_at
- ; set type to NULL
- ld de, act_type
- add hl, de
- ld a, ACT_T_NULL
- ld [hl], a
+ pop de
+ push hl
+ pop bc
+ ; de = attacker
+ ; bc = attacked unit
+ push hl
+ call stat_calc_physical_damage_vs
+ pop hl
ldnull bc
ret
floor_1_actor_table:
map_c_actor_table:
.db 7 ; size
-dw unit_demo_2
+dw unit_demo_warrior
dw unit_demo_warrior
dw unit_demo_warrior
dw unit_demo_mage
; loads current start of save game slot
; based on the current map seed index
+ ; inputs:
+ ; a: map cursor
; returns:
; bc: act save game slot
act_sg_load_current_slot:
- ld a, [player_map_cursor] ; a = seed index
-
ld hl, act_sg
; no need to loop if a is 0
cp a, 0
@done:
push hl
pop bc ; we want return value in bc
+ BREAK
ret
ld a, [map_header+1]
or a, b
ret z
+
+ ld a, [player_map_cursor_prev]
call act_sg_load_current_slot
ld hl, p0_units
inc bc
pop hl
+ ; store hp
+ push hl
+ ld de, act_hp
+ add hl, de
+
+ ld a, [hl]
+ ld [bc], a
+ inc bc
+ pop hl
+
+ ; sotre mp
+ push hl
+ ld de, act_mp
+ add hl, de
+
+ ld a, [hl]
+ ld [bc], a
+ inc bc
+ pop hl
+
; advance to next actor
ld de, act_size
add hl, de
; restores actor save game based on
; current map's seed offset
act_sg_restore:
+ ld a, [player_map_cursor]
call act_sg_load_current_slot
; skip over player
.rep i, act_sg_size, 1, inc bc
pop hl
+ ; load hp
+ push hl
+ ld de, act_hp
+ add hl, de
+
+ ld a, [bc]
+ ld [hl], a
+ inc bc
+
+ pop hl
+
+ ; load mp
+ push hl
+ ld de, act_mp
+ add hl, de
+
+ ld a, [bc]
+ ld [hl], a
+ inc bc
+ pop hl
+
ld de, act_size
add hl, de ; next actor
ret
.de act_sg_pos_y, 1
.de act_sg_pos_x, 1
.de act_sg_p0, 1
+.de act_sg_hp, 1
+.de act_sg_mana, 1
.de act_sg_size, 0
#define ACT_SG_DEFAULT_VALUE 0xFF
; a: damage
stat_calc_physical_damage_vs:
; actor 1
+ push bc
call stat_calc_weapon_damage
; a = damage
; weapon damage + strenth / 8
call stat_calc_str
- sla a ; / 2
- sla a ; / 4
- sla a ; / 8
+ sra a ; / 2
+ sra a ; / 4
+ sra a ; / 8
add a, b
ld b, a ; b = real damage
; actor 2
- push bc
pop de ; de = actor2 now
; damage - ac/2
call stat_calc_ac
- sla a
+ sra a
sub_ba
jp c, @no_damage
; write new hp
ld [hl], a
+
+ ; a = damage dealt
+ ld a, b
ret
@no_damage:
@dead:
xor a, a
ld [hl], a ; write 0 hp
+ ld a, b ; a = damage dealt
ret
; calculates the real speed state
#define UNIT_SCAN_RANGE_Y MAP_H/4
#define UNIT_SCAN_RANGE_X MAP_W/4
+
+ ; checks if the unit is dead
+ ; if so sets type to 0
+ ; inputs:
+ ; de: actor
+ ; returns:
+ ; z-flag if dead
+unit_cpu_check_dead:
+ ld hl, act_hp
+ add hl, de
+ ld a, [hl]
+ cp a, 0
+ ret nz ; not dead
+ push af
+
+ ld a, ACT_T_NULL
+ ld hl, act_type
+ add hl, de
+ ld [hl], a ; set type to NULL
+
+ pop af
+ ret
; handles cpu inputs
; chaser CPU script
; bc: next state
unit_handle_cpu_inputs:
#define MOVE_MADE scratch
+
+ ; check if dead
+ ; if so set type to 0
+ call unit_cpu_check_dead
+ ret z
; check if player has taken turn
; if not exit
ld de, objanim
call st_update
+ ld a, [player_map_cursor]
+ ld [player_map_cursor_prev], a
+
ldnull bc
ret
; go left: dec
; go right: inc
player_map_cursor: .adv 1
+ ; the previous frame's map cursor
+player_map_cursor_prev: .adv 1
; one byte per map
; indicating where doors should be placed