Task Parsing (repost for format)

Stephen Zepp zoran at enid.com
Sun Dec 28 13:35:23 CET 1997


Jon A. Lambert said,

How do AI nodes work?  That's one topic I haven't a clue on.  The only
poster I'm aware of who seems to have a good handle on this is Nathan.
After exploring some of the AI/ANN web sites, I think I understand why
why there hasn't been much in-depth discussion of the topic.  

Disclaimer:  This is probably not the book answer.  This is one hobbyist coder's attempt to do cool things with estates.
NOTE: sorry about the repost, I am _still_ trying to figure out how to get Nescape Communicator mailer to format
properly.

I sort of misspoke.  At the moment, I'm actually working on the task handler portion, which is not a true ai, as the
actor doesn't actually make any goal oriented decisions.

However, here is what I'm working on: :)
        I have an estate management system which let's players attract populations, hire workgroups, build buildings,
and expand their estate.  Workgroups can be assigned to harvest resources from the terrain around them, carry them to
buildings which process them into refined resources, or items ( lumbermill turns raw lumber into boards, smithy makes a
shortsword from 3 iron, or a breastplate from 5 iron 2 leather 1 cloth ), or use them to construct new buildings with
various effects.
        Currently, players (or npcs, though that's the ai part that is still in design ) may assign a specific workgroup
a task such as:
  harvest lumber
  patrol from path1 to path2 to path3 to path1
  build fountain at location1

Currently what I'm tuning is the assignment task parser, which breaks a seemingly simple task like harvest lumber into:
  seek work find lumber process lumber deliver lumber repeat all

seek work:  sends to the workgroup back to their assigned workplace, to serve as a starting point.
find lumber:  checks their info nodes to see if they know of a specific place to find lumber ( a lumber resource site ).
If so, hunt that room, if not, enter a search pattern
process lumber:  work the resource site, and pick up the lumber when it is finally produced
deliver lumber: hunt their workplace, then either place all the lumber they have in storage ( storage building ) or drop
it, as appropriate
repeat all:  self explanatory

        To handle this expanded task string, the code calls a function that parses the various sub tasks into what I
call ai nodes, which construct the various state machine values for processing, such as:
"seek work" becomes:
 ai_node_goal_type AI_GOAL_SEEK_ROOM
 ai_node_target_type AI_TARGET_TYPE_ROOM
 ai_node_target (room_index_data *) target = ( known information about a lumber site from the ai info list of the actor
)
 ai_node_status AI_STATUS_WORKING

We then add that node to the actors ai->node_list, and continue on until the task string is empty.

>From there, you parse the node on top of the ai_node list, run it through the task handler state machine ( which is
really just a huge set of nested switch statements ), and the workgroup is on it's way.

I'm currently working on message handling between actors ( wg A is attempting to build a wall, but needs 3 more stone.
Currently, they inject a harvest stone task in front of the build wall task, and start working on that next iteration.
What I want to do is to send a message back to the estate itself requesting stone, and the message handler will find
idling workgroups that haven't been reserved, and assign them that task.  This is where the goal setting/goal handling
portion is starting to come in, which to me is all the AI I really need at the moment.

In many ways, this could be handled within the Merc mob prog enhancement ( or whatever you have for "programming" mobs
), but it is a lot more generic, pulling most of the information one level up so that it can be used with any actor_type
( ACTOR_TYPE_ROOM, ACTOR_TYPE_ESTATE, ACTOR_TYPE_WORKGROUP are all valid, just need to alias their specfic data into the
state maching properly ).  I'm having some difficulties with re-ordering goal priorities, which are going to become more
important when this system is used from the npc standpoint.

        As an aside, this all resulted from wanting to have a resource based economy, and not having many builders for
my game persist ( they all give up, it's too much work :P )...the system is designed to take a terrain map, and allow
the system to build an explorable, operating "area" out of it, wether it be a city, cavern, ship, whatever.  All world
objects are created using this system, and while very rough, the economy runs off of it at the moment.  Trade, including
barter and regional exchange is in the works, along with pretty much anything that you would need to do as an estate
manager.  It's
fun, too :)

Z



More information about the mud-dev-archive mailing list