It's code of DEPLETING AMMO in use. The methods is checking all weapon wielded by agents before quitting missions, if they are ammo then save the ammount into a dummy troop's slots.
Then we use the slots' value to set the troop's ammo inventory.
A dummy troop to save the array :
The slot :
The scripts
We must save agent's ammo just before quiting mission. for battle's mission, script_count_mission_casualties_from_agents is a good place for it has loops for all agents already.
It's tricky for non battle missions, we should take care of any possibile ti_on_leave_area and ti_tab_pressed,
adding this line to execute :
Assigning the ammo values to troops :
- When on the world map.
- And may be at menus that the mission ending jump to.
Add this line :
Don't worry about double/tripple calling of script_adjust_troops_ammo, only the 1st call has effect for it will reset the slots.
PS. It's not fix version yet for there are issues that should be fixed yet. I posted it here just to make harry's thread clean.
Then we use the slots' value to set the troop's ammo inventory.
A dummy troop to save the array :
Code:
["ammo", "{!}na","{!}na",tf_hero|tf_inactive,0,reserved,fac_neutral,[],0,0,0,0],
The slot :
Code:
slot_item_max_ammo = 101 # use another slot number if you wish
The scripts
Code:
def set_item_max_ammo():
item_max_ammo = []
for i_item in xrange(len(items)):
type = items[i_item][3] & 0x000000ff
if (type==itp_type_bow)|(type==itp_type_crossbow)|(type==itp_type_pistol)|(type==itp_type_musket):
item_max_ammo.append((item_set_slot, i_item, slot_item_max_ammo, get_max_ammo(items[i_item][6])))
return item_max_ammo[:]
Code:
(call_script, "script_init_max_ammo"),
Code:
# Dunde's Depleted Ammo BEGIN
("init_max_ammo", set_item_max_ammo()),
("save_agent_ammo_to_slot",
[(store_script_param_1, ":agent_no"),
(agent_get_troop_id, ":troop_no", ":agent_no"),
(try_begin),
(troop_is_hero, ":troop_no"),
#(this_or_next|eq, ":troop_no", "trp_player"),
#(main_party_has_troop, ":troop_no"),
(store_and, ":troop_bits", ":troop_no", 0xFFFF),
(val_lshift, ":troop_bits", 24),
(try_for_range, ":slot", 0, 4),
(agent_get_item_slot, ":item_no", ":agent_no", ":slot"),
(gt, ":item_no", 0),
(item_get_type, ":data", ":item_no"),
(this_or_next|eq, ":data", itp_type_bow), # remove any weapon you want to exclude
(this_or_next|eq, ":data", itp_type_crossbow),
(this_or_next|eq, ":data", itp_type_musket),
(this_or_next|eq, ":data", itp_type_pistol),
(this_or_next|eq, ":data", itp_type_arrows),
(this_or_next|eq, ":data", itp_type_bolts),
(this_or_next|eq, ":data", itp_type_bullets),
(eq, ":data", itp_type_thrown),
(store_and, ":item_bits", ":item_no", 0xFFFF),
(val_lshift, ":item_bits", 8),
(agent_get_ammo_for_slot, ":number", ":agent_no", ":slot"),
(store_and, ":number_bits", ":number", 0xFF),
(store_or, ":data", ":troop_bits", ":item_bits"),
(val_or, ":data", ":number_bits"),
(troop_get_slot, ":number", "trp_ammo", 0),
(val_add, ":number", 1),
(troop_set_slot, "trp_ammo", 0, ":number"),
(troop_set_slot, "trp_ammo", ":number", ":data"),
(try_end),
(try_end), ]),
("adjust_troops_ammo",
[(troop_get_slot, ":number_slot", "trp_ammo", 0),
(try_begin),
(gt, ":number_slot", 0),
(val_add, ":number_slot", 1),
(try_for_range, ":slot",1, ":number_slot"),
(troop_get_slot, ":data", "trp_ammo", ":slot"),
(store_and, ":troop_no", ":data", 0xFFFF000000),
(val_rshift,":troop_no", 24),
(troop_is_hero, ":troop_no"),
#(this_or_next|eq, ":troop_no", "trp_player"), # uncomment these 2 lines
#(main_party_has_troop, ":troop_no"), # to apply only to player and companions
(store_and, ":item_no", ":data", 0xFFFF00),
(val_rshift,":item_no", 8),
(gt, ":item_no", 0),
(item_get_type, ":type", ":item_no"),
(this_or_next|eq, ":type", itp_type_arrows),
(this_or_next|eq, ":type", itp_type_bolts),
(this_or_next|eq, ":type", itp_type_bullets),
(eq, ":type", itp_type_thrown),
(store_and, ":number", ":data", 0xFF),
(assign, ":found", 0),
(try_for_range, ":inv_slot", 0, max_inventory_items),
(eq, ":found", 0),
(troop_get_inventory_slot, ":item_in_slot", ":troop_no", ":inv_slot"),
(eq, ":item_no", ":item_in_slot"),
(troop_inventory_slot_get_item_max_amount,":max", ":troop_no", ":inv_slot"),
(neq, ":number", ":max"),
(troop_inventory_slot_get_item_amount, ":amount", ":troop_no", ":inv_slot"),
(eq, ":amount", ":max"),
(try_begin),
(eq, ":number", 0),
(troop_set_inventory_slot, ":troop_no", ":inv_slot", -1),
(else_try),
(troop_inventory_slot_set_item_amount, ":troop_no", ":inv_slot", ":number"),
(try_end),
(assign, ":found", 1),
(try_end),
(troop_set_slot, "trp_ammo", ":slot", 0),
(try_end),
(try_for_range, ":slot",1, ":number_slot"),
(troop_get_slot, ":data", "trp_ammo", ":slot"),
(store_and, ":troop_no", ":data", 0xFFFF000000),
(val_rshift,":troop_no", 24),
(troop_is_hero, ":troop_no"),
#(this_or_next|eq, ":troop_no", "trp_player"),
#(main_party_has_troop, ":troop_no"),
(store_and, ":item_no", ":data", 0xFFFF00),
(val_rshift,":item_no", 8),
(gt, ":item_no", 0),
(item_get_type, ":weapon", ":item_no"),
(assign, ":type", 0),
(try_begin),
(eq, ":weapon", itp_type_bow),
(assign, ":type", itp_type_arrows),
(else_try),
(eq, ":weapon", itp_type_crossbow),
(assign, ":type", itp_type_bolts),
(else_try),
(this_or_next|eq, ":weapon", itp_type_musket),
(eq, ":weapon", itp_type_pistol),
(assign, ":type", itp_type_bullets),
(try_end),
(neq, ":type", 0),
(store_and, ":ammo_left", ":data", 0xFF),
(item_get_slot, ":max_ammo", ":item_no", slot_item_max_ammo),
(store_sub, ":number", ":max_ammo", ":ammo_left"),
(gt, ":number", 0),
(try_for_range, ":inv_slot", 0, max_inventory_items),
(gt, ":number", 0),
(troop_get_inventory_slot, ":item_in_slot", ":troop_no", ":inv_slot"),
(gt, ":item_in_slot", 0),
(item_get_type, ":type_in_slot", ":item_in_slot"),
(eq, ":type", ":type_in_slot"),
(troop_inventory_slot_get_item_amount, ":amount", ":troop_no", ":inv_slot"),
(try_begin),
(ge, ":amount", ":number"),
(val_sub, ":amount", ":number"),
(assign, ":number", 0),
(else_try),
(val_sub, ":number", ":amount"),
(assign, ":amount", 0),
(try_end),
(try_begin),
(eq, ":amount", 0),
(troop_set_inventory_slot, ":troop_no", ":inv_slot", -1),
(else_try),
(troop_inventory_slot_set_item_amount, ":troop_no", ":inv_slot", ":amount"),
(try_end),
(try_end),
(troop_set_slot, "trp_ammo", ":slot", 0),
(try_end),
(troop_set_slot, "trp_ammo", 0, 0),
(try_end), ]),
("save_agents_ammo_to_slot",
[(try_for_agents, ":agent"),
(call_script, "script_save_agent_ammo_to_slot", ":agent"),
(try_end), ]), # Dunde's Depleted Ammo END
We must save agent's ammo just before quiting mission. for battle's mission, script_count_mission_casualties_from_agents is a good place for it has loops for all agents already.
Code:
#script_count_mission_casualties_from_agents
# INPUT: none
# OUTPUT: none
("count_mission_casualties_from_agents",
[(party_clear, "p_player_casualties"),
(party_clear, "p_enemy_casualties"),
(party_clear, "p_ally_casualties"),
(assign, "$any_allies_at_the_last_battle", 0),
#(assign, "$num_routed_us", 0), #these should not assign to 0 here to protect routed agents to spawn again in next turns.
#(assign, "$num_routed_allies", 0),
#(assign, "$num_routed_enemies", 0),
#initialize all routed counts of troops
(try_for_agents, ":cur_agent"),
(agent_is_human, ":cur_agent"),
(call_script, "script_save_agent_ammo_to_slot", ":cur_agent"), # Dunde's Depleted Ammo
(agent_get_party_id, ":agent_party", ":cur_agent"),
adding this line to execute :
Code:
(call_script, "script_save_agents_ammo_to_slot"),
Assigning the ammo values to troops :
- When on the world map.
Code:
(0,
[(map_free),
(troop_slot_ge, "trp_ammo", 0, 1),
(call_script, "script_adjust_troops_ammo"), # Dunde's Depleted Ammo
]),
Add this line :
Code:
(call_script, "script_adjust_troops_ammo"), # Dunde's Depleted Ammo
PS. It's not fix version yet for there are issues that should be fixed yet. I posted it here just to make harry's thread clean.