common_AI_fight2 = ( #find hero va enemy
0.0, 0, 0, [], [
(assign, ":count1", 0),
# (try_begin), # This is is NOT necessary
(try_for_agents, ":agent_temp"),
(agent_is_human, ":agent_temp"),
(try_begin),
(agent_is_alive, ":agent_temp"),
(agent_has_item_equipped, ":agent_temp", "itm_glaive"), # hero is the man who have this item.
(assign, "$agent_hero", ":agent_temp"), # $agent_hero is a global variable
(else_try),
(agent_is_alive, "$agent_hero"),
(assign, "$agent_enemy", ":agent_temp"), #$agent_enemy is a global variable
(agent_get_position, pos12, "$agent_enemy"),
(agent_get_position, pos11, "$agent_hero"),
(get_sq_distance_between_positions, ":sq_dist", pos11, pos12),
# (get_distance_between_positions, reg17, pos11, pos12), # This is unused
(try_begin),
(agent_is_alive, "$agent_enemy"),
(le, ":sq_dist", 6400), # Square in cm2
(store_add, ":count1", ":count1", 1),
# (assign, reg11, ":count1"), # These two are not used as well
(assign, "$enemy_count1", ":count1"), #$enemy_count1 is number of enemy
(assign, "$agent_enemy1", "$agent_enemy"), #$agent_enemy1 is the enemy inside Square range.
(else_try),
(agent_is_alive, "$agent_enemy"),
(gt, ":sq_dist", 6400),
(store_add, ":count1", ":count1", 0),
# (assign, reg11, ":count1"),
(assign, "$enemy_count1", ":count1"),
(try_end),
(try_end),
(try_end),
])
common_AI_fight3 = ( #Display number of enemy in range of Square
0.2, 0.1, 0, [],[
(try_begin),
(agent_is_alive, "$agent_hero"),
# (assign, reg12, "$enemy_count1"), #reg12 is number of enemy in range of Square
# ^ Why would you do that? Makes no sense
(val_add, reg16, 0),
(try_begin),
(neg|eq, "$enemy_count1", reg16),
(try_begin),
(eq, "$enemy_count1", "$enemy_count_check"),
(assign, reg12, "$enemy_count1"), # Allowed for debugging purposes only
(display_message, "@DEBUG: There are {reg12} enemies in Square's range"),
(assign, reg16, "$enemy_count1"),
(else_try),
(neg|eq, "$enemy_count1", "$enemy_count_check"),
(assign, "$enemy_count1", "$enemy_count_check"),
(assign, reg12, "$enemy_count1"), # Once again, for debugging only
(display_message, "@DEBUG: There are {reg12} enemies in Square's range"), # What "Square"?
(try_end),
(try_end),
(try_end),
])
common_AI_fight4 = ( #check number of enemy in Square to compare with common_AI_fight3
0.1, 0.0, 0, [], [
(try_begin),
(agent_is_alive, "$agent_hero"),
(assign, "$enemy_count_check", "$enemy_count1"), # check number of enemy every 0,1s
(try_end),
])
common_AI_fight5 = ( #check number enemies in Square's range to decided how to move
0.3, 0.0, 0, [], [
(try_begin),#1
(eq, reg12, 0), #number of enemy in S range is 0
(display_message, "@There is no enemy in range"),
(else_try),
(eq, reg12, 1), #number of enemy in S range is 1
(agent_is_alive, "$agent_hero"),
(agent_is_alive, "$agent_enemy1"),
(agent_get_position, pos21, "$agent_hero"),
(agent_get_position, pos22, "$agent_enemy1"),
(get_distance_between_positions, reg21, pos21, pos22), #reg21 is the distance between hero and the only 1 enemy in S range
(try_begin),
(le, reg21, 300),
(try_begin),
(agent_get_attack_action, ":atk_action_enemy", "$agent_enemy1"),
(try_begin),
(eq, ":atk_action_enemy", 0),
(agent_set_attack_action, "$agent_hero", 1, 0),
(else_try),
(is_between, ":atk_action_enemy", 1, 4),
(agent_get_action_dir, ":action_dir", "$agent_enemy1"),
(try_begin),
(eq, ":action_dir", 0),
(agent_set_animation, "$agent_hero", "anim_runbackward_left"),
(else_try),
(eq, ":action_dir", 1),
(agent_set_animation, "$agent_hero", "anim_runbackward_right"),
(else_try),
(eq, ":action_dir", 2),
(agent_set_animation, "$agent_hero", "anim_runbackward_left"),
(else_try),
(eq, ":action_dir", 3),
(agent_set_animation, "$agent_hero", "anim_runbackward_right"),
(try_end),#1.4
(else_try),
(eq, ":atk_action_enemy", 4),
(agent_set_attack_action, "$agent_hero", 2, 0),
(else_try),
(eq, ":atk_action_enemy", 6),
(agent_set_attack_action, "$agent_hero", 3, 0),
(try_end),
(try_end),
(else_try),
(is_between, reg21, 301, 600),
(agent_set_attack_action, "$agent_hero", 0, 0),
(agent_set_animation, "$agent_hero", "anim_run_forward"),
(try_end),
(else_try),
(le, reg12, 3), # If number of enemies is little than 4
(store_random_in_range, ":rand", 1, 10), # hero do random move to avoid enemy's attack
(try_begin),
(le, ":rand", 4),
(agent_set_animation, "$agent_hero", "anim_runbackward_left"),
(else_try),
(le, ":rand", 8),
(agent_set_animation, "$agent_hero", "anim_runbackward_right"),
(else_try),
(eq, ":rand", 9),
(agent_set_animation, "$agent_hero", "anim_runbackward"),
(try_end),
(else_try),
(gt, reg12, 3), # If number of enemies is greater than 3
(store_random_in_range, ":rand", 1, 11),
(try_begin),
(eq, ":rand", 1),
(agent_set_animation, "$agent_hero", "anim_runbackward_left"),
(else_try),
(le, ":rand", 4),
(agent_set_animation, "$agent_hero", "anim_runbackward_right"),
(else_try),
(gt, ":rand", 4),
(agent_set_animation, "$agent_hero", "anim_runbackward"),
(try_end),
(try_end),
])
common_AI_fight6 = ( #decided how to block or attack.
0.0, 0.0, 0, [], [
(le, reg21, 350),
(try_begin),
(agent_get_attack_action, ":atk_action_enemy", "$agent_enemy1"),
(agent_get_attack_action, ":atk_action_hero", "$agent_hero"),
(try_begin),
(eq, ":atk_action_enemy", 2),
(le, ":atk_action_hero", 1),
(agent_get_action_dir, ":action_dir", "$agent_enemy1"),
(try_begin),
(eq, ":action_dir", 0),
(agent_set_defend_action, "$agent_hero", 0, 20),
(else_try),
(eq, ":action_dir", 1),
(agent_set_defend_action, "$agent_hero", 1, 20),
(else_try),
(eq, ":action_dir", 2),
(agent_set_defend_action, "$agent_hero", 2, 20),
(else_try),
(eq, ":action_dir", 3),
(agent_set_defend_action, "$agent_hero", 3, 20),
(try_end),
(else_try),
(eq, ":atk_action_enemy", 4),
(agent_set_attack_action, "$agent_hero", 2, 0),
(else_try),
(eq, ":atk_action_enemy", 6),
(agent_set_attack_action, "$agent_hero", 3, 0),
(try_end),
(try_end),
])