Put framework in place for dealing with graphs in 3 dimensions
This commit is contained in:
20
gamedata.cpp
20
gamedata.cpp
@ -38,7 +38,7 @@ void GameData::toggle_turn()
|
||||
void GameData::do_vertex(int x, int y, int r)
|
||||
{
|
||||
if (current != NULL &&
|
||||
(MathUtils::distance(current->x, current->y, x, y)
|
||||
(MathUtils::distance(current->x, current->y, current->z, x, y, 0)
|
||||
> get_range()))
|
||||
{
|
||||
select_vertex(x, y);
|
||||
@ -51,12 +51,12 @@ void GameData::do_vertex(int x, int y, int r)
|
||||
|
||||
if (mode == MODE_MOVE)
|
||||
{
|
||||
if (point_in_vertex(x, y)) select_vertex(x, y);
|
||||
else add_vertex(x, y, r, colour);
|
||||
if (point_in_vertex(x, y, 0)) select_vertex(x, y);
|
||||
else add_vertex(x, y, 0, r, colour);
|
||||
}
|
||||
if (mode == MODE_ATTACK)
|
||||
{
|
||||
Vertex* v = vertex_at(x, y);
|
||||
Vertex* v = vertex_at(x, y, 0);
|
||||
if (v == NULL) return;
|
||||
|
||||
if (v->colour == colour) select_vertex(x, y);
|
||||
@ -72,7 +72,7 @@ void GameData::select_vertex(int x, int y)
|
||||
cursor != vertices.end(); cursor++)
|
||||
{
|
||||
Vertex* v = *cursor;
|
||||
if ((MathUtils::distance(v->x, v->y, x, y) <= v->r) &&
|
||||
if ((MathUtils::distance(v->x, v->y, v->z, x, y, 0) <= v->r) &&
|
||||
(v->colour == PLAYER1_COLOUR && player == PLAYER1 ||
|
||||
v->colour == PLAYER2_COLOUR && player == PLAYER2))
|
||||
{
|
||||
@ -83,7 +83,7 @@ void GameData::select_vertex(int x, int y)
|
||||
}
|
||||
|
||||
|
||||
bool GameData::add_vertex(int x, int y, int r, int colour)
|
||||
bool GameData::add_vertex(int x, int y, int z, int r, int colour)
|
||||
{
|
||||
if (mode == MODE_ATTACK) return false;
|
||||
|
||||
@ -93,7 +93,7 @@ bool GameData::add_vertex(int x, int y, int r, int colour)
|
||||
if ((player == PLAYER1 && !player1_played) ||
|
||||
(player == PLAYER2 && !player2_played))
|
||||
{
|
||||
Graph::add_vertex(x, y, r, colour, 10);
|
||||
Graph::add_vertex(x, y, z, r, colour, 10);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "debug: GameData::add_vertex(): strength=%2.f\n",
|
||||
calculate_strength(*(vertices.rbegin())));
|
||||
@ -106,7 +106,7 @@ bool GameData::add_vertex(int x, int y, int r, int colour)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Graph::add_vertex(x, y, r, colour, 10, current))
|
||||
if (Graph::add_vertex(x, y, z, r, colour, 10, current))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "debug: GameData::add_vertex(): strength=%.2f\n",
|
||||
@ -191,7 +191,9 @@ int GameData::get_range(Vertex* node)
|
||||
cursor != neighbors.end(); cursor++)
|
||||
{
|
||||
Vertex* v = *cursor;
|
||||
range -= (100 - MathUtils::distance(v->x, v->y, node->x, node->y)) / 2;
|
||||
range -= (100 - MathUtils::distance(v->x, v->y, v->z,
|
||||
node->x, node->y, node->z))
|
||||
/ 2;
|
||||
}
|
||||
if (range < 0) range = 0;
|
||||
return range;
|
||||
|
Reference in New Issue
Block a user