cucas
Regular

Hey everyone!
I was thinking about adding a basic encumbrance system to my private mod.
So far, I've already tried two systems, unsuccessfully. One in which your weight affects your skills and the other in which the equipment itself will affect your skills. Maybe there's a more straightforward method?
I've been trying this for days, editing the *.PYs, researching, etc, but I just can't seem to get something this simple right...
Thanks, I'll release the script here for the public if I manage to get it to work!
Here is my research so far:
1. Insert this code in module_scripts.py (green color is original text, blue is text to insert)
# -*- coding: cp1254 -*-
from header_common import *
from header_operations import *
from module_constants import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_music import *
from header_map_icons import *
from ID_animations import *
#from header_presentations import *
### > Encumbrance System: Part 1/3
def get_hrd_weight
:
a = (y >> ibf_weight_bits) & ibf_armor_mask
return int(25 * a)
def set_item_score():
item_score = []
for i_item in xrange(len(items)):
## weight
item_score.append((item_set_slot, i_item, slot_item_weight, get_hrd_weight(items[i_item][6])))
### < Encumbrance System: Part 1/3
####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################
(...)
#script_game_get_skill_modifier_for_troop
# This script is called from the game engine when a skill's modifiers are needed
# INPUT: arg1 = troop_no, arg2 = skill_no
# OUTPUT: trigger_result = modifier_value
("game_get_skill_modifier_for_troop",
[(store_script_param, ":troop_no", 1),
(store_script_param, ":skill_no", 2),
(assign, ":modifier_value", 0),
(try_begin),
(eq, ":skill_no", "skl_wound_treatment"),
(call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_wound_treatment_reference"),
(gt, reg0, 0),
(val_add, ":modifier_value", 1),
(else_try),
(eq, ":skill_no", "skl_trainer"),
(call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_training_reference"),
(gt, reg0, 0),
(val_add, ":modifier_value", 1),
(else_try),
(eq, ":skill_no", "skl_surgery"),
(call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_surgery_reference"),
(gt, reg0, 0),
(val_add, ":modifier_value", 1),
### > Encumbrance System: Part 2/3
(else_try),
(eq, ":skill_no", "skl_riding"),
(eq, "$g_encumbrance_penalty", 1),
(this_or_next|eq, ":troop_no", "trp_player"),
(is_between, ":troop_no", companions_begin, companions_end),
(main_party_has_troop, ":troop_no"), ##Floris fix so companions-as-lords aren't affected
(store_attribute_level, ":agi", ":troop_no", ca_agility),
(call_script, "script_get_total_equipment_weight", ":troop_no"),
(assign, ":total_weight", reg0),
(val_sub, ":total_weight", 10),
(val_sub, ":total_weight", ":agi"),
(val_div, ":total_weight", 10),
(store_sub, ":modifier_value", 0, ":total_weight"),
(val_min, ":modifier_value", 0),
(else_try),
(eq, ":skill_no", "skl_power_draw"),
(eq, "$g_encumbrance_penalty", 1),
(this_or_next|eq, ":troop_no", "trp_player"),
(is_between, ":troop_no", companions_begin, companions_end),
(main_party_has_troop, ":troop_no"), ##Floris fix so companions-as-lords aren't affected
(store_attribute_level, ":str", ":troop_no", ca_strength),
(call_script, "script_get_total_equipment_weight", ":troop_no"),
(assign, ":total_weight", reg0),
(val_sub, ":total_weight", 10),
(val_sub, ":total_weight", ":str"),
(val_div, ":total_weight", 10),
(store_sub, ":modifier_value", 0, ":total_weight"),
(val_min, ":modifier_value", 0),
(else_try),
(eq, ":skill_no", "skl_horse_archery"),
(eq, "$g_encumbrance_penalty", 1),
(this_or_next|eq, ":troop_no", "trp_player"),
(is_between, ":troop_no", companions_begin, companions_end),
(main_party_has_troop, ":troop_no"), ##Floris fix so companions-as-lords aren't affected
(store_attribute_level, ":agi", ":troop_no", ca_agility),
(store_attribute_level, ":str", ":troop_no", ca_strength),
(call_script, "script_get_total_equipment_weight", ":troop_no"),
(assign, ":total_weight", reg0),
(val_mul, ":total_weight", 2),
(val_sub, ":total_weight", 20),
(val_sub, ":total_weight", ":agi"),
(val_sub, ":total_weight", ":str"),
(val_div, ":total_weight", 10),
(store_sub, ":modifier_value", 0, ":total_weight"),
(val_min, ":modifier_value", 0),
### < Encumbrance System: Part 2/3
(try_end),
(set_trigger_result, ":modifier_value"),
]),
### > Encumbrance System: Part 3/3
# script_get_total_equipment_weight:
# INPUT:
# param1: troop_no
# OUTPUT: total equipment weight
("get_total_equipment_weight",[
(store_script_param_1, ":troop_no"),
(assign, ":total_weight", 0),
(try_for_range, ":cur_slot", 0, 8 ),
(troop_get_inventory_slot, ":cur_item", ":troop_no", ":cur_slot"),
(ge, ":cur_item", 0),
(item_get_slot, ":cur_item_weight", ":cur_item", slot_item_weight),
(val_add, ":total_weight", ":cur_item_weight"),
(try_end),
(val_div, ":total_weight", 100),
(assign, reg0, ":total_weight"),
]),
### < Encumbrance System: Part 3/3
(...)
2. Put this in module_constants.py
Simple, huh? Well, apparently, this isn't working yet. =/
So, if you could lend a hand, it'd be great! This simple system, would be a very nice addition to any mod. It could balance tremendously the game.
I was thinking about adding a basic encumbrance system to my private mod.
So far, I've already tried two systems, unsuccessfully. One in which your weight affects your skills and the other in which the equipment itself will affect your skills. Maybe there's a more straightforward method?
I've been trying this for days, editing the *.PYs, researching, etc, but I just can't seem to get something this simple right...
Thanks, I'll release the script here for the public if I manage to get it to work!
Here is my research so far:
1. Insert this code in module_scripts.py (green color is original text, blue is text to insert)
# -*- coding: cp1254 -*-
from header_common import *
from header_operations import *
from module_constants import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_music import *
from header_map_icons import *
from ID_animations import *
#from header_presentations import *
### > Encumbrance System: Part 1/3
def get_hrd_weight
a = (y >> ibf_weight_bits) & ibf_armor_mask
return int(25 * a)
def set_item_score():
item_score = []
for i_item in xrange(len(items)):
## weight
item_score.append((item_set_slot, i_item, slot_item_weight, get_hrd_weight(items[i_item][6])))
### < Encumbrance System: Part 1/3
####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################
(...)
#script_game_get_skill_modifier_for_troop
# This script is called from the game engine when a skill's modifiers are needed
# INPUT: arg1 = troop_no, arg2 = skill_no
# OUTPUT: trigger_result = modifier_value
("game_get_skill_modifier_for_troop",
[(store_script_param, ":troop_no", 1),
(store_script_param, ":skill_no", 2),
(assign, ":modifier_value", 0),
(try_begin),
(eq, ":skill_no", "skl_wound_treatment"),
(call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_wound_treatment_reference"),
(gt, reg0, 0),
(val_add, ":modifier_value", 1),
(else_try),
(eq, ":skill_no", "skl_trainer"),
(call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_training_reference"),
(gt, reg0, 0),
(val_add, ":modifier_value", 1),
(else_try),
(eq, ":skill_no", "skl_surgery"),
(call_script, "script_get_troop_item_amount", ":troop_no", "itm_book_surgery_reference"),
(gt, reg0, 0),
(val_add, ":modifier_value", 1),
### > Encumbrance System: Part 2/3
(else_try),
(eq, ":skill_no", "skl_riding"),
(eq, "$g_encumbrance_penalty", 1),
(this_or_next|eq, ":troop_no", "trp_player"),
(is_between, ":troop_no", companions_begin, companions_end),
(main_party_has_troop, ":troop_no"), ##Floris fix so companions-as-lords aren't affected
(store_attribute_level, ":agi", ":troop_no", ca_agility),
(call_script, "script_get_total_equipment_weight", ":troop_no"),
(assign, ":total_weight", reg0),
(val_sub, ":total_weight", 10),
(val_sub, ":total_weight", ":agi"),
(val_div, ":total_weight", 10),
(store_sub, ":modifier_value", 0, ":total_weight"),
(val_min, ":modifier_value", 0),
(else_try),
(eq, ":skill_no", "skl_power_draw"),
(eq, "$g_encumbrance_penalty", 1),
(this_or_next|eq, ":troop_no", "trp_player"),
(is_between, ":troop_no", companions_begin, companions_end),
(main_party_has_troop, ":troop_no"), ##Floris fix so companions-as-lords aren't affected
(store_attribute_level, ":str", ":troop_no", ca_strength),
(call_script, "script_get_total_equipment_weight", ":troop_no"),
(assign, ":total_weight", reg0),
(val_sub, ":total_weight", 10),
(val_sub, ":total_weight", ":str"),
(val_div, ":total_weight", 10),
(store_sub, ":modifier_value", 0, ":total_weight"),
(val_min, ":modifier_value", 0),
(else_try),
(eq, ":skill_no", "skl_horse_archery"),
(eq, "$g_encumbrance_penalty", 1),
(this_or_next|eq, ":troop_no", "trp_player"),
(is_between, ":troop_no", companions_begin, companions_end),
(main_party_has_troop, ":troop_no"), ##Floris fix so companions-as-lords aren't affected
(store_attribute_level, ":agi", ":troop_no", ca_agility),
(store_attribute_level, ":str", ":troop_no", ca_strength),
(call_script, "script_get_total_equipment_weight", ":troop_no"),
(assign, ":total_weight", reg0),
(val_mul, ":total_weight", 2),
(val_sub, ":total_weight", 20),
(val_sub, ":total_weight", ":agi"),
(val_sub, ":total_weight", ":str"),
(val_div, ":total_weight", 10),
(store_sub, ":modifier_value", 0, ":total_weight"),
(val_min, ":modifier_value", 0),
### < Encumbrance System: Part 2/3
(try_end),
(set_trigger_result, ":modifier_value"),
]),
### > Encumbrance System: Part 3/3
# script_get_total_equipment_weight:
# INPUT:
# param1: troop_no
# OUTPUT: total equipment weight
("get_total_equipment_weight",[
(store_script_param_1, ":troop_no"),
(assign, ":total_weight", 0),
(try_for_range, ":cur_slot", 0, 8 ),
(troop_get_inventory_slot, ":cur_item", ":troop_no", ":cur_slot"),
(ge, ":cur_item", 0),
(item_get_slot, ":cur_item_weight", ":cur_item", slot_item_weight),
(val_add, ":total_weight", ":cur_item_weight"),
(try_end),
(val_div, ":total_weight", 100),
(assign, reg0, ":total_weight"),
]),
### < Encumbrance System: Part 3/3
(...)
2. Put this in module_constants.py
(...)
slot_item_multiplayer_item_class = 61 #temporary, can be moved to higher values
slot_item_multiplayer_availability_linked_list_begin = 62 #temporary, can be moved to higher values
slot_item_weight = 63
slot_item_multiplayer_faction_price_multipliers_begin = 30 #reserve around 10 slots after this
########################################################
## AGENT SLOTS #############################
########################################################
(...)
slot_item_multiplayer_item_class = 61 #temporary, can be moved to higher values
slot_item_multiplayer_availability_linked_list_begin = 62 #temporary, can be moved to higher values
slot_item_weight = 63
slot_item_multiplayer_faction_price_multipliers_begin = 30 #reserve around 10 slots after this
########################################################
## AGENT SLOTS #############################
########################################################
(...)
Simple, huh? Well, apparently, this isn't working yet. =/
So, if you could lend a hand, it'd be great! This simple system, would be a very nice addition to any mod. It could balance tremendously the game.


