Example #1
0
def upgradeUnit(un, diff):
    """Handle the actual upgrading process on a unit based on difficulty"""
    creds = 0.0
    curmount = 0
    mycargo = VS.Cargo("", "", 0, 0, 0, 0)
    str = ""
    debug.debug("Calling basicUnit(%s, %.2f)" % (un.getName(), float(diff)))
    basicUnit(un, diff)
    debug.debug("'- basicUnit returned")
    mycargo = GetRandomHull()  # ok now we get some hull upgrades
    creds = upgradeHelper(un, mycargo, 0, creds, 1, 0)
    mycargo = GetRandomArmor()  # and some random armor
    creds = upgradeHelper(un, mycargo, 0, creds, 1, 0)
    inc = 0
    rndnum = vsrandom.random() * 2
    if (rndnum < diff):
        # there is a small chance that you will get a repair system.
        mycargo = GetRandomRepairSys()
        creds = upgradeHelper(un, mycargo, 0, creds, 1, 0)
    turretz = un.getSubUnits()
    turretcount = 0
    while (not turretz.isDone()):
        turretcount += 1
        turretz.advance()
    #turretcount -= 1
    debug.debug("Iterating through turrets...")
    for i in range(turretcount):
        for j in range(4):
            mycargo = GetRandomTurret()  # turrets as 3rd...
            creds = upgradeHelper(un, mycargo, i, creds, 0, 0)
    debug.debug("'- Done iterating through turrets.")
    turretcount = diff * 50
    if (turretcount > 24):
        turretcount = 24
    elif (turretcount < 3):
        turretcount = 3
    debug.debug("Iterating through difficulty-based turretcount...")
    for i in range(int(turretcount)):
        for j in range(10):
            if (vsrandom.random() < 0.66):
                # weapons go on as first two items of loop
                mycargo = GetRandomWeapon(diff)
            else:
                mycargo = GetRandomAmmo()
            cont = mycargo.GetContent()
            if (cont.find('tractor') == -1 and cont.find('repulsor') == -1
                    and cont.find("steltek_gun") == -1):
                creds = upgradeHelper(
                    un, mycargo, curmount, creds, 0, 1
                )  # we pass this in to the credits...and we only loop through all mounts if we're adding a weapon
                break
        curmount += 1  # increase starting mounts hardpoint
    debug.debug("'- Done interating through difficulty-based turretcount.")
Example #2
0
def addTechLevel(level, addToBase=True):
    try:
        import faction_ships
        upgrades = faction_ships.earnable_upgrades[level]
    except:
        debug.warn("No tech level named " + str(level))
        return
    bas = getDockedBase()
    if (not bas):
        import unit
        import vsrandom
        debug.debug("getting significant for upgrade addage")
        bas = unit.getSignificant(vsrandom.randrange(1, 20), 1, 0)
    for upgrade in upgrades:
        if (len(upgrade) < 5):
            debug.debug("Upgrade list not big enough to add to tech")
            print(upgrade)
            continue
        import Director
        import VS
        cp = VS.getCurrentPlayer()
        siz = Director.getSaveStringLength(cp, "master_part_list_content")
        doIt = True
        for index in range(siz):
            if (Director.getSaveString(cp, "master_part_list_content",
                                       index) == upgrade[0]):
                doIt = False
        if (doIt):
            debug.debug("added UPGRADE AS FOLLOWS to tech level ")
            print(upgrade)
            Director.pushSaveString(cp, "master_part_list_content",
                                    str(upgrade[0]))
            Director.pushSaveString(cp, "master_part_list_category",
                                    str(upgrade[1]))
            Director.pushSaveString(cp, "master_part_list_price",
                                    str(upgrade[2]))
            Director.pushSaveString(cp, "master_part_list_mass",
                                    str(upgrade[3]))
            Director.pushSaveString(cp, "master_part_list_volume",
                                    str(upgrade[4]))
            if (len(upgrade) > 5):
                Director.pushSaveString(cp, "master_part_list_description",
                                        str(upgrade[5]))
            else:
                Director.pushSaveString(cp, "master_part_list_description",
                                        "No description")
            if (bas and addToBase):
                debug.debug(" adding " + str(upgrade[0]) + " to base " +
                            bas.getName())
                cargo = VS.Cargo(str(upgrade[0]), str(upgrade[1]),
                                 float(upgrade[2]), 1, float(upgrade[3]),
                                 float(upgrade[4]))
                bas.forceAddCargo(cargo)
def getItem(cat, parentcat=None):
    if not cat:
        return VS.Cargo("", "", 0, 0, 0, 0)
    list = VS.getRandCargo(1, cat)  #try to get a cargo from said category
    if (list.GetQuantity() <= 0):  #if no such cargo exists in this cateogry
        if (parentcat != None):
            #            debug.warn("Python Upgrade Error: finding %s using %s instead", cat, parentcat)
            list = VS.getRandCargo(1,
                                   parentcat)  #get it from the parent category
        if (list.GetQuantity() <=
                0):  #otherwise get cargo from upgrades category
            #            debug.warn("Python Upgrade Error: category %s -- getting random instead", cat)
            list = VS.getRandCargo(1, "upgrades")  #this always succeeds
    return list
def upgradeUnit(un, diff):
    creds = 0.0
    curmount = 0
    mycargo = VS.Cargo("", "", 0, 0, 0, 0)
    str = ""
    basicUnit(un, diff)
    mycargo = GetRandomHull()  #ok now we get some hull upgrades
    creds = upgradeHelper(un, mycargo, 0, creds, 1, 0)
    mycargo = GetRandomArmor(diff)  #and some random armor
    creds = upgradeHelper(un, mycargo, 0, creds, 1, 0)
    inc = 0
    rndnum = vsrandom.random() * 2
    if (rndnum < diff):
        mycargo = GetRandomRepairSys(
        )  #here there is a small chance that you will get a repair system.
        creds = upgradeHelper(un, mycargo, 0, creds, 1, 0)
    turretz = un.getSubUnits()
    turretcount = 0
    while (turretz.current()):
        turretz.advance()
        turretcount += 1
    turretcount -= 1
    for i in range(turretcount):
        for j in range(4):
            mycargo = GetRandomTurret()  #turrets as 3rd...
            creds = upgradeHelper(un, mycargo, i, creds, 0, 0)
    turretcount = diff * 50
    if (turretcount > 24):
        turretcount = 24
    elif (turretcount < 3):
        turretcount = 3
    for i in range(int(turretcount)):
        for j in range(10):
            if (vsrandom.random() < 0.66):
                mycargo = GetRandomWeapon(
                    diff)  #weapons go on as first two items of loop
            else:
                mycargo = GetRandomAmmo()
            cont = mycargo.GetContent()
            if (cont.find('tractor') == -1 and cont.find('repulsor') == -1
                    and cont.find("steltek_gun") == -1):
                creds = upgradeHelper(
                    un, mycargo, curmount, creds, 0, 1
                )  #we pass this in to the credits...and we only loop through all mounts if we're adding a weapon
                break
        curmount += 1  #increase starting mounts hardpoint