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

Functions

def shieldBuildName
 
def shieldBuildCategory
 
def afterburnerBuildName
 
def afterburnerBuildCategory
 
def reactorBuildName
 
def reactorBuildCategory
 
def engineBuildName
 
def engineBuildCategory
 
def armorBuildName
 
def armorBuildCategory
 
def GetDiffInt
 
                                                  #
               IMPLEMENTATION                     #
                                                  #

Dataset changes are UNLIKELY to require # implementation changes. More...

 
def GetDiffCargo
 
def getItem
 
def BuildDiffCat
 
def GetRandomWeapon
 
def getRandIncDec
 
def GetShieldLevelZero
 
def GetRandomShield
 
def GetRandomAfterburner
 
def getRandomRadar
 
def UpgradeRadar
 
def UpgradeAfterburner
 
def getRandomEngine
 
def UpgradeEngine
 
def GetRandomHull
 
def GetRandomTurret
 
def GetRandomArmor
 
def UpgradeArmor
 
def GetRandomAmmo
 
def GetRandomRepairSys
 
def basicUnit
 
def upgradeHelper
 
def upgradeUnit
 

Variables

string upgrades_weapons_category = "upgrades/Weapons"
 
                                                  #
               CONFIGURATION                      #
                                                  #

IMPORTANT: dataset changes are LIKELY to require # configuration changes. More...

 
list upgrades_weapons_prefixes = ["Beam_Arrays_","Mounted_Guns_"]
 
list upgrades_weapons_postfixes = ["Light","Medium","Heavy"]
 
string upgrades_weapons_default_weapon = "laser"
 
int upgrades_weapons_default_weapon_count = 2
 
dictionary shieldMaxLevel = { 2:14 , 4:14 }
 
int afterburnerMaxLevel = 5
 
string upgrades_sensors_category = "upgrades/Sensors"
 
list upgrades_sensors_prefixes = [""]
 
list upgrades_sensors_postfixes = ["Common","Confed","Highborn","Rlaan"]
 
int reactorMaxLevel = 14
 
int engineMaxLevel = 0
 
 upgrades_hull_category = None
 
string upgrades_turrets_category = "upgrades/Weapons/Turrets"
 
int armorMaxLevel = 5
 
string upgrades_ammo_category_pri = "upgrades/Ammunition/Common"
 
string upgrades_ammo_category_sec = "upgrades/Ammunition"
 
string upgrades_repair_category_pri = "upgrades/Repair_Systems/Research"
 
string upgrades_repair_category_sec = "upgrades/Repair_Systems"
 

Function Documentation

def ship_upgrades.afterburnerBuildCategory (   level)

Definition at line 65 of file ship_upgrades.py.

65 
66 def afterburnerBuildCategory(level):
67  return "upgrades/Overdrive"
68 
69 # Sensors category construction:
# Similar to weapons category construction
def ship_upgrades.afterburnerBuildName (   level)

Definition at line 60 of file ship_upgrades.py.

60 
61 def afterburnerBuildName(level):
62  if (level > afterburnerMaxLevel):
63  level = afterburnerMaxLevel
64  return "mult_overdrive%02d" % level
def ship_upgrades.armorBuildCategory (   level)

Definition at line 111 of file ship_upgrades.py.

112 def armorBuildCategory(level):
113  return "upgrades/Armor"
114 
115 
# Ammo - try primary, then secondary
def ship_upgrades.armorBuildName (   level)

Definition at line 106 of file ship_upgrades.py.

107 def armorBuildName(level):
108  if (level > armorMaxLevel):
109  level = armorMaxLevel
110  return "armor%02d" % level
def ship_upgrades.basicUnit (   un,
  diff 
)

Definition at line 270 of file ship_upgrades.py.

References vsrandom.random(), and UpgradeAfterburner().

271 def basicUnit (un, diff):
272  i=0
273  for i in range(upgrades_weapons_default_weapon_count): #no unarmed ships, please
274  percent=un.upgrade(upgrades_weapons_default_weapon,i,0,0,1)
275  UpgradeEngine (un,diff)
276  UpgradeRadar (un,diff)
277  #UpgradeArmor (un,diff)
278  if ((vsrandom.random()<0.9) and (vsrandom.random()<(diff*5.0))):
279  UpgradeAfterburner(un,diff)
280  if ((vsrandom.random()<0.9) and (vsrandom.random()<(diff*5.0))):
281  percent=un.upgrade("jump_drive",i,i,0,1)
282  else:
283  percent=un.upgrade("jump_drive",i,i,0,1)
284 
#this function does the dirty work of the upgrade unit function... Given the list that contains a piece of cargo, it upgrades it, subtracts the price, and slaps it on your ship, and returns the new number of creds the computer player has. It may well be negative cus we thought that these guys may go in debt or something
def ship_upgrades.BuildDiffCat (   diff,
  basecat,
  prefixes,
  postfixes,
  use_all = 1,
  dont_use_all = 0 
)

Definition at line 177 of file ship_upgrades.py.

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

178 def BuildDiffCat (diff,basecat,prefixes,postfixes,use_all=1,dont_use_all=0):#gets random beam or mounted gun from master part list
179  return GetDiffCargo(diff,basecat+"/"+prefixes[vsrandom.randrange(0,len(prefixes),1)],basecat,use_all,postfixes,dont_use_all)
def ship_upgrades.engineBuildCategory (   level)

Definition at line 93 of file ship_upgrades.py.

93 
94 def engineBuildCategory(level):
95  return "upgrades/Engines/Standard"
96 
# Hull upgrades
def ship_upgrades.engineBuildName (   level)

Definition at line 88 of file ship_upgrades.py.

88 
89 def engineBuildName(level):
90  if (level > reactorMaxLevel):
91  level = reactorMaxLevel
92  return "engine%02d" % level
def ship_upgrades.GetDiffCargo (   diff,
  base_category,
  all_category,
  use_all,
  postfixes,
  dont_use_all = 0 
)

Definition at line 151 of file ship_upgrades.py.

References vsrandom.randrange().

152 def GetDiffCargo (diff, base_category, all_category, use_all, postfixes, dont_use_all=0):
153  cat=all_category
154  ch=dont_use_all
155  #this makes ch only 1
156  if (diff<=0.2):
157  ch=1
158  elif (diff<=0.4):
159  ch=2-vsrandom.randrange(dont_use_all,3)
160  elif ((diff<=0.7) or use_all):
161  ch=3-vsrandom.randrange(dont_use_all,4)
162  return base_category + postfixes[(ch-1)*len(postfixes)/3]
163 
#this gets a random cargo listed on the master part list.
def ship_upgrades.GetDiffInt (   diff)

                                                  #
               IMPLEMENTATION                     #
                                                  #

Dataset changes are UNLIKELY to require # implementation changes.

In the following section # #

Definition at line 134 of file ship_upgrades.py.

References vsrandom.randrange().

135 def GetDiffInt (diff):
136  ch=0
137  if (diff<=0.1):
138  ch=0
139  elif (diff<=0.3):
140  ch=1-vsrandom.randrange(0,2)
141  elif (diff<=0.5):
142  ch=2-vsrandom.randrange(0,3)
143  elif (diff<=0.7):
144  ch=3-vsrandom.randrange(0,4)
145  elif (diff<=0.9):
146  ch=4-vsrandom.randrange(0,5)
147  else:
148  ch=5-vsrandom.randrange(0,6)
149  return ch
150 
# This function makes a string based on the difficulty. In this way it can be restricted to light or medium mounts when the difficulty is low, avoiding unaffordable weapons
def ship_upgrades.getItem (   cat,
  parentcat = None 
)

Definition at line 164 of file ship_upgrades.py.

165 def getItem (cat,parentcat=None):
166  if not cat:
167  return VS.Cargo("","",0,0,0,0)
168  list=VS.getRandCargo(1,cat)#try to get a cargo from said category
169  if (list.GetQuantity()<=0):#if no such cargo exists in this cateogry
170  if (parentcat!=None):
171  print "Python Upgrade Error: finding %s using %s instead" % (cat,parentcat)
172  list=VS.getRandCargo(1,parentcat)#get it from the parent category
173  if (list.GetQuantity()<=0):#otherwise get cargo from upgrades category
174  print "Python UpgradeError: category %s -- getting random instead" % (cat)
175  list=VS.getRandCargo(1,"upgrades")#this always succeeds
176  return list
def ship_upgrades.getRandIncDec (   type)

Definition at line 187 of file ship_upgrades.py.

188 def getRandIncDec (type):
189  type += vsrandom.randrange (-1,2,2)
190  if (type<0):
191  type=0
192  elif (type>5):
193  type=5
194  return type
def ship_upgrades.GetRandomAfterburner (   diff)

Definition at line 202 of file ship_upgrades.py.

References afterburnerBuildName(), and GetDiffInt().

203 def GetRandomAfterburner (diff):#get random afterburner from master part list (returns filename)
204  return afterburnerBuildName(1+diff*(GetDiffInt(diff)*(afterburnerMaxLevel-1)/5))
def ship_upgrades.GetRandomAmmo ( )

Definition at line 263 of file ship_upgrades.py.

264 def GetRandomAmmo ():
265  return getItem (upgrades_ammo_category_pri,upgrades_ammo_category_sec)
def ship_upgrades.GetRandomArmor (   diff)

Definition at line 257 of file ship_upgrades.py.

References armorBuildName(), and GetDiffInt().

258 def GetRandomArmor (diff):
259  return VS.GetMasterPartList().GetCargo(armorBuildName(1+diff*(GetDiffInt(diff)*(armorMaxLevel-1)/5)))
def ship_upgrades.getRandomEngine (   diff)

Definition at line 223 of file ship_upgrades.py.

References engineBuildName(), GetDiffInt(), and reactorBuildName().

224 def getRandomEngine (diff): #get random engine from master part list
225  myint=GetDiffInt(diff)
226  cat=engineBuildName(myint*engineMaxLevel/5)
227  dog=reactorBuildName(myint*reactorMaxLevel/5)
228  return (myint,cat,dog)
def ship_upgrades.GetRandomHull ( )

Definition at line 251 of file ship_upgrades.py.

References getItem().

252 def GetRandomHull ():
253  return getItem(upgrades_hull_category)
def ship_upgrades.getRandomRadar (   diff)

Definition at line 205 of file ship_upgrades.py.

References BuildDiffCat(), debug.debug, and getItem().

206 def getRandomRadar (diff):
207  cat=BuildDiffCat(diff,upgrades_sensors_category,upgrades_sensors_prefixes,upgrades_sensors_postfixes,1,0)
208  debug.debug("Getting sensors from %s... " % cat)
209  item=getItem(cat,upgrades_sensors_category)
210  debug.debug("Got %s\n" % item)
211  return item
def ship_upgrades.GetRandomRepairSys ( )

Definition at line 266 of file ship_upgrades.py.

267 def GetRandomRepairSys ():
268  return getItem (upgrades_repair_category_pri,upgrades_repair_category_sec)
269 
#this function sets up a blank unit with some basic upgrades that are really a necessecity for any sort of figthing
def ship_upgrades.GetRandomShield (   faces,
  type 
)

Definition at line 198 of file ship_upgrades.py.

References shieldBuildName().

199 def GetRandomShield (faces,type):#gets random shield system from master part list (returns filename)
200  type = getRandIncDec (type)
201  return shieldBuildName(faces,type)
def ship_upgrades.GetRandomTurret ( )

Definition at line 254 of file ship_upgrades.py.

References getItem().

255 def GetRandomTurret ():
256  return getItem(upgrades_turrets_category,None) # No fallback
def ship_upgrades.GetRandomWeapon (   diff)

Definition at line 180 of file ship_upgrades.py.

References BuildDiffCat(), debug.debug, and getItem().

181 def GetRandomWeapon (diff):#gets random beam or mounted gun from master part list
182  cat=BuildDiffCat(diff,upgrades_weapons_category,upgrades_weapons_prefixes,upgrades_weapons_postfixes,1,0)
183  debug.debug("Getting weapon from %s... " % cat)
184  item=getItem(cat,upgrades_weapons_category)
185  debug.debug("Got %s\n" % item)
186  return item
def ship_upgrades.GetShieldLevelZero (   faces)

Definition at line 195 of file ship_upgrades.py.

References shieldBuildName().

196 def GetShieldLevelZero(faces):
197  return shieldBuildName(faces,0)
def ship_upgrades.reactorBuildCategory (   level)

Definition at line 82 of file ship_upgrades.py.

82 
83 def reactorBuildCategory(level):
84  return "upgrades/Reactors/Standard"
85 
# Engines
def ship_upgrades.reactorBuildName (   level)

Definition at line 77 of file ship_upgrades.py.

77 
78 def reactorBuildName(level):
79  if (level > reactorMaxLevel):
80  level = reactorMaxLevel
81  return "reactor%02d" % level
def ship_upgrades.shieldBuildCategory (   faces,
  level 
)

Definition at line 50 of file ship_upgrades.py.

50 
51 def shieldBuildCategory(faces,level):
52  facestring = {
53  2:"upgrades/Shield_Systems/Standard_Dual_Shields",
54  4:"upgrades/Shield_Systems/Standard_Quad_Shields"
55  }
56  return facestring.get(faces, "upgrades/Shield_Systems")
57 
# Engine enhancements (afterburners):
def ship_upgrades.shieldBuildName (   faces,
  level 
)

Definition at line 43 of file ship_upgrades.py.

43 
44 def shieldBuildName(faces,level):
45  facestring = { 2:"dual",4:"quad" }
46  maxlevel = shieldMaxLevel.get(faces,14)
47  if (level > maxlevel):
48  level = maxlevel
49  return "%sshield%02d" % (facestring.get(faces,""),level+1)
def ship_upgrades.UpgradeAfterburner (   un,
  diff 
)

Definition at line 217 of file ship_upgrades.py.

References GetRandomAfterburner().

218 def UpgradeAfterburner (un,diff):
219  i=0
220  while (i<diff*3.0):
221  temp=un.upgrade (GetRandomAfterburner(diff),0,0,1,0)
222  i=i+1
def ship_upgrades.UpgradeArmor (   un,
  diff 
)

Definition at line 260 of file ship_upgrades.py.

References GetRandomArmor().

261 def UpgradeArmor (un, diff):
262  return un.upgrade(GetRandomArmor(diff).GetContent(),0,0,1,0)
def ship_upgrades.UpgradeEngine (   un,
  diff 
)

Definition at line 229 of file ship_upgrades.py.

References debug.debug, GetShieldLevelZero(), and locale.str().

230 def UpgradeEngine (un, diff):
231  (type,cat,dog) = getRandomEngine (diff)
232  if (type!=0):
233  temp=un.upgrade (cat,0,0,1,0)
234  temp=un.upgrade (dog,0,0,1,0)
235  debug.debug("Upgrading Engine %s percent %f" % (cat,temp))
236  if (temp>0.0):
237  cat = GetRandomShield (2,type)
238  temp=un.upgrade (cat,0,0,1,0)
239  debug.debug("Upgrading Shield %s percent %f" % (cat,temp))
240  cat = GetRandomShield (4,type)
241  temp=un.upgrade (cat,0,0,1,0)
242  debug.debug("Upgrading Shield4 %s percent %f" % (cat,temp))
243  return True
244  cat=GetShieldLevelZero(2)
245  temp = un.upgrade(cat,0,0,1,0)
246  debug.debug("Upgrading Shield2 level 0... percent="+str(temp))
247  cat=GetShieldLevelZero(4)
248  temp = un.upgrade(cat,0,0,1,0)
249  debug.debug("Upgrading Shield4 level 0... percent="+str(temp))
250  return False
def ship_upgrades.upgradeHelper (   un,
  mycargo,
  curmount,
  creds,
  force,
  cycle 
)

Definition at line 285 of file ship_upgrades.py.

286 def upgradeHelper (un, mycargo, curmount,creds, force, cycle):
287  newcreds=0.0
288  if (mycargo.GetQuantity()<=0): #if somehow the cargo isn't there
289  return 0.0 #and terminate the enclosing loop by saying we're out of cash
290  else:
291  str=mycargo.GetContent() #otherwise our name is the GetContent() function
292  newcreds=mycargo.GetPrice() #and the price is the GetPrice() function
293  newcreds = newcreds*un.upgrade(str,curmount,curmount,force,cycle)
294  creds = creds -newcreds #we added some newcreds and subtracted them from credit ammt
295  return creds #return new creds
def ship_upgrades.UpgradeRadar (   un,
  diff 
)

Definition at line 212 of file ship_upgrades.py.

References getRandomRadar().

213 def UpgradeRadar (un,diff):
214  item = getRandomRadar(diff)
215  if item:
216  temp=un.upgrade(item.GetContent(),0,0,1,0)
def ship_upgrades.upgradeUnit (   un,
  diff 
)

Definition at line 296 of file ship_upgrades.py.

References basicUnit(), GetRandomAmmo(), GetRandomArmor(), GetRandomHull(), GetRandomRepairSys(), GetRandomTurret(), GetRandomWeapon(), and vsrandom.random().

297 def upgradeUnit (un, diff):
298  creds=0.0
299  curmount=0
300  mycargo=VS.Cargo("","",0,0,0,0)
301  str=""
302  basicUnit(un,diff)
303  mycargo = GetRandomHull() #ok now we get some hull upgrades
304  creds =upgradeHelper (un,mycargo,0,creds,1,0)
305  mycargo = GetRandomArmor(diff) #and some random armor
306  creds =upgradeHelper (un,mycargo,0,creds,1,0)
307  inc=0
308  rndnum=vsrandom.random()*2
309  if (rndnum<diff):
310  mycargo = GetRandomRepairSys() #here there is a small chance that you will get a repair system.
311  creds =upgradeHelper (un,mycargo,0,creds,1,0)
312  turretz=un.getSubUnits()
313  turretcount=0
314  while (turretz.current()):
315  turretz.advance()
316  turretcount += 1
317  turretcount-=1
318  for i in range(turretcount):
319  for j in range(4):
320  mycargo=GetRandomTurret()#turrets as 3rd...
321  creds = upgradeHelper (un,mycargo,i,creds,0,0)
322  turretcount=diff*50
323  if (turretcount>24):
324  turretcount=24
325  elif (turretcount<3):
326  turretcount=3
327  for i in range(int(turretcount)):
328  for j in range (10):
329  if (vsrandom.random()<0.66):
330  mycargo=GetRandomWeapon(diff)#weapons go on as first two items of loop
331  else:
332  mycargo=GetRandomAmmo()
333  cont = mycargo.GetContent()
334  if (cont.find('tractor')==-1 and cont.find('repulsor')==-1 and cont.find("steltek_gun")==-1):
335  creds =upgradeHelper (un,mycargo,curmount,creds,0,1)#we pass this in to the credits...and we only loop through all mounts if we're adding a weapon
336  break
337  curmount+=1#increase starting mounts hardpoint

Variable Documentation

int afterburnerMaxLevel = 5

Definition at line 58 of file ship_upgrades.py.

int armorMaxLevel = 5

Definition at line 104 of file ship_upgrades.py.

int engineMaxLevel = 0

Definition at line 86 of file ship_upgrades.py.

int reactorMaxLevel = 14

Definition at line 75 of file ship_upgrades.py.

dictionary shieldMaxLevel = { 2:14 , 4:14 }

Definition at line 41 of file ship_upgrades.py.

string upgrades_ammo_category_pri = "upgrades/Ammunition/Common"

Definition at line 116 of file ship_upgrades.py.

string upgrades_ammo_category_sec = "upgrades/Ammunition"

Definition at line 117 of file ship_upgrades.py.

upgrades_hull_category = None

Definition at line 97 of file ship_upgrades.py.

string upgrades_repair_category_pri = "upgrades/Repair_Systems/Research"

Definition at line 120 of file ship_upgrades.py.

string upgrades_repair_category_sec = "upgrades/Repair_Systems"

Definition at line 121 of file ship_upgrades.py.

string upgrades_sensors_category = "upgrades/Sensors"

Definition at line 70 of file ship_upgrades.py.

list upgrades_sensors_postfixes = ["Common","Confed","Highborn","Rlaan"]

Definition at line 72 of file ship_upgrades.py.

list upgrades_sensors_prefixes = [""]

Definition at line 71 of file ship_upgrades.py.

string upgrades_turrets_category = "upgrades/Weapons/Turrets"

Definition at line 100 of file ship_upgrades.py.

string upgrades_weapons_category = "upgrades/Weapons"

                                                  #
               CONFIGURATION                      #
                                                  #

IMPORTANT: dataset changes are LIKELY to require # configuration changes.

In the following section # is a list of required upgrade names and bits, # and also functions building the required names. # They're used throughout the code to compose # the upgrade names and categories. # #

Definition at line 33 of file ship_upgrades.py.

string upgrades_weapons_default_weapon = "laser"

Definition at line 36 of file ship_upgrades.py.

int upgrades_weapons_default_weapon_count = 2

Definition at line 37 of file ship_upgrades.py.

list upgrades_weapons_postfixes = ["Light","Medium","Heavy"]

Definition at line 35 of file ship_upgrades.py.

list upgrades_weapons_prefixes = ["Beam_Arrays_","Mounted_Guns_"]

Definition at line 34 of file ship_upgrades.py.