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 GenerateAllShips(): global fgnames, origfgnames, fgoffset for fnr in range(faction_ships.getMaxFactions()): fgnames.append( fg_util.GetRandomFGNames(-1, faction_ships.factions[fnr])) fgoffset.append(0) origfgnames.append(list(fgnames[-1]))
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 launchUnits(sys): print "Launching units for "+sys import faction_ships import launch_recycle import universe sig_units=universe.significantUnits() ownerfac= VS.GetGalaxyFaction(sys) jumpcount=0 planetcount=0 # asteroidcount=0 basecount=0 farlen=0 for sig in sig_units: if sig.isJumppoint(): jumpcount+=1 elif sig.isPlanet(): planetcount+=1 # elif sig.isAsteroid(): # asteroidcount+=1 else: basecount+=1 tmplen=Vector.Mag(sig.Position()) if tmplen>farlen: farlen=tmplen for factionnum in range(0,faction_ships.getMaxFactions()-1): faction=faction_ships.intToFaction(factionnum) fglist=filterLaunchedFGs(FGsInSystem(faction,sys)) isHostile=VS.GetRelation(ownerfac,faction)<0 isForeign=faction.find(ownerfac)==-1 if isForeign: if basecount+jumpcount: frac=len(fglist)/float(basecount+jumpcount) else: frac=0.0 else: if basecount+planetcount+jumpcount: frac=len(fglist)/float(planetcount+basecount+jumpcount) else: frac=0.0 if isHostile: for flightgroup in fglist: X=incr_by_abs(vsrandom.uniform(-1.0,1.0),1)*farlen Y=incr_by_abs(vsrandom.uniform(-1.0,1.0),1)*farlen Z=incr_by_abs(vsrandom.uniform(-1.0,1.0),1)*farlen typenumbers=ShipsInFG(flightgroup,faction) #print "Really Far Apart around "+" "+str(X)+" "+str(Y)+" "+str(Z)+" and 10000" debug.debug(" launching "+str(typenumbers) +" for "+faction+" at "+str((X,Y,Z))) launch_recycle.launch_types_around(flightgroup,faction,typenumbers,'default',1,(X,Y,Z),0,'','',1,10000) else: for flightgroup in fglist: #jp = sig.isJumppoint() #if sig.isPlanet() or not isForeign: sig = sig_units[vsrandom.randrange(0,len(sig_units))] typenumbers=ShipsInFG(flightgroup,faction) debug.debug(" XXlaunching "+str(typenumbers) +" for "+faction) print "LALALAUNCHING "+str(typenumbers)+" t "+sig.getName()+":"+sig.getFullname() launch_recycle.launch_types_around(flightgroup,faction,typenumbers,'default',sig.rSize()*vsrandom.randrange(10,100),sig,0,'','',1,10000)
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 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 GenerateAllShips (): global fgnames,origfgnames,fgoffset for fnr in xrange(faction_ships.getMaxFactions()): fgnames.append(fg_util.GetRandomFGNames(-1,faction_ships.factions[fnr])) fgoffset.append(0) origfgnames.append(list(fgnames[-1]))
def launchUnits(sys): debug.info("Launching units for %s", sys) import faction_ships import launch_recycle import universe sig_units=universe.significantUnits() ownerfac= VS.GetGalaxyFaction(sys) jumpcount=0 planetcount=0 # asteroidcount=0 basecount=0 farlen=0 for sig in sig_units: if sig.isJumppoint(): jumpcount+=1 elif sig.isPlanet(): planetcount+=1 # elif sig.isAsteroid(): # asteroidcount+=1 else: basecount+=1 tmplen=Vector.Mag(sig.Position()) if tmplen>farlen: farlen=tmplen for factionnum in xrange(0,faction_ships.getMaxFactions()-1): faction=faction_ships.intToFaction(factionnum) fglist=filterLaunchedFGs(FGsInSystem(faction,sys)) isHostile=VS.GetRelation(ownerfac,faction)<0 isForeign=faction.find(ownerfac)==-1 if isForeign: if basecount+jumpcount: frac=len(fglist)/float(basecount+jumpcount) else: frac=0.0 else: if basecount+planetcount+jumpcount: frac=len(fglist)/float(planetcount+basecount+jumpcount) else: frac=0.0 if isHostile: for flightgroup in fglist: X=incr_by_abs(vsrandom.uniform(-1.0,1.0),1)*farlen Y=incr_by_abs(vsrandom.uniform(-1.0,1.0),1)*farlen Z=incr_by_abs(vsrandom.uniform(-1.0,1.0),1)*farlen XYZ = (X,Y,Z) typenumbers=ShipsInFG(flightgroup,faction) debug.debug("Really Far Apart around %s and 10000",XYZ) debug.debug(" launching %s for %s at %s", typenumbers, faction, XYZ) launch_recycle.launch_types_around(flightgroup,faction,typenumbers,'default',1,XYZ,0,'','',1,10000) else: for flightgroup in fglist: #jp = sig.isJumppoint() #if sig.isPlanet() or not isForeign: sig = sig_units[vsrandom.randrange(0,len(sig_units))] typenumbers=ShipsInFG(flightgroup,faction) debug.debug(" launching %s for %s", typenumbers, faction) launch_recycle.launch_types_around(flightgroup,faction,typenumbers,'default',sig.rSize()*vsrandom.randrange(10,100),sig,0,'','',1,10000)
def launch_near(self,un, forceLaunch=False): if (VS.GetGameTime()<10 and not forceLaunch): debug.debug("hola!") return cursys=VS.getSystemFile() cursysfaction=VS.GetGalaxyFaction(cursys) # Computing probability numbers is relatively expensive, # accessing multiple times FG/Galaxy/Universe API. # Although with some optimization it becomes acceptable on # a director loop, this is still much better: we compute # probabilities roughly once per system entry, and then just # launch a single flightgroup per director execution (to spread # launch load in time and make it less intrusive on gameplay - # ie, stutter less noticeably). Outside code will take care # of ceasing to call this function when no more flightgroups # are needed. # Validate probability cache if (cursysfaction != self.probability_cache[0]) \ or (cursys != self.probability_cache[1]) \ or (faction_ships.getMaxFactions() != len(self.probability_cache[2])): debug.debug('Probability numbers:') psum = 0 probs = [] for factionnum in range(faction_ships.getMaxFactions()): faction=faction_ships.intToFaction(factionnum) num=fg_util.NumFactionFGsInSystem(faction,cursys) # will count bases... but... much quicker. if num==1: #cannot accept counting bases in this case... num=len(fg_util.FGsInSystem(faction,cursys)) 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(cursysfaction,faction)<0 and cursys in faction_ships.fortress_systems))*fortress_level+(1-fortress_level) debug.debug('Chance for %s ship: %g'%(faction, avg)) probs.append(avg) psum += avg self.probability_cache = (cursysfaction,cursys,probs,psum) else: debug.debug('Probability numbers cached.') # Launch a single random flightgroup in the bunch rnd = vsrandom.random() * self.probability_cache[3] p = 0 for factionnum in range(len(self.probability_cache[2])): p += self.probability_cache[2][factionnum] if (p>=rnd): #now we know that we will generate some ships! faction=faction_ships.intToFaction(factionnum) fglist=fg_util.FGsInSystem(faction,cursys) for k in range(10): #try 10 times flightgroup=fglist[vsrandom.randrange(len(fglist))] typenumbers=fg_util.GetShipsInFG(flightgroup,faction) if not len(typenumbers): continue 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,'','',100) break # Update DJ dj_lib.PlayMusik(0,dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)
def launch_near(self, un, forceLaunch=False): if (VS.GetGameTime() < 10 and not forceLaunch): debug.debug("hola!") return cursys = VS.getSystemFile() cursysfaction = VS.GetGalaxyFaction(cursys) # Computing probability numbers is relatively expensive, # accessing multiple times FG/Galaxy/Universe API. # Although with some optimization it becomes acceptable on # a director loop, this is still much better: we compute # probabilities roughly once per system entry, and then just # launch a single flightgroup per director execution (to spread # launch load in time and make it less intrusive on gameplay - # ie, stutter less noticeably). Outside code will take care # of ceasing to call this function when no more flightgroups # are needed. # Validate probability cache if (cursysfaction != self.probability_cache[0]) \ or (cursys != self.probability_cache[1]) \ or (faction_ships.getMaxFactions() != len(self.probability_cache[2])): debug.debug('Probability numbers:') psum = 0 probs = [] for factionnum in range(faction_ships.getMaxFactions()): faction = faction_ships.intToFaction(factionnum) num = fg_util.NumFactionFGsInSystem( faction, cursys) # will count bases... but... much quicker. if num == 1: #cannot accept counting bases in this case... num = len(fg_util.FGsInSystem(faction, cursys)) 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(cursysfaction, faction) < 0 and cursys in faction_ships.fortress_systems) ) * fortress_level + (1 - fortress_level) debug.debug('Chance for %s ship: %g' % (faction, avg)) probs.append(avg) psum += avg self.probability_cache = (cursysfaction, cursys, probs, psum) else: debug.debug('Probability numbers cached.') # Launch a single random flightgroup in the bunch rnd = vsrandom.random() * self.probability_cache[3] p = 0 for factionnum in range(len(self.probability_cache[2])): p += self.probability_cache[2][factionnum] if (p >= rnd): #now we know that we will generate some ships! faction = faction_ships.intToFaction(factionnum) fglist = fg_util.FGsInSystem(faction, cursys) for k in range(10): #try 10 times flightgroup = fglist[vsrandom.randrange(len(fglist))] typenumbers = fg_util.GetShipsInFG(flightgroup, faction) if not len(typenumbers): continue 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, '', '', 100) break # assume after 10 tries we launched a flightgroup, we're done here break # Update DJ dj_lib.PlayMusik(0, dj_lib.HOSTILE_NEWLAUNCH_DISTANCE)