1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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
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"
34 #include "nel/georges/u_form.h"
35 #include "nel/georges/u_form_elm.h"
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"
47 * \author Benjamin Legros
48 * \author Nevrax France
51 class CContinentContainer
54 /// Container of continent
55 class CContinentMoveContainer
58 CContinentMoveContainer() : GlobalRetriever(NULL
), RetrieverBank(NULL
), MoveContainer(NULL
), AllowAutoSpawn(false) {}
59 /// Then name of the continent
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
78 std::string PacsRBank
;
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
)
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
)
118 s
.serial(PacsRBank
, PacsGR
, LandscapeIG
);
119 s
.serialCont(ListIG
);
122 static uint
getVersion () { return 1; }
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
;
137 TContinentContainer _Continents
;
140 TPacsPrimMap _PacsPrimMap
;
143 typedef std::map
<NLMISC::CSheetId
, CSheet
> TSheetMap
;
149 TTriggerMap _TriggerMap
;
155 double _PrimitiveMaxSize
;
158 /// Should load dynamic collision (e.g. trees)
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);
170 void buildSheets(const std::string
&packedSheetsDirectory
);
173 void initPacsPrim(const std::string
&path
= std::string("landscape_col_prim_pacs_list.txt"));
177 void loadContinent(std::string name
, std::string file
, sint index
, bool allowAutoSpawn
= true);
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
);
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
);
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
);
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
)
221 // finds the continent that fits given position
223 for (i
=0; i
<_Continents
.size(); ++i
)
225 if (_Continents
[i
].GlobalRetriever
== NULL
||
226 !_Continents
[i
].AllowAutoSpawn
)
229 NLPACS::UGlobalPosition globalPosition
= _Continents
[i
].GlobalRetriever
->retrievePosition(worldPosition
);
230 if (globalPosition
.InstanceId
!= -1 && globalPosition
.LocalPosition
.Surface
!= -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
,
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
)
263 /// Get container size
264 sint
size() const { return (sint
)_Continents
.size(); }
266 /// clear the container -- WARNING
270 for (i
=0; i
<_Continents
.size(); ++i
)
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
;
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
);
292 void loadPacsPrims(const CSheet
&sheet
, NLPACS::UMoveContainer
*moveContainer
);
296 #endif // NL_CONTINENT_CONTAINER_H
298 /* End of continent_container.h */