home · contact · privacy
Re-factor treatment of things as obstacles for SourcedMaps.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 14 Dec 2020 20:17:47 +0000 (21:17 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 14 Dec 2020 20:17:47 +0000 (21:17 +0100)
plomrogue/mapping.py
plomrogue/things.py

index e3c071f85251ae9e947183a474fe69d78294e2bf..d3baba67527e1f83f4d548071c2033eb86c27d85 100644 (file)
@@ -210,8 +210,8 @@ class Map():
 
 class SourcedMap(Map):
 
 
 class SourcedMap(Map):
 
-    def __init__(self, block_chars, things, source_maps, source_center, radius,
-                 get_map):
+    def __init__(self, block_chars, obstacle_positions, source_maps,
+                 source_center, radius, get_map):
         self.block_chars = block_chars
         self.radius = radius
         example_map = get_map(YX(0, 0))
         self.block_chars = block_chars
         self.radius = radius
         example_map = get_map(YX(0, 0))
@@ -219,20 +219,13 @@ class SourcedMap(Map):
         size, self.offset, self.center = \
             self.source_geometry.define_segment(source_center, radius)
         self.geometry = self.source_geometry.__class__(size)
         size, self.offset, self.center = \
             self.source_geometry.define_segment(source_center, radius)
         self.geometry = self.source_geometry.__class__(size)
-        for yx in self:
-            big_yx, _ = self.source_yxyx(yx)
-            get_map(big_yx)
         self.source_map_segment = ''
         self.source_map_segment = ''
-        obstacles = {}
-        for yxyx in [t.position for t in things if t.blocking]:
-            if yxyx == source_center:
-                continue
-            if yxyx[0] not in obstacles:
-                obstacles[yxyx[0]] = []
-            obstacles[yxyx[0]] += [yxyx[1]]
-        for yx in self:  # TODO: iter and source_yxyx expensive, cache earlier?
+        if source_center in obstacle_positions:
+            obstacle_positions.remove(source_center)
+        for yx in self:
             big_yx, little_yx = self.source_yxyx(yx)
             big_yx, little_yx = self.source_yxyx(yx)
-            if big_yx in obstacles and little_yx in obstacles[big_yx]:
+            get_map(big_yx)
+            if (big_yx, little_yx) in obstacle_positions:
                 self.source_map_segment += self.block_chars[0]
             else:
                 self.source_map_segment += source_maps[big_yx][little_yx]
                 self.source_map_segment += self.block_chars[0]
             else:
                 self.source_map_segment += source_maps[big_yx][little_yx]
index df5ea58c4c89291b846d0d0c649896dfa50e1289..0d17d3c029469713ed25305d20433467a847b6d2 100644 (file)
@@ -68,11 +68,13 @@ class Thing(ThingBase):
             return lowered_msg
 
         largest_audible_distance = 20
             return lowered_msg
 
         largest_audible_distance = 20
-        # player's don't block sound (or should they?)
-        things = [t for t in self.game.things if t.type_ != 'Player']
+        # player's don't block sound
+        obstacles = [t.position for t in self.game.things
+                     if t.blocking and t.type_ != 'Player']
         sound_blockers = self.game.get_sound_blockers()
         sound_blockers = self.game.get_sound_blockers()
-        dijkstra_map = DijkstraMap(sound_blockers, things, self.game.maps, self.position,
-                                   largest_audible_distance, self.game.get_map)
+        dijkstra_map = DijkstraMap(sound_blockers, obstacles, self.game.maps,
+                                   self.position, largest_audible_distance,
+                                   self.game.get_map)
         url_limits = []
         for m in re.finditer('https?://[^\s]+', msg):
             url_limits += [m.start(), m.end()]
         url_limits = []
         for m in re.finditer('https?://[^\s]+', msg):
             url_limits += [m.start(), m.end()]
@@ -117,7 +119,6 @@ class ThingSpawner(Thing):
                   if t != self and t.position == self.position]:
             return
         self.game.add_thing(self.child_type, self.position)
                   if t != self and t.position == self.position]:
             return
         self.game.add_thing(self.child_type, self.position)
-        # self.game.changed = True  handled by add_thing
 
 
 
 
 
 
@@ -184,7 +185,8 @@ class Thing_Bottle(Thing):
         fov_map_class = self.game.map_geometry.fov_map_class
         fov_radius = 12
         light_blockers = self.game.get_light_blockers()
         fov_map_class = self.game.map_geometry.fov_map_class
         fov_radius = 12
         light_blockers = self.game.get_light_blockers()
-        fov = fov_map_class(light_blockers, self.game.things, self.game.maps,
+        obstacles = [t.position for t in self.game.things if t.blocking]
+        fov = fov_map_class(light_blockers, obstacles, self.game.maps,
                             self.position, fov_radius, self.game.get_map)
         fov.init_terrain()
         visible_players = []
                             self.position, fov_radius, self.game.get_map)
         fov.init_terrain()
         visible_players = []
@@ -372,7 +374,6 @@ class Thing_BottleDeposit(Thing):
             elif choice == 'Hat':
                 msg += 'pick it up and then use "(un-)wear" on it!'
             self.sound('BOTTLE DEPOSITOR', msg)
             elif choice == 'Hat':
                 msg += 'pick it up and then use "(un-)wear" on it!'
             self.sound('BOTTLE DEPOSITOR', msg)
-            # self.game.changed = True  done by game.add_thing
 
     def accept(self):
         self.bottle_counter += 1
 
     def accept(self):
         self.bottle_counter += 1
@@ -465,7 +466,8 @@ class ThingAnimate(Thing):
         fov_map_class = self.game.map_geometry.fov_map_class
         fov_radius = 3 if self.drunk > 0 else 12
         light_blockers = self.game.get_light_blockers()
         fov_map_class = self.game.map_geometry.fov_map_class
         fov_radius = 3 if self.drunk > 0 else 12
         light_blockers = self.game.get_light_blockers()
-        self._fov = fov_map_class(light_blockers, self.game.things, self.game.maps,
+        obstacles = [t.position for t in self.game.things if t.blocking]
+        self._fov = fov_map_class(light_blockers, obstacles, self.game.maps,
                                   self.position, fov_radius, self.game.get_map)
 
     def multiprocessible_fov_stencil(self):
                                   self.position, fov_radius, self.game.get_map)
 
     def multiprocessible_fov_stencil(self):