Creature invalidation fixes.
authorNeil Moore <neil@s-z.org>
Sat, 31 May 2008 11:31:07 +0000 (07:31 -0400)
committerNeil Moore <neil@s-z.org>
Sat, 31 May 2008 11:31:07 +0000 (07:31 -0400)
Add a creature when starting the game.

Color unknown creatures red.

Do not make Creature invalidations important.

Make Player invalidations important.

Check for no location in Thing.invalidate.

creature.py
roguelike.py
thing.py

index c9f938e..d8378cb 100644 (file)
@@ -50,9 +50,6 @@ class Creature(thing.Thing):
         return self.slots[name]
     def is_wielding(self, item):
         return item in self.slots
-    def invalidate(self):
-        if self.location is not None:
-            self.location.invalidate(important = True)
     def vis_radius(self):
         return 5
     def can_see(self, y, x):
@@ -105,7 +102,7 @@ class Creature(thing.Thing):
     def can_swim(self):
         return False
     def render(self, pic=None):
-        return ( "?", ui.Color('BrightMagenta').cp )
+        return ( "?", ui.Color('BrightRed').cp )
     def move_north(self):
         return self.try_move(self.location.north())
     def move_south(self):
@@ -176,3 +173,6 @@ class Player(Creature):
     def format_intrinsics(self):
         return " ".join([ intr.abbrev for intr in self.intrinsics ]
                 + [ "/" ] + [ extr.abbrev for extr in self.extrinsics ])
+    def invalidate(self):
+        if self.location is not None:
+            self.location.invalidate(important = True)
index 20cb5b4..16446e3 100755 (executable)
@@ -361,6 +361,7 @@ if __name__ == '__main__':
     def main(stdscr):
         me = creature.Player()
         him = creature.Player()
+        it = creature.Creature()
         ui = AppUI(stdscr, [me, him])
 
         thing.Material.loadall(open("materials/materials.mtl"))
@@ -369,6 +370,7 @@ if __name__ == '__main__':
         lvl = level.Level("level0")
         me.place(lvl.loc(min(13, lvl.h - 2), min(2, lvl.w - 2)))
         him.place(lvl.loc(max(2, lvl.h - 5), max(5, lvl.w - 10)))
+        it.place(lvl.loc(min(43, lvl.h - 2), min(5, lvl.w - 2)))
         ui.set_level(lvl)
 
         ui.event_loop()
index 3372441..202efa3 100644 (file)
--- a/thing.py
+++ b/thing.py
@@ -151,7 +151,8 @@ class Thing (object):
         self.location = None
         self.place(location)
     def invalidate(self):
-        self.location.invalidate(important = False)
+        if self.location is not None:
+            self.location.invalidate(important = False)
     def is_creature(self):
         return False
     def is_item(self):
@@ -181,9 +182,6 @@ class Item(Thing):
     wielded = None
     slot = None
 
-    def __init__(self, location=None):
-        super(Item, self).__init__(location)
-
     def is_item(self):
         return True
     def render(self, pic=None):