Changing default AI combat behaviour

Users who are viewing this thread

John25-

Sergeant at Arms
In my mod I have noticed that sometimes one of the faction does not move and 'waits' for the other one in battle. So is there a way to change it and make all factions charge instead of keeping their position or even advancing progressively over the battlefield? (i.e. to make it the same way as when fighting bandits)

It seems that the topic has already been mentioned there: https://forums.taleworlds.com/index...quick-questions-and-answers.6575/post-8913773, but I haven't found a precise answer on how to do it
 
Solution
It doesn't seem to be related to mission templates, I have made changes in module_scripts.py in the following section and it works as I wanted:
Code:
 ("battle_tactic_apply_aux",

I just removed all the triggers to make it look like this:
Code:
  ("battle_tactic_apply_aux",
    [
      (store_script_param, ":team_no", 1),
      (store_script_param, ":battle_tactic", 2),
          (assign, ":battle_tactic", 0),
          (team_give_order, ":team_no", grc_everyone, mordr_charge),
      (assign, reg0, ":battle_tactic"),
  ]),
But this is because that's the way I need it to be in my mod - now the armies of all factions charge as if they were bandits instead of following the usual battle behaviour
The precise answer is to basically look up how VC made it :lol:

To prevent charging at the start of a battle you can set an additional trigger to the mission template as described here. I would therefore guess that you should take a good look at the battle mission templates and compare them via WinMerge or another software of your choice to easily see the differences.
 
Upvote 0
It doesn't seem to be related to mission templates, I have made changes in module_scripts.py in the following section and it works as I wanted:
Code:
 ("battle_tactic_apply_aux",

I just removed all the triggers to make it look like this:
Code:
  ("battle_tactic_apply_aux",
    [
      (store_script_param, ":team_no", 1),
      (store_script_param, ":battle_tactic", 2),
          (assign, ":battle_tactic", 0),
          (team_give_order, ":team_no", grc_everyone, mordr_charge),
      (assign, reg0, ":battle_tactic"),
  ]),
But this is because that's the way I need it to be in my mod - now the armies of all factions charge as if they were bandits instead of following the usual battle behaviour
 
Upvote 0
Solution
Good that you found a solution. If you take a deeper look you will find that battle_tactic_apply_aux is getting called by the script battle_tactic_apply which is getting called in a trigger at the mission templates.
Code:
      (5, 0, 0, [
          (store_mission_timer_a,":mission_time"),

          (ge,":mission_time",3),
          
          (call_script, "script_battle_tactic_apply"),
          ], []), #applying battle tactic

      common_battle_order_panel,
      common_battle_order_panel_tick,

    ],
In the end it's pretty much the same as I linked above :wink:
 
Upvote 0
("battle_tactic_apply_aux",
[
(store_script_param, ":team_no", 1),
(store_script_param, ":battle_tactic", 2),
(store_mission_timer_a, ":mission_time"),
(try_begin),
(eq, ":battle_tactic", btactic_hold),
(copy_position, pos1, pos52),
(call_script, "script_get_closest3_distance_of_enemies_at_pos1", ":team_no", 1),
(assign, ":avg_dist", reg0),
(assign, ":min_dist", reg1),
(try_begin),
(this_or_next|lt, ":min_dist", 1000),
(lt, ":avg_dist", 4000),
(assign, ":battle_tactic", 0),
(team_give_order, ":team_no", grc_everyone, mordr_charge),
(try_end),
(else_try),
(eq, ":battle_tactic", btactic_follow_leader),
(team_get_leader, ":ai_leader", ":team_no"),
(try_begin),
(ge, ":ai_leader", 0),
(agent_is_alive, ":ai_leader"),
(agent_set_speed_limit, ":ai_leader", 9),
(call_script, "script_team_get_average_position_of_enemies", ":team_no"),
(copy_position, pos60, pos0),
(agent_get_position, pos61, ":ai_leader"),
(position_transform_position_to_local, pos62, pos61, pos60), #pos62 = vector to enemy w.r.t leader
(position_normalize_origin, ":distance_to_enemy", pos62),
(convert_from_fixed_point, ":distance_to_enemy"),
(assign, reg17, ":distance_to_enemy"),
(position_get_x, ":dir_x", pos62),
(position_get_y, ":dir_y", pos62),
(val_mul, ":dir_x", 23),
(val_mul, ":dir_y", 23), #move 23 meters
(position_set_x, pos62, ":dir_x"),
(position_set_y, pos62, ":dir_y"),

(position_transform_position_to_parent, pos63, pos61, pos62), #pos63 is 23m away from leader in the direction of the enemy.
(position_set_z_to_ground_level, pos63),

(team_give_order, ":team_no", grc_everyone, mordr_hold),
(team_set_order_position, ":team_no", grc_everyone, pos63),
(agent_get_position, pos1, ":ai_leader"),
(try_begin),
(lt, ":distance_to_enemy", 50),
(ge, ":mission_time", 30),
(assign, ":battle_tactic", 0),
(team_give_order, ":team_no", grc_everyone, mordr_charge),
(agent_set_speed_limit, ":ai_leader", 60),
(try_end),
(else_try),
(assign, ":battle_tactic", 0),
(team_give_order, ":team_no", grc_everyone, mordr_charge),
(try_end),
(try_end),

(try_begin), # charge everyone after a while
(neq, ":battle_tactic", 0),
(ge, ":mission_time", 300),
(assign, ":battle_tactic", 0),
(team_give_order, ":team_no", grc_everyone, mordr_charge),
(team_get_leader, ":ai_leader", ":team_no"),
(agent_set_speed_limit, ":ai_leader", 60),
(try_end),
(assign, reg0, ":battle_tactic"),
]),

Hi, I tried this trigger but it gives me an error. Can someone help me understand this script? What values do I have to change for AI to adopt a different attitude? All I need is for the cavalry not to attack early in the battle. Thx.
 
Upvote 0
Hi, I tried this trigger but it gives me an error. Can someone help me understand this script? What values do I have to change for AI to adopt a different attitude? All I need is for the cavalry not to attack early in the battle. Thx.
What is the error text exactly?
 
Upvote 0
mneUp.jpg


I added in AI triggers inside mission_template.py (lead_charge)

bDdYo.jpg
 
Upvote 0
Sorry but what do I have to delete?

( 0, 2, ti_once, [],
[
(get_player_agent_no, ":player_agent"),
(agent_get_team, ":agent_team", ":player_agent"),
(team_give_order, ":agent_team", grc_everyone, mordr_hold)],

If I leave it like this, it gives me an error on line 3636 which is the end:

uZfvP.jpg


y-fTZ.jpg
 
Upvote 0
:xf-tongue: Worked, cavalry holds for an instant after they charge, I wish they wait a little bit longer, but I guess is the way the script is made (they check distance or something). But I´m happy how is it now.

Thx again.
 
Upvote 0
Back
Top Bottom