Up to Main Index                          Up to Journal for February, 2017

                    JOURNAL FOR SUNDAY 12TH FEBRUARY, 2017
______________________________________________________________________________

SUBJECT: Doors, locks, panics and resets
   DATE: Sun 12 Feb 22:11:24 GMT 2017

I thought I would spend my Sunday coding, but what on? It seemed time to work
on resets. Resets are needed for items and mobiles — creatures, critters and
other things that move. When an item is sold, junked or otherwise used up it
needs to be reset and placed back into the world. If a mobile is killed it
likewise needs to be reset and put back into the world. Solved puzzles need to
be reset so they can be solved again. Without resets the world would become
empty and desolate with nothing left to do after a period of time.

MUDs typically implement one of two types of resets. Stop the world resets and
rolling resets. With stop the world resets players are removed from the game
and put into a waiting area, limbo or simply kicked out of the game. The world
is reset and players are then let back in again. With rolling resets objects,
puzzles and mobiles are continually reset all the time as needed.

Rolling resets are much harder to implement.

As far as I know MirrorWorld[1] was one of the first MUDs to implement rolling
resets. MirrorWorld was also first MUD I played, and because I didn’t know any
different, I implemented rolling resets in WolfMUD. I also didn’t know at the
time that MirrorWorld was unique in this respect.

I thought for a while about what was the simplest reset I could start with and
came up with — doors. A door can be opened and closed. If left open it can
automatically close after a period of time. So I added the tavern door to the
zinara.wrj zone file:


  %%
        Ref: L3N11
  Narrative:
       Name: the tavern door
    Aliases: DOOR
       Door: BLOCK→E CLOSE→30s

  It's a door.
  %%


I then added the door to the tavern entrance location:


  %%
        Ref: L3
       Name: Tavern entrance
    Aliases: TAVERN ENTRANCE
      Exits: E→L5 S→L4 SW→L2 W→L1
  Inventory: L3N1

  You are in the entryway to the dragon's breath tavern. To the west you see an
  inviting fireplace and south an even more inviting bar. Eastward a door leads
  out into the street.
  %%


At this point the DOOR attribute was unknown to the server but the door should
have been added as a narrative object, in the right place and examinable.

I ran the server… and it blew up:


  panic: runtime error: invalid memory address or nil pointer dereference


I then spent a few hours finding out why. Turned out the reference on the door
was wrong and should have been ‘L3N1’ not ‘L3N11’. Still, the server should
not have blown up! I have since fixed this little bug in the zone loader as
commit c3a8d77: zones: Fix nil panic in linkupInventory.

Next, I realised that doors were not so simple. First of all, like exits, they
have to be in two places at once. For a door leading from the tavern entrance
to the street it also needs to lead from the street into the tavern. This
means that doors need to be linked up when loaded and unmarshalled — again,
just like exits. Doors also have to block movement when closed. Doors can also
be locked and require a key to be unlocked. Locked doors cannot be opened
until unlocked.

I’m going to try and block movement using a veto. Vetoes should also work for
preventing opening of locked doors. I might even be able to use a veto to stop
locked doors from being unlocked with the wrong key.

I’ve mocked up a locked door in the zone file:


  %%
        Ref: L36N3
  Narrative:
       Name: a shed door
    Aliases: DOOR
       Door: BLOCK→S CLOSE→30s KEY→SHEDKEY

  This is a small, wooden shed door.
  %%


However I’m now thinking that locks should be a separate attribute so that
they can be used on containers and possibly other items. I could also specify
a complexity or level for the lock for use with various skills such as lock
picking. Maybe something like:


  %%
        Ref: L36N3
  Narrative:
       Name: a shed door
    Aliases: DOOR
       Door: BLOCK→S CLOSE→30s
       Lock: KEY→SHEDKEY LEVEL→SIMPLE

  This is a small, wooden shed door.
  %%


I could also have PHRASE and/or CODE keywords for the lock requiring a phrase
or code respectively to be spoken/entered to open the lock.

This may seem like a lot of effort to put into a simple door. However it
touches on a lot of small things that will be important for building bigger
things later on. So I think the time spent will be worth it.

Looks like I’ve found myself another rabbit hole to explore…

--
Diddymus

  [1] WolfMUD was heavily inspired by MirrorWorld and I have a lot of fond
      memories of playing it and of Pippin, Penfold and other players.


  Up to Main Index                          Up to Journal for February, 2017