77 lines
1.5 KiB
C++
77 lines
1.5 KiB
C++
#ifndef MAP_H
|
|
#define MAP_H
|
|
|
|
#include "coord.h"
|
|
|
|
struct Pixel
|
|
{
|
|
enum Type {
|
|
BEDROCK, GRASS, TREE, BERRIES, ROCK, IRON_ORE, // nature
|
|
FOOD, WOOD, STONE, IRON, SWORD, // resources
|
|
DUDE, DEAD_DUDE, // humans
|
|
SPAWN, WALL, ROAD, MARK, LIBRARY // buildings
|
|
};
|
|
|
|
union PixelData {
|
|
int nbRes;
|
|
void* knowledge;
|
|
};
|
|
|
|
Type type;
|
|
PixelData data;
|
|
|
|
Pixel() : type(GRASS) {}
|
|
};
|
|
|
|
class Map
|
|
{
|
|
Pixel *m_map;
|
|
Coord *m_teams;
|
|
|
|
int m_width;
|
|
int m_height;
|
|
int m_nbTeams;
|
|
|
|
public:
|
|
Map(int nbTeams, int width, int height = 0);
|
|
~Map();
|
|
|
|
int getWidth() const { return m_width; }
|
|
int getHeight() const { return m_height; }
|
|
int getNbTeams() const { return m_nbTeams; }
|
|
|
|
/**
|
|
* Teams accessers :
|
|
*/
|
|
|
|
Coord & team(int i)
|
|
{ return m_teams[i]; }
|
|
|
|
/**
|
|
* Pixel accessers :
|
|
*/
|
|
|
|
Pixel &getPixel(int x, int y)
|
|
{ return m_map[m_height*x + y]; }
|
|
Pixel &getPixel(const Coord &c)
|
|
{ return m_map[m_height*c.x + c.y]; }
|
|
|
|
/**
|
|
* @brief operator [] allows to access a pixel of the map with the following syntax :
|
|
* Pixel &p = map[x][y];
|
|
* or
|
|
* Pixel &p = map[Coord(x, y)];
|
|
*/
|
|
Pixel* operator[](int i)
|
|
{ return m_map + m_height*i; }
|
|
Pixel &operator[](const Coord &c)
|
|
{ return m_map[m_height*c.x + c.y]; }
|
|
};
|
|
|
|
/**
|
|
* must be named "generate"
|
|
*/
|
|
typedef void (*GenerateFunction)(Map *map);
|
|
|
|
#endif // MAP_H
|