|
|
@ -76,6 +76,11 @@ struct SpawnerTag{ |
|
|
|
friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs); |
|
|
|
friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ZoneData{ |
|
|
|
|
|
|
|
geom2d::rect<int>zone; |
|
|
|
|
|
|
|
bool isUpper=false; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct Map{ |
|
|
|
struct Map{ |
|
|
|
MapTag MapData; |
|
|
|
MapTag MapData; |
|
|
|
std::string name; |
|
|
|
std::string name; |
|
|
@ -85,7 +90,7 @@ struct Map{ |
|
|
|
std::string mapType=""; |
|
|
|
std::string mapType=""; |
|
|
|
std::set<int>spawns; |
|
|
|
std::set<int>spawns; |
|
|
|
std::map<int,SpawnerTag> SpawnerData; //Spawn groups have IDs, mobs associate which spawner they are tied to via this ID.
|
|
|
|
std::map<int,SpawnerTag> SpawnerData; //Spawn groups have IDs, mobs associate which spawner they are tied to via this ID.
|
|
|
|
std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
std::map<std::string,std::vector<ZoneData>> ZoneData; |
|
|
|
std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles); |
|
|
|
std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles); |
|
|
|
std::string FormatSpawnerData(std::ostream& os, std::map<int,SpawnerTag>tiles); |
|
|
|
std::string FormatSpawnerData(std::ostream& os, std::map<int,SpawnerTag>tiles); |
|
|
|
friend std::ostream& operator << (std::ostream& os, Map& rhs); |
|
|
|
friend std::ostream& operator << (std::ostream& os, Map& rhs); |
|
|
@ -114,6 +119,7 @@ class TMXParser{ |
|
|
|
bool buildingSpawner=false; |
|
|
|
bool buildingSpawner=false; |
|
|
|
SpawnerTag obj; |
|
|
|
SpawnerTag obj; |
|
|
|
int prevSpawner; |
|
|
|
int prevSpawner; |
|
|
|
|
|
|
|
ZoneData*prevZoneData=nullptr; |
|
|
|
void ParseTag(std::string tag); |
|
|
|
void ParseTag(std::string tag); |
|
|
|
int monsterPropertyTagCount=-1; |
|
|
|
int monsterPropertyTagCount=-1; |
|
|
|
XMLTag monsterTag; |
|
|
|
XMLTag monsterTag; |
|
|
@ -126,7 +132,6 @@ class TMXParser{ |
|
|
|
TMXParser(std::string file); |
|
|
|
TMXParser(std::string file); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
|
|
|
|
//#define TMX_PARSER_SETUP //Toggle for code-writing.
|
|
|
|
//#define TMX_PARSER_SETUP //Toggle for code-writing.
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TMX_PARSER_SETUP |
|
|
|
#ifdef TMX_PARSER_SETUP |
|
|
@ -161,7 +166,7 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
return std::stod(data[dataTag]); |
|
|
|
return std::stod(data[dataTag]); |
|
|
|
} |
|
|
|
} |
|
|
|
bool XMLTag::GetBool(std::string dataTag) { |
|
|
|
bool XMLTag::GetBool(std::string dataTag) { |
|
|
|
if (data[dataTag]=="0") { |
|
|
|
if (data[dataTag]=="0"||data[dataTag]=="false") { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -315,6 +320,9 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
prevSpawner=newTag.GetInteger("id"); |
|
|
|
prevSpawner=newTag.GetInteger("id"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else
|
|
|
|
} else
|
|
|
|
|
|
|
|
if(newTag.tag=="property"&&newTag.data["name"]=="Upper?"&&prevZoneData!=nullptr){ |
|
|
|
|
|
|
|
prevZoneData->isUpper=newTag.GetBool("value"); |
|
|
|
|
|
|
|
}else |
|
|
|
if (newTag.tag=="property"&&newTag.data["name"]=="Optimize"&&newTag.data["value"]=="true") { |
|
|
|
if (newTag.tag=="property"&&newTag.data["name"]=="Optimize"&&newTag.data["value"]=="true") { |
|
|
|
parsedMapInfo.MapData.optimized=true; |
|
|
|
parsedMapInfo.MapData.optimized=true; |
|
|
|
} else
|
|
|
|
} else
|
|
|
@ -357,12 +365,13 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end()){ |
|
|
|
if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end()){ |
|
|
|
//This is an object with a type that doesn't fit into other categories, we can add it to ZoneData.
|
|
|
|
//This is an object with a type that doesn't fit into other categories, we can add it to ZoneData.
|
|
|
|
if(parsedMapInfo.ZoneData.find(newTag.data["type"])!=parsedMapInfo.ZoneData.end()){ |
|
|
|
if(parsedMapInfo.ZoneData.find(newTag.data["type"])!=parsedMapInfo.ZoneData.end()){ |
|
|
|
std::vector<geom2d::rect<int>>&zones=parsedMapInfo.ZoneData[newTag.data["type"]]; |
|
|
|
std::vector<ZoneData>&zones=parsedMapInfo.ZoneData.at(newTag.data["type"]); |
|
|
|
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
zones.emplace_back(geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
|
|
|
prevZoneData=&zones.back(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
std::vector<geom2d::rect<int>>zones; |
|
|
|
std::vector<ZoneData>&zones=parsedMapInfo.ZoneData[newTag.data["type"]]; |
|
|
|
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
zones.emplace_back(geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
parsedMapInfo.ZoneData[newTag.data["type"]]=zones;
|
|
|
|
prevZoneData=&zones.back(); |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n"; |
|
|
|
if(_DEBUG_MAP_LOAD_INFO)std::cout<<"Unsupported tag format! Ignoring."<<"\n"; |
|
|
@ -423,9 +432,9 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
SpawnerTag&spawner=spawnerData.second; |
|
|
|
SpawnerTag&spawner=spawnerData.second; |
|
|
|
for(auto&zoneData:parsedMapInfo.ZoneData){ |
|
|
|
for(auto&zoneData:parsedMapInfo.ZoneData){ |
|
|
|
if(zoneData.first=="UpperZone"){ |
|
|
|
if(zoneData.first=="UpperZone"){ |
|
|
|
std::vector<geom2d::rect<int>>&zones=zoneData.second; |
|
|
|
std::vector<ZoneData>&zones=zoneData.second; |
|
|
|
for(geom2d::rect<int>&zone:zones){ |
|
|
|
for(ZoneData&zone:zones){ |
|
|
|
if(geom2d::overlaps(zone,geom2d::rect<int>{{spawner.ObjectData.GetInteger("x"),spawner.ObjectData.GetInteger("y")},{spawner.ObjectData.GetInteger("width"),spawner.ObjectData.GetInteger("height")}})){ |
|
|
|
if(geom2d::overlaps(zone.zone,geom2d::rect<int>{{spawner.ObjectData.GetInteger("x"),spawner.ObjectData.GetInteger("y")},{spawner.ObjectData.GetInteger("width"),spawner.ObjectData.GetInteger("height")}})){ |
|
|
|
spawner.upperLevel=true; |
|
|
|
spawner.upperLevel=true; |
|
|
|
goto continueSpawnerLoop; |
|
|
|
goto continueSpawnerLoop; |
|
|
|
} |
|
|
|
} |
|
|
|