[MUD-Dev] TECH: Complex NPCs

John Robert Arras johna at wam.umd.edu
Mon Apr 1 11:45:46 New Zealand Daylight Time 2002


On Sun, 31 Mar 2002, ****** <tryguy74 at hotmail.com> wrote:

> The current state of NPCs in IF is very disappointing. They are
> geared to help (or hinder) the player in predetermined ways as the
> story dictates. NPC-player interaction is usually simplistic, and
> on the majority entirely scripted. There are exceptions, such as
> people designing chatterbot-like NPCs, but on the whole even these
> are not satisfactory. They have no "life", just more detailed
> stimuli-responces and topic-tracking code.

> I want to develop better NPCs. I know the technology now exists to
> have worthwhile NPCs, but I don't know where to start to develop
> them for my stories.

> I base my speculation on "The Sims". Essentially, I'd like to
> dulicate this kind of functionality to a text-based
> environment. I've been thinking of what functionality I'd like my
> NPCs to have, and The Sims' npcs have most of the underlying
> intelligence I'd like. I've read that The Sims' technology is
> based on fuzzy state machines and a-life. This makes sense.

> A-life -- Gives them the underyling needs/wants, and basic
> motivations, and possibly basic senses.  FuSM -- similar to FSM,
> which I already use to some extent. Good for modelling complex
> behaviour in a bounded system.

> Now, I could blunder my way through and arrive at something
> approximating The Sims' behaviours, but I thought I'd ask for help
> first!

> I'd like absolutely anything that would help me get a basic (or
> detailed) model up and running. I have lots of ideas to improve
> The Sims' engine for my personal, storytelling needs, but if I
> could get help on exactly how the engine works, that'd be
> priceless. A rough, generalized outline, a detailed description of
> how the different sub-engines co-operate, pseudocode of
> anything. Even code from MUDs that do things similar to what I'm
> after would be great.

Hi,

I think the mobs need to have certain goals and needs like "I need
to go to my house and sleep when its' between 10pm and 6am", and "I
need to stop and eat at certain hours.." which could be given as
general actions that any NPC should undertake on a regular
basis. (Except as overridden for nighttime guards and so forth...) 
There should also be some ?hardcoded? ability to fight or run away
as needed. Group level tactics should be dealt with on a different
level, however.

I don't think complexity is possible if you look at the NPC level
only. I think you have to look at the level of a group or society to
get the complex interactions that you want. You model the needs of a
society, such as they need food, shelter, clothing for their
inhabitants. And, I think you need to look at how do these things
come into existence and design processes for creating them. I say
this because I am absolutely fascinated with modeling societies. :)
Fortunately MUDs give me a good fun way to do that.

An example:

For food, the society has the goal of having a 7 day supply of food
on hand in its stores and warehouses. It figures out the size of
this supply by looking at the average amount eaten per person, then
multiplying that by the number of people then times 7.

How does it get food? It has a list of things that count as food
units, such as fish, animals, breads, fruits, and vegetables. Each
item like catfish, shrimp, lamb's meat, wild berries, apples,
carrots has a certain process that has to get carried out to create
that item. In some cases, that would consist of going out to the
edge of the water with a net or a fishing hook and fishing. It could
be "go into the forest and pick berries." In other cases, these
processes require raising animals or planting seeds then watching
them grow. The process may require land of a certain type for
raising animals or growing crops and it may have to be prepared if
there is suitable but undeveloped land.  In any case, these
processes are stored or known within the system, and the society can
access these processes and knowledge as it needs them.

And, as an example of how to integrate with combat, if the society
wants land or resources and none is available because of other
societies, the society attacks (the weakest) neighbor in an attempt
to secure more resources...but that is another topic for another
day. :)

It decides what kind of food it wants, and it sets out to assign
society members to do those jobs (it should not just go for the
easiest thing like all fishing at the local stream). Then, the
society members either get assigned to a) buy or create the
equipment they need, or b) go to the location where they will raise
crops and prepare the land.

It finds society members either by them growing up (they started as
children) and choosing a career, or by ending whatever job they had
(some members get bored/sick of doing what they want). They may also
be found if the society de-emphasizes some of the tasks that the
society members are doing and reassigns them to different
tasks. This pool of society members is used when new tasks come up.

As an example of preparing the land, the society could decide to
plop a farm down at some location, and it would leave markers on the
ground representing fences that need to be built and farmland that
needs to be tilled and then seeds planted. The farmer mobs would go
to this location and since they're assigned to the farmer process,
they look to see if work needs to be done, and the markers on the
ground tell them what they need to do (fences come first, then
tilling, then planting...and they have to complete one part of the
process before the next one gets done).

In terms of making more complex things like bread, the society would
have to know that as part of the process of making bread, they have
to make grain, which comes from wheat, so they know they have to set
things in motion to create wheat, then when the wheat comes in, it
has to know that someone has to grind it, so another job would be
the "grind grain" job, then when the flour exists, the flour has to
get transferred to a baker whose job it is to make bread from the
wheat.

To be a little more detailed with the breadmaking, when the farmer
collects the grain (when the ground starts sending the "harvest me"
message as opposed to the "till me" or "weed me" or "water me"
messages, then the farmer gets a unit of wheat for each unit of area
in the farm. The reason the wheat gets created is that the same
object on the ground that was giving the "harvest me" message knows
that when the harvest method is applied to it, it reverts to barren
ground and a unit of wheat pops up in that spot.

Then, the farmer wonders what to do with the wheat. Well, the wheat
not only has a "made_from" process attached to it that tells how
it's made, it also has a "turns_into" list attached to it, that
tells what it can be turned into. For wheat, you basically have
"turns into flour". So, the farmer references the "flour" item and
looks at its "made_from" process. And, it finds that it's
"made_from" wheat that has been "milled".

So, the farmer has to find someone to do the milling process. It
looks up the milling process and finds that you need to find a mill
to do that.  So, the farmer scans (or looks at a list of the
society's assets) and looks for a mill. If there's a mill or one
being built, the farmer gets as much wheat as possible and starts to
take it to the mill. If he can't carry it all, he takes what he can
and then goes back and forth until it's all done.

If there's no mill, then the farmer sends a message to the society
saying that we need to build a mill. The society then assigns a few
people to go make a mill. It first tries to find a suitable location
(mills must be beside streams) and it sends them out to build it. If
they need stone, they ask the society for stone (which it hopefully
has stockpiled and can give to them). Then, they go to the mill site
and start to work on it. Eventually they build it and the farmer can
move the grain there.
 
Then, the mill converts the grain into flour using the mill_grain
process, and the people at the mill need to decide what to do with
the flour. They know that flour can be made into bread, so they ask
how does that get done?

They find that bread is made using the "bake_bread" process, and
that it takes place at a "bakery". If there's a bakery someplace in
the society, the flour gets moved there, and the baker can then bake
bread. Then, the baker puts the bread out for sale in her shop.

Also, while the mill is in existence, it could ask the society for
grain if it's not doing anything, which could make the society
create more wheat farms. And if the baker has no flour to make bread
with, it could ask the society to make more mills.

Anyway, you can do this kind of reasoning for most processes. The
idea is that complex things (like baking bread) can be broken down
into simpler processes where each process has some external raw
materials you need to get the building or factory up and running,
then it needs other raw materials for the actual construction. So,
the people who are running these processes don't really have to do
much thinking, they just have to know where the raw materials come
from, and where the finished products go to (and these are
determined externally as "known processes" that the mobs just
implement).

You can perform the same kind of analysis and decomposition to other
areas like making weapons (get minerals, refine them, create
weapons) and have the simple processes at each step again, and the
fact that when the mobs aren't getting what they need, they appeal
to the central society which magically assigns things to do those
jobs as people become available.


That I think is the key thing. The society wants bread so it starts
out making bakeries. Then, the bakeries realize since they're doing
the "bake" process that they need flour, so they tell the society to
give them flour. Then, the society looks at what makes flour and
realizes it needs mills, so it builds some mills. Then, the mills
realize that they need grain, so they complain to the society and
get farms created. I really think this kind of backward chaining
from the goal will let you make more complex processes, since the
society only has to think about planning for the final
products...and it can merely react to needs for other earlier
materials in the (well defined) process. It will still need to
prioritize goals and assignments of resources (people) but if it
only has to think about general categories like food and shelter, it
can make sure it assigns things to its most critical categories
first.

It will be slower than just building everything that it needs at
once, but it's also simpler and it will allow for much greater
interactions since if we wanted to make cornbread, the society would
only know that it needs "cornbread", and then the baker could know
it needs "cornmeal" and the mill would know to get "corn" to make
cornmeal...and the code is the same.


Anyway, there's a lot more that can be done here, but hopefully you
get the idea behind what I'm thinking about: make each mob have a
simple thing to do and make it request things from the society when
it needs them, and build things up from the finished products back
to the raw materials as needed.

John

_______________________________________________
MUD-Dev mailing list
MUD-Dev at kanga.nu
https://www.kanga.nu/lists/listinfo/mud-dev



More information about the MUD-Dev mailing list