I would like to share my code for injuried system, hoping for response and opinions.
This injuried system I use in my module I'm building.
In module_mission_template :
# Dunde's Wounded System Start --------------------------------
wounded_system_init = (
ti_before_mission_start, 0, 0, [],
[
(call_script, "script_do_init_wounded_system"),
])
wounded_system_tick = (
0.1, 0, 0, [],
[
(call_script, "script_do_check_is_any_body_injured"),
])
# Dunde's Wounded System End ----------------------------------
Adding :
wounded_system_init,
wounded_system_tick,
for any mission use wounded system.
in module_script.py :
#-- Dunde'sBegin
#initialization
("do_init_wounded_system",
[
(try_for_range, ":cur_troop", wounded_heroes_begin, wounded_heroes_end), # Check all Heroes, yeah may be isn't effective, but a hero may comes as reinforcement, might he not?
(assign,":troop_id", ":cur_troop"),
(try_begin),
(eq, ":cur_troop", "trp_kingdom_heroes_including_player_begin"),
(assign,":troop_id", "trp_player"),
(try_end),
(store_troop_health,":troop_health", ":troop_id", 0),
(troop_set_slot, ":troop_id", slot_troop_hp, ":troop_health"), # Initial points.
(try_end),
]),
#in battle simulation
("do_check_simulated_batle_injuried",
[
(store_script_param, ":party_id", 1),
(try_for_range, ":troop_no", wounded_heroes_begin, wounded_heroes_end), # Check all Heroes, yeah may be isn't effective, but a hero may comes as reinforcement, might he not?
(assign,":troop_id", ":troop_no"),
(try_begin),
(eq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
(assign,":troop_id", "trp_player"),
(try_end),
(troop_get_slot, ":old_hp", ":troop_id", slot_troop_hp),
(store_troop_health,":hit_points", ":troop_id", 0),
(troop_set_slot, ":troop_id", slot_troop_hp, ":hit_points"),
(store_sub, ":wound", ":old_hp", ":hit_points"),
(gt, ":wound", 0),
(str_clear, s1), (str_clear, s2), (str_clear, s3),
# DUNDE : Ironflesh has effect too...
(store_skill_level, ":skl", "skl_ironflesh", ":troop_id"),
(val_sub, ":wound", ":skl"),
# DUNDE : Add random number...
# Yeach, sometime luck can produce unpredictable result in war.
# Comment lines betwen RANDOM BEGIN and RANDOM END if you don't like it, and prefer exact and predictable formula!
# RANDOM BEGIN -----------------------------------------------------
(assign,":min_bond",-10),
# Dunde's Luck Begin
(troop_get_slot,":luck", ":troop_id", slot_troop_luck),
(store_div, ":luck_factor", ":luck", 10),
(val_sub, ":luck_factor", 5),
(val_add, ":min_bond", ":luck_factor"),
# Dunde's Luck End
(store_random_in_range, ":mod", ":min_bond", 11),
(val_add, ":wound", ":mod"),
# RANDOM END -------------------------------------------------------
(assign, ":penalty", ":wound"),
(party_get_skill_level, ":skl", "skl_first_aid", ":party_id"), # First Aid may be help...
(val_mul, ":skl", 3), # Double it for your favour...
# Random end -----
(try_begin), # OK, let's start counting how bad is the blow destroy your hero!
(lt, ":wound", 25), # less then 25% HP, it's no big deal, just scretch
(assign, ":penalty", 0),
(else_try),
(lt, ":wound", 50), # 25% - 50% HP, it's begin hurt ( 2.5 - 5 hours recovery)
# do nothing
(else_try),
(lt, ":wound", 75), # 50% - 75% HP, it's big blow ( 25 - 50 hours recovery)
(val_sub, ":penalty",25),
(val_mul, ":penalty", 10),
(else_try),
(lt, ":wound", 90), # 40% - 60% HP, it's tereble much (175 - 250 hours recovery)
(val_sub, ":penalty", 40), # Death may be come from this kind of blow..
(val_mul, ":penalty", 50),
(str_store_string, s2, "str_serious"),
(store_random_in_range, ":mod",":luck",101), # OK!!! Your last chance to survive in 75% died, except for lucky one
(val_add, ":mod", ":skl"), # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
(lt, ":mod", 25),
(assign, ":penalty", -1),
(else_try), # more then 95% HP, oh, no! A deadly blow.. No body can survive from that!!! Your luck can't help you anymore...
(val_sub, ":penalty", 40), # 1000 - 1200 hours recovery for survivors
(val_mul, ":penalty", 200),
(str_store_string, s2, "str_deadly"),
(store_random_in_range, ":mod",0,101), # OK!!! Your last chance to survive in 50-50 dice!
(val_add, ":mod", ":skl"), # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
(lt, ":mod", 25),
(assign, ":penalty", -1),
(try_end),
(str_store_troop_name, s1, ":troop_id"),
(troop_get_type, reg3,":troop_id"),
(try_begin),
(lt, ":penalty", 0),
(agent_set_hit_points, ":troop_id", 0, 0),
(troop_set_slot, ":troop_id", slot_troop_death, 1), # Death
(else_try),
(gt, ":penalty", 0),
(val_sub, ":penalty", ":skl"), # First Aid
(val_max, ":penalty", 1), # Even best healer can't do immediate heal or make a hit occurs positive effect.
(try_begin),
(lt, ":wound", 80), # Big Blow is on head or torso only
(store_random_in_range, ":mod", 1, 7), # Part of body that hit.
(else_try),
(store_random_in_range, ":mod", 1, 3), # Head or torso..
(try_end),
(try_begin),
(eq, ":mod", 1),
(troop_get_slot, ":wound", ":troop_id", slot_troop_head_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_head_injuried,":wound"),
(else_try),
(eq, ":mod", 2),
(troop_get_slot, ":wound", ":troop_id", slot_troop_torso_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_torso_injuried,":wound"),
(else_try),
(eq, ":mod", 3),
(troop_get_slot, ":wound", ":troop_id", slot_troop_arm1_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_arm1_injuried,":wound"),
(else_try),
(eq, ":mod", 4),
(troop_get_slot, ":wound", ":troop_id", slot_troop_arm2_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_arm2_injuried,":wound"),
(else_try),
(eq, ":mod", 5),
(troop_get_slot, ":wound", ":troop_id", slot_troop_leg1_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_leg1_injuried,":wound"),
(else_try),
(troop_get_slot, ":wound", ":troop_id", slot_troop_leg2_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_leg2_injuried,":wound"),
(try_end),
(try_end),
(try_end),
]),
#tick to check
("do_check_is_any_body_injured",
[
(try_for_agents, ":agent_id"), # Search in battlefield
(agent_get_troop_id, ":troop_id", ":agent_id"), # Get his Troop ID
(assign, ":mod", 0),
(try_begin),
(ge, ":troop_id", wounded_heroes_begin), # He must be Wounded System's target.
(lt, ":troop_id", wounded_heroes_end),
(assign, ":mod", 1),
(else_try),
(eq, ":troop_id", "trp_player"),
(assign, ":mod", 1),
(end_try),
(gt, ":mod", 0),
(troop_get_slot, ":old_hp", ":troop_id", slot_troop_hp),
(store_agent_hit_points, ":hit_points", ":agent_id", 0),
(troop_set_slot, ":troop_id", slot_troop_hp, ":hit_points"),
(store_sub, ":wound", ":old_hp", ":hit_points"),
(gt, ":wound", 0),
(str_clear, s1), (str_clear, s2), (str_clear, s3),
# DUNDE : Ironflesh has effect too...
(store_skill_level, ":skl", "skl_ironflesh", ":troop_id"),
(val_sub, ":wound", ":skl"),
# DUNDE : Add random number...
# Yeach, sometime luck can produce unpredictable result in war.
# Comment lines betwen RANDOM BEGIN and RANDOM END if you don't like it, and prefer exact and predictable formula!
# RANDOM BEGIN -----------------------------------------------------
(assign,":min_bond",-10),
# Dunde's Luck Begin
(troop_get_slot,":luck", ":troop_id", slot_troop_luck),
(store_div, ":luck_factor", ":luck", 10),
(val_sub, ":luck_factor", 5),
(val_add, ":min_bond", ":luck_factor"),
# Dunde's Luck End
(store_random_in_range, ":mod", ":min_bond", 11),
(val_add, ":wound", ":mod"),
# RANDOM END -------------------------------------------------------
(assign, ":penalty", ":wound"),
(agent_get_party_id, ":party", ":agent_id"),
(party_get_skill_level, ":skl", "skl_first_aid", ":party"), # First Aid may be help...
(val_mul, ":skl", 3), # Double it for your favour...
# Random end -----
(try_begin), # OK, let's start counting how bad is the blow destroy your hero!
(lt, ":wound", 10), # less then 10% HP, it's no big deal, just scretch
(assign, ":penalty", 0),
(else_try),
(lt, ":wound", 25), # 10% - 25% HP, it's begin hurt ( 1 - 5 hours recovery)
(val_sub, ":penalty", 5),
(str_store_string, s2, "str_hurting"),
(else_try),
(lt, ":wound", 40), # 25% - 40% HP, it's big blow ( 20 - 30 hours recovery)
(val_sub, ":penalty",10),
(val_mul, ":penalty", 10),
(str_store_string, s2, "str_big"),
(else_try),
(lt, ":wound", 60), # 40% - 60% HP, it's tereble much (100 - 200 hours recovery)
(val_sub, ":penalty", 20), # Death may be come from this kind of blow..
(val_mul, ":penalty", 50),
(str_store_string, s2, "str_serious"),
(store_random_in_range, ":mod",":luck",101), # OK!!! Your last chance to survive in 75% died, except for lucky one
(val_add, ":mod", ":skl"), # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
(lt, ":mod", 50),
(assign, ":penalty", -1),
(else_try),
(lt, ":wound", 75), # 60% - 75% HP, it's fatal serious (350 - 500 hours recovery)
(val_sub, ":penalty", 25),
(val_mul, ":penalty", 100),
(str_store_string, s2, "str_fatal"),
(store_random_in_range, ":mod",":luck",101), # OK!!! Your last chance to survive in 75% died, except for lucky one
(val_add, ":mod", ":skl"), # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
(lt, ":mod", 75),
(assign, ":penalty", -1),
(else_try), # more then 95% HP, oh, no! A deadly blow.. No body can survive from that!!! Your luck can't help you anymore...
(val_sub, ":penalty", 40), # 700 - 1800 hours recovery for survivors
(val_mul, ":penalty", 200),
(str_store_string, s2, "str_deadly"),
(store_random_in_range, ":mod",0,101), # OK!!! Your last chance to survive in 50-50 dice!
(val_add, ":mod", ":skl"), # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
(lt, ":mod", 75),
(assign, ":penalty", -1),
(try_end),
(str_store_troop_name, s1, ":troop_id"),
(troop_get_type, reg3,":troop_id"),
(try_begin),
(lt, ":penalty", 0),
(store_random_in_range, ":mod", 1, 3),
(try_begin),
(eq, ":mod", 1),
(str_store_string, s2, "str_torso"),
(else_try),
(str_store_string, s2, "str_head"),
(try_end),
(display_message, "@{s1} 's death for being hit by (s2} at {reg3?his:her} {s3}."),
(agent_set_hit_points, ":troop_id", 0, 0),
(troop_set_slot, ":troop_id", slot_troop_death, 1), # Death
(else_try),
(gt, ":penalty", 0),
(val_sub, ":penalty", ":skl"), # First Aid
(val_max, ":penalty", 1), # Even best healer can't do immediate heal or make a hit occurs positive effect.
(try_begin),
(lt, ":wound", 80), # Big Blow is on head or torso only
(store_random_in_range, ":mod", 1, 7), # Part of body that hit.
(else_try),
(store_random_in_range, ":mod", 1, 3), # Head or torso..
(try_end),
(try_begin),
(eq, ":mod", 1),
(troop_get_slot, ":wound", ":troop_id", slot_troop_head_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_head_injuried,":wound"),
(str_store_string, s3, "str_head"),
(else_try),
(eq, ":mod", 2),
(troop_get_slot, ":wound", ":troop_id", slot_troop_torso_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_torso_injuried,":wound"),
(str_store_string, s3, "str_torso"),
(else_try),
(eq, ":mod", 3),
(troop_get_slot, ":wound", ":troop_id", slot_troop_arm1_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_arm1_injuried,":wound"),
(str_store_string, s3, "str_left_arm"),
(else_try),
(eq, ":mod", 4),
(troop_get_slot, ":wound", ":troop_id", slot_troop_arm2_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_arm2_injuried,":wound"),
(str_store_string, s3, "str_right_arm"),
(else_try),
(eq, ":mod", 5),
(troop_get_slot, ":wound", ":troop_id", slot_troop_leg1_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_leg1_injuried,":wound"),
(str_store_string, s3, "str_left_leg"),
(else_try),
(troop_get_slot, ":wound", ":troop_id", slot_troop_leg2_injuried),
(val_add, ":wound", ":penalty"),
(troop_set_slot, ":troop_id", slot_troop_leg2_injuried,":wound"),
(str_store_string, s3, "str_right_arm"),
(try_end),
(display_message, "@{s1} 's {s2} hit at {reg3?his:her} {s3}."),
(try_end),
(try_end),
]),
#calculate how bad injuried is
# output : reg0 = penalty
("calculate_injuried_penalty",
[
(store_script_param, ":injuried", 1),
(try_begin),
(lt, ":injuried", 100),
(assign, reg0, 0),
(else_try),
(lt, ":injuried", 300),
(assign, reg0, 1),
(else_try),
(lt, ":injuried", 700),
(assign, reg0, 2),
(else_try),
(assign, reg0, 3),
(try_end),
]),
#calculate penalty
# output : reg0 = penalty
("calculate_injuried_skill_penalty",
[
(store_script_param, ":troop_id", 1),
(store_script_param, ":skill_id", 2),
(troop_get_slot, ":temp_inj", ":troop_id", slot_troop_head_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":head", reg0),
(troop_get_slot, ":temp_inj",":troop_id", slot_troop_torso_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":torso", reg0),
(troop_get_slot, ":temp_inj", ":troop_id", slot_troop_arm1_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":arm1", reg0),
(troop_get_slot, ":temp_inj", ":troop_id", slot_troop_arm2_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":arm2", reg0),
(troop_get_slot, ":temp_inj", ":troop_id", slot_troop_leg1_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":leg1", reg0),
(troop_get_slot, ":temp_inj", ":troop_id", slot_troop_leg2_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":leg2", reg0),
(assign, reg0, 0),
(try_begin), # need consentration
(this_or_next|eq, ":skill_id", "skl_trade"), (this_or_next|eq, ":skill_id", "skl_leadership"),
(this_or_next|eq, ":skill_id", "skl_engineer"), (this_or_next|eq, ":skill_id", "skl_first_aid"),
(this_or_next|eq, ":skill_id", "skl_surgery"), (this_or_next|eq, ":skill_id", "skl_wound_treatment"),
(this_or_next|eq, ":skill_id", "skl_spotting"), (this_or_next|eq, ":skill_id", "skl_pathfinding"),
(this_or_next|eq, ":skill_id", "skl_tactics"), (this_or_next|eq, ":skill_id", "skl_trainer"), (eq, ":skill_id", "skl_horse_archery"),
(val_add, reg0, ":head"),
(try_end),
(try_begin), # overall health
(this_or_next|eq, ":skill_id", "skl_athletics"), (eq, ":skill_id", "skl_ironflesh"),
(val_add, reg0, ":torso"),
(try_end),
(try_begin), # need booth hand minors
(this_or_next|eq, ":skill_id", "skl_first_aid"), (this_or_next|eq, ":skill_id", "skl_wound_treatment"),
(this_or_next|eq, ":skill_id", "skl_surgery"), (eq, ":skill_id", "skl_horse_archery"),
(assign, ":temp_inj", ":arm1"), (val_add, ":temp_inj", ":arm2"), (val_div, ":temp_inj", 2),
(val_add, reg0, ":temp_inj"),
(try_end),
(try_begin), # need right hand more
(this_or_next|eq, ":skill_id", "skl_power_draw"), (this_or_next|eq, ":skill_id", "skl_power_throw"),
(this_or_next|eq, ":skill_id", "skl_power_strike"), (eq, ":skill_id", "skl_weapon_master"),
(assign, ":temp_inj", ":arm2"), (val_mul, ":temp_inj", 2), (val_add, ":temp_inj", ":arm1"), (val_div, ":temp_inj", 2),
(val_add, reg0, ":temp_inj"),
(try_end),
(try_begin), # need left hand only
(eq, ":skill_id", "skl_shield"),
(assign, ":temp_inj", ":arm1"), (val_mul, ":temp_inj", 3), (val_div, ":temp_inj", 2),
(val_add, reg0, ":temp_inj"),
(try_end),
(try_begin), # need legs
(eq, ":skill_id", "skl_athletics"),
(assign, ":temp_inj", ":leg1"), (val_add, ":temp_inj", ":leg2"),
(val_add, reg0, ":temp_inj"),
(try_end),
(try_begin), # need armst & legs
(eq, ":skill_id", "skl_riding"),
(assign, ":temp_inj", ":leg1"), (val_add, ":temp_inj", ":leg2"), (val_add, ":temp_inj", ":arm1"), (val_add, ":temp_inj", ":arm2"), (val_div, ":temp_inj", 3),
(val_add, reg0, ":temp_inj"),
(try_end),
]),
#treat injuried
("do_treat_injuried",
[
(store_script_param, ":troop_id", 1),
(store_script_param, ":heal", 2),
(try_for_range, ":injuried_type", injuried_begin, injuried_end),
(troop_get_slot, ":injuried", ":troop_id", ":injuried_type"),
(val_sub, ":injuried", ":heal"),
(troop_set_slot, ":troop_id", ":injuried_type", ":injuried"),
(try_end),
]),
# script_dunde_get_injuried_text
# input : troop_id ;
# output : S1 - S6 ; injuried state in text
("dunde_get_injuried_text",
[
(store_script_param, ":troop_id", 1),
(troop_get_type, reg13, ":troop_id"),
(troop_get_slot, ":injuried", ":troop_id", slot_troop_head_injuried),
(assign, reg1, ":injuried"),
(try_begin),
(lt, ":injuried", 100),
(str_clear, s1),
(else_try),
(lt, ":injuried", 300),
(str_store_string, s1, "@light concussion"),
(else_try),
(lt, ":injuried", 700),
(str_store_string, s1, "@heavy concussion"),
(else_try),
(str_store_string, s1, "@cracked bone"),
(try_end),
(troop_get_slot, ":injuried", ":troop_id", slot_troop_torso_injuried),
(assign, reg2, ":injuried"),
(try_begin),
(lt, ":injuried", 100),
(str_clear, s2),
(else_try),
(lt, ":injuried", 300),
(str_store_string, s2, "@light wound in {reg13?her:his}"),
(else_try),
(lt, ":injuried", 700),
(str_store_string, s2, "@severe wound in {reg13?her:his} chest"),
(else_try),
(str_store_string, s2, "@tereble internal bleeding"),
(try_end),
(troop_get_slot, ":injuried", ":troop_id", slot_troop_arm1_injuried),
(assign, reg3, ":injuried"),
(try_begin),
(lt, ":injuried", 100),
(str_clear, s3),
(else_try),
(lt, ":injuried", 300),
(str_store_string, s3, "@light wound in {reg13?her:his} left arm"),
(else_try),
(lt, ":injuried", 700),
(str_store_string, s3, "@severe wound in {reg13?her:his} left arm"),
(else_try),
(str_store_string, s3, "@broken left arm"),
(try_end),
(troop_get_slot, ":injuried", ":troop_id", slot_troop_arm2_injuried),
(assign, reg4, ":injuried"),
(try_begin),
(lt, ":injuried", 100),
(str_clear, s4),
(else_try),
(lt, ":injuried", 300),
(str_store_string, s4, "@light wound in {reg13?her:his} right arm"),
(else_try),
(lt, ":injuried", 700),
(str_store_string, s4, "@severe wound in {reg13?her:his} right arm"),
(else_try),
(str_store_string, s4, "@broken right arm"),
(try_end),
(troop_get_slot, ":injuried", ":troop_id", slot_troop_leg1_injuried),
(assign, reg5, ":injuried"),
(try_begin),
(lt, ":injuried", 100),
(str_clear, s5),
(else_try),
(lt, ":injuried", 300),
(str_store_string, s5, "@light wound in {reg3?her:his} left leg"),
(else_try),
(lt, ":injuried", 700),
(str_store_string, s5, "@severe wound in {reg13?her:his} left leg"),
(else_try),
(str_store_string, s5, "@broken left leg"),
(try_end),
(troop_get_slot, ":injuried", ":troop_id", slot_troop_leg2_injuried),
(assign, reg6, ":injuried"),
(try_begin),
(lt, ":injuried", 100),
(str_clear, s6),
(else_try),
(lt, ":injuried", 300),
(str_store_string, s6, "@light wound in {reg13?her:his} right leg"),
(else_try),
(lt, ":injuried", 700),
(str_store_string, s6, "@severe wound in {reg13?her:his} left leg"),
(else_try),
(str_store_string, s6, "@broken right leg"),
(try_end),
]),
#-- Dunde's Wounded System End