This is how is set up in general.
The NewtonAI is a self contained world for NewtonAIAgent veru much like the Newton world is a self contained world for rigid bodies.
The Newton AI manage only NewtonAI agents and these agents can be connected to other agent with a link the same way the Newton world connect bodies with joints.
These conception allow then use to establish relation between agents that can be permanent of temporal.
and agent can be anything, for example a particle, a rigid body, a sound, even an input handle.
what give personality to the NewtonAI agent is the user data is assigned to it.
If you look at the folder NewtonTool I am making a high level manage for the AI were stared some high level agents like the car and the player. In the future there will be other like navigation and Plath finding which I will use to demonstrate player and car demo.
The NewtonAI has an Update function, and it also has a special Agent call the GameStateAgent .
The Game state Agent is where the application code the General Game login that control the entire application. the update function for this agent is call first and then all of the update function for all other agents are call in a round robin way.
Basically the Agents system is a graph the connected all again and the Game state is always the root node of the graph.
Here is a example how it can work.
say you are making a first person shooter game.
you have firs game element that are all different and you need to relate the all together.
The first thing element is the general game control, This handles inputs, Cameral, the state of the game lake organizing enemies in grouo and so.
you code that is the call back of eth Game State Agent, you can have the Agent has a pointer to the Player Agent with is simple another Agent.
It does not know what the player is or how is suppose to work, it simple send signal to that agent if it has one, and hope the agent obey the order.
And example of that is you hit the key "pick weapon"
The Game state will read that key input, and after some process in it update function it determine that this key mean to tell the player to pick some weapon.
if the Game state agent has a pointer to a player, it will send the signal Pick weapon.
the play maybe have a way to pick weapon or may not.
Say for example this player have a way to pick weapon (and we will see how that work later)
The again will do that if it decided that this is a sensible order.
say that you have different player that do different action in respond to the same order.
for exampel for play A [pick weapon is pick a pistol. for player B it could be pick a rifle,
a player could be a transport vehicle an Pick weapon can be something else or simple ignored.
a player could be mu weapon guy an pick weapon can be cycling between weapon, and so on.
you can even implement a player who is a moron like Gomer Pyle and pick weapon is literally pick a weapon from the floor.
you can see that decoupling the Game logic from what you control already simply the logic. The strategy make it possible that the game can be impleneted even of eth player or the players do not exist yet.
Now let us say we make the Game player.
The Player is another AI Agent that can be link to a series of sub AI agent.
remember I mentioned that agent can be connected
The idea is taken from how the Brain of Mammal work. The brain is organize on layers.
Take for example the human brain, there are a few region that can be identified like the cerebral cortex, the locomotion system, immune system, vision, olfactory, etc
these layer function largely independent and they solve many of the mundane task by them self without telling the cerebral cortex what they did. However when it the present of some even that they do not know how to handle, they ask for the cerebral cortex for instructions. The cerebral cortex analyzed the event and mane order that part to do some action, or it may even order other systems to assist in respond to that event.
an example of that is the olfactory system.
Any mammal do not think about breading, they do it all the time while they are alive.
however of a mammal come across a smell they are not familiar to them, the cerebral cortex is immediately notified.
he cerebral cortex analyzed the signal and if for example the smell is something they smell before and was food, they order the locomotion system to head in the direction of the smell. They also order the olfactory system to focus of that smell so that the locomotion system can get better guidance.
If for example they smell is an odor but they have no record of it, the can order the sensory system to cover the nose, the also order all system to be causes and approach the in the direction of the event.
A smart cerebral cortex may record that event for future response.
If the event is form a predator and they had prior record, they may instruct the locomotion system to run away.
the small can be some harmful fume than can kill the against, and they may react to scape, or to protect. and so on.
This can extend to the vision system, the locomotion system and all other systems.
I hope that by now you start to get how an complex agent can be coded and they can be program to learn, or to be stupid, you can even make the evolve, for example the off ring of and agent can inherit the database of eth parent.
The way this is achieved with Newton AI is that the Agent represent the Brain system with AI against that are linked together.
Each one of these Sub agent have their own independent states that only respond to that system. They can even have sub AI agents than can do complex task and repot only to the parent AI, and example of that will be the new player.
If you look the class
- Code: Select all
class dAIAgentCharacterController: public dAIAgent
{
// locomotion states
class dLocomotionAgent: public dAIAgent
{
public:
enum
{
m_idle,
m_walk,
m_strafe,
};
dLocomotionAgent (dAI* const manager);
virtual ~dLocomotionAgent ();
virtual void Update (dFloat timestep, int threadID);
};
public:
dAIAgentCharacterController (dAI* const manager, NewtonBody* const playerBody);
virtual ~dAIAgentCharacterController ();
virtual void Update (dFloat timestep, int threadID);
dLocomotionAgent* m_locomotionSystem;
};
so far it only has a Locomotion subsystem, but I will add the sensory and some other optional
The Locomotion system is when a Newton Player controller will leave.
These system will use a physics join to make the player walk, run, swim, jump, and do all of the stuff a player do. It is here where all the stuff will be coordinated.
for example when the class dAIAgentCharacterController which is the cerebral cortex of the player tell the play walk in this direction, the dLocomotionAgent Agent will go about his business walking, so as alone ahs it does not get a different instruction it will be walking. The dLocomotionAgent will sue the physics engine to scan the environment (ray cast, convex cast and collision, etc) and as long as the input that it get is the same as the one if was given by the cerebral cortex, it will continue walking without tell anyone.
If the input it receives is for an obstacle or some different like a step, a ramp, a wall, another player, anything it will notify the cerebral cortex, dAIAgentCharacterController and way for instructions.
The cerebral cortex may not know what that is or it may know.
if it knows, say for example is a small object. an may decide to say continue walking, and it may send a signal to that other AI agent to be push away.
if the over is a step or a ramp, it will send the locomotion system to change to a sate to so that actions.
If the dAIAgentCharacterController get and instruction from another another Agent (the Game state for example) say the order is Jump.
The dAIAgentCharacterController will simple tell the Locomotion system to stops what was doing and do a jump.
The locomotion system will get the signal, and it may do immediately if is in condition to do so, or it may bring the action of the stuff that was doing to a point where the jump can be executed, or it may simple do nothing if it no capable of jumping.
does that gives you an idea?