Inside our code, in aim to be able to implement these states machines, we are going to need a couple of classes. We call them auxiliary classes. The first class is CRebirth, which is a class which will allow us to insert into our game different positions inside the scene where both the enemies and the players can respawn. They are support points. Then we have CWaypoints Track class, which will load an *.XML file in which there will be many points, called waypoints, which will mark a path inside the scenario. So, understanding the difference between a waypoint and a track is as simple as imagining our scenario, which consists of many rooms. OK? The non-accessible zones can be these ones. These will be the non-accessible zones inside our scenario. So, what we will be doing is defining some waypoints. Waypoints are points inside our scenario where the bot will patrol. We could do something like this. If this is the first origin point, we will make it walk this way. These would be the waypoints to walk through our scene. So, these waypoints define a track. If we draw a line between each of these waypoints we will be telling our bot to go this way. In our case, this bot is going to patrol this track, this way. And if he reaches the end he will start again. So, these waypoints are going to define us a track, and we will do it through a Waypoint Track class. And these are the classes we are going to use as auxiliary classes. Let's go to the code to see how they are implemented. Let's finish with the 3D part. Let's go to the code, to the Logics part. There is Logic, and we see how we have the two classes we have mentioned. We have the Rebirth class, which is a class derived from XML Parser, so it gives it an XML file. And it will contain a list of positions inside the scene. If we go to our executable folder, Inside Data XML we have a file called Logic, where we can find all the Rebirth elements, the respawn positions. We have a tag called Rebirth and the XYZ positions of each one of those rebirths. In this case we have six rebirth points. In lines 2 to 7. This class will read the XML file and it will add each of these points to the Rebirth positions vector. Also, we will have the methods apart from the lLoadFind which gives the XML files, we have the method which adds a rebirth position, and we can also create an XML file to record the positions. And the one we are interested in is GetARandomRebirth which takes us back to a random position inside the positions list. And another method is the one which gives us back the number of rebirth positions. If we go to the CPP we see that the rebirth position will make the pushback of the vector in rebirth positions. Void rebirth uses C file structure to save a file to this position, and the LoadFile method makes its choice based on the XML file we give it. And in case we receive the Rebirth element, the onStartElement method reads the XYZ position as we give it the field attribute Pos. And from the position to the positions vectors using AddReversePosition method. And the last method is the GetARandomRebirthPosition which simply calculates a random value and takes out the module in full values depending on the size of ReversePosition's vector. And this will give us a random value on GetARandomRebirthPosition, an identifier. And we will see the position depending on the identifier going to the vector or the RebirthPosition list from lines 47 to 52. OK.. Waypoints Track also comes from the XML parser class, so there will be an XML file. In this case we have used the same XML file to read the rebirth and the waypoint tracks. If we go back to the logics file, we see we have a track. In this case we have created a track in which every waypoint is a point in the scenario. And the waypoints are set in a sequential way. This means, in aim to to to the 0 point. That is, the first point is the 0, then comes the next point, the next one and the next one. And bot has to go through these points in a sequential way. When it gets to the last point we go back to the first point. So this would be our track. If we go back to the C part, we have that our Waypoint Tracks has a waypoints vector, which is a positions vector. We have the onStartElement which is the place in which the XML Parser class method writes in aim to read the XML file. Builder-debuilder, LoadFile method which reads the XML file, AddWayPoint method which adds a waypoint to our track. We also have a WriteWaypointtoFile in aim to write the position of an XML file. The GetTheClosestWaypoint which gives us back the ID of the waypoint closest to a position. GetWaypointPosition which gives us back a waypoint's position based on its ID. GetNumWaypoints which gives us back the number of waypoints this track has. And GetNextWaypoint gives us back the ID next to the current waypoint, to the waypoint ID we have. So if I ask ID 0 for the next waypoint it will give us back the ID 1. If I ask the last waypoint for the next one, it will take us back to the first one. That's why we do this to simplify it. If we go to the class CPP we have that the builder and the debuilder don't do anything, they are empty. AddWaypoint adds the waypoint's position inside the vector, line 15. GetNextWaypoint, which is what we were talking on, takes us to the next waypoint. And in case I reach the end it takes me to the first waypoint. That is, if you are asking me for the next waypoint in the last one, it will take you back to the first one. In this case it's 21 and 22 condition. WriteWaypointToFile which again didn't save any data in the XML file we have used. The LoadFile waypoint method, which uses the XMLParselFile method in aim to read the XML file. And the onStartElement method we have overwritten, which will, in case we get the tag waypoint in line 44, read the XYZ position in the XML's Pos attribute and we add the Pos to the waypoints vector through the AddWayPoints method, in line 48. The next method, which is GetTheClosestWaypoint, calculates the distance from the position we give it to each of the waypoints and gives back the closest waypoint's ID. That is, the one which has the less distance to this position. To do so it goes through all the waypoints and decides which is the closest one to this position. And then we have the GetWaypointPosition, to which we give the waypoint's ID and which gives us back the geometrical position in this waypoint's scenario depending on its ID.