I am working on creating a salvage mechanic for my game. I want different units to calculate salvage after an encounter to randomly determine how much each one was able to scavenge from fallen allies or attackers.
As I have it setup up now its calculate as a group.
IE: If I have group of units whom collectively can salvage value of 5 and for each point of salvage I can potentially gain 1-4 piece of salvage then I have a range of 5-20 pieces of salvage (provided there are 20 or more pieces of salvage to collect). I am simply multiplying the total salvage value of the group by a randomly determined number in a range of 1-4.
My question is, how can I get each unit to calculate its salvage individually from its own range, rather than as a group as I'm doing now to give greater variance in the amount of salvage generated?
I am rather new and any suggestion or insight would be appreciated.
Below is the code for a demo I setup for the salvage system:
import random
parts_inventory = 0
undif_unit_count = 999
haulers = 2
foragers = 1
salvage_value = (haulers * 2) + foragers
temp_salvage = 0
salvage_random = random.randint(1, 4)
attack = random.randint(1, 6)
fatalities = attack
salvage_pool = fatalities * 4
print("There were {} units destroyed resulting in {} pieces of potential salvage".format(attack, salvage_pool))
print("Your units can haul away {} peice of salvage".format(salvage_value))
def salvage_operation(parts_inventory=parts_inventory):
print("Encounter Haul {}".format(salvage_value))
if salvage_value <= salvage_pool:
print("You gained {} salvaged parts.".format(salvage_value))
parts_inventory = parts_inventory + salvage_value
if salvage_value > salvage_pool:
print("You gained {} salvaged parts.".format(salvage_pool))
parts_inventory = parts_inventory + salvage_pool
salvage_operation()