-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.h
More file actions
196 lines (154 loc) · 5.76 KB
/
map.h
File metadata and controls
196 lines (154 loc) · 5.76 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef map_h
#define map_h
#include "object.h"
#include "character.h"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <map>
#include <cstdlib>
#include <iostream>
#include <sstream>
class JobMgr;
/********************************************************************/
struct TerrainType {
int red;
int green;
int blue;
int height;
std::string label;
};
class MapUtility {
public:
static TerrainType* readColorMap(const std::string& filename);
static bool saveColorMap(const std::string& filename, TerrainType* regions, int regionCount);
};
struct TileItem {
char name; // B for background, S for sol, M for mur, P for porte and F for fenetre
int type; // for example: 0 for water, 1 for sand, 2 for grass, ...
int value; // pixmap item
};
class Tile {
public:
enum Type { BLOCK, DOOR, FLOOR, EMPTY, WALL };
enum BType { NONE, WATER, SAND, DIRT, GRASS, ROCK, COAL, COPPER, IRON };
enum FType { METAL, PLASTIC };
public:
Tile(int id=0, Type cell_type=EMPTY, BType background_type=NONE, FType floor_type=METAL);
~Tile();
int id() const;
Type cell_type() const;
BType background_type() const;
FType floor_type() const;
int occurrences() const;
const std::vector<CountedItem>& counted_items() const { return counted_items_; }
std::vector<CountedItem>& counted_items() { return counted_items_; }
void setTile(int id, Type cell_type, BType background_type, FType floor_type);
void setCellTile(int id, Type cell_type);
void setBackgroundTile(int id, BType background_type);
void setFloorTile(int id, FType floor_type);
void setOccurrences(int value);
static std::string typeTileToString(Tile::Type type);
static std::string btypeTileToString(Tile::BType type);
static bool isWall(const Tile& tile);
static bool isFloor(const Tile& tile);
static bool isDoor(const Tile& tile);
void addItem(const BasicItem& item, int nb=1);
std::string removeItem(const BasicItem& item, int nb=1);
private:
int id_;
Type cell_type_;
int occurrences_;
BType background_type_;
FType floor_type_;
std::vector<CountedItem> counted_items_;
};
/********************************************************************/
class MapData {
public:
MapData(int width, int height);
~MapData();
const Tile& tile(int x,int y) const;
Tile& tile(int x,int y);
void addWall(int x, int y);
void removeWall(int x, int y);
void addFloor(int x, int y);
void removeFloor(int x, int y);
void addDoor(int x, int y);
void removeDoor(int x, int y);
void addGround(int x, int y);
void removeGround(int x, int y);
void addField(int x, int y);
void removeField(int x, int y);
void extractItemFromTile(int x,int y);
void cleanItemFromTile(int x,int y,Character* people);
void addObject(Object* object, int x, int y);
bool removeObject(int x, int y);
Object* getObject(Position tile_position);
bool store(const BasicItem& item, Position tile_position, int occurrence = 1);
std::vector<Object*>& objects() { return objects_; }
void reset(int width, int height);
int width() const { return width_; }
int height() const { return height_; }
void setMapImageName(const std::string& map_image_name);
const std::string& getMapImageName() const;
bool transferItems(Character* people);
void transferItems(Character* people, Chest* chest);
Object* getNearestChest(Position position);
bool removeItemFromChest(Position position, const BasicItem& item);
Object* getNearestEmptyChest(Position position, const BasicItem& item);
Object* getAssociatedChest(Position position);
void getEmptyGrassTilePosition(int& tile_x, int& tile_y);
static void createMap(MapData* data);
private:
int width_;
int height_;
std::string map_image_name_;
Tile* tiles_;
std::vector<Object*> objects_;
};
/********************************************************************/
class TileSetLib {
private:
TileSetLib();
~TileSetLib();
public:
static TileSetLib* instance();
static void kill();
static SDL_Texture* getTextureFromTile(const Tile& tile, SDL_Renderer* renderer);
SDL_Surface* tiles() { return tiles_surface_; }
SDL_Surface* walls() { return walls_surface_; }
SDL_Surface* doors() { return doors_surface_; }
SDL_Surface* grounds() { return grounds_surface_; }
std::map<int, SDL_Texture*>& mapOfTiles() { return mapOfTiles_; }
std::map<int, SDL_Texture*>& mapOfWalls() { return mapOfWalls_; }
std::map<int, SDL_Texture*>& mapOfDoors() { return mapOfDoors_; }
std::map<int, SDL_Texture*>& mapOfGrounds() { return mapOfGrounds_; }
private:
static TileSetLib* singleton_;
SDL_Surface* tiles_surface_;
SDL_Surface* walls_surface_;
SDL_Surface* doors_surface_;
SDL_Surface* grounds_surface_;
std::map<int, SDL_Texture*> mapOfTiles_;
std::map<int, SDL_Texture*> mapOfWalls_;
std::map<int, SDL_Texture*> mapOfDoors_;
std::map<int, SDL_Texture*> mapOfGrounds_;
};
/********************************************************************/
class PeopleGroup;
class GameBoard {
public:
GameBoard(PeopleGroup* group, MapData* data, JobMgr* manager);
~GameBoard();
void animate(double delay_ms);
MapData* data() const { return data_; }
PeopleGroup* group() const { return group_; }
JobMgr* jobManager() const { return job_mgr_; }
static GameBoard* cur_board;
protected:
PeopleGroup* group_;
MapData* data_;
JobMgr* job_mgr_;
};
/********************************************************************/
#endif // map_h