1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
18 #include "nel/misc/types_nl.h"
19 #include "nel/misc/file.h"
20 #include "nel/3d/quad_tree.h"
21 #include "nel/3d/zone.h"
28 using namespace NLMISC
;
32 /*******************************************************************\
34 \*******************************************************************/
35 std::string
getDir (const std::string
& path
)
38 strcpy (tmpPath
, path
.c_str());
39 char* slash
=strrchr (tmpPath
, '/');
42 slash
=strrchr (tmpPath
, '\\');
54 /*******************************************************************\
56 \*******************************************************************/
57 std::string
getName (const std::string
& path
)
59 std::string dir
=getDir (path
);
62 strcpy (tmpPath
, path
.c_str());
65 nlassert (dir
.length()<=strlen(tmpPath
));
68 char* point
=strrchr (name
, '.');
76 /*******************************************************************\
78 \*******************************************************************/
79 std::string
getExt (const std::string
& path
)
81 std::string dir
=getDir (path
);
82 std::string name
=getName (path
);
85 strcpy (tmpPath
, path
.c_str());
88 nlassert (dir
.length()+name
.length()<=strlen(tmpPath
));
89 ext
+=dir
.length()+name
.length();
94 /*******************************************************************\
96 \*******************************************************************/
97 bool getZoneCoordByName(const char * name
, uint16
& x
, uint16
& y
)
101 std::string
zoneName(name
);
104 string::size_type ind1
= zoneName
.find("_");
105 if(ind1
== string::npos
|| ind1
>=zoneName
.length())
107 nlwarning("bad file name");
110 std::string ystr
= zoneName
.substr(0,ind1
);
111 for(i
=0; i
<ystr
.length(); i
++)
113 if(!isdigit(ystr
[i
]))
115 nlwarning("y code size is not a 2 characters code");
120 NLMISC::fromString(ystr
, y
);
124 uint ind2
= (uint
)zoneName
.length();
127 nlwarning("x code size is not a 2 characters code");
130 std::string xstr
= zoneName
.substr(ind1
+1,ind2
-ind1
-1);
131 for(i
=0; i
<xstr
.length(); i
++)
133 if (isalpha(xstr
[i
]))
136 x
+= (tolower(xstr
[i
])-'a');
140 nlwarning("invalid");
148 /*******************************************************************\
150 \*******************************************************************/
151 void getLettersFromNum(uint16 num
, std::string
& code
)
155 nlwarning("zone index too high");
159 uint16 remainder
= num
%26;
160 code
+= 'A' + num
/26;
161 code
+= 'A' + remainder
;
165 /*******************************************************************\
167 \*******************************************************************/
168 void getZoneNameByCoord(uint16 x
, uint16 y
, std::string
& zoneName
)
172 sprintf(stmp
,"%d",y
);
173 std::string ystrtmp
= std::string(stmp
);
177 getLettersFromNum(x
, xstrtmp
);
187 /*******************************************************************\
188 getAdjacentZonesName()
189 \*******************************************************************/
190 void getAdjacentZonesName(const std::string
& zoneName
, std::vector
<std::string
>& names
)
195 std::string
empty("empty");
199 getZoneCoordByName(zoneName
.c_str(), x
, y
);
207 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
208 names
.push_back(nametmp
);
216 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
217 names
.push_back(nametmp
);
225 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
226 names
.push_back(nametmp
);
234 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
235 names
.push_back(nametmp
);
240 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
241 names
.push_back(nametmp
);
249 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
250 names
.push_back(nametmp
);
255 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
256 names
.push_back(nametmp
);
261 getZoneNameByCoord(xtmp
, ytmp
, nametmp
);
262 names
.push_back(nametmp
);
266 /*******************************************************************\
268 \*******************************************************************/
269 uint16
createZoneId(std::string zoneName
)
272 getZoneCoordByName(zoneName
.c_str(), x
, y
);
273 return ((y
-1)<<8) + x
;