1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "zone_util.h"
24 #include "nel/misc/path.h"
25 #include "nel/misc/vector_2f.h"
33 bool getPosFromZoneName(const std::string
&name
,NLMISC::CVector2f
&dest
)
38 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
42 static std::string zoneName
;
43 static string xStr
, yStr
;
46 zoneName
= NLMISC::CFile::getFilenameWithoutExtension(name
);
48 while (zoneName
[i
] != '_')
50 if ((uint8
)zoneName
[i
] >= (uint8
)'\x80' || !::isdigit(zoneName
[i
])) return false;
51 yStr
+= zoneName
[i
]; ++i
;
52 if (i
== zoneName
.size())
56 while (i
< zoneName
.size())
58 if ((uint8
)zoneName
[i
] >= (uint8
)'\x80' || !::isalpha(zoneName
[i
])) return false;
59 xStr
+= (char) NLMISC::toUpper(zoneName
[i
]); ++i
;
61 if (xStr
.size() != 2) return false;
62 dest
.x
= 160.f
* ((xStr
[0] - 'A') * 26 + (xStr
[1] - 'A'));
64 NLMISC::fromString(yStr
, nY
);
69 bool getZonePosFromZoneName(const std::string
&name
, sint
&x
, sint
&y
)
74 nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
78 static std::string zoneName
;
79 static string xStr
, yStr
;
82 zoneName
= NLMISC::CFile::getFilenameWithoutExtension(name
);
84 while (zoneName
[i
] != '_')
86 if ((uint8
)zoneName
[i
] >= (uint8
)'\x80' || !::isdigit(zoneName
[i
])) return false;
87 yStr
+= zoneName
[i
]; ++i
;
88 if (i
== zoneName
.size())
92 while (i
< zoneName
.size())
94 if ((uint8
)zoneName
[i
] >= (uint8
)'\x80' || !::isalpha(zoneName
[i
])) return false;
95 xStr
+= (char) NLMISC::toUpper(zoneName
[i
]); ++i
;
97 if (xStr
.size() != 2) return false;
98 x
= (xStr
[0] - 'A') * 26 + (xStr
[1] - 'A');
99 NLMISC::fromString(yStr
, y
);