|
|
|
@ -76,6 +76,11 @@ struct SpawnerTag{ |
|
|
|
|
friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct ZoneData{ |
|
|
|
|
geom2d::rect<int>zone; |
|
|
|
|
bool isUpper=false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct Map{ |
|
|
|
|
MapTag MapData; |
|
|
|
|
std::string name; |
|
|
|
@ -85,7 +90,7 @@ struct Map{ |
|
|
|
|
std::string mapType=""; |
|
|
|
|
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<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 FormatSpawnerData(std::ostream& os, std::map<int,SpawnerTag>tiles); |
|
|
|
|
friend std::ostream& operator << (std::ostream& os, Map& rhs); |
|
|
|
@ -114,6 +119,7 @@ class TMXParser{ |
|
|
|
|
bool buildingSpawner=false; |
|
|
|
|
SpawnerTag obj; |
|
|
|
|
int prevSpawner; |
|
|
|
|
ZoneData*prevZoneData=nullptr; |
|
|
|
|
void ParseTag(std::string tag); |
|
|
|
|
int monsterPropertyTagCount=-1; |
|
|
|
|
XMLTag monsterTag; |
|
|
|
@ -126,7 +132,6 @@ class TMXParser{ |
|
|
|
|
TMXParser(std::string file); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
|
//#define TMX_PARSER_SETUP //Toggle for code-writing.
|
|
|
|
|
|
|
|
|
|
#ifdef TMX_PARSER_SETUP |
|
|
|
@ -161,7 +166,7 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
|
return std::stod(data[dataTag]); |
|
|
|
|
} |
|
|
|
|
bool XMLTag::GetBool(std::string dataTag) { |
|
|
|
|
if (data[dataTag]=="0") { |
|
|
|
|
if (data[dataTag]=="0"||data[dataTag]=="false") { |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
return true; |
|
|
|
@ -315,6 +320,9 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
|
prevSpawner=newTag.GetInteger("id"); |
|
|
|
|
} |
|
|
|
|
} 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") { |
|
|
|
|
parsedMapInfo.MapData.optimized=true; |
|
|
|
|
} 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()){ |
|
|
|
|
//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()){ |
|
|
|
|
std::vector<geom2d::rect<int>>&zones=parsedMapInfo.ZoneData[newTag.data["type"]]; |
|
|
|
|
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
std::vector<ZoneData>&zones=parsedMapInfo.ZoneData.at(newTag.data["type"]); |
|
|
|
|
zones.emplace_back(geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
prevZoneData=&zones.back(); |
|
|
|
|
} else { |
|
|
|
|
std::vector<geom2d::rect<int>>zones; |
|
|
|
|
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
parsedMapInfo.ZoneData[newTag.data["type"]]=zones;
|
|
|
|
|
std::vector<ZoneData>&zones=parsedMapInfo.ZoneData[newTag.data["type"]]; |
|
|
|
|
zones.emplace_back(geom2d::rect<int>{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
prevZoneData=&zones.back(); |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
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; |
|
|
|
|
for(auto&zoneData:parsedMapInfo.ZoneData){ |
|
|
|
|
if(zoneData.first=="UpperZone"){ |
|
|
|
|
std::vector<geom2d::rect<int>>&zones=zoneData.second; |
|
|
|
|
for(geom2d::rect<int>&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")}})){ |
|
|
|
|
std::vector<ZoneData>&zones=zoneData.second; |
|
|
|
|
for(ZoneData&zone:zones){ |
|
|
|
|
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; |
|
|
|
|
goto continueSpawnerLoop; |
|
|
|
|
} |
|
|
|
|