1 /*
2  * Copyright 2011-2013 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 // Code: Cyril Meynier
44 //
45 // Copyright (c) 1999-2001 ARKANE Studios SA. All rights reserved
46 
47 #ifndef ARX_GUI_MINIMAP_H
48 #define ARX_GUI_MINIMAP_H
49 
50 #include <string>
51 #include <vector>
52 #include "math/MathFwd.h"
53 #include "gui/Interface.h"
54 #include "gui/Text.h"
55 #include "io/resource/PakReader.h"
56 #include "game/EntityManager.h"
57 #include "game/Player.h"
58 #include "graphics/data/Mesh.h"
59 
60 class TextureContainer;
61 struct SavedMiniMap;
62 
63 #define MINIMAP_MAX_X 50
64 #define MINIMAP_MAX_Z 50
65 #define MAX_MINIMAP_LEVELS 32
66 
67 class MiniMap {
68 
69 public:
70 
71 	//! MiniMap data
72 	struct MiniMapData {
73 
74 		TextureContainer* m_texContainer;
75 
76 		//! Start of scene pos x
77 		float m_offsetX;
78 		float m_offsetY;
79 
80 		//! Multiply x by ratioX to obtain real-world pos
81 		float m_ratioX;
82 		float m_ratioY;
83 
84 		//! Bitmap width/height
85 		float m_width;
86 		float m_height;
87 
88 		unsigned char m_revealed[MINIMAP_MAX_X][MINIMAP_MAX_Z];
89 
90 	};
91 
92 	//! Map markers
93 	struct MapMarkerData {
94 		float m_x;
95 		float m_y;
96 		int m_lvl;
97 		std::string m_name;
98 		std::string m_text;
99 	};
100 
101 	void mapMarkerRemove(const std::string &name);
102 	void mapMarkerAdd(float x, float y, int lvl, const std::string &name);
103 	void mapMarkerInit(size_t reserveSize = 0);
104 	size_t mapMarkerCount();
105 	MapMarkerData mapMarkerGet(size_t id);
106 
107 	void firstInit(ARXCHARACTER *pl, PakReader *pakRes, EntityManager *entityMng); // This should be a constructor
108 	void reset();
109 	void purgeTexContainer();
110 
111 	/*!
112 	* Calls revealPlayerPos if the player moved, also sets m_currentLevel and m_playerPos
113 	*
114 	* @param int currentLevel
115 	* @param long blockPlayerControls
116 	* @param ARX_INTERFACE_BOOK_MODE bookMode
117 	*/
118 	void validatePlayerPos(int currentLevel, long blockPlayerControls, ARX_INTERFACE_BOOK_MODE bookMode);
119 
120 	/*!
121 	* Shows the top right minimap
122 	*
123 	* @param int showLevel
124 	*/
125 	void showPlayerMiniMap(int showLevel);
126 
127 	/*!
128 	* Shows the zoomed-in minimap in the book
129 	*
130 	* @param int showLevel
131 	*/
132 	void showBookMiniMap(int showLevel);
133 
134 	/*!
135 	* Shows the entire map in the book
136 	*
137 	* @param int showLevel
138 	*/
139 	void showBookEntireMap(int showLevel);
140 
141 	//! Reveals entirely all levels
142 	void reveal();
143 
144 	void clearMarkerTexCont();
145 
146 	void load(const SavedMiniMap *saved, size_t size);
147 	void save(SavedMiniMap *toSave, size_t size);
148 
149 	void setActiveBackground(EERIE_BACKGROUND *activeBkg);
150 
151 private:
152 
153 	int m_currentLevel;
154 	EntityManager *m_entities;
155 	EERIE_BACKGROUND *m_activeBkg;
156 
157 	float m_miniOffsetX[MAX_MINIMAP_LEVELS];
158 	float m_miniOffsetY[MAX_MINIMAP_LEVELS];
159 	float m_mapMaxY[MAX_MINIMAP_LEVELS];
160 
161 	TextureContainer *m_pTexDetect;
162 	TextureContainer *m_mapMarkerTexCont;
163 
164 	ARXCHARACTER *m_player;
165 	float m_playerLastPosX;
166 	float m_playerLastPosZ;
167 
168 	/*const */float m_modX; // used everywhere, calculate it once
169 	/*const */float m_modZ; // should and will be const
170 
171 	std::vector<MapMarkerData> m_mapMarkers;
172 	MiniMapData m_levels[MAX_MINIMAP_LEVELS];
173 
174 	void getData(int showLevel);
175 	void resetLevels();
176 	void loadOffsets(PakReader *pakRes);
177 	void validatePos();
178 
179 	/*!
180 	* Reveals the direct surroundings of the player
181 	*
182 	* @param int showLevel
183 	*/
184 	void revealPlayerPos(int showLevel);
185 
186 	/*!
187 	* Gets the id from the MapMarker's name. Returns -1 when not found.
188 	*
189 	* @param std::string name
190 	* @return MapMarker's id (int).
191 	*/
192 	int mapMarkerGetID(const std::string &name);
193 
194 	Vec2f computePlayerPos(float zoom, int showLevel);
195 	void drawBackground(int showLevel, Rect boundaries, float startX, float startY, float zoom, float fadeBorder = 0.f, float decalX = 0.f, float decalY = 0.f, bool invColor = false, float alpha = 1.f);
196 	void drawPlayer(float playerSize, float playerX, float playerY, bool alphaBlending = false);
197 	void drawDetectedEntities(int showLevel, float startX, float startY, float zoom);
198 
199 };
200 
201 extern MiniMap g_miniMap;
202 
203 #endif // ARX_GUI_MINIMAP_H
204