def initrandom(minns, maxns, credsmin, credsmax, run_away, minshipdifficulty, maxshipdifficulty, jumps=(), var_to_set=''): you = VS.getPlayer() tempfaction = 'aera' if (you): name = you.getFactionName() factionname = vsrandom.randrange(0, faction_ships.getMaxFactions()) tempfaction = faction_ships.intToFaction(factionname) i = 0 while ((name == tempfaction or name == "unknown") and i < 10): factionname = vsrandom.randrange(0, faction_ships.getMaxFactions()) tempfaction = faction_ships.intToFaction(factionname) i += 1 sd = vsrandom.random() * (maxshipdifficulty - minshipdifficulty) + minshipdifficulty return bounty(minns, maxns, (1.0 + (sd * 0.5)) * (vsrandom.random() * (credsmax - credsmin) + credsmin), run_away, sd, tempfaction, jumps, var_to_set) else: print "aborting bounty initrandom" VS.terminateMission(0)
def MakeBar(concourse, concoursetext, bartext, BaseTexture, createCampaignFixers=True, defaultbtr=None, forcedefbtr=False, bartenderprefix="", bartenderloc=(.89725,.0813), patrons=[],fixerlocations=[(-0.80025, -1.0088, 0.776, 1.2416),(-0.0725, -0.4058125, 0.1758125, 0.5385)]): if vsrandom.random()<.6: forcedefbtr=True # remove me if you want random bartenders at random bars import bartender bartender.speaktimes=0 room0 = Base.Room ('Bar') x=0 y=0 Base.Texture (room0, 'background', BaseTexture+'.spr', x, y) for p in patrons: if vsrandom.random()<.85: Base.Texture(room0,str(p[0]),'bases/generic/'+str(p[0])+'.spr',float(p[1]),float(p[2])) if defaultbtr: if not forcedefbtr: defaultbtr=bartenders[vsrandom.randrange(len(bartenders))] Base.Texture(room0,'btr','bases/generic/'+bartenderprefix+'bartender'+str(defaultbtr)+'.spr', float(bartenderloc[0]),float(bartenderloc[1])) if VS.networked(): Base.Python (room0, 'newscomp', -1, .7, .3, .3, 'Public Terminal', '#\nimport custom\ncustom.run("computer",[],None)',True) else: Base.Comp (room0, 'newscomp', -1, .7, .3, .3, 'Public Terminal', 'News') Base.Link (room0, 'my_link_id', -0.998047, -0.997396, 1.99414, 0.119792, concoursetext ,concourse) Base.Python (room0, 'talk', bartenderloc[0]-.16, bartenderloc[1]-.15,.3,.3,'Talk to the Bartender',bartext,0) import fixers func=fixers.CreateFixers if not createCampaignFixers: func=fixers.CreateMissionFixers func(room0,[(fixerlocations[0][0],fixerlocations[0][1],fixerlocations[0][2],fixerlocations[0][3],"_1"),(fixerlocations[1][0],fixerlocations[1][1],fixerlocations[1][2],fixerlocations[1][3],"_2")])#add more locations? return room0;
def generateCleansweepMission(path,numplanets,enemy, pricescale = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricescale","16000")), jumpscale = float(VS.vsConfig("dynamic_universe","missions.cleansweep.jumpscale","1.2")), sweepmod = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricemod.sweep","4")), capshipmod = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricemod.capship","4")), forceattackmod = float(VS.vsConfig("dynamic_universe","missions.cleansweep.pricemod.forceattack","0.25")) ): fighterprob=vsrandom.random()*.75+.25; capshipprob=0.0 if (vsrandom.random()<.2): capshipprob=vsrandom.random()*.25; forceattack=vsrandom.randrange(0,2) cleansweep=vsrandom.randrange(0,2) minships=maxships=vsrandom.randrange(1,4) creds = ( pricescale * ( 1+ cleansweep*sweepmod+ capshipprob*capshipmod+ forceattack*forceattackmod ) * minships * fighterprob + jumpscale * syscreds * len(path) ) creds*=getPriceModifier(False) addstr="" isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n" elif isFixer<guildpct: creds*=1.5 if (cleansweep): addstr+="#G#Bounty#\n" else: addstr+="#G#Patrol#\n" missiontype="patrol_enemies" additional="" additionalinstructions="" patrolorclean="Patrol" dist=1000 if (cleansweep): dist=1500 additional=",1" patrolorclean="Clean_Sweep" missiontype="cleansweep" additionalinstructions+=" Eliminate all such forces encountered to receive payment." if (capshipprob): additionalinstructions+=" Capital ships are possibly in the area." writemissionsavegame (addstr+"import %s\ntemp=%s.%s(0, %d, %d, %d, %s,'',%d,%d,%f,%f,'%s',%d%s)\ntemp=0\n"%(missiontype,missiontype,missiontype,numplanets, dist, creds, str(path),minships,maxships,fighterprob,capshipprob,enemy,forceattack,additional)) writedescription("Authorities would like a detailed scan of the %s system. We require %d nav locations be visited on the scanning route. The pay for this mission is %d. Encounters with %s forces likely.%s"%(processSystem(path[-1]),numplanets,creds,enemy,additionalinstructions)) ispoint="s" if numplanets==1: ispoint="" if len(path)==1: mistype = 'IN-SYSTEM ATTACK' else: mistype = 'ATTACK' writemissionname("%s/%s_%d_Point%s_in_%s"%(patrolorclean,patrolorclean,numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr)) writemissionvars( { 'MISSION_TYPE' : mistype } )
def generateBountyMission( path, fg, fac, baseprice=float(VS.vsConfig("dynamic_universe", "missions.bounty.baseprice", "20000")), runawayprice=float(VS.vsConfig("dynamic_universe", "missions.bounty.runaway", "5000")), diffprice=float(VS.vsConfig("dynamic_universe", "missions.bounty.diffprice", "500")), jumpscale=float(VS.vsConfig("dynamic_universe", "missions.bounty.jumpscale", "1")), capscale=float(VS.vsConfig("dynamic_universe", "missions.bounty.capscale", "4")), ): typ = fg_util.RandomShipIn(fg, fac) cap = faction_ships.isCapital(typ) makemissionharder = vsrandom.randrange(0, 2) diff = vsrandom.randrange(0, adjustQuantityDifficulty(7)) + howMuchHarder(makemissionharder) runaway = vsrandom.random() >= 0.75 creds = baseprice + runawayprice * runaway + diffprice * diff + jumpscale * syscreds * len(path) if cap: creds *= capscale finalprice = creds * getPriceModifier(False) addstr = "" isFixer = vsrandom.random() if isFixer < fixerpct: finalprice *= 2 addstr += "#F#bases/fixers/hunter.spr#Talk with the Bounty Hunter#We will pay you on mission completion. And as far as anyone knows - we never met." if runaway: addstr += "#Also-- we have information that the target may be informed about your attack and may be ready to run. Be quick!" addstr += "#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Bounty#\n" writemissionsavegame( addstr + "import bounty\ntemp=bounty.bounty(0, 0, %g, %d, %d, '%s', %s, '', '%s','%s')\ntemp=0\n" % (finalprice, runaway, diff, fac, str(path), fg, typ) ) diffstr = "" if diff > 0: diffstr = " The ship in question is thought to have %d starships for protection." % diff if len(path) == 1: mistype = "IN-SYSTEM BOUNTY" else: mistype = "BOUNTY" writedescription( "A %s starship in the %s flightgroup has been harassing operations in the %s system. Reward for the termination of said ship is %d credits.%s" % (formatShip(typ), fg, processSystem(path[-1]), finalprice, diffstr) ) if cap: writemissionname( "Bounty/on_%s_Capital_Vessel_in_%s" % (fac, processSystem(path[-1])), path, isFixerString(addstr) ) else: writemissionname( "Bounty/Bounty_on_%s_starship_in_%s" % (fac, processSystem(path[-1])), path, isFixerString(addstr) ) writemissionvars({"MISSION_TYPE": mistype})
def generateCargoMission(path, numcargos, category, fac, cargoprice=250.0, baseprice=500.0, contrabandprice=5000.0, starshipprice=20000.0): #if (isNotWorthy(fac)): # return launchcap = (vsrandom.random() >= .97) if (not launchcap) and not isHabitable(path[-1]): return diff = vsrandom.randrange(0, adjustQuantityDifficulty(6)) creds = (cargoprice * numcargos + baseprice * diff + syscreds * len(path) + contrabandprice * (category[:10] == "Contraband") + starshipprice * (category[:9] == "starships")) addstr = "" creds *= getPriceModifier(False) isFixer = vsrandom.random() if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Cargo#\n" writemissionsavegame( addstr + "import cargo_mission\ntemp=cargo_mission.cargo_mission('%s', 0, %d, %d, %g, %d, 0, '%s', %s, '')\ntemp=0\n" % (fac, numcargos, diff, creds, launchcap, category, str(path))) if (category == ''): category = 'generic' randCompany = GetRandomCompanyName() if (randCompany == ''): strStart = "We need to deliver some " else: strStart = randCompany + " seeks delivery of " brief = GetRandomCargoBrief() if brief: # a comparison to an empty string returns False composedBrief = brief.replace('$CL', randCompany) composedBrief = composedBrief.replace('$CG', formatCargoCategory(category)) composedBrief = composedBrief.replace(' $DB', '') composedBrief = composedBrief.replace('$DS', processSystem(path[-1])) composedBrief = composedBrief.replace('$PY', str(int(creds))) writedescription(composedBrief) else: writedescription( strStart + "%s cargo to the %s system. The mission is worth %d credits to us. You will deliver it to a base owned by the %s.%s" % (formatCargoCategory(category), processSystem(path[-1]), creds, fac, pathWarning(path, isFixer < guildpct))) writemissionname( "Cargo/Deliver_%s_to_%s" % (changecat(category), processSystem(path[-1])), path, isFixerString(addstr))
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.")
def PlayMusik(forcechange=1, hostile_dist=0): un = VS.getPlayer() if (not un): mpl(PEACELIST, PEACELIST, forcechange) debug.info("PlayMusik: Peace (not un)") else: perfect = 1 #debug.debug("before 'uni = VS.getUnitList()'") uni = VS.getUnitList() #debug.debug("after 'uni = VS.getUnitList()'") unlist = [] asteroid = 0 while (not uni.isDone()): #debug.debug("before 'target = next(uni)'") target = next(uni) #debug.debug("after 'target = next(uni)'") if not target.isNull(): #debug.debug("inside 'if not target.isNull():'") ftmp = 2 * target.getRelation(un) nam = target.getName().lower() if un.getSignificantDistance(target) <= 2 * target.rSize( ) and ('afield' == nam[:6] or 'asteroid' == nam[:8]): asteroid = 1 hdis = HOSTILE_AUTODIST if (hostile_dist != 0): hdis = hostile_dist if (target.GetTarget() == un or (ftmp < 0 and un.getDistance(target) < hdis)): unlist.append(target.getFactionName()) perfect = 0 if (perfect): if asteroid and asteroidmisic != -1 and vsrandom.random() < .7: mpl(asteroidmisic, PEACELIST, forcechange) return sys = VS.getSystemFile() fact = VS.GetGalaxyFaction(sys) if vsrandom.random() < .5: fact = None mpl(LookupTable(peacelist, fact), PEACELIST, forcechange) debug.info("PlayMusik: Peace") else: ftmp = (un.FShieldData() + 2 * un.GetHullPercent() + un.RShieldData() - 2.8) * 2 fact = None if len(unlist) and vsrandom.random() < .5: fact = unlist[vsrandom.randrange(0, len(unlist))] debug.info("faction: %s" % (fact)) if (ftmp < -.5): mpl(LookupTable(paniclist, fact), BATTLELIST, forcechange) debug.info("PlayMusik: Panic") else: mpl(LookupTable(battlelist, fact), BATTLELIST, forcechange) debug.info("PlayMusik: Battle")
def DeletePatrolPoint(self, num, nam): import vsrandom if (vsrandom.random() < self.encounterprob): import faction_ships fac = self.faction if (type(fac) is list or type(fac) is tuple): fac = fac[vsrandom.randrange(0, len(fac))] dynfg = "" import fg_util import VS allfg = fg_util.AllFGsInSystem(fac, VS.getSystemFile()) if (len(allfg)): dynfg = allfg[vsrandom.randrange(0, len(allfg))] for i in range(vsrandom.randrange(self.minships, self.maxships + 1)): import launch L = launch.Launch() if self.fgname == "": fgname = "Patrol" else: fgname = self.fgname L.fg = fgname L.dynfg = dynfg if (vsrandom.random() < self.capshipprob): L.type = faction_ships.getRandomCapitol(fac) else: L.type = faction_ships.getRandomFighter(fac) L.ai = "default" L.faction = fac L.num = 1 L.minradius = 3000.0 L.maxradius = 4000.0 if i == 0: L.fgappend = "" else: L.fgappend = "_" + str(i) try: L.minradius *= faction_ships.launch_distance_factor L.maxradius *= faction_ships.launch_distance_factor except: pass if (self.patrolpoints[num]): newun = L.launch(self.patrolpoints[num]) if (self.forceattack): lead = newun.getFlightgroupLeader() if (lead): lead.SetTarget(self.you) else: newun.setFlightgroupLeader(newun) newun.SetTarget(self.you) newun.setFgDirective("A.") self.Track(newun) patrol.patrol.DeletePatrolPoint(self, num, nam)
def DeletePatrolPoint(self,num,nam): import vsrandom if (vsrandom.random()<self.encounterprob): import faction_ships fac=self.faction if (type(fac) is list or type(fac) is tuple): fac = fac[vsrandom.randrange(0,len(fac))] dynfg="" import fg_util import VS allfg=fg_util.AllFGsInSystem(fac,VS.getSystemFile()) if (len(allfg)): dynfg = allfg[vsrandom.randrange(0,len(allfg))] for i in range(vsrandom.randrange(self.minships,self.maxships+1)): import launch L=launch.Launch() if self.fgname=="": fgname="Patrol" else: fgname = self.fgname L.fg = fgname L.dynfg=dynfg if (vsrandom.random()<self.capshipprob): L.type=faction_ships.getRandomCapitol(fac) else: L.type=faction_ships.getRandomFighter(fac) L.ai="default" L.faction=fac L.num=1 L.minradius=3000.0 L.maxradius=4000.0 if i == 0: L.fgappend="" else: L.fgappend="_"+str(i) try: L.minradius*=faction_ships.launch_distance_factor L.maxradius*=faction_ships.launch_distance_factor except: pass if (self.patrolpoints[num]): newun=L.launch(self.patrolpoints[num]) if (self.forceattack): lead=newun.getFlightgroupLeader() if (lead): lead.SetTarget(self.you) else: newun.setFlightgroupLeader(newun) newun.SetTarget(self.you) newun.setFgDirective("A.") self.Track(newun) patrol.patrol.DeletePatrolPoint(self,num,nam)
def basicUnit (un, diff): i=0 for i in range(upgrades_weapons_default_weapon_count): #no unarmed ships, please percent=un.upgrade(upgrades_weapons_default_weapon,i,0,0,1) UpgradeEngine (un,diff) UpgradeRadar (un,diff) #UpgradeArmor (un,diff) if ((vsrandom.random()<0.9) and (vsrandom.random()<(diff*5.0))): UpgradeAfterburner(un,diff) if ((vsrandom.random()<0.9) and (vsrandom.random()<(diff*5.0))): percent=un.upgrade("jump_drive",i,i,0,1) else: percent=un.upgrade("jump_drive",i,i,0,1)
def generateBountyMission(path, fg, fac): typ = fg_util.RandomShipIn(fg, fac) cap = faction_ships.isCapital(typ) makemissionharder = vsrandom.randrange(0, 2) diff = vsrandom.randrange(0, adjustQuantityDifficulty(7)) + howMuchHarder(makemissionharder) runaway = vsrandom.random() >= 0.75 creds = 750 + 1000 * runaway + 450 * diff + syscreds * len(path) if cap: creds *= 4 finalprice = creds + syscreds * len(path) finalprice *= getPriceModifier(False) addstr = "" isFixer = vsrandom.random() if isFixer < fixerpct: finalprice *= 2 addstr += "#F#bases/fixers/hunter.spr#Talk with the Bounty Hunter#We will pay you on mission completion. And as far as anyone knows-- we never met." if runaway: addstr += "#Also-- we have information that the target may be informed about your attack and may be ready to run. Be quick!" addstr += "#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Bounty#\n" elif use_missioncomputer: addstr += "#C#Bounty#\n" writemissionsavegame( addstr + mission_script_template % dict(module="bounty", constructor="bounty", args=(0, 0, finalprice, runaway, diff, fac, path, "", fg, typ)) ) diffstr = "" if diff > 0: diffstr = " The ship in question is thought to have %d starships for protection." % diff randCompany = GetRandomCompanyName() bountyb = GetRandomBountyBrief() composedBrief = bountyb.replace("$CL", randCompany) composedBrief = composedBrief.replace("$MT", formatShip(typ)) composedBrief = composedBrief.replace("$DS", processSystem(path[-1])) composedBrief = composedBrief.replace("$PY", str(int(finalprice))) if len(path) == 1: mistype = "IN-SYSTEM BOUNTY" else: mistype = "BOUNTY" writedescription(composedBrief) if cap: writemissionname( "Bounty/on_%s_Capital_Vessel_in_%s" % (fac, processSystem(path[-1])), path, isFixerString(addstr) ) else: writemissionname("Bounty/on_%s_starship_in_%s" % (fac, processSystem(path[-1])), path, isFixerString(addstr)) writemissionvars({"MISSION_TYPE": mistype})
def PlayMusik(forcechange=1, hostile_dist=0): un = VS.getPlayer() if (not un): mpl (PEACELIST,PEACELIST,forcechange) debug.info("PlayMusik: Peace (not un)") else: perfect = 1 #debug.debug("before 'uni = VS.getUnitList()'") uni = VS.getUnitList() #debug.debug("after 'uni = VS.getUnitList()'") unlist = [] asteroid = 0 while (not uni.isDone()): #debug.debug("before 'target = next(uni)'") target = next(uni) #debug.debug("after 'target = next(uni)'") if not target.isNull(): #debug.debug("inside 'if not target.isNull():'") ftmp = 2 * target.getRelation(un) nam = target.getName().lower() if un.getSignificantDistance(target) <= 2 * target.rSize() and ('afield' == nam[:6] or 'asteroid'== nam[:8]): asteroid = 1 hdis = HOSTILE_AUTODIST if (hostile_dist != 0): hdis = hostile_dist if (target.GetTarget() == un or (ftmp < 0 and un.getDistance(target) < hdis)): unlist.append(target.getFactionName()) perfect = 0 if (perfect): if asteroid and asteroidmisic != -1 and vsrandom.random() < .7: mpl(asteroidmisic, PEACELIST, forcechange) return sys = VS.getSystemFile() fact = VS.GetGalaxyFaction(sys) if vsrandom.random() < .5: fact = None mpl(LookupTable(peacelist, fact), PEACELIST, forcechange) debug.info("PlayMusik: Peace") else: ftmp = (un.FShieldData() + 2 * un.GetHullPercent() + un.RShieldData() - 2.8) * 2 fact = None if len(unlist) and vsrandom.random() < .5: fact = unlist[vsrandom.randrange(0, len(unlist))] debug.info("faction: %s" % (fact)) if (ftmp < -.5): mpl(LookupTable(paniclist, fact), BATTLELIST, forcechange) debug.info("PlayMusik: Panic") else: mpl(LookupTable(battlelist, fact), BATTLELIST, forcechange) debug.info("PlayMusik: Battle")
def basicUnit(un, diff): """This sets up a blank unit with the basic upgrades needed for any sort of figthing""" i = 0 while (i < 2): # two lasers percent = un.upgrade("laser", i, i, 0, 1) i = i + 1 UpgradeEngine(un, diff) UpgradeRadar(un) if ((vsrandom.random() < 0.9) and (vsrandom.random() < (diff * 5.0))): UpgradeAfterburner(un, diff) if ((vsrandom.random() < 0.9) and (vsrandom.random() < (diff * 5.0))): percent = un.upgrade("jump_drive", i, i, 0, 1) else: percent = un.upgrade("jump_drive", i, i, 0, 1)
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.")
def basicUnit(un, diff): i = 0 for i in range( upgrades_weapons_default_weapon_count): #no unarmed ships, please percent = un.upgrade(upgrades_weapons_default_weapon, i, 0, 0, 1) UpgradeEngine(un, diff) UpgradeRadar(un, diff) #UpgradeArmor (un,diff) if ((vsrandom.random() < 0.9) and (vsrandom.random() < (diff * 5.0))): UpgradeAfterburner(un, diff) if ((vsrandom.random() < 0.9) and (vsrandom.random() < (diff * 5.0))): percent = un.upgrade("jump_drive", i, i, 0, 1) else: percent = un.upgrade("jump_drive", i, i, 0, 1)
def PlayMusik(forcechange=1,hostile_dist=0): global __enabled un = VS.getPlayer() if not un or not __enabled: #mpl (PEACELIST,PEACELIST,forcechange) #print "Ppeace" pass elif un.DockedOrDocking() not in [1,2]: perfect=1 iter = VS.getUnitList() target = iter.current() unlist=[] asteroid=0 while (iter.notDone()): if (target): ftmp = 2*target.getRelation(un) nam=target.getName().lower() if un.getSignificantDistance(target)<=2*target.rSize() and ('afield'==nam[:6] or 'asteroid'==nam[:8]): asteroid=1 hdis = HOSTILE_AUTODIST if (hostile_dist!=0): hdis = hostile_dist if (target.GetTarget()==un or (ftmp<0 and un.getDistance(target)<hdis)): unlist.append(target.getFactionName()) perfect=0 iter.advance() target=iter.current() if (perfect): if asteroid and asteroidmisic!=-1 and vsrandom.random()<.7: mpl(asteroidmisic,PEACELIST,forcechange) return sys=VS.getSystemFile() fact=VS.GetGalaxyFaction(sys) if vsrandom.random()<.5: fact=None mpl(LookupTable(peacelist,fact),PEACELIST,forcechange) print "peaCce" else: ftmp = (un.FShieldData()+2*un.GetHullPercent()+un.RShieldData()-2.8)*2 fact=None if len(unlist) and vsrandom.random()<.5: fact=unlist[vsrandom.randrange(0,len(unlist))] print fact if (ftmp<-.5): mpl(LookupTable(paniclist,fact),BATTLELIST,forcechange) print "paAnic" else: mpl(LookupTable(battlelist,fact),BATTLELIST,forcechange) print "bSattle"
def generateBountyMission(path, fg, fac, baseprice=1200.0, runawayprice=1000.0, diffprice=450.0, capscale=4.0): typ = fg_util.RandomShipIn(fg, fac) cap = faction_ships.isCapital(typ) makemissionharder = vsrandom.randrange(0, 2) diff = vsrandom.randrange( 0, adjustQuantityDifficulty(7)) + howMuchHarder(makemissionharder) runaway = (vsrandom.random() >= .75) creds = (baseprice + runawayprice * runaway + diffprice * diff + syscreds * len(path)) if (cap): creds *= capscale finalprice = creds + syscreds * len(path) finalprice *= getPriceModifier(False) addstr = "" isFixer = vsrandom.random() if isFixer < fixerpct: finalprice *= 2 addstr += "#F#bases/fixers/hunter.spr#Talk with the Bounty Hunter#We will pay you on mission completion. And as far as anyone knows -- we never met." if (runaway): addstr += '#Also-- we have information that the target may be informed about your attack and may be ready to run. Be quick!' addstr += "#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Bounty#\n" writemissionsavegame( addstr + "import bounty\ntemp=bounty.bounty(0, 0, %g, %d, %d, '%s', %s, '', '%s','%s')\ntemp=0\n" % (finalprice, runaway, diff, fac, str(path), fg, typ)) diffstr = "" if (diff > 0): diffstr = " The ship in question is thought to have %d starships for protection." % diff writedescription( "A %s starship in the %s flightgroup has been harassing operations in the %s system. Reward for the termination of said ship is %d credits.%s" % (formatShip(typ), fg, processSystem(path[-1]), finalprice, diffstr)) if (cap): writemissionname( "Bounty/on_%s_Capital_Vessel_in_%s" % (fac, processSystem(path[-1])), path, isFixerString(addstr)) else: writemissionname( "Bounty/on_%s_starship_in_%s" % (fac, processSystem(path[-1])), path, isFixerString(addstr))
def generateCargoMission (path, numcargos,category, fac): #if (isNotWorthy(fac)): # return if (vsrandom.random()<.25): return launchcap=0 if (not launchcap) and not isHabitable(path[-1]): return diff=vsrandom.randrange(0,adjustQuantityDifficulty(6)) creds=65*numcargos+145*diff+syscreds*len(path)+3250*(category[:10]=="Contraband")+5000*(category[:9]=="starships") addstr="" creds*=getPriceModifier(False) isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Cargo#\n" elif use_missioncomputer: addstr+="#C#Cargo#\n" writemissionsavegame (addstr+mission_script_template % dict( module='cargo_mission', constructor='cargo_mission', args=(fac,0,numcargos,diff,creds,launchcap,0,category,path,''))) if (category==''): category='generic' randCompany = GetRandomCompanyName() if (randCompany==''): strStart = "We need to deliver some " else: strStart = randCompany+" seeks delivery of " if len(path)==1: mistype = 'IN-SYSTEM CARGO' else: mistype = 'CARGO' brief = GetRandomCargoBrief() if (brief<>''): composedBrief = brief.replace('$CL',randCompany) composedBrief = composedBrief.replace('$CG',formatCargoCategory(category)) composedBrief = composedBrief.replace(' $DB','') composedBrief = composedBrief.replace('$DS',processSystem(path[-1])) composedBrief = composedBrief.replace('$PY',str(int(creds))) writedescription(composedBrief) else: writedescription(strStart+"%s cargo to the %s system. The mission is worth %d credits to us. You will deliver it to a base owned by the %s.%s"%(formatCargoCategory(category), processSystem(path[-1]),creds,fac,pathWarning(path,isFixer<guildpct))) writemissionname("Cargo/Deliver_%s_to_%s"%(changecat(category),processSystem(path[-1])),path,isFixerString(addstr)) writemissionvars( { 'MISSION_TYPE' : mistype } )
def generateEscortMission (path,fg,fac): ### if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] diff=vsrandom.randrange(0,6) creds=250*diff+1.2*syscreds*len(path) creds*=getPriceModifier(False) addstr="" isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until you reach the destination.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" elif use_missioncomputer: addstr+="#C#Escort#\n" if len(path)==1: mistype = 'IN-SYSTEM ESCORT' else: mistype = 'ESCORT' writemissionsavegame (addstr+mission_script_template % dict( module='escort_mission', constructor='escort_mission', args=(fac,diff,float(creds),0,0,path,'',fg,typ))) writedescription("The %s %s in the %s flightgroup requres an escort to %s. The reward for a successful escort is %d credits."%(fac,formatShip(typ),fg, processSystem(path[-1]),creds)) writemissionname("Escort/Escort_%s_%s_to_%s"%(fac,fg,processSystem(path[-1])),path,isFixerString(addstr)) writemissionvars( { 'MISSION_TYPE' : mistype } )
def generateDefendMission (path,defendfg,defendfac, attackfg,attackfac, baseprice=1200.0 ): if (isNotWorthy(defendfac)): return #defendtyp = fg_util.RandomShipIn(defendfg,defendfac) attacktyp = fg_util.RandomShipIn(attackfg,attackfac) isbase=fg_util.BaseFGInSystemName(path[-1])==defendfg creds=baseprice minq = 1 maxq = adjustQuantityDifficulty(5) makemissionharder=vsrandom.randrange(0,2) quantity = vsrandom.randrange(minq,maxq)+howMuchHarder(makemissionharder) reallydefend = "1" if (vsrandom.randrange(0,4)==0): reallydefend="0" addstr="" creds=creds*quantity+syscreds*len(path) creds*=getPriceModifier(makemissionharder) isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your defense will help confed in the long run. We appreciate the support of the bounty hunting community.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Defend#\n" writemissionsavegame(addstr+"import defend\ntemp=defend.defend('%s', %d, %d, 8000.0, 100000.0, %g, %s, %d, '%s', %s, '%s', '%s', '%s', '%s')\ntemp=0\n"% (attackfac, 0, quantity, creds, reallydefend, isbase, defendfac, str(path), '',attackfg, attacktyp,defendfg)) iscapitol="" if isbase: iscapitol="capital " writedescription("A %s assault wing named %s has jumped in and is moving for an attack on one of our %sassets in the %s system.\nYour task is to eradicate them before they eliminate our starship.\nIntelligence shows that they have %d starships of type %s. Your reward is %d credits."%(attackfac, attackfg, iscapitol, processSystem(path[-1]),quantity, formatShip(attacktyp),creds)) writemissionname("Defend/Defend_%s_from_%s"%(defendfac, attackfac),path,isFixerString(addstr))
def generateEscortMission(path, fg, fac, baseprice=500.0, jumpscale=1.2): ### if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg, fac) if typ in faction_ships.unescortable: return diff = vsrandom.randrange(0, 6) creds = baseprice * diff + jumpscale * syscreds * len(path) creds *= getPriceModifier(False) addstr = "" isFixer = vsrandom.random() if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until you reach the destination.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Escort#\n" writemissionsavegame( addstr + "import escort_mission\ntemp=escort_mission.initrandom('%s', %d, %g, 0, 0, %s, '','%s','%s')\ntemp=0\n" % (fac, diff, float(creds), str(path), fg, typ)) writedescription( "The %s %s in the %s flightgroup requres an escort to %s. The reward for a successful escort is %d credits." % (fac, formatShip(typ), fg, processSystem(path[-1]), creds)) writemissionname( "Escort/Escort_%s_%s_to_%s" % (fac, fg, processSystem(path[-1])), path, isFixerString(addstr))
def generateEscortMission (path,fg,fac): ### if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] diff=vsrandom.randrange(0,6) creds=500*diff+1.2*syscreds*len(path) creds*=getPriceModifier(False) addstr="" isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Danke. Ich vertraue dir, dass du meinen Geschaeftspartner sicher geleiten wirst, bis er sein Ziel erreicht.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" writemissionsavegame (addstr+"import escort_mission\ntemp=escort_mission.initrandom('%s', %d, %g, 0, 0, %s, '','%s','%s')\ntemp=0\n"%(fac, diff, float(creds), str(path),fg,typ)) # From plueschinger to avoid sometimes squadrons and sometimes not # we mention the squadrons or konvois later in the following message if "Squadron" == fg[-8:]: fg = fg[:-9] # end of plueschingers addition writedescription("Die %s %s in dem %s Konvoi benoetigt eine Eskorte nach %s. Die Belohnung fuer eine erfolgreiche Eskorte betraegt %d Kredite."%(fac,formatShip(typ),fg, processSystem(path[-1]),creds)) writemissionname("Eskorte/Eskortiere den_%s aus der_%s Schwadron in das_%s System"%(fac,fg,processSystem(path[-1])),path,isFixerString(addstr))
def Execute(self): generate_dyn_universe.KeepUniverseGenerated() dynamic_battle.UpdateCombatTurn() if (self.cur_player>=len(self.players)): self.AddPlayer() self.cur=self.players[self.cur_player] if (self.cur.curquest<len(self.cur.quests)): if (self.cur.quests[self.cur.curquest].Execute()): self.cur.curquest+=1 else: del self.cur.quests[self.cur.curquest] else: self.cur.curquest=0 un = self.decideMode () if (self.cur.curmode!=self.cur.lastmode): #lastmode=curmode#processed this event don't process again if in critical zone if ((self.spawning or (vsrandom.random()<(self.fighterprob*self.cur.UpdatePhaseAndAmplitude()))) and un): debug.debug("curmodechange %d in progress" % (self.cur.curmode)) if (VS.vsConfig("physics","spawn_units_close","false")=="true" and not self.atLeastNInsignificantUnitsNear (un,self.min_num_ships)): #determine whether to launch more ships next to significant thing based on ships in that range debug.debug("launch near") self.launch_near (VS.getPlayerX(self.cur_player)) self.spawning=1 else: self.cur.lastmode=self.cur.curmode self.spawning=0 debug.debug("curmodechange %d ended" % (self.cur.curmode)) else: self.cur.lastmode=self.cur.curmode self.spawning=0 debug.debug("curmodechange %d ended" % (self.cur.curmode)) self.cur_player+=1 if (self.cur_player>=VS.getNumPlayers()): self.cur_player=0 VS.setMissionOwner(self.cur_player)
def generateEscortLocal(path,fg,fac): if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] enfac = faction_ships.get_enemy_of(fac) diff=vsrandom.randrange(1,4) waves=vsrandom.randrange(0,5-diff) incoming=vsrandom.randrange(0,2) enfg =fg_util.AllFGsInSystem(enfac,path[-1]) creds=3500.0*diff*(1+waves); if (len(enfg)): enfg=enfg[vsrandom.randrange(0,len(enfg))] else: enfg='' isFixer=vsrandom.random() addstr="" if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Unterhalte Dich mit dem Kaufmann#Danke. Ich vertraue dir, dass du meinen Geschaeftspartner sicher geleiten wirst, bis er sein Ziel erreicht.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" additionalinfo="zu dem Sprungpunkt" if (incoming): additionalinfo="von dem Sprungpunkt zu einer nahen Basis" writemissionsavegame(addstr+"import escort_local\ntemp=escort_local.escort_local('%s',0,%d,%d,500,%d,%d,'%s',(),'','%s','','%s','%s')"%(enfac,diff,waves,creds,incoming,fac,enfg,fg,typ)) # From plueschinger to avoid sometimes squadrons and sometimes not # we mention the squadrons or konvois later in the following message if "Squadron" == fg[-8:]: fg = fg[:-9] # end of plueschingers addition writedescription("Eine Eskorte %s ist erforderlich fuer die %s Klasse %s der Raumschiffe aus der %s Schwadron in diesem System. Angriffe von der %s Gruppe sind moeglich. Sie werden bezahlt mit %d Krediten, falls das Raumschiff in diesem Sternensystem ueberlebt, bis es seinen Zielort erreicht."%(additionalinfo,formatShip(typ),fac,fg,enfac,int(creds))) writemissionname("Eskorte/Eskortiere den_%s in dem_%s Konvoi"%(fac,fg),[path[-1]],isFixerString(addstr))
def PlayLaunch(): if (vsrandom.random() < .02): VS.musicPlaySong('../music/launchjoke.ogg') # VS.micro_sleep(45000000) else: if (GlobalMusic != -1): VS.musicPlayList(GlobalMusic)
def generateEscortMission (path,fg,fac, baseprice = float(VS.vsConfig("dynamic_universe","missions.escort.waveprice","500")), jumpscale = float(VS.vsConfig("dynamic_universe","missions.escort.jumpscale","0.5")) ): ### if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: typ = faction_ships.unescortable[typ] diff=vsrandom.randrange(0,6) creds=baseprice*diff+jumpscale*syscreds*len(path) creds*=getPriceModifier(False) addstr="" isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust that you will safely guide my collegue until you reach the destination.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" if len(path)==1: mistype = 'IN-SYSTEM ESCORT' else: mistype = 'ESCORT' writemissionsavegame (addstr+"import escort_mission\ntemp=escort_mission.initrandom('%s', %d, %g, 0, 0, %s, '','%s','%s')\ntemp=0\n"%(fac, diff, float(creds), str(path),fg,typ)) writedescription("The %s %s in the %s flightgroup requres an escort to %s. The reward for a successful escort is %d credits."%(fac,formatShip(typ),fg, processSystem(path[-1]),creds)) writemissionname("Escort/Escort_%s_%s_to_%s"%(fac,fg,processSystem(path[-1])),path,isFixerString(addstr)) writemissionvars( { 'MISSION_TYPE' : mistype } )
def generatePatrolMission (path, numplanets, planetprice = float(VS.vsConfig("dynamic_universe","missions.patrol.planetprice","100")), baseprice = float(VS.vsConfig("dynamic_universe","missions.patrol.baseprice","2400")), jumpscale = float(VS.vsConfig("dynamic_universe","missions.patrol.jumpscale","1")) ): dist=400 creds = numplanets*planetprice+baseprice+jumpscale*syscreds*len(path) creds*=getPriceModifier(False) addstr="" isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Patrol#\n" writemissionsavegame (addstr+"import patrol\ntemp=patrol.patrol(0, %d, %d, %d, %s)\ntemp=0\n"%(numplanets, dist, creds, str(path))) writedescription("Insystem authorities would like a detailed scan of the %s system. We require %d nav locations be visited on the scanning route. The pay for this mission is %d."%(processSystem(path[-1]),numplanets,creds)) ispoint="s" if numplanets==1: ispoint="" if len(path)==1: mistype = 'IN-SYSTEM PATROL' else: mistype = 'PATROL' writemissionname("Patrol/Patrol_%d_Point%s_in_%s"%(numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr)) writemissionvars( { 'MISSION_TYPE' : mistype } )
def generatePatrolMission(path, numplanets, planetprice=100.0, baseprice=800.0, jumpscale=3.0): dist = 400 creds = numplanets * planetprice + jumpscale * baseprice + syscreds * len( path) creds *= getPriceModifier(False) addstr = "" isFixer = vsrandom.random() if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your help makes space a safer place.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Patrol#\n" writemissionsavegame( addstr + "import patrol\ntemp=patrol.patrol(0, %d, %d, %d, %s)\ntemp=0\n" % (numplanets, dist, creds, str(path))) writedescription( "Insystem authorities would like a detailed scan of the %s system. We require %d nav locations be visited on the scanning route. The pay for this mission is %d." % (processSystem(path[-1]), numplanets, creds)) ispoint = "s" if numplanets == 1: ispoint = "" writemissionname( "Patrol/Patrol_%d_Point%s_in_%s" % (numplanets, ispoint, processSystem(path[-1])), path, isFixerString(addstr))
def generateWingmanMission(fg, faction): numships=vsrandom.randrange(1,4) creds=10000+15000*numships writemissionsavegame ('#\n' + mission_script_template % dict( module='wingman', constructor='wingman', args=(creds,faction,numships,0))) s="A pilot" EorA="a" are="is" if numships > 1: s=str(numships)+" pilots" EorA="e" are="are" isFixer=vsrandom.random() if isFixer<fixerpct and fixer_has_wingman: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Wingman#\n" elif use_missioncomputer: addstr+="#C#Wingman#\n" writedescription(s+" in the %s faction %s willing to help you out and fight with you as long as you pay %d credits."%(faction, are, creds)) writemissionname("Wingmen/Hire_%d_%s_Wingm%sn"%(numships,faction,EorA),[VS.getSystemFile()],0) writemissionvars( { 'MISSION_TYPE' : 'CONTRACT WINGMAN' } )
def PlayLaunch (): if (vsrandom.random()<.02): VS.musicPlaySong('../music/launchjoke.ogg') # VS.micro_sleep(45000000) else: if (GlobalMusic!= -1): VS.musicPlayList (GlobalMusic)
def Execute (self): ## if (VS.getGameTime()>mission_time): ## VS.IOmessage (0,"cargo mission",self.mplay,"You Have failed to deliver your cargo in a timely manner.") ## VS.IOmessage (0,"cargo mission",self.mplay,"The cargo is no longer of need to us.") ## if (you): ## takeCargoAndTerminate(you,0) ## return if (self.you.isNull() or (self.arrived and self.base.isNull())): VS.IOmessage (0,"cargo mission",self.mplay,"#ff0000You were unable to deliver cargo. Mission failed.") self.SetVar(-1) VS.terminateMission(0) return if (not self.adjsys.Execute() and not (self.arrived and self.base and self.base.isDocked(self.you))): return if (self.arrived): self.adjsys.Execute=self.adjsys.HaveArrived if (self.base.isDocked(self.you) or (self.base.getDistance(self.you)<=1 and not self.knownBases())): self.takeCargoAndTerminate(self.you,1) return else: self.arrived=1 tempfac=self.faction if vsrandom.random()<=.5: tempfac='' self.adjsys=go_somewhere_significant(self.you,1,100,not self.capship,tempfac) capstr="planet" dockstr="land" if tempfac=='': dockstr="dock" capstr="ship" self.adjsys.Print("You must visit the %%s %s" % (capstr),"cargo mission",", docked around the %s",0) VS.IOmessage(0,"cargo mission",self.mplay,"Once there, %s and we will transport the cargo off of your ship." % (dockstr)) self.base=self.adjsys.SignificantUnit() self.role=self.base.getCombatRole() self.base.setCombatRole("INERT")
def AddSysDict(cursys): #pick random fighter from insysenemies with .3 probability OR pick one from the friendlies list. # debug.debug('Addsysdict') sysfaction = VS.GetGalaxyFaction(cursys) global fgnames, fglists i = 0 AddBasesToSystem(sysfaction, cursys) for i in range(1 + vsrandom.randrange( fg_util.MinNumFlightgroupsInSystem(cursys) - 1, fg_util.MaxNumFlightgroupsInSystem(cursys)) ): #number of fgs in a system. faction = sysfaction friendly = 0 if vsrandom.random( ) < .3 or sysfaction == 'unknown' or sysfaction == '': faction = faction_ships.get_rabble_of(sysfaction) else: faction = faction_ships.get_friend_of(sysfaction) if (faction == sysfaction): friendly = 1 if (sysfaction in faction_ships.production_centers): if (cursys in faction_ships.production_centers[sysfaction]): friendly = 2 #if (friendly): # debug.debug(faction+" "+sysfaction+" "+cursys) factionnr = faction_ships.factionToInt(faction) global maxshipsinfg typenumbertuple = GenerateFgShips( vsrandom.randrange(maxshipsinfg) + 1, factionnr, friendly) fgname = GetNewFGName(faction) fg_util.AddShipsToFG(fgname, faction, typenumbertuple, cursys) return i
def look_for (fg, faction, numships,myunit, pos, gcd,newship=[None]): i=0 debug.debug("VS.getUnit (%d)" % (i)) un = VS.getUnit (i) while (not un.isNull()): i+=1 debug.debug("VS.getUnit (%d)" % (i)) un = VS.getUnit (i) i-=1 #now our i is on the last value while ((i>=0) and (numships>0)): debug.debug("VS.getUnit (%d)" % (i)) un = VS.getUnit (i) if (not un.isNull()): if (unOrTupleDistance(un,myunit,1)>gcd ): fac = un.getFactionName () fgname = un.getFlightgroupName () name = un.getName () if ((fg==fgname) and (fac==faction)): if (numships>0): if (vsrandom.random()<0.75): pos=move_to (un,pos) numships-=1 newship[0]=un debug.info("TTYmoving %s to current area" % (name)) else: #toast 'im! un.Kill() debug.info("TTYaxing %s" % (name)) i-=1 return (numships,pos)
def GetShipsInFG(fgname,faction): ships = ReadStringList (ccp,MakeFGKey(fgname,faction)) if (len(ships)<=ShipListOffset()): return [] try: count=int(ships[0]) except: debug.error('bad flightgroup record %s', ships) launchnum = DefaultNumShips() if (launchnum>count): launchnum=count nent = (len(ships) - ShipListOffset()) / PerShipDataSize() retn = [0] * nent for i in xrange(_prob_round(launchnum*(0.7+vsrandom.random()+0.3))): which = vsrandom.randrange(count) for j in xrange(nent): pos = j*PerShipDataSize()+ShipListOffset() which -= int(ships[pos+2]) if which <= 0: retn[j] += 1 break ret = [] for i in xrange(nent): if retn[i]: pos = i*PerShipDataSize()+ShipListOffset() ret.append((ships[pos],retn[i])) return ret
def launch_near(self,un): if (VS.GetGameTime()<10): print "hola!" return cursys=VS.getSystemFile() # numsigs=universe.GetNumSignificantsForSystem(cursys) for factionnum in range(faction_ships.getMaxFactions()-1): faction=faction_ships.intToFaction(factionnum) fglist=fg_util.FGsInSystem(faction,cursys) if not len(fglist): print 'no flight group for faction: '+faction+' in system '+cursys+'.' continue num=len(fglist) print 'Probability numbers: ',num, fg_util.MaxNumFlightgroupsInSystem(cursys)#,numsigs avg=float(num)/float(fg_util.MaxNumFlightgroupsInSystem(cursys))#/float(numsigs) fortress_level=0 if cursys in faction_ships.fortress_systems: foretress_level=faction_ships.fortress_systems[cursys] avg*=(not (VS.GetRelation(VS.GetGalaxyFaction(cursys),faction)<0 and cursys in faction_ships.fortress_systems))*fortress_level+(1-fortress_level) print 'Chance for %s ship: %g'%(faction, avg) rndnum=vsrandom.random() print 'Random number: %g; will generate ship: %d'%(rndnum,rndnum<avg) if rndnum<avg: #now we know that we will generate some ships! flightgroup=fglist[vsrandom.randrange(len(fglist))] typenumbers=fg_util.GetShipsInFG(flightgroup,faction) print 'FG Name: "%s", ShipTypes: %s'%(flightgroup,str(typenumbers)) launch_recycle.launch_types_around(flightgroup,faction,typenumbers,'default',self.generation_distance*vsrandom.random()*0.9,un,self.generation_distance*vsrandom.random()*2,'')
def loopbriefing(self): size=len(self.JumpPoints()) time = VS.GetGameTime() Briefing.setCamPosition((1.6*(time-self.begintime)*self.brief_stage,0.0,0.0)) if (((time-self.begintime)>=5.0) and self.added_warp): self.jump_ani=Briefing.addShip("brief_warp",self.faction,(20.0*(self.brief_stage),self.rnd_y,79.5+self.rnd_y)) self.added_warp=0 if (((time-self.begintime)>=6.0)): if (self.jump_ani!=0): Briefing.removeShip(self.jump_ani) self.jump_ani=0 if ((size==self.brief_stage) and ((time-self.begintime)>=6.0)): self.brief_stage=size+1 self.added_warp=0 self.time=0.0 elif ((self.brief_stage>size) and ((time-self.begintime)>=11.0)): return self.brief_you elif (((time-self.begintime)>=6.0) and (self.brief_stage<size)): self.added_warp=1 self.rnd_y=(vsrandom.random()*40.0-20.0) Briefing.addShip("brief_jump",self.faction,(20.0*(self.brief_stage+1),self.rnd_y,79.6+self.rnd_y)) Briefing.enqueueOrder (self.brief_you,(20.0*(self.brief_stage+1) ,self.rnd_y,80.0+self.rnd_y) , 5.0) self.begintime=time myname=self.JumpPoints() [self.brief_stage] VS.IOmessage (0,"cargo mission","briefing","You must go to the '%s' jump point" % (myname)) self.brief_stage+=1 return -1
def AddSysDict (cursys): #pick random fighter from insysenemies with .3 probability OR pick one from the friendlies list. # debug.debug('Addsysdict') sysfaction=VS.GetGalaxyFaction(cursys) global fgnames, fglists i=0 AddBasesToSystem(sysfaction, cursys) for i in range (1+vsrandom.randrange(fg_util.MinNumFlightgroupsInSystem(cursys)-1,fg_util.MaxNumFlightgroupsInSystem(cursys))): #number of fgs in a system. faction=sysfaction friendly=0 if vsrandom.random()<.3 or sysfaction=='unknown' or sysfaction=='': faction=faction_ships.get_rabble_of(sysfaction) else: faction=faction_ships.get_friend_of(sysfaction) if (faction==sysfaction): friendly=1 if (sysfaction in faction_ships.production_centers): if (cursys in faction_ships.production_centers[sysfaction]): friendly=2 #if (friendly): # debug.debug(faction+" "+sysfaction+" "+cursys) factionnr=faction_ships.factionToInt(faction) global maxshipsinfg typenumbertuple=GenerateFgShips(vsrandom.randrange(maxshipsinfg)+1,factionnr,friendly) fgname=GetNewFGName(faction) fg_util.AddShipsToFG (fgname,faction,typenumbertuple,cursys) return i
def generateEscortLocal(path,fg,fac, waveprice=3500.0 ): if (isNotWorthy(fac)): return typ = fg_util.RandomShipIn(fg,fac) if typ in faction_ships.unescortable: return enfac = faction_ships.get_enemy_of(fac) diff=vsrandom.randrange(1,4) waves=vsrandom.randrange(0,5-diff) incoming=vsrandom.randrange(0,2) enfg =fg_util.AllFGsInSystem(enfac,path[-1]) creds=waveprice*diff*(1+waves); if (len(enfg)): enfg=enfg[vsrandom.randrange(0,len(enfg))] else: enfg='' isFixer=vsrandom.random() addstr="" if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I trust that you will safely escort my colleague to the destination.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Escort#\n" additionalinfo="to the jump point" if (incoming): additionalinfo="from the jump point to a nearby base" writemissionsavegame(addstr+"import escort_local\ntemp=escort_local.escort_local('%s',0,%d,%d,500,%d,%d,'%s',(),'','%s','','%s','%s')"%(enfac,diff,waves,creds,incoming,fac,enfg,fg,typ)) writedescription("Escort %s is required for the %s type %s starship from the %s flightgroup in this system. Attacks from the %s faction are likely. You will be paid %d credits if the starship survives in this starsystem until it reaches its destination."%(additionalinfo,formatShip(typ),fac,fg,enfac,int(creds))) writemissionname("Escort/Escort_%s_%s"%(fac,fg),[path[-1]],isFixerString(addstr))
def generateCargoMission (path, numcargos,category, fac, cargoprice=250.0, baseprice=500.0, contrabandprice=5000.0, starshipprice=20000.0 ): #if (isNotWorthy(fac)): # return launchcap=(vsrandom.random()>=.97) if (not launchcap) and not isHabitable(path[-1]): return diff=vsrandom.randrange(0,adjustQuantityDifficulty(6)) creds = ( cargoprice*numcargos + baseprice*diff + syscreds*len(path) + contrabandprice*(category[:10]=="Contraband") + starshipprice*(category[:9]=="starships") ) addstr="" creds*=getPriceModifier(False) isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Talk to the Merchant#Thank you. I entrust you will make the delivery successfully.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Cargo#\n" writemissionsavegame (addstr+"import cargo_mission\ntemp=cargo_mission.cargo_mission('%s', 0, %d, %d, %g, %d, 0, '%s', %s, '')\ntemp=0\n"%(fac, numcargos, diff, creds, launchcap, category, str(path))) if (category==''): category='generic' randCompany = GetRandomCompanyName() if (randCompany==''): strStart = "We need to deliver some " else: strStart = randCompany+" seeks delivery of " brief = GetRandomCargoBrief() if brief: # a comparison to an empty string returns False composedBrief = brief.replace('$CL',randCompany) composedBrief = composedBrief.replace('$CG',formatCargoCategory(category)) composedBrief = composedBrief.replace(' $DB','') composedBrief = composedBrief.replace('$DS',processSystem(path[-1])) composedBrief = composedBrief.replace('$PY',str(int(creds))) writedescription(composedBrief) else: writedescription(strStart+"%s cargo to the %s system. The mission is worth %d credits to us. You will deliver it to a base owned by the %s.%s"%(formatCargoCategory(category), processSystem(path[-1]),creds,fac,pathWarning(path,isFixer<guildpct))) writemissionname("Cargo/Deliver_%s_to_%s"%(changecat(category),processSystem(path[-1])),path,isFixerString(addstr))
def initrandom (minns, maxns, credsmin, credsmax, run_away, minshipdifficulty, maxshipdifficulty,jumps=(),var_to_set=''): you=VS.getPlayer() tempfaction='aera' if (you): name = you.getFactionName () factionname=vsrandom.randrange(0,faction_ships.getMaxFactions()) tempfaction=faction_ships.intToFaction(factionname) i=0 while ((name==tempfaction or name=="unknown") and i<10): factionname=vsrandom.randrange(0,faction_ships.getMaxFactions()) tempfaction=faction_ships.intToFaction(factionname) i+=1 sd = vsrandom.random()*(maxshipdifficulty-minshipdifficulty)+minshipdifficulty return bounty (minns,maxns,(1.0+(sd*0.5))*(vsrandom.random ()*(credsmax-credsmin)+credsmin),run_away,sd,tempfaction,jumps,var_to_set) else: print "aborting bounty initrandom" VS.terminateMission(0)
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
def MakeBar(concourse, time_of_day, bartext, BaseTexture, createCampaignFixers=True, bar_sprite_320x200=False, defaultbtr=None, forcedefbtr=False, patrons=[],bartenderhead=None): if vsrandom.random()<.875: forcedefbtr=True # remove me if you want random bartenders at random bars chbtr=True import bartender bartender.speaktimes=0 room0 = Base.Room ('Bar') x=0.0 y=0.0 if bar_sprite_320x200: x=0.0 #0.582 y=0.0 #-0.2716 Base.Texture (room0, 'background', BaseTexture+'.spr', x, y) for p in patrons: if vsrandom.random()<.85: Base.Texture(room0,str(p[0]),'bases/bar/'+str(p[0])+'.spr',float(p[1]),float(p[2])) if defaultbtr: if not forcedefbtr: defaultbtr=bartenders[vsrandom.randrange(len(bartenders))] Base.Texture(room0,'btr','bases/'+str(defaultbtr)+'/btr.spr', 0.925, -0.259765625) #0.89725, -0.2813) if not bartenderhead: bartenderhead = defaultbtr #Base.Texture (room0, 'texture', 'bases/bar/sandoval.spr', -0.43875, -0.373333) Base.Link (room0, 'concourse_link', -0.9225, -0.973333, 1.8275, 0.146667, 'Exit the Bar',concourse) script="#\n" if bartenderhead: import campaign_lib if campaign_lib.doTalkingHeads(): script+="import Base\nimport campaign_lib\ncampaign_lib.AddConversationStoppingSprite('Bartender','bases/heads/"+bartenderhead+".spr',(0,0),(3.2,2.0),'Return_To_Bar').__call__(Base.GetCurRoom(),None)\n" Base.Python (room0, 'talk', 0.5875, -0.373333, 0.285, 0.626667,'Talk to the Bartender',script+"import bartender\nbartender.Speak (bartender.GetBartenderText("+repr(bartext)+"))\n",0) Base.Python (room0, 'drink', 0.2875, -0.373333, 0.285, 0.326667,'Get a drink ',script+"import bartender\nbartender.Drink(100)\n",0) import fixers #was: # -0.53, -0.673333, 0.205, 0.61 #better: # -0.61, -0.86, 0.4105, 1 func=fixers.CreateFixers if not createCampaignFixers: func=fixers.CreateMissionFixers func(room0,[(-0.80025, -0.9764, 0.776, 1.2416, "_1"),(-0.0725, -0.4058125, 0.1758125, 0.5385, "_2")])#add more locations? 288 844 #func(room0,[(-0.80025, -1.0088, 0.776, 1.2416, "_1"),(-0.0725, -0.4058125, 0.1758125, 0.5385, "_2")])#add more locations? 288 844 #func(room0,[(-0.825, -1.04, 0.8, 1.28, "_1"),(-0.0747, -0.418, 0.181, 0.555, "_2")])#add more locations? 280 850 return room0;
def initrandom (minns, maxns, credsmin, credsmax, run_away, minshipdifficulty, maxshipdifficulty,jumps=(),var_to_set=''): you=VS.getPlayer() tempfaction='unknown' if (you): name = you.getFactionName () i=vsrandom.randrange(0,len(faction_ships.factionsInNormalMissions)) tempfaction=faction_ships.factionsInNormalMissions[i] i=0 while ((name==tempfaction or name=="unknown") and i<10): i=vsrandom.randrange(0,len(faction_ships.factionsInNormalMissions)) tempfaction=faction_ships.factionsInNormalMissions[i] i+=1 sd = vsrandom.random()*(maxshipdifficulty-minshipdifficulty)+minshipdifficulty return bounty (minns,maxns,(1.0+(sd*0.5))*(vsrandom.random ()*(credsmax-credsmin)+credsmin),run_away,sd,tempfaction,jumps,var_to_set) else: debug.info("aborting bounty initrandom") VS.terminateMission(0)
def GenerateFgShips (shipinfg,factionnr,friendly): lst=[] capship=() fac = faction_ships.intToFaction(factionnr) fpr=XProductionRate(fac,faction_ships.fighterProductionRate) cpr=XProductionRate(fac,faction_ships.capitalProductionRate) if cpr>0 and (friendly==2 or (friendly==1 and vsrandom.random()<cpr/fpr)): capship=((faction_ships.getRandomCapitolInt(factionnr),1),) debug.debug("Generating capital "+str(capship)) return ((faction_ships.getRandomFighterInt(factionnr),shipinfg),)+capship
def Execute(self): self.count+=1 if (self.count<3): return self.count=0 quant = (vsrandom.random()*(self.quantity-1))+1 #debug.debug("un = VS.getUnit (%d)" % (self.last_ship)) un = VS.getUnit (self.last_ship) if (un.isNull()): self.last_ship=0 else: if (un.isSignificant()): if (un.isPlayerStarship()==-1): global production name = un.getName() faction= un.getFactionName() if un.isPlanet(): name = un.getFullname(); faction="planets" prad=production.get((name,faction)) if None==prad: prad= getImports(name,faction) production[(name,faction)]=prad if len(prad): prod=prad[vsrandom.randrange(0,len(prad))] cargo=VS.getRandCargo(int(prod[3]+prod[4]),prod[0]) if (cargo.GetCategory()==prod[0]): removeCargo=False if (prod[3] or prod[4]): ownedcargo=un.GetCargo(cargo.GetContent()) quant=ownedcargo.GetQuantity() #if un.getName()=="mining_base" and (cargo.GetContent()=="Tungsten" or cargo.GetContent()=="Space_Salvage"): # debug.debug("Mining "+str(quant)+" from "+str(prod[3])+" to "+str(prod[4])) if (quant<prod[3]-prod[4] or quant==0): quant=int(prod[3]+vsrandom.uniform(-1,1)*prod[4]) #if un.getName()=="mining_base" and (cargo.GetContent()=="Tungsten" or cargo.GetContent()=="Space_Salvage"): # debug.debug("Will add quant "+str(quant)) if (quant>0): cargo.SetQuantity(quant) price = prod[1]+vsrandom.uniform(-1,1)*prod[2] cargo.SetPrice(cargo.GetPrice()*price) debug.debug(" adding "+str(quant)+" of "+cargo.GetContent()+" cargo for "+str(price)) un.addCargo(cargo) else: removeCargo=True elif quant>prod[3]+prod[4]: removeCargo=True else: removeCargo=True if removeCargo: ownedcargo=un.GetCargo(cargo.GetContent()) if (ownedcargo.GetQuantity()): debug.debug("Removing one "+ownedcargo.GetContent()) un.removeCargo(ownedcargo.GetContent(), ownedcargo.GetQuantity()//3 + 1, 0) self.last_ship+=1
def generateDefendMission(path, defendfg, defendfac, attackfg, attackfac, baseprice=float( VS.vsConfig("dynamic_universe", "missions.defend.baseprice", "5000")), jumpscale=float( VS.vsConfig("dynamic_universe", "missions.defend.jumpscale", "1"))): if (isNotWorthy(defendfac)): return #defendtyp = fg_util.RandomShipIn(defendfg,defendfac) attacktyp = fg_util.RandomShipIn(attackfg, attackfac) isbase = fg_util.BaseFGInSystemName(path[-1]) == defendfg creds = baseprice minq = 1 maxq = adjustQuantityDifficulty(5) makemissionharder = vsrandom.randrange(0, 2) quantity = vsrandom.randrange(minq, maxq) + howMuchHarder(makemissionharder) reallydefend = "1" if (vsrandom.randrange(0, 4) == 0): reallydefend = "0" addstr = "" creds = creds * quantity + jumpscale * syscreds * len(path) creds *= getPriceModifier(makemissionharder) isFixer = vsrandom.random() if isFixer < fixerpct: creds *= 2 addstr += "#F#bases/fixers/confed.spr#Talk to the Confed Officer#Thank you. Your defense will help confed in the long run. We appreciate the support of the bounty hunting community.#\n" elif isFixer < guildpct: creds *= 1.5 addstr += "#G#Defend#\n" writemissionsavegame( addstr + "import defend\ntemp=defend.defend('%s', %d, %d, 8000.0, 100000.0, %g, %s, %d, '%s', %s, '%s', '%s', '%s', '%s')\ntemp=0\n" % (attackfac, 0, quantity, creds, reallydefend, isbase, defendfac, str(path), '', attackfg, attacktyp, defendfg)) iscapitol = "" if isbase: iscapitol = "capital " if len(path) == 1: mistype = 'IN-SYSTEM DEFEND' else: mistype = 'DEFEND' writedescription( "A %s assault wing named %s has jumped in and is moving for an attack on one of our %sassets in the %s system.\nYour task is to eradicate them before they eliminate our starship.\nIntelligence shows that they have %d starships of type %s. Your reward is %d credits." % (attackfac, attackfg, iscapitol, processSystem( path[-1]), quantity, formatShip(attacktyp), creds)) writemissionname("Defend/Defend_%s_from_%s" % (defendfac, attackfac), path, isFixerString(addstr)) writemissionvars({'MISSION_TYPE': mistype})
def generateCleansweepMission(path,numplanets,enemy): fighterprob=vsrandom.random()*.75+.25; capshipprob=0.0 if (vsrandom.random()<.2): capshipprob=vsrandom.random()*.25; forceattack=vsrandom.randrange(0,2) cleansweep=vsrandom.randrange(0,2) minships=maxships=vsrandom.randrange(1,4) creds = numplanets*(cleansweep*4+1+capshipprob*4+.25*forceattack)*500*minships*fighterprob creds*=getPriceModifier(False) addstr="" isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/confed.spr#Unterhalte Dich mit dem konfoederiertem Offizier#Danke. Deine Hilfe macht den Weltraum zu einem weniger gefaehrlichem Platz.#\n" elif isFixer<guildpct: creds*=1.5 if (cleansweep): addstr+="#G#Bounty#\n" else: addstr+="#G#Patrol#\n" missiontype="patrol_enemies" additional="" additionalinstructions="" patrolorclean="Patrouille" dist=1500 if (cleansweep): dist=1500 additional=",1" patrolorclean="Saeuberungsaktion" missiontype="cleansweep" additionalinstructions+="Vernichte alle Streitkraefte, die du aufgespuert hast, um die Bezahlung zu erhalten." if (capshipprob): additionalinstructions+="Feindliche Kriegsschiffe koennen in der Gegend sein." writemissionsavegame (addstr+"import %s\ntemp=%s.%s(0, %d, %d, %d, %s,'',%d,%d,%f,%f,'%s',%d%s)\ntemp=0\n"%(missiontype,missiontype,missiontype,numplanets, dist, creds, str(path),minships,maxships,fighterprob,capshipprob,enemy,forceattack,additional)) writedescription("Die Obrigkeit haette gerne einen detaillierten Scan des %s System. Wir verlangen, dass %d Navigationspunkte in dem zu scannenden Gebiet kontrolliert werden. Die Bezahlung fuer diese Mission betraegt %d Kredite. Begegnungen_mit_%s Streitkraeften sind moeglich. %s"%(processSystem(path[-1]),numplanets,creds,enemy,additionalinstructions)) ispoint="e" if numplanets==1: ispoint="" writemissionname("%s/Kontrolliere %d Punkt%s im %s System"%(patrolorclean,numplanets,ispoint, processSystem(path[-1])),path,isFixerString(addstr))
def appendName(faction): from difficulty import usingDifficulty use_diff = usingDifficulty() use_blank = useBlank[faction] _random = vsrandom.random() #debug.debug("faction %s: (use_blank=%d >= _random=%.3f) ?" % (intToFaction(faction), use_blank, _random)) if use_diff and use_blank >= _random: #debug.debug("'-> using .blank") return ".blank" else: #debug.debug("'-> NOT using .blank") return ""
def CreateRandomMission(whichnum): """ This function gets a random mission and saves the information in an array as the which element. Returns the sprite file and text.""" which = str(whichnum) missiontype = vsrandom.random() fac = VS.GetGalaxyFaction(VS.getSystemFile()) if fac == "pirates": if (missiontype > .5): return None missiontype *= .2 elif (VS.GetRelation(fac, "pirates") < -.8 and missiontype < .1): missiontype = 0.1 + 0.9 * missiontype plr = getMissionPlayer() if (missiontype < .05): return MakePlunder(which) elif (missiontype < .1): return MakeContraband(which) else: goodlist = [] for indx in range(Director.getSaveStringLength(plr, "mission_scripts")): script = Director.getSaveString(plr, "mission_scripts", indx) if script.find("#F#") != -1: goodlist.append(indx) goodlist.sort() goodlist.reverse() if len(goodlist): i = goodlist[vsrandom.randrange(len(goodlist))] script = Director.getSaveString(plr, "mission_scripts", i) desc = Director.getSaveString(plr, "mission_descriptions", i) vars = PickleTools.decodeMap( Director.getSaveString(plr, "mission_vars", i)) vars.setdefault('MISSION_SHORTDESC', Director.getSaveString(plr, "mission_names", i)) Director.eraseSaveString(plr, "misson_scripts", i) Director.eraseSaveString(plr, "misson_descriptions", i) Director.eraseSaveString(plr, "misson_names", i) Director.eraseSaveString(plr, "misson_vars", i) mylist = script.split( "#" ) ###Skip the first two because first is always '' and second is always 'F' try: vars['MISSION_ID'] = vars['MISSION_ID'] except: vars['MISSION_ID'] = which description = vars['MISSION_SHORTDESC'].split("/")[1] vars['MISSION_NAME'] = description AddNewMission(description, script, None, desc, mylist[4], vars, vars) return (mylist[2], mylist[3], which, description) else: # It should only get here if no fixer missions were found return None # Fixer code will generate a NoFixer hopefully.
def GenerateFgShips(shipinfg, factionnr, friendly): lst = [] capship = () fac = faction_ships.intToFaction(factionnr) fpr = XProductionRate(fac, faction_ships.fighterProductionRate) cpr = XProductionRate(fac, faction_ships.capitalProductionRate) if cpr > 0 and (friendly == 2 or (friendly == 1 and vsrandom.random() < cpr // fpr)): capship = ((faction_ships.getRandomCapitolInt(factionnr), 1), ) debug.debug("Generating capital " + str(capship)) return ( (faction_ships.getRandomFighterInt(factionnr), shipinfg), ) + capship
def launch_near(self, un): if (VS.GetGameTime() < 10): debug.debug("launch_near called too soon!") return cursys = VS.getSystemFile() #numsigs=universe.GetNumSignificantsForSystem(cursys) for factionnum in range(faction_ships.getMaxFactions() - 1): faction = faction_ships.intToFaction(factionnum) fglist = fg_util.FGsInSystem(faction, cursys) if not len(fglist): debug.debug('no flight group for faction: ' + faction + ' in system ' + cursys + '.') continue num = len(fglist) debug.info( 'Probability numbers: %d %d' % (num, fg_util.MaxNumFlightgroupsInSystem(cursys))) #,numsigs avg = float(num) / float( fg_util.MaxNumFlightgroupsInSystem(cursys)) #/float(numsigs) fortress_level = 0 if cursys in faction_ships.fortress_systems: foretress_level = faction_ships.fortress_systems[cursys] avg *= (not ( VS.GetRelation(VS.GetGalaxyFaction(cursys), faction) < 0 and cursys in faction_ships.fortress_systems) ) * fortress_level + (1 - fortress_level) debug.debug('Chance for %s ship: %g' % (faction, avg)) rndnum = vsrandom.random() debug.debug('Random number: %g; will generate ship: %d' % (rndnum, rndnum < avg)) if rndnum < avg: #now we know that we will generate some ships! flightgroup = fglist[vsrandom.randrange(len(fglist))] typenumbers = fg_util.GetShipsInFG(flightgroup, faction) debug.debug('FG Name: "%s", ShipTypes: %s' % (flightgroup, str(typenumbers))) launch_recycle.launch_types_around( flightgroup, faction, typenumbers, 'default', self.generation_distance * vsrandom.random() * 0.9, un, self.generation_distance * vsrandom.random() * 2, '')
def generateCargoMission (path, numcargos,category, fac): if (isNotWorthy(fac)): return launchcap=(vsrandom.random()>=.97) if (not launchcap) and not isHabitable(path[-1]): return diff=vsrandom.randrange(0,adjustQuantityDifficulty(6)) creds=250*numcargos+500*diff+syscreds*len(path)+5000*(category[:10]=="Contraband")+20000*(category[:9]=="starships") addstr="" creds*=getPriceModifier(False) isFixer=vsrandom.random() if isFixer<fixerpct: creds*=2 addstr+="#F#bases/fixers/merchant.spr#Unterhalte Dich mit dem Kaufmann#Danke. Ich vertraue dir, dass du die Fracht erfolgreich liefern wirst.#\n" elif isFixer<guildpct: creds*=1.5 addstr+="#G#Cargo#\n" writemissionsavegame (addstr+"import cargo_mission\ntemp=cargo_mission.cargo_mission('%s', 0, %d, %d, %g, %d, 0, '%s', %s, '')\ntemp=0\n"%(fac, numcargos, diff, creds, launchcap, category, str(path))) if (category==''): category='generic' randCompany = GetRandomCompanyName() if (randCompany==''): strStart = "Wir muessen " else: strStart = randCompany+" seeks delivery of " brief = GetRandomCargoBrief() if (brief<>''): composedBrief = brief.replace('$CL',randCompany) composedBrief = composedBrief.replace('$CG',formatCargoCategory(category)) composedBrief = composedBrief.replace(' $DB','') composedBrief = composedBrief.replace('$DS',processSystem(path[-1])) composedBrief = composedBrief.replace('$PY',str(int(creds))) writedescription(composedBrief) else: writedescription(strStart+"Fracht (%s) in das %s System liefern. Die Mission ist uns %d Kredite wert. Du wirst die Fracht zu einer Basis liefern, die bewohnt wird von den %s.%s"%(formatCargoCategory(category), processSystem(path[-1]),creds,fac,pathWarning(path,isFixer<guildpct))) # avoid supplies supplies if "upplies" == category[-7:]: category = category[:-9] writemissionname("Fracht/Liefere_%s in das_%s_System"%(changecat(category),processSystem(path[-1])),path,isFixerString(addstr))
def GetRandomWeapon(diff): """Get a random beam or mounted gun from master part list""" rndnum = vsrandom.random() cat = "upgrades" if (rndnum < 0.5): cat = GetDiffCargo(diff, "upgrades/Weapons/Beam_Arrays_", "upgrades/Weapons", 1) else: cat = GetDiffCargo(diff, "upgrades/Weapons/Mounted_Guns_", "upgrades/Weapons", 1) debug.debug("Getting item: %s" % (str(cat))) item = getItem(cat, "upgrades/Weapons") return item
def AddBasesToSystem(faction, sys): if (sys in doNotAddBasesTo): return slash = sys.find("/") if (slash != -1): if (sys[0:slash] in doNotAddBasesTo): return if faction in faction_ships.factions: fsfac = list(faction_ships.factions).index(faction) numbases = 0 # numplanets=VS.GetGalaxyProperty(sys,"num_planets"); numjumppoints = VS.GetNumAdjacentSystems(sys) if (numjumppoints < 4): if (vsrandom.random() >= .25): numbases = 1 elif (vsrandom.random() >= .005): if (numjumppoints < 7): numbases = vsrandom.randrange(1, int(numjumppoints // 2) + 1) elif numjumppoints == 7: numbases = vsrandom.randrange(1, 6) else: numbases = vsrandom.randrange(1, numjumppoints + 1) if numbases == 0: return shiplist = [] nums = [] for i in range(numbases): whichbase = faction_ships.bases[fsfac][vsrandom.randrange( 0, len(faction_ships.bases[fsfac]))] if whichbase in shiplist: nums[shiplist.index(whichbase)] += 1 else: shiplist += [whichbase] nums.append(1) tn = [] for i in range(len(shiplist)): tn += [(shiplist[i], nums[i])] fg_util.AddShipsToFG(fg_util.BaseFGInSystemName(sys), faction, tn, sys)