Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / server_share / continent_container.h
blob0b4ad40f38325e041e1837bb6381c7887ddb88b2
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef NL_CONTINENT_CONTAINER_H
23 #define NL_CONTINENT_CONTAINER_H
25 // Nel Misc
26 #include "nel/misc/types_nl.h"
27 #include "nel/misc/smart_ptr.h"
28 #include "nel/misc/vectord.h"
29 #include "nel/misc/sheet_id.h"
30 #include "nel/misc/log.h"
31 #include "nel/misc/entity_id.h"
33 // Nel Georges
34 #include "nel/georges/u_form.h"
35 #include "nel/georges/u_form_elm.h"
37 // Nel Pacs
38 #include "nel/pacs/u_move_container.h"
39 #include "nel/pacs/u_move_primitive.h"
40 #include "nel/pacs/u_retriever_bank.h"
41 #include "nel/pacs/u_global_retriever.h"
42 #include "nel/pacs/u_global_position.h"
43 #include "nel/pacs/u_primitive_block.h"
45 /**
46 * <Class description>
47 * \author Benjamin Legros
48 * \author Nevrax France
49 * \date 2001
51 class CContinentContainer
53 protected:
54 /// Container of continent
55 class CContinentMoveContainer
57 public:
58 CContinentMoveContainer() : GlobalRetriever(NULL), RetrieverBank(NULL), MoveContainer(NULL), AllowAutoSpawn(false) {}
59 /// Then name of the continent
60 std::string Name;
61 /// The PACS global retriever for this continent
62 NLPACS::UGlobalRetriever *GlobalRetriever; // Global retriever retrieved surfaces of all territory
63 /// The PACS retriever bank for this continent
64 NLPACS::URetrieverBank *RetrieverBank; // Bank of global retriever
65 /// The PACS move container for this continent
66 NLPACS::UMoveContainer *MoveContainer; // Move container
67 /// True if entities are allowed to try spawning in this continent if no continent index is provided
68 bool AllowAutoSpawn;
71 ///
72 class CSheet
74 public:
75 CSheet() {}
77 std::string Name;
78 std::string PacsRBank;
79 std::string PacsGR;
80 std::string LandscapeIG;
81 std::vector<std::string> ListIG;
83 void readGeorges (const NLMISC::CSmartPtr<NLGEORGES::UForm> &form, const NLMISC::CSheetId &sheetId)
85 Name = sheetId.toString();
86 // the form was found so read the true values from George
87 form->getRootNode ().getValueByName (PacsRBank, "PacsRBank");
88 form->getRootNode ().getValueByName (PacsGR, "PacsGR");
89 form->getRootNode ().getValueByName (LandscapeIG, "LandscapeIG");
92 NLGEORGES::UFormElm *node;
93 uint numVillages, numIgs;
95 if (form->getRootNode().getNodeByName(&node, "Villages") && node &&
96 node->getArraySize(numVillages))
98 for (uint village=0; village<numVillages; ++village)
100 if (form->getRootNode ().getNodeByName(&node, NLMISC::toString("Villages[%d].IgList", village).c_str()) && node &&
101 node->getArraySize(numIgs))
103 for (uint ig=0; ig<numIgs; ++ig)
105 std::string igName;
106 if (form->getRootNode ().getValueByName(igName, NLMISC::toString("Villages[%d].IgList[%d].IgName", village, ig).c_str()))
107 ListIG.push_back(igName);
115 void serial (NLMISC::IStream &s)
117 s.serial(Name);
118 s.serial(PacsRBank, PacsGR, LandscapeIG);
119 s.serialCont(ListIG);
122 static uint getVersion () { return 1; }
124 void removed() {}
127 /// The global continent container
128 typedef std::vector<CContinentMoveContainer> TContinentContainer;
131 typedef std::map<std::string, NLPACS::UPrimitiveBlock*> TPacsPrimMap;
134 typedef std::map<uint, NLMISC::CVectorD> TTriggerMap;
136 /// the continents
137 TContinentContainer _Continents;
139 /// pacs primitives
140 TPacsPrimMap _PacsPrimMap;
142 /// Sheet map type
143 typedef std::map<NLMISC::CSheetId, CSheet> TSheetMap;
146 TSheetMap _SheetMap;
149 TTriggerMap _TriggerMap;
152 uint _GridWidth;
153 uint _GridHeight;
154 double _CellSize;
155 double _PrimitiveMaxSize;
156 uint _NbWorldImages;
158 /// Should load dynamic collision (e.g. trees)
159 bool _LoadPacsPrims;
161 public:
163 /// Constructor
164 CContinentContainer();
166 /// Init whole continent container
167 void init(uint gridWidth, uint gridHeight, double primitiveMaxSize, uint nbWorldImages, const std::string &packedSheetsDirectory, double cellSize=0.0, bool loadPacsPrims = true);
169 /// Build sheets
170 void buildSheets(const std::string &packedSheetsDirectory);
172 /// Init pacs prims
173 void initPacsPrim(const std::string &path = std::string("landscape_col_prim_pacs_list.txt"));
176 /// Load continent
177 void loadContinent(std::string name, std::string file, sint index, bool allowAutoSpawn = true);
179 /// Remove continent
180 void removeContinent(sint index);
183 /// Get move container for continent
184 NLPACS::UMoveContainer *getMoveContainer(sint index)
186 if (index < 0 || index >= (sint)_Continents.size())
188 nlwarning("getMoveContainer(): invalid index %d", index);
189 return NULL;
191 return _Continents[index].MoveContainer;
194 /// Get move container for continent
195 NLPACS::UGlobalRetriever *getRetriever(sint index)
197 if (index < 0 || index >= (sint)_Continents.size())
199 nlwarning("getRetriever(): invalid index %d", index);
200 return NULL;
202 return _Continents[index].GlobalRetriever;
205 /// Get move container for continent
206 NLPACS::URetrieverBank *getRetrieverBank(sint index)
208 if (index < 0 || index >= (sint)_Continents.size())
210 nlwarning("getRetriverBank(): invalid index %d", index);
211 return NULL;
213 return _Continents[index].RetrieverBank;
217 /// Find continent to spawn in
218 sint findContinent(const NLMISC::CVectorD &worldPosition, const NLMISC::CEntityId& id = NLMISC::CEntityId::Unknown)
220 sint continent = -1;
221 // finds the continent that fits given position
222 uint i;
223 for (i=0; i<_Continents.size(); ++i)
225 if (_Continents[i].GlobalRetriever == NULL ||
226 !_Continents[i].AllowAutoSpawn)
227 continue;
229 NLPACS::UGlobalPosition globalPosition = _Continents[i].GlobalRetriever->retrievePosition(worldPosition);
230 if (globalPosition.InstanceId != -1 && globalPosition.LocalPosition.Surface != -1)
232 if (continent != -1)
234 nlwarning("findContinent%s: continent not provided, and sole position (%.3f, %.3f, %.3f) refers to several continents (%d, %d) -- use first found",
235 id.toString().c_str(),
236 worldPosition.x, worldPosition.y, worldPosition.z,
237 i, continent);
238 continue;
241 continent = i;
245 if (continent == -1)
247 if (worldPosition.x != 0.0 || worldPosition.y != 0.0 || worldPosition.z != 0.0)
248 nlwarning("findContinent%s: can't find best fitting continent for position (%.3f, %.3f, %.3f) -- use first available continent", id.toString().c_str(), worldPosition.x, worldPosition.y, worldPosition.z);
250 for (uint i=0; i<_Continents.size(); ++i)
252 if (_Continents[i].MoveContainer != NULL)
254 continent = i;
255 break;
260 return continent;
263 /// Get container size
264 sint size() const { return (sint)_Continents.size(); }
266 /// clear the container -- WARNING
267 void clear()
269 uint i;
270 for (i=0; i<_Continents.size(); ++i)
271 removeContinent(i);
272 _Continents.clear();
275 /// get trigger position
276 NLMISC::CVectorD getTriggerPosition(uint i) const
278 TTriggerMap::const_iterator it = _TriggerMap.find(i);
279 return (it == _TriggerMap.end()) ? NLMISC::CVectorD::Null : (*it).second;
282 /// Display triggers
283 void displayTriggers(NLMISC::CLog *log = NLMISC::InfoLog) const
285 TTriggerMap::const_iterator it;
286 for (it=_TriggerMap.begin(); it!=_TriggerMap.end(); ++it)
287 log->displayNL("Trigger %d: (%.3f, %.3f, %.3f)", (*it).first, (*it).second.x, (*it).second.y, (*it).second.z);
290 protected:
292 void loadPacsPrims(const CSheet &sheet, NLPACS::UMoveContainer *moveContainer);
296 #endif // NL_CONTINENT_CONTAINER_H
298 /* End of continent_container.h */