Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
plunder.py
Go to the documentation of this file.
1 from go_somewhere_significant import go_somewhere_significant
2 import vsrandom
3 import universe
4 import launch
5 import faction_ships
6 import Director
7 import unit
8 import quest
9 import VS
10 
11 class plunder (Director.Mission):
12 
13  def __init__ (self, creds, faction, quantity, category, returntobase, var_when_done=''):
14  Director.Mission.__init__ (self)
15  self.newship=""
16  self.mplay="all"
17  self.obj=0
18  self.enemy=VS.Unit()
19  self.curiter=0
20  self.content=""
21  self.quantity=quantity
22  self.arrived=0
23  self.faction = faction
24  self.cred=creds
25  self.category=category
26  self.donevar=var_when_done
27  sysfile = VS.getSystemFile()
29  self.you=VS.getPlayer()
30  self.pos=self.you.Position()
31  self.gosig=go_somewhere_significant(self.you,0,10000.)
33  if (self.you):
34  VS.IOmessage (0,"plunder mission",self.mplay,"Your mission is to destroy a %s merchant unit." % (self.newship))
35  VS.IOmessage (1,"plunder mission",self.mplay,"It is orbiting around the %s planet in the system." % (unit.getUnitFullName(self.gosig.SignificantUnit())))
36  VS.IOmessage (2,"plunder mission",self.mplay,"After it is destroyed, pick up all %s cargo that got ejected."%self.category)
37  VS.IOmessage (3,"plunder mission",self.mplay,"Then return to a %s base with your cargo. #00ff00Good luck!"%self.faction)
38  else:
39  print "aboritng plunder constructor..."
40  VS.terminateMission (0)
41 
42  def Win (self,un,terminate):
43  VS.IOmessage (0,"plunder mission",self.mplay,"#00ff00Excellent work pilot.")
44  VS.IOmessage (0,"plunder mission",self.mplay,"#00ff00You have been rewarded for your effort as agreed.")
45  VS.IOmessage (0,"plunder mission",self.mplay,"#00ff00Your contribution to the war effort will be remembered.")
46  print "do you win?"
47  un.addCredits(self.cred)
48  if len(self.donevar):
49  quest.removeQuest(self.you.isPlayerStarship(),self.donevar,1)
50  if (terminate):
51  print "you win plunder mission!"
52  VS.terminateMission(1)
53 
54  def Lose (self,terminate):
55  VS.IOmessage(0,"plunder mission",self.mplay,"#ff0000You have failed this mission and will not be rewarded.")
56  if len(self.donevar):
57  quest.removeQuest(int(self.mplay[1:]),self.donevar,-1)
58  if (terminate):
59  print "lose plunder mission"
60  VS.terminateMission(0)
61 
62  def Execute (self):
63  isSig=0
64  if (self.you.isNull()):
65  self.Lose (1)
66  return
67  if (self.arrived==3):
68  self.gosig.Execute()
69  cargquant=self.you.GetCargo(self.content).GetQuantity()
70  if cargquant<self.quantity:
71 # print "ohnooohnoohno!!!!!!!"
72  VS.IOmessage(0,"plunder mission",self.mplay,'Not enough of %s cargo... Get more until you have %d.'%(self.quantity))
73  VS.setCompleteness(self.obj,0.)
74  elif self.you.isDocked(self.gosig.SignificantUnit()) or self.gosig.SignificantUnit().isDocked(self.you):
75 # print "du hast gewonnen!"
76  self.you.removeCargo(self.content,self.quantity,1)
77  self.Win(self.you,1)
78 # else:
79 # print 'hihohohiho'
80  elif (self.arrived==2):
81  cargquant=self.you.GetCargo(self.content).GetQuantity()
82  VS.setCompleteness(self.obj,float(cargquant)/float(self.quantity))
83  if cargquant==self.quantity:
84  self.arrived=3
85  self.gosig=go_somewhere_significant(self.you,1,3000.,1,"pirates")
86  self.gosig.SignificantUnit().setCombatRole("INERT")
87  VS.IOmessage(0,"plunder mission",self.mplay,'Give all of your cargo to the %s unit.'%(unit.getUnitFullName(self.gosig.SignificantUnit())))
88  elif (self.arrived==1):
89  if (self.enemy):
90  self.pos=self.enemy.Position()
91  curun=VS.getUnit(self.curiter)
92  self.curiter+=1
93  if (curun==self.enemy):
94  self.enemy.SetTarget(self.you)
95  elif (curun.isNull()):
96  self.curiter=0
97  if (self.enemy.isNull()):
98  VS.setCompleteness(self.obj,1.)
99  self.arrived=2
100  self.enemy=[]
101  for i in range(self.quantity*2):
102  launch.launch_wave_around_area("shadow","upgrades","generic_cargo","sitting_duck",1,5.,10.,self.pos,'',0).setName(self.content)
103  self.obj=VS.addObjective("Pick up %d %s cargo"%(self.quantity,self.content))
104  VS.IOmessage(0,"plunder mission",self.mplay,'You must now pick up at least %d of the %s cargo.'%(self.quantity,self.content))
105  else:
106  significant=self.gosig.SignificantUnit()
107  if (significant.isNull ()):
108  print "sig null"
109  VS.terminateMission(0)
110  return
111  else:
112  if (self.you.getSignificantDistance(significant)<10000.0):
113  if (self.newship==""):
114  self.newship=faction_ships.getRandomFighter('merchant')
115  carg=VS.getRandCargo(self.quantity,self.category)
116  if (carg.GetQuantity()==0):
117  carg = VS.getRandCargo(self.quantity,"") #oh no... could be starships...
118  self.content=carg.GetContent()
119  carg.SetQuantity(self.quantity*2)
120  self.enemy=launch.launch_wave_around_unit("shadow","merchant",self.newship,"default",1,200.0,500.0,self.you)
121  self.enemy.addCargo(carg)
122  VS.setCompleteness(self.gosig.obj,1.)
123  VS.IOmessage(0,"plunder mission",self.mplay,'You must now destroy the %s ship.'%self.newship)
124  VS.IOmessage(0,"plunder mission",self.mplay,'That fighter contains the wanted %s cargo in its hold.'%self.content)
125  self.obj=VS.addObjective("Destroy the %s ship." % (unit.getUnitFullName(self.enemy)))
126  if (self.enemy):
127  self.arrived=1
128  else:
129  print "enemy null"
130  VS.terminateMission(0)
131  return
132 
133  def initbriefing(self):
134  print "ending briefing"
135 
136  def loopbriefing(self):
137  print "loop briefing"
138  Briefing.terminate();
139 
140  def endbriefing(self):
141  print "ending briefing"
142 
143 
144 ##def initrandom (minns, maxns, credsmin, credsmax, run_away, minshipdifficulty, maxshipdifficulty):
145 ## you=VS.getPlayer()
146 ## tempfaction
147 ## if (you):
148 ## name = you.getFaction ()
149 ## factionname=vsrandom.randrange(0,faction_ships.getMaxFactions())
150 ## tempfaction=faction_ships.intToFaction(factionname)
151 ## i=0
152 ## while (name==tempfaction and i<10):
153 ## factionname=vsrandom.randrange(0,faction_ships.getMaxFactions())
154 ## tempfaction=faction_ships.intToFaction(factionname)
155 ## i+=1
156 ## sd = vsrandom.random()*(maxshipdifficulty-minshipdifficulty)+minshipdifficulty
157 ## return bounty (minns,maxns,(1.0+(sd*0.5))*(vsrandom.random ()*(credsmax-credsmin)+credsmin),run_away,sd,tempfaction)
158 ## else:
159 ## print "aborting bounty initrandom"
160 ## VS.terminateMission(0)