diff --git a/Crawler/Class.cpp b/Crawler/Class.cpp index 5d820128..ef4095d0 100644 --- a/Crawler/Class.cpp +++ b/Crawler/Class.cpp @@ -102,7 +102,7 @@ bool Warrior::AutoAttack(){ bool Warrior::Ability1(){ ACCESS_PLAYER - game->AddEffect(Effect(p.pos,0.1,AnimationState::BATTLECRY_EFFECT,1,0.3)); + game->AddEffect(Effect(p.pos,0.1,AnimationState::BATTLECRY_EFFECT,p.upperLevel,1,0.3)); p.AddBuff(BuffType::ATTACK_UP,10,0.1); p.AddBuff(BuffType::DAMAGE_REDUCTION,10,0.1); for(Monster&m:MONSTER_LIST){ diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index a6414fca..4204d6e9 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -1034,16 +1034,18 @@ void Crawler::LoadLevel(MapName map){ foregroundTileGroups.clear(); currentLevel=map; WORLD_SIZE={MAP_DATA[map].MapData.width,MAP_DATA[map].MapData.height}; - for(SpawnerTag&spawner:MAP_DATA[map].SpawnerData){ + for(auto key:MAP_DATA[map].SpawnerData){ + SpawnerTag&spawnData=MAP_DATA[map].SpawnerData[key.first]; std::vector>monster_list; - vf2d spawnerRadius=vf2d{spawner.ObjectData.GetFloat("width"),spawner.ObjectData.GetFloat("height")}/2; - for(XMLTag&property:spawner.properties){ - int monsterTypeID=property.GetInteger("value")-1; + + vf2d spawnerRadius=vf2d{spawnData.ObjectData.GetFloat("width"),spawnData.ObjectData.GetFloat("height")}/2; + for(XMLTag&monster:spawnData.monsters){ + int monsterTypeID=monster.GetInteger("value")-1; if(monsterTypeID>=0&&monsterTypeID{spawner.GetPos(),spawner.GetRange()},pos)){ + if(!spawner.SpawnTriggered()&&geom2d::contains(geom2d::rect{spawner.GetPos(),spawner.GetRange()},pos)){ spawner.SetTriggered(true); } } diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index 8a638eb6..036399ff 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -31,7 +31,7 @@ struct LayerTag{ struct SpawnerTag{ XMLTag ObjectData; - std::vectorproperties; + std::vectormonsters; std::string str(); friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs); }; @@ -40,10 +40,10 @@ struct Map{ MapTag MapData; std::vector TilesetData; std::vector LayerData; - std::vector SpawnerData; + std::map SpawnerData; //Spawn groups have IDs, mobs associate which spawner they are tied to via this ID. std::map>> ZoneData; std::string FormatLayerData(std::ostream& os, std::vectortiles); - std::string FormatSpawnerData(std::ostream& os, std::vectortiles); + std::string FormatSpawnerData(std::ostream& os, std::maptiles); friend std::ostream& operator << (std::ostream& os, Map& rhs); friend std::ostream& operator << (std::ostream& os, std::vector& rhs); }; @@ -56,6 +56,10 @@ class TMXParser{ bool buildingSpawner=false; SpawnerTag obj; void ParseTag(std::string tag); + int monsterPropertyTagCount=-1; + XMLTag monsterTag; + XMLTag spawnerLinkTag; + std::vectoraccumulatedMonsterTags; public: TMXParser(std::string file); }; @@ -108,8 +112,8 @@ typedef std::map>> ZoneData; } std::string SpawnerTag::str() { std::string displayStr=ObjectData.tag+"\n"+ObjectData.FormatTagData(ObjectData.data); - for(XMLTag tag:properties){ - displayStr+=" ("+tag.FormatTagData(tag.data)+" )\n"; + for(XMLTag&monster:monsters){ + displayStr+=" ("+monster.FormatTagData(monster.data)+" )\n"; } return displayStr; } @@ -124,10 +128,10 @@ typedef std::map>> ZoneData; } return displayStr; } - std::string Map::FormatSpawnerData(std::ostream& os, std::vectortiles) { + std::string Map::FormatSpawnerData(std::ostream& os, std::maptiles) { std::string displayStr; - for (int i=0;i>> ZoneData; return parsedMapInfo; } void TMXParser::ParseTag(std::string tag) { - XMLTag newTag; - //First character is a '<' so we discard it. - tag.erase(0,1); tag.erase(tag.length()-1,1); //Erase the first and last characters in the tag. Now parse by spaces. - std::stringstream s(tag); //Turn it into a string stream to now parse into individual whitespaces. - std::string data; - while (s.good()) { - int quotationMarkCount=0; - bool pastEquals=false; - data=""; - bool valid=false; - while(s.good()){ - int character=s.get(); - if(character=='"'){ - quotationMarkCount++; - } - if(character==' '&"ationMarkCount%2==0){ - valid=true; - break; - } - data+=character; - if(pastEquals&"ationMarkCount%2==0){ - valid=true; - break; - } - if(character=='='&"ationMarkCount%2==0){ - pastEquals=true; + + + auto ReadNextTag=[&](){ + XMLTag newTag; + //First character is a '<' so we discard it. + tag.erase(0,1); tag.erase(tag.length()-1,1); //Erase the first and last characters in the tag. Now parse by spaces. + std::stringstream s(tag); //Turn it into a string stream to now parse into individual whitespaces. + std::string data; + while (s.good()) { + int quotationMarkCount=0; + bool pastEquals=false; + data=""; + bool valid=false; + while(s.good()){ + int character=s.get(); + if(character=='"'){ + quotationMarkCount++; + } + if(character==' '&"ationMarkCount%2==0){ + valid=true; + break; + } + data+=character; + if(pastEquals&"ationMarkCount%2==0){ + valid=true; + break; + } + if(character=='='&"ationMarkCount%2==0){ + pastEquals=true; + } } - } - if(valid&&data.length()>0){ - if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag. - newTag.tag=data; - std::cout<<"Tag: "<0){ + if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag. + newTag.tag=data; + std::cout<<"Tag: "<>> ZoneData; parsedMapInfo.LayerData.push_back(l); }else if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup") { - if(buildingSpawner){ - parsedMapInfo.SpawnerData.push_back(obj); - } - buildingSpawner=true; - obj={newTag}; - goto spawnerResetSkip; + parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag}; } else if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") { parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2}; @@ -232,19 +238,25 @@ typedef std::map>> ZoneData; parsedMapInfo.ZoneData[newTag.data["type"]]=zones; } }else - if (newTag.tag=="property"&&buildingSpawner) { - if(newTag.data["propertytype"]=="MonsterName"){ - obj.properties.push_back(newTag); - } - goto spawnerResetSkip; + if (newTag.tag=="object"&&newTag.data["type"]=="Monster") { + //XMLTag monsterTag=ReadNextTag(); + //XMLTag spawnerLinkTag=ReadNextTag(); + //newTag.data["value"]=monsterTag.GetInteger("value"); //Value now contains which monster name this spawn represents. + monsterTag=newTag; + monsterPropertyTagCount=0; + } else + if (newTag.tag=="property"&&monsterPropertyTagCount==0) { + monsterTag.data["value"]=newTag.data["value"]; + monsterPropertyTagCount++; + } else + if (newTag.tag=="property"&&monsterPropertyTagCount==1) { + spawnerLinkTag=newTag; + monsterTag.data["spawnerLink"]=spawnerLinkTag.data["value"]; + accumulatedMonsterTags.push_back(monsterTag); + monsterPropertyTagCount=-1; } else { std::cout<<"Unsupported tag format! Ignoring."<<"\n"; } - if(buildingSpawner){ - parsedMapInfo.SpawnerData.push_back(obj); - } - buildingSpawner=false; - spawnerResetSkip: std::cout<<"\n"<<"=============\n"; } TMXParser::TMXParser(std::string file){ @@ -289,8 +301,8 @@ typedef std::map>> ZoneData; } } - if(buildingSpawner){ - parsedMapInfo.SpawnerData.push_back(obj); + for(XMLTag&monster:accumulatedMonsterTags){ + parsedMapInfo.SpawnerData[monster.GetInteger("spawnerLink")].monsters.push_back(monster); } std::cout<<"Parsed Map Data:\n"< - + @@ -1044,7 +1044,6 @@ - @@ -1054,9 +1053,6 @@ - - - @@ -1133,6 +1129,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +