Room cleanups and fixes, and wet rooms.
authorNeil Moore <neil@s-z.org>
Wed, 28 May 2008 07:07:21 +0000 (03:07 -0400)
committerNeil Moore <neil@s-z.org>
Wed, 28 May 2008 07:07:21 +0000 (03:07 -0400)
Remove unused union-find support from Room class.

Do not try to pick two preceding Rooms if there is only one.

Rooms have a 1/10 chance to be full of water (instead of floor).

level.py

index ce2c50f..a894743 100644 (file)
--- a/level.py
+++ b/level.py
@@ -36,12 +36,6 @@ class Room (object):
         self.ymax = y + h - 1
         self.xmax = x + w - 1
         self.doors = { 't': False, 'b': False, 'l': False, 'r': False }
-        self.__ufcomp = self
-
-    def component(self):
-        if self.__ufcomp is not self:
-            self.__ufcomp = self.__ufcomp.component()
-        return self.__ufcomp
 
     def facing(self, room):
         possible = []
@@ -87,13 +81,8 @@ class Room (object):
     def __and__(self, room):
         yoverlap = (self.y <= room.ymax+1 and self.ymax >= room.y-1)
         xoverlap = (self.x <= room.xmax+1 and self.xmax >= room.x-1)
-        if xoverlap and yoverlap:
-            self += room
         return yoverlap and xoverlap
 
-    def __iadd__(self, room):
-        self.__ufcomp = room.component()
-
 
 class Level (object):
     """Represents an area of the map comprising a contiguous rectangular
@@ -216,17 +205,22 @@ class Level (object):
                 ry = random.randint(0, self.h - rh)
                 rx = random.randint(0, self.w - rw)
                 rm = Room(ry, rx, rh, rw)
+
+            wet = random.random() < 0.1
+
             rooms.append(rm)
             for i in xrange(rm.y+1, rm.ymax):
                 for j in xrange(rm.x+1, rm.xmax):
                     if rno in st_rooms and i == ry + rh//2 and j == rx + rw//2:
                         self.grid[i][j] = loc.Stair(self, i, j)
+                    elif wet:
+                        self.grid[i][j] = loc.Water(self, i, j)
                     else:
                         self.grid[i][j] = loc.Floor(self, i, j)
 
         ct = 0
         for rno in xrange(1,nrooms):
-            nct = 1 if random.random() < 0.8 else 2
+            nct = 1 if rno == 1 or random.random() < 0.8 else 2
             for tgt in random.sample(range(0, rno), nct):
                 self.connect(rooms[rno], rooms[tgt])
                 ct = ct + 1