home · contact · privacy
Fix faulty FOV handling of non-player Things.
[plomrogue2] / plomrogue / game.py
index 6e8afdf83182dded8a25c735b94dc7cdc2a7095a..1dc1e92cd2a29a0a28a72aa22a5d4365741fa95d 100755 (executable)
@@ -210,6 +210,22 @@ class Game(GameBase):
                 return '/O  O\\' + '| oo |' + '\\>--</'
         return None
 
+    def remove_thing(self, t):
+        self.things.remove(t)
+        self.changed_fovs = True
+
+    def add_thing(self, type_, position, id_=0):
+        t_old = None
+        if id_ > 0:
+            t_old = self.get_thing(id_)
+        t = self.thing_types[type_](self, id_=id_, position=position)
+        if t_old:
+            self.things[self.things.index(t_old)] = t
+        else:
+            self.things += [t]
+        self.changed_fovs = True
+        return t
+
     def send_gamestate(self, connection_id=None):
         """Send out game state data relevant to clients."""
 
@@ -294,8 +310,7 @@ class Game(GameBase):
                 t = self.get_player(connection_id)
                 if hasattr(t, 'name'):
                     self.io.send('CHAT ' + quote(t.name + ' left the map.'))
-                self.things.remove(t)
-                self.changed_fovs = True
+                self.remove_thing(t)
                 to_delete += [connection_id]
         for connection_id in to_delete:
             del self.sessions[connection_id]
@@ -313,7 +328,7 @@ class Game(GameBase):
                                           if self.sessions[c_id]['thing_id'] == t.id_]:
                         self.io.send('PLAY_ERROR ' + quote(str(e)), connection_id)
         if self.changed_fovs:
-            for t in [t for t in self.things]:
+            for t in [t for t in self.things if t.type_ == 'Player']:
                 t.invalidate_map_view()
         if self.changed:
             self.turn += 1