AI Project Blog
AI Project Blog
|Posted by Heem on 10 March, 2014 at 1:20|
So , you ask how the project has been going? Well, I have been working hard on it since last week and I can say that the three most important systems of my project have been implemented. The three systems being StateMachine Handler, Steering Behavoir Manager, and Message Passing system.
I tested the three systems and they are working great! One of the aims for me while making these systems was to make them modular and independant of each other, and I can say that they are. So how do they work you might ask? Let me describe them to you one by one -
Steering Behaviors -
So for this system, I create a normal class and used it as an object in the Players class. The steeringBehavior class has a member in it called m_pOwner which basically maintains a pointer to the player it is associated with. So now, all I need to do is turn on the behavior in the steeringBehavior object of that player. So for e.g. in order to purse the ball I would have the following call -
playerObj->getSteeringBehaviour()->setTarget( ballObj );
This works because in every update call of the player , a call to calculateForces() function present in the SteeringBehavior is made. This function takes care of updating the velocity of the m_pOwner member, as a result the playerObj's velocity gets updated.
The behaviors I have implemented are pusuit, arrive and interpose.
So this one was a littel bit tricky, because there are three classes which basically have a state machine associated with them i.e. FieldPlayers , GoalKeeper ( both of these classes inherit from Players ) and Teams. So what I did is I made an abstract template class called State<T> which had three functions enter(), execute() and exit(). Now, I made another class called StateMachine, which had an objects of State i.e. currentState, and previousState. Now, in the update function of StateMachine, I called the updateFunction of that particular state. This way, all I had to do was have an object of StateMachine in whichever class I needed.
now you may ask, that how did I manage different States? and Why is there a different State class? Well, for that I made classes whihc would inherit from that state class.So for e.g. goalKeeper had state classes such as GoalKeeperReturnHome: public State<GoalKeeper>.
What this allowed me to do was have a set of different states for each of my classes that required a StateMachine. This way, I managed to create a single system that could be used by more than one entity.
Message Passing System
So, for this I had to create a data structure for messages. For that I created a class called Message which had sender, receiver ( both of type baseGameEntity ) , MessageType , delayForMessage and extraInfo ( which was of type void* , and could be used to send any object ) .
Now, I created a singleton class called MessageDispatcher, this had three functions - dispatchMessage, dispatchDelayedMessage and sendMessage. Send MEssage basicallay called the handleMessage of the receiver . dispatchMessage would calle the function sendMessage immediately procided the delay was 0, other wise it would store the message in a priority queue and the function dispatchDelayedMessage would handle it and send it after the amount of delay that was specified in the message.
Since the BaseGameEntity had a purely virtual function of HandleMessage, all the classes that inherited from it had the ability to send messages. If a particular class did not have any message to handle, it would simply return false and it would mean that there is somethign wrong in the way the game has been programmed because its an exception.
So that describes the 3 main systems that consist of my project. I should now finally be able to move on to coding the behavior and reaction of the agents. Fun!
PS: I was going through my code yesterday and realized that I had about 23 header files, about 19 source files and almost about 2500 lines of code