1 /*
2 Copyright © 2011-2012 Clint Bellanger
3 Copyright © 2012 Stefan Beller
4 Copyright © 2013-2014 Henrik Andersson
5 Copyright © 2012-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 /**
22  * class MapRenderer
23  *
24  * Map data structure and rendering
25  * This class is capable of rendering isometric and orthogonal maps.
26  */
27 
28 #ifndef MAP_RENDERER_H
29 #define MAP_RENDERER_H
30 
31 #include "Camera.h"
32 #include "CommonIncludes.h"
33 #include "Map.h"
34 #include "MapCollision.h"
35 #include "MapParallax.h"
36 #include "TileSet.h"
37 #include "TooltipData.h"
38 #include "Utils.h"
39 
40 class FileParser;
41 class Sprite;
42 class WidgetTooltip;
43 
44 class MapRenderer : public Map {
45 private:
46 
47 	WidgetTooltip *tip;
48 	TooltipData tip_buf;
49 	Point tip_pos;
50 	bool show_tooltip;
51 
52 	bool enemyGroupPlaceEnemy(float x, float y, const Map_Group &g);
53 	void pushEnemyGroup(Map_Group &g);
54 
55 	void clearQueues();
56 
57 	void drawRenderable(std::vector<Renderable>::iterator r_cursor);
58 
59 	void renderIsoLayer(const Map_Layer& layerdata);
60 
61 	// renders only objects
62 	void renderIsoBackObjects(std::vector<Renderable> &r);
63 
64 	// renders interleaved objects and layer
65 	void renderIsoFrontObjects(std::vector<Renderable> &r);
66 	void renderIso(std::vector<Renderable> &r, std::vector<Renderable> &r_dead);
67 
68 	void renderOrthoLayer(const Map_Layer& layerdata);
69 	void renderOrthoBackObjects(std::vector<Renderable> &r);
70 	void renderOrthoFrontObjects(std::vector<Renderable> &r);
71 	void renderOrtho(std::vector<Renderable> &r, std::vector<Renderable> &r_dead);
72 
73 	void clearLayers();
74 
75 	void createTooltip(EventComponent *ec);
76 
77 	void getTileBounds(const int_fast16_t x, const int_fast16_t y, const Map_Layer& layerdata, Rect& bounds, Point& center);
78 
79 	void drawDevCursor();
80 	void drawDevHUD();
81 
82 	void drawHiddenEntityMarkers();
83 
84 	void checkHiddenEntities(const int_fast16_t x, const int_fast16_t y, const Map_Layer& layerdata, std::vector<Renderable> &r);
85 
86 	TileSet tset;
87 
88 	MapParallax map_parallax;
89 
90 	Sprite* entity_hidden_normal;
91 	Sprite* entity_hidden_enemy;
92 
93 	std::vector<std::vector<Renderable>::iterator> hidden_entities;
94 
95 public:
96 	// functions
97 	MapRenderer();
98 	~MapRenderer();
99 
100 	MapRenderer(const MapRenderer &copy); // not implemented
101 
102 	int load(const std::string& filename);
103 	void logic(bool paused);
104 	void render(std::vector<Renderable> &r, std::vector<Renderable> &r_dead);
105 
106 	void checkEvents(const FPoint& loc);
107 	void checkHotspots();
108 	void checkNearestEvent();
109 	void checkTooltip();
110 
111 	// some events are automatically triggered when the map is loaded
112 	void executeOnLoadEvents();
113 
114 	// some events are triggered on exiting the map
115 	void executeOnMapExitEvents();
116 
117 	// some events can trigger powers
118 	void activatePower(PowerID power_index, unsigned statblock_index, const FPoint &target);
119 
120 	bool isValidTile(const unsigned &tile);
121 	Point centerTile(const Point& p);
122 
123 	void setMapParallax(const std::string& mp_filename);
124 
125 	// cam is where on the map the camera is pointing
126 	Camera cam;
127 
128 	// indicates that the map was changed by an event, so the GameStatePlay
129 	// will tell the mini map to update.
130 	bool map_change;
131 
132 	MapCollision collider;
133 
134 	// event-created loot or items
135 	std::vector<EventComponent> loot;
136 	Point loot_count;
137 
138 	// teleport handling
139 	bool teleportation;
140 	FPoint teleport_destination;
141 	std::string teleport_mapname;
142 	std::string respawn_map;
143 	FPoint respawn_point;
144 
145 	// cutscene handling
146 	bool cutscene;
147 	std::string cutscene_file;
148 
149 	// stash handling
150 	bool stash;
151 	FPoint stash_pos;
152 
153 	// enemy clear
154 	bool enemies_cleared;
155 
156 	// event talker
157 	std::string event_npc;
158 
159 	// trigger for save game events
160 	bool save_game;
161 
162 	// map soundids
163 	std::vector<SoundID> sids;
164 
165 	// npc handling
166 	int npc_id;
167 
168 	// book from map event
169 	std::string show_book;
170 
171 	void loadMusic();
172 
173 	/**
174 	 * The index of the layer, which mixes with the objects on screen. Layers
175 	 * before that are painted below objects; Layers after are painted on top.
176 	 */
177 	unsigned index_objectlayer;
178 
179 	// flag used to prevent rendering when in maps/spawn.txt
180 	bool is_spawn_map;
181 };
182 
183 
184 #endif
185