Example #1
0
def GetStats(name):
    try:
        return stattable[name]
    except:
        shipclass = VS.LookupUnitStat(name, "default", "Combat_Role")
        debug.info('cannot find ' + name +
                   ' in stattable, using defaults for class ' + shipclass +
                   ' - fix faction_ships_lists.py')
        if ((shipclass == "INTERCEPTOR") or (shipclass == "FIGHTER")
                or (shipclass == "SCAVENGER")):
            return (0.62, 0.66, 18, 52.5, 48)
        if (shipclass == "TROOP"):
            return (.5, .5, 1, 1, 1)
        if (shipclass == "BOMBER"):
            return (0.44, 0.48, 95.8, 80, 148)
        if (shipclass == "MERCHANTMAN"):
            return (0.1, 0.2, 32.8, 80, 38)
        if (shipclass == "CAP_NOPHASE"):
            return (0.26, 0.2, 68.3, 220, 66)
        if (shipclass == "CAP_PHASE"):
            return (0.2, 0.2, 77.22, 260, 66)
        if (shipclass == "CARRIER"):
            return (0.26, 0.2, 68.3, 320, 66)
        if (shipclass == "BASE"):
            return (.5, 0, 600, 6000, 2)
        else:
            return (.5, .5, 1, 1, 1)
Example #2
0
def getRandomShipType(ship_list):
    #debug.debug("getRandomShipType(%s)" % (ship_list))
    ffvalidate = ""
    while (ffvalidate == ""):
        index = vsrandom.randrange(0, len(ship_list))
        fishedship = ship_list[index]
        ffvalidate = str(
            VS.LookupUnitStat(fishedship, "default", "Default_Speed_Governor"))
        if (ffvalidate == ""):
            debug.warning("Ship type " + str(fishedship) +
                          " does not have a flight model!")
    #debug.debug("shipdata: "+str(fishedship) +" has speed governor = "+str(ffvalidate))
    return fishedship
Example #3
0
def getImports(name,faction):
    try:
        prodlist=[]
        s = VS.LookupUnitStat(name,faction,"Cargo_Import")
        while (len(s)):
            where=s.find("{")
            if (where==-1):
                s=""
                break;
            else:
                s=s[where+1:]
            # _very_ verbose!
            #debug.debug("head:\n%s" % (debug.pp(s)))
            where = s.find("}")
            if (where==-1):
                s=""
                break;
            else:
                tmp=s[:where]
                prodlist.append(tmp.split(";"))
                s=s[where+1:]
                if (len(prodlist[-1])>4):
                    try:
                        prodlist[-1][1]=float(prodlist[-1][1]) # price
                    except:
                        prodlist[-1][1]=0.0
                    try:
                        prodlist[-1][2]=float(prodlist[-1][2]) # price variance
                    except:
                        prodlist[-1][2]=0.0
                    try:
                        prodlist[-1][3]=float(prodlist[-1][3]) # quantity
                    except:
                        prodlist[-1][3]=0.0
                    try:
                        prodlist[-1][4]=float(prodlist[-1][4]) # quantity variance
                    except:
                        prodlist[-1][4]=0.0
                # _very_ verbose!
                #debug.debug("tail:\n%s" % (debug.pp(s)))
        #debug.debug("whole list:\n%s" % (debug.pp(prodlist)))
        return prodlist
    except:
        import sys
        print("GetImportFailure")
        print( str(sys.exc_info()[0]) + str(sys.exc_info()[1]) )
    return []
Example #4
0
def get_manifest_text(player):
    cargo_dict = {}

    # get the hold volume
    int_hold_volume = int(
        VS.LookupUnitStat(player.getName(), player.getFactionName(),
                          "Hold_Volume"))
    if (player.hasCargo("add_cargo_volume")):
        # capacity increases by 50% if they have the cargo expansion
        int_hold_volume = int(int_hold_volume * 1.5)

    int_total_quantity = 0
    for i in range(player.numCargo()):
        cargo = player.GetCargoIndex(i)

        name = cargo.GetContent()
        category = cargo.GetCategory()
        quantity = cargo.GetQuantity()

        if name == '': continue
        if category[:8] == 'upgrades': continue
        if category[:9] == 'starships': continue

        if (quantity > 0):
            cargo_dict[name] = quantity
            int_total_quantity += quantity

    int_space_left = int_hold_volume - int_total_quantity
    keys = cargo_dict.keys()
    if len(keys) > 0:
        str_manifest = "Space left: %s\n\n" % (int_space_left)
        keys.sort()
        for i in keys:
            count = cargo_dict[i]
            # try to pad the columns so they line up
            str_pad = "   "
            int_pad_len = len(str_pad) - len(str(count))
            if int_pad_len < 1:
                str_pad = ""
            else:
                str_pad = str_pad[:int_pad_len]
            str_manifest += "%s%s  %s\n" % (str_pad, count, i)
    else:
        str_manifest = "Space left: %s\nNo cargo loaded.\n" % (int_space_left)

    return str_manifest
Example #5
0
def getImports(name, faction):
    try:
        prodlist = []
        s = VS.LookupUnitStat(name, faction, "Cargo_Import")
        while (len(s)):
            where = s.find("{")
            if (where == -1):
                s = ""
                break
            else:
                s = s[where + 1:]
            #debug.debug("beg: "+s)
            where = s.find("}")
            if (where == -1):
                s = ""
                break
            else:
                tmp = s[:where]
                prodlist.append(tmp.split(";"))
                s = s[where + 1:]
                if (len(prodlist[-1]) > 4):
                    try:
                        prodlist[-1][1] = float(prodlist[-1][1])
                    except:
                        prodlist[-1][1] = 0.0
                    try:
                        prodlist[-1][2] = float(prodlist[-1][2])
                    except:
                        prodlist[-1][2] = 0.0
                    try:
                        prodlist[-1][3] = float(prodlist[-1][3])
                    except:
                        prodlist[-1][3] = 0.0
                    try:
                        prodlist[-1][4] = float(prodlist[-1][4])
                    except:
                        prodlist[-1][4] = 0.0
                #debug.debug("rest "+s)
        #debug.debug("whole list: " +str(prodlist))
        return prodlist
    except:
        import sys
        debug.error("GetImportFailure\n" + str(sys.exc_info()[0]) +
                    str(sys.exc_info()[1]))
    return []
def LookupRealName(oldname, faction):
    import VS
    newname = VS.LookupUnitStat(oldname, faction, "Name")
    if len(newname) == 0:
        return oldname
    return newname
Example #7
0
def contractMissionsFor(fac, baseship, minsysaway, maxsysaway):
    global totalMissionNumber
    global insysMissionNumber
    totalMissionNumber = 0
    insysMissionNumber = 0
    facnum = faction_ships.factionToInt(fac)
    enemies = list(faction_ships.enemies[facnum])
    script = ''
    cursystem = VS.getSystemFile()
    thisfaction = VS.GetGalaxyFaction(cursystem)
    preferredfaction = None
    if (VS.GetRelation(fac, thisfaction) >= 0):
        preferredfaction = thisfaction  #try to stay in this territory
    l = []
    num_wingmen = 2
    num_rescue = 2
    num_defend = 1
    num_idefend = 2
    num_bounty = 1
    num_ibounty = 1
    num_patrol = 1
    num_ipatrol = 1
    num_escort = 1
    num_iescort = 1
    mincount = 2
    for i in range(minsysaway, maxsysaway + 1):
        for j in getSystemsNAway(cursystem, i, preferredfaction):
            if (i < 2 and num_rescue > 0):
                if j[-1] in dynamic_battle.rescuelist:
                    generateRescueMission(j, dynamic_battle.rescuelist[j[-1]])
                    if checkCreatedMission():
                        num_rescue -= 1


#            if (0 and i==0):
#                generateRescueMission(j,("confed","Shadow","pirates"))
            l = dynamic_battle.BattlesInSystem(j[-1])
            nodefend = 1
            for k in l:
                if (VS.GetRelation(fac, k[1][1]) >= 0):
                    if ((j[-1] == VS.getSystemFile() and num_idefend <= 0) or
                        (j[-1] != VS.getSystemFile() and num_defend <= 0)):
                        mungeFixerPct()
                        debug.debug("Munged")
                    else:
                        nodefend = 0
                    generateDefendMission(j, k[1][0], k[1][1], k[0][0],
                                          k[0][1])
                    restoreFixerPct()
                    if checkInsysNum():
                        num_idefend -= 1
                    if checkMissionNum():
                        num_defend -= 1
                    debug.debug("Generated defendX with insys at: " +
                                str(num_idefend) + " and outsys at " +
                                str(num_defend))
            (m, nummerchant,
             numthisfac) = GetFactionToDefend(thisfaction, fac, j[-1])

            if preferredfaction:
                for kk in faction_ships.enemies[
                        faction_ships.factiondict[thisfaction]]:
                    k = faction_ships.intToFaction(kk)
                    for mm in fg_util.FGsInSystem(k, j[-1]):
                        if (i == 0 or vsrandom.randrange(0, 4)
                                == 0):  #fixme betterthan 4
                            if nodefend and len(m) and vsrandom.random() < .4:
                                if 1:  #for i in range(vsrandom.randrange(1,3)):
                                    insys = (j[-1] == VS.getSystemFile())
                                    if (insys and num_idefend <= 0):
                                        mungeFixerPct()
                                    elif (num_defend <= 0 and not insys):
                                        mungeFixerPct()
                                    rnd = vsrandom.randrange(0, len(m))
                                    def_fg = m[rnd]
                                    def_fac = "merchant"
                                    if rnd >= nummerchant:
                                        def_fac = thisfaction
                                    if rnd >= numthisfac:
                                        def_fac = fac
                                    generateDefendMission(
                                        j, def_fg, def_fac, mm, k)
                                    restoreFixerPct()
                                    if checkInsysNum():
                                        num_idefend -= 1
                                    if checkMissionNum():
                                        num_defend -= 1
                                    debug.debug(
                                        "Generated defendY with insys at: " +
                                        str(num_idefend) + " and outsys at " +
                                        str(num_defend))
                                nodefend = 0
                            elif ((i == 0 or vsrandom.random() < .5)):
                                if ((j[-1] == VS.getSystemFile()
                                     and num_ibounty <= 0)
                                        or (j[-1] != VS.getSystemFile()
                                            and num_bounty <= 0)):
                                    mungeFixerPct()
                                generateBountyMission(j, mm, k)
                                restoreFixerPct()
                                if checkInsysNum():
                                    debug.debug(
                                        " decrementing INSYS bounty to " +
                                        str(num_ibounty))
                                    num_ibounty -= 1
                                if checkMissionNum():
                                    debug.debug(" decrementing bounty to " +
                                                str(num_bounty))
                                    num_bounty -= 1
            #
            mincount = -2
            if i == 0:
                mincount = 1
            for k in range(vsrandom.randrange(
                    mincount, 4)):  ###FIXME: choose a better number than 4.
                if k < 0:
                    k = 0
                rnd = vsrandom.random()
                if (rnd < .15):  # 15% - nothing
                    pass
                if (rnd < .5 or i == 0):  # 35% - Patrol Mission
                    if ((j[-1] == VS.getSystemFile() and num_ipatrol <= 0) or
                        (j[-1] != VS.getSystemFile() and num_patrol <= 0)):
                        mungeFixerPct()
                    if (vsrandom.randrange(0, 2)
                            or j[-1] in faction_ships.fortress_systems):
                        generatePatrolMission(j, vsrandom.randrange(4, 10))
                    else:
                        generateCleansweepMission(
                            j, vsrandom.randrange(4, 10),
                            faction_ships.get_enemy_of(fac))
                    restoreFixerPct()
                    if checkInsysNum():
                        num_ipatrol -= 1
                    if checkMissionNum():
                        num_patrol -= 1
                else:  # 50% - Cargo mission
                    numcargos = vsrandom.randrange(1, 25)
                    playership = VS.getPlayer().getName()
                    try:
                        hold = int(
                            VS.LookupUnitStat(playership, "privateer",
                                              "Hold_Volume"))
                    except:
                        hold = 10
                    if hold < 10:
                        hold = 10
                    if hold > 32000:
                        hold = 32000
                    numcargos = vsrandom.randrange(hold // 5, hold // 2)
                    if numcargos < 20:
                        numcargos = vsrandom.randrange(hold // 2, hold)
                    category = ''
                    if (rnd > .87 and fac != 'confed' and fac != "ISO"
                            and fac != "militia" and fac != "homeland-security"
                            and fac != "kilrathi" and fac != "merchant"):
                        category = 'Contraband'
                    else:
                        for myiter in range(100):
                            carg = VS.getRandCargo(numcargos, category)
                            category = carg.GetCategory()
                            if (category[:9] != 'Fragments'
                                    and category[:10] != 'Contraband'
                                    and category.find('upgrades') != 0
                                    and (category.find('starships') != 0
                                         or rnd > .999)):
                                break
                            if (myiter != 99):
                                category = ''
                        if baseship:
                            faction = fac
                            name = baseship.getName()
                            if baseship.isPlanet():
                                faction = "planets"
                                name = baseship.getFullname()
                            debug.info("TRADING")
                            debug.debug(
                                "getFullname(): %s, getName(): %s, faction: %s"
                                % (baseship.getFullname(), baseship.getName(),
                                   faction))
                            exports = trading.getNoStarshipExports(
                                name, faction, 20)
                            debug.debug("exports:\n%s" % (debug.pp(exports)))
                            if (category.find("assengers") == -1
                                    and len(exports)):
                                category = exports[vsrandom.randrange(
                                    0, len(exports))][0]
                    #debug.debug("CATEGORY OK "+category)
                    generateCargoMission(j, numcargos, category, fac)
                numescort = vsrandom.randrange(0, 2)
                if (numescort > len(m)):
                    numescort = len(m)
                count = 0
                for k in m:
                    if (i == 0):
                        if vsrandom.random() < .92:
                            count += 1
                            continue
                    elif (vsrandom.random() < .97):
                        count += 1
                        continue
                    f = "merchant"
                    if count >= nummerchant:
                        f = thisfaction
                    if count >= numthisfac:
                        f = fac
                    if (vsrandom.random() < .25):
                        if (num_wingmen > 0):
                            generateWingmanMission(k, f)
                            num_wingmen -= 1
                    elif (i == 0):
                        if (vsrandom.random() < .25):
                            if num_iescort <= 0:
                                mungeFixerPct()
                            generateEscortLocal(j, k, f)
                            restoreFixerPct()
                            if checkCreatedMission():
                                num_iescort -= 1
                    else:
                        if num_escort <= 0:
                            mungeFixerPct()
                        generateEscortMission(j, k, f)
                        restoreFixerPct()
                        if checkCreatedMission():
                            num_escort -= 1
                    count += 1