本帖最后由 ssy_aaa 于 2024-6-25 16:43 编辑
通过对战团打君悦大佬的AI补丁,我发现有点超标了,只要是骑马的弓箭手,都很厉害,比如50个诺德皇家侍卫可能被50个不带标枪,全带弓箭的响马杀了,所以对骑射AI做了一些削弱,原版骑射AI的核心是速度,将速度限制住之后,射手在马上就射的准了,所以我给速度加了一个罚函数,这个罚函数和兵种的骑射等级有关,骑射等级越高,对速度的影响越小,也就射的越准,对于游戏里面的最高骑射兵种库吉特资深骑射手的测试发现,不会出现骑射手对步兵刷屏的现象了。
- ## CC 骑射AI
- (0.5, 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", 1003, 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"),
- ##判断是否为骑射↓
- (gt, ":horse_no", -1),
- (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_pistol),
- (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", 1003, 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", 100000),#1000m
- (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),
- (try_begin),#算出骑兵相对你的横向速度↓
- (agent_get_horse, ":enemies_horse", ":enemies"),
- (gt, ":enemies_horse", -1),
- (agent_get_speed, pos0, ":enemies"),#马速一般6-10,人一般0-4,输出时会乘以fixed_point_multiplier值再输出
- (position_get_y,":speed_enemies",pos0),
- (store_sub, ":speed_1", ":speed_enemies", ":speed_y"),
- (position_transform_position_to_local, pos0, pos1, pos2),
- (position_get_rotation_around_z, ":angle_1", pos0),
- (convert_to_fixed_point, ":angle_1"),
- (store_cos, ":cos", ":angle_1"),
- (store_sin, ":sin", ":angle_1"),
- (position_get_x, ":x1", pos0),
- (position_get_y, ":y1", pos0),
- (position_normalize_origin, ":d1", pos0),
- (store_mul, ":k1", ":x1", ":cos"),
- (store_mul, ":k2", ":y1", ":sin"),
- (store_add, ":speed_relevant", ":k1", ":k2"),
- (val_mul, ":speed_relevant", ":speed_enemies",),
- (val_div, ":speed_relevant", ":d1"),
- (convert_from_fixed_point, ":speed_relevant"),
- (val_abs, ":speed_relevant"),
- (try_begin),#提高骑兵优先度
- (lt, ":speed_relevant", 3000),
- (store_div, ":distance_cavalry", ":speed_1",5),
- (val_max, ":distance_cavalry", 0),
- (val_add, ":distance_cavalry", 500),
- (val_sub, ":distance", ":distance_cavalry"),
- (else_try),#暂时忽视不是冲你来的骑兵
- (val_add, ":distance", 5000),
- (try_end),
- (else_try),#提高无盾步兵的优先度↓
- (agent_get_wielded_item, ":weapon_hold", ":enemies", 1),
- (neg|gt, ":weapon_hold", 1),
- (val_sub, ":distance", 500),
- (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),
- #----------------减速设置↓-----------------------------------------------------------
- (assign, ":speed_limit", 1000),
- (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_pistol),
- (eq, ":weapon_type", itp_type_musket),
- (agent_get_bone_position, pos4, ":agent_no", 8, 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_begin),
- (assign, ":shoot_distance", 4000),
- (agent_get_attack_action, ":attack_action", ":agent_no"),
- (eq, ":attack_action", 1),#准备攻击
- (try_begin),#减速设置↓
- (gt, ":distance_closest", 700),
- (le, ":distance_closest", ":shoot_distance"),
- (store_div, ":speed_limit_1", ":speed_y",2000),#
- ## 速度罚函数
- (agent_get_troop_id,":trp_t_1", ":agent_no"),
- (store_skill_level, ":horse_archery_lev", "skl_horse_archery", ":trp_t_1"),
- (store_add, ":speed_limit_2",":speed_limit_1", 40), ## 7:19, 3:31
- (store_mul, ":horse_archery_fac",":horse_archery_lev", 3),
- (store_sub, ":speed_limit", ":speed_limit_2",":horse_archery_fac"),
- ## 速度罚函数
- (val_max, ":speed_limit", 0),
- (try_end),
- (eq, ":weapon_type", itp_type_bow),
- (try_begin),
- (le, ":distance_true", ":shoot_distance"),
- (agent_set_defend_action, ":agent_no", -2, 1),
- (agent_set_attack_action, ":agent_no", 3, 0),
- (else_try),
- (gt, ":distance_true", ":shoot_distance"),
- (agent_set_attack_action, ":agent_no", -2, 1),
- (agent_set_defend_action, ":agent_no", 3, 1),#取消射击
- (try_end),
- (else_try),#非拉弓状态
- (eq, ":weapon_type", itp_type_bow),
- (le, ":distance_true", ":shoot_distance"),#
- (agent_get_combat_state, ":combat_state", ":agent_no"),#获取战斗状态
- (neq, ":combat_state", 8),#能看到
- (agent_set_attack_action, ":agent_no", 3, 1),
- (try_end),
- #让弓骑更积极地射击↑
- (try_end),
- (agent_set_speed_limit, ":agent_no", ":speed_limit"),#限制速度
- #----------------减速设置↑-----------------------------------------------------------
- #----------------绕圈的计算↓---------------------------------------------------------
- (try_begin),
- (agent_slot_eq, ":enemies_closest", slot_agent_is_running_away, 0),
- (lt, ":distance_closest", 12000),
- (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),#小于10m时后退
- (neg|gt, ":distance_closest", 1000),
- (assign, ":effect", -78),
- (else_try),#大于25m时靠近
- (gt, ":distance_closest", 2500),
- (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"),
- (position_move_x, pos1, ":move_x", 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),
- (gt, ":melee_weapon", -1),
- (agent_get_horse, ":enemies_horse", ":enemies_closest"),
- (gt, ":enemies_horse", -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", 1003, 0),
- (agent_set_slot, ":agent_no", 1003, 1),
- (else_try),
- (agent_slot_eq, ":agent_no", 1003, 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),
- (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", 1003, 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),
- ]),
- ## CC 骑射AI
复制代码 改动只有下面这几句
- ## 速度罚函数
- (agent_get_troop_id,":trp_t_1", ":agent_no"),
- (store_skill_level, ":horse_archery_lev", "skl_horse_archery", ":trp_t_1"),
- (store_add, ":speed_limit_2",":speed_limit_1", 40), ## 7:19, 3:31
- (store_mul, ":horse_archery_fac",":horse_archery_lev", 3),
- (store_sub, ":speed_limit", ":speed_limit_2",":horse_archery_fac"),
- ## 速度罚函数
复制代码 这样就可以实现不同骑射等级的兵种骑射效果的差异,也可以实现骑射的游戏平衡。
|