// Ryzom - MMORPG Framework
// Copyright (C) 2010 Winch Gate Property Limited
//
// This source file has been modified by the following contributors:
// Copyright (C) 2020 Jan BOON (Kaetemi)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
#include "stdpch.h"
#include "zone_util.h"
#include "nel/misc/path.h"
#include "nel/misc/vector_2f.h"
using namespace std;
#ifdef DEBUG_NEW
#define new DEBUG_NEW
#endif
bool getPosFromZoneName(const std::string &name,NLMISC::CVector2f &dest)
{
if (name.empty())
{
nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
return false;
}
static std::string zoneName;
static string xStr, yStr;
xStr.clear();
yStr.clear();
zoneName = NLMISC::CFile::getFilenameWithoutExtension(name);
uint32 i = 0;
while (zoneName[i] != '_')
{
if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isdigit(zoneName[i])) return false;
yStr += zoneName[i]; ++i;
if (i == zoneName.size())
return false;
}
++i;
while (i < zoneName.size())
{
if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isalpha(zoneName[i])) return false;
xStr += (char) NLMISC::toUpper(zoneName[i]); ++i;
}
if (xStr.size() != 2) return false;
dest.x = 160.f * ((xStr[0] - 'A') * 26 + (xStr[1] - 'A'));
sint nY;
NLMISC::fromString(yStr, nY);
dest.y = 160.f * -nY;
return true;
}
bool getZonePosFromZoneName(const std::string &name, sint &x, sint &y)
{
if (name.empty())
{
nlwarning ("getPosFromZoneName(): empty name, can't getPosFromZoneName");
return false;
}
static std::string zoneName;
static string xStr, yStr;
xStr.clear();
yStr.clear();
zoneName = NLMISC::CFile::getFilenameWithoutExtension(name);
uint32 i = 0;
while (zoneName[i] != '_')
{
if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isdigit(zoneName[i])) return false;
yStr += zoneName[i]; ++i;
if (i == zoneName.size())
return false;
}
++i;
while (i < zoneName.size())
{
if ((uint8)zoneName[i] >= (uint8)'\x80' || !::isalpha(zoneName[i])) return false;
xStr += (char) NLMISC::toUpper(zoneName[i]); ++i;
}
if (xStr.size() != 2) return false;
x = (xStr[0] - 'A') * 26 + (xStr[1] - 'A');
NLMISC::fromString(yStr, y);
y = -y;
return true;
}