Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
bounty.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import universe
3 from go_to_adjacent_systems import go_to_adjacent_systems
4 from go_somewhere_significant import go_somewhere_significant
5 import vsrandom
6 import Vector
7 import launch
8 import faction_ships
9 import Director
10 import Briefing
11 import unit
12 import VS
13 import quest
14 
15 class bounty (Director.Mission):
16  def SetVar (self,val):
17  if (self.var_to_set!=''):
18  quest.removeQuest (self.you.isPlayerStarship(),self.var_to_set,val)
19 
20  def __init__ (self,minnumsystemsaway, maxnumsystemsaway, creds, run_away, shipdifficulty, tempfaction,jumps=(),var_to_set='',dynfg='',dyntype="",displayLocation=1,greetingText=['It appears we have something in common, privateer.','My name may be on your list, but now your name is on mine.'],dockable_unit=False):
21  Director.Mission.__init__ (self)
22  self.firsttime=VS.GetGameTime()
23  self.newship=dyntype
24  self.dynfg=dynfg
25  self.mplay="all"
26  self.var_to_set = var_to_set
27  self.istarget=0
28  self.obj=0
29  self.curiter=0
30  self.arrived=0
31  self.faction = tempfaction
32  self.difficulty = shipdifficulty
33  self.runaway=run_away
34  self.greetingText=greetingText
35  self.cred=creds
36  mysys=VS.getSystemFile()
37  sysfile = VS.getSystemFile()
38  self.you=VS.getPlayer()
39  self.enemy=VS.Unit()
40  self.adjsys=go_to_adjacent_systems (self.you,vsrandom.randrange(minnumsystemsaway,maxnumsystemsaway+1),jumps)
41  self.dockable_unit=dockable_unit
43  self.displayLocation=displayLocation
44  if (self.you):
45  VS.IOmessage (0,"bounty mission",self.mplay,"[Computer] Bounty Mission Objective: (%.2f Credits)" % self.cred)
46  self.adjsys.Print("From %s system","Procede to %s","Search for target at %s, your final destination","bounty mission",1)
47  VS.IOmessage (1,"bounty mission",self.mplay,"Target is a %s unit." % (self.faction))
48  else:
49  print "aboritng bounty constructor..."
50  VS.terminateMission (0)
51 
52  def AdjLocation(self):
53  print "ADJUSTING LOC"
54  self.enemy.SetPosition(Vector.Add(self.enemy.LocalPosition(),Vector.Scale(self.enemy.GetVelocity(),-40))) #eta 20 sec
55 
56  def Win (self,un,terminate):
57  self.SetVar(1)
58  VS.IOmessage (0,"bounty mission",self.mplay,"[Computer] #00ff00Bounty Mission Accomplished!")
59  un.addCredits(self.cred)
60  if (terminate):
61  print "you win bounty mission!"
62  VS.terminateMission(1)
63 
64  def Lose (self,terminate):
65  VS.IOmessage(0,"bounty mission",self.mplay,"[Computer] #ff0000Bounty Mission Failed.")
66  self.SetVar(-1)
67  if (terminate):
68  print "lose bounty mission"
69  VS.terminateMission(0)
70 
71  def LaunchedEnemies(self,significant):
72  pass
73 
74  def Execute (self):
75  isSig=0
76  if (self.you.isNull()):
77  self.Lose (1)
78  return
79  if (self.arrived==2):
80  if (not self.runaway):
81  if (not self.istarget):
82  if (self.enemy):
83  curun=VS.getUnit(self.curiter)
84  self.curiter+=1
85  if (curun==self.enemy):
86  self.enemy.SetTarget(self.you)
87  elif (curun.isNull()):
88  self.curiter=0
89  else:
90  if (VS.GetGameTime()>self.firsttime+2.5 and self.enemy):
91  self.firsttime+=1000000
92  self.AdjLocation()
93  if (self.enemy.isNull()):
94  self.Win(self.you,1)
95  return
96  elif (self.arrived==1):
97  significant=self.adjsys.SignificantUnit()
98  if (significant.isNull ()):
99  print "sig null"
100  VS.terminateMission(0)
101  return
102  else:
103  if (self.you.getSignificantDistance(significant)<self.adjsys.distfrombase):
104  if (self.newship==""):
105  self.newship=faction_ships.getRandomFighter(self.faction)
106  #self.enemy=launch.launch_wave_around_unit("Shadow",self.faction,self.newship,"default",1+self.difficulty,3000.0,4000.0,significant)
107  L = launch.Launch()
108  L.fg="Shadow"
109  L.dynfg=self.dynfg
110  L.type = self.newship
111  L.faction = self.faction
112  L.ai = "default"
113  L.num=1+self.difficulty
114  L.minradius=3000.0
115  L.maxradius = 4000.0
116  try:
117  L.minradius*=faction_ships.launch_distance_factor
118  L.maxradius*=faction_ships.launch_distance_factor
119  except:
120  pass
121  self.enemy=L.launch(significant)
122  self.enemy.SetTarget(self.you)
123  self.enemy.setFgDirective('B.')
124  self.you.SetTarget(self.enemy)
125  universe.greet(self.greetingText,self.enemy,self.you)
126  str_faction = self.faction.split('_')[0]
127  quest.playSoundCockpit('sounds/missions/' + str_faction + '_it-appears-we-have.ogg')
128  self.obj=VS.addObjective("Destroy %s." % (unit.getUnitFullName(self.enemy)))
129  if (self.enemy):
130  if (self.runaway):
131  self.enemy.SetTarget(significant) #CHANGE TO SetTarget ==>NOT setTarget<==
132  self.enemy.ActivateJumpDrive(0)
133  self.firsttime=VS.GetGameTime()
134  #self.enemy.SetPosAndCumPos(Vector.Add(self.you.Position(),Vector.Vector(0,0,self.you.rSize()*1.2)))
135  self.LaunchedEnemies(significant)
136  self.arrived=2
137  else:
138  print "enemy null"
139  VS.terminateMission(0)
140  return
141  else:
142  if (self.adjsys.Execute()):
143  self.arrived=1
144  if (self.newship=="" and self.dynfg==''):
145  self.newship=faction_ships.getRandomFighter(self.faction)
146  self.adjsys=go_somewhere_significant(self.you,self.dockable_unit,10000.0,0,'','',self.displayLocation)
147  if not self.displayLocation:
148  VS.addObjective("Search/Destroy "+self.faction.capitalize()+" mark");
149  localdestination=unit.getUnitFullName(self.adjsys.SignificantUnit(),True)
150  tmpfg=self.dynfg
151  if len(tmpfg)==0:
152  tmpfg="shadow"
153  VS.IOmessage (3,"bounty mission",self.mplay,"Hunt the %s unit in the %s flightgroup in this system." % (self.newship,tmpfg))
154  if (self.runaway): #ADD OTHER JUMPING IF STATEMENT CODE HERE
155  VS.IOmessage (4,"bounty mission",self.mplay,"Target is fleeing to the jump point!")
156  VS.IOmessage (5,"bounty mission",self.mplay,"Target Destination appears to be %s" % (localdestination))
157  elif (self.displayLocation):
158  VS.IOmessage (4,"bounty mission",self.mplay,"Scanners detect bounty target!")
159  VS.IOmessage (5,"bounty mission",self.mplay,"Coordinates appear near %s" % (localdestination))
160  else:
161  print "Location "+str(self.displayLocation)
162  VS.IOmessage (4,"bounty mission",self.mplay,"[Computer] Mission description indicates bounty target may be in this system.")
163 
164  def initbriefing(self):
165  print "ending briefing"
166 
167  def loopbriefing(self):
168  print "loop briefing"
169  Briefing.terminate();
170 
171  def endbriefing(self):
172  print "ending briefing"
173 
174 def initrandom (minns, maxns, credsmin, credsmax, run_away, minshipdifficulty, maxshipdifficulty,jumps=(),var_to_set=''):
175  you=VS.getPlayer()
176  tempfaction='aera'
177  if (you):
178  name = you.getFactionName ()
180  tempfaction=faction_ships.intToFaction(factionname)
181  i=0
182  while ((name==tempfaction or name=="unknown") and i<10):
184  tempfaction=faction_ships.intToFaction(factionname)
185  i+=1
186  sd = vsrandom.random()*(maxshipdifficulty-minshipdifficulty)+minshipdifficulty
187  return bounty (minns,maxns,(1.0+(sd*0.5))*(vsrandom.random ()*(credsmax-credsmin)+credsmin),run_away,sd,tempfaction,jumps,var_to_set)
188  else:
189  print "aborting bounty initrandom"
190  VS.terminateMission(0)