|
|
|
@ -59,7 +59,13 @@ CScenarioEntryPoints::CScenarioEntryPoints()
|
|
|
|
|
|
|
|
|
|
void CScenarioEntryPoints::init()
|
|
|
|
|
{
|
|
|
|
|
_CompleteIslandsFilename = "r2_islands.xml";
|
|
|
|
|
_HardIslandsPath = false;
|
|
|
|
|
_CompleteIslandsFilenames.clear();
|
|
|
|
|
_CompleteIslandsFilenames.push_back("r2_desert_islands.xml");
|
|
|
|
|
_CompleteIslandsFilenames.push_back("r2_lakes_islands.xml");
|
|
|
|
|
_CompleteIslandsFilenames.push_back("r2_jungle_islands.xml");
|
|
|
|
|
_CompleteIslandsFilenames.push_back("r2_forest_islands.xml");
|
|
|
|
|
_CompleteIslandsFilenames.push_back("r2_roots_islands.xml");
|
|
|
|
|
_EntryPointsFilename = "r2_entry_points.txt";
|
|
|
|
|
}
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
@ -98,6 +104,26 @@ const CScenarioEntryPoints::TEntryPoints& CScenarioEntryPoints::getEntryPoints()
|
|
|
|
|
return _EntryPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CScenarioEntryPoints::setFiles(const std::string &completeIslandsFilename, const std::string &entryPointsFilename)
|
|
|
|
|
{
|
|
|
|
|
if (_CompleteIslandsFilenames.size() != 1
|
|
|
|
|
|| _CompleteIslandsFilenames[0] != completeIslandsFilename
|
|
|
|
|
|| _EntryPointsFilename != entryPointsFilename)
|
|
|
|
|
{
|
|
|
|
|
_HardIslandsPath = completeIslandsFilename.find('/') != std::string::npos
|
|
|
|
|
|| completeIslandsFilename.find('\\') != std::string::npos;
|
|
|
|
|
_CompleteIslandsFilenames.clear();
|
|
|
|
|
_CompleteIslandsFilenames.push_back(completeIslandsFilename);
|
|
|
|
|
_EntryPointsFilename = entryPointsFilename;
|
|
|
|
|
_CompleteIslands.clear();
|
|
|
|
|
_CompleteIslandsLoaded = false;
|
|
|
|
|
_EntryPoints.clear();
|
|
|
|
|
_IsLoaded = false;
|
|
|
|
|
_LastFoundIsland = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// TEMP
|
|
|
|
|
uint32 CScenarioEntryPoints::getIslandId(const CSString& island)
|
|
|
|
@ -224,7 +250,18 @@ void CScenarioEntryPoints::loadFromFile()
|
|
|
|
|
CScenarioEntryPoints::CCompleteIsland *CScenarioEntryPoints::getCompleteIslandFromCoords(const NLMISC::CVector2f &pos)
|
|
|
|
|
{
|
|
|
|
|
loadCompleteIslands();
|
|
|
|
|
if (fabs((double) pos.x - _LastTestedCoords.x) > 20.f ||
|
|
|
|
|
if (_LastFoundIsland)
|
|
|
|
|
{
|
|
|
|
|
if (pos.x >= (float) _LastFoundIsland->XMin &&
|
|
|
|
|
pos.x <= (float) _LastFoundIsland->XMax &&
|
|
|
|
|
pos.y >= (float) _LastFoundIsland->YMin &&
|
|
|
|
|
pos.y <= (float) _LastFoundIsland->YMax)
|
|
|
|
|
{
|
|
|
|
|
return _LastFoundIsland;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!_LastFoundIsland ||
|
|
|
|
|
fabs((double) pos.x - _LastTestedCoords.x) > 20.f ||
|
|
|
|
|
fabs((double) pos.y - _LastTestedCoords.y) > 20.f)
|
|
|
|
|
{
|
|
|
|
|
_LastTestedCoords = pos;
|
|
|
|
@ -293,17 +330,24 @@ void CScenarioEntryPoints::loadFromXMLFile()
|
|
|
|
|
|
|
|
|
|
// clear out the entry point vector before we begin
|
|
|
|
|
_CompleteIslands.clear();
|
|
|
|
|
_LastFoundIsland = NULL;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < _CompleteIslandsFilenames.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
// File stream
|
|
|
|
|
CIFile file;
|
|
|
|
|
|
|
|
|
|
// setup the file name
|
|
|
|
|
std::string pathFileName = CPath::lookup(_CompleteIslandsFilename.c_str());
|
|
|
|
|
std::string pathFileName = _HardIslandsPath
|
|
|
|
|
? _CompleteIslandsFilenames[i]
|
|
|
|
|
: CPath::lookup(_CompleteIslandsFilenames[i]);
|
|
|
|
|
|
|
|
|
|
// Open the file
|
|
|
|
|
if (!file.open(pathFileName.c_str()))
|
|
|
|
|
{
|
|
|
|
|
nlinfo("Can't open the file for reading : %s", pathFileName.c_str());
|
|
|
|
|
if (_HardIslandsPath)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the XML stream
|
|
|
|
@ -323,7 +367,7 @@ void CScenarioEntryPoints::loadFromXMLFile()
|
|
|
|
|
const char *island = (const char *)xmlGetProp(islandNode, (xmlChar *)"island");
|
|
|
|
|
if (island == 0)
|
|
|
|
|
{
|
|
|
|
|
nlinfo("no 'island' tag in %s", _CompleteIslandsFilename.c_str());
|
|
|
|
|
nlinfo("no 'island' tag in %s", _CompleteIslandsFilenames[i].c_str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -399,7 +443,6 @@ void CScenarioEntryPoints::loadFromXMLFile()
|
|
|
|
|
else
|
|
|
|
|
completeIsland.Package = CSString(package);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// zones
|
|
|
|
|
xmlNodePtr zoneNode = input.getFirstChildNode(islandNode, "zone");
|
|
|
|
|
|
|
|
|
@ -409,7 +452,7 @@ void CScenarioEntryPoints::loadFromXMLFile()
|
|
|
|
|
const char *zoneName = (const char *)xmlGetProp(zoneNode, (xmlChar *)"name");
|
|
|
|
|
if (zoneName == 0)
|
|
|
|
|
{
|
|
|
|
|
nlinfo("no 'zone name' tag in %s", _CompleteIslandsFilename.c_str());
|
|
|
|
|
nlinfo("no 'zone name' tag in %s", _CompleteIslandsFilenames[i].c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
completeIsland.Zones.push_back(std::string(zoneName));
|
|
|
|
@ -427,11 +470,11 @@ void CScenarioEntryPoints::loadFromXMLFile()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!entryPoints.empty())
|
|
|
|
|
{
|
|
|
|
|
completeIsland.EntryPoints = entryPoints;
|
|
|
|
|
_CompleteIslands.push_back(completeIsland);
|
|
|
|
|
_LastFoundIsland = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
islandNode = input.getNextChildNode(islandNode, "complete_island");
|
|
|
|
@ -440,6 +483,7 @@ void CScenarioEntryPoints::loadFromXMLFile()
|
|
|
|
|
|
|
|
|
|
// Close the file
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_CompleteIslandsLoaded = true;
|
|
|
|
|
}
|
|
|
|
@ -470,7 +514,8 @@ void CScenarioEntryPoints::saveXMLFile(const TCompleteIslands & completeIslands,
|
|
|
|
|
COFile file;
|
|
|
|
|
|
|
|
|
|
// setup the file name
|
|
|
|
|
std::string pathFilename = CPath::lookup(fileName.c_str());
|
|
|
|
|
std::string pathFilename = (fileName.find('/') != std::string::npos || fileName.find('\\') != std::string::npos)
|
|
|
|
|
? fileName : CPath::lookup(fileName.c_str());
|
|
|
|
|
|
|
|
|
|
// Open the file
|
|
|
|
|
if (!file.open(pathFilename.c_str()))
|
|
|
|
|