Roger Firth's IF pages

Home

InfAct -- about Inform NPCs

Email
Back up

Some NPCs are intrinsically rooted to the spot; perhaps their role is such that this follows naturally ("Sorry, guv, I've gotta stay guardin' this 'ere priceless jewel." or "You want fries with that?"), or maybe their situation requires it ("I say, what beastly rotten luck to be stuck in bed with a broken leg, right in the middle of the bally old tennis season!"). More often than not, though, the game would appear more realistic if your NPC had the semblance of independent mobility. Like conversation, this is hard to do well, so there are a couple of packages which you should consider. Neither, by the way, is here shown working at full capacity -- they both support important features like arrival/departure processing and the handling of doors which are beyond our current scope.

MoveClass.h

The MoveClass.h package is pretty easy to set up. Your rooms must be of class Room and your NPC of class MoveClass; beyond that, your basic choices are about movement types:

Here's what it takes to set up random movement; this for the NPC:

 
Object  usher "gentleman usher" cloakroom
  class MoveClass
  with  name 'usher' 'gentleman' 'gentle' 'man',
        description "The usher is smartly uniformed.",
        walkon "arrives",
        walkoff "walks off",
  has   animate male;

together with this in your Initialise() routine:

 
[ Initialise;
    location = foyer;
    move cloak to player;
    give cloak worn;
    StartDaemon(usher);
    NPC_Path(usher, RANDOM_MOVE, 80);
   "^^Hurrying through the rainswept November night, you're glad to see the
    bright lights of the Opera House. It's surprising that there aren't more
    people about but, hey, what do you expect in a cheap demo game...?^^";
    ];

And here he comes:

 
Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with
glittering chandeliers overhead. The entrance from the street is to the north,
and there are doorways south and west.

The gentleman usher arrives.

>WAIT
Time passes.

>WAIT
Time passes.

The gentleman usher walks off to the south.

Here, instead, he's moving to and fro between the cloakroom and the bar, with a short pause at each end:

 
Object  usher "gentleman usher" cloakroom
  class MoveClass
  with  name 'usher' 'gentleman' 'gentle' 'man',
        description "The usher is smartly uniformed.",
        walkon "arrives",
        walkoff "walks off",
        npc_arrived [;
            StartTimer(self, 2);
            NPC_Path(self, NO_MOVE);
            ],
        time_left 0,
        time_out [;
            if (parent(self) == bar) NPC_Path(self, AIMED_MOVE, cloakroom);
            else NPC_Path(self, AIMED_MOVE, bar);
            ],
  has   animate male;

Just hang around and you'll see him:

 
Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with
glittering chandeliers overhead. The entrance from the street is to the north,
and there are doorways south and west.

>WAIT
Time passes.

The gentleman usher arrives.

>WAIT
Time passes.

The gentleman usher walks off to the south.

>WAIT
Time passes.

>WAIT
Time passes.

>WAIT
Time passes.

The gentleman usher arrives.

>WAIT
Time passes.

The gentleman usher walks off to the west.

Follower.h

The Follower.h package enables you to FOLLOW an NPC who's moving around the game. It's nicely compatible with MoveClass.h; hardly any extra code is needed:

 
Include "Follower";
dots
Object  usher "gentleman usher" cloakroom
  class MoveClass FollowClass
  with  name 'usher' 'gentleman' 'gentle' 'man',
        dots

NPC_Engine.h

The NPC_Engine.h package is even easier to get going. Its capabilities match those of MoveClass.h (except that there seems to be no support for randomly wandering around), and it includes some tasty extras listed below. Your rooms must be of class NPC_Room and your NPC of class NPC_Engine, and you get to choose between moving to a room, moving along a path, or standing still. So, here's more shuttling to the bar and back, again with a small pause at each end:

 
Object  usher "gentleman usher" cloakroom
  class NPC_Engine
  with  name 'usher' 'gentleman' 'gentle' 'man',
        description "The usher is smartly uniformed.",
        npc_arrived [ x;
            if (x == bar) NPC_Schedule(self, cloakroom, 2);
            else NPC_Schedule(self, bar, 2);
            ],
  has   animate male;
dots
[ Initialise;
    location = foyer;
    move cloak to player;
    give cloak worn;
    NPC_Initialise();
    NPC_Path(usher, bar);
   "^^Hurrying through the rainswept November night, you're glad to see the
    bright lights of the Opera House. It's surprising that there aren't more
    people about but, hey, what do you expect in a cheap demo game...?^^";
    ];

The NPC behaves much as he did before:

 
Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with
glittering chandeliers overhead. The entrance from the street is to the north,
and there are doorways south and west.

>WAIT
Time passes.
The gentleman usher is walking past you.

>WAIT
Time passes.
The gentleman usher heads off to the south.

>WAIT
Time passes.

>WAIT
Time passes.

>WAIT
Time passes.
The gentleman usher is walking past you.

>WAIT
Time passes.
The gentleman usher heads off to the west.

In addition to its basic movement capabilities, this package also comes with

which make it well worth a serious look.


Would you believe it? we've run out of time. Tune in again next week for...