home · contact · privacy
Add bottle spinning.
[plomrogue2] / plomrogue / things.py
index 4f802db6e25a9f340a9da02074b219d80502b0ab..7234d8ea395e05ab017fa55796bc32df1f21d94c 100644 (file)
@@ -1,5 +1,6 @@
 from plomrogue.errors import GameError, PlayError
 from plomrogue.mapping import YX
+from plomrogue.misc import quote
 import random
 
 
@@ -40,7 +41,6 @@ class Thing(ThingBase):
 
     def sound(self, name, msg):
         from plomrogue.mapping import DijkstraMap
-        from plomrogue.misc import quote
 
         def lower_msg_by_volume(msg, volume, largest_audible_distance):
             import random
@@ -151,11 +151,32 @@ class Thing_Bottle(Thing):
     portable = True
     full = True
     thing_char = '~'
+    spinnable = True
 
     def empty(self):
         self.thing_char = '_'
         self.full = False
 
+    def spin(self):
+        import random
+        all_players = [t for t in self.game.things if t.type_ == 'Player']
+        # TODO: refactor with ThingPlayer.prepare_multiprocessible_fov_stencil
+        # and ThingPlayer.fov_test
+        fov_map_class = self.game.map_geometry.fov_map_class
+        fov_radius = 12
+        fov = fov_map_class(self.game.things, self.game.maps,
+                            self.position, fov_radius, self.game.get_map)
+        fov.init_terrain()
+        visible_players = []
+        for p in all_players:
+            test_position = fov.target_yx(p.position[0], p.position[1])
+            if fov.inside(test_position) and fov[test_position] == '.':
+                visible_players += [p]
+        if len(visible_players) == 0:
+            self.sound('BOTTLE', 'no visible players in spin range')
+        pick = random.choice(visible_players)
+        self.sound('BOTTLE', 'BOTTLE picks: ' + pick.name)
+
 
 
 class Thing_BottleSpawner(ThingSpawner):