Unique troops for each towns

Users who are viewing this thread

Captain Lust said:
A fairly basic script for the specific towns using 'party_add_members' would do the job fairly easily.
Hmm... Can you tell me? I'm very novice at coding at this time.
I'm making a mod anyway.  :mrgreen:
 
Well, at first you need the troops and the towns. Towns are already around aplenty, so let us skip them.
For troops you may duplicate and then modify or write from scratch one of the existing troop trees. Basically, create new troops, link them with the "upgrade"- and "upgrade2"-functions to form a tree.

... Now, you have to cut off the normal way for the towns you aim for to receive troops. From a quick look this seems to be done in the simple trigger headed with "#Hiring men with center wealths (once a day)". The relevant code block would be
Code:
     (try_for_range, ":center_no", walled_centers_begin, walled_centers_end),
       (neg|party_slot_eq, ":center_no", slot_town_lord, "trp_player"), #center does not belong to player.
       (party_slot_ge, ":center_no", slot_town_lord, 1), #center belongs to someone.       
       (party_slot_eq, ":center_no", slot_center_is_besieged_by, -1), #center not under siege

       (store_faction_of_party, ":center_faction", ":center_no"),
       (try_begin),
         (this_or_next|eq, ":center_faction", "fac_player_supporters_faction"),
         (eq, ":center_faction", "$players_kingdom"),        
         (assign, ":reinforcement_cost", reinforcement_cost_moderate),
       (else_try),
         (game_get_reduce_campaign_ai, ":reduce_campaign_ai"),
         (assign, ":reinforcement_cost", reinforcement_cost_moderate),
         (try_begin), 
           (eq, ":reduce_campaign_ai", 0), #hard (1x or 2x reinforcing)
           (assign, ":reinforcement_cost", reinforcement_cost_hard),
           (store_random_in_range, ":num_hiring_rounds", 0, 2),
           (val_add, ":num_hiring_rounds", 1),
         (else_try), 
           (eq, ":reduce_campaign_ai", 1), #moderate (1x reinforcing)
           (assign, ":reinforcement_cost", reinforcement_cost_moderate),
           (assign, ":num_hiring_rounds", 1),
         (else_try), 
           (eq, ":reduce_campaign_ai", 2), #easy (none or 1x reinforcing)
           (assign, ":reinforcement_cost", reinforcement_cost_easy),
           (store_random_in_range, ":num_hiring_rounds", 0, 2),
         (try_end),           
       (try_end),

       (try_for_range, ":unused", 0, ":num_hiring_rounds"), 		 
         (party_get_slot, ":cur_wealth", ":center_no", slot_town_wealth),
         (assign, ":hiring_budget", ":cur_wealth"),
         (val_div, ":hiring_budget", 2),
         (gt, ":hiring_budget", ":reinforcement_cost"),       
         (call_script, "script_cf_reinforce_party", ":center_no"),
         (val_sub, ":cur_wealth", ":reinforcement_cost"),
         (party_set_slot, ":center_no", slot_town_wealth, ":cur_wealth"),
       (try_end),  
     (try_end),
For the centers you desire to have custom troops, you may wish to reroute the control flow from script_cf_reinforce_party to a custom build. Or you could check their ID within the script and there switch away from standard procedure, your call really.
Code:
      (faction_get_slot, ":party_template_a", ":party_faction", slot_faction_reinforcements_a),
      (faction_get_slot, ":party_template_b", ":party_faction", slot_faction_reinforcements_b),
      (faction_get_slot, ":party_template_c", ":party_faction", slot_faction_reinforcements_c),
See these lines? You could define three party templates for each town, containing the troops you desire; replace the faction templates fetched here with custom templates if the current party is one of your chosen centers and let the script proceed normally. That seems to be the easiest, quickest solution.
You want to do it the right way, though, not just hack it. Right? Right!? Sure.
So, check for the center ID in the beginning (right after "(store_script_param_1, ":party_no"),") and put an (else_try)-block around everything to the last of those three lines I just showed.
Into the (try_begin) you shove an (eq, ":party_no", <one of your chosen centers>), and then an "assign" for the 'a', 'b' and 'c' templates.
For each of your other chosen cities you add an (else_try) between the (try_begin) and the (else_try)-block holding the original code.
Code:
      (try_begin),
        (eq, ":party_no", <one of your chosen centers>),

        (assign, ":party_template_a", <this center's custom party_template_a>),
        (assign, ":party_template_b", <this center's custom party_template_b>),
        (assign, ":party_template_c", <this center's custom party_template_c>),
      (else_try),
        # original code
        (store_faction_of_party, ":party_faction", ":party_no"),
        (party_get_slot, ":party_type",":party_no", slot_party_type),

#Rebellion changes begin: 
        (try_begin),
          (eq, ":party_type", spt_kingdom_hero_party),
          (party_stack_get_troop_id, ":leader", ":party_no"),
          (troop_get_slot, ":party_faction",  ":leader", slot_troop_original_faction),
        (try_end),
#Rebellion changes end

        (try_begin),
          (eq, ":party_faction", "fac_player_supporters_faction"),
          (party_get_slot, ":town_lord", ":party_no", slot_town_lord),
          (try_begin),
            (gt, ":town_lord", 0),
            (troop_get_slot, ":party_faction", ":town_lord", slot_troop_original_faction),
          (else_try),
            (party_get_slot, ":party_faction", ":party_no", slot_center_original_faction),
          (try_end),
        (try_end),

        (faction_get_slot, ":party_template_a", ":party_faction", slot_faction_reinforcements_a),
        (faction_get_slot, ":party_template_b", ":party_faction", slot_faction_reinforcements_b),
        (faction_get_slot, ":party_template_c", ":party_faction", slot_faction_reinforcements_c),
      (try_end),

There, done. Unless there are other sources of troops for a center, of course. You will have to hunt down these on your own.
 
Maybe if you actually looked in the source (available with every download) you'd find the following
Code:
	  # Towns (loop)
	  (try_for_range, ":town_no", towns_begin, towns_end),
		# #regional setup done here (these are defined in module_parties)
		(try_begin),
		  (party_get_num_companion_stacks, ":troop", ":town_no"),
		  (gt, ":troop", 0),
		  (party_stack_get_troop_id, ":troop", ":town_no", 0),
		  (gt, ":troop", 0),
		  (party_set_slot, ":town_no", slot_town_regional, ":troop"),
		  # (str_store_troop_name_plural, s2, ":troop"),
		  # (str_store_party_name_link, s1, ":town_no"),
		  # (display_message, "@{s1} has {s2}"),
		(try_end),
	  (try_end),
Code:
  (36.0, 0.0, 24.0 * 30,
   [],
   [
    (game_get_reduce_campaign_ai, ":reduce"),
    (try_for_range, ":town_no", towns_begin, towns_end), #loop through every town
      (party_get_slot,":troop", ":town_no", slot_town_regional), #get troops
      (gt, ":troop", 0),
      (store_random_in_range,":rein_num", 2,4),
      (party_get_slot, ":leader", ":town_no", slot_town_lord),
      (try_begin),
        (is_between, ":leader", original_kingdom_heroes_begin, active_npcs_end),
        (troop_get_slot, ":party_no", ":leader", slot_troop_leaded_party),
        (troop_get_slot, ":renown", ":leader", slot_troop_renown),
        (val_div,":renown", 400),#kings ~ 2000
        (val_add,":rein_num",":renown"),
        (party_is_active, ":party_no"),
        (party_add_members, ":party_no", ":troop", ":rein_num"),
      (try_end),
      (val_div,":rein_num",2), #add half to town
      (val_add, ":rein_num", ":reduce"),
      (party_add_members, ":town_no", ":troop", ":rein_num"),
    (try_end),

]),
To set this up, simply put a troop in module_parties for the respective towns. Only the first one will be selected as the town troop.
 
Warband vanilla. But as it is nothing outlandish it will work in M&B 1.011 as well... without modifications even, if I am not mistaken (have no MS for that anymore and will bother to fetch as much as you bothered to tell us whether you need 1.011 code in the first place).
 
Back
Top Bottom