OSP Code Campaign Arch3r OS: Terrain advantage

Users who are viewing this thread

What this does: When simulating battles some troops get advantages. Mounted troops get more bonus on the steppe, desert or plain ground, infantry gets an advantage in forests while archers get a penalty. I used this for the mod Avarice of the Exiled, where I also checked for items that gave certain units advantages in snow or desert.

How this works: When a battle is simulated (with either the "Order your troops to attack without you" or AI battles) the script_game_event_simulate_battle is called. Inside the script it uses script_party_calculate_strength to see which party is stronger. I added terrain to this, to give Khergits for example a bonus on steppe.

How to implent it: Search for the script party_calculate_strength. Add the lines in the spoiler right above:

        (try_begin),
          (neg|troop_is_hero, ":stack_troop"),
          (party_stack_get_size, ":stack_size",":party",":i_stack"),
          (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
          (val_sub, ":stack_size", ":num_wounded"),
          (val_mul, ":stack_strength", ":stack_size"),
        (else_try),
          (troop_is_wounded, ":stack_troop"), #hero...
          (assign,":stack_strength",0),
        (try_end),
        (val_add,reg(0), ":stack_strength"),
      (try_end),
      (party_set_slot, ":party", slot_party_cached_strength, reg(0)),
  ]),


##AotE terrain advantages
      (party_get_current_terrain, ":terrain_type", ":party"),
      (try_begin),
        (eq, ":terrain_type", rt_steppe),
        (troop_is_guarantee_horse, ":stack_troop"),
        (val_mul, ":stack_strength", 1.5),
      (else_try),
        (eq, ":terrain_type", rt_plain),
        (troop_is_guarantee_horse, ":stack_troop"),
        (val_mul, ":stack_strength", 1.1),
      (else_try),
        (eq, ":terrain_type", rt_snow),
#        (try_for_range,":items","itm_zrak_wildman_chest","itm_zrak_berserker_chest"),
#          (troop_has_item_equipped,":stack_troop",":items"),
#          (val_mul, ":stack_strength", 1.4),
#        (try_end),
#        (try_for_range,":items","itm_vaegir_woodcutter_coat","itm_vaegir_woodcutter_helmet"),
#          (troop_has_item_equipped,":stack_troop",":items"),
#          (val_mul, ":stack_strength", 1.5),
#        (try_end),
        (val_mul, ":stack_strength", 0.95),
      (else_try),
        (eq, ":terrain_type", rt_desert),
#        (try_for_range,":items","itm_kabiel_villager_chest","itm_kabiel_villager_helmet"),
#          (troop_is_guarantee_horse, ":stack_troop"),
#          (troop_has_item_equipped,":stack_troop",":items"),
#          (val_mul, ":stack_strength", 1.8 ),
#        (else_try),
#          (troop_is_guarantee_horse, ":stack_troop"),
#          (val_mul, ":stack_strength", 1.4),
#        (try_end),
        (val_mul, ":stack_strength", 0.95),
      (else_try),
        (eq, ":terrain_type", rt_steppe_forest),
        (troop_is_guarantee_horse, ":stack_troop"),
        (val_mul, ":stack_strength", 1.2),
      (else_try),
        (eq, ":terrain_type", rt_forest),
        (neg|troop_is_guarantee_horse, ":stack_troop"),
        (neg|troop_is_guarantee_ranged, ":stack_troop"),
        (val_mul, ":stack_strength", 1.2),
      (else_try),
        (eq, ":terrain_type", rt_snow_forest),
#        (try_for_range,":items","itm_zrak_wildman_chest","itm_zrak_berserker_chest"),
#          (troop_has_item_equipped,":stack_troop",":items"),
#          (val_mul, ":stack_strength", 1.2),
#        (try_end),
#        (try_for_range,":items","itm_vaegir_woodcutter_coat","itm_vaegir_woodcutter_helmet"),
#          (troop_has_item_equipped,":stack_troop",":items"),
#          (val_mul, ":stack_strength", 1.2),
#        (try_end),
        (neg|troop_is_guarantee_horse, ":stack_troop"),
        (neg|troop_is_guarantee_ranged, ":stack_troop"),
        (val_mul, ":stack_strength", 1.2),
      (try_end),
##AotE terrain advantages

That should do it, if I forgot something or this doesn't work, tell me.
 
Part of your code turned into a smiley. If I'm not mistaken it's suppose to be 
Code:
8-)
I'm not code savvy but I think it's odd that there's a negative right after your number.

At any rate, very useful thing you've made here.

edit: Also, I note part of your code contains bits referring to items in your mod, so if I want to implement this into my own or another mod I just need to remove these bits or substitute them for mine?
 
Thats pretty cool :smile:

Just a suggestion: Would'nt it be good if you added advantage for archers on plain, steppe and desert aswell, and then also gave the cavalry a penalty in forrests?
 
well this is a great idea.
But...

1. Doesn't the archers already have natural penalty in forests like I mean.. with all the trees in the way for their shooting. and the same with cavalry. That they get stuck in every tree.

2. How does your penalty system work? does it reduce stats or?
 
Arch3r said:
How this works: When a battle is simulated (with either the "Order your troops to attack without you" or AI battles) the script_game_event_simulate_battle is called. Inside the script it uses script_party_calculate_strength to see which party is stronger. I added terrain to this, to give Khergits for example a bonus on steppe.

@bjorne.: Might want to see this, its for simulated battles, for a more realistic battle simulation.

Cruger said:
Thats pretty cool :smile:

Just a suggestion: Would'nt it be good if you added advantage for archers on plain, steppe and desert aswell, and then also gave the cavalry a penalty in forrests?
Cavalry already have a penalty in forests, well, archers and cavalry don't have a penalty, but infantry has an advantage. Also I can give archers a slight advantage on plain,steppe and desert ya.
 
Back
Top Bottom