2019-08-05 14:32:22 +02:00
|
|
|
#include "map.h"
|
2019-08-06 13:45:02 +02:00
|
|
|
#include "item.h"
|
|
|
|
#include <gint/std/string.h>
|
2019-08-05 14:32:22 +02:00
|
|
|
|
|
|
|
|
2019-08-06 13:45:02 +02:00
|
|
|
#define DIM_X 5
|
|
|
|
#define DIM_Y 5
|
|
|
|
|
|
|
|
// la map correspond à un système par couches successives :
|
|
|
|
|
|
|
|
// fond de carte => terrain constructible ou pas, accessible ou pas...
|
|
|
|
// les items (troupes, maisons, routes, murs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generic_map map[DIM_Y][DIM_X];
|
|
|
|
void create_map()
|
2019-08-05 14:32:22 +02:00
|
|
|
{
|
2019-08-06 13:45:02 +02:00
|
|
|
// effacement
|
|
|
|
for (int x=0;x<DIM_X;x++)
|
|
|
|
{
|
|
|
|
for (int y=0;y<DIM_Y;y++)
|
|
|
|
{
|
|
|
|
map[y][x].terrain=EARTH;
|
|
|
|
map[y][x].explored=false;
|
|
|
|
map[y][x].item.type=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ajout du village allié et de la zone d'exploration
|
|
|
|
|
|
|
|
// ajout du village ennemi
|
|
|
|
|
|
|
|
// ajout des bords
|
|
|
|
for (int x=0;x<DIM_X;x++)
|
|
|
|
{
|
|
|
|
map[0][x].terrain=WATER;
|
|
|
|
map[DIM_Y-1][x].terrain=WATER;
|
|
|
|
}
|
|
|
|
for (int y=0;y<DIM_Y;y++)
|
|
|
|
{
|
|
|
|
map[y][0].terrain=WATER;
|
|
|
|
map[y][DIM_X-1].terrain=WATER;
|
|
|
|
}
|
|
|
|
|
|
|
|
map[0][0].item.type=WALL;
|
|
|
|
map[0][1].item.type=WALL;
|
|
|
|
map[0][2].item.type=WALL;
|
|
|
|
|
|
|
|
map[2][0].item.type=WALL;
|
|
|
|
map[2][1].item.type=WALL;
|
|
|
|
map[2][2].item.type=WALL;
|
|
|
|
|
|
|
|
map[1][0].item.type=WALL;
|
|
|
|
map[1][2].item.type=WALL;
|
2019-08-06 16:15:34 +02:00
|
|
|
map[1][1].item.type=HOUSE;
|
|
|
|
|
|
|
|
map[3][1].item.type=HOUSE;
|
|
|
|
map[3][2].item.type=HOUSE;
|
|
|
|
map[4][2].item.type=HOUSE;
|
2019-08-05 14:32:22 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 13:45:02 +02:00
|
|
|
|
|
|
|
int dx=0, dy=0; // delta(en items) pour l'affichage
|
|
|
|
|
|
|
|
generic_item* get_item(int x, int y)
|
|
|
|
{
|
2019-08-06 16:15:34 +02:00
|
|
|
if (x<0||x>=DIM_X||y<0||y>=DIM_Y)
|
2019-08-06 13:45:02 +02:00
|
|
|
return 0;
|
|
|
|
return &map[y][x].item;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get_visibility(int x, int y)
|
|
|
|
{
|
|
|
|
if (x<0||x>=DIM_X||y<0||y>DIM_Y)
|
|
|
|
return true;
|
|
|
|
return 1-map[y][x].explored;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_item(int x, int y, generic_item const * const item)
|
|
|
|
{
|
|
|
|
if (x<0||x>=DIM_X||y<0||y>DIM_Y)
|
|
|
|
return;
|
|
|
|
memcpy(&map[y][x].item,item,sizeof(generic_item));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void display()
|
2019-08-05 14:32:22 +02:00
|
|
|
{
|
2019-08-06 13:45:02 +02:00
|
|
|
dclear(C_WHITE);
|
|
|
|
for (int x=0;x<16;x++)
|
|
|
|
{
|
|
|
|
for (int y=0;y<8;y++)
|
|
|
|
{
|
|
|
|
display_case(x-dx,y-dy,8*x,8*y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dupdate();
|
2019-08-05 14:32:22 +02:00
|
|
|
}
|