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

Data Structures

class  playerdata
 

Public Member Functions

def __init__
 
def AddPlayer
 
def NewSystemHousekeeping
 
def RestoreDroneMission
 
def CalculateSignificantDistance
 
def SetEnemyProb
 
def AsteroidNear
 
def TrueEnProb
 
def launch_near
 
def atLeastNInsignificantUnitsNear
 
def SetModeZero
 
def SetModeOne
 
def decideMode
 
def DifferentSystemP
 
def Execute
 

Data Fields

 capship_gen_distance
 
 enprob
 
 fighterprob
 
 det_distance
 
 sig_distance
 
 players
 
 generation_distance
 
 min_num_ships
 
 gen_num_ships
 
 capship_prob
 
 cur_player
 
 sig_distance_table
 
 spawning
 
 probability_cache
 
 cur
 

Static Public Attributes

int psum = 0
 
list probs = []
 
tuple faction = faction_ships.intToFaction(factionnum)
 
tuple num = fg_util.NumFactionFGsInSystem(faction,cursys)
 
tuple avg = float(num)
 
int fortress_level = 0
 
list foretress_level = faction_ships.fortress_systems[cursys]
 
tuple rnd = vsrandom.random()
 
int p = 0
 
tuple fglist = fg_util.FGsInSystem(faction,cursys)
 
list flightgroup = fglist[vsrandom.randrange(len(fglist))]
 
tuple typenumbers = fg_util.GetShipsInFG(flightgroup,faction)
 

Detailed Description

Definition at line 18 of file random_encounters.py.

Constructor & Destructor Documentation

def __init__ (   self,
  sigdis,
  detectiondis,
  gendis,
  minnships,
  gennships,
  unitprob,
  enemyprob,
  capprob,
  capdist 
)

Definition at line 45 of file random_encounters.py.

References debug.debug.

45 
46  def __init__(self, sigdis, detectiondis, gendis, minnships, gennships, unitprob, enemyprob, capprob, capdist):
47  unitprob=1
48  debug.debug("init random enc")
49 
50  self.capship_gen_distance=capdist
51  # player_num=player
52  self.enprob = enemyprob
53  self.fighterprob = unitprob
54 
55  self.det_distance = detectiondis
56  self.sig_distance = sigdis
57  self.players=[]
58  self.generation_distance=gendis
59  self.min_num_ships=minnships
60  self.gen_num_ships=gennships
61  self.capship_prob=capprob
62  self.cur_player=0
63  self.sig_distance_table = {"enigma_sector/heavens_gate":(2000,4000,.4)}
64  self.spawning=0
65  # Cache format is (Faction,System,Probability[Faction],sum)
66  self.probability_cache = (0,'',[],0)
debug.debug("end random enc")

Member Function Documentation

def AddPlayer (   self)

Definition at line 67 of file random_encounters.py.

References random_encounters.det_distance, random_encounters.players, Campaign.players, and random_encounters.sig_distance.

67 
68  def AddPlayer (self):
69 # debug.debug("begin add player")
71 # debug.debug("add player")
def AsteroidNear (   self,
  uni,
  how 
)

Definition at line 117 of file random_encounters.py.

References debug.debug.

118  def AsteroidNear (self,uni, how):
119  i = VS.getUnitList()
120  dd = self.cur.detection_distance
121  while i.notDone():
122  un = i.current()
123  if (uni.getSignificantDistance(un)<how):
124  if (unit.isAsteroid (un)):
125  debug.debug("asty near")
126  return 1
127  i.advance()
return 0
def atLeastNInsignificantUnitsNear (   self,
  uni,
  n 
)

Definition at line 202 of file random_encounters.py.

203  def atLeastNInsignificantUnitsNear (self,uni, n):
204  num_ships=0
205  leadah = uni.getFlightgroupLeader ()
206  i = VS.getUnitList()
207  dd = self.cur.detection_distance
208  while i.notDone():
209  un = i.current()
210  if (uni.getSignificantDistance(un)<dd*1.6):
211  if ((not un.isSignificant()) and (not un.isSun())):
212  unleadah = un.getFlightgroupLeader ()
213  if (leadah!=unleadah):
214  num_ships+=1
215  i.advance()
216  return num_ships>=n
def CalculateSignificantDistance (   self)

Definition at line 93 of file random_encounters.py.

References debug.debug, random_encounters.det_distance, unit.minimumSigDistApart(), random_encounters.sig_distance, and random_encounters.sig_distance_table.

93 
95  sysfile = VS.getSystemFile()
96  self.cur.GeneratePhaseAndAmplitude()
97  if sysfile in self.sig_distance_table:
98  self.cur.significant_distance = self.sig_distance_table[sysfile][0]
99  self.cur.detection_distance = self.sig_distance_table[sysfile][1]
100  self.cur.prob_amplitude = self.sig_distance_table[sysfile][2]
101  return
102  minsig = unit.minimumSigDistApart()
103  if (self.sig_distance>minsig*0.15):
104  self.cur.significant_distance=minsig*0.15
105  else:
106  self.cur.significant_distance=self.sig_distance
107  if (self.det_distance>minsig*0.2):
108  self.cur.detection_distance=minsig*0.2
109  else:
110  self.cur.detection_distance=self.det_distance
111 
112  debug.debug("resetting sigdist=%f detdist=%f" % (self.cur.significant_distance,self.cur.detection_distance))
def decideMode (   self)

Definition at line 238 of file random_encounters.py.

References random_encounters.cur_player, debug.debug, random_encounters.DifferentSystemP(), random_encounters.SetModeOne(), and random_encounters.SetModeZero().

239  def decideMode(self):
240  myunit=VS.getPlayerX(self.cur_player)
241  if (not myunit):
242  self.SetModeZero()
243  return myunit
244  significant_unit = self.cur.sig_container
245 # un=VS.getUnit(0);
246 # i=0
247 # while (un):
248 # debug.debug(un.getName())
249 # i+=1
250 # un= VS.getUnit(i)
251 
252  if (not significant_unit):
253  un=VS.getUnit(self.cur.last_ship)
254  if (self.DifferentSystemP()):
255  un.setNull()
256  if (not un):
257  self.SetModeZero()
258  else:
259  sd = self.cur.significant_distance
260  if ((un.getSignificantDistance(myunit)<sd) and (un.isSignificant())):
261  self.SetModeOne (un)
262  return un
263  self.cur.last_ship+=1
264  return VS.Unit()
265  else:
266  #significant_unit is something.... lets see what it is
267  cursys = VS.getSystemFile()
268  if (self.DifferentSystemP()):
269  debug.debug("different")
270  self.SetModeZero()
271  significant_unit.setNull ()
272  else:
273  dd = self.cur.detection_distance
274  if (myunit.getSignificantDistance (significant_unit)>dd):
275  self.SetModeZero ()
276  return VS.Unit()
277  else:
278  return significant_unit
return significant_unit
def DifferentSystemP (   self)

Definition at line 279 of file random_encounters.py.

References random_encounters.NewSystemHousekeeping().

280  def DifferentSystemP(self):
281  cursys=VS.getSystemFile()
282  if (cursys==self.cur.lastsys):
283  return 0
284  self.NewSystemHousekeeping(self.cur.lastsys,cursys)
285  self.cur.lastsys=cursys
return 1
def Execute (   self)

Definition at line 286 of file random_encounters.py.

References random_encounters.AddPlayer(), random_encounters.cur_player, generate_dyn_universe.KeepUniverseGenerated(), random_encounters.players, Campaign.players, and dynamic_battle.UpdateCombatTurn().

287  def Execute(self):
290  if (self.cur_player>=len(self.players)):
291  self.AddPlayer()
292  self.cur=self.players[self.cur_player]
293  if (self.cur.curquest<len(self.cur.quests)):
294  if (self.cur.quests[self.cur.curquest].Execute()):
295  self.cur.curquest+=1
296  else:
297  del self.cur.quests[self.cur.curquest]
298  else:
299  self.cur.curquest=0
300  un = self.decideMode ()
301  if (self.cur.curmode!=self.cur.lastmode):
302  #lastmode=curmode#processed this event don't process again if in critical zone
303  if ((self.spawning or (vsrandom.random()<(self.fighterprob*self.cur.UpdatePhaseAndAmplitude()))) and un):
304  debug.debug("curmodechange %d in progress" % (self.cur.curmode))
305  if (VS.vsConfig("physics","spawn_units_close","false")=="true" and not self.atLeastNInsignificantUnitsNear (un,self.min_num_ships)):
306  #determine whether to launch more ships next to significant thing based on ships in that range
307  debug.debug("launch near")
308  self.launch_near (VS.getPlayerX(self.cur_player))
309  self.spawning=1
310  else:
311  self.cur.lastmode=self.cur.curmode
312  self.spawning=0
313  debug.debug("curmodechange %d ended" % (self.cur.curmode))
314  else:
315  self.cur.lastmode=self.cur.curmode
316  self.spawning=0
317  debug.debug("curmodechange %d ended" % (self.cur.curmode))
318  self.cur_player+=1
319  if (self.cur_player>=VS.getNumPlayers()):
320  self.cur_player=0
321  VS.setMissionOwner(self.cur_player)
322 
323 debug.debug("done loading rand enc")
def launch_near (   self,
  un,
  forceLaunch = False 
)

Definition at line 137 of file random_encounters.py.

References debug.debug, faction_ships.getMaxFactions(), and random_encounters.probability_cache.

138  def launch_near(self,un, forceLaunch=False):
139  if (VS.GetGameTime()<10 and not forceLaunch):
140  debug.debug("hola!")
141  return
cursys=VS.getSystemFile()
def NewSystemHousekeeping (   self,
  oldsystem,
  newsystem 
)

Definition at line 72 of file random_encounters.py.

References ShowProgress.activateProgressScreen(), random_encounters.CalculateSignificantDistance(), random_encounters.cur_player, ShowProgress.deactivateProgressScreen(), fg_util.launchBases(), fg_util.launchUnits(), news.newNews(), and random_encounters.RestoreDroneMission().

72 
73  def NewSystemHousekeeping(self,oldsystem,newsystem):
74  print oldsystem,' IS NOW AT ',newsystem
75  print oldsystem.split('/')[0]
76  if oldsystem.split('/')[0]=='Special':
77  print 'Showing splash screen!'
79  fg_util.launchBases(newsystem)
80  fg_util.launchUnits(newsystem)
81  news.newNews()
82  newquest = adventure.newAdventure (self.cur_player,oldsystem,newsystem)
83  if (newquest):
84  self.cur.quests+=[newquest]
85  else:
86  self.RestoreDroneMission()
VS.hideSplashScreen()
def RestoreDroneMission (   self)

Definition at line 89 of file random_encounters.py.

References random_encounters.cur_player.

89 
90  def RestoreDroneMission(self):
91  qdf=adventure.persistentAdventure (self.cur_player)
92  if (qdf):
self.cur.quests+=[qdf]
def SetEnemyProb (   self,
  enp 
)

Definition at line 113 of file random_encounters.py.

References random_encounters.enprob.

114  def SetEnemyProb (self,enp):
115  self.enprob = enp
116 
def SetModeOne (   self,
  significant 
)

Definition at line 224 of file random_encounters.py.

References random_encounters.NewSystemHousekeeping().

225  def SetModeOne (self,significant):
226  self.cur.last_ship=0
227  self.cur.curmode=1
228  self.cur.sig_container=significant
229  cursys = VS.getSystemFile()
230  oldsys = self.cur.lastsys==cursys
231  if (not oldsys):
232  self.NewSystemHousekeeping(self.cur.lastsys,cursys)
233  self.cur.lastsys=cursys
234  for q in self.cur.quests:
235  q.SignificantsNear(self.cur.sig_container)
236 # import dynamic_battle
237 # dynamic_battle.UpdateCombatTurn()
def SetModeZero (   self)

Definition at line 217 of file random_encounters.py.

218  def SetModeZero(self):
219  self.cur.last_ship=0
220  self.cur.curmode=0
221  self.cur.sig_container.setNull()
222  for q in self.cur.quests:
223  q.NoSignificantsNear()
def TrueEnProb (   self,
  enprob 
)

Definition at line 128 of file random_encounters.py.

References debug.debug.

129  def TrueEnProb(self,enprob):
130  ret=1
131  nam = VS.numActiveMissions()
132  while (nam>0):
133  ret*=(1-enprob)
134  nam-=1
135  debug.debug(1-ret)
136  return 1-ret;

Field Documentation

tuple avg = float(num)
static

Definition at line 169 of file random_encounters.py.

capship_gen_distance

Definition at line 49 of file random_encounters.py.

capship_prob

Definition at line 60 of file random_encounters.py.

cur

Definition at line 291 of file random_encounters.py.

cur_player

Definition at line 61 of file random_encounters.py.

det_distance

Definition at line 54 of file random_encounters.py.

enprob

Definition at line 51 of file random_encounters.py.

tuple faction = faction_ships.intToFaction(factionnum)
static

Definition at line 163 of file random_encounters.py.

tuple fglist = fg_util.FGsInSystem(faction,cursys)
static

Definition at line 189 of file random_encounters.py.

fighterprob

Definition at line 52 of file random_encounters.py.

list flightgroup = fglist[vsrandom.randrange(len(fglist))]
static

Definition at line 191 of file random_encounters.py.

list foretress_level = faction_ships.fortress_systems[cursys]
static

Definition at line 172 of file random_encounters.py.

int fortress_level = 0
static

Definition at line 170 of file random_encounters.py.

gen_num_ships

Definition at line 59 of file random_encounters.py.

generation_distance

Definition at line 57 of file random_encounters.py.

min_num_ships

Definition at line 58 of file random_encounters.py.

tuple num = fg_util.NumFactionFGsInSystem(faction,cursys)
static

Definition at line 164 of file random_encounters.py.

int p = 0
static

Definition at line 183 of file random_encounters.py.

players

Definition at line 56 of file random_encounters.py.

probability_cache

Definition at line 65 of file random_encounters.py.

list probs = []
static

Definition at line 161 of file random_encounters.py.

int psum = 0
static

Definition at line 160 of file random_encounters.py.

tuple rnd = vsrandom.random()
static

Definition at line 182 of file random_encounters.py.

sig_distance

Definition at line 55 of file random_encounters.py.

sig_distance_table

Definition at line 62 of file random_encounters.py.

spawning

Definition at line 63 of file random_encounters.py.

tuple typenumbers = fg_util.GetShipsInFG(flightgroup,faction)
static

Definition at line 192 of file random_encounters.py.


The documentation for this class was generated from the following file: