treewars/gamedata.h

72 lines
1.7 KiB
C++

/* This takes the general graph code and does stuff specific to the game
* with it. It stores the current turn, selected vertex and other useful
* information
*/
#ifndef _GAMEDATA_H_
#define _GAMEDATA_H_
#include "graph.h"
#include "player.h"
enum Mode {MODE_MOVE, MODE_ATTACK, MODE_BUILD, MODE_SELECT};
enum VertexType {VERTEX_ATTACKER, VERTEX_DEFENDER, VERTEX_PRODUCER};
class GameVertex : public Vertex
{
public:
GameVertex(int x, int y, int z, int r, int colour = 0, int score = 0,
VertexType type = VERTEX_ATTACKER, Player* player = NULL);
VertexType type;
Player* player;
};
class GameData : public Graph
{
public:
GameData();
~GameData();
Vertex* get_current_vertex(bool only_mine = false) const;
void clear_current_vertex();
void toggle_turn();
// select or add vertex, as appropriate
void handle_click(int x, int y);
bool select_vertex(int x, int y, bool only_mine = false);
void attack_vertex(Vertex* target);
bool add_vertex(int x, int y, int z, int r, int colour);
Mode get_mode() const { return mode; }
void set_mode(Mode m);
// returns the move/attack range for the specified node
// (or the selected node if node == NULL)
int get_range(Vertex* node = NULL);
// check for (and set, if needed) winner
bool endgame();
Player* get_turn() const { return turn; }
float calculate_strength(Vertex* node);
float calculate_armor(Vertex* node);
private:
float calculate_strength_r(Vertex* node, unsigned int depth, list<Vertex*>& visited);
Vertex* current;
Mode mode;
Player player1, player2;
Player* turn;
static int PLAYER1_COLOUR;
static int PLAYER2_COLOUR;
static int BASE_BUILD_RADIUS;
static int NODE_RADIUS;
};
#endif