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

Functions

def catInCatList
 
def adjustUnitCargo
 
def systemCargoDemand
 
def setFirstSaveData
 
def getAdjacentSystems
 
def getAdjacentSystemList
 
def getRandomJumppoint
 
def getJumppointList
 
def getMessagePlayer
 
def punish
 
def significantUnits
 
def GetNumSignificantsForSystem
 
def greet
 def init(): #(?) outstr=_string.new() current_system=_std.GetSystemName() last_system=_std.GetSystemName() old_system=_std.GetSystemName() system_map=_omap.new() _omap.set(system_map,current_system,current_system) More...
 
def getDockedBase
 
def getDockedBaseName
 
def ReachableSystems
 
def AllSystems
 
def addTechLevel
 

Function Documentation

def universe.addTechLevel (   level,
  addToBase = True 
)

Definition at line 229 of file universe.py.

References debug.debug, getDockedBase(), unit.getSignificant(), vsrandom.randrange(), locale.str(), and debug.warn.

230 def addTechLevel(level, addToBase=True):
231  try:
232  import faction_ships
233  upgrades=faction_ships.earnable_upgrades[level]
234  except:
235  debug.warn("No tech level named "+str(level))
236  return
237  bas=getDockedBase()
238  if (not bas):
239  import unit
240  import vsrandom
241  debug.debug("getting significant for upgrade addage")
242  bas = unit.getSignificant(vsrandom.randrange(1,20),1,0);
243  for upgrade in upgrades:
244  if (len(upgrade)<5):
245  debug.debug("Upgrade list not big enough to add to tech")
246  print upgrade
247  continue
248  import Director
249  import VS
250  cp = VS.getCurrentPlayer()
251  siz = Director.getSaveStringLength(cp,"master_part_list_content")
252  doIt=True
253  for index in range (siz):
254  if (Director.getSaveString(cp,"master_part_list_content",index)==upgrade[0]):
255  doIt=False
256  if (doIt):
257  debug.debug("added UPGRADE AS FOLLOWS to tech level ")
258  print upgrade
259  Director.pushSaveString(cp,"master_part_list_content",str(upgrade[0]))
260  Director.pushSaveString(cp,"master_part_list_category",str(upgrade[1]))
261  Director.pushSaveString(cp,"master_part_list_price",str(upgrade[2]))
262  Director.pushSaveString(cp,"master_part_list_mass",str(upgrade[3]))
263  Director.pushSaveString(cp,"master_part_list_volume",str(upgrade[4]))
264  if (len(upgrade)>5):
265  Director.pushSaveString(cp,"master_part_list_description",str(upgrade[5]))
266  else:
267  Director.pushSaveString(cp,"master_part_list_description","No description")
268  if (bas and addToBase):
269  debug.debug(" adding "+str(upgrade[0]) +" to base "+bas.getName())
270  cargo=VS.Cargo(str(upgrade[0]),str(upgrade[1]),float(upgrade[2]),1,float(upgrade[3]),float(upgrade[4]))
271  bas.forceAddCargo(cargo)
def universe.adjustUnitCargo (   un,
  cat,
  pr,
  qr 
)

Definition at line 22 of file universe.py.

References catInCatList().

22 
23 def adjustUnitCargo(un,cat,pr,qr):
24  numcargo = un.numCargo()
25  carglist =[]
26  for i in range(numcargo):
27  carg = un.GetCargoIndex(i)
28  if (len(cat)==0 or catInCatList(carg.GetCategory(),cat)):
29  carg.SetPrice (pr*carg.GetPrice())
30  carg.SetQuantity (int(qr*carg.GetQuantity()))
31  carglist += [carg]
32  for carg in carglist:
33  un.removeCargo (carg.GetCategory(),carg.GetQuantity(),1)
34  for carg in carglist:
35  un.addCargo(carg)
36  carglist=0
37 
#universe.systemCargoDemand (("Natural_Products","starships",),.0001,1000)
def universe.AllSystems ( )

Definition at line 223 of file universe.py.

References ReachableSystems().

224 def AllSystems():
225  sys=VS.getSystemFile()
226  if (VS.GetGalaxyProperty("Sol/Sol","jumps")!="" and VS.GetGalaxyProperty("Sol/Sol","faction")!=""):
227  sys="Sol/Sol"
228  return ReachableSystems(sys)
def universe.catInCatList (   cat,
  catlist 
)

Definition at line 15 of file universe.py.

15 
16 def catInCatList (cat,catlist):
17  for i in catlist:
18  loc =cat.find (i)
19  if (loc==0):
20  return 1
21  return 0
def universe.getAdjacentSystemList (   tothissystem)

Definition at line 84 of file universe.py.

84 
85 def getAdjacentSystemList (tothissystem):
86  list=[]
87  max=VS.GetNumAdjacentSystems(tothissystem);
88  for i in range(max):
89  list.append(VS.GetAdjacentSystem(tothissystem,i))
90  return list
def universe.getAdjacentSystems (   currentsystem,
  sysaway,
  jumps = (),
  preferredfaction = '' 
)
returns a tuple in the format ("[lastsystem]",(system1,system2,system3,...))

Definition at line 56 of file universe.py.

References vsrandom.randrange().

56 
57 def getAdjacentSystems (currentsystem, sysaway, jumps=(),preferredfaction=''):
58  """returns a tuple in the format ("[lastsystem]",(system1,system2,system3,...))"""
59  if preferredfaction=='':
60  preferredfaction=VS.GetGalaxyProperty(currentsystem,"faction")
61  max=VS.GetNumAdjacentSystems(currentsystem)
62  if ((sysaway<=0) or (max<=0)):
63 # _io.message (1,"game","all","Your final destination is %s" % (currentsystem))
64  return (currentsystem,jumps)
65  else:
66  syslist=[]
67  numadj=VS.GetNumAdjacentSystems(currentsystem)
68  for i in range(numadj):
69  cursys=VS.GetAdjacentSystem(currentsystem,i)
70  if preferredfaction!=None:
71  if VS.GetGalaxyProperty(cursys,"faction")!=preferredfaction:
72  continue
73  if ((cursys in jumps) or (cursys == VS.getSystemFile())):
74  continue
75  syslist.append(cursys)
76  if not len(syslist):
77  return getAdjacentSystems(currentsystem,0,jumps)
78  nextsystem=syslist[vsrandom.randrange(0,len(syslist))]
79 # _io.message (1,"game","all","Jump from %s to %s." % (currentsystem,nextsystem))
80  return getAdjacentSystems(nextsystem,sysaway-1,jumps+(nextsystem,))
81 
82 #def getAdjacentSystems (currentsystem, num_systems_away):
83 # return nearsys (currentsystem,num_systems_away,())
def universe.getDockedBase ( )

Definition at line 195 of file universe.py.

196 def getDockedBase():
197  iter = VS.getUnitList()
198  while iter.notDone():
199  if VS.getPlayer().isDocked(iter.current()) or iter.current().isDocked(VS.getPlayer()):
200  return iter.current()
201  iter.advance()
202  return iter.current()
def universe.getDockedBaseName ( )

Definition at line 203 of file universe.py.

References getDockedBase().

204 def getDockedBaseName():
205  un = getDockedBase()
206  if (un):
207  return (un.getName(),un.getFullname())
208  return ('','')
def universe.getJumppointList ( )

Definition at line 99 of file universe.py.

99 
100 def getJumppointList():
101  jp_list=[]
102  i = VS.getUnitList()
103  i.advanceNJumppoint(0)
104  while i.notDone():
105  jp_list.append(i.current())
106  i.advanceJumppoint()
107  return jp_list
def universe.getMessagePlayer (   un)

Definition at line 108 of file universe.py.

References locale.str().

109 def getMessagePlayer(un):
110  num=un.isPlayerStarship()
111  if (num<0):
112  return "all"
113  else:
114  return "p"+str(num)
def universe.GetNumSignificantsForSystem (   cursys)

Definition at line 145 of file universe.py.

146 def GetNumSignificantsForSystem (cursys):
147  numjmp=VS.GetNumAdjacentSystems(cursys)
148  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
#use go_somewhere_significant instead:
def universe.getRandomJumppoint ( )

Definition at line 91 of file universe.py.

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

91 
92 def getRandomJumppoint():
93  jp_list=getJumppointList()
94  size=len(jp_list)
95  if (size>0):
96  return jp_list[vsrandom.randrange(0,size)]
97  else:
98  return VS.Unit()
def universe.greet (   greetingText,
  enemy = None,
  you = None 
)

def init(): #(?) outstr=_string.new() current_system=_std.GetSystemName() last_system=_std.GetSystemName() old_system=_std.GetSystemName() system_map=_omap.new() _omap.set(system_map,current_system,current_system)

def Execute(): jumped=false current_system=_std.GetSystemName() if(current_system!=last_system): // we have jumped _io.sprintf(outstr,"jumped from %s to %s",last_system,current_system) _io.message(0,"game","all",outstr) old_system=last_system last_system=_std.GetSystemName() jumped=true return jumped

Definition at line 169 of file universe.py.

References getMessagePlayer().

170 def greet(greetingText,enemy=None,you=None):
171  for i in range(len(greetingText)):
172  color="#ff0000"
173  text=greetingText[i]
174  if type(greetingText[i])==tuple:
175  if not len(greetingText[i]):
176  continue
177  if len(greetingText[i])>1 and greetingText[i][1]:
178  color="#0000ff"
179  if len(greetingText[i])>2 and greetingText[i][2] and you:
180  VS.playSound(greetingText[i][2],(0.,0.,0.),(0.,0.,0.))
181  if enemy:
182  you.communicateTo(enemy,-1)
183  #else: doesn't actually do anything
184  # you.communicateTo(VS.Unit(),-1)
185  text=greetingText[i][0]
186  if (enemy):
187  fromname=enemy.getFlightgroupName()+", "+enemy.getName()+"#000000"
188  else:
189  fromname="[Unidentified]"
190  if (you):
191  toname = getMessagePlayer(you)
192  else:
193  toname="all"
194  VS.IOmessage (8+i*4,color+fromname,toname,"#ff0000"+text+"#000000")
def universe.punish (   you,
  faction,
  difficulty 
)

Definition at line 115 of file universe.py.

References getMessagePlayer(), faction_ships.getRandomFighter(), and launch.launch_wave_around_unit().

116 def punish (you,faction,difficulty):
117  VS.AdjustRelation(you.getFactionName(),faction,difficulty*-.01,1)
118  if (difficulty>=2):
119  VS.IOmessage (0,"mission",getMessagePlayer(you),"#ff0000Your idiocy will be punished.")
120  VS.IOmessage (0,"mission",getMessagePlayer(you),"#ff0000You had better run for what little life you have left.")
121  for i in range(difficulty):
123  newunit=launch.launch_wave_around_unit("shadow", faction, un, "default", 1, 200.0,400.0,you)
124  newunit.setFgDirective("B")
125  newunit.SetTarget(you)
def universe.ReachableSystems (   startingsys)

Definition at line 209 of file universe.py.

References getAdjacentSystemList().

210 def ReachableSystems(startingsys):
211  rv_list=[]
212  closed={}
213  opened=[startingsys]
214  while len(opened):
215  openmore=[]
216  for sys in opened:
217  if not sys in closed:
218  closed[sys]=1
219  rv_list.append(sys)
220  openmore += getAdjacentSystemList(sys)
221  opened=openmore
222  return rv_list
def universe.setFirstSaveData (   player,
  key,
  val 
)

Definition at line 49 of file universe.py.

49 
50 def setFirstSaveData(player,key,val):
51  mylen = Director.getSaveDataLength(player,key)
52  if (mylen>0):
53  Director.putSaveData(player,key,0,val)
54  else:
55  Director.pushSaveData(player,key,val)
def universe.significantUnits ( )

Definition at line 132 of file universe.py.

References debug.debug, and debug.error.

133 def significantUnits():
134  ret=[]
135  iter= VS.getUnitList()
136  iter.advanceNSignificant(0)
137  while (iter.notDone()):
138  un = iter.current()
139  debug.debug('Found sig unit: '+un.getName()+' ('+un.getFullname()+')')
140  if not un.isSignificant():
141  debug.error('Unit '+un.getName()+' ('+un.getFullname()+') is not significant!')
142  ret.append(iter.current())
143  iter.advanceSignificant()
144  return ret
def universe.systemCargoDemand (   category,
  priceratio,
  quantratio,
  ships = 1,
  planets = 1 
)

Definition at line 38 of file universe.py.

References adjustUnitCargo().

38 
39 def systemCargoDemand (category,priceratio,quantratio,ships=1,planets=1):
40  i = VS.getUnitList()
41  un = i.current()
42  while (not un.isNull()):
43  if (un.isPlayerStarship()==-1):
44  isplanet = un.isPlanet()
45  if ( (isplanet and planets) or ((not isplanet) and ships)):
46  adjustUnitCargo(un,category,priceratio,quantratio)
47  i.advance()
48  un=i.current()