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/>.
20 #include "zone_util.h"
21 #include "nel/misc/path.h"
22 #include "nel/misc/vector_2f.h"
30 bool getPosFromZoneName(const std::string
&name
,NLMISC::CVector2f
&dest
)
35 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
39 static std::string zoneName
;
40 static string xStr
, yStr
;
43 zoneName
= NLMISC::CFile::getFilenameWithoutExtension(name
);
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())
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'));
61 NLMISC::fromString(yStr
, nY
);
66 bool getZonePosFromZoneName(const std::string
&name
, sint
&x
, sint
&y
)
71 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
75 static std::string zoneName
;
76 static string xStr
, yStr
;
79 zoneName
= NLMISC::CFile::getFilenameWithoutExtension(name
);
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())
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
);