Created GameVertex class so that we can store game-specific data in the vertices

This commit is contained in:
2011-07-01 22:04:58 -04:00
parent e221f1990c
commit a2f36a447b
4 changed files with 39 additions and 11 deletions

View File

@ -14,6 +14,15 @@ int GameData::BASE_BUILD_RADIUS = 75;
int GameData::NODE_RADIUS = 10;
GameVertex::GameVertex(int x, int y, int z, int r, int colour, int score,
VertexType type, Player* player)
: Vertex(x, y, z, r, colour, score)
{
this->type = type;
this->player = player;
}
GameData::GameData()
: Graph(true)
{
@ -108,12 +117,15 @@ bool GameData::select_vertex(int x, int y, bool only_mine)
bool GameData::add_vertex(int x, int y, int z, int r, int colour)
{
GameVertex* v = new GameVertex(x, y, z, r, colour, 10, VERTEX_ATTACKER,
turn);
if (current == NULL)
{
// this is the special case for adding the first vertex for each player
if (!turn->has_played())
{
if (Graph::add_vertex(x, y, z, r, colour, 10))
if (Graph::add_vertex(v))
{
#ifdef DEBUG
fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n", calculate_strength(*(vertices.rbegin())));
@ -124,17 +136,26 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
}
// really, we shouldn't be able to get here. return false just in case
delete v;
return false;
}
// same here - just a logic check
if (current->colour != turn->get_colour()) return false;
if (current->colour != turn->get_colour())
{
delete v;
return false;
}
// This is the range check...
if (MathUtils::distance(current->x, current->y, 0, x, y, 0) > get_range())
if (MathUtils::distance(current->x, current->y, 0, v->x, v->y, 0) >
get_range())
{
delete v;
return false;
}
if (Graph::add_vertex(x, y, z, r, colour, 10, current))
if (Graph::add_vertex(v, current))
{
#ifdef DEBUG
fprintf(stderr, "debug: GameData::add_vertex(): strength=%.2f\n",
@ -144,6 +165,8 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
toggle_turn();
return true;
}
delete v;
return false;
}