This project was developed in C++ as I learnt how to implement A* Pathfinding.
The player’s stated goal is to use abilities to prevent either of the two AI controlled factions from defeating the other.
The Project
The project involves AI armies that quickly grow in size and strength, and then form squads to attack enemy buildings.
Each of the four armies begins by having its elemental patrol between their base and well, collecting resources to create new units.
As they do so, they'll also grow in strength and move to assault the enemy bases.
For more information on this process, please read the accordion tab named State Machines.
Mapping Tool
The greatest achievement in this project is the implementation of a Map Editor I made for a completely unrelated project in C#, using WinForms. The Map editor is designed to function similarly to RPGMaker's one, with users selecting tile types from a menu and laying them onto squares. Each tile the user places down also has an index layer, which is exported along with the Image, and is then fed into the A* pathfinding's node map.
All art used in this project was downloaded from opengameart.
The map tool was initially envisioned to create maps similar to ones seen in RPGs like Fire Emblem, or in RPGMaker maps.
Tiles are copied and pasted from a list onto the table, and their information has space for an optional name and tag. The tag is actually considered the most important part, as this is what is actually used by the agents to traverse the terrain.
When the map is completed, the users export the map as a single png image. When this is done, a text file containing the tag numbers of every tile in the map is also exported with the same name as the map. This is just a large table of something like:
1 0 1 0 0 0 1 1 1 1
0 1 1 1 1 0 0 0 0 1
, etc.
In the game I made, if a tile has a tag of 0, the tile is impassable. If a tag was 1, the space could be moved on freely. 2s and above could also be used to make forests that impede movement or the like.
So when the png is loaded in as the map, the table is also read in using a filestream, writing the numbers into an array of ints.
The code then runs a for loop through the rows and columns of the table, removing the ability for agents to enter nodes which have a tag of less than 1.
The code looks like this:
int inc = 0;
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
if (textVariables[inc]<1)
{
nodeList[i][j]->removeConnections();
}
++inc;
}
}
since the array taken from the text file, textVariables, is one-dimensional, inc is used to progress through it.
This gives the project the potential for more maps to be built, implemented, loaded in and set up without needing to heavily alter the code.
The development and implementation of state-based AI was the primary focus of this project. To accomplish this and the game's goals, the agents have been given five states.
In the gather state, agents run between the gathering point and the well, creating new allies and growing stronger as they do so. If the unit is attacked, it will retreat to the well and enter garrison state until it is safe. If it reaches a high enough level, it will enter the Attack state.
The attack state begins with the rally phase, wherein the agent will wait at the garrison and check the current states and levels of nearby units, recruiting them as allies if they're strong enough. Once enough time has passed, or the unit has a squad of 4 other followers, it departs the base, first checking the other base to see if it is in need of reinforcement, then moves towards the tower and attacks any defenders.
Agents in the follow state escort the leader which set them to this state, copying its movement and attack targets. If their leader is destroyed, any surviving followers will retreat to the base.
In the tower state, the agent has been assigned a position at one of the five spots around the tower. When a unit in this state attacks, other towered agents will attack the same target. Agents in the attack or attack follower state will enter this state when going near the tower if a spot is empty. Agents cannot run past this state until all five spots are manned by allied units.