93 lines
2.0 KiB
C++
93 lines
2.0 KiB
C++
#ifndef MAP_H
|
|
#define MAP_H
|
|
|
|
#include "behavior.h"
|
|
|
|
class Dude;
|
|
|
|
struct Pixel
|
|
{
|
|
union PixelData {
|
|
int nbRes; // RESOURCES
|
|
char *knowledge; // LIBRARY
|
|
int teamId; // SPAWN
|
|
Dude *dudePtr; // DUDE
|
|
};
|
|
|
|
PixelType 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]; }
|
|
|
|
Coord &toreillerLoop(Coord &c)
|
|
{
|
|
while(c.x < 0)
|
|
c.x += m_width;
|
|
while(c.y < 0)
|
|
c.y += m_width;
|
|
// this is the shader implementation of the toreiller
|
|
Coord nbRevolutions(c.x/m_width, c.y/m_height);
|
|
if(std::abs(nbRevolutions.y % 2))
|
|
{
|
|
c.x += m_width/2;
|
|
nbRevolutions.x = c.x/m_width;
|
|
}
|
|
c -= Coord(nbRevolutions.x*m_width, nbRevolutions.y*m_height);
|
|
return c;
|
|
}
|
|
Coord toreillerLoop(const Coord &c)
|
|
{ Coord myCoord = c; toreillerLoop(myCoord); return myCoord; }
|
|
};
|
|
|
|
/**
|
|
* must be named "generate"
|
|
*/
|
|
typedef void (*GenerateFunction)(Map *map);
|
|
|
|
#endif // MAP_H
|