def getAdjacentSystems(currentsystem, sysaway, jumps=(), preferredfaction=''): """returns a tuple in the format ("[lastsystem]",(system1,system2,system3,...))""" if preferredfaction == '': preferredfaction = VS.GetGalaxyProperty(currentsystem, "faction") max = VS.GetNumAdjacentSystems(currentsystem) if ((sysaway <= 0) or (max <= 0)): # _io.message (1,"game","all","Your final destination is %s" % (currentsystem)) return (currentsystem, jumps) else: syslist = [] numadj = VS.GetNumAdjacentSystems(currentsystem) for i in range(numadj): cursys = VS.GetAdjacentSystem(currentsystem, i) if preferredfaction != None: if VS.GetGalaxyProperty(cursys, "faction") != preferredfaction: continue if ((cursys in jumps) or (cursys == VS.getSystemFile())): continue syslist.append(cursys) if not len(syslist): return getAdjacentSystems(currentsystem, 0, jumps) nextsystem = syslist[vsrandom.randrange(0, len(syslist))] # _io.message (1,"game","all","Jump from %s to %s." % (currentsystem,nextsystem)) return getAdjacentSystems(nextsystem, sysaway - 1, jumps + (nextsystem, ))
def isStoryRelevant(self, strin): """Is the event in this string relevant to the current system and dockedat faction?""" varlist = self.sTovarlist(strin) limit = False if varlist[self.EVENT_TYPE_INDEX] in [ self.TYPE_BATTLE, self.TYPE_DESTROYED ]: limit = 1 else: return True event_sys = varlist[self.EVENT_SYSTEM_INDEX] syslist = [VS.getSystemFile()] done_syslist = list() while limit >= 0: if event_sys in syslist: return True else: done_syslist += syslist new_syslist = list() for syst in syslist: for i in range(VS.GetNumAdjacentSystems(syst)): sy = VS.GetAdjacentSystem(syst, i) if sy not in done_syslist: new_syslist.append(sy) syslist = new_syslist limit -= 1 return False
def launch_new_wave(self): un = VS.getPlayer() if (vsrandom.randrange(0, 4) == 0): if (un): currentsystem = VS.getSystemFile() numadj = VS.GetNumAdjacentSystems(currentsystem) if (numadj): cursys = VS.GetAdjacentSystem( currentsystem, vsrandom.randrange(0, numadj)) else: cursys = 'enigma_sector/heavens_gate' debug.info("TJ: jumping to " + cursys) un.JumpTo(cursys) else: debug.warn("TJ: jumping to [ERROR: you are null]") return else: siglist = universe.significantUnits() if len(siglist) == 0: debug.info("TJ: siglist empty") return sig = siglist[vsrandom.randrange(0, len(siglist))] if (not sig): debug.info("TJ: sig null") return debug.info("TJ: autopiloting to " + sig.getName()) un.AutoPilotTo(sig, True) un.SetTarget(sig)
def launch_new_wave(self): un = VS.getPlayer() if (vsrandom.randrange(0,4)==0): if (un): currentsystem = VS.getSystemFile() numadj=VS.GetNumAdjacentSystems(currentsystem) if (numadj): cursys=VS.GetAdjacentSystem(currentsystem,vsrandom.randrange(0,numadj)) else: cursys = 'enigma_sector/heavens_gate' debug.info("TJ: jumping to "+cursys) un.JumpTo(cursys) else: debug.info("TJ: jumping to [ERROR: you are null]") side = vsrandom.randrange(0,2) faction="confed" ai = vsrandom.randrange(0,6) if (0 and ai==0): ai = "printhello.py" else: ai = "default" if (side==0): faction=faction_ships.get_enemy_of("confed") else: faction=faction_ships.get_friend_of("confed") launched = launch.launch_wave_around_unit ("Shadow",faction,faction_ships.getRandomFighter(faction),ai,vsrandom.randrange(1,10),100.0,2000.0,VS.getPlayer(),'') if (vsrandom.randrange(0,10)==0): launch.launch_wave_around_unit ("ShadowCap",faction,faction_ships.getRandomCapitol(faction),ai,1,2000.0,4000.0,VS.getPlayer(),'')
def attackFlightgroup (fgname, faction, enfgname, enfaction,iscap): global dnewsman_ if (iscap): battlename=dnewsman_.TYPE_FLEETBATTLE (leader,enleader)=iscap.split(",") else: battlename = dnewsman_.TYPE_BATTLE leader = fg_util.getFgLeaderType(fgname,faction) enleader = fg_util.getFgLeaderType(enfgname,enfaction) sys = fg_util.FGSystem (fgname,faction) ensys = fg_util.FGSystem (enfgname,enfaction) if (sys==ensys): if (0 and VS.systemInMemory(sys)): VS.pushSystem(sys) LaunchEqualShips (fgname,faction,enfgname,enfaction) VS.TargetEachOther (fgname,faction,enfgname,enfaction) VS.popSystem() #debug.debug('duke '+fgname + ' '+enfgname) SimulatedDukeItOut (fgname,faction,enfgname,enfaction) elif (sys!='nil' and ensys!='nil'): #pursue other flightgroup import universe adjSystemList=universe.getAdjacentSystemList(sys) if ensys in adjSystemList: fg_util.TransferFG (fgname,faction,ensys) else: return 0 else: return 0 #debug.debug('nil DRAW error') if (fg_util.NumShipsInFG(fgname,faction)==0): if (fg_util.NumShipsInFG(enfgname,enfaction)==0): dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),battlename,dnewsman_.STAGE_END,faction,enfaction,dnewsman_.SUCCESS_DRAW,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgname,leader,enfgname,enleader]) else: dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),battlename,dnewsman_.STAGE_END,faction,enfaction,dnewsman_.SUCCESS_LOSS,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgname,leader,enfgname,enleader]) return 0 elif (fg_util.NumShipsInFG(enfgname,enfaction)==0): dnewsman_.writeDynamicString([str(Director.getSaveData(0,"stardate",0)),battlename,dnewsman_.STAGE_END,faction,enfaction,dnewsman_.SUCCESS_WIN,str(getImportanceOfSystem(sys)),sys,dnewsman_.KEYWORD_DEFAULT,fgname,leader,enfgname,enleader]) return 0 if (vsrandom.randrange(0,4)==0): #FIXME if it is advantageous to stop attacking only!! #FIXME add a stop attacking news report? -- this should now be fixed, as a draw is reported (not heavilly tested) #CAUSES TOO MUCH NEWS#Director.pushSaveString(0,"dynamic_news",dynamic_news.makeVarList([str(Director.getSaveData(0,"stardate",0)),battlename,"end",faction,enfaction,"0",str(getImportanceOfSystem(sys)),sys,"all",fgname,leader,enfgname,enleader])) return 0 if (vsrandom.randrange(0,4)==0 and enfgname!=fg_util.BaseFGInSystemName(ensys)): #FIXME if it is advantageous to run away only #FIXME add a retreat news report? -- this should now be fixed, as a draw is reported (not heavilly tested) #CAUSES TOO MUCH NEWS#Director.pushSaveString(0,"dynamic_news",dynamic_news.makeVarList([str(Director.getSaveData(0,"stardate",0)),battlename,"end",faction,enfaction,"-1",str(getImportanceOfSystem(sys)),sys,"all",fgname,leader,enfgname,enleader])) num=VS.GetNumAdjacentSystems(ensys) if (num>0): ensys=VS.GetAdjacentSystem(ensys,vsrandom.randrange(0,num)) fg_util.TransferFG (fgname,faction,ensys) return 1
def moveSurroundingCapshipsToSiege(fac,sys): suc=0 for i in xrange(VS.GetNumAdjacentSystems(sys)): asys=VS.GetAdjacentSystem(sys,i) for fg in fg_util.AllFGsInSystem(fac,asys): if fg_util.CapshipInFG(fg,fac): suc=1 fg_util.TransferFG(fg,fac,sys) if (not suc): for fg in fg_util.AllFGsInSystem(fac,sys): if (fg_util.CapshipInFG(fg,fac)): suc=1 return suc
def KeepUniverseGenerated(): if VS.networked(): dj_lib.enable() #debug.debug('Not generating dyn universe: Networked game') return False sys = VS.getSystemFile() if not VS.GetNumAdjacentSystems(sys): #debug.debug('Not generating dyn universe: System has no jumps or is not in Universe XML.') return False dj_lib.enable() #curfaclist = fg_util.AllFactions() #reflist = fg_util.ReadStringList(cp,"FactionRefList") #if (reflist == curfaclist): # debug.debug('Generating dyn universe!'); if not hasUniverse: ReloadUniverse() return True return False
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)
def neighborFaction(sys,fac): for i in xrange(VS.GetNumAdjacentSystems(sys)): asys=VS.GetAdjacentSystem(sys,i) if (VS.GetGalaxyFaction(asys)==fac): return True return False
def getAdjacentSystemList(tothissystem): list_2 = [] max = VS.GetNumAdjacentSystems(tothissystem) for i in range(max): list_2.append(VS.GetAdjacentSystem(tothissystem, i)) return list_2
def GetNumSignificantsForSystem(cursys): numjmp = VS.GetNumAdjacentSystems(cursys) return _tmpint(VS.GetGalaxyProperty(cursys, "num_planets"), 3) + _tmpint( VS.GetGalaxyProperty(cursys, "num_moons"), 4) + _tmpint( VS.GetGalaxyProperty(cursys, "num_gas_giants"), 2) + _tmpint( VS.GetGalaxyProperty(cursys, "num_starbases"), 1) + numjmp