本帖最后由 杰喵喵 于 2023-10-3 22:34 编辑
简易的骑兵反复对步兵冲锋AI:
1.介绍:
简易的骑兵反复对步兵冲锋AI,战团中的骑兵对步兵群会拥挤成一团,针对这点进行优化。
2.核心原理:
(1)agent_set_scripted_destination;
(2)agent_clear_scripted_mode;
3.代码效果展示:
骑马与砍杀战团-简易AI骑兵反复冲锋_骑马与砍杀 (bilibili.com)
4.代码:
- common_agent_rider_lead_charge = (0.5, 0, 0,
- [
- (assign,":is_run,",0),
- (eq,":is_run,",0),
- ],
- [
- (set_fixed_point_multiplier, 100),
-
- (assign,":move_value",5000),
- #获得地图最大限制
- (init_position,pos26),
- (init_position,pos27),
- (get_scene_boundaries, pos26, pos27),#左下角和右上角的点,方向朝上
- (position_get_x, ":lower_left_corner_x", pos26),
- (position_get_y, ":lower_left_corner_y", pos26),
- (position_get_x, ":upper_right_corner_x", pos27),
- (position_get_y, ":upper_right_corner_y", pos27),
- (val_add,":lower_left_corner_x",":move_value"),
- (val_add,":lower_left_corner_y",":move_value"),
- (val_sub,":upper_right_corner_x",":move_value"),
- (val_sub,":upper_right_corner_y",":move_value"),
-
- (try_for_agents, ":agent_no"),
- (agent_is_alive, ":agent_no"),
- (agent_is_human, ":agent_no"),
- (agent_is_non_player, ":agent_no"),
- (agent_get_horse, ":horse_no", ":agent_no"),
- (gt,":horse_no",-1),
- (agent_get_team,":agent_team",":agent_no"),
- (agent_get_division, ":agent_division", ":agent_no"),
- (team_get_movement_order, ":movement_order", ":agent_team", ":agent_division"),
- (agent_get_wielded_item, ":weapon_hold", ":agent_no", 0),#获取右手武器
- (gt, ":weapon_hold", 0),
- (item_get_type, ":item_weapon_type", ":weapon_hold"),
- (neq,":item_weapon_type",itp_type_bow),
- (neq,":item_weapon_type",itp_type_pistol),
- (neq,":item_weapon_type",itp_type_thrown),
- (neq,":item_weapon_type", itp_type_musket),
- (neq,":item_weapon_type", itp_type_crossbow),
-
- (try_begin),
- (eq, ":movement_order", mordr_charge),
- (agent_ai_get_move_target,":target_agent",":agent_no"),
- #强制设定目标
- (try_begin),
- (lt,":target_agent",0),
- (agent_clear_scripted_mode, ":agent_no"),
- (agent_ai_get_num_cached_enemies, ":num", ":agent_no"),
- (try_for_range,":index",0,":num"),#get target_agent
- (store_random_in_range,":index",0,":num"),
- (agent_ai_get_cached_enemy, reg40,":agent_no",":index"),
- (agent_is_alive, reg40),
- (assign,":target_agent",reg40),
- (agent_set_look_target_agent,":agent_no",":target_agent"),
- (assign,":num",-1),#break
- (try_end),
- (try_end),
-
- (gt,":target_agent",-1),
- (agent_get_horse, ":horse_no", ":target_agent"),
- (try_begin),
- (lt, ":horse_no",0),
- (agent_slot_eq, ":target_agent", slot_agent_is_running_away, 0),#非逃跑
- #使用长杆触发
- #(eq,":item_weapon_type",itp_type_polearm),
- (init_position,pos40),
- (init_position,pos41),
- (agent_get_position,pos40,":agent_no"),
- (agent_get_position,pos41,":target_agent"),
- (neg|position_is_behind_position,pos40,pos41),
- (position_copy_rotation,pos41,pos40),
- (assign,":move_y",":move_value"),
- (position_move_y,pos41,":move_y"),
- (position_set_z_to_ground_level,pos41),
- (position_get_x, ":x_value", pos41),
- (position_get_y, ":y_value", pos41),
- (try_begin),
- (is_between,":x_value",":lower_left_corner_x",":upper_right_corner_x"),
- (is_between, ":y_value",":lower_left_corner_y",":upper_right_corner_y"),
- (agent_set_scripted_destination,":agent_no",pos41,1,1),
- (else_try),
- (agent_clear_scripted_mode, ":agent_no"),
- (try_end),
- (try_end),
- (else_try),
- (agent_clear_scripted_mode, ":agent_no"),
- (try_end),
-
-
- ]
- )
复制代码
|