treewars/gamedata.h

78 lines
1.9 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=0x1, MODE_ATTACK=0x2, MODE_BUILD=0x4, MODE_SELECT=0x8};
enum VertexType {VERTEX_NONE=0x1, VERTEX_ATTACKER=0x2, VERTEX_DEFENDER=0x4,
VERTEX_PRODUCER=0x8};
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);
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);
VertexType get_build_type() const { return build_type; }
void set_build_type(VertexType type) { build_type = type; }
// 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;
Player player1, player2;
Player* turn;
Mode mode;
VertexType build_type;
static int PLAYER1_COLOUR;
static int PLAYER2_COLOUR;
static int BASE_BUILD_RADIUS;
static int NODE_RADIUS;
};
#endif