1 /*
2 Copyright © 2011-2012 Clint Bellanger
3 Copyright © 2012-2013 Stefan Beller
4 Copyright © 2013 Henrik Andersson
5 Copyright © 2013-2016 Justin Jacobs
6 
7 This file is part of FLARE.
8 
9 FLARE is free software: you can redistribute it and/or modify it under the terms
10 of the GNU General Public License as published by the Free Software Foundation,
11 either version 3 of the License, or (at your option) any later version.
12 
13 FLARE is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 FLARE.  If not, see http://www.gnu.org/licenses/
19 */
20 
21 #ifndef MAP_H
22 #define MAP_H
23 
24 #include "CommonIncludes.h"
25 #include "EventManager.h"
26 #include "MapCollision.h"
27 #include "Utils.h"
28 
29 class Event;
30 class FileParser;
31 class StatBlock;
32 
33 class Map_Group {
34 public:
35 	std::string type;
36 	std::string category;
37 	Point pos;
38 	Point area;
39 	int levelmin;
40 	int levelmax;
41 	int numbermin;
42 	int numbermax;
43 	float chance;
44 	int direction;
45 	std::queue<FPoint> waypoints;
46 	int wander_radius;
47 	std::vector<StatusID> requires_status;
48 	std::vector<StatusID> requires_not_status;
49 	std::vector<StatusID> invincible_requires_status;
50 	std::vector<StatusID> invincible_requires_not_status;
51 
Map_Group()52 	Map_Group()
53 		: type("")
54 		, category("")
55 		, pos()
56 		, area(1,1)
57 		, levelmin(0)
58 		, levelmax(0)
59 		, numbermin(1)
60 		, numbermax(1)
61 		, chance(1.0f)
62 		, direction(-1)
63 		, waypoints(std::queue<FPoint>())
64 		, wander_radius(4)
65 		, requires_status()
66 		, requires_not_status()
67 		, invincible_requires_status()
68 		, invincible_requires_not_status() {
69 	}
70 };
71 
72 class Map_NPC {
73 public:
74 	std::string type;
75 	std::string id;
76 	FPoint pos;
77 	std::vector<StatusID> requires_status;
78 	std::vector<StatusID> requires_not_status;
79 
Map_NPC()80 	Map_NPC()
81 		: type("")
82 		, id("")
83 		, pos()
84 		, requires_status()
85 		, requires_not_status() {
86 	}
87 };
88 
89 class Map_Enemy {
90 public:
91 	std::string type;
92 	FPoint pos;
93 	int direction;
94 	std::queue<FPoint> waypoints;
95 	int wander_radius;
96 	bool hero_ally;
97 	bool enemy_ally;
98 	PowerID summon_power_index;
99 	StatBlock* summoner;
100 	std::vector<StatusID> requires_status;
101 	std::vector<StatusID> requires_not_status;
102 	std::vector<StatusID> invincible_requires_status;
103 	std::vector<StatusID> invincible_requires_not_status;
104 
105 	Map_Enemy(const std::string& _type="", FPoint _pos=FPoint())
type(_type)106 		: type(_type)
107 		, pos(_pos)
108 		, direction(rand() % 8)
109 		, waypoints(std::queue<FPoint>())
110 		, wander_radius(4)
111 		, hero_ally(false)
112 		, enemy_ally(false)
113 		, summon_power_index(0)
114 		, summoner(NULL)
115 		, requires_status()
116 		, requires_not_status()
117 		, invincible_requires_status()
118 		, invincible_requires_not_status() {
119 	}
120 };
121 
122 class Map {
123 protected:
124 	void loadHeader(FileParser &infile);
125 	void loadLayer(FileParser &infile);
126 	void loadEnemyGroup(FileParser &infile, Map_Group *group);
127 	void loadNPC(FileParser &infile);
128 
129 	void clearLayers();
130 	void clearQueues();
131 
132 	std::vector<StatBlock> statblocks;
133 
134 	std::string filename;
135 	std::string tileset;
136 public:
137 	Map();
138 	~Map();
getFilename()139 	std::string getFilename() { return filename; }
getTileset()140 	std::string getTileset() { return tileset; }
setTileset(const std::string & tset)141 	void setTileset(const std::string& tset) { tileset = tset; }
142 	void removeLayer(unsigned index);
143 
144 	int load(const std::string& filename);
145 
146 	std::string music_filename;
147 
148 	std::vector<Map_Layer> layers; // visible layers in maprenderer
149 	std::vector<std::string> layernames;
150 
151 	void clearEvents();
152 
153 	int addEventStatBlock(Event &evnt);
154 
155 	// enemy load handling
156 	std::queue<Map_Enemy> enemies;
157 	std::queue<Map_Group> enemy_groups;
158 
159 	// npc load handling
160 	std::queue<Map_NPC> npcs;
161 
162 	// map events
163 	std::vector<Event> events;
164 	std::vector<Event> delayed_events;
165 
166 	// intemap_random queue
167 	std::string intermap_random_filename;
168 	std::queue<EventComponent> intermap_random_queue;
169 
170 	// vars
171 	std::string title;
172 	unsigned short w;
173 	unsigned short h;
174 	bool hero_pos_enabled;
175 	FPoint hero_pos;
176 	std::string parallax_filename;
177 	Color background_color;
178 
179 };
180 
181 #endif // MAP_H
182