1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef NL_WORLD_CONTAINER_H
20 #define NL_WORLD_CONTAINER_H
22 #include "ai_share/world_map.h"
24 #include "nel/misc/types_nl.h"
25 #include "nel/misc/stream.h"
30 * The whole World Container, manager for collision and pathfinding for AI
31 * This class is not a singleton.
32 * \author Benjamin Legros
33 * \author Nevrax France
40 /// List of merged continents
41 static std::vector
<std::string
> _ContinentNames
;
43 /// Three world maps, one for each type of creature (1, 3 and 5 meters width)
44 static RYAI_MAP_CRUNCH::CWorldMap _WorldMaps
;
47 static inline const RYAI_MAP_CRUNCH::CWorldMap
& getWorldMap()
52 static inline RYAI_MAP_CRUNCH::CWorldMap
& getWorldMapNoCst()
63 /// \name Continent management
66 /// Merge a continent, like "fyros" or "matis"
67 static void loadContinent(const std::string
&name
);
68 /// Get the list of merged continents
69 static std::vector
<std::string
> &getContinentList() {return _ContinentNames
; }
73 // static uint32 getMapSize(double physicalRadius)
76 //// if (physicalRadius<=0.5)
78 //// if (physicalRadius>1.5)
87 virtual ~CPosValidator() {}
88 virtual bool check(const RYAI_MAP_CRUNCH::CWorldPosition
& wpos
) const=0;
92 class CPosValidatorDefault
96 CPosValidatorDefault() {}
97 virtual ~CPosValidatorDefault() {}
98 virtual bool check(const RYAI_MAP_CRUNCH::CWorldPosition
& wpos
) const
105 static bool calcNearestWPosFromPosAnRadius (const AITYPES::TVerticalPos
&verticalPos
, const RYAI_MAP_CRUNCH::CWorldMap
&worldMap
, RYAI_MAP_CRUNCH::CWorldPosition
& wpos
, const T
&pos
, float radius
, uint32 tries
, const CPosValidator
&validator
)
107 H_AUTO(CalcNearestWPos
)
108 bool foundValidPlace
=false;
111 while ( !foundValidPlace
114 double rad
=(radius
*incTries
)/tries
;
115 CAIVector
rndPos(pos
.x()+rad
*cos((double)incTries
),pos
.y()+rad
*sin((double)incTries
));
116 foundValidPlace
=worldMap
.setWorldPosition(verticalPos
, wpos
,rndPos
);
118 foundValidPlace
=validator
.check(wpos
);
121 return incTries
<tries
;
125 static bool calcNearestWPosFromPosAnRadius (const AITYPES::TVerticalPos
&verticalPos
, RYAI_MAP_CRUNCH::CWorldPosition
& wpos
, const T
&pos
, float radius
, uint32 tries
, const CPosValidator
&validator
)
127 return calcNearestWPosFromPosAnRadius(verticalPos
, getWorldMap(), wpos
, pos
, radius
, tries
, validator
);
131 static bool calcNearestWPosFromPosAnRadius (sint verticalPos
, const RYAI_MAP_CRUNCH::CWorldMap
&worldMap
, RYAI_MAP_CRUNCH::CWorldPosition
& wpos
, const T
&pos
, float radius
, uint32 tries
, const CPosValidator
&validator
)
133 H_AUTO(CalcNearestWPos
)
134 bool foundValidPlace
=false;
137 while ( !foundValidPlace
140 double rad
=(radius
*incTries
)/tries
;
141 CAIVector
rndPos(pos
.x()+rad
*cos((double)incTries
),pos
.y()+rad
*sin((double)incTries
));
142 foundValidPlace
=worldMap
.setWorldPosition((sint32
)verticalPos
, wpos
,rndPos
);
144 foundValidPlace
=validator
.check(wpos
);
147 return incTries
<tries
;
151 static bool calcNearestWPosFromPosAnRadius (sint verticalPos
, RYAI_MAP_CRUNCH::CWorldPosition
& wpos
, const T
&pos
, float radius
, uint32 tries
, const CPosValidator
&validator
)
153 return calcNearestWPosFromPosAnRadius(verticalPos
, getWorldMap(), wpos
, pos
, radius
, tries
, validator
);
160 #endif // NL_WORLD_CONTAINER_H
162 /* End of world_container.h */