Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
quest_intro.py
Go to the documentation of this file.
1 import quest
2 import VS
3 import fixers
4 from fixers import Conversation, Node, RootNode, SubNode
5 import Director
6 
7 TRIGGER_SAVE = "IntroJP"
8 TRIGGER_VALUE = 1
9 TRIGGER_MESSAGE = ["[Reminder]","Jenek on Wiley may have a jump drive going cheap."]
10 
11 DEFAULT_VALUE = 0
12 REFUSED_VALUE = 2
13 DONE_VALUE = 3
14 
15 JP_DRV_PRICE = 7000
16 
17 DRV_SUCCESS = 1
18 DRV_FAIL = 2
19 
20 JP_DISTANCE = 10000
21 
22 FIXER_NAME = "IntroFixer"
23 FIXER_TEXT = "#\nimport quest_intro\nconversation = quest_intro.getJenekConversation()"
24 
26  def __init__ (self):
27  quest.quest_factory.__init__ (self,"quest_introduction")
28  def create (self):
29  return quest_introduction()
30 
32 
33  def __init__(self):
34  self.playa = VS.getPlayer()
35  self.jps = list()
36  self.refreshJumpPoints()
37  Director.eraseSaveData(self.playa.isPlayerStarship(),TRIGGER_SAVE,0)
38  Director.pushSaveData(self.playa.isPlayerStarship(),TRIGGER_SAVE,DEFAULT_VALUE)
39 #I work on the assumption that only one value exists in the TRIGGER_SAVE var,
40 # thus before writing to it, you must delete the first value :-)
41 
42  def refreshJumpPoints(self):
43  """Updates the jumppoint list \'self.jps\' used by \'self.checkDistances()\'."""
44  self.jps = list()
45 #This is how to use the unit iterator. *Very useful*
46  iter = VS.getUnitList()
47  while iter.notDone():
48  if iter.current().isJumppoint():
49  self.jps.append(iter.current())
50  iter.advance()
51 
52  def checkDistances(self):
53  """Determines whether \'self.playa\' (the player) is close enough to
54  a jumppoint to trigger the IOMessage."""
55 #You will find yourself doing this a lot :-)
56  for jp in self.jps:
57  if self.playa.getDistance(jp) <= JP_DISTANCE:
58  return 1
59  return 0
60 
61  def Execute(self):
62  if self.checkDistances() and quest.checkSaveValue(self.playa.isPlayerStarship(),TRIGGER_SAVE,DEFAULT_VALUE):
63  VS.IOmessage (0,TRIGGER_MESSAGE[0],"all",TRIGGER_MESSAGE[1])
64  Director.eraseSaveData(self.playa.isPlayerStarship(),TRIGGER_SAVE,0)
65  Director.pushSaveData(self.playa.isPlayerStarship(),TRIGGER_SAVE,TRIGGER_VALUE)
66  elif quest.checkSaveValue(self.playa.isPlayerStarship(),TRIGGER_SAVE,DONE_VALUE):
67  Director.eraseSaveData(self.playa.isPlayerStarship(),TRIGGER_SAVE,0)
68  fixers.eraseCFixer(self.playa.isPlayerStarship(), FIXER_NAME)
69  self.removeQuest()
70 #You only want to remove the quest once the fixer has finished doing his thing :-)
71  return 0
72  return 1
73 
74 
75 def buyDrive():
76  if haveDrive():
77  return DRV_FAIL
78  elif VS.getPlayer().getCredits()>=JP_DRV_PRICE:
79 #deducts the required sum
80  VS.getPlayer().addCredits(-JP_DRV_PRICE)
81 #adds the jumpdrive temporarily (will be removed if player upgrades)
82  VS.getPlayer().upgrade("jump_drive",0,0,1,0)
83 #adds the jumpdrive to cargo, making it a permenant upgrade
84  VS.getPlayer().addCargo(VS.GetMasterPartList().GetCargo("jump_drive"))
85  print "TEST: Bought Jump Drive"
86  Director.eraseSaveData(VS.getPlayer().isPlayerStarship(),TRIGGER_SAVE,0)
87  Director.pushSaveData(VS.getPlayer().isPlayerStarship(),TRIGGER_SAVE,DONE_VALUE)
88  return DRV_SUCCESS
89  return 0
90 
91 def haveDrive():
92  """Does the player already have a jumpdrive?"""
93  if VS.getPlayer().GetJumpStatus()>-2:
94 # when -2 is returned by GetJumpStatus, the player doesn't have a jumpdrive
95  print "TEST: You have a jump drive already!"
96  return 1
97  return 0
98 
100  """Checks if the player is docked to the right planet, and the fixer is still \'around\'."""
101  if not quest.checkSaveValue(VS.getPlayer().isPlayerStarship(),TRIGGER_SAVE,DONE_VALUE):
102  iter = VS.getUnitList()
103  while iter.notDone():
104  if iter.current().isPlanet() and (VS.getPlayer().isDocked(iter.current()) or iter.current().isDocked(VS.getPlayer())):
105 #Not sure why both have to be checked, it seems to second gives a more consistantly correct response
106  return iter.current().getName() == 'Wiley'
107  iter.advance()
108  return 0
109 
111  """Returns the conversation object for the Jenek fixer."""
112  con = Conversation(FIXER_NAME, ['#\nimport quest_intro\nresult = quest_intro.okayDrawJenek()'])
113 
114  roo = RootNode()
115  roo.addSubNode(SubNode( "knownjenek",
116  [str(TRIGGER_SAVE) + '#' + str(TRIGGER_VALUE)],
117  ["#\nimport quest_intro\nquest_intro.interactWithJenek(\"jenek\")"],
118  "bases/fixers/merchant.spr",
119  "Talk to Jenek about the jump drive." ))
120  roo.addSubNode(SubNode( "unknownjenek",
121  list(),
122  ["#\nimport quest_intro\nquest_intro.interactWithJenek(\"jenek\")"],
123  "bases/fixers/merchant.spr",
124  "Talk to Jenek." ))
125  con.addNode(roo)
126 
127  jen = Node()
128  jen.addSubNode(SubNode( "Ahh, that's right. You're here about the jump drive!",
129  [str(TRIGGER_SAVE) + '#' + str(TRIGGER_VALUE)],
130  ["bases/fixers/no.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"nojump\")|Sorry, what else do you have?",
131  "bases/fixers/yes.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"yesjump\")|Yeah, I'm interested."],
132  "bases/fixers/merchant.spr",
133  "Talk to Jenek about the jump drive." ))
134  jen.addSubNode(SubNode( "So you're interested in the jump drive now?",
135  [str(TRIGGER_SAVE) + '#' + str(REFUSED_VALUE)],
136  ["bases/fixers/no.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"nojump\")|Sorry.",
137  "bases/fixers/yes.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"yesjump\")|Yeah, I'm interested."],
138  "bases/fixers/merchant.spr",
139  "Talk to Jenek about the jump drive." ))
140  jen.addSubNode(SubNode( "Well, what are you waiting for? Go and give it a spin!",
141  ["#\nimport quest_intro\nresult = quest_intro.haveDrive()"] ))
142  jen.addSubNode(SubNode( "You're back! Quite a party that was the other night, if it wasn't for my reminder I would have forgotten you! You still interested in that jump drive I've got?",
143  list(),
144  ["bases/fixers/no.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"forgetjump\")|Sorry, I have no idea what you are talking about!",
145  "bases/fixers/yes.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"yesjump\")|I completely forgot myself! Of course I'm interested."],
146  "bases/fixers/merchant.spr",
147  "Talk to Jenek." ))
148  con.addNode(jen,"jenek")
149 
150  forg = Node()
151  forg.addSubNode(SubNode( "Well, I can't say I'm surprised ... not with the amount of Tripezian Premium you downed! Anyway, I've come across a few \'spare\' jump drives, and your ship, last you spoke about it, was one short. Are you still as interested as you were then?",
152  list(),
153  ["bases/fixers/no.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"nojump\")|Sorry, don't suppose you've got anything else?",
154  "bases/fixers/yes.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"yesjump\")|Yeah, I'm interested."] ))
155  con.addNode(forg, "forgetjump")
156 
157  yes = Node()
158  yes.addSubNode(SubNode( "Great! I can let you have one for just %s. Do you want it now?"%str(JP_DRV_PRICE),
159  list(),
160  ["bases/fixers/no.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"rejectdrive\")|Maybe later.",
161  "bases/fixers/yes.spr|#\nimport quest_intro\nquest_intro.interactWithJenek(\"takedrive\")|Okay."] ))
162  con.addNode(yes, "yesjump")
163 
164  no = Node()
165  no.addSubNode(SubNode( "If it's not about the jump drive I don't have the time. Come back later." ))
166  con.addNode(no, "nojump")
167 
168  tak = Node()
169  tak.addSubNode(SubNode( "I'll send some mechanics to fit it for you now. Nice to see you again!",
170  ["#\nimport quest_intro\nresult = quest_intro.buyDrive()==%s"%str(DRV_SUCCESS)] ))
171  tak.addSubNode(SubNode( "You idiot, you already have a jumpdrive!",
172  ["#\nimport quest_intro\nresult = quest_intro.buyDrive()==%s"%str(DRV_FAIL)] ))
173  tak.addSubNode(SubNode( "Sorry, it looks like your account is a little dry. Come back when you've got %s credit."%str(JP_DRV_PRICE) ))
174  con.addNode(tak, "takedrive")
175 
176  rej = Node()
177  rej.addSubNode(SubNode( "Fine. I may not be around for much longer though." ))
178  con.addNode(rej, "rejectdrive")
179 
180  return con
181 
182 def interactWithJenek(ref="Root"):
183  """Iterates the conversation, allowing for extra events to be launched
184  during the conversation."""
185  if ref == "nojump" or ref == "rejectdrive":
186  Director.eraseSaveData(VS.getPlayer().isPlayerStarship(),TRIGGER_SAVE,0)
187  Director.pushSaveData(VS.getPlayer().isPlayerStarship(),TRIGGER_SAVE,REFUSED_VALUE)
188  getJenekConversation().iterate(ref)