Author Topic: Python script/scheme/source exchange  (Read 21714 times)

Highlander

  • Guest
Re: Python script/scheme/source exchange
« Reply #15 on: July 07, 2007, 10:17:07 AM »
Getting a parties map coordinates.

in module_parties:
  ("x70y-70","collective_enemy",pf_disabled, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(70,-70),[]),
  ("x70y70","collective_enemy",pf_disabled, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(70,70),[]),

in module_scripts:
("sqrt",[
      (store_script_param_1,':var'),
      (store_script_param_2,':flag'),
      (try_begin),
        (eq,':flag',0),
        (val_add,':var',1),
        (val_div,':var',2),
        (assign,'$return',0),
      (try_end),
      (try_begin),
        (gt,':var','$return'),
        (val_sub,':var','$return'),
        (val_add,'$return',1),
        (call_script,"script_sqrt",':var',1),
      (try_end),
   ]),
# Calculate the coordinates of party on the map
("calculate_coords",
[
(store_distance_to_party_from_party,reg(6),"p_x70y70","p_x70y-70"),
(store_distance_to_party_from_party,reg(9),"p_x70y-70","p_main_party"),
(store_distance_to_party_from_party,reg(10),"p_x70y70","p_main_party"),

(store_mul,":ph2",reg(6),reg(6)),
(store_mul,":bh2",reg(9),reg(9)),
(store_mul,":ah2",reg(10),reg(10)),
(store_add,":pm2",reg(6),reg(6)),

(store_sub,reg(11),":ph2",":bh2"),
(store_add,reg(12),reg(11),":ah2"),
(val_div,reg(12),":pm2"),

(assign,"$pos_x",reg(12)),

(store_mul,":xh2","$pos_x","$pos_x"),

(store_sub,reg(11),":ah2",":xh2"),

(call_script,"script_sqrt",reg(11)),

(assign,"$pos_y",'$return'),

(val_sub,"$pos_y",70),
(val_sub,"$pos_x",70),
(val_mul,"$pos_y",-1),
(val_mul,"$pos_x",-1),

]),

change the red numbers to the map's max_y and the blue one to the map's min_y. It does only work on quadratic maps, but with some work it would work on others as well.
Not all the credit go to me, since the square root script is by Manitas and the whole thing is inspirated by Amarillo's Agent coordination script.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Python script/scheme/source exchange
« Reply #16 on: October 14, 2007, 11:23:23 PM »
Here's a little script I wrote as a shortcut to lots of tedious manual looping:

  ("loop_input_script",
   [
   (store_script_param, ":input_script",1),
   (store_script_param, ":input_loops",2),
   (store_script_param, ":input_script_range_low",3),
   (store_script_param, ":input_script_range_high",4),
   (store_script_param, ":input_script_param_1",5),
   (store_script_param, ":input_script_param_2",6),
   (store_script_param, ":input_script_param_3",7),
   (store_script_param, ":input_script_param_4",8),
   (store_script_param, ":input_script_param_5",9),
   (store_script_param, ":input_script_param_6",10),

   (assign,"$output",-1),
   (assign, ":loops", 1),
      (try_for_range,":unused",0,":loops"),
      (lt,":loops",":input_loops"),
      (call_script,":input_script",":input_script_param_1",":input_script_param_2",":input_script_param_3",":input_script_param_4",":input_script_param_5",":input_script_param_6"),
      (assign,"$output",reg0),
      (neg|is_between,"$output",":input_script_range_low",":input_script_range_high"),
      (val_add,":loops",1),
      (try_end),
   ]),


It can be called like in this example:    (call_script,"script_loop_input_script","script_cf_select_random_center_with_faction",100,towns_begin,castles_end,":faction",0,0,0,0,0),


This script calls an input script for a number of times up to the value of ":input_loops" or until success of the input script. It will work for any input script that outputs to reg0 and whose output is a single integer or range.

I imagine it could be made somewhat more elegant with some effort, but I'm not in the mood for it just now.
« Last Edit: October 14, 2007, 11:25:54 PM by Winter »

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Python script/scheme/source exchange
« Reply #17 on: October 15, 2007, 02:36:26 PM »
Note on Winter's above script - one elegant feature of the parameters system is that it auto-fills zeroes if there are fewer parameters than requested*.  So in Winter's example, it would be more cleanly expressed with the five zeroes at the end omitted - just the trailing ) after ":faction".

* Caveat - not yet tested on (store_script_param), this is 0.808 behaviour from (store_script_param_1) and its twin, not to mention all of the header_operations ops.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Python script/scheme/source exchange
« Reply #18 on: October 15, 2007, 03:21:26 PM »
Note on Winter's above script - one elegant feature of the parameters system is that it auto-fills zeroes if there are fewer parameters than requested*.  So in Winter's example, it would be more cleanly expressed with the five zeroes at the end omitted - just the trailing ) after ":faction".

* Caveat - not yet tested on (store_script_param), this is 0.808 behaviour from (store_script_param_1) and its twin, not to mention all of the header_operations ops.

I added the zeroes because I've been having trouble with 'illegal script param' error messages in-game, and I didn't want to put a possibly buggy script up here.

Highlander

  • Guest
Re: Python script/scheme/source exchange
« Reply #19 on: November 05, 2007, 12:34:03 PM »
To get the rotation around x (can be also used for y in a slightly modified version).
input: 20 is the position you want the information from.
output: reg(1) is the rotation around x.
     (init_position,21),
     (position_copy_origin,21,20),
     (position_get_rotation_around_z,reg(1),20),
     (position_rotate_z,21,reg(1)),
     (position_rotate_y,21,90),
     (position_transform_position_to_local,22,21,20),
     (position_get_rotation_around_z,reg(1),22),

Offline KON_Air

  • Craftsman
  • **
  • Posts: 110
    • View Profile
Re: Python script/scheme/source exchange
« Reply #20 on: December 29, 2007, 06:56:52 PM »
Not enough bandits? Go spawn bandits! This simple script when fed with a value will spawn a party from template. For villages press 1... ok that's stupid, for villages it spawns a random bandit party of two preset types, same for towns but for castles the script checks the faction of the castle and spawns a faction specific bandit (deserters for example).

Code: [Select]
  #script_spawn_random_center_bandit:
  # INPUTS:
  #":centersize"
  # 1 village, 2 castle, 3 town
  #OUTPUT:
  # bandits
 ("spawn_random_center_bandit",
   [
   (store_script_param_1, ":center_size"),
    # (display_message, "str_ran"),
(assign, ":bandit_party", -1),
(try_begin),
(eq, ":center_size", 1),
(store_random_in_range, ":random_center", villages_begin, villages_end),
(set_spawn_radius,2),

(store_random_in_range, ":bandit_type", 1, 5),
(try_begin),
(eq, ":bandit_type", 1),
    (spawn_around_party,":random_center","pt_peasant_rebels"),
(else_try),
(spawn_around_party,":random_center","pt_village_bandits"),
(try_end),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (str_store_party_name, s1, ":random_center"),
# (display_message, "str_ran1"),

(else_try),
(eq, ":center_size", 2),
(store_random_in_range, ":random_center", towns_begin, towns_end),
(set_spawn_radius,2),

(store_random_in_range, ":bandit_type2", 1, 10),
(try_begin),
(eq, ":bandit_type2", 1),
(spawn_around_party,":random_center","pt_city_bandits1"),
(else_try),
(spawn_around_party,":random_center","pt_city_bandits2"),
(try_end),

(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (str_store_party_name, s1, ":random_center"),
# (display_message, "str_ran2"),

(else_try),
(eq, ":center_size", 3),
(store_random_in_range, ":random_center", castles_begin, castles_end),
(store_faction_of_party, ":center_faction", ":random_center"),
(try_begin),
(eq, ":center_faction", "fac_kingdom_1"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac1_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (str_store_party_name, s1, ":random_center"),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_2"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac2_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_3"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac3_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_4"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac4_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_5"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac5_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(try_end),
(try_end),
# (display_message, "str_ranb"),
 ]),

Recommended to use with such trigger (given all party templates have same spt assigned);

Code: [Select]
(0, 0, 72, [], [
(call_script, "script_count_parties_of_faction_and_party_type", "fac_outlaws", spt_random_bandit),
(assign, ":random_bandit_count", reg0),
(try_begin),
(lt, ":random_bandit_count", 10),
(call_script,"script_spawn_random_center_bandit", 1),
(call_script,"script_spawn_random_center_bandit", 2),
(call_script,"script_spawn_random_center_bandit", 3),
....etc.
« Last Edit: December 29, 2007, 06:59:09 PM by KON_Air »

Offline KON_Air

  • Craftsman
  • **
  • Posts: 110
    • View Profile
Re: Python script/scheme/source exchange
« Reply #21 on: December 30, 2007, 09:18:36 PM »
Bank stuff, loan, interest and account, not thoroughly tested

Notes; it is a wee bit messy, "$sperk_bcstmr" is a perk (remove its try), trp_pawn_merc was supposed to be a pawn shop owner but became banker etc, etc... bank_clerk is to be used for branches in other towns (I made a single scene, single troop for that, so you can make scenes for all 14 town and still use one troop)... Script is just a mess, but I kinda like it that way, 2500 is good enough for early on with skills and renown players can withdraw ridiculous amounts of money for kicks (thought I'll have inane monetary requirements for some stuff in my mod).

Scripts;

Code: [Select]
#script_credit_calculation
#changes the value of "$lend_max" when called. And is called via dialouge whenever plyr asks for loan
("credit_calculation",[
(try_begin),
(ge, "$bank_account", 0),
(assign, "$lend_max", "$bank_account"),
(else_try),
(eq, "$bank_account", 0),
(assign, "$lend_max", 500),
(try_end),
(troop_get_slot, ":troop_renown", "trp_player", slot_troop_renown),
(store_skill_level, ":skl_trade", "skl_trade", "trp_player"),
(store_skill_level, ":skl_persuade", "skl_persuasion", "trp_player"),
(store_add, ":skill_bonus", ":skl_trade"),
(val_add, ":skill_bonus", ":skl_persuade"),
(val_div, ":troop_renown", 100),
(val_div, ":skill_bonus", 2),

(val_mul, ":skill_bonus", ":troop_renown"),
(val_mul, "$lend_max", ":skill_bonus"),
#Then of course no points in skills may result in a 0 lend_max, thus we make sure player gets at least 2500 denars minimum
(try_begin),
(lt, "$lend_max", 2500),
(assign, "$lend_max", 2500),
(else_try),
#This is the extra boost thingy for lend_max
(val_mul, "$lend_max", 125),
(val_div, "$lend_max", 100),
(try_end),
]),

Triggers;

Code: [Select]
  (24.0 * 7, 0.0, 0.0,
   [],
   [
       (val_mul,"$bank_debt",105),
       (val_div,"$bank_debt",100),
   (try_begin),
   (eq, "$debt_bank_over_due", 1),
       (val_mul,"$bank_debt",102),
       (val_div,"$bank_debt",100),
   (try_end),
    ]
   ),
  (24.0 * 7, 0.0, 0.0,
   [],
   [
       (val_mul,"$bank_account",103),
       (val_div,"$bank_account",100),
   (try_begin),
   (eq, "$sperk_bcstmr", 1),
       (val_mul,"$bank_account",102),
       (val_div,"$bank_account",100),
   (try_end),
    ]
   ),
   
  (0.1, 24.0 * 30, 0.0,
   [(gt, "$bank_debt", 1)],
   [
(assign, "$debt_bank_over_due",1)
    ]
   ),

Dialogues;

Code: [Select]
   [trp_pawn_merc,"start",[],
   "Hello {sir/madam}, how can I help you?", "banker_list",[]],
   [trp_pawn_merc|plyr,"banker_list",[],
   "I would like to review my account.", "banker_account",[]],
   [trp_pawn_merc|plyr,"banker_list",[],
   "I would like buy some precious metals and gems.", "banker_trade",[]],
   [trp_pawn_merc|plyr,"banker_list",[],
   "I was just here to check my safe.", "banker_chat",[]],
    [trp_pawn_merc,"banker_chat", [], "Of course {sir/madam}, it is upstairs first door.", "close_window",[]],
   [trp_pawn_merc,"banker_trade", [], "Ah, of course we have the purest gold and silver and other valuables.", "banker_restart",[[change_screen_trade]]],
 
   
#Tell account Status
   [anyone,"banker_account", [
   (assign, reg1, "$bank_account"),
   (assign, reg2, "$bank_debt"),
   (try_begin),
   (eq, "$bank_account", 0),
   (str_store_string, s1, "@You don't have any money in your account."),
   (else_try),
   (str_store_string, s1, "@You have {reg1} denars in your account."),
   (try_end),
   (try_begin),
   (eq, "$bank_debt", 0),
   (str_store_string, s2, "@_"),
   (else_try),
   (eq, "$debt_bank_over_due", 1),
   (str_store_string, s2, "@You also have a debt of {reg2} denars, which you should pay as soon as possible because I am afraid Trade Guild has blacklisted you."),
   (else_try),
   (str_store_string, s2, "@You also have a debt of {reg2} denars."),
   (try_end),
   ], "{s1} {s2}", "banker_actions",[]],
   
   [anyone|plyr,"banker_actions",[],
   "I would like to deposit money into my account.", "banker_chat_actions_1",[]],
   [anyone|plyr,"banker_actions",[(gt, "$bank_account", 0)],
   "I would like to take money from my account.", "banker_chat_actions_2",[]],
   
   [anyone,"banker_chat_actions_1",[],
   "Sure {sir/madam}, how much would you like to deposit? You will have an interest rate of three percent per week.", "banker_actions_1",[]],
   [anyone,"banker_chat_actions_2",[],
   "Sure {sir/madam}, how much would you like to draw?", "banker_actions_2",[]],
   
   [anyone|plyr,"banker_actions",[(eq, "$bank_debt", 0)],
   "I need a loan.", "banker_chat_actions_3",[]],
   
   [anyone|plyr,"banker_actions",[(gt, "$bank_debt", 1)],
   "I'd like to pay my debt.", "banker_chat_actions_4",[]],
   
   [anyone|plyr,"banker_actions",[],
   "That's all I needed to know.", "banker_restart",[]],
   [anyone,"banker_restart",[],
   "Well {sir/madam}, do you need anything else?", "banker_list",[]],
   
   [anyone|plyr,"banker_actions",[],
   "Goodbye.", "close_window",[]],
   
#Add money to account
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg(0)],[ge,reg(0),500]],
   "I would like to add 500 denars to account.", "banker_add_money",[(assign, "$money_diff", 500)]],
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg(0)],[ge,reg(0),1000]],
   "I would like to add 1000 denars to account.", "banker_add_money",[(assign, "$money_diff", 1000)]],
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg(0)],[ge,reg(0),2500]],
   "I would like to add 2500 denars to account.", "banker_add_money",[(assign, "$money_diff", 2500)]],
#Add all money
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg2], (ge, reg2, 100)],
   "I have {reg2} denars I'd like to deposit all of it.", "banker_add_money",[(assign, "$money_diff", reg2)]],
   [anyone,"banker_add_money",[],
   "Sure {Sir/Madam} {playername}, right away", "banker_account",[
   (troop_remove_gold, "trp_player", "$money_diff"),
   (val_add, "$bank_account", "$money_diff"),
   ]],
   [anyone|plyr,"banker_actions_1",[],
   "Let me think of something else.", "banker_restart",[]],
#Take money from account
   [anyone|plyr,"banker_actions_2",[(gt, "$bank_account", 499)],
   "I would like to withdraw 500 denars from account.", "banker_take_money",[(assign, "$money_diff", 500)]],
   [anyone|plyr,"banker_actions_2",[(gt, "$bank_account", 999)],
   "I would like to withdraw 1000 denars from account.", "banker_take_money",[(assign, "$money_diff", 1000)]],
   [anyone|plyr,"banker_actions_2",[(gt, "$bank_account", 2499)],
   "I would like to withdraw 2500 denars from account.", "banker_take_money",[(assign, "$money_diff", 2500)]],
#Take all money
   [anyone|plyr,"banker_actions_2",[(assign, reg2, "$bank_account")],
   "I'd like to withdraw all {reg2} denars.", "banker_take_money",[(assign, "$money_diff", reg2)]],
   [anyone,"banker_take_money",[],
   "Sure {Sir/Madam} {playername}, right away", "banker_account",[
   (troop_add_gold, "trp_player", "$money_diff"),
   (val_sub, "$bank_account", "$money_diff"),
   ]],
   [anyone|plyr,"banker_actions_2",[],
   "Let me think of something else.", "banker_restart",[]],
#Take a loan
   [anyone,"banker_chat_actions_3",[],
   "Let me see how much we can give you...", "banker_think_actions_3",[
   (call_script, "script_credit_calculation"),
   ]],
   [anyone,"banker_think_actions_3",[(assign, reg3, "$lend_max")],
   "Well {sir/madam} {playername}, we can give you {reg3} and expect you to pay within thirty days. If you don't pay within thirty days the Trade Guild will blacklist you, which will prevent you from trading with merchants. Don't worry thought we will still buy valuables and other stuff from you to make the money you need. Also, well, if they have money, the villages will continue to trade with you too. Are you sure you can make {reg3} denars in a month with an interest rate of five percent? Also when your debt is over due there will be an additional two percent interest.", "banker_actions_3",[]],
   [anyone|plyr,"banker_actions_3",[],
   "I'll take all of it.", "banker_lend_money",[(assign, "$money_diff", "$lend_max")]],
   [anyone|plyr,"banker_actions_3",[],
   "I just need half of it.", "banker_lend_money",[
   (val_div, "$lend_max", 2),
   (assign, "$money_diff", "$lend_max")]],
   [anyone|plyr,"banker_actions_3",[],
   "Let me think of something else.", "banker_restart",[
      (assign, "$bank_debt_end", 0),
  # (assign, "$bank_debt_start", 0),
   ]],
#Set up triggers and other stuff about loan
   [anyone,"banker_lend_money",[
   (store_current_day, "$bank_debt_end"),
 (val_add, "$bank_debt_end", 30),
 (str_store_date, s2, "$bank_debt_end"),
   ],
   "Sure {Sir/Madam} {playername}, right away. Let me see you should pay at {s2}. Other wise you know what can happen.", "banker_account",[
   (troop_add_gold, "trp_player", "$money_diff"),
   (assign, "$bank_debt", "$money_diff"),
   ]],
   
 
#Pay debt
   [anyone,"banker_chat_actions_4",[],
   "Let me see how much you us...", "banker_think_actions_4",[]],
   [anyone,"banker_think_actions_4",[(assign, reg6, "$bank_debt"),
   (str_store_date, s2, "$bank_debt_end"),
   (try_begin),
   (eq, "$debt_bank_over_due", 1),
   (str_store_string, s1, "@and it is overdue, you should pay it as soon as you can."),
   (else_try),
   (eq, "$debt_bank_over_due", 0),
   (str_store_string, s1, "@you still have some time untill the dead line which is {s2}."),
   (try_end),
   ],
   "You owe {reg6} denars {s1}", "banker_actions_4",[]],
   
   [anyone|plyr,"banker_actions_4",[[store_troop_gold,reg(0)],[ge,reg(0),"$bank_debt"]],
   "I'd like to pay all of it and close my debt.", "banker_pay_debt",[]],
   
   [anyone,"banker_pay_debt",[],
   "Oh, great put the money over there and I am writing it down... and your signature here... done. Now you don't owe us any money, any more.", "banker_list",[
      (troop_remove_gold, "trp_player", "$bank_debt"),
  (assign, "$debt_bank_over_due", 0),   
  (assign, "$bank_debt", 0),
  (assign, "$bank_debt_end", 0),
   ]],
   
      [anyone|plyr,"banker_actions_4",[],
   "Let me think of something else.", "banker_restart",[]],   
   
   [trp_bank_clerk,"start",[],
   "Hello {sir/madam}, how may I serve you?", "banker_list",[]],
   [trp_bank_clerk|plyr,"banker_list",[],
   "I would like to review my account.", "banker_account",[]],
   [trp_bank_clerk|plyr,"banker_list",[],
   "I am just looking around.", "close_window",[]],

dunde

  • Guest
Re: Python script/scheme/source exchange
« Reply #22 on: February 09, 2009, 04:56:04 AM »
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

dunde

  • Guest
Re: Python script/scheme/source exchange
« Reply #23 on: February 09, 2009, 04:57:50 AM »
contined from my last post :

in module_constant.py :
#-- Dunde's  Constants Begin ----
slot_troop_luck = 142
slot_troop_hp   = 143
slot_troop_head_injuried = 144
slot_troop_torso_injuried = 145
slot_troop_arm1_injuried = 146
slot_troop_arm2_injuried = 147
slot_troop_leg1_injuried = 148
slot_troop_leg2_injuried = 149
slot_troop_death = 150

then, spawning kingdom heroes in module_simple_triggers.py, changed to :
  # Respawn hero party after kingdom hero is released from captivity.
  (48,
   [
       (try_for_range, ":troop_no", kingdom_heroes_begin, kingdom_heroes_end), 
         (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),                                                            # He is a hero, an a lord.
         #(troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
         (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),                                                                 # He must not be a prisoner
         (neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 1),                                                                      # He must not be leading a party (active)
         # Dunde's Wounded System : 
         (neg|troop_slot_ge, ":troop_no", slot_troop_death, 1),                                                                             # Death Heroes never be respawned. 
         # ---------------------------------------------------------------------------------   
         (store_troop_faction, ":cur_faction", ":troop_no"),                                                                                # DUNDE's NEW KNOWLEDGE :   
         (try_begin),                                                                                                                       # find center of his own faction
           (call_script, "script_cf_select_random_walled_center_with_faction_and_owne r_priority_no_siege", ":cur_faction", ":troop_no"),    #Can fail
           (assign, ":center_no", reg0),
           (call_script, "script_create_kingdom_hero_party", ":troop_no", ":center_no"),
           (party_attach_to_party, "$pout_party", ":center_no"),
         (else_try),
           (neg|faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),                                                           # if faction's destroyed
           (try_begin),
             (is_between, ":troop_no", kings_begin, kings_end),                                                                             # then their king become commoner
             (troop_set_slot, ":troop_no", slot_troop_change_to_faction, "fac_commoners"),
           (else_try),
             (store_random_in_range, ":random_no", 0, 100),
             (lt, ":random_no", 10),                                                                                                        # and the others, 10% chance to join another faction     
             (call_script, "script_cf_get_random_active_faction_except_player_faction_a nd_faction", ":cur_faction"),                        # 90% chance to continue hiding.   
             (troop_set_slot, ":troop_no", slot_troop_change_to_faction, reg0),
           (try_end),
         (try_end),
       (try_end),
    ]),

for luck system :
  # Dunde's Luck Begin --------------------------------------------- 
  (24,                                                  # It's that make luck wave...
   [
       (try_for_range, ":troop_no", wounded_heroes_begin, wounded_heroes_end),  # For all Heroes, let's start with about 50's
          (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, ":current_luck", ":troop_id", slot_troop_luck),
          (store_random_in_range, ":luck", -10, 11),
          (try_begin),
             (gt, ":luck",0),                                  # This loop make bad/good luck is harder to go away
             (val_mul, ":luck", ":current_luck"),
             (val_div, ":luck", 50),
          (else_try),
             (gt, ":current_luck",0),                          # avoiding division by zero
             (val_mul, ":luck", 50),
             (val_div, ":luck", ":current_luck"),
          (try_end),
          (try_begin),
             (eq, ":luck", 0), 
             (store_random_in_range, ":luck", -5, 6),          # Just in case, division make them to nol always
          (try_end),
          (val_add, ":current_luck", ":luck"),         
          (val_add, ":current_luck", ":luck"),
          (val_clamp, ":current_luck", 0, 101),                # Luck is 0 till 100 range
          (troop_set_slot, ":troop_id", slot_troop_luck, ":current_luck"),
      (try_end),   
    ]),
  # Dunde's Luck End ------------------------------------------------ 


in module_scripts.py, initialitation for luck for any heroes :
  ("game_start",
   [
      #Autoloot---
      # initialization hook
      (call_script, "script_init_item_difficulties"),
      #end Autoloot---
      (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
      # -- DUNDE BEGIN ----------------------------------------------------------------------------------
      # Let's redone Luck system
      # ORI : (assign, "$g_player_luck", 200),
      (try_for_range, ":cur_troop", wounded_heroes_begin, wounded_heroes_end),  # For all Heroes, let's start with about 50's
         (store_random_in_range, ":luck", -10, 11),
         (val_add, ":luck", 50),
         (assign,":troop_id", ":cur_troop"),
         (try_begin),
            (eq, ":cur_troop", "trp_kingdom_heroes_including_player_begin"),
            (assign,":troop_id", "trp_player"),     
         (try_end),           
         (troop_set_slot, ":troop_id", slot_troop_luck, ":luck"),
      (try_end),
      # -- DUNDE END ------------------------------------------------------------------------------------
      (troop_set_slot, "trp_player", slot_troop_occupation, slto_kingdom_hero),
      (troop_set_slot, "trp_player", slot_troop_prisoner_of_party, -1),

in module_troops.py :
I move xerina cs. so it closed to another npc so I can select by range all npc for injuried system
# Tavern minstrel.
  ["tavern_minstrel_1","Minstrel","Minstrel",tf_hero|tf_randomize_face, 0, reserved, fac_commoners,[itm_leather_jacket,itm_hide_boots],def_attrib|level(5),wp(20),knows_common,merchant_face_1,merchant_face_2],

#-- DUNDE BEGIN --
# DUNDE : New Locations for Xerina cs, this marked as wounded system begin
#         These bastard tourney champions must be included in woundes system too...
#         What for? For my future plan to redone tournament completely, and perhaps... Hey, don't you want to duel with or recruit them?
#         Btw, wow.... I never realize their level before... And now, I know  why they often beat me in tourney before...
  ["Xerina","Xerina","Xerina",tf_hero|tf_female, scn_the_happy_boar|entry(5),reserved,  fac_commoners,[itm_leather_jerkin,itm_hide_boots],def_attrib|str_15|agi_15|level(39),wp(312),knows_power_strike_5|knows_ironflesh_5|knows_riding_6|knows_power_draw_4|knows_athletics_8|knows_shield_3,0x00000001ac0820074920561d0b51e6ed00000000001d40ed0000000000000000],
  ["Dranton","Dranton","Dranton",tf_hero, scn_the_happy_boar|entry(2),reserved,  fac_commoners,[itm_leather_vest,itm_hide_boots],def_attrib|str_15|agi_14|level(42),wp(324),knows_power_strike_5|knows_ironflesh_7|knows_riding_4|knows_power_draw_4|knows_athletics_4|knows_shield_3,0x0000000a460c3002470c50f3502879f800000000001ce0a00000000000000000],
  ["Kradus","Kradus","Kradus",tf_hero, scn_the_happy_boar|entry(3),reserved,  fac_commoners,[itm_padded_leather,itm_hide_boots],def_attrib|str_15|agi_14|level(43),wp(270),knows_power_strike_5|knows_ironflesh_7|knows_riding_4|knows_power_draw_4|knows_athletics_4|knows_shield_3,0x0000000f5b1052c61ce1a9521db1375200000000001ed31b0000000000000000],
#-- DUNDE END ----


#NPC system changes begin
#Companions
  ["npc1","Borcha","Borcha",tf_hero|tf_unmoveable_in_party_window, 0, reserved, fac_commoners,[itm_khergit_armor,itm_nomad_boots,itm_knife],
   str_8|agi_7|int_12|cha_7|level(3),wp(60),knows_tracker_npc|
   knows_ironflesh_1|knows_power_strike_1|knows_pathfinding_3|knows_athletics_2|knows_tracking_1|knows_riding_2, #skills 2/3 player at that level
   0x00000004bf086143259d061a9046e23500000000001db52c000000000 0000000],
  ["npc2","Marnid","Marnid", tf_hero|tf_unmoveable_in_party_window, 0,reserved, fac_commoners,[itm_linen_tunic,itm_hide_boots,itm_club],


If battle simulation need for injuried to :
module_scripts.py
  #script_game_event_simulate_battle:
  # This script is called whenever the game simulates the battle between two parties on the map.
  # INPUT:
  # param1: Defender Party
  # param2: Attacker Party
  ("game_event_simulate_battle",
    [
       (store_script_param_1, ":root_defender_party"),
       (store_script_param_2, ":root_attacker_party"),

       (try_begin),
         (store_faction_of_party, ":defender_faction", ":root_defender_party"),
         (store_faction_of_party, ":attacker_faction", ":root_attacker_party"),
         (neq, ":defender_faction", "fac_player_faction"),
         (neq, ":attacker_faction", "fac_player_faction"),
         (store_relation, ":reln", ":defender_faction", ":attacker_faction"),
         (ge, ":reln", 0),
         (set_trigger_result, 1),
       (else_try),
         (assign, ":trigger_result", 0),

         (try_begin),
           (this_or_next|eq, "$g_battle_simulation_cancel_for_party", ":root_defender_party"),
           (eq, "$g_battle_simulation_cancel_for_party", ":root_attacker_party"),
           (assign, "$g_battle_simulation_cancel_for_party", -1),
           (assign, "$auto_enter_town", "$g_battle_simulation_auto_enter_town_after_battle"),
           (assign, ":trigger_result", 1),
         (else_try),
           (try_begin),
             (this_or_next|party_slot_eq, ":root_defender_party", slot_party_retreat_flag, 1),
             (party_slot_eq, ":root_attacker_party", slot_party_retreat_flag, 1),
             (assign, ":trigger_result", 1), #End battle!
           (try_end),
           (party_set_slot, ":root_attacker_party", slot_party_retreat_flag, 0),

  ##         (assign, ":cancel_attack", 0),

           (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
           (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),

 #          (call_script, "script_party_count_fit_for_battle", "p_collective_ally"),
           (call_script, "script_party_calculate_strength", "p_collective_ally", 0),
           (assign, ":defender_strength", reg0),
#           (call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
           (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
           (assign, ":attacker_strength", reg0),

           (store_div, ":defender_strength", ":defender_strength", 20),
           (val_min, ":defender_strength", 50),
           (val_max, ":defender_strength", 1),
           (store_div, ":attacker_strength", ":attacker_strength", 20),
           (val_min, ":attacker_strength", 50),
           (val_add, ":attacker_strength", 1),
           (try_begin),
             #For sieges increase attacker casualties and reduce defender casualties.
             (this_or_next|party_slot_eq, ":root_defender_party", slot_party_type, spt_castle),
             (party_slot_eq, ":root_defender_party", slot_party_type, spt_town),
             (val_mul, ":defender_strength", 3),
             (val_div, ":defender_strength", 2),
             (val_div, ":attacker_strength", 2),
           (try_end),

# Dunde's Wounded System Initialitation point ------------------------------------------------------------------------
           (call_script,"script_do_init_wounded_system"),
# --------------------------------------------------------------------------------------------------------------------
       
           (try_begin),
             (neg|is_currently_night), #Don't fight at night
             (inflict_casualties_to_party_group, ":root_attacker_party", ":defender_strength", "p_temp_casualties"),
             (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),
           (try_end),
# Dunde's Wounded System for defender --------------------------------------------------------------------------------
           (call_script, "script_do_check_simulated_batle_injuried", "p_collective_enemy"),
# --------------------------------------------------------------------------------------------------------------------
           (call_script, "script_party_count_fit_for_battle", "p_collective_enemy", 0),
           (assign, ":new_attacker_strength", reg0),

           (try_begin),
#             (gt, ":new_attacker_strength", 0),                            COMMENTED BY DUNDE : Unfair for attacker
             (neg|is_currently_night), #Don't fight at night
             (inflict_casualties_to_party_group, ":root_defender_party", ":attacker_strength", "p_temp_casualties"),
             (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
           (try_end),
# Dunde's Wounded System for attacker --------------------------------------------------------------------------------
           (call_script, "script_do_check_simulated_batle_injuried", "p_collective_ally"),
# --------------------------------------------------------------------------------------------------------------------
           (call_script, "script_party_count_fit_for_battle", "p_collective_ally", 0),
           (assign, ":new_defender_strength", reg0),

           (try_begin),
             (this_or_next|eq, ":new_attacker_strength", 0),
             (eq, ":new_defender_strength", 0),
             # Battle concluded! determine winner

             (try_begin),
               (eq, ":new_attacker_strength", 0),
               (eq, ":new_defender_strength", 0),
               (assign, ":root_winner_party", -1),
               (assign, ":root_defeated_party", -1),
               (assign, ":collective_casualties", -1),
             (else_try),
               (eq, ":new_attacker_strength", 0),
               (assign, ":root_winner_party",   ":root_defender_party"),
               (assign, ":root_defeated_party", ":root_attacker_party"),
               (assign, ":collective_casualties",    "p_collective_enemy"),
             (else_try),
               (assign, ":root_winner_party", ":root_attacker_party"),
               (assign, ":root_defeated_party",  ":root_defender_party"),
               (assign, ":collective_casualties",  "p_collective_ally"),
             (try_end),

             (try_begin),
               (ge, ":root_winner_party", 0),
               (call_script, "script_get_nonempty_party_in_group", ":root_winner_party"),
               (assign, ":nonempty_winner_party", reg0),
               (store_faction_of_party, ":faction_receiving_prisoners", ":nonempty_winner_party"),
               (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),
             (else_try),
               (assign, ":nonempty_winner_party", -1),
             (try_end),

             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_get_num_companion_stacks, ":num_stacks", ":collective_casualties"),
             (else_try),
               (assign, ":num_stacks", 0),
             (try_end),
             (try_for_range, ":troop_iterator", 0, ":num_stacks"),
               (party_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
               (troop_is_hero, ":cur_troop_id"),
               (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
               (troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
               (store_random_in_range, ":rand", 0, 100),
               (str_store_troop_name_link, s1, ":cur_troop_id"),
               (str_store_faction_name_link, s2, ":faction_receiving_prisoners"),
               (store_troop_faction, ":defeated_troop_faction", ":cur_troop_id"),
               (str_store_faction_name_link, s3, ":defeated_troop_faction"),
               (try_begin),
                  (troop_get_slot, ":death", ":cur_troop_id", slot_troop_death),
                  (gt, ":death",0),
                  (display_message,"@{s1} of {s3} was defeated in battle and death... "),
               (else_try),
                 (ge, ":rand", hero_escape_after_defeat_chance),
                 #------ Ga Seru donk.... Bandit juga bisa menawan hero ------------------------------------------------------------------------       
                 #(party_stack_get_troop_id, ":leader_troop_id", ":nonempty_winner_party", 0),
                 #(is_between, ":leader_troop_id", kingdom_heroes_begin, kingdom_heroes_end), #disable non-kingdom parties capturing enemy lords
                 #------------------------------------------------------------------------------------------------------------------------------
                 (party_add_prisoners, ":nonempty_winner_party", ":cur_troop_id", 1),
                 (gt, reg0, 0),
                 #(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 1),
                 (troop_set_slot, ":cur_troop_id", slot_troop_prisoner_of_party, ":nonempty_winner_party"),
                 (display_log_message, "str_hero_taken_prisoner"),
               (else_try),
                 (display_message,"@{s1} of {s3} was defeated in battle but managed to escape."),
               (try_end),
               (try_begin),
                 (store_troop_faction, ":cur_troop_faction", ":cur_troop_id"),
                 (faction_slot_eq, ":cur_troop_faction", slot_faction_marshall, ":cur_troop_id"),
                 #Marshall is defeated, refresh ai.
                 (assign, "$g_recalculate_ais", 1),
               (try_end),
             (try_end),
             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_get_num_prisoner_stacks, ":num_stacks", ":collective_casualties"),
             (else_try),
               (assign, ":num_stacks", 0),
             (try_end),
             (try_for_range, ":troop_iterator", 0, ":num_stacks"),
               (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
               (troop_is_hero, ":cur_troop_id"),
               (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
               (store_troop_faction, ":cur_troop_faction", ":cur_troop_id"),
               (str_store_troop_name_link, s1, ":cur_troop_id"),
               (str_store_faction_name_link, s2, ":faction_receiving_prisoners"),
               (str_store_faction_name_link, s3, ":cur_troop_faction"),
               (display_log_message,"str_hero_freed"),
             (try_end),

             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_clear, "p_temp_party"),
               (assign, "$g_move_heroes", 0), #heroes are already processed above. Skip them here.
               (call_script, "script_party_add_party_prisoners", "p_temp_party", ":collective_casualties"),
               (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", ":collective_casualties"),
               (distribute_party_among_party_group, "p_temp_party", ":root_winner_party"),
               (call_script, "script_clear_party_group", ":root_defeated_party"),
                # -- NNY PATROL BEGIN --
                (call_script,"script_cf_fix_party_size", "p_temp_party",0),       
                # -- NNY PATROL END --
             (try_end),
             (assign, ":trigger_result", 1), #End battle!

             #Center captured
             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_get_slot, ":cur_party_type", ":root_defeated_party", slot_party_type),
               (this_or_next|eq, ":cur_party_type", spt_town),
               (eq, ":cur_party_type", spt_castle),

               (assign, "$g_recalculate_ais", 1),

               (store_faction_of_party, ":winner_faction", ":root_winner_party"),
               (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),

               (str_store_party_name, s1, ":root_defeated_party"),
               (str_store_faction_name, s2, ":winner_faction"),
               (str_store_faction_name, s3, ":defeated_faction"),
               (display_log_message, "str_center_captured"),

               (try_begin),
                    (eq, "$g_encountered_party", ":root_defeated_party"),
  ##                  (display_message, "@Player participation in siege called from g_encountered_party"),
                    (call_script, "script_add_log_entry", logent_player_participated_in_siege, "trp_player",  "$g_encountered_party", 0, "$g_encountered_party_faction"),
               (try_end),
  ##             (try_begin),
  ##                  (eq, "$g_encountered_party_2", ":root_defeated_party"),
  ##                  (display_message, "@Player participation in siege called from game_event_simulate_battle thanks to g_encountered_party"),
  ##             (try_end),
  ##             (try_begin),
  ##                  (eq, "$g_enemy_party", ":root_defeated_party"),
  ##                  (display_message, "@Player participation in siege called from game_event_simulate_battle thanks to g_encountered_party"),
  ##             (try_end),


               (try_begin),
                 (party_get_num_companion_stacks, ":num_stacks", ":root_winner_party"),
                 (gt, ":num_stacks", 0),
                 (party_stack_get_troop_id, ":leader_troop_no", ":root_winner_party", 0),
                 (is_between, ":leader_troop_no", kingdom_heroes_begin, kingdom_heroes_end),
                 (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, ":leader_troop_no"),
               (else_try),
                 (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, -1),
               (try_end),

               (call_script, "script_lift_siege", ":root_defeated_party", 0),
               (call_script, "script_give_center_to_faction", ":root_defeated_party", ":winner_faction"),
               (try_begin),
                 (eq, ":defeated_faction", "fac_player_supporters_faction"),
                 (call_script, "script_add_notification_menu", "mnu_notification_center_lost", ":root_defeated_party", ":winner_faction"),
               (try_end),
               #Reduce prosperity of the center by 5
               (call_script, "script_change_center_prosperity", ":root_defeated_party", -5),
               (call_script, "script_order_best_besieger_party_to_guard_center", ":root_defeated_party", ":winner_faction"),
               (call_script, "script_cf_reinforce_party", ":root_defeated_party"),
               (call_script, "script_cf_reinforce_party", ":root_defeated_party"),
             (try_end),
           (try_end),

           #ADD XP
           (try_begin),
             (party_slot_eq, ":root_attacker_party", slot_party_type, spt_kingdom_hero_party),
             (store_random_in_range, ":random_num",0, 100),
             (lt, ":random_num", 25),
             (gt, ":new_attacker_strength", 0),
             (call_script, "script_upgrade_hero_party", ":root_attacker_party", 1000),
           (try_end),
           (try_begin),
             (party_slot_eq, ":root_defender_party", slot_party_type, spt_kingdom_hero_party),
             (store_random_in_range, ":random_num",0, 100),
             (lt, ":random_num", 25),
             (gt, ":new_defender_strength", 0),
             (call_script, "script_upgrade_hero_party", ":root_defender_party", 1000),
           (try_end),

           (store_random_in_range, ":random_num", 0, 100),
           (try_begin),
             (lt, ":random_num", 10),
  ##           (this_or_next|lt, ":random_num", 10),
  ##           (eq, ":cancel_attack", 1),
             (assign, ":trigger_result", 1), #End battle!
           (try_end),
         (try_end),
         (set_trigger_result, ":trigger_result"),
       (try_end),
  ]),


Healing :
module_simple_triggers.py
  # Dunde's Healing
  (0.5,
   [
       (try_for_parties, ":party_id"),
          (party_get_num_companion_stacks, ":num_stacks", ":party_id"),
          # Seach between troops in parties
          (try_for_range, ":stack_no", 0, ":num_stacks"),
             (party_stack_get_troop_id, ":troop_id", ":party_id", ":stack_no"),
             (is_between, ":troop_id", wounded_heroes_begin, wounded_heroes_end),
             (troop_get_slot, ":death", ":troop_id", slot_troop_death),
             (store_troop_health,":troop_health", ":troop_id", 0),
             (eq, ":death", 0),   
             (assign, ":rest", 0),
             (assign, ":mod", 5), 
             (try_begin),
                (is_between, ":party_id", centers_begin, centers_end),
                (store_skill_level, ":treatment", "skl_wound_treatment", ":troop_id"),
                (assign, ":rest", 1),   
             (else_try), 
                (party_get_skill_level, ":treatment", ":party_id", "skl_wound_treatment"),
                (neg|map_free), (eq, ":party_id", "p_main_party"), (assign, ":rest", 1),
             (try_end),
             (try_begin),
                (eq, ":rest", 1), (val_mul, ":mod", 3),  (val_div, ":mod", 2),   
             (try_end),
             (val_mul, ":mod", ":troop_health"),
             (val_mul, ":treatment", 75),
             (val_add, ":mod", ":treatment"), 
             (val_div, ":mod", 100),
             (call_script, "script_do_treat_injuried", ":troop_id", ":mod"), 
          (try_end),
          (party_get_num_prisoner_stacks , ":num_stacks", ":party_id"),
          # Search between prisoners
          (try_for_range, ":stack_no", 0, ":num_stacks"),
             (party_prisoner_stack_get_troop_id, ":troop_id", ":party_id", ":stack_no"),           
             (is_between, ":troop_id", wounded_heroes_begin, wounded_heroes_end),
             (store_troop_health,":troop_health", ":troop_id", 0),
             (store_skill_level, ":treatment", "skl_wound_treatment", ":troop_id"),
             (assign, ":mod", 5),
             (val_mul, ":mod", ":troop_health"),
             (val_mul, ":treatment", 75),
             (val_add, ":mod", ":treatment"), 
             (val_div, ":mod", 100),
             (call_script, "script_do_treat_injuried", ":troop_id", ":mod"),
          (try_end),             
       (try_end),               # for parties
   ]),     


Hoping someone can help me testing or debugging this.
Thanks.

Dunde
« Last Edit: February 09, 2009, 05:02:47 AM by dunde »