def launch_waves_around_area(fgname, faction, type, ai, nr_ships, nr_waves, r1, r2, pos, logo="", useani=1, skipdj=0): pos = ( (pos[0] + vsrandom.uniform(r1, r2) * vsrandom.randrange(-1, 2, 2)), (pos[1] + vsrandom.uniform(r1, r2) * vsrandom.randrange(-1, 2, 2)), (pos[2] + vsrandom.uniform(r1, r2) * vsrandom.randrange(-1, 2, 2)), ) return launch(fgname, faction, type, ai, nr_ships, nr_waves, pos, logo, useani, skipdj)
def teleportNPC (self,un): pos=un.Position() rsiz = un.rSize() size=4*rsiz sig = unit.getSignificant (vsrandom.randrange(0,50),0,0) if (not sig): return nam = sig.getName() if (nam.find ("lackhole")!=-1): return targetpos = sig.Position() arad = sig.rSize()*2+size targetpos = Vector.Add(targetpos,(vsrandom.uniform(arad,arad*1.5), vsrandom.uniform(arad,arad*1.5), vsrandom.uniform(arad,arad*1.5))) targetpos = VS.SafeEntrancePoint (targetpos,rsiz) if (size<1000): size=1000 print "kill" print un.getName() un.SetCurPosition(targetpos) VS.playAnimation("warp.ani",pos,size) VS.playSound("cloak.wav",pos,(1,0,0)) VS.playAnimation("warp.ani",targetpos,size) VS.playSound("cloak.wav",targetpos,(1,0,0))
def launch_waves_in_area(fgname, faction, type, ai, nr_ships, nr_waves, radius, pos, logo="", useani=1, skipdj=0): pos = ( pos[0] + vsrandom.uniform((-radius) // 2, radius / 2.0), pos[1] + vsrandom.uniform((-radius) // 2, radius / 2.0), pos[2] + vsrandom.uniform((-radius) // 2, radius / 2.0), ) un = launch(fgname, faction, type, ai, nr_ships, nr_waves, pos, logo, useani, skipdj)
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 reposition(un,playa,min_distance,vel): ex=(vsrandom.uniform(-1,1),vsrandom.uniform(-1,1),vsrandom.uniform(-1,1)) if vel[0]==0 and vel[1]==0 and vel[2]==0: vel=(1,0,0) dir=Vector.Scale(Vector.ScaledCross(ex,vel),min_distance) debug.debug("offsetting you a few meters to the %s" % (str(dir))) un.SetPosition(Vector.Add(playa.Position(),dir))
def randomFlagLocation(self): if (len(self.flags)): i = vsrandom.randrange(0, len(self.flags)) return Vector.Add( (vsrandom.uniform(-20, 20), vsrandom.uniform(-20, 20), vsrandom.uniform(-20, 20)), self.flags[i].Position()) return (0, 0, 0)
def teleportNPC(self, un): pos = un.Position() rsiz = un.rSize() size = 4 * rsiz sig = unit.getSignificant(vsrandom.randrange(0, 50), 0, 0) if (not sig): return nam = sig.getName() if (nam.find("lackhole") != -1): return targetpos = sig.Position() arad = sig.rSize() * 2 + size targetpos = Vector.Add(targetpos, (vsrandom.uniform( arad, arad * 1.5), vsrandom.uniform( arad, arad * 1.5), vsrandom.uniform(arad, arad * 1.5))) targetpos = VS.SafeEntrancePoint(targetpos, rsiz) if (size < 1000): size = 1000 print("kill") print(un.getName()) un.SetCurPosition(targetpos) VS.playAnimation("warp.ani", pos, size) VS.playSound("cloak.wav", pos, (1, 0, 0)) VS.playAnimation("warp.ani", targetpos, size) VS.playSound("cloak.wav", targetpos, (1, 0, 0))
def AddFighterTo(fgname,fac,isNew=False): sys = VS.getSystemFile() #print 'add fighter' import generate_dyn_universe numsystems = generate_dyn_universe.systemcount[fac] if (VS.GetGalaxyFaction(sys)!=fac): try: homeworlds=faction_ships.production_centers except: homeworlds=faction_ships.homeworlds if fac in homeworlds: if type(homeworlds[fac])==type(""): sys=homeworlds[fac] else: sys=homeworlds[fac][vsrandom.randrange(0,len(homeworlds[fac]))] numfighters = int(generate_dyn_universe.XProductionRate(fac,faction_ships.fighterProductionRate)*numsystems) try: if fac in faction_ships.staticFighterProduction: numfighters+=faction_ships.staticFighterProduction[fac] except: pass if (numfighters<1): if (vsrandom.uniform(0,1)<numfighters): numfighters=1 #print "Generating "+str(numfighters)+ " fighters for "+fac+" at "+sys if isNew: fgk=fg_util.AllFGsInSystem(fac,sys) if len(fgk): fgname=fgk[vsrandom.randrange(0,len(fgk))] stat=6 if fac in faction_ships.fightersPerFG: stat=faction_ships.fightersPerFG[fac] elif "default" in faction_ships.fightersPerFG: stat=faction_ships.fightersPerFG["default"] if fg_util.NumShipsInFG(fgname,fac)+numfighters<=numfighters+stat: isNew=False if isNew: fgname=generate_dyn_universe.GetNewFGName(fac) if numfighters>=1: fg_util.AddShipsToFG (fgname,fac,((faction_ships.getRandomFighter(fac),int(numfighters)),),sys) numcapships = generate_dyn_universe.XProductionRate(fac,faction_ships.capitalProductionRate)*numsystems if (numcapships<1): if (vsrandom.uniform(0,1)>numcapships): return numcapships=1 sys = fg_util.FGSystem(fgname,fac) if (1 or VS.GetGalaxyFaction(sys)!=fac): try: homeworlds=faction_ships.production_centers except: homeworlds=faction_ships.homeworlds if fac in homeworlds: if type(homeworlds[fac])==type(""): sys=homeworlds[fac] else: sys=homeworlds[fac][vsrandom.randrange(0,len(homeworlds[fac]))] cap =faction_ships.getRandomCapitol(fac) #print "Generating "+str(numcapships)+ " capship "+cap+" for "+fac+" at "+sys fg_util.AddShipsToFG(fgname,fac,((cap,int(numcapships)),),sys)
def reposition(un, playa, min_distance, vel): ex = (vsrandom.uniform(-1, 1), vsrandom.uniform(-1, 1), vsrandom.uniform(-1, 1)) if vel[0] == 0 and vel[1] == 0 and vel[2] == 0: vel = (1, 0, 0) dir = Vector.Scale(Vector.ScaledCross(ex, vel), min_distance) debug.debug("offsetting you a few meters to the %s" % (str(dir))) un.SetPosition(Vector.Add(playa.Position(), dir))
def setDroneNear(self, playa): global drone vec = playa.Position() vec = Vector.Add( vec, (vsrandom.uniform(-1000, 1000), vsrandom.uniform( -1000, 1000), vsrandom.uniform(-1000, 1000))) drone.SetCurPosition(vec) drone.SetTarget(playa)
def setDroneNear (self,playa): vec = playa.Position() vec = Vector.Add (vec,(vsrandom.uniform(-1000,1000), vsrandom.uniform(-1000,1000), vsrandom.uniform(-1000,1000))) if (not self.drone.isNull()): self.drone.SetCurPosition(vec) self.drone.SetTarget(playa)
def setDroneNear (self,playa): global drone vec = playa.Position() vec = Vector.Add (vec,(vsrandom.uniform(-1000,1000), vsrandom.uniform(-1000,1000), vsrandom.uniform(-1000,1000))) drone.SetCurPosition(vec) drone.SetTarget(playa)
def AddFighterTo(fgname,fac,isNew=False): sys = VS.getSystemFile() #debug.debug('add fighter') numsystems = generate_dyn_universe.systemcount[fac] if (VS.GetGalaxyFaction(sys)!=fac): try: homeworlds=faction_ships.production_centers except: homeworlds=faction_ships.homeworlds if fac in homeworlds: if type(homeworlds[fac])==type(""): sys=homeworlds[fac] else: sys=homeworlds[fac][vsrandom.randrange(0,len(homeworlds[fac]))] numfighters = int(generate_dyn_universe.XProductionRate(fac,faction_ships.fighterProductionRate)*numsystems) try: if fac in faction_ships.staticFighterProduction: numfighters+=faction_ships.staticFighterProduction[fac] except: pass if (numfighters<1): if (vsrandom.uniform(0,1)<numfighters): numfighters=1 #debug.debug("Generating "+str(numfighters)+ " fighters for "+fac+" at "+sys) if isNew: fgk=fg_util.FGsInSystem(fac,sys) if len(fgk): fgname=fgk[vsrandom.randrange(0,len(fgk))] stat=6 if fac in faction_ships.fightersPerFG: stat=faction_ships.fightersPerFG[fac] elif "default" in faction_ships.fightersPerFG: stat=faction_ships.fightersPerFG["default"] if fg_util.NumShipsInFG(fgname,fac)+numfighters<=numfighters+stat: isNew=False if isNew: fgname=generate_dyn_universe.GetNewFGName(fac) if numfighters>=1: fg_util.AddShipsToFG (fgname,fac,((faction_ships.getRandomFighter(fac),int(numfighters)),),sys) numcapships = generate_dyn_universe.XProductionRate(fac,faction_ships.capitalProductionRate)*numsystems if (numcapships<1): if (vsrandom.uniform(0,1)>numcapships): return numcapships=1 sys = fg_util.FGSystem(fgname,fac) if (1 or VS.GetGalaxyFaction(sys)!=fac): try: homeworlds=faction_ships.production_centers except: homeworlds=faction_ships.homeworlds if fac in homeworlds: if type(homeworlds[fac])==type(""): sys=homeworlds[fac] else: sys=homeworlds[fac][vsrandom.randrange(0,len(homeworlds[fac]))] cap =faction_ships.getRandomCapitol(fac) #debug.debug("Generating "+str(numcapships)+ " capship "+cap+" for "+fac+" at "+sys) fg_util.AddShipsToFG(fgname,fac,((cap,int(numcapships)),),sys)
def reposition(un,playa,min_distance,vel): import Vector import vsrandom ex=(vsrandom.uniform(-1,1),vsrandom.uniform(-1,1),vsrandom.uniform(-1,1)) if vel[0]==0 and vel[1]==0 and vel[2]==0: vel=(1,0,0) dir=Vector.Scale(Vector.ScaledCross(ex,vel),min_distance) print "offsetting you a few meters to the "+str(dir) un.SetPosition(Vector.Add(playa.Position(),dir))
def reposition(un, playa, min_distance, vel): import Vector import vsrandom ex = (vsrandom.uniform(-1, 1), vsrandom.uniform(-1, 1), vsrandom.uniform(-1, 1)) if vel[0] == 0 and vel[1] == 0 and vel[2] == 0: vel = (1, 0, 0) dir = Vector.Scale(Vector.ScaledCross(ex, vel), min_distance) print "offsetting you a few meters to the " + str(dir) un.SetPosition(Vector.Add(playa.Position(), dir))
def randDirection(): leng=2 while leng>1 or leng<.00001: X = vsrandom.uniform(-1,1); Y = vsrandom.uniform(-1,1); Z = vsrandom.uniform(-1,1); leng=X*X+Y*Y+Z*Z import VS leng=VS.sqrt(leng) return (X/leng,Y/leng,Z/leng)
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 HowMuchDamage (shiptypes,defenseroll): dam=0 for i in shiptypes: stats=faction_ships.GetStats(i[0]) #debug.debug(str(stats[0])+ ' needs above '+str(defenseroll)) if (vsrandom.uniform(0,stats[0])>defenseroll): dam+=stats[2]*i[1] #guns if (len(stats)>3): if (vsrandom.uniform(0,.05)>defenseroll): dam+=stats[3]*i[1] #missiles return dam
def _prob_round(curnum): import vsrandom ret = int(curnum) diff = curnum-int(curnum) if (diff>0): if (vsrandom.uniform (0,1)<diff): ret+=1 else: if (vsrandom.uniform (0,1)<-diff): ret-=1 return ret
def randomLocation(self): for i in range(50): vec = (vsrandom.uniform(-self.arenasize, self.arenasize), 0, vsrandom.uniform(-self.arenasize, self.arenasize)) for i in self.flags: if (self.toonear(vec, i)): continue for i in self.obstacles: if (self.toonear(vec, i)): continue return vec return vec
def randomLocation(self): for i in range (50): vec=(vsrandom.uniform(-self.arenasize,self.arenasize), 0, vsrandom.uniform(-self.arenasize,self.arenasize)) for i in self.flags: if (self.toonear (vec,i)): continue for i in self.obstacles: if (self.toonear (vec,i)): continue return vec return vec
def SimulatedDukeItOut (fgname,faction,enfgname,enfaction): ally=fg_util.LandedShipsInFG(fgname,faction) enemy=fg_util.LandedShipsInFG(enfgname,enfaction) if (len(enemy) and len(ally)): allyvictim = vsrandom.randrange(0,len(ally)) allystats = faction_ships.GetStats(ally[allyvictim][0]) envictim = vsrandom.randrange(0,len(enemy)) enstats = faction_ships.GetStats(enemy[envictim][0]) endam = HowMuchDamage(enemy,vsrandom.uniform(0,allystats[1])) if (enfgname==fgname and enfaction==faction): debug.error("FAULT FAULT FAULT") ApplyDamage(enfgname,enfaction,enemy,envictim,enstats,HowMuchDamage(ally,vsrandom.uniform(0,enstats[1])),fgname,faction) ApplyDamage(fgname,faction,ally,allyvictim,allystats,endam,enfgname,enfaction)
def launch_waves_in_area(fgname, faction, type, ai, nr_ships, nr_waves, radius, pos, logo='', useani=1): pos = (pos[0] + vsrandom.uniform( (-radius) / 2, radius / 2.0), pos[1] + vsrandom.uniform( (-radius) / 2, radius / 2.0), pos[2] + vsrandom.uniform( (-radius) / 2, radius / 2.0)) un = launch(fgname, faction, type, ai, nr_ships, nr_waves, pos, logo, useani)
def floatToRand(maximum): if maximum == 0: return 0 tmp = vsrandom.randrange(0, int(maximum) + 1) if (vsrandom.uniform(0, 1) < maximum - int(maximum)): return tmp + 1 return tmp
def launch_waves_around_area(fgname, faction, type, ai, nr_ships, nr_waves, r1, r2, pos, logo='', useani=1): pos = ((pos[0] + vsrandom.uniform(r1, r2) * vsrandom.randrange(-1, 2, 2)), (pos[1] + vsrandom.uniform(r1, r2) * vsrandom.randrange(-1, 2, 2)), (pos[2] + vsrandom.uniform(r1, r2) * vsrandom.randrange(-1, 2, 2))) return launch(fgname, faction, type, ai, nr_ships, nr_waves, pos, logo, useani)
def floatToRand(maximum): if maximum==0: return 0 tmp=vsrandom.randrange(0,int(maximum)+1) if (vsrandom.uniform(0,1)<maximum-int(maximum)): return tmp+1 return tmp
def init(self, un): self.shipiter = 0 self.speed = vsrandom.uniform(maxspeed / 3, maxspeed) print("self.speed") print(self.speed) self.stopping = 0 self.begin = 1 self.restoreCruisingSpeed(self.speed)
def init(self, un): self.shipiter = 0 self.speed = vsrandom.uniform(maxspeed / 3, maxspeed) print 'self.speed' print self.speed self.stopping = 0 self.begin = 1 self.restoreCruisingSpeed(self.speed)
def init(self,un): self.shipiter=0; self.speed = vsrandom.uniform (maxspeed/3,maxspeed); print 'self.speed' print self.speed self.stopping=0 self.begin=1 self.restoreCruisingSpeed(self.speed)
def launchBaseOrbit(type,faction,loc,orbitradius,orbitspeed,unit): #orbitradius*=2 import Vector import dynamic_universe R = Vector.Vector(vsrandom.uniform(1.25*orbitradius,orbitradius), vsrandom.uniform(1.25*orbitradius,orbitradius), vsrandom.uniform(1.25*orbitradius,orbitradius)) RMag = Vector.Mag(R) T = Vector.Vector(vsrandom.uniform(.5*orbitradius,orbitradius), vsrandom.uniform(.75*orbitradius,.85*orbitradius), vsrandom.uniform(.5*orbitradius,orbitradius)) S = Vector.Cross (T,R) S = Vector.Scale(S, vsrandom.uniform (1.5*orbitradius,orbitradius) /Vector.Mag(S)) SMag = Vector.Mag(S) bas=VS.launch("Base",type,faction,"unit","default",1,1,Vector.Add(loc,R),'') nam=GetRandomBaseName (1,faction); R = Vector.Scale (R,(RMag+2.0*bas.rSize())/RMag) S = Vector.Scale (S,(SMag+2.0*bas.rSize())/SMag) bas.orbit (unit,orbitspeed,R,S,(0.0,0.0,0.0)) #bas.SetPosition(Vector.Add(loc,R)) dynamic_universe.TrackLaunchedShip (BaseFGInSystemName(VS.getSystemFile()), faction, type, bas)
def launchSingleBase (type,faction,sig): radpct = VS.getPlanetRadiusPercent() sigrsize=sig.rSize() radpct = sigrsize*(1+radpct) if radpct<200000000.+sigrsize: radpct=200000000.+sigrsize speed = vsrandom.uniform (0,50) debug.debug('Lauching %s base %s by sig %s (%s)', faction, type, sig.getName(), sig.getFullname()) launchBaseOrbit (type,faction,sig.Position(),radpct,speed,sig)
def makeSurplusShortage(): (sys,mylist)=universe.getAdjacentSystems(VS.getSystemFile(),vsrandom.randrange(1,3)) adj=vsrandom.uniform (-.5,.5) myquest=0 cats = tuple(set([VS.getRandCargo(1,"").GetCategory(), VS.getRandCargo(1,"").GetCategory()])) news="" if (adj<0): news = "SURPLUS IN %s: There are reports of surpluses of %s items in the %s system. Wise Privateers have been purchasing the surpluses in hopes of future gains elsewhere." % (sys," and ".join(cats),sys) else: news = "DEMAND FOR %s in %s: Citizens in the %s system have been frusterated by the expensive prices and low quantities of %s goods. Privateers are currently banding together to try to bring supply to meet the demand. But while prices are still high, some big traders could certainly capitalize on this shortage." % (" AND ".join(cats),sys,sys," and ".join(cats)) return (sys,quest_surplus_factory(cats,1+adj,1-adj,1,1),news)
def Execute(self): import unit import Vector import vsrandom VS.PythonAI.Execute(self) distance = abs(self.GetParent().getDistance(self.target)) # evade the target and almost parallel flyby if (distance <= 2000 and VS.GetGameTime() > self.timer): angle = unit.facingAngleToUnit(self.GetParent(), self.target) velocity = unit.getSignedVelocity(self.GetParent()) if (angle < 0.30): angular = 0.80 - angle change = (vsrandom.uniform(-angular, angular), vsrandom.uniform(angular, angular), vsrandom.uniform(-angular, angular)) self.GetParent().SetAngularVelocity(change) if (velocity < 100): self.GetParent().LongitudinalThrust(100) self.timer = VS.GetGameTime() + 1 # patrol in random direction if (distance > 2000 and distance < 7000 and VS.GetGameTime() > self.timer): angular = vsrandom.uniform(0.01, 0.10) change = (vsrandom.uniform(-angular, angular), vsrandom.uniform(angular, angular), vsrandom.uniform(-angular, angular)) self.GetParent().SetAngularVelocity(change) velocity = unit.getSignedVelocity(self.GetParent()) if (velocity < 100): self.GetParent().LongitudinalThrust(200) self.timer = VS.GetGameTime() + 2 # return to target proximity if (distance >= 7000 and VS.GetGameTime() > self.timer): # calculates the angular velocity required to turn back on target vec = Vector.Sub(self.GetParent().Position(), self.target.Position()) change = Vector.Cross( Vector.SafeNorm(self.GetParent().GetOrientation()[2]), Vector.SafeNorm(vec)) self.GetParent().SetAngularVelocity(change) # calculate the required thrust depending on mass and # signed velocity magnitude as result of momentum velocity = unit.getSignedVelocity(self.GetParent()) if (velocity < 100): if (velocity < 0): # thrust more while not flying forward thrust = self.thrustfactor * max(abs(velocity), 300) else: thrust = self.thrustfactor * 300 self.GetParent().LongitudinalThrust(thrust) self.timer = VS.GetGameTime() + 1 return 1
def Execute(self): import unit import Vector import vsrandom VS.PythonAI.Execute(self); distance = abs(self.GetParent().getDistance(self.target)) # evade the target and almost parallel flyby if (distance<=2000 and VS.GetGameTime()>self.timer): angle = unit.facingAngleToUnit(self.GetParent(),self.target) velocity = unit.getSignedVelocity(self.GetParent()) if (angle<0.30): angular = 0.80-angle change = (vsrandom.uniform(-angular,angular), vsrandom.uniform(angular,angular), vsrandom.uniform(-angular,angular)) self.GetParent().SetAngularVelocity(change) if (velocity<100): self.GetParent().LongitudinalThrust(100) self.timer = VS.GetGameTime()+1 # patrol in random direction if (distance>2000 and distance<7000 and VS.GetGameTime()>self.timer): angular = vsrandom.uniform(0.01,0.10) change = (vsrandom.uniform(-angular,angular), vsrandom.uniform(angular,angular), vsrandom.uniform(-angular,angular)) self.GetParent().SetAngularVelocity(change) velocity = unit.getSignedVelocity(self.GetParent()) if (velocity<100): self.GetParent().LongitudinalThrust(200) self.timer = VS.GetGameTime()+2 # return to target proximity if (distance>=7000 and VS.GetGameTime()>self.timer): # calculates the angular velocity required to turn back on target vec = Vector.Sub(self.GetParent().Position(),self.target.Position()) change = Vector.Cross(Vector.SafeNorm(self.GetParent().GetOrientation()[2]),Vector.SafeNorm(vec)) self.GetParent().SetAngularVelocity(change) # calculate the required thrust depending on mass and # signed velocity magnitude as result of momentum velocity = unit.getSignedVelocity(self.GetParent()) if (velocity<100): if (velocity<0): # thrust more while not flying forward thrust = self.thrustfactor * max(abs(velocity),300) else: thrust = self.thrustfactor * 300 self.GetParent().LongitudinalThrust(thrust) self.timer = VS.GetGameTime()+1 return 1
def makeSurplusShortage(): (sys, mylist) = universe.getAdjacentSystems(VS.getSystemFile(), vsrandom.randrange(1, 3)) adj = vsrandom.uniform(-0.5, 0.5) myquest = 0 cats = (VS.getRandCargo(1, "").GetCategory(), VS.getRandCargo(1, "").GetCategory()) news = "" if (adj < 0): news = "SURPLUS IN %s: There are reports of surpluses of %s and %s items in the %s system. Wise Privateers have been purchasing the surpluses in hopes of future gains elsewhere." % ( sys, cats[0], cats[1], sys) else: news = "DEMAND FOR %s AND %s in %s: Citizens in the %s system have been frusterated by the expensive prices and low quantities of %s and %s goods. Privateers are currently banding together to try to bring supply to meet the demand. But while prices are still high, some big traders could certainly capitalize on this shortage." % ( cats[0], cats[1], sys, sys, cats[0], cats[1]) return (sys, quest_surplus_factory(cats, 1 + adj, 1 - adj, 1, 1), news)
def initrandom(factionname, numsysaway, minenquant, maxenquant, credperen, defendit, defend_base, p_faction='', jumps=(), var_to_set=''): enq = minenquant enq = vsrandom.uniform(minenquant, maxenquant) return defend(factionname, numsysaway, enq, 8000.0, 100000.0, enq * credperen, defendit, defend_base, p_faction, jumps, var_to_set)
import dynamic_mission import VS import vsrandom import industrial_lib sunny = vsrandom.uniform(0, 1) >= 0.99 time_of_day = "" plist = VS.musicAddList("new_detroit.m3u") VS.musicPlayList(plist) dynamic_mission.CreateMissions() industrial_lib.MakeIndustrial(sunny, time_of_day, False)
import dynamic_mission import VS import vsrandom import industrial_lib sunny=vsrandom.uniform(0,1)>.9 time_of_day='' plist=VS.musicAddList('AWACS.m3u') VS.musicPlayList(plist) dynamic_mission.CreateMissions() industrial_lib.MakeIndustrial(sunny,time_of_day,True)
def Execute (self): if (self.player): #print str(self.player.Position()) # launch the actors if (self.stage<=self.groups and VS.GetGameTime()>=self.timer): #print "group: " +str(self.stage) self.names = fg_util.GetRandomFGNames(self.groups,"confed") shiptype = faction_ships.getRandomCapitolInt(faction_ships.confed) #print "group/name: " + str(self.stage) + "/"+names[self.stage-1] # launch capital ships number = vsrandom.randrange(2,4) #print ">capital/type: " +str(number)+"/"+shiptype location = Vector.Add (self.object.Position(),(vsrandom.uniform(-10000,10000), vsrandom.uniform(-10000,10000), vsrandom.uniform(-10000,10000))) offset = (vsrandom.uniform(1000,2000),vsrandom.uniform(1000,2000),vsrandom.uniform(1000,2000)) for i in range(number): #self.capital += [launch.launch_wave_around_unit(names[self.stage-1],'confed',shiptype,'sitting_duck',1,5000,20000,self.object)] # launch(name,type,faction,unittype,ai,nr,nrwaves,pos,squadlogo) pos = Vector.Add (location,Vector.Scale(offset,i)) self.capital += [VS.launch(self.names[self.stage-1],shiptype,'confed','unit','sitting_duck',1,1,pos,'')] # launch fighters number = number*vsrandom.randrange(3,6) # test: Lancelot, Schroedinger, Quicksilver, Convolution shiptype = faction_ships.getRandomFighterInt(faction_ships.confed) #print ">fighters/type: " + str(number) + "/" + shiptype ship = self.capital[0] for i in range(number): self.fighter += [launch.launch_wave_around_unit(self.names[self.stage-1],'confed',shiptype,'sitting_duck',1,1000,2000,ship)] # change orders for capital ships for ship in self.capital: ship.PrimeOrders() unit.faceTaget(ship, self.object) # change orders for fighter ships for ship in self.fighter: #unit.faceTaget(ship, self.capital[0]) ship.PrimeOrders() #ship.SetTarget(self.capital[0]) ship.SetTarget(self.object) #ship.UnFire() #ship.setFgDirective("E.") # escort ship.LoadAIScript("modules/ai_escortpatrol.py") # time between spawning the groups self.timer = VS.GetGameTime() #+10 self.stage += 1 if (self.stage==self.groups+1 and VS.GetGameTime()>self.timer): self.stage = 10 # publish news if (self.stage==10 and VS.GetGameTime()>self.timer): text = "JUMP POINT BLOCKADE IN " + self.system + " SYSTEM\\\Intelligence has uncovered Aeran plans to invade Confederation space." text += "As a preventive measure " + str(self.groups) + " flight groups were dispatched and stationed near the Nethuuleil jump point. " text += "Multiple capital vessels are guarding the jump point while a multitude of fighter escorts is patrolling nearby space." news.publishNews(text) self.timer = VS.GetGameTime()+5 self.stage = 11 #make some random chatter if (self.stage==11 and VS.GetGameTime()>self.timer): # select two pilots to chatter flightgroup = 1 #vsrandom.randrange(1,self.groups) numchatters = 0 chatters = [] while (numchatters<2): chatter = vsrandom.randrange(0,len(self.fighter)-1) if (self.fighter[chatter].getFlightgroupName()==self.names[flightgroup-1]): chatters += [chatter] numchatters += 1 VS.IOmessage (0,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"... lousy bar on our mothership?") VS.IOmessage (5,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"Yeah, bad lighting, and no bar company besides your dull face.") VS.IOmessage (10,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"The drinks selection is not the best I have seen.") VS.IOmessage (15,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"And this bartender droid really gets on my nerves.") VS.IOmessage (20,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"He never stops talking for an instant.") VS.IOmessage (25,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"Guess, we've got to live with that.") VS.IOmessage (30,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"Yeah.") self.timer = VS.GetGameTime()+240 self.stage = 12 if (self.stage==12 and VS.GetGameTime()>self.timer): # select two pilots to chatter flightgroup = 2 #vsrandom.randrange(1,self.groups) numchatters = 0 chatters = [] while (numchatters<2): chatter = vsrandom.randrange(0,len(self.fighter)-1) if (self.fighter[chatter].getFlightgroupName()==self.names[flightgroup-1]): chatters += [chatter] numchatters += 1 VS.IOmessage (0,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"Phil?") VS.IOmessage (10,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"What's up, buddy?") VS.IOmessage (15,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"The rumor is the Aera are planning an invasion.") VS.IOmessage (25,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"Maybe no rumor anymore. Probably it's all over the news now.") VS.IOmessage (35,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"That's why we are here? Will we have to fight?") VS.IOmessage (40,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"Calm down, youngling.") VS.IOmessage (45,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"The war hasn't quite started yet.") VS.IOmessage (50,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"I tell ya. This operation is to prepare the worlds for the war.") VS.IOmessage (55,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"All staged by the higherups.") VS.IOmessage (65,unit.getUnitFullName(self.fighter[chatters[0]]),"all",self.msgColor[0]+"You think so? And what if you're not right? Will you take care of my 'lil sister if I die?") VS.IOmessage (75,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"Ho, ho. Now stop that blubber. Nobody's gonna die here.") VS.IOmessage (80,unit.getUnitFullName(self.fighter[chatters[1]]),"all",self.msgColor[1]+"Just stick to your orders and by dinner time we'll have a big jar of Pilsner and a nice long talk.") self.timer = VS.GetGameTime()+300 self.stage = 13 # just a temporary backup if (self.stage==99): #for ship in self.fighter: # ship = VS.getUnit(i) # if (ship.getFlightgroupName()==names[flightgroup]): # print "shipname: " + ship.getFullName() # #ship.setFgDirective("E.") # escort # #VS.PythonAI.XMLScript("++evade.xml") self.stage = 98 #if (self.stage==99 and not VS.getSystemName()==self.system): if (not VS.getSystemName()==self.system): self.stage += 1 # don't enter this loop anymore self.playernum = -1 self.name = "quest_capital" self.removeQuest() return 0
def randomFlagLocation(self): if (len(self.flags)): i = vsrandom.randrange(0,len(self.flags)) return Vector.Add((vsrandom.uniform(-20,20),vsrandom.uniform(-20,20),vsrandom.uniform(-20,20)),self.flags[i].Position()) return (0,0,0)
def Execute(self): if (self.player): #print str(self.player.Position()) # launch the actors if (self.stage <= self.groups and VS.GetGameTime() >= self.timer): #print "group: " +str(self.stage) self.names = fg_util.GetRandomFGNames(self.groups, "confed") shiptype = faction_ships.getRandomCapitolInt( faction_ships.confed) #print "group/name: " + str(self.stage) + "/"+names[self.stage-1] # launch capital ships number = vsrandom.randrange(2, 4) #print ">capital/type: " +str(number)+"/"+shiptype location = Vector.Add(self.object.Position(), (vsrandom.uniform(-10000, 10000), vsrandom.uniform(-10000, 10000), vsrandom.uniform(-10000, 10000))) offset = (vsrandom.uniform(1000, 2000), vsrandom.uniform(1000, 2000), vsrandom.uniform(1000, 2000)) for i in range(number): #self.capital += [launch.launch_wave_around_unit(names[self.stage-1],'confed',shiptype,'sitting_duck',1,5000,20000,self.object)] # launch(name,type,faction,unittype,ai,nr,nrwaves,pos,squadlogo) pos = Vector.Add(location, Vector.Scale(offset, i)) self.capital += [ VS.launch(self.names[self.stage - 1], shiptype, 'confed', 'unit', 'sitting_duck', 1, 1, pos, '') ] # launch fighters number = number * vsrandom.randrange(3, 6) # test: Lancelot, Schroedinger, Quicksilver, Convolution shiptype = faction_ships.getRandomFighterInt( faction_ships.confed) #print ">fighters/type: " + str(number) + "/" + shiptype ship = self.capital[0] for i in range(number): self.fighter += [ launch.launch_wave_around_unit( self.names[self.stage - 1], 'confed', shiptype, 'sitting_duck', 1, 1000, 2000, ship) ] # change orders for capital ships for ship in self.capital: ship.PrimeOrders() unit.faceTaget(ship, self.object) # change orders for fighter ships for ship in self.fighter: #unit.faceTaget(ship, self.capital[0]) ship.PrimeOrders() #ship.SetTarget(self.capital[0]) ship.SetTarget(self.object) #ship.UnFire() #ship.setFgDirective("E.") # escort ship.LoadAIScript("modules/ai_escortpatrol.py") # time between spawning the groups self.timer = VS.GetGameTime() #+10 self.stage += 1 if (self.stage == self.groups + 1 and VS.GetGameTime() > self.timer): self.stage = 10 # publish news if (self.stage == 10 and VS.GetGameTime() > self.timer): text = "JUMP POINT BLOCKADE IN " + self.system + " SYSTEM\\\Intelligence has uncovered Aeran plans to invade Confederation space." text += "As a preventive measure " + str( self.groups ) + " flight groups were dispatched and stationed near the Nethuuleil jump point. " text += "Multiple capital vessels are guarding the jump point while a multitude of fighter escorts is patrolling nearby space." news.publishNews(text) self.timer = VS.GetGameTime() + 5 self.stage = 11 #make some random chatter if (self.stage == 11 and VS.GetGameTime() > self.timer): # select two pilots to chatter flightgroup = 1 #vsrandom.randrange(1,self.groups) numchatters = 0 chatters = [] while (numchatters < 2): chatter = vsrandom.randrange(0, len(self.fighter) - 1) if (self.fighter[chatter].getFlightgroupName() == self.names[flightgroup - 1]): chatters += [chatter] numchatters += 1 VS.IOmessage( 0, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "... lousy bar on our mothership?") VS.IOmessage( 5, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "Yeah, bad lighting, and no bar company besides your dull face." ) VS.IOmessage( 10, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "The drinks selection is not the best I have seen.") VS.IOmessage( 15, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "And this bartender droid really gets on my nerves.") VS.IOmessage( 20, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "He never stops talking for an instant.") VS.IOmessage( 25, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "Guess, we've got to live with that.") VS.IOmessage(30, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "Yeah.") self.timer = VS.GetGameTime() + 240 self.stage = 12 if (self.stage == 12 and VS.GetGameTime() > self.timer): # select two pilots to chatter flightgroup = 2 #vsrandom.randrange(1,self.groups) numchatters = 0 chatters = [] while (numchatters < 2): chatter = vsrandom.randrange(0, len(self.fighter) - 1) if (self.fighter[chatter].getFlightgroupName() == self.names[flightgroup - 1]): chatters += [chatter] numchatters += 1 VS.IOmessage(0, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "Phil?") VS.IOmessage(10, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "What's up, buddy?") VS.IOmessage( 15, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "The rumor is the Aera are planning an invasion.") VS.IOmessage( 25, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "Maybe no rumor anymore. Probably it's all over the news now." ) VS.IOmessage( 35, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "That's why we are here? Will we have to fight?") VS.IOmessage(40, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "Calm down, youngling.") VS.IOmessage( 45, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "The war hasn't quite started yet.") VS.IOmessage( 50, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "I tell ya. This operation is to prepare the worlds for the war." ) VS.IOmessage(55, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "All staged by the higherups.") VS.IOmessage( 65, unit.getUnitFullName(self.fighter[chatters[0]]), "all", self.msgColor[0] + "You think so? And what if you're not right? Will you take care of my 'lil sister if I die?" ) VS.IOmessage( 75, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "Ho, ho. Now stop that blubber. Nobody's gonna die here.") VS.IOmessage( 80, unit.getUnitFullName(self.fighter[chatters[1]]), "all", self.msgColor[1] + "Just stick to your orders and by dinner time we'll have a big jar of Pilsner and a nice long talk." ) self.timer = VS.GetGameTime() + 300 self.stage = 13 # just a temporary backup if (self.stage == 99): #for ship in self.fighter: # ship = VS.getUnit(i) # if (ship.getFlightgroupName()==names[flightgroup]): # print "shipname: " + ship.getFullName() # #ship.setFgDirective("E.") # escort # #VS.PythonAI.XMLScript("++evade.xml") self.stage = 98 #if (self.stage==99 and not VS.getSystemName()==self.system): if (not VS.getSystemName() == self.system): self.stage += 1 # don't enter this loop anymore self.playernum = -1 self.name = "quest_capital" self.removeQuest() return 0
def Siege(fac): global siegenumber global siegenumtimes global siegeprob # turns_till_siege_effective=100 if (not fac in faction_ships.siegingfactions): return numfg= fg_util.NumAllFlightgroups(fac) if (numfg): if (siegenumber==0): siegeprob = float(numfg)/float(faction_ships.siegingfactions[fac]); siegenumtimes = int (siegeprob) if (siegenumtimes==0): siegenumtimes=1 else: siegeprob =1 if siegenumber>=siegenumtimes: siegenumber=0 return 0 else: if (vsrandom.uniform(0,1)<siegeprob): fg =fg_util.RandomFlightgroup(fac) sys = fg_util.FGSystem(fg,fac) enfac=VS.GetGalaxyFaction(sys) if (not sys in faction_ships.invincible_systems): #fg_util.CheckAllShips(fac) #fg_util.CheckAllShips(enfac) if enfac == "unknown": debug.debug("exploration: "+sys) fgleader = fg_util.getFgLeaderType(fg,fac) exploration = 1 else: exploration = 0 if (VS.GetRelation(fac,enfac)<0 and neighborFaction(sys,fac)):#FIXME maybe even less than that numenemyfg = fg_util.NumFactionFGsInSystem(enfac,sys) numfriendfg = fg_util.NumFactionFGsInSystem(fac,sys) #debug.debug('siegarol enemioes '+str(numenemyfg)+ ' friends '+str(numfriendfg)) global dnewsman_ if exploration: if sys != 'nil': generate_dyn_universe.TakeoverSystem(fac,sys) #HACK, regenerate bases instnatly dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_EXPLORATION,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fg,fgleader,"unknown","unknown"]) #FIXME use keyword (ignore #keyword for now Daniel) elif (numenemyfg==0 and numfriendfg==0): #If both annihalate each other completely (unlikely but possible) facnum = VS.GetFactionIndex (fac) debug.debug('cehcking started') debug.error("DRAW error "+fg+" sys has "+sys+" has " +str(fg_util.NumFactionFGsInSystem(fac,sys))+" String is "+Director.getSaveString(0,fg_util.MakeStarSystemFGKey(sys),facnum)) if sys != 'nil': dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_SIEGE,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fg,"unknown","unknown","unknown"]) #FIXME use keyword (ignore #keyword for now Daniel) elif (numenemyfg==0 and (fg_util.CapshipInFG(fg,fac) or moveSurroundingCapshipsToSiege(fac,sys))): #If aggressor succeeded debug.debug(fac + ' took over '+ sys + ' originally owned by '+enfac) #ok now we have him... while the siege is going on the allies had better initiate the battle--because we're now defending the place... so that means if the owners are gone this place is ours at this point in time fgs = fg_util.FGsInSystem(fac,sys) if (len(fgs)>0): fgs=fgs[0] else: fgs = "unknown" if sys != 'nil': dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_SIEGE,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgs,"unknown","unknown","unknown"]) #FIXME use keyword (ignore #keyword for now Daniel) generate_dyn_universe.TakeoverSystem(fac,sys) #HACK, regenerate bases instnatly elif (numfriendfg==0): #If aggressor lost debug.error('wtf!!') fgs = fg_util.FGsInSystem(enfac,sys) if (len(fgs)>0): fgs=fgs[0] else: fgs = "unknown" if sys != 'nil': dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),dnewsman_.TYPE_SIEGE,dnewsman_.STAGE_END,fac,enfac,dnewsman_.SUCCESS_LOSS,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,"unknown","unknown",fgs,"unknown"]) #FIXME use keyword (ignore #keyword for now Daniel) #FIXME add if statements if there is instead a (non appocalyptic) draw (if waring factions have relations "almost neutral" you could have a cease fire, or if the two factions are evenly matched and go nowhere a withdraw of the attackers might occur)!!! siegenumber+=1 return 1 else: return 0
def launchSingleBase(type, faction, sig): radpct = VS.getPlanetRadiusPercent() radpct = sig.rSize() * (1 + radpct) speed = vsrandom.uniform(0, 50) launchBaseOrbit(type, faction, (0, 0, 0), radpct, speed, sig)
def launchSingleBase (type,faction,sig): radpct = VS.getPlanetRadiusPercent() radpct = sig.rSize()*(1+radpct) speed = vsrandom.uniform (0,50) launchBaseOrbit (type,faction,(0,0,0),radpct,speed,sig)
def initrandom(factionname,numsysaway,minenquant,maxenquant,credperen,defendit,defend_base,p_faction='',jumps=(),var_to_set=''): enq=minenquant enq=vsrandom.uniform(minenquant,maxenquant) return defend(factionname,numsysaway,enq,8000.0,100000.0,enq*credperen,defendit,defend_base,p_faction,jumps,var_to_set)
import dynamic_mission import VS import vsrandom import industrial_lib sunny = vsrandom.uniform(0, 1) > .9 time_of_day = '' plist = VS.musicAddList('AWACS.m3u') VS.musicPlayList(plist) dynamic_mission.CreateMissions() industrial_lib.MakeIndustrial(sunny, time_of_day, True)
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)