init -2 python:
#for testing purposes
    def tlog(text):
        f = open("traitlist.txt","a")
        f.write(text)
        f.close()
      
    def exclude_test(text,tags):
        if isinstance(tags,list):
            if text in tags:
                return 1
        else:
            if text == tags:
                return 1
        return 0
    #We had to do this because some idiot used max as a variable!!! Moron
    #def max_key(dict):
    #    m = 0
    #    k = None
    #    for key in dict:
    #        if dict[key] > m:
    #            m = dict[key]
    #            k = key
    #    return k
      
    def generate_contract(contract_tier = 0):
      
        t_mental = 0
        t_physical = 0
        t_sexual = 0
        t_medical = 0
        t_flaws = 0
        t_attention = 0
      
        serum_bases = []
        base_slots = []
        high_cap = None
      
        available_traits = []
      
        lts = list_of_traits
        #this is used because Vren initialized it before the MC is initialized
        try:
            mc
        except NameError:
            lts = list_of_traits
        else:
            lts = list_of_traits + mc.business.blueprinted_traits
      
        #Create a list of bases <= contract tier
        for trait in lts:
            if trait.tier <= contract_tier and exclude_test("Production",trait.exclude_tags):
                serum_bases.append(trait)
                base_slots.append(trait.slots)
      
        #build list of available traits
        #traits have to be below the level of contract and researched
        for t in range (0,4):
            if contract_tier >= t:
                for trait in lts:
                    if trait.tier == t and trait.researched == True and trait.name != "High Capacity Design" and not exclude_test("Production",trait.exclude_tags):
                        available_traits.append(trait)
        #High Cap
        for trait in lts:
            if trait.name == "High Capacity Design":
                high_cap = trait
      
        #select the actual level of serum base
        ct = 0
        if contract_tier > 0:
            ct = renpy.random.randint(0,len(serum_bases)-1)
        slots = serum_bases[ct].slots
        #add bases aspects to aspects
        t_mental = serum_bases[ct].mental_aspect
        t_physical = serum_bases[ct].physical_aspect
        t_sexual = serum_bases[ct].sexual_aspect
        t_medical = serum_bases[ct].medical_aspect
        t_flaws = serum_bases[ct].flaws_aspect
        t_attention = serum_bases[ct].attention
      
        #determine if High Capacity is used.
        HC_Test = 0
        if renpy.random.randint(1,7) < 4 and high_cap.researched:
            HC_Test = 1
        if HC_Test:
            slots += 1
            #include HC aspects
            t_mental += high_cap.mental_aspect
            t_physical += high_cap.physical_aspect
            t_sexual += high_cap.sexual_aspect
            t_medical += high_cap.medical_aspect
            t_flaws += high_cap.flaws_aspect
            t_attention += high_cap.attention
      
        #Determine number of slots filled
        fill = 1
        if ct > 0 and HC_Test != 1:    #tier >0 and no High Cap, may not use all slots
            fill = renpy.random.randint(1,slots)
        if HC_Test == 1:              #if HC is used all slots are used
            fill = slots
        trait_names = "Min Traits:"         #string of the tait names selected for trouble shooting purposes
      
        #select traits to fill slots
        if(len(available_traits)>0): #needed because you start with a base but no traits
            Rn = 0
            selected_traits = []            #these are traits already selected in serum
            for x in range(0,fill):
                while Rn in selected_traits:
                    Rn = renpy.random.randint(0,len(available_traits)-1)
                selected_trait = available_traits[Rn]
                selected_traits.append(Rn)
                trait_names += " " + selected_trait.name
                t_mental += selected_trait.mental_aspect
                t_physical += selected_trait.physical_aspect
                t_sexual += selected_trait.sexual_aspect
                t_medical += selected_trait.medical_aspect
                t_flaws += selected_trait.flaws_aspect
                t_attention += selected_trait.attention
      
        t_flaws += renpy.random.randint(0,(ct+1)*2)
      
        #Some idiot use max as a variable
        asp_dict = {"mental":int(t_medical),"physical":int(t_physical),"sexual":int(t_sexual),"medical":int(t_medical)}
        primary_aspect = max(asp_dict,key=asp_dict.get)
        #primary_aspect = max_key(asp_dict)
        del asp_dict[primary_aspect]
        #secondary_aspect = max_key(asp_dict)
        secondary_aspect = max(asp_dict,key=asp_dict.get)
      
      
      
        #These are shity and don't really match serums either
        #Temp for now
        contract_name, contract_description = get_contract_description(primary_aspect, secondary_aspect, contract_tier)
      
        amount_desired = 5*(contract_tier+renpy.random.randint(1,3))*(contract_tier+renpy.random.randint(1,3))
      
        contract_length = 3 + (renpy.random.randint(0,3+contract_tier) * renpy.random.randint(0,3+contract_tier))
        #My change
        contract_description += " " + trait_names
        #end change
        new_contract = Contract(contract_name, contract_description, contract_length,
            mental_requirement = t_mental, physical_requirement = t_physical, sexual_requirement = t_sexual, medical_requirement = t_medical,
            flaw_tolerance = t_flaws, attention_tolerance = t_attention, amount_desired = amount_desired)
        return new_contract
  
  
    def get_contract_description(primary_aspect, secondary_aspect, contract_tier):
        contract_dict = {("mental","physical"):("Eltaro Co. Employee Boosters","Eltaro Co. is looking for a way to improve the general productivity of their employees by sharpening both body and mind."),
        ("Mental","sexual"):("Iris Cosmetics Makeup Additive","Having a beautiful mind is just as important as clear skin or perfect makeup. Iris cosmetics is looking for something to promote that feeling in their customers, and a little sex appeal always helps sell products."),
        ("mental","medical"):("Tresmon Pharmaceuticals Neuotropics","Tresmon Pharmaceuticals has a number of clients interested in thought-boosting drugs, and they're willing to pay top dollar for you to fill those orders for them."),
      
        ("physical","mental"):("Univerity Athletics Council Request","The university athletics council is looking for a way to improve the performance of their key athletes, on and off the field."),
        ("physical","sexual"):("Univerity Cheerleading Council Request","Attendance at recent sporting events has been down, and many are blaming the new \"respectful\" cheerleading uniforms. Cheer leadership is looking for a new workout enhancer, ideally one that will reduce resistance to a return to the old uniform."),
        ("physical","medical"):("Gary's Power Lifting Additive","Gary runs a local gym, and he's always on the look out for another performance enhancing drug to peddle to those looking for a quick path to fitness."),
      
        ("sexual","mental"):("Personal Business Supplies","A C-suite executive of a nearby business has a secretary they want to turn into a, quote, \"Cock drunk bimbo-slut\", and they're willing to pay good money for a large stock of serum to make it happen."),
        ("sexual","physical"):(str(strip_club.name),str(strip_club_owner) + " is interested in anything that will give his girls more sex appeal while they're stripping on stage. Bigger tits, toned bodies, whatever you think they need to get more twenties on the stage."),
        ("sexual","medical"):("A Questionable Contact","An individual using an obviously fake name has requested \"Anything that gets 'em horny, wet, and ready to suck dick.\". Their name might be fake, but their cash definitely isn't."),
      
        ("medical","mental"):("Tresmon Pharmaceuticals Research Materials","Tresmon Pharmaceuticals is intensely interested in our work on mind altering substances. They want a stock of their own to perform advanced R&D with."),
        ("medical","physical"):("Military Research Study","The military is interested in potential \"super soldier\" applications, and they're willing to work with civilian sources to obtain research material."),
        ("medical","sexual"):("Female Libedo Enhancements","Low libedo is a side effect for many different medications. Tresmon Pharmaceuticals is interested in an additive that might lessen or eliminate that problem from their existing drugs.")
        }
        r = contract_dict.get((primary_aspect,secondary_aspect))
        contract_name = r[0]
        contract_description = r[1]
        return contract_name, contract_description