Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / zone_util.cpp
blob0f2a846364decc84d19a93a0b015517be36a047a
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 #include "stdpch.h"
20 #include "zone_util.h"
21 #include "nel/misc/path.h"
22 #include "nel/misc/vector_2f.h"
24 using namespace std;
26 #ifdef DEBUG_NEW
27 #define new DEBUG_NEW
28 #endif
30 bool getPosFromZoneName(const std::string &name,NLMISC::CVector2f &dest)
33 if (name.empty())
35 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
36 return false;
39 static std::string zoneName;
40 static string xStr, yStr;
41 xStr.clear();
42 yStr.clear();
43 zoneName = NLMISC::CFile::getFilenameWithoutExtension(name);
44 uint32 i = 0;
45 while (zoneName[i] != '_')
47 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isdigit(zoneName[i])) return false;
48 yStr += zoneName[i]; ++i;
49 if (i == zoneName.size())
50 return false;
52 ++i;
53 while (i < zoneName.size())
55 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isalpha(zoneName[i])) return false;
56 xStr += (char) NLMISC::toUpper(zoneName[i]); ++i;
58 if (xStr.size() != 2) return false;
59 dest.x = 160.f * ((xStr[0] - 'A') * 26 + (xStr[1] - 'A'));
60 sint nY;
61 NLMISC::fromString(yStr, nY);
62 dest.y = 160.f * -nY;
63 return true;
66 bool getZonePosFromZoneName(const std::string &name, sint &x, sint &y)
69 if (name.empty())
71 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
72 return false;
75 static std::string zoneName;
76 static string xStr, yStr;
77 xStr.clear();
78 yStr.clear();
79 zoneName = NLMISC::CFile::getFilenameWithoutExtension(name);
80 uint32 i = 0;
81 while (zoneName[i] != '_')
83 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isdigit(zoneName[i])) return false;
84 yStr += zoneName[i]; ++i;
85 if (i == zoneName.size())
86 return false;
88 ++i;
89 while (i < zoneName.size())
91 if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isalpha(zoneName[i])) return false;
92 xStr += (char) NLMISC::toUpper(zoneName[i]); ++i;
94 if (xStr.size() != 2) return false;
95 x = (xStr[0] - 'A') * 26 + (xStr[1] - 'A');
96 NLMISC::fromString(yStr, y);
97 y = -y;
98 return true;