Example with moving NPCs

Here is a playable example with three NPCs.

Ambling Albert moves randomly, but avoids going back to where he just came from. Ringing Rita moves towards Albert, and if they are already in the same room she rings a bell. Ringing the bell sets the target for Homing Hepsie, who moves closer to her target on every tick.

The player can also order the NPCs around.

Summary
(story title)   The adventures of Albert, Rita, and Hepsie
(story noun)    An NPC demonstration
(story author)  Linus Åkesson
(story ifid)    F673BF24-D760-4E39-9FE9-7388BB488184
(story release 1)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The map

#nwn
(name *)        northwestern nook
(room *)

(from * go #southeast to #square)
(from * go #south through #wdoor to #swn)

#nen
(name *)        northeastern nook
(room *)

(from * go #southwest to #square)
(from * go #south through #edoor to #sen)

#swn
(name *)        southwestern nook
(room *)

(from * go #northeast to #square)
(from * go #north through #wdoor to #nwn)

#sen
(name *)        southeastern nook
(room *)

(from * go #northwest to #square)
(from * go #north through #edoor to #nen)

#edoor
(door *)
(name *)        wooden door
(openable *)

#wdoor
(door *)
(name *)        wooden door
(openable *)

#square
(name *)        main square
(room *)
(look *)
        A lamp post illuminates the main square.

(from * go #northeast to #nen)
(from * go #southeast to #sen)
(from * go #northwest to #nwn)
(from * go #southwest to #swn)

(narrate $Person leaving * #up to $)
        (The $Person) climbs up the lamp post.

(narrate $Person entering * from #uplamp)
        (The $Person) slides down from the lamp post.

#lamp
(name *)        lamp post
(* is #in #square)

#uplamp
(room *)
(name *)        top of the lamp post
(room header *) Up the lamp post
(look *)        What a view!
(from * go #down to #square)
(from #square go #up to *)

%% Let pathfinding work all over the map.
(*(room $) is visited)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The player

#player
(* is #in #square)
(current player *)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Homing Hepsie

#hepsie
(name *)        Homing Hepsie
(proper *)
(female *)
(* is #in #square)
(appearance * $ $)
        (The *) is here.

(global variable (target of hepsie is $))

(on every tick)
        (par)
        (* is in room $Room)
        (target of hepsie is $Target)
        (first step from $Room to $Target is $Dir)
        (let * go $Dir)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ringing Rita

#rita
(name *)        Ringing Rita
(proper *)
(female *)
(* is #in #nen)
(appearance * $ $)
        (The *) is here.

(global variable (rita has rung in $))

(on every tick)
        (par)
        (* is in room $RitaRoom)
        (#albert is in room $AlbertRoom)
        (if) ($RitaRoom = $AlbertRoom) (then)
                (if)
                        ~(rita has rung in $RitaRoom)
                        ~(#hepsie is in room $RitaRoom)
                (then)
                        %% Ringing Rita rings her bell.
                        (if) (player can see *) (then)
                                Rita rings a bell.
                        (else)
                                (current room $PlayerRoom)
                                (if) (from $PlayerRoom go $BellDir to room $RitaRoom) (then)
                                        You hear a bell from (from-adverb $BellDir).
                                (else)
                                        You hear a distant bell.
                                (endif)
                                (if) (player can see #hepsie) (then)
                                        Hepsie's ears perk up.
                                (endif)
                        (endif)
                        (now) (rita has rung in $RitaRoom)
                        (now) (target of hepsie is $RitaRoom)
                (endif)
        (elseif) (first step from $RitaRoom to $AlbertRoom is $Dir) (then)
                (let * go $Dir)
        (endif)

#bell
(name *)        bell
(* is #heldby #rita)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Ambling Albert

#albert
(name *)        Ambling Albert
(proper *)
(male *)
(* is #in #nwn)
(appearance * $ $)
        (The *) is here.

(global variable (albert avoids $))

(on every tick)
        (par)
        (* is in room $AlbertRoom)
        (select)
                (collect $Obj)
                        {
                                *($Obj is #in $AlbertRoom)
                        (or)
                                *($AlbertRoom attracts $Obj)
                        }
                        ~($Obj = *)
                (into $List)
                (randomly select $Target from $List)
                (if) (openable $Target) (then)
                        (if) ($Target is closed) (then)
                                (let * open $Target)
                        (else)
                                (let * close $Target)
                        (endif)
                (elseif) (player can see *) (then)
                        (select)
                                Albert scrutinizes (the $Target).
                        (or)
                                Albert suddenly sneezes.
                        (or)
                                Albert seems startled by the presence of (the $Target).
                        (purely at random)
                (endif)
        (or)
                (collect $Dir)
                        *(from $AlbertRoom go $Dir to room $)
                        ~(albert avoids $Dir)
                (into $Exits)
                (now) ~(albert avoids $)
                (randomly select $Dir from $Exits)
                (let * go $Dir)
                (opposite of $Dir is $OppDir)
                (now) (albert avoids $OppDir)
        (purely at random)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Giving orders

(perform [tell (animate $Actor) to go $Dir])
        ($Actor is in room $Room)
        (from $Room go $Dir to room $)
        (agreement)
        (let $Actor go $Dir)

(perform [tell (animate $Actor) to open (door $Door)])
        ($Door is closed)
        (agreement)
        (let $Actor open $Door)

(perform [tell (animate $Actor) to close (door $Door)])
        ($Door is open)
        (agreement)
        (let $Actor close $Door)

(agreement)
        (select)
                “Sure thing.”
        (or)
                “Can do.”
        (or)
                “No problem.”
        (at random)

(perform [tell (animate $Actor) to | $])
        “Nah,” says (the $Actor).
5 Likes