[Inform] NPC Question

8 views
Skip to first unread message

Jon Petersen

unread,
Nov 23, 1998, 3:00:00 AM11/23/98
to
Well... it seems like it would be easiest just to use two separate
objects. Have a

Class Jeff
with
name "Jeff",
life
[; Kiss: "You don't want to kiss Jeff--he's a libertarian!";
], ! (Since you always want that response to KISS JEFF.)
has (blah, blah);

(Putting the redundant code there.)

Then just make your separate objects.

Jeff jeffmad
with description "Jeff looks mad.",
before
[; Attack: "~Stay away from me,~ Jeff sulks.";
];

Jeff jeffnormal
with description "Jeff looks normal.",
before
[; Attack: "~Oh, keep your frolicsome paws off me, darling!~ Jeff
laughs.";
];

Jon

green_g...@my-dejanews.com

unread,
Nov 24, 1998, 3:00:00 AM11/24/98
to
Help :(

Let's say I have an NPC - he receives bad news and goes tromping off to the
library to drink and sulk. Should the PC wander in at this time, he would not
receive her well. He may or may not answer her questions - he may dismiss her
altogether, be argumentative... etc. At some other point in the game, when he
is in a better mood - things might go much better. All this is determined at
run-time by things the player does or doesn't do.

What I'm trying to do is come up with the best way to CODE this. I do know
that I do NOT want to have huge switch statements in the NPC code (or the
room code, or in any other code) which checks to see if the "bad thing" has
happened (or some mood property) and acts accordingly. I think that would
become horribly complicated to maintain and difficult to debug. However, I'm
not quite sure what else will work.

So, I'm considering creating a variety of "npc_scene" objects (as interacting
with the NPC during these times will probably play out much like a scene in a
movie, though the ultimate outcome will be determined by the PC's actions).
The objects will contain many of the same pieces that are found in regular
NPC code... perhaps something for orders, ask/tell... etc, that will handle
the NPC's mood/circumstances correctly. I could have a bunch of these lying
in wait and stuff them into the appropriate properties as the game indicates.

Does this seem reasonable in Inform? Is there a better way to handle
"complex" NPC's?

Thanks in advance,
Kathleen (the uncertain)


--
-- Excuse me while I dance a little jig of despair.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Joe Mason

unread,
Nov 24, 1998, 3:00:00 AM11/24/98
to
green_g...@my-dejanews.com <green_g...@my-dejanews.com> wrote (not insribed, ok? wrote):

>Let's say I have an NPC - he receives bad news and goes tromping off to the
>library to drink and sulk. Should the PC wander in at this time, he would not
>receive her well. He may or may not answer her questions - he may dismiss her
>altogether, be argumentative... etc. At some other point in the game, when he
>is in a better mood - things might go much better. All this is determined at
>run-time by things the player does or doesn't do.

<snip>

>So, I'm considering creating a variety of "npc_scene" objects (as interacting
>with the NPC during these times will probably play out much like a scene in a
>movie, though the ultimate outcome will be determined by the PC's actions).
>The objects will contain many of the same pieces that are found in regular
>NPC code... perhaps something for orders, ask/tell... etc, that will handle
>the NPC's mood/circumstances correctly. I could have a bunch of these lying
>in wait and stuff them into the appropriate properties as the game indicates.

That's pretty much the way I do it. I have a class for each NPC holding
the stuff that doesn't change. For example (from _In The End_, where I first
used this and found it very convenient), AnnieClass holds Annie's name
property, flags (animate, female, etc.) and a basic description which other
classes can override or not.

Then objects of that class hold code for Annie in various situations. Like
Annie_In_Parking_Lot, Suspicious_Annie, and Bitter_Annie. Finally, I have a
global variable AnnieObj: I can tell which version of Annie is being used
right now by testing "if (AnnieObj == Annie_In_Car)", etc, and whenever I
need to do something to "Annie - whichever one it is", I refer to AnnieObj
instead of the actual object.

The last piece of the puzzle is a routine called new_persona, which is in
the AnnieClass. (I actually have it in a class above that, NPC:
AnnieClass calls the inherited version, which works for all NPC's, and then
does other things which only Annie needs.)

Here's NPC:

Class NPC
class MyObj,
with
new_persona [ new;
if (self ~= new && new.register_self())
{
move new to parent(self);
remove self;
while (child(self)~=0)
move child(self) to new;
StopDaemon(self);
StartDaemon(new);
if (self has female && herobj == self) herobj = new;
else { if (himobj == self) himobj = new; };
}
],
register_self [; rtrue; ],
has animate;

Here's AnnieClass's version of new_persona (from memory, since I've lost the
source code). Also her register_self:

new_persona [ new;
self.NPC::new_persona(new);
if (self has proper)
{
new.short_name = "Annie";
give new proper;
}
],
register_self [;
Annie_Obj = self;
],

That's just an illustration of how you can override new_persona in order to
pass shared information among all your NPC objects. (In this case, all the
Annie's start with short_name "young woman", until the player finds out her
name.)

The other function used here that I forgot to mention is register_self. It
just sets the appropriate global variable. Using these, when your NPC becomes
angry, just use:

HappyObj.new_persona(AngryObj);

Presto!

Joe
--
I think OO is great... It's no coincidence that "woohoo" contains "oo" twice.
-- GLYPH

Jonadab the Unsightly One

unread,
Nov 25, 1998, 3:00:00 AM11/25/98
to
Jon Petersen <en...@ucla.edu> wrote:

> Well... it seems like it would be easiest just to use two separate
> objects.

Jonadab nods in agreement.

Kathleen Fischer

unread,
Nov 25, 1998, 3:00:00 AM11/25/98
to
Joe Mason wrote:
> That's pretty much the way I do it. I have a class for each NPC
> holding the stuff that doesn't change.

> Then objects of that class hold code for Annie in various situations.

... That seems easier than what I had invisioned... of course, if annie
is carrying something you need to move it -- or if there are properties
set you will need to copy them. Hmmmmm.

I sure wish NPC's were easier!

Kathleen (going off to ponder your code for a while... thanks!)

--
*******************************************************************
* Kathleen M. Fischer *
* kfischer@x_greenhouse.llnl.gov (Remove 'x_' before replying) *
** "Don't stop to stomp ants while the elephants are stampeding" **

Joe Mason

unread,
Nov 26, 1998, 3:00:00 AM11/26/98
to
Kathleen Fischer <kfischer@x_greenhouse.llnl.gov> wrote (not insribed, ok? wrote):

>Joe Mason wrote:
>> That's pretty much the way I do it. I have a class for each NPC
>> holding the stuff that doesn't change.
>
>> Then objects of that class hold code for Annie in various situations.
>
>... That seems easier than what I had invisioned... of course, if annie
>is carrying something you need to move it -- or if there are properties
>set you will need to copy them. Hmmmmm.

You'll notice the new_persona routine automatically moves everything the
old persona over to the new persona. Any attributes and properties that
you set would have to be copied by hand, though.

Joe
--
Surely you're not trying to tell us that you've never, nay _never_ walked
across miles and miles of Scottish heath searching for a witch only to
find that three go by all at once? -- Den of Iniquity

David Glasser

unread,
Nov 27, 1998, 3:00:00 AM11/27/98
to
Joe Mason <jcm...@uwaterloo.ca> wrote:

> if (self has female && herobj == self) herobj = new;
> else { if (himobj == self) himobj = new; };

If I'm not wrong, isn't fooling around with the pronobjs not good coding
anymore?

--
David Glasser gla...@NOSPAMuscom.com http://onramp.uscom.com/~glasser
DGlasser @ ifMUD : fovea.retina.net 4000 (webpage fovea.retina.net:4001)
Sadie Hawkins, official band of David Glasser: http://sadie.retina.net
"We take our icons very seriously in this class."

Joe Mason

unread,
Nov 27, 1998, 3:00:00 AM11/27/98
to
David Glasser <gla...@DELETEuscom.com> wrote (not insribed, ok? wrote):

>Joe Mason <jcm...@uwaterloo.ca> wrote:
>
>> if (self has female && herobj == self) herobj = new;
>> else { if (himobj == self) himobj = new; };
>
>If I'm not wrong, isn't fooling around with the pronobjs not good coding
>anymore?

Probably not. This is cannibalized Inform 5 code which I transferred to
another game.

Reply all
Reply to author
Forward
0 new messages