Start using dynamic_casts where appropriate, cleaned up some bugs

This commit is contained in:
2011-07-01 23:24:41 -04:00
parent 2bdc7e0e59
commit 306f3d0c17
5 changed files with 10 additions and 12 deletions

View File

@ -41,7 +41,7 @@ Vertex* GameData::get_current_vertex(bool only_mine) const
if (only_mine)
{
if (current != NULL &&
current->colour == turn->get_colour()) return current;
dynamic_cast<GameVertex*>(current)->player == turn) return current;
return NULL;
}
@ -93,23 +93,17 @@ void GameData::handle_click(int x, int y)
else if (mode == MODE_ATTACK)
{
Vertex* v = vertex_at(x, y, 0);
if (v == NULL || v->colour == turn->get_colour()) return;
if (v == NULL || dynamic_cast<GameVertex*>(v)->player == turn) return;
if (v->colour != colour) attack_vertex(v);
}
}
bool GameData::select_vertex(int x, int y, bool only_mine)
bool GameData::select_vertex(int x, int y)
{
Vertex * v = vertex_at(x, y, 0);
if (v == NULL) return false;
if (only_mine && v->colour == turn->get_colour())
{
current = v;
return true;
}
current = v;
return true;
}
@ -141,7 +135,7 @@ bool GameData::add_vertex(int x, int y, int z, int r, int colour)
}
// same here - just a logic check
if (current->colour != turn->get_colour())
if (dynamic_cast<GameVertex*>(current)->player != turn)
{
delete v;
return false;
@ -243,7 +237,7 @@ void GameData::set_mode(Mode m)
if (current == NULL) return;
// The other modes all require current to match the player
if (current->colour == turn->get_colour()) mode = m;
if (dynamic_cast<GameVertex*>(current)->player == turn) mode = m;
}