Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / zone_check_bind / zone_utility.cpp
blobce4cf379ffd05e04cd7edc96d7587b33bbdad72d
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
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"
22 #include <iostream>
23 #include <vector>
24 #include <set>
27 using namespace NL3D;
28 using namespace NLMISC;
29 using namespace std;
33 /*******************************************************************\
34 getZoneCoordByName()
35 \*******************************************************************/
36 bool getZoneCoordByName(const char * name, uint16& x, uint16& y)
38 uint i;
40 std::string zoneName(name);
42 // y
43 string::size_type ind1 = zoneName.find("_");
44 if(ind1 == string::npos || ind1>=zoneName.length())
46 nlwarning("bad file name");
47 return false;
49 std::string ystr = zoneName.substr(0,ind1);
50 for(i=0; i<ystr.length(); i++)
52 if(!isdigit(ystr[i]))
54 nlwarning("y code size is not a 2 characters code");
55 return false;
58 NLMISC::fromString(ystr, y);
60 // x
61 x = 0;
62 uint ind2 = (uint)zoneName.length();
63 if((ind2-ind1-1)!=2)
65 nlwarning("x code size is not a 2 characters code");
66 return false;
68 std::string xstr = zoneName.substr(ind1+1,ind2-ind1-1);
69 for(i=0; i<xstr.length(); i++)
71 if (isalpha(xstr[i]))
73 x *= 26;
74 x += (tolower(xstr[i])-'a');
76 else
78 nlwarning("invalid");
79 return false;
82 return true;
85 /*******************************************************************\
86 getLettersFromNum()
87 \*******************************************************************/
88 void getLettersFromNum(uint16 num, std::string& code)
90 if(num>26*26)
92 nlwarning("zone index too high");
93 return;
95 code.resize(0);
96 uint16 remainder = num%26;
97 code += 'A' + num/26;
98 code += 'A' + remainder;
101 /*******************************************************************\
102 getZoneNameByCoord()
103 \*******************************************************************/
104 void getZoneNameByCoord(uint16 x, uint16 y, std::string& zoneName)
106 // y str
107 char stmp[10];
108 sprintf(stmp,"%d",y);
109 std::string ystrtmp = std::string(stmp);
111 // x str
112 std::string xstrtmp;
113 getLettersFromNum(x, xstrtmp);
115 // name
116 zoneName = ystrtmp;
117 zoneName +="_";
118 zoneName +=xstrtmp;