OSP Code Combat AI deploy pavise shields

Users who are viewing this thread

Making the AI able to deploy pavise shields(friend and foe),
they will deploy when shooting and recover when moving away from it.
Inspierd by Cartread Deployable Pavise Shield.

*One issuse is that the banner mesh that apply on the heraldic shields is the one of the enemy, if some1 can help with that it will be great.
Needed files to edit:
module_constants.py
module_scene_props.py
module_mission_templates.py
module_game_menus.py


The steps:
1)
Add those lines in the end of the file:
Code:
slot_agent_attached_prop          = 23
slot_prop_pavise_banner_mesh = 24
slot_agent_attached_pavise_item          = 26
slot_agent_pavise_on_ground         = 0
slot_agent_pavise_allow          = 0
pavise_begin = "itm_tab_shield_pavise_a"  # the first pavise shield item id
pavise_end = "itm_tab_shield_small_round_a"# one line after the last pavise shield item id
2.0)
Add this block somewhere in the start of the file :
Code:
pavise_init = (ti_on_init_scene_prop,
   [
    (store_trigger_param_1, ":instance_no"),
  (assign, ":agent_no", reg5), #reg5 is caller agent, set before (spawn_scene_prop) in "cf_agent_deploy_pavise"
  (try_begin),
    (agent_is_active, ":agent_no"),
    (agent_get_troop_id, ":troop_no", ":agent_no"),
    (call_script, "script_agent_troop_get_banner_mesh", ":agent_no", ":troop_no"),
    (assign, ":mesh", reg0),
  (else_try),
    (assign, ":mesh", "mesh_banners_default_b"),
  (try_end),
  (scene_prop_set_slot, ":instance_no", slot_prop_pavise_banner_mesh, ":mesh"),
  (assign, ":tableau", "tableau_pavise_shield_2"),
  (try_begin),
    (prop_instance_get_scene_prop_kind, reg0, ":instance_no"),
    (eq, reg0, "spr_pavise_1"),
    (assign, ":tableau", "tableau_pavise_shield_1"),
  (try_end),
  (cur_scene_prop_set_tableau_material, ":tableau", ":mesh"),
   ])
2.1)
Add this line at the end of the file :
Code:
("pavise_1", sokf_moveable, "tableau_shield_pavise_prop_1", "bo_tableau_shield_pavise_prop_1", [pavise_init]),
3.0)
Add those blocks somewhere in the start of the file :
Code:
#Pavise
deploy_pavise_on_ground_allies = (
   0, 0, 3,
   [
      (troop_slot_eq, "trp_player", slot_agent_pavise_allow, 1),
   ],[
       (try_for_agents, ":agent"),
       (agent_is_alive, ":agent"),
       (agent_is_human, ":agent"),
       (agent_is_ally, ":agent"),
       (agent_is_non_player, ":agent"),
       (agent_get_class, ":agent_class", ":agent"),
       (try_for_range, ":item", all_items_begin, all_items_end),
(is_between, ":item", pavise_begin, pavise_end),
       (agent_has_item_equipped, ":agent", ":item"),
      (agent_slot_eq, ":agent", slot_agent_pavise_on_ground, 0),
       (agent_set_slot, ":agent", slot_agent_attached_pavise_item, ":item"),
       (eq, ":agent_class", grc_archers),
       (agent_get_combat_state, ":agent_cs", ":agent"),
       (this_or_next | eq, ":agent_cs", 3),
       (eq, ":agent_cs", 4),  # 7 = no visible targets (state for ranged units)
       (agent_get_position, pos2, ":agent"),
       (position_move_y, pos2, 90),
       (set_spawn_position, pos2),
       (spawn_scene_prop, "spr_pavise_1"),  # pavise spawn
              (agent_set_slot, ":agent", slot_agent_pavise_on_ground, 1),
       (agent_set_slot, ":agent", slot_agent_attached_prop, reg0),
       (agent_get_slot, ":spr_pavise", ":agent", slot_agent_attached_prop),
       (prop_instance_enable_physics, ":spr_pavise", 1),
       (agent_unequip_item, ":agent", ":item"),
   (else_try),
       (try_end),
       (try_end),
   ])
deploy_pavise_remove_allies = (
    0, 0, 3, [
    (troop_slot_eq, "trp_player", slot_agent_pavise_allow, 1),
    ], [
        (try_for_agents, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_is_human, ":agent"),
        (agent_is_ally, ":agent"),
        (agent_is_non_player, ":agent"),
        (agent_slot_eq, ":agent", slot_agent_pavise_on_ground, 1),
(agent_get_position, pos2, ":agent"),
        (agent_get_slot, ":spr_pavise", ":agent", slot_agent_attached_prop),
        (prop_instance_get_position, pos3, ":spr_pavise"),
           (get_distance_between_positions, ":cur_distance", pos3, pos2),
          (ge, ":cur_distance", 100),  # 1 meters
        (agent_get_slot, ":spr_pavise_itnm", ":agent", slot_agent_attached_pavise_item),
        (agent_equip_item, ":agent", ":spr_pavise_itnm"),
        (position_move_z, pos4, -350),  # moving back to ground level
        (prop_instance_set_position, ":spr_pavise", pos4),
        (scene_prop_fade_out, ":spr_pavise", 1),
        (prop_instance_enable_physics, ":spr_pavise", 0),
     (agent_set_slot, ":agent", slot_agent_pavise_on_ground, 0),
     (else_try),
        (try_end),
    ])
deploy_pavise_on_ground_enemies = (
   0, 0, 3,
   [
      (troop_slot_eq, "trp_player", slot_agent_pavise_allow, 1),
   ],[
       (try_for_agents, ":agent"),
       (agent_is_alive, ":agent"),
       (agent_is_human, ":agent"),
       (neg | agent_is_ally, ":agent"),
       (agent_is_non_player, ":agent"),
       (agent_get_class, ":agent_class", ":agent"),
       (try_for_range, ":item", all_items_begin, all_items_end),
(is_between, ":item", pavise_begin, pavise_end),
      (agent_slot_eq, ":agent", slot_agent_pavise_on_ground, 0),
       (agent_has_item_equipped, ":agent", ":item"),
       (agent_set_slot, ":agent", slot_agent_attached_pavise_item, ":item"),
       (eq, ":agent_class", grc_archers),
       (agent_get_combat_state, ":agent_cs", ":agent"),
       (this_or_next | eq, ":agent_cs", 3),
       (eq, ":agent_cs", 4),  # 7 = no visible targets (state for ranged units)
       (agent_get_position, pos2, ":agent"),
       (position_move_y, pos2, 90),
       (set_spawn_position, pos2),
       (spawn_scene_prop, "spr_pavise_1"),  # pavise spawn
     (agent_set_slot, ":agent", slot_agent_pavise_on_ground, 1),
       (agent_set_slot, ":agent", slot_agent_attached_prop, reg0),
       (agent_get_slot, ":spr_pavise", ":agent", slot_agent_attached_prop),
       (prop_instance_enable_physics, ":spr_pavise", 1),
       (agent_unequip_item, ":agent", ":item"),
   (else_try),
       (try_end),
       (try_end),
   ])
deploy_pavise_remove_enemies = (
    0, 0, 3, [
     (troop_slot_eq, "trp_player", slot_agent_pavise_allow, 1),
    ], [
        (try_for_agents, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_is_human, ":agent"),
        (neg | agent_is_ally, ":agent"),
        (agent_is_non_player, ":agent"),
      (agent_slot_eq, ":agent", slot_agent_pavise_on_ground, 1),
         (agent_get_position, pos2, ":agent"),
        (agent_get_slot, ":spr_pavise", ":agent", slot_agent_attached_prop),
        (prop_instance_get_position, pos3, ":spr_pavise"),
           (get_distance_between_positions, ":cur_distance", pos3, pos2),
          (ge, ":cur_distance", 100),  # 1 meters
        (agent_get_slot, ":spr_pavise_itnm", ":agent", slot_agent_attached_pavise_item),
        (agent_equip_item, ":agent", ":spr_pavise_itnm"),
        (position_move_z, pos4, -350),  # moving back to ground level
        (prop_instance_set_position, ":spr_pavise", pos4),
        (scene_prop_fade_out, ":spr_pavise", 1),
        (prop_instance_enable_physics, ":spr_pavise", 0),
    (agent_set_slot, ":agent", slot_agent_pavise_on_ground, 0),
     (else_try),
        (try_end),
    ])
#Pavise
3.1)
Add those new blocks names in any mission you want it to be active on, for example on lead charge missions,
In this entry :
Code:
"lead_charge",mtf_battle_mode|mtf_synch_inventory,charge,
 "You lead your men to battle.",
 [

Scroll down and you will see this line:
common_battle_init_banner,
Add to this the new blocks names so it will look like this:
common_battle_init_banner,
deploy_pavise_remove_enemies,
deploy_pavise_on_ground_enemies,
deploy_pavise_remove_allies,
deploy_pavise_on_ground_allies,
4)
In the camp actions menu below the "camp_recruit_prisoners" entry(or anywhere else you want it to be) add those lines:
Code:
("pavise_allow_yes", [(troop_slot_eq, "trp_player", slot_agent_pavise_allow, 0), ], "Enable auto deploy and recover of pavise shield(currently disabled)",
[
 (troop_set_slot, "trp_player", slot_agent_pavise_allow, 1),
(jump_to_menu, "mnu_camp_action"),
 ]),
 ("pavise_allow_no", [(troop_slot_eq, "trp_player", slot_agent_pavise_allow, 1), ], "Disable auto deploy and recover of pavise shield(currently enabled)",
[              
 (troop_set_slot, "trp_player", slot_agent_pavise_allow, 0),
(jump_to_menu, "mnu_camp_action"),
]),
You also need the collision of the shield, downalod it here(brf with collision, mesh, mat and texture of the shield):
and add in the module.ini file this line: load_mod_resource = pavise_shield

https://imgur.com/a/8d9HQNO
 
1) You forget to assign xbow agent to reg5.
2) You don't need 4 triggers. 2 for ally and 2 for enemy. Just leave 2 triggers and remove agent_is_ally check.
3) (position_move_z, pos4, -350), # moving back to ground level- here change pos4 to pos3. Increase distance.

Currently prop is undestructible. It should be broken by any melee weapon or cavalry charge or maybe don't deploy pavises if enemy near. Use old props instead of overflow memory.
 
Last edited:
Back
Top Bottom