comparison gamelib/scenes/machine.py @ 329:0bb1ab329bee

Link up laser welder
author Simon Cross <hodgestar+bzr@gmail.com>
date Sat, 28 Aug 2010 14:00:38 +0200
parents 3d1a5c0c362a
children 81f5fb9f50e4
comparison
equal deleted inserted replaced
328:3cb48621759a 329:0bb1ab329bee
25 self.add_thing(LaserWelderButton()) 25 self.add_thing(LaserWelderButton())
26 self.add_thing(LaserWelderPowerLights()) 26 self.add_thing(LaserWelderPowerLights())
27 self.add_thing(Grinder()) 27 self.add_thing(Grinder())
28 self.add_thing(ManualThing()) 28 self.add_thing(ManualThing())
29 self.add_item(TitaniumMachete('machete')) 29 self.add_item(TitaniumMachete('machete'))
30 self.add_item(TinPipe('tin_pipe')) 30 self.add_item(CryoPipesOne('cryo_pipes_one'))
31 self.add_item(CryoPipesTwo('cryo_pipes_two'))
32 self.add_item(CryoPipesThree('cryo_pipes_three'))
31 self.add_item(Manual('manual')) 33 self.add_item(Manual('manual'))
32 self.add_thing(GenericDescThing('machine.wires', 2, 34 self.add_thing(GenericDescThing('machine.wires', 2,
33 "Wires run to all the machines in the room", 35 "Wires run to all the machines in the room",
34 ( 36 (
35 (250, 172, 252, 12), 37 (250, 172, 252, 12),
93 class LaserWelderSlot(Thing): 95 class LaserWelderSlot(Thing):
94 96
95 NAME = "machine.welder.slot" 97 NAME = "machine.welder.slot"
96 98
97 INTERACTS = { 99 INTERACTS = {
98 "weld": InteractNoImage(241, 310, 178, 66), 100 "empty": InteractImage(241, 310, "welder_empty.png"),
99 } 101 "can": InteractImage(241, 310, "welder_can.png"),
100 102 "tube": InteractImage(241, 310, "welder_pipe.png"),
101 INITIAL = "weld" 103 "can_and_tube": InteractImage(241, 310, "welder_can_pipe.png"),
104 }
105
106 INITIAL = "empty"
102 107
103 INITIAL_DATA = { 108 INITIAL_DATA = {
104 'cans_in_place': 0, 109 'contents': set(),
105 } 110 }
111
112 def update_contents(self):
113 """Update the interact after a contents change."""
114 contents = self.get_data('contents')
115 if not contents:
116 self.set_interact("empty")
117 elif len(contents) == 1:
118 if "can" in contents:
119 self.set_interact("can")
120 elif "tube" in contents:
121 self.set_interact("tube")
122 else:
123 self.set_interact("can_and_tube")
106 124
107 def interact_without(self): 125 def interact_without(self):
108 return Result("You really don't want to but your hand in there.") 126 return Result("You really don't want to but your hand in there.")
109 127
110 def interact_with_empty_can(self, item): 128 def interact_with_empty_can(self, item):
111 starting_cans = self.get_data('cans_in_place') 129 contents = self.get_data('contents')
112 if starting_cans < 3: 130 if "can" in contents:
113 self.state.remove_inventory_item(item.name) 131 return Result("There is already a can in the welder.")
114 self.set_data('cans_in_place', starting_cans + 1) 132 self.state.remove_inventory_item(item.name)
115 return Result({ 133 contents.add("can")
116 0: "You carefully place the empty can in the area marked 'to weld'.", 134 self.update_contents()
117 1: "You carefully place the empty can next to the other.", 135 return Result("You carefully place the can in the laser welder.")
118 2: "You carefully place the empty can next to its mates.", 136
119 }[starting_cans]) 137 def interact_with_tube_fragment(self, item):
138 contents = self.get_data('contents')
139 if "tube" in contents:
140 return Result("There is already a tube fragment in the welder.")
141 self.state.remove_inventory_item(item.name)
142 contents.add("tube")
143 self.update_contents()
144 return Result("You carefully place the tube fragments in the laser welder.")
145
146 def get_description(self):
147 contents = self.get_data('contents')
148 if not contents:
149 return "This is a Smith and Wesson 'zOMG' class high-precision laser welder."
150 if len(contents) == 1:
151 msg = "The laser welder looks hungry, somehow."
152 if "can" in contents:
153 msg += " It currently contains an empty can."
154 elif "tube" in contents:
155 msg += " It currently contains a tube fragment."
156 elif len(contents) == 2:
157 msg = "The laser welder looks expectant. "
158 if "can" in contents and "tube" in contents:
159 msg += " It currently contains an empty can and a tube fragment."
160 return msg
161
162
163 class LaserWelderButton(Thing):
164
165 NAME = "machine.welder.button"
166
167 INTERACTS = {
168 "button": InteractNoImage(406, 389, 28, 31),
169 }
170
171 INITIAL = "button"
172
173 def interact_without(self):
174 contents = self.scene.things["machine.welder.slot"].get_data("contents")
175 if not contents:
176 return Result("The laser welder doesn't currently contain anything weldable.")
177 elif len(contents) == 1:
178 if "can" in contents:
179 return Result("The laser welder needs something to weld the can to.")
180 elif "tube" in contents:
181 return Result("The laser welder needs something to weld the tube fragments to.")
120 else: 182 else:
121 return Result("The machine has enough cans to weld for the moment.") 183 self.scene.things["machine.welder.slot"].set_data("contents", set())
122 184 self.scene.things["machine.welder.slot"].update_contents()
123 def get_description(self): 185 if self.state.items["cryo_pipes_one"] in self.state.inventory:
124 if self.get_data('cans_in_place') == 0: 186 self.state.replace_inventory_item("cryo_pipes_one", "cryo_pipes_two")
125 return "This is a Smith and Wesson 'zOMG' class high-precision laser welder." 187 elif self.state.items["cryo_pipes_two"] in self.state.inventory:
126 msg = "The laser welder looks hungry, somehow." 188 self.state.replace_inventory_item("cryo_pipes_two", "cryo_pipes_three")
127 if self.get_data('cans_in_place') == 1: 189 elif self.state.items["cryo_pipes_three"] in self.state.inventory:
128 msg += " It currently contains an empty can." 190 # just for safety
129 elif self.get_data('cans_in_place') == 2: 191 pass
130 msg += " It currently contains two empty cans." 192 else:
131 elif self.get_data('cans_in_place') == 3: 193 self.state.add_inventory_item("cryo_pipes_one")
132 msg += " It currently contains three empty cans." 194 return Result("With high-precision spitzensparken, the can and tube a welded"
133 return msg 195 " into a whole greater than the parts.",
134 196 soundfile='laser.ogg')
135
136 class LaserWelderButton(Thing):
137
138 NAME = "machine.welder.button"
139
140 INTERACTS = {
141 "button": InteractNoImage(406, 389, 28, 31),
142 }
143
144 INITIAL = "button"
145
146 def interact_without(self):
147 cans_in_place = self.scene.things["machine.welder.slot"].get_data("cans_in_place")
148 if cans_in_place < 1:
149 return Result("The laser welder doesn't currently contain anything weldable.")
150 elif cans_in_place < 3:
151 return Result("You'll need more cans than that.")
152 else:
153 self.scene.things["machine.welder.slot"].set_data("cans_in_place", 0)
154 self.state.add_inventory_item('tin_pipe')
155 return Result("With high-precision spitzensparken, the cans are welded into a replacement tube.",
156 soundfile='laser.ogg')
157 197
158 198
159 class LaserWelderPowerLights(Thing): 199 class LaserWelderPowerLights(Thing):
160 200
161 NAME = "machine.welder.lights" 201 NAME = "machine.welder.lights"
170 return random.choice([ 210 return random.choice([
171 "The power lights pulse expectantly.", 211 "The power lights pulse expectantly.",
172 ]) 212 ])
173 213
174 214
175 class TinPipe(Item): 215 class CryoPipesOne(Item):
176 "A pipe made out of welded-together tins." 216 "A single cryo pipe (made from a tube fragment and can)."
177 217
178 INVENTORY_IMAGE = "tube_fragments.png" 218 INVENTORY_IMAGE = "cryo_pipes_one.png"
179 CURSOR = CursorSprite('tube_fragments_cursor.png') 219 CURSOR = CursorSprite('cryo_pipes_one_cursor.png')
180 TOOL_NAME = "pipe" 220 TOOL_NAME = "cryo_pipes_one"
221
222
223 class CryoPipesTwo(Item):
224 "Two cryo pipes (each made from a tube fragment and can)."
225
226 INVENTORY_IMAGE = "cryo_pipes_two.png"
227 CURSOR = CursorSprite('cryo_pipes_two_cursor.png')
228 TOOL_NAME = "cryo_pipes_two"
229
230
231 class CryoPipesThree(Item):
232 "Three cryo pipes (each made from a tube fragment and can)."
233
234 INVENTORY_IMAGE = "cryo_pipes_three.png"
235 CURSOR = CursorSprite('cryo_pipes_three_cursor.png')
236 TOOL_NAME = "cryo_pipes_three"
181 237
182 238
183 class Grinder(Thing): 239 class Grinder(Thing):
184 240
185 NAME = "machine.grinder" 241 NAME = "machine.grinder"