Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
cargo_mission.py
Go to the documentation of this file.
1 from go_to_adjacent_systems import *
2 from go_somewhere_significant import *
3 import vsrandom
4 import launch
5 import faction_ships
6 import VS
7 import Briefing
8 import universe
9 import unit
10 import Director
11 import quest
12 import debug
13 class cargo_mission (Director.Mission):
14  def initbriefing(self):
15  VS.IOmessage (0,"cargo mission","briefing","Your mission for today will be to run some %s cargo" % self.cargoname)
16  self.briefgametime = 0
17  self.adjsys.initbriefing()
18 
19 
20  def loopbriefing(self):
21  brief_you=self.adjsys.loopbriefing()
22  if (brief_you != -1):
23  VS.IOmessage(0,"cargo mission","briefing","Once there, you must drop the cargo off at a specified unit")
24  if (self.briefgametime==0):
25  self.briefgametime = VS.GetGameTime()
26  elif ((VS.GetGameTime()-self.briefgametime)>5):
27  Briefing.terminate()
28  def endbriefing(self):
29  self.adjsys.endbriefing()
30  del self.briefgametime
31  def SetVar (self,val):
32  if (self.var_to_set!=''):
33  quest.removeQuest (self.you.isPlayerStarship(),self.var_to_set,val)
34 
35  def GetSomeCargo(self,category):
36  carg=VS.getRandCargo(self.quantity,category)
37  if (carg.GetQuantity()==0 or category==''):
38  carg = VS.getRandCargo(self.quantity,"") #oh no... could be starships...
39  i=0
40  while i<50 and (carg.GetCategory()[:10]=="Contraband" or carg.GetCategory()[:8]=="upgrades"):
41  debug.debug("contraband and upgrades==bad")
42  carg = VS.getRandCargo(self.quantity,"")
43  i+=1
44  self.cargoname=carg.GetContent()
45  carg.SetMissionFlag(1)
46  return carg
47 
48  def __init__ (self,factionname, numsystemsaway, cargoquantity, missiondifficulty, creds, launchoncapship, time_to_complete, category,jumps=(),var_to_set=''):
49  Director.Mission.__init__(self);
50  self.you=VS.Unit()
51  self.base=VS.Unit()
52  self.role="ESCORTCAP"
53  self.arrived=0
54  self.var_to_set=var_to_set
55  self.mplay="all"
56 # self.mission_time=VS.GetGameTime()+time_to_complete*100*float(1+numsystemsaway)
57  self.capship= launchoncapship
58  self.faction=factionname
59  self.cred=creds
60  self.difficulty=missiondifficulty
61  self.you=VS.getPlayer()
62  self.adjsys=go_to_adjacent_systems(self.you,numsystemsaway,jumps)
63  self.quantity=cargoquantity
65  if (self.quantity<1):
66  self.quantity=1
67  tempquantity=self.quantity
68  name = self.you.getName ()
69  if (not self.you.isNull()):
70  j=0
71  while j<15:
72  #if j>10:
73  # category = ''
74  carg = self.GetSomeCargo(category)
75  found=False
76  for i in range(self.you.numCargo()):
77  tmpcarg=self.you.GetCargoIndex(i)
78  if (tmpcarg.GetCategory()==category and tmpcarg.GetMissionFlag()) or self.cargoname==tmpcarg.GetContent():
79  print category, tmpcarg.GetCategory()
80  found=True
81  break
82  if not found:
83  newquantity = self.you.addCargo(carg) #I add some cargo
84  if newquantity>0:
85  print "It wasnt found %s"%self.cargoname
86  self.quantity=newquantity
87  break
88  if found and tmpcarg.GetMissionFlag(): #self.cargoname==tmpcarg.GetContent():
89  self.cargoname=tmpcarg.GetContent()
90  self.quantity=int(tmpcarg.GetQuantity())
91  tempquantity=self.quantity
92  print ("already have "+str(self.quantity)+" cargo of this kind "+self.cargoname)
93  break
94  # Else, let's look for another cargo of this kind
95  print ("already have "+str(int(tmpcarg.GetQuantity()))+" non-mission cargo of this kind "+self.cargoname)
96 
97  j+=1
98  else: # While loop's condition failed... i.e. j got too big.
99  if not category:
100  category='generic'
101  VS.IOmessage (2,"cargo mission",self.mplay,"#ff0000Unable to find suitable %s cargo that is not already loaded. Mission canceled."%category)
102  VS.terminateMission (0)
103  return
104  else:
105  VS.IOmessage (2,"cargo mission",self.mplay,"#ff0000Unable to establish communications. Mission failed.")
106  VS.terminateMission (0)
107  return
108 # creds_deducted = (carg.GetPrice()*float(self.quantity)*vsrandom.random()+1)
109 # self.cred += creds_deducted
110  if (tempquantity>0):
111  self.cred*=float(self.quantity)/float(tempquantity)
112  else:
113  VS.IOmessage (2,"cargo mission",self.mplay,"#ff0000You do not have space to add our %s cargo to your ship. Mission failed."%self.cargoname)
114  VS.terminateMission(0)
115  return
116 
117  if (self.quantity==0):
118  VS.IOmessage (2,"cargo mission",self.mplay,"#ff0000You do not have space to add our cargo to the mission. Mission failed.")
119  VS.terminateMission(0)
120  return
121 
122  VS.IOmessage (0,"cargo mission",self.mplay,"Your mission is as follows:" )
123  self.adjsys.Print("You should start in the system named %s","Then jump to %s","Finally, jump to %s, your final destination","cargo mission",1)
124  VS.IOmessage (2,"cargo mission",self.mplay,"Give the cargo to a %s unit or planet." % (self.faction))
125  VS.IOmessage (3,"cargo mission",self.mplay,"You will receive %d of the %s cargo" % (self.quantity,self.cargoname))
126 # VS.IOmessage (4,"cargo mission",self.mplay,"We will deduct %.2f credits from your account for the cargo needed." % (creds_deducted))
127  VS.IOmessage (4,"cargo mission",self.mplay,"You will earn %.2f credits when you deliver our cargo." % (creds))
128  VS.IOmessage (4,"cargo mission",self.mplay,"#00ff00Good luck!")
129 # self.you.addCredits (-creds_deducted)
130 
131  def takeCargoAndTerminate (self,you, remove):
132  removenum=0 #if you terminate without remove, you are SKREWED
133  self.base.setCombatRole(self.role)
134  if (remove):
135  removenum=you.removeCargo(self.cargoname,self.quantity,1)
136  debug.debug("removed %d" % removenum)
137  mpart=VS.GetMasterPartList()
138  newcarg=mpart.GetCargo(self.cargoname)
139  newcarg.SetQuantity(removenum)
140  #self.base.addCargo(newcarg)#not for resale
141  has=self.you.hasCargo(self.cargoname)
142  if (has):
143  has=self.you.removeCargo(self.cargoname,has,1)
144  newcarg.SetMissionFlag(0)
145  newcarg.SetQuantity(has)
146  self.you.addCargo(newcarg) #It seems that removing and then adding it again is the only way...
147  if ((removenum>=self.quantity) or (self.quantity==0) or removenum>=1):
148  VS.IOmessage (0,"cargo mission",self.mplay,"#00ff00Excellent work pilot.")
149  VS.IOmessage (0,"cargo mission",self.mplay,"#00ff00You have been rewarded for your effort as agreed.")
150  VS.IOmessage (0,"cargo mission",self.mplay,"#00ff00Your excellent work will be remembered.")
151  you.addCredits(self.cred)
152  VS.AdjustRelation(you.getFactionName(),self.faction,.01*self.difficulty,1)
153  self.SetVar(1)
154  VS.terminateMission(1)
155  return
156  else:
157  VS.IOmessage (0,"cargo mission",self.mplay,"#ff0000You did not follow through on your end of the deal.")
158  if (self.difficulty<1):
159  VS.IOmessage (0,"cargo mission",self.mplay,"#ff0000Your pay will be reduced")
160  VS.IOmessage (0,"cargo mission",self.mplay,"#ff0000And we will consider if we will accept you on future missions.")
161  addcred=(float(removenum)/(float(self.quantity*(1+self.difficulty))))*self.cred
162  you.addCredits(addcred)
163  else:
164  VS.IOmessage (0,"cargo mission",self.mplay,"#ff0000You will not be paid!")
165  universe.punish(self.you,self.faction,self.difficulty)
166  self.SetVar(-1)
167  VS.terminateMission(0)
168  return
169 
170 
171  def Execute (self):
172 ## if (VS.getGameTime()>mission_time):
173 ## VS.IOmessage (0,"cargo mission",self.mplay,"You Have failed to deliver your cargo in a timely manner.")
174 ## VS.IOmessage (0,"cargo mission",self.mplay,"The cargo is no longer of need to us.")
175 ## if (you):
176 ## takeCargoAndTerminate(you,0)
177 ## return
178  if (self.you.isNull() or (self.arrived and self.base.isNull())):
179  VS.IOmessage (0,"cargo mission",self.mplay,"#ff0000You were unable to deliver cargo. Mission failed.")
180  self.SetVar(-1)
181  VS.terminateMission(0)
182  return
183  if (not self.adjsys.Execute() and not (self.arrived and self.base and self.base.isDocked(self.you))):
184  return
185  if (self.arrived):
186  self.adjsys.Execute=self.adjsys.HaveArrived
187  if (self.base.isDocked(self.you)):
188  self.takeCargoAndTerminate(self.you,1)
189  return
190  else:
191  self.arrived=1
192  tempfac=self.faction
193  if vsrandom.random()<=.5:
194  tempfac=''
195  self.adjsys=go_somewhere_significant(self.you,1,100,not self.capship,tempfac)
196  capstr="planet"
197  dockstr="land"
198  if tempfac=='':
199  dockstr="dock"
200  capstr="ship"
201  self.adjsys.Print("You must visit the %%s %s" % (capstr),"cargo mission",", docked around the %s",0)
202  VS.IOmessage(0,"cargo mission",self.mplay,"Once there, %s and we will transport the cargo off of your ship." % (dockstr))
203  self.base=self.adjsys.SignificantUnit()
204  self.role=self.base.getCombatRole()
205  self.base.setCombatRole("INERT")
206 def initrandom (factionname, missiondifficulty,creds_per_jump, launchoncapship, sysmin, sysmax, time_to_complete, category,jumps=(),var_to_set=''):
207  numsys=vsrandom.randrange(sysmin,sysmax)
208  return cargo_mission(factionname,numsys, 15, missiondifficulty,creds_per_jump*float(1+numsys),launchoncapship, 10.0, category,jumps,var_to_set)
209 
210 
211 
212 
213 
214 
215 
216 
217