Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
generate_dyn_universe Namespace Reference

Functions

def XProductionRate
 
def floatToRand
 
def GenerateCivilianFgShips
 
def GenerateFgShips
 
def GenerateAllShips
 
def AddBasesToSystem
 
def GetNewFGName
 
def AddSysDict
 
def ForEachSys
 
def MakeUniverse
 
def getSystemCount
 
def CountSystems
 
def TakeoverSystem
 
def ReloadUniverse
 
def KeepUniverseGenerated
 

Variables

 cp = fg_util.ccp
 
int maxshipsinfg = 20
 
list fgnames = []
 
list fgoffset = []
 
list origfgnames = []
 
int _generatedsys = 0
 
int _last_progress_percent = -1
 

Function Documentation

def generate_dyn_universe.AddBasesToSystem (   faction,
  sys 
)

Definition at line 85 of file generate_dyn_universe.py.

References fg_util.AddShipsToFG(), webpageize.index, vsrandom.random(), and vsrandom.randrange().

85 
86 def AddBasesToSystem (faction,sys):
87  if (sys in doNotAddBasesTo):
88  return
89  slash = sys.find("/")
90  if (slash!= -1):
91  if (sys[0:slash] in doNotAddBasesTo):
92  return
93  if faction in faction_ships.factions:
94  fsfac= list(faction_ships.factions).index(faction)
95  numbases=0
96 # numplanets=VS.GetGalaxyProperty(sys,"num_planets");
97  numjumppoints=VS.GetNumAdjacentSystems(sys);
98  if (numjumppoints<4):
99  if (vsrandom.random()>=.25):
100  numbases=1
101  elif (vsrandom.random()>=.005):
102  if (numjumppoints<7):
103  numbases=vsrandom.randrange(1,int(numjumppoints/2)+1)
104  elif numjumppoints==7:
105  numbases=vsrandom.randrange(1,6)
106  else:
107  numbases=vsrandom.randrange(1,numjumppoints+1)
108  if numbases==0:
109  return
110  shiplist=[]
111  nums=[]
112  for i in xrange(numbases):
113  whichbase = faction_ships.bases[fsfac][vsrandom.randrange(0,len(faction_ships.bases[fsfac]))]
114  if whichbase in shiplist:
115  nums[shiplist.index(whichbase)]+=1
116  else:
117  shiplist.append(whichbase)
118  nums.append(1)
119  tn =[]
120  for i in xrange(len(shiplist)):
121  tn+=[ (shiplist[i],nums[i])]
122  fg_util.AddShipsToFG(fg_util.BaseFGInSystemName (sys),faction,tn,sys)
123 
124 numericalfaction=0
def generate_dyn_universe.AddSysDict (   cursys)

Definition at line 145 of file generate_dyn_universe.py.

References AddBasesToSystem(), faction_ships.factionToInt(), GenerateCivilianFgShips(), GenerateFgShips(), faction_ships.get_friend_of_no_citizen(), faction_ships.get_rabble_of_no_citizen(), universe.getAdjacentSystemList(), GetNewFGName(), getSystemCount(), fg_util.MaxNumFlightgroupsInSystem(), fg_util.MinNumFlightgroupsInSystem(), vsrandom.random(), vsrandom.randrange(), ShowProgress.setProgressBar(), and ShowProgress.setProgressMessage().

146 def AddSysDict (cursys):
147  global _generatedsys, _last_progress_percent
148  #pick random fighter from insysenemies with .3 probability OR pick one from the friendlies list.
149 # debug.debug('Addsysdict')
150  sysfaction=VS.GetGalaxyFaction(cursys)
151 
153 
154  #debug.debug("Initializing system %s with %d flightgroups... " % (cursys,numflightgroups))
155  progress_percent = (float(_generatedsys) / getSystemCount())
156  if progress_percent - _last_progress_percent > 0.01:
157  ShowProgress.setProgressBar("loading",progress_percent)
158  ShowProgress.setProgressMessage("loading","Generating dynamic universe (%.2f%%)" % (100*progress_percent))
159  _last_progress_percent = progress_percent
160  _generatedsys += 1
161 
162  global fgnames, fglists
163  i=0
164  AddBasesToSystem(sysfaction, cursys)
165  adjsystems=getAdjacentSystemList(cursys)
166  for i in xrange(len(faction_ships.factions)):
167  thisfac=faction_ships.factions[i]
168  thisfactionnr=faction_ships.factionToInt(thisfac)
169  rel=VS.GetRelation(sysfaction,thisfac)
170  iscit=VS.isCitizen(thisfac)
171  if iscit and thisfac.find(sysfaction)!=-1:
172  #debug.debug("generating spc civilian for "+cursys+" faction "+thisfac)
173  #do somethign special for this military faction
174  if thisfac==sysfaction:
175  pass
176  elif iscit:
177  for neighbor in adjsystems:
178  if (VS.GetRelation(thisfac,VS.GetGalaxyFaction(neighbor))>-.05):
179  #fgname=cursys+"->"+neighbor
180  fgname="(CivReg) "+GetNewFGName(thisfac)
181  typenumbertuple=GenerateCivilianFgShips(thisfac,thisfactionnr,True)
182  fg_util.AddShipsToFG (fgname,thisfac,typenumbertuple,cursys)
183  fgname="Insystem_"+cursys;
184  typenumbertuple=GenerateCivilianFgShips(thisfac,thisfactionnr,False)
185  if iscit:
186  #debug.debug("generating gen civilian for "+cursys+" faction "+thisfac)
187  if VS.GetRelation(thisfac,sysfaction)>-.05:#brave citizens of the new order...
188  fgname=GetNewFGName(thisfac)
189  typenumbertuple=GenerateCivilianFgShips(thisfac,thisfactionnr,True)
190  fg_util.AddShipsToFG (fgname,thisfac,typenumbertuple,cursys)
191  friendlychance=.7
192  if cursys in faction_ships.fortress_systems:
193  friendlychance=faction_ships.fortress_systems[cursys]
194  #debug.debug('enemy chance for '+cursys +'= '+str(friendlychance))
195  for i in xrange (numflightgroups): #number of fgs in a system.
196  faction=sysfaction
197  friendly=0
198  if not sysfaction or sysfaction=='unknown' or vsrandom.random()>friendlychance:
199  faction=faction_ships.get_rabble_of_no_citizen(sysfaction)#why even have citizens on the list then
200  else:
201  faction=faction_ships.get_friend_of_no_citizen(sysfaction)#likewise--- maybe this should be a faction_ships fix
202  if (faction==sysfaction):
203  friendly=1
204  if (sysfaction in faction_ships.production_centers):
205  if (cursys in faction_ships.production_centers[sysfaction]):
206  friendly=2
207  #if (friendly):
208  # debug.debug(faction+" "+sysfaction+" "+cursys)
209  factionnr=faction_ships.factionToInt(faction)
210  global maxshipsinfg
211  typenumbertuple=GenerateFgShips(vsrandom.randrange(maxshipsinfg)+1,factionnr,friendly)
212  fgname=GetNewFGName(faction)
213  fg_util.AddShipsToFG (fgname,faction,typenumbertuple,cursys)
214  return i
def generate_dyn_universe.CountSystems (   sys)

Definition at line 230 of file generate_dyn_universe.py.

231 def CountSystems(sys):
232  fac =VS.GetGalaxyFaction(sys)
233  if fac in systemcount:
234  systemcount[fac]+=1
235  else:
236  systemcount[fac]=1
systemcount[None] += 1
def generate_dyn_universe.floatToRand (   maximum)

Definition at line 22 of file generate_dyn_universe.py.

References vsrandom.randrange(), and vsrandom.uniform().

22 
23 def floatToRand(maximum):
24  if maximum==0:
25  return 0
26  tmp=vsrandom.randrange(0,int(maximum)+1)
27  if (vsrandom.uniform(0,1)<maximum-int(maximum)):
28  return tmp+1
return tmp
def generate_dyn_universe.ForEachSys (   functio)

Definition at line 215 of file generate_dyn_universe.py.

References universe.AllSystems(), and debug.debug.

216 def ForEachSys (functio):
217  debug.debug("Getting reachable systems...")
218  systems = AllSystems()
219  debug.debug("done")
220  for sys in systems:
221  functio(sys)
return len(systems)
def generate_dyn_universe.GenerateAllShips ( )

Definition at line 76 of file generate_dyn_universe.py.

References faction_ships.getMaxFactions(), and fg_util.GetRandomFGNames().

76 
77 def GenerateAllShips ():
78  global fgnames,origfgnames,fgoffset
79  for fnr in xrange(faction_ships.getMaxFactions()):
80  fgnames.append(fg_util.GetRandomFGNames(-1,faction_ships.factions[fnr]))
81  fgoffset.append(0)
82  origfgnames.append(list(fgnames[-1]))
83 
84 
doNotAddBasesTo={"enigma_sector/heavens_gate":1,"sol_sector/celeste":1,"enigma_sector/enigma":1,"enigma_sector/niven":1,"Gemini":1,"Crucible/Cephid_17":1}
def generate_dyn_universe.GenerateCivilianFgShips (   faction,
  factionnr,
  docapships 
)

Definition at line 29 of file generate_dyn_universe.py.

References floatToRand().

29 
30 def GenerateCivilianFgShips (faction,factionnr,docapships):
31  lst=[]
32  capitals=faction_ships.capitals[factionnr]
33  fighters=faction_ships.fighters[factionnr]
34  numfighters=1
35  try:
36  numfighters=faction_ships.fightersPerFG["default"]
37  numfighters=faction_ships.fightersPerFG[faction]
38  except:
39  pass
40  numcapitals=0
41  if docapships:
42  try:
43  numcapitals=faction_ships.fightersPerFG["default"]
44  numcapitals=faction_ships.PerFG[faction]
45  except:
46  pass
47  fighters_per=len(fighters)
48  ht={}
49  for i in fighters:
50  numtogen=floatToRand(numfighters/float(len(fighters)))
51  if numtogen:
52  if i in ht:
53  ht[i]+=numtogen
54  else:
55  ht[i]=numtogen
56  for i in capitals:
57  numtogen=floatToRand(numcapitals/float(len(capitals)))
58  if numtogen>0:
59  if i in ht:
60  ht[i]+=numtogen
61  else:
62  ht[i]=numtogen
63  for hv in ht:
64  lst.append([hv,ht[hv]])
return lst
def generate_dyn_universe.GenerateFgShips (   shipinfg,
  factionnr,
  friendly 
)

Definition at line 65 of file generate_dyn_universe.py.

References debug.debug, faction_ships.getRandomCapitolInt(), faction_ships.getRandomFighterInt(), faction_ships.intToFaction(), vsrandom.random(), locale.str(), and XProductionRate().

65 
66 def GenerateFgShips (shipinfg,factionnr,friendly):
67  lst=[]
68  capship=()
69  fac = faction_ships.intToFaction(factionnr)
70  fpr=XProductionRate(fac,faction_ships.fighterProductionRate)
71  cpr=XProductionRate(fac,faction_ships.capitalProductionRate)
72  if cpr>0 and (friendly==2 or (friendly==1 and vsrandom.random()<cpr/fpr)):
73  capship=((faction_ships.getRandomCapitolInt(factionnr),1),)
74  debug.debug("Generating capital "+str(capship))
75  return ((faction_ships.getRandomFighterInt(factionnr),shipinfg),)+capship
def generate_dyn_universe.GetNewFGName (   faction)

Definition at line 125 of file generate_dyn_universe.py.

References debug.debug, debug.error, faction_ships.factionToInt(), vsrandom.randrange(), locale.str(), and fg_util.TweakFGNames().

126 def GetNewFGName(faction):
127  factionnr=faction_ships.factionToInt(faction)
128  global numericalfaction,fgnames,origfgnames,fgoffset
129  if(factionnr>=len(fgnames)):
130  debug.error("Faction "+faction+" unable to create fgname")
131 
132  numericalfaction+=1
133  return "Alpha_"+str(numericalfaction)
134  if (not len(fgnames[factionnr])):
135  debug.debug("Loading FG names for %s" % faction)
136  fg_util.origoffset=fgoffset[factionnr]
137  fgnames[factionnr]=fg_util.TweakFGNames(origfgnames[factionnr])
138  fgoffset[factionnr]+=1
139  k=vsrandom.randrange(0,len(fgnames[factionnr])); #pop returns item inside array
140  fgname=fgnames[factionnr][k]
141  del fgnames[factionnr][k]
142  return fgname
def generate_dyn_universe.getSystemCount (   fac = None)

Definition at line 227 of file generate_dyn_universe.py.

228 def getSystemCount(fac=None):
229  global systemcount
return systemcount[fac]
def generate_dyn_universe.KeepUniverseGenerated ( )

Definition at line 294 of file generate_dyn_universe.py.

References dj_lib.enable(), and ReloadUniverse().

296  if VS.networked():
297  dj_lib.enable()
298  #debug.debug('Not generating dyn universe: Networked game')
299  return False
300 
301  sys = VS.getSystemFile()
302  if not VS.GetNumAdjacentSystems(sys):
303  #debug.debug('Not generating dyn universe: System has no jumps or is not in Universe XML.')
304  return False
305 
306  dj_lib.enable()
307  #curfaclist = fg_util.AllFactions()
308  #reflist = fg_util.ReadStringList(cp,"FactionRefList")
309  #if (reflist == curfaclist):
310  # debug.debug('Generating dyn universe!');
311  if not hasUniverse:
313  return True
314  return False
def generate_dyn_universe.MakeUniverse ( )

Definition at line 222 of file generate_dyn_universe.py.

References fg_util.DeleteAllFGFromAllSystems(), and ForEachSys().

223 def MakeUniverse():
225  ForEachSys(AddSysDict)
226 
systemcount={None:0}
def generate_dyn_universe.ReloadUniverse ( )

Definition at line 246 of file generate_dyn_universe.py.

References ShowProgress.activateProgressScreen(), fg_util.AllFactions(), ShowProgress.deactivateProgressScreen(), debug.debug, fg_util.DeleteLegacyFGLeftovers(), debug.error, ForEachSys(), GenerateAllShips(), fg_util.HasLegacyFGFormat(), campaigns.loadAll(), MakeUniverse(), fg_util.PurgeZeroShips(), fg_util.ReadStringList(), locale.str(), fg_util.TweakFGNames(), debug.warn, and fg_util.WriteStringList().

247 def ReloadUniverse():
248  global genUniverse, hasUniverse
249  if cp>=0:
250  ShowProgress.activateProgressScreen("loading",force=True)
251  debug.debug('Purging...')
252  for i in fg_util.AllFactions():
254  systemcount[i]=0
255  debug.debug('StartSystemCount')
256  ForEachSys(CountSystems)
257  debug.debug(systemcount)
258  debug.debug('EndSystemCount')
259  genUniverse=0
260  needNewUniverse=0
261  curfaclist = fg_util.AllFactions()
262  reflist = fg_util.ReadStringList(cp,"FactionRefList")
263 
264  if (reflist !=curfaclist):
265  needNewUniverse = 1
266  debug.debug('reflist is '+str(reflist))
267  debug.debug('curfaclist is '+str(curfaclist))
268 
270  needNewUniverse = 1
271  debug.warn('save using legacy FG format... resetting universe to reformat')
273 
274  if needNewUniverse:
275  fg_util.WriteStringList(cp,"FactionRefList",curfaclist)
276  debug.debug('generating ships... ... ...')
277  GenerateAllShips() ###Insert number of flight groups and max ships per fg
278  debug.debug('placing ships... ... ...')
279  genUniverse=MakeUniverse()
280  #now every system has distributed ships in the save data!
281  else:
283  debug.debug("Second Load")
284  for i in xrange(len(fgnames)):
285  fg_util.origfgoffset=fgoffset[i]
286  fgnames[i]=fg_util.TweakFGNames(origfgnames[i])
287  fgoffset[i]+=1
289  hasUniverse=True;
290  #TODO: add ships to current system (for both modes) uru?
292  else:
293  debug.error('fatal error: no cockpit')
def generate_dyn_universe.TakeoverSystem (   fac,
  sys 
)

Definition at line 237 of file generate_dyn_universe.py.

References AddBasesToSystem().

238 def TakeoverSystem(fac,sys):
239  systemcount[VS.GetGalaxyFaction(sys)]-=1
240  VS.SetGalaxyFaction(sys,fac)
241  systemcount[fac]+=1
242  AddBasesToSystem(fac,sys)
243 
244 hasUniverse=False
245 
genUniverse=-1
def generate_dyn_universe.XProductionRate (   fac,
  type 
)

Definition at line 18 of file generate_dyn_universe.py.

18 
19 def XProductionRate(fac,type):
20  if fac in type:
21  return type[fac]
return type["default"]

Variable Documentation

int _generatedsys = 0

Definition at line 143 of file generate_dyn_universe.py.

int _last_progress_percent = -1

Definition at line 144 of file generate_dyn_universe.py.

cp = fg_util.ccp

Definition at line 12 of file generate_dyn_universe.py.

list fgnames = []

Definition at line 14 of file generate_dyn_universe.py.

list fgoffset = []

Definition at line 15 of file generate_dyn_universe.py.

int maxshipsinfg = 20

Definition at line 13 of file generate_dyn_universe.py.

list origfgnames = []

Definition at line 16 of file generate_dyn_universe.py.