[Reality] Exits

Christopher Armstrong reality@twistedmatrix.com
17 Jun 2002 10:03:07 -0400


Here's the use case: we need to be able to have a ship (which is made of
multiple rooms) enter a spaceport entirely and make its entrances available to
people in the spaceport. The ship may have multiple entrances: one for the
cockpit and one for the cargo bay, f.e.

Two concepts here:
  1) collection of rooms. We probable need an "Area" class or something.
  2) "entrances". We need areas (or perhaps any object with an 'entrances'
     attribute?) to be able to expose them to their current location.

So here's what dash, exarkun, and I came up with:

  We'll have an Area class. Probably every room will have a reference to the
  area its in. Any exits that are created in a room 'bob' that lead to
  'bob.area' (or perhaps a special constant OUTSIDE, which I think is more
  readable) will send the player to bob.area.location. So, that was the easy
  part: regular exits. Entrances will be similar, but instead of *leading* to
  bob.area (or OUTSIDE), their *source* will be bob.area. This assumes two
  things: that we have first class Exit objects that have both "source" and
  "dest" properties, and that there is a hook bound to creating exits in a room
  that checks whether or not exit.source == room.area. If it is, then add the
  Exit object to areaObj.entrances.

  So that's entrances and exits. Making the entrances available to
  area.location would take nothing more than a hook inserted into the
  "movement" event, to the new location to update its exits list.

OK, so this doesn't seem like a very robust solution after some consideration
(at least that entrances bit, anyway) - f.e., what happens if you change the
source of the Exit object after it's created?

Hrm, then again, we could just make the special Area-checking part of the Exit
class, so that's no worry (i.e., add a set_source method that checks whether
source is an area object, if it is, tell it to update its entrances).

Suggestions welcome.

-- 
                                Chris Armstrong
                         << radix@twistedmatrix.com >>
                http://twistedmatrix.com/users/carmstro.twistd/