comparison gamelib/scenes/machine.py @ 854:3577c51029f1 default tip

Remove Suspended Sentence. pyntnclick is the library we extracted from it
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 21 Jun 2014 22:15:54 +0200
parents f95830b58336
children
comparison
equal deleted inserted replaced
853:f95830b58336 854:3577c51029f1
1 """Machine room where tools and machines are found."""
2
3 from pyntnclick.i18n import _
4 from pyntnclick.state import Scene, Item, Thing, Result
5 from pyntnclick.cursor import CursorSprite
6 from pyntnclick.scenewidgets import (
7 InteractNoImage, InteractImage, InteractAnimated, GenericDescThing,
8 TakeableThing)
9
10 from gamelib.scenes.game_widgets import Door
11
12
13 class Machine(Scene):
14
15 FOLDER = "machine"
16 BACKGROUND = "machine_room.png"
17
18 def setup(self):
19 self.add_thing(ToMap())
20 self.add_thing(LaserWelderSlot())
21 self.add_thing(LaserWelderButton())
22 self.add_thing(LaserWelderPowerLights())
23 self.add_thing(Grinder())
24 self.add_thing(ManualThing())
25 self.add_item_factory(TitaniumMachete)
26 self.add_item_factory(CryoPipesOne)
27 self.add_item_factory(CryoPipesTwo)
28 self.add_item_factory(CryoPipesThree)
29 self.add_item_factory(Manual)
30 self.add_thing(GenericDescThing('machine.wires', 2,
31 _("Wires run to all the machines in the room"),
32 (
33 (250, 172, 252, 12),
34 (388, 183, 114, 13),
35 (496, 112, 36, 64),
36 (533, 85, 19, 45),
37 (647, 114, 10, 308),
38 (111, 96, 13, 285),
39 (152, 106, 34, 30),
40 (189, 136, 27, 28),
41 (222, 157, 24, 25),
42 (120, 86, 34, 29),
43 (110, 80, 21, 15),
44 (383, 196, 12, 56),
45 (553, 61, 26, 50),
46 (574, 39, 16, 48),
47 (648, 85, 22, 26),
48 (674, 54, 23, 36),
49 )))
50 self.add_thing(GenericDescThing('machine.diagram', 3,
51 _("A wiring diagram of some sort"),
52 ((694, 140, 94, 185),)))
53 self.add_thing(GenericDescThing('machine.powerpoint', 4,
54 _("The cables to this power point have been cut"),
55 ((155, 22, 92, 74),)))
56 self.add_thing(GenericDescThing("machine.powerpoint", 5,
57 _("All the machines run off this powerpoint"),
58 ((593, 19, 74, 57),)))
59 self.add_thing(GenericDescThing("machine.drill_press", 6,
60 _("An impressive looking laser drill press"),
61 (
62 (519, 338, 36, 63),
63 (545, 348, 93, 46),
64 (599, 309, 41, 150),
65 (588, 445, 66, 42),
66 (616, 479, 41, 14),
67 (527, 393, 15, 17),
68 (510, 360, 13, 11),
69 (532, 331, 14, 11),
70 (605, 304, 26, 8),
71 )))
72 self.add_thing(GenericDescThing("machine.drill_press_block", 7,
73 _("The block for the laser drill press"),
74 ((461, 446, 38, 27),)))
75
76
77 class ToMap(Door):
78
79 SCENE = "machine"
80
81 INTERACTS = {
82 "door": InteractNoImage(695, 350, 97, 212),
83 }
84
85 INITIAL = "door"
86
87
88 class LaserWelderSlot(Thing):
89
90 NAME = "machine.welder.slot"
91
92 INTERACTS = {
93 "empty": InteractImage(241, 310, "welder_empty.png"),
94 "can": InteractImage(241, 310, "welder_can.png"),
95 "tube": InteractImage(241, 310, "welder_pipe.png"),
96 "can_and_tube": InteractImage(241, 310, "welder_can_pipe.png"),
97 }
98
99 INITIAL = "empty"
100
101 INITIAL_DATA = {
102 'contents': [],
103 }
104
105 def select_interact(self):
106 contents = self.get_data('contents')
107 if not contents:
108 return "empty"
109 elif len(contents) == 1:
110 if "can" in contents:
111 return "can"
112 elif "tube" in contents:
113 return "tube"
114 else:
115 return "can_and_tube"
116
117 def interact_without(self):
118 return Result(_("You really don't want to put your hand in there."))
119
120 def interact_with_empty_can(self, item):
121 contents = self.get_data('contents')
122 if "can" in contents:
123 return Result(_("There is already a can in the welder."))
124 self.game.remove_inventory_item(item.name)
125 contents.append("can")
126 self.set_interact()
127 return Result(_("You carefully place the can in the laser welder."))
128
129 def interact_with_tube_fragment(self, item):
130 contents = self.get_data('contents')
131 if "tube" in contents:
132 return Result(_("There is already a tube fragment in the welder."))
133 self.game.remove_inventory_item(item.name)
134 contents.append("tube")
135 self.set_interact()
136 return Result(_("You carefully place the tube fragments in the"
137 " laser welder."))
138
139 def get_description(self):
140 contents = self.get_data('contents')
141 if not contents:
142 return (_("This is a Smith and Wesson 'zOMG' class high-precision"
143 " laser welder."))
144 if len(contents) == 1:
145 msg = _("The laser welder looks hungry, somehow.")
146 if "can" in contents:
147 msg += _(" It currently contains an empty can.")
148 elif "tube" in contents:
149 msg += _(" It currently contains a tube fragment.")
150 elif len(contents) == 2:
151 msg = _("The laser welder looks expectant. ")
152 if "can" in contents and "tube" in contents:
153 msg += _(" It currently contains an empty can and a"
154 " tube fragment.")
155 return msg
156
157
158 class LaserWelderButton(Thing):
159
160 NAME = "machine.welder.button"
161
162 INTERACTS = {
163 "button": InteractNoImage(406, 389, 28, 31),
164 }
165
166 INITIAL = "button"
167
168 def interact_without(self):
169 welder_slot = self.scene.things["machine.welder.slot"]
170 contents = welder_slot.get_data("contents")
171 if not contents:
172 return Result(_("The laser welder doesn't currently contain"
173 " anything weldable."))
174 elif len(contents) == 1:
175 if "can" in contents:
176 return Result(_("The laser welder needs something to weld the"
177 " can to."))
178 elif "tube" in contents:
179 return Result(_("The laser welder needs something to weld the"
180 " tube fragments to."))
181 else:
182 welder_slot.set_data("contents", [])
183 welder_slot.set_interact()
184 if self.game.is_in_inventory("cryo_pipes_one:"):
185 self.game.replace_inventory_item("cryo_pipes_one:",
186 "cryo_pipes_two")
187 return Result(_("With high-precision spitzensparken, you weld"
188 " together a second pipe. You bundle the two"
189 " pipes together."), soundfile='laser.ogg')
190 elif self.game.is_in_inventory("cryo_pipes_two:"):
191 self.game.replace_inventory_item("cryo_pipes_two:",
192 "cryo_pipes_three")
193 return Result(_("With high-precision spitzensparken, you"
194 " create yet another pipe. You store it with"
195 " the other two."), soundfile='laser.ogg')
196 elif self.game.is_in_inventory("cryo_pipes_three:"):
197 # just for safety
198 return None
199 else:
200 self.game.add_inventory_item("cryo_pipes_one")
201 return Result(_("With high-precision spitzensparken, the can"
202 " and tube are welded into a whole greater"
203 " than the sum of the parts."),
204 soundfile='laser.ogg')
205
206
207 class LaserWelderPowerLights(Thing):
208
209 NAME = "machine.welder.lights"
210
211 INTERACTS = {
212 "lights": InteractAnimated(199, 273, ["power_lights_%d.png" % i for i
213 in range(8) + range(6, 0, -1)],
214 10),
215 }
216
217 INITIAL = 'lights'
218
219 def get_description(self):
220 return _("The power lights pulse expectantly.")
221
222
223 class CryoPipesOne(Item):
224 "A single cryo pipe (made from a tube fragment and can)."
225
226 NAME = 'cryo_pipes_one'
227 INVENTORY_IMAGE = "cryo_pipes_one.png"
228 CURSOR = CursorSprite('cryo_pipes_one_cursor.png')
229 TOOL_NAME = "cryo_pipes_one"
230
231
232 class CryoPipesTwo(Item):
233 "Two cryo pipes (each made from a tube fragment and can)."
234
235 NAME = 'cryo_pipes_two'
236 INVENTORY_IMAGE = "cryo_pipes_two.png"
237 CURSOR = CursorSprite('cryo_pipes_two_cursor.png')
238 TOOL_NAME = "cryo_pipes_two"
239
240
241 class CryoPipesThree(Item):
242 "Three cryo pipes (each made from a tube fragment and can)."
243
244 NAME = 'cryo_pipes_three'
245 INVENTORY_IMAGE = "cryo_pipes_three.png"
246 CURSOR = CursorSprite('cryo_pipes_three_cursor.png')
247 TOOL_NAME = "cryo_pipes_three"
248
249
250 class Grinder(Thing):
251
252 NAME = "machine.grinder"
253
254 INTERACTS = {
255 "grind": InteractNoImage(86, 402, 94, 63),
256 }
257
258 INITIAL = "grind"
259
260 def interact_without(self):
261 return Result(_("It looks like it eats fingers. Perhaps a different"
262 " approach is in order?"))
263
264 def interact_with_titanium_leg(self, item):
265 self.game.replace_inventory_item(item.name, 'machete')
266 return Result(_("After much delicate grinding and a few close calls"
267 " with various body parts, the titanium femur now"
268 " resembles a machete more than a bone. Nice and"
269 " sharp, too."), soundfile="grinder.ogg")
270
271 def get_description(self):
272 return _("A pretty ordinary, albeit rather industrial, grinding"
273 " machine.")
274
275
276 class TitaniumMachete(Item):
277 "Titanium machete, formerly a leg."
278
279 NAME = 'machete'
280 INVENTORY_IMAGE = "machete.png"
281 CURSOR = CursorSprite('machete_cursor.png', 23, 1)
282
283
284 class ManualThing(TakeableThing):
285
286 NAME = "machine.manual"
287
288 INTERACTS = {
289 "manual": InteractImage(432, 493, "manual_on_floor.png"),
290 }
291
292 INITIAL = "manual"
293 ITEM = 'manual'
294
295 def interact_without(self):
296 self.take()
297 return Result(_("Ah! The ship's instruction manual. You'd feel better"
298 " if the previous owner wasn't lying next to it with a"
299 " gaping hole in his rib cage."))
300
301
302 class Manual(Item):
303 "A ship instruction manual."
304
305 NAME = 'manual'
306 INVENTORY_IMAGE = "manual.png"
307 CURSOR = None
308
309 def is_interactive(self, tool=None):
310 return True
311
312 def interact_without(self):
313 return Result(detail_view='manual_detail')
314
315
316 SCENES = [Machine]