Jump to content

  • Log In with Google      Sign In   
  • Create Account


Civilian AI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 DarkMage139   Members   -  Reputation: 294

Like
Likes
Like

Posted 03 February 2000 - 11:04 AM

I''m making an RPG that has plenty of civilians in it. My question is HOW DO I MAKE A "WANDERING" AI. The civilians are supposed to wander around aimlessly, but I don''t know how to write an AI for that. - DarkMage139

Sponsor:

#2 Sphet   Members   -  Reputation: 631

Like
Likes
Like

Posted 03 February 2000 - 11:14 AM

Randomless AI == rand() %8

If you have eight directions, do a rand(), mod it by 8, and use a switch statement to see what to do in each case:

switch (rand() % 8)
{
case 0: // go up
locationY--;
break;
case 1: // go up & right
locationY--;
locationX++;
break;
.. etc.

}

There''s nothing intelligent about it.

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 03 February 2000 - 03:35 PM

The other thing to do is to design some patterns for the people to follow. You can have some do circles, or whatever. Once you get numerous civilians, each running one of a few set patterns, it will seems like they are wandering around aimlessly.

You can make an array of integers, each with a number 1 throgh 8 (for the 8 directions described above). Then, each civilian has a pattern integer and location integer (the location in the pattern''s array) in the structure/class. You then use the code in the previous post to move the people around. Of course, when the pattern comes to completion, you reset the pattern location integer to 0. At this point in time, the civilian may or may not be in the same position he started. It doesn''t really matter, just be sure you don''t put a lot of the same numbers in the pattern, in case the civilian gets next to a wall or something.

This will add a little more control to what the civilians do.

Ben

#4 Woop   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 February 2000 - 10:21 PM

By ''wandering'' I assume you do not mean entirely random, just that you want them to look like they are going about their own business.

You could try a simple state-based system. Maybe a moving state and a choice state, or something like that.

Basically you could use the random idea from above each time the civilian is in the choice state, to select a direction to move in. From there the civilian switches into the moving state and might move in the random direction for ten spaces, or ten units of time or whatever.

Then they return to the choice state to make a new decision on direction.

Just an idea.

Woop

#5 Ferretman   GDNet+   -  Reputation: 276

Like
Likes
Like

Posted 06 February 2000 - 11:31 AM

quote:
Original post by DarkMage139

I''m making an RPG that has plenty of civilians in it. My question is HOW DO I MAKE A "WANDERING" AI. The civilians are supposed to wander around aimlessly, but I don''t know how to write an AI for that.

- DarkMage139


Hey DarkMage:


Well, I assume you''re after some behavior on the part of the NPCs that at least makes them look like they''re actually "living a life", right? The Ultima games do a pretty darn good job of that.

As one person already suggested, a simple state system can help you with this. Pick out a half-dozen occupations your NPCs will do in their village or town or whatnot, then set up a simple 3- or 4-state engine for each of them. For example, a ticket salesman at a railroad station might do the following:

State 1 (default) - Sits on bench at window waiting
to sell somebody a ticket.
State 2 - Puts up the "Went to Lunch" sign and walks
to the railroad cafeteria. Returns to ticket
counter.
State 3 - Sings a little diddy about a travelling
salesman and a minister''s daughter.
State 4 - Stands up in his office behind the counter
and shuffles some papers around; returns to State
1 when somebody comes up to buy a ticket.


A crude example, but with just a few of these you can quickly bring an area to life. Of course, if a player stands around forever and watches everybody he''ll sooner or later pick up the pattern--but if they just move through the railroad station en route to other areas of the game it''ll look pretty good.





Ferretman

From the High Mountains of Colorado


#6 DarkMage139   Members   -  Reputation: 294

Like
Likes
Like

Posted 07 February 2000 - 04:20 PM

Thanks for all those ideas, everyone!

- DarkMage139




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS