(#步弓AI
1, 0, 0, [],
[
(set_fixed_point_multiplier, 1000),
# (get_player_agent_no, ":agent_player"),
# (agent_get_team ,":team_player", ":agent_player"),
(try_for_agents, ":agent_no"),
(agent_is_alive, ":agent_no"),
(agent_is_human, ":agent_no"),
(agent_is_non_player, ":agent_no"),
# (agent_get_troop_id, ":troop", ":agent_no"),
# (troop_is_hero, ":troop"),
(neg|agent_slot_eq, ":agent_no", 1005, 1),#slot 1003,1代表非骑射,2代表是骑射,3代表是骑射不执行骑射ai的待命状态
(agent_get_horse, ":horse_no", ":agent_no"),
(assign, ":melee_weapon", -1),
(try_begin),
(agent_slot_eq, ":agent_no", slot_agent_is_running_away, 0),#非逃跑
(agent_get_team, ":team_no", ":agent_no"),
# (neg|teams_are_enemies, ":team_no", ":team_player"),
##判断是否为骑射↓
(lt, ":horse_no", 0),
(assign, ":thrown_ammo", 0),
(assign, ":ranged_weapon", -1),
(try_for_range, ":item", 0, 4),
(agent_get_item_slot, ":item_weapon", ":agent_no", ":item"),
(gt, ":item_weapon", 0),
(item_get_type, ":item_weapon_type", ":item_weapon"),
(try_begin),
(eq, ":item_weapon_type", itp_type_thrown),#获取投掷弹药
(agent_get_ammo_for_slot, ":ammo_for_slot", ":agent_no", ":item"),
(val_add, ":thrown_ammo", ":ammo_for_slot"),
(else_try),
(this_or_next|eq, ":item_weapon_type", itp_type_bow),
(this_or_next|eq, ":item_weapon_type", itp_type_crossbow),
(eq, ":item_weapon_type", itp_type_musket),
(assign, ":ranged_weapon", ":item_weapon"),
(else_try),
(this_or_next|eq, ":item_weapon_type", itp_type_one_handed_wpn),
(this_or_next|eq, ":item_weapon_type", itp_type_two_handed_wpn),
(eq, ":item_weapon_type", itp_type_polearm),
(assign, ":melee_weapon", ":item_weapon"),
(try_end),
(try_end),
(gt, ":ranged_weapon", -1),
##(neg|item_has_property, ":ranged_weapon", itp_cant_reload_on_horseback),
##(neg|item_has_property, ":ranged_weapon", itp_cant_use_on_horseback),
(agent_get_ammo, ":ammo", ":agent_no", 0),#除去投掷的弹药↓
(val_sub, ":ammo", ":thrown_ammo"),
(gt, ":ammo", 0),
(agent_set_slot, ":agent_no", 1005, 2),
##判断是否为骑射↑
(agent_get_division, ":class_no", ":agent_no"),#命令的处理↓
(team_get_weapon_usage_order, ":weapon_usage_order", ":team_no", ":class_no"),
(team_get_movement_order, ":movement_order", ":team_no", ":class_no"),
(team_get_hold_fire_order, ":hold_fire", ":team_no", ":class_no"),
(neg|eq, ":hold_fire", aordr_hold_your_fire),
(neg|eq, ":weapon_usage_order", wordr_use_melee_weapons),
(neg|eq, ":weapon_usage_order", wordr_use_blunt_weapons),
(eq, ":movement_order", mordr_charge),
#---------------筛出目标敌人↓-------------------------------------------------
(agent_get_position, pos1, ":agent_no"),
##(agent_get_speed, pos0, ":agent_no"),
##(position_get_y,":speed_y",pos0),
(assign, ":distance_closest", 15000),#150m
(assign, ":enemies_closest", -1),
(try_for_agents, ":enemies"),
(agent_is_alive, ":enemies"),
(agent_is_human, ":enemies"),
(agent_get_position, pos2, ":enemies"),
(agent_get_team, ":enemies_team", ":enemies"),
(teams_are_enemies, ":team_no", ":enemies_team"),
(get_distance_between_positions, ":distance", pos1, pos2),#获取距离(单位厘米)
(try_begin),#暂时忽视逃跑的敌人↓
(agent_slot_eq, ":enemies", slot_agent_is_running_away, 1),
(val_add, ":distance", 10000),
(try_end),
(lt, ":distance", ":distance_closest"),
(assign, ":distance_closest", ":distance"),
(assign, ":enemies_closest", ":enemies"),
(try_end),
#---------------筛出目标敌人↑-------------------------------------------------
(neq, ":enemies_closest", -1),
(agent_get_position, pos3, ":enemies_closest"),
(get_distance_between_positions, ":distance_true", pos1, pos3),
#----------------减速设置↓-----------------------------------------------------------
(try_begin),
(agent_get_wielded_item, ":weapon_hold", ":agent_no", 0),#获取右手武器
(gt, ":weapon_hold", 0),
(item_get_type, ":weapon_type", ":weapon_hold"),
## (this_or_next|eq, ":weapon_type", itp_type_bow),
## (this_or_next|eq, ":weapon_type", itp_type_crossbow),
##(eq, ":weapon_type", itp_type_musket),
## (agent_get_bone_position, pos4, ":agent_no", 9, 1),
## (agent_get_bone_position, pos5, ":enemies_closest", 9, 1),
##(position_has_line_of_sight_to_position, pos4, pos5),
# # (agent_set_look_target_agent, ":agent_no", ":enemies_closest"),
#让弓骑更积极地射击↓
#让弓骑更积极地射击↑
(try_end),
#----------------减速设置↑-----------------------------------------------------------
#----------------绕圈的计算↓---------------------------------------------------------
(try_begin),
(agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),
(lt, ":distance_closest", 10000),
##(agent_set_slot, ":agent_no", 1005, 4),#new
(try_begin),
#计算到边界距离↓
(get_scene_boundaries, pos6, pos7),#左下角和右上角的点,方向朝上
(position_transform_position_to_local, pos0, pos6,pos1),
(position_get_x, ":left", pos0),
(position_get_y, ":down", pos0),
(position_transform_position_to_local, pos0, pos6,pos7),
(position_get_x, ":map_width", pos0),
(position_get_y, ":map_height", pos0),
(store_sub, ":right", ":map_width", ":left"),
(store_sub, ":up", ":map_height", ":down"),
#计算到边界距离↑
(position_transform_position_to_local, pos0, pos1, pos3),
(position_get_x, ":enemies_x", pos0),
(position_get_y, ":enemies_y", pos0),
(assign, ":effect", 0),
(assign, ":boundary", 1500),
(try_begin),#小于25m时后退
(neg|gt, ":distance_closest",2500),
(assign, ":effect", -78),
(else_try),#大于90m时靠近
(gt, ":distance_closest", 9000),
(position_transform_position_to_local, pos0, pos6,pos3),
(position_get_x, ":left_enemy", pos0),
(position_get_y, ":down_enemy", pos0),
(store_sub, ":right_enemy", ":map_width", ":left_enemy"),
(store_sub, ":up_enemy", ":map_height", ":down_enemy"),
(assign, ":distance_to_boundary", ":boundary"),#判断离地图边界最近是否在15m内
(val_min, ":distance_to_boundary", ":left_enemy"),
(val_min, ":distance_to_boundary", ":up_enemy"),
(val_min, ":distance_to_boundary", ":right_enemy"),
(val_min, ":distance_to_boundary", ":down_enemy"),
(try_begin),
(lt, ":distance_to_boundary", ":boundary"),
(assign, ":effect", 90),
(else_try),
(assign, ":effect", 45),#45°向心运动
(try_end),
(try_end),
(convert_to_fixed_point, ":effect"),
#靠近地图边界时的计算↓
(assign, ":distance_to_boundary", ":boundary"),#判断离地图边界最近是否在15m内
(val_min, ":distance_to_boundary", ":left"),
(val_min, ":distance_to_boundary", ":up"),
(val_min, ":distance_to_boundary", ":right"),
(val_min, ":distance_to_boundary", ":down"),
(try_begin),
(lt, ":distance_closest", 1000),
(lt, ":distance_to_boundary", ":boundary"),
(agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),#敌人非逃跑
#计算地图中点↓
(store_div, ":map_middle_x", ":map_width", 20),
(store_div, ":map_middle_y", ":map_height", 20),
(position_copy_origin, pos10, pos6),
(position_move_x, pos10, ":map_middle_x", 1),#中点#单位厘米
(position_move_y, pos10, ":map_middle_y", 1),#中点
(get_distance_between_positions,":distance_middle", pos10, pos1),
(position_transform_position_to_local, pos0, pos1, pos10),
(position_get_x, ":map_middle_x", pos0),
(position_get_y, ":map_middle_y", pos0),
#计算地图中点↑
#算出偏转多少度是朝着地图中点移动↓
(val_mul, ":map_middle_x", 100),
(val_mul, ":map_middle_y", 100),
(val_mul, ":enemies_x", 100),
(val_mul, ":enemies_y", 100),
(store_div,":cos_middle",":map_middle_x",":distance_middle"),
(store_div,":sin_middle",":map_middle_y",":distance_middle"),
(store_div,":cos_enemies",":enemies_x",":distance_true"),
(store_div,":sin_enemies",":enemies_y",":distance_true"),
(store_acos, ":angle_cos", ":cos_middle"),
(store_asin, ":angle_sin", ":sin_middle"),
(store_acos, ":angle_cos_enemies", ":cos_enemies"),
(store_asin, ":angle_sin_enemies", ":sin_enemies"),
(try_begin),
(lt, ":angle_sin", 0),
(val_mul,":angle_cos", -1),
(val_add,":angle_cos", 360000),
(try_end),
(try_begin),
(lt, ":angle_sin_enemies", 0),
(val_mul,":angle_cos_enemies", -1),
(val_add,":angle_cos_enemies", 360000),
(try_end),
(store_sub, ":k2", ":angle_cos", ":angle_cos_enemies"),
(val_sub, ":k2", 270000),
(val_sub, ":k2", ":effect"),
(store_add, ":effect", ":k2", ":effect"),
(try_begin),
(lt, ":angle_cos", ":angle_cos_enemies"),
(val_add, ":effect", 360000),
(try_end),
#这里算出偏转多少度是朝着地图中点移动↑
(val_clamp,":effect",-210000, 15000),#这里偏转角做个限制,防止向地图中点向心移动时拿弓撞人
##(agent_set_attack_action, ":agent_no", -2, 1),
##(agent_set_defend_action, ":agent_no", 3, 1),#取消射击
(try_end),
#靠近地图边界时的计算↑
#位置的计算,默认绕敌人切线逆时针移动,effect是偏转角,为正则向心,为负则离心↓
(try_begin,),#对手枪处理,其向右射
(eq, ":weapon_type", itp_type_pistol),
(val_mul, ":effect", -1),
(val_add, ":effect", 180000),
(try_end),
(store_cos, ":cos", ":effect"),#这段是极坐标方程 x=ρcos(θ-90+effect) 和y=ρsin(θ-90+effect)的计算
(store_sin, ":sin", ":effect"),
(store_mul, ":k_x1", ":cos", ":enemies_y",),
(store_mul, ":k_x2", ":sin", ":enemies_x",),
(store_mul, ":k_y1", ":sin", ":enemies_y",),
(store_mul, ":k_y2", ":cos", ":enemies_x",),
(store_add, ":move_x",":k_x1", ":k_x2"),
(store_sub, ":move_y",":k_y1", ":k_y2"),
(store_random_in_range, ":random", -1000, 1000),
(val_max, ":move_y", 1000),#new
(val_min, ":move_y", -1000),#new
(position_move_x, pos1,":random", 0),#厘米
(position_move_y, pos1, ":move_y", 0),#厘米
#位置的计算,默认绕敌人切线逆时针移动,effect是偏转角,为正则向心,为负则离心↑
(try_end),
(agent_set_scripted_destination, ":agent_no", pos1, 1),
(else_try),
(agent_clear_scripted_mode, ":agent_no"),
##(agent_force_rethink, ":agent_no"),
(try_end),
(try_begin),#武器切换的处理
(agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),
(gt,":distance_true",500),
(agent_set_wielded_item, ":agent_no", ":ranged_weapon"),
(else_try),
(le, ":distance_true", 500),
(agent_get_speed, pos50, ":enemies_closest"), #获取马速
(position_get_y,":speedmul", pos50),
(convert_from_fixed_point, ":speedmul"),
##(agent_get_horse, ":enemies_horse", ":enemies_closest"),
##(gt, ":enemies_horse", -1),
(le,":speedmul",4),
(gt, ":melee_weapon", -1),
(agent_set_wielded_item, ":agent_no", ":melee_weapon"),
##(agent_set_attack_action, ":agent_no", -2, 1),
(agent_set_scripted_destination, ":agent_no", pos3, 1),
(try_end),
#-----------------绕圈的计算↑---------------------------------------------------------
(else_try),
(try_begin),
(agent_slot_eq, ":agent_no", 1005, 0),
(agent_set_slot, ":agent_no", 1005, 1),
(else_try),
(agent_slot_eq, ":agent_no", 1005, 2),
(this_or_next|agent_slot_eq, ":agent_no", slot_agent_is_running_away, 1),
##(this_or_next|lt, ":horse_no", 0),
## (this_or_next|eq, ":ammo", 0),
(this_or_next|eq, ":hold_fire", aordr_hold_your_fire),
##(this_or_next|eq, ":weapon_usage_order", wordr_use_melee_weapons),
## (this_or_next|eq, ":weapon_usage_order", wordr_use_blunt_weapons),
(this_or_next|eq, ":enemies_closest", -1),
(neq, ":movement_order", mordr_charge),
(neq, ":ammo", 0),#new
(agent_clear_scripted_mode, ":agent_no"),
(agent_set_speed_limit, ":agent_no", 100),
##(agent_force_rethink, ":agent_no"),
(agent_set_attack_action, ":agent_no", -2, 1),
(agent_set_slot, ":agent_no", 1005, 3),#设为待命状态
(this_or_next|eq, ":hold_fire", aordr_hold_your_fire),
(eq, ":ammo", 0),
(gt, ":melee_weapon", -1),
(agent_set_wielded_item, ":agent_no", ":melee_weapon"),
(else_try),#new
(agent_slot_eq, ":agent_no", 1005, 2),
(this_or_next|eq, ":weapon_usage_order", wordr_use_melee_weapons),
(this_or_next|eq, ":weapon_usage_order", wordr_use_blunt_weapons),
(eq, ":ammo", 0),
(agent_clear_scripted_mode, ":agent_no"),
(agent_set_speed_limit, ":agent_no", 100),
(agent_force_rethink, ":agent_no"),
(agent_set_attack_action, ":agent_no", -2, 1),
(agent_set_slot, ":agent_no", 1005, 3),#设为待命状态
(this_or_next|eq, ":hold_fire", aordr_hold_your_fire),
(eq, ":ammo", 0),
(gt, ":melee_weapon", -1),
(agent_set_wielded_item, ":agent_no", ":melee_weapon"),
(try_end),
(try_end),
(try_end),
]),
|