Added ai command setEquipment
[ryzomcore.git] / ryzom / server / src / ai_service / world_container.h
blob2abcec8f002e9ad9b9554b641a1bb0c407840ab6
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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"
27 #include <string>
29 /**
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
34 * \date 2003
36 class CWorldContainer
38 protected:
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;
46 public:
47 static inline const RYAI_MAP_CRUNCH::CWorldMap& getWorldMap()
49 return _WorldMaps;
52 static inline RYAI_MAP_CRUNCH::CWorldMap& getWorldMapNoCst()
54 return _WorldMaps;
57 /// Constructor
58 CWorldContainer();
60 /// Clear up
61 static void clear();
63 /// \name Continent management
64 // @{
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; }
71 // @}
73 // static uint32 getMapSize(double physicalRadius)
74 // {
75 // return 0;
76 //// if (physicalRadius<=0.5)
77 //// return 0;
78 //// if (physicalRadius>1.5)
79 //// return 2;
80 //// return 1;
81 // }
83 class CPosValidator
85 public:
86 CPosValidator() {}
87 virtual ~CPosValidator() {}
88 virtual bool check(const RYAI_MAP_CRUNCH::CWorldPosition& wpos) const=0;
89 protected:
90 private:
92 class CPosValidatorDefault
93 :public CPosValidator
95 public:
96 CPosValidatorDefault() {}
97 virtual ~CPosValidatorDefault() {}
98 virtual bool check(const RYAI_MAP_CRUNCH::CWorldPosition& wpos) const
99 { return true; }
100 protected:
101 private:
104 template <class T>
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;
109 uint32 incTries=0;
111 while ( !foundValidPlace
112 && incTries<tries)
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);
117 if (foundValidPlace)
118 foundValidPlace=validator.check(wpos);
119 incTries++;
121 return incTries<tries;
124 template <class T>
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);
130 template <class T>
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;
135 uint32 incTries=0;
137 while ( !foundValidPlace
138 && incTries<tries)
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);
143 if (foundValidPlace)
144 foundValidPlace=validator.check(wpos);
145 incTries++;
147 return incTries<tries;
150 template <class T>
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 */