forked from EmilyMansfield/citybuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.hpp
80 lines (59 loc) · 1.84 KB
/
map.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef MAP_HPP
#define MAP_HPP
#include <SFML/Graphics.hpp>
#include <string>
#include <map>
#include <vector>
#include "tile.hpp"
class Map
{
private:
void depthfirstsearch(std::vector<TileType>& whitelist,
sf::Vector2i pos, int label, int type);
public:
unsigned int width;
unsigned int height;
std::vector<Tile> tiles;
/* Resource map */
std::vector<int> resources;
unsigned int tileSize;
unsigned int numRegions[1];
/* 0 = Deselected, 1 = Selected, 2 = Invalid */
std::vector<char> selected;
unsigned int numSelected;
/* Select the tiles within the bounds */
void select(sf::Vector2i start, sf::Vector2i end, std::vector<TileType> blacklist);
/* Deselect all tiles */
void clearSelected();
/* Load map from disk */
void load(const std::string& filename, unsigned int width, unsigned int height,
std::map<std::string, Tile>& tileAtlas);
/* Save map to disk */
void save(const std::string& filename);
/* Draw the map */
void draw(sf::RenderWindow& window, float dt);
/* Checks if one position in the map is connected to another by
* only traversing tiles in the whitelist */
void findConnectedRegions(std::vector<TileType> whitelist, int type);
/* Update the direction of directional tiles so that they face the correct
* way. Used to orient roads, pylons, rivers etc */
void updateDirection(TileType tileType);
/* Blank map constructor */
Map()
{
this->numSelected = 0;
this->tileSize = 8;
this->width = 0;
this->height = 0;
this->numRegions[0] = 1;
}
/* Load map from file constructor */
Map(const std::string& filename, unsigned int width, unsigned int height,
std::map<std::string, Tile>& tileAtlas)
{
this->numSelected = 0;
this->tileSize = 8;
load(filename, width, height, tileAtlas);
}
};
#endif /* MAP_HPP */