################
# race/gender fix (call before dialogs)
# concept by Keedo420 - http://forums.taleworlds.com/index.php/topic,59300.msg1534679.html#msg1534679
# GS this could also be just a simple mod(2) test of race: with 0 or 1 resulting
("gender_fix",
[
(store_script_param, ":troop_no", 1),
(troop_get_type,":character_race",":troop_no"),
(assign, ":gender",-1), # GS gender curious if any cases outside this tree pop up
(try_begin), #male species
(this_or_next|eq,":character_race",tf_male),
(eq,":character_race",tf_undead),
(assign, ":gender",0),
(else_try), #female species
(this_or_next|eq,":character_race",tf_female),
(eq,":character_race",tf_pretty_female),
(assign, ":gender",1),
(try_end),
(try_begin),
(eq, ":gender", -1),
(assign, reg33, ":character_race"), # want a trap here for now
(display_message, "@{!} ERROR: called script gender_fix with bad argument {reg33}"),
(try_end),
(assign, reg33, ":gender"), #we return the choice as 1 or 0, Female =1 male=0 -1=big problem
#in dialogs 1 is used for the first option of the conditional and 0 for the second one
#{reg33?her:him}
]),
##script_cf_dplmc_troop_is_female
#
#This exists to make it easy to modify this to work with mods that redefine the troop types.
#See script_dplmc_store_troop_is_female
#
#INPUT: arg1: troop_no
#OUTPUT: reg33 0=male 1=female (global written from script_gender_fix) #GS gender updated
("cf_dplmc_troop_is_female",
[
(store_script_param_1, ":troop_no"),
#(ge, ":troop_no", 0),#Undefined behavior when the arguments are invalid.
(try_begin),
(eq, ":troop_no", active_npcs_including_player_begin),
(assign, ":troop_no", "trp_player"),
(try_end),
# (assign, reg33, 0), # GS force male redundant
(try_begin),
(call_script, "script_gender_fix", ":troop_no"), # GS gender change 10 Nov 2014
(try_end),
#The following will make it so, for example, tf_undead does not appear to be female.
#Mods where this is relevant will likely want to tweak it, but this will work in at
#least one that I know of that has non-human lords.
#(eq, ":is_female", tf_female),
]),
##script_dplmc_store_is_female_troop_1_troop_2
#
#This exists to make it easy to modify this to work with mods that redefine the troop types.
#See script_dplmc_store_troop_is_female
#
#INPUT:
# arg1: troop_1
# arg2: troop_2
#OUTPUT:
# reg0: 0 for not female, 1 for female
# reg1: 0 for not female, 1 for female
# reg33: set back to player gender
("dplmc_store_is_female_troop_1_troop_2",
[
(store_script_param_1, ":troop_1"),
(store_script_param_2, ":troop_2"),
(try_begin),
(call_script, "script_gender_fix", ":troop_1"),
(try_end),
(assign, ":is_female_1", reg33),
(try_begin), # GS gender Michadr had a function that assigned a status to "gender_fix" so need to strip that or get stack creep
(call_script, "script_gender_fix", ":troop_2"),
(try_end),
(assign, ":is_female_2", reg33),
(try_begin),
(call_script, "script_gender_fix", "trp_player"),
(try_end),
#The following will make it so, for example, tf_undead does not appear to be female.
#Mods where this is relevant will likely want to tweak it, but this will work in at
#least one that I know of that has non-human lords.
#(try_begin),
# (neq, ":is_female_1", 0),
# (neq, ":is_female_1", 1),
# (assign, ":is_female_1", 0),
#(try_end),
#(try_begin),
# (neq, ":is_female_2", 0),
# (neq, ":is_female_2", 1),
# (assign, ":is_female_2", 0),
#(try_end),
(assign, reg0, ":is_female_1"),
(assign, reg1, ":is_female_2"),
]),
##script_dplmc_store_troop_is_female
#
#This exists to make it easy to modify this to work with mods that redefine the troop types.
#
#If you change this, remember to also change script_cf_dplmc_troop_is_female and
#script_dplmc_store_is_female_troop_1_troop_2
#
#INPUT: arg1: troop_no
#
#OUTPUT:
# reg0: 1 is F, 0 is M for gender of troop_no [and -1 is error trap from gender_fix]
#
("dplmc_store_troop_is_female",
[
(store_script_param_1, ":troop_no"),
(try_begin),
(call_script, "script_cf_dplmc_troop_is_female", "trp_player"), # GS gender refresh reg33 for strings lordlady,sirmadam
(try_end),
(assign, ":return_reg33",reg33), # GS gender to attempt to save reg33 as player gender, implicitly
(try_begin),
(eq, ":troop_no", active_npcs_including_player_begin),
(assign, ":troop_no", "trp_player"),
(try_end),
(assign, reg0, 0), # GS gender default male
(try_begin),
(call_script, "script_gender_fix", ":troop_no"), # GS gender fix attempt ??
(try_end), # GS currently gender_fix overwrites reg33, which I'd like to stay player's gender
(assign, reg0, reg33), #
(assign, reg33, ":return_reg33"), # GS trying to save reg33 as implicit player gender
#(try_begin),
# (neq, reg0, 0),
# (neq, reg0, 1),
# (assign, reg0, 0),#e.g. this would apply to tf_undead
#(try_end),
]),
("dplmc_store_troop_is_female_reg",
[
(store_script_param_1, ":troop_no"),
(store_script_param_2, ":reg_no"),
(try_begin),
(call_script, "script_cf_dplmc_troop_is_female", "trp_player"), # GS gender refresh reg33 for strings lordlady,sirmadam
(try_end),
(assign, ":return_reg33",reg33), # GS gender to attempt to save reg33 as player gender, implicitly
(try_begin),
(call_script, "script_gender_fix", ":troop_no"), # GS gender fix ??
(try_end), # returns reg33 as sex 0 male 1 female
#The following will make it so, for example, tf_undead does not appear to be female.
#Mods where this is relevant will likely want to tweak it, but this will work in at
#least one that I know of that has non-human lords.
#(try_begin),
# (neq, ":is_female", 0),
# (neq, ":is_female", 1),
# (assign, ":is_female", 0),
#(try_end),
##Can asign to registers 0,1,2,3, 65, or 4
(try_begin),
(eq, ":reg_no", 4),
(assign, reg4, reg33), # GS gender
(else_try),
(eq, ":reg_no", 3),
(assign, reg3, reg33),
(else_try),
(eq, ":reg_no", 2),
(assign, reg2, reg33),
(else_try),
(eq, ":reg_no", 1),
(assign, reg1, reg33),
(else_try),
(eq, ":reg_no", 0),
(assign, reg0, reg33),
(else_try),
(eq, ":reg_no", 65),
(assign, reg65, reg33),
(else_try),
##default to reg4
(assign, reg4, ":reg_no"),
(display_message, "@{!} ERROR: called script dplmc-store-troop-is-female-reg with bad argument {reg4}"),
(assign, reg4, reg33),
(try_end),
(assign, reg33,":return_reg33"), # GS gender "about the player" sets reg33 = player gender cleanup
]),