Changing center leader/merchant races mid-game. (RESOLVED)

Users who are viewing this thread

I'm working on a mod that adds a second 'race'. I have the walkers changing over, but now I'm working on getting the Guild Master, Armorer, Weaponsmith, etc. changing races too. Unfortunately, it's not working.

Here's the current script:

Code:
("change_town_staff_race",
	[
       (store_script_param, ":center_no", 1),
       (store_faction_of_party, ":center_faction", ":center_no"),
	   (party_get_slot, ":town_mayor", ":center_no", slot_town_elder),
	   (party_get_slot, ":town_tavernkeeper", ":center_no", slot_town_tavernkeeper),
	   (party_get_slot, ":town_weaponsmith", ":center_no", slot_town_weaponsmith),
	   (party_get_slot, ":town_merchant", ":center_no", slot_town_merchant),
	   (party_get_slot, ":town_armorer", ":center_no", slot_town_armorer),
	   (party_get_slot, ":town_horse_merchant", ":center_no", slot_town_horse_merchant),
	   
	   (troop_get_type, ":mayor_race", ":town_mayor"),
	   (troop_get_type, ":tavernkeeper_race", ":town_tavernkeeper"),
	   (troop_get_type, ":weaponsmith_race", ":town_weaponsmith"),
	   (troop_get_type, ":merchant_race", ":town_merchant"),
	   (troop_get_type, ":armorer_race", ":town_armorer"),
	   (troop_get_type, ":horse_merchant_race", ":town_horse_merchant"),
	   
	   (try_begin),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":mayor_race", 0),
			(troop_set_type, ":town_mayor", 2),
		(else_try),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":mayor_race", 1),
			(troop_set_type, ":town_mayor", 3),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":mayor_race", 2),
			(troop_set_type, ":town_mayor", 0),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":mayor_race", 3),
			(troop_set_type, ":town_mayor", 1),
		(try_end),
	   
	   (try_begin),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":tavernkeeper_race", 0),
			(troop_set_type, ":town_tavernkeeper", 2),
		(else_try),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":tavernkeeper_race", 1),
			(troop_set_type, ":town_tavernkeeper", 3),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":tavernkeeper_race", 2),
			(troop_set_type, ":town_tavernkeeper", 0),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":tavernkeeper_race", 3),
			(troop_set_type, ":town_tavernkeeper", 1),
		(try_end),
	   
	   (try_begin),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":weaponsmith_race", 0),
			(troop_set_type, ":town_weaponsmith", 2),
		(else_try),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":weaponsmith_race", 1),
			(troop_set_type, ":town_weaponsmith", 3),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":weaponsmith_race", 2),
			(troop_set_type, ":town_weaponsmith", 0),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":weaponsmith_race", 3),
			(troop_set_type, ":town_weaponsmith", 1),
		(try_end),
	   
	   (try_begin),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":merchant_race", 0),
			(troop_set_type, ":town_merchant", 2),
		(else_try),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":merchant_race", 1),
			(troop_set_type, ":town_merchant", 3),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":merchant_race", 2),
			(troop_set_type, ":town_merchant", 0),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":merchant_race", 3),
			(troop_set_type, ":town_merchant", 1),
		(try_end),
	   
	   (try_begin),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":armorer_race", 0),
			(troop_set_type, ":town_armorer", 2),
		(else_try),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":armorer_race", 1),
			(troop_set_type, ":town_armorer", 3),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":armorer_race", 2),
			(troop_set_type, ":town_armorer", 0),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":armorer_race", 3),
			(troop_set_type, ":town_armorer", 1),
		(try_end),
	   
	   (try_begin),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":horse_merchant_race", 0),
			(troop_set_type, ":town_horse_merchant", 2),
		(else_try),
			(this_or_next|eq, ":center_faction", fac_culture_7),
			(eq, ":center_faction", fac_culture_tamek),
			
			(eq, ":horse_merchant_race", 1),
			(troop_set_type, ":town_horse_merchant", 3),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":horse_merchant_race", 2),
			(troop_set_type, ":town_horse_merchant", 0),
		(else_try),
			(neq, ":center_faction", fac_culture_7),
			(neq, ":center_faction", fac_culture_tamek),
			
			(eq, ":horse_merchant_race", 3),
			(troop_set_type, ":town_horse_merchant", 1),
		(try_end),
			
	]),

Can anyone see what's going wrong? I have it all set up by trigger just like the walkers, so I know it's firing (plus a good bit of lag when it DOES fire), but they're remaining human when they should be changing to the new race.
 
I haven't tried it, but my procedure would be like this:
-Add a race to module_skins. Let's say the race is "dwarf" If you've done with skins, skeletons etc...
-Add tf_dwarf = 3 to header troops.
-Go to the module_troops and search for "armor merchants", "tavern keepers" et cetera.
After deciding what town will be dwarven town,
["town_1_weaponsmith", "Weaponsmith","{!}Weaponsmith",tf_hero|tf_randomize_face|tf_dwarf|tf_is_merchant, 0, 0, fac_commoners,[itm_linen_tunic,      itm_hide_boots,itm_straw_hat],def_attrib|level(2),wp(20),knows_inventory_management_10, face_code, face_code_2],
And put tf_dwarf flag to every dwarf on that town.
Or is it got to be that complicated?
 
No, I've already done that. What I'm trying to do is get it so that if a Dwarven kingdom, to use your example, conquers a Human city/village, the Guild Master/Elder/Armorsmith/etc. will dynamically change to be dwarves without editing the game.

I've noticed a greviously idiotic error in the previous example (I was checking the kingdom against the culture, not the culture against the culture), fixed it, but still not working- Dwarven villages are switching to have Human elders when under the control of a Dwarven kingdom, and human kingdoms aren't switching to dwarven leaders ever.

Here's the code for the villages, which is what I'm working on, since it's much shorter than the aforeposted town code.

Code:
("change_village_staff_race",
	[
       (store_script_param, ":village_no", 1),
       (store_faction_of_party, ":center_faction", ":village_no"),
	   (faction_get_slot, ":center_culture", ":center_faction"),
	   (party_get_slot, ":town_mayor", ":village_no", slot_town_elder),
	   
	   (troop_get_type, ":mayor_race", ":town_mayor"),
	   
		(try_begin),
			(this_or_next|eq, ":center_culture", fac_culture_7),
			(eq, ":center_culture", fac_culture_tamek),
			(try_begin),
				(eq, ":mayor_race", 0),
				(troop_set_type, ":town_mayor", 2),
			(else_try),
				(eq, ":mayor_race", 1),
				(troop_set_type, ":town_mayor", 3),
			(try_end),
		(else_try),
			(neq, ":center_culture", fac_culture_7),
			(neq, ":center_culture", fac_culture_tamek),
			(try_begin),
				(eq, ":mayor_race", 2),
				(troop_set_type, ":town_mayor", 0),
			(else_try),
				(eq, ":mayor_race", 3),
				(troop_set_type, ":town_mayor", 1),
			(try_end),
		(try_end),
			
	]),

EDIT: Once again, I sighted a grevious error (I wasn't telling the :center_culture part to check the culture), fixed it, and it is now working flawlessly.
 
Code:
  (try_begin),
    (eq, ":mayor_race", 0),
      (troop_set_type, ":town_mayor", 2),
  (else_try),
    (eq, ":mayor_race", 1),
      (troop_set_type, ":town_mayor", 3),
  (try_end),
Code:
    (val_add, ":mayor_race", 2), # equivalent to above
Code:
  (else_try),
    (neq, ":center_culture", fac_culture_7),    # If it were, this block had not been reached.
    (neq, ":center_culture", fac_culture_tamek),
 
Can mayor_race ever be not 0 nor 1? Honour is like overhead: a luxury.
... If it can indeed, that would be the answer to the question I posed - and I question not without purpose.
 
Don't know, but that's an unnecessary (and dishonorable) assumption. In addition, all race numbers should be changed to constants like tf_female and tf_dwarf. There should be no math with those.
 
MadVader said:
[A]ll race numbers should be changed to constants like tf_female and tf_dwarf.
Proficient.
MadVader said:
There should be no math with those.
Why not exploit the knowledge that a transition from race A to race B is equal to the addition of B-A? (addendum due to late revelation: because direct assignment is equivalent but faster!) It would work for n races, as long as the amount of genders per race remained constant - which might be a problem for the yet to appear "herm-aphrodisiaCalradia" mod, I concede.
MadVader said:
honor [...] dishonorable
At first I had thought you were merely quipping, but now I am unsure: Is this an established term of some sort, similar to the often abused "evil" (as in: "evil code", a superlative for "bad")? It would be an even more dangerous terminology...

addendum:
Code:
tt_male   = 0
tt_female = 1

tt_human        = 0
tt_human_male   = tt_human + tt_male
tt_human_female = tt_human + tt_female
tt_tamek        = tt_human_female + 1
tt_tamek_male   = tt_tamek + tt_male
tt_tamek_female = tt_tamek + tt_female

troop_types_begin = tt_human
troop_types_end   = tt_tamek_female + 1
Code:
#script_change_troop_race
# INPUT : arg0 = troop, arg1 = new race
# OUTPUT: none
("change_troop_race",[
  (store_script_param_1, ":troop"),
  (store_script_param_2, ":newRace"),

# (is_between, ":newRace", troop_types_begin, troop_types_end),     # optional check if not all invokations are guaranteed to offer valid values
  (troop_get_type, ":currentRace", ":troop"),
# (is_between, ":currentRace", troop_types_begin, troop_types_end), # of course, script should receive cf_-prefix under employ
  (store_and, ":gender", ":currentRace", 1),
  (val_sub, ":currentRace", ":gender"),
  (val_sub, ":newRace", ":currentRace"),
  (val_add, ":currentRace", ":gender"),
  (val_add, ":newRace", ":currentRace"), # Stupid, is it not? I have my weak moments.
  (troop_set_type, ":troop", ":newRace")
]),

#script_change_troop_gender
# INPUT : arg0 = troop, arg1 = new gender in {tt_male, tt_female}
# OUTPUT: none
("change_troop_gender",[
  (store_script_param_1, ":troop"),
  (store_script_param_2, ":newGender"),

# (is_between, ":newGender", tt_male, tt_female + 1),                 # again, check if not invariant
  # only the last bit is of interest and it can be overwritten
  (troop_get_type, ":currentGender", ":troop"),
# (is_between, ":currentGender", troop_types_begin, troop_types_end), # again, add cf_-prefix if employed
  (val_and, ":currentGender", 0xFFFFFFFE),  # sets last bit to 0
  (val_or, ":currentGender", ":newGender"), # sets last bit to 1 if newGender is 1, or not if not
  (troop_set_type, ":troop", ":newGender"),
])
Math does exist to serve, its beauty is just a bonus.
 
Your Tamek math is unnecessary (and dishonorable), at that level you should just assign numbers, because you need to know how they map to the skins. Using math to add apples and oranges is without... honor.
Pulling your leg with "honor", that's just Klingon-speak. :smile:
 
Bah, I see it now. The two races are a special case, in larger jumps with arbitrary direction, the formula is cancelled down to direct assignment - and should therefore be implemented as such.

... You know, you could have just told me, so that I had not have to suffer a revelation while brushing my teeth, before coffee and breakfast and webcomics... and clothes.

Totally had me going with the "honour"-talk, too. Well done, well done.
 
Back
Top Bottom