Merge r2 entry points changes

feature/core4-atys
kaetemi 3 years ago
parent 9792fee256
commit 97c7f85aed
No known key found for this signature in database
GPG Key ID: 9873C4D40BB479BC

@ -59,7 +59,9 @@ CScenarioEntryPoints::CScenarioEntryPoints()
void CScenarioEntryPoints::init() void CScenarioEntryPoints::init()
{ {
_CompleteIslandsFilename = "r2_islands.xml"; _HardIslandsPath = false;
_CompleteIslandsFilenames.clear();
_CompleteIslandsFilename.push_back("r2_islands.xml");
_EntryPointsFilename = "r2_entry_points.txt"; _EntryPointsFilename = "r2_entry_points.txt";
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -98,6 +100,26 @@ const CScenarioEntryPoints::TEntryPoints& CScenarioEntryPoints::getEntryPoints()
return _EntryPoints; 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 // TEMP
uint32 CScenarioEntryPoints::getIslandId(const CSString& island) uint32 CScenarioEntryPoints::getIslandId(const CSString& island)
@ -224,7 +246,18 @@ void CScenarioEntryPoints::loadFromFile()
CScenarioEntryPoints::CCompleteIsland *CScenarioEntryPoints::getCompleteIslandFromCoords(const NLMISC::CVector2f &pos) CScenarioEntryPoints::CCompleteIsland *CScenarioEntryPoints::getCompleteIslandFromCoords(const NLMISC::CVector2f &pos)
{ {
loadCompleteIslands(); 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) fabs((double) pos.y - _LastTestedCoords.y) > 20.f)
{ {
_LastTestedCoords = pos; _LastTestedCoords = pos;
@ -293,17 +326,24 @@ void CScenarioEntryPoints::loadFromXMLFile()
// clear out the entry point vector before we begin // clear out the entry point vector before we begin
_CompleteIslands.clear(); _CompleteIslands.clear();
_LastFoundIsland = NULL;
for (size_t i = 0; i < _CompleteIslandsFilenames.size(); ++i)
{
// File stream // File stream
CIFile file; CIFile file;
// setup the file name // 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 // Open the file
if (!file.open(pathFileName.c_str())) if (!file.open(pathFileName.c_str()))
{ {
nlinfo("Can't open the file for reading : %s", pathFileName.c_str()); nlinfo("Can't open the file for reading : %s", pathFileName.c_str());
if (_HardIslandsPath)
continue;
} }
// Create the XML stream // Create the XML stream
@ -323,7 +363,7 @@ void CScenarioEntryPoints::loadFromXMLFile()
const char *island = (const char *)xmlGetProp(islandNode, (xmlChar *)"island"); const char *island = (const char *)xmlGetProp(islandNode, (xmlChar *)"island");
if (island == 0) if (island == 0)
{ {
nlinfo("no 'island' tag in %s", _CompleteIslandsFilename.c_str()); nlinfo("no 'island' tag in %s", _CompleteIslandsFilenames[i].c_str());
continue; continue;
} }
else else
@ -399,7 +439,6 @@ void CScenarioEntryPoints::loadFromXMLFile()
else else
completeIsland.Package = CSString(package); completeIsland.Package = CSString(package);
// zones // zones
xmlNodePtr zoneNode = input.getFirstChildNode(islandNode, "zone"); xmlNodePtr zoneNode = input.getFirstChildNode(islandNode, "zone");
@ -409,7 +448,7 @@ void CScenarioEntryPoints::loadFromXMLFile()
const char *zoneName = (const char *)xmlGetProp(zoneNode, (xmlChar *)"name"); const char *zoneName = (const char *)xmlGetProp(zoneNode, (xmlChar *)"name");
if (zoneName == 0) 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 else
completeIsland.Zones.push_back(std::string(zoneName)); completeIsland.Zones.push_back(std::string(zoneName));
@ -427,11 +466,11 @@ void CScenarioEntryPoints::loadFromXMLFile()
} }
} }
if (!entryPoints.empty()) if (!entryPoints.empty())
{ {
completeIsland.EntryPoints = entryPoints; completeIsland.EntryPoints = entryPoints;
_CompleteIslands.push_back(completeIsland); _CompleteIslands.push_back(completeIsland);
_LastFoundIsland = NULL;
} }
islandNode = input.getNextChildNode(islandNode, "complete_island"); islandNode = input.getNextChildNode(islandNode, "complete_island");
@ -440,6 +479,7 @@ void CScenarioEntryPoints::loadFromXMLFile()
// Close the file // Close the file
file.close(); file.close();
}
_CompleteIslandsLoaded = true; _CompleteIslandsLoaded = true;
} }
@ -470,7 +510,8 @@ void CScenarioEntryPoints::saveXMLFile(const TCompleteIslands & completeIslands,
COFile file; COFile file;
// setup the file name // 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 // Open the file
if (!file.open(pathFilename.c_str())) if (!file.open(pathFilename.c_str()))

@ -135,6 +135,8 @@ namespace R2
// get the vector of complete islands // get the vector of complete islands
const TCompleteIslands& getCompleteIslands(); const TCompleteIslands& getCompleteIslands();
void setFiles(const std::string &completeIslandsFilename, const std::string &entryPointsFilename);
private: private:
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// this is a singleton so prevent instantiation // this is a singleton so prevent instantiation
@ -184,7 +186,8 @@ namespace R2
NLMISC::CVector2f _LastTestedCoords; NLMISC::CVector2f _LastTestedCoords;
CCompleteIsland *_LastFoundIsland; CCompleteIsland *_LastFoundIsland;
std::string _CompleteIslandsFilename; bool _HardIslandsPath;
std::vector<std::string> _CompleteIslandsFilenames;
std::string _EntryPointsFilename; std::string _EntryPointsFilename;
}; };

Loading…
Cancel
Save