Browse Source

Adds ability to clear mapflags
* Added the Clear label to allow mapflags to be removed for importing use.
* Converts mapflag storage into multimap.

aleos 1 year ago
parent
commit
941085e826
3 changed files with 25 additions and 8 deletions
  1. 1 1
      doc/map_zones.txt
  2. 22 5
      src/map/map.cpp
  3. 2 2
      src/map/map.hpp

+ 1 - 1
doc/map_zones.txt

@@ -73,4 +73,4 @@ Mapflags: Mapflags that are applies to a zone. By default, the Value label is 1/
   - Flag: Skill_Duration
 	Value: AL_SANCTUARY,400 # Sets the 'skill_duration' mapflag to the zone.
   - Flag: NoMemo # Removes the 'nomemo' mapflag to the zone. Useful for import.
-    Value: 0
+    Clear: true

+ 22 - 5
src/map/map.cpp

@@ -449,9 +449,6 @@ uint64 MapZoneDatabase::parseBodyNode(const ryml::NodeRef& node) {
 	if (this->nodeExists(node, "Mapflags")) {
 		const auto &mapflagNode = node["Mapflags"];
 
-		// Mapflags are stored as double-key so that duplicate mapflags can be parsed.
-		uint16 mapflag_index = 0;
-
 		for (const auto &it : mapflagNode) {
 			std::string flag_name;
 
@@ -474,8 +471,28 @@ uint64 MapZoneDatabase::parseBodyNode(const ryml::NodeRef& node) {
 			} else
 				value = "1";
 
-			zone->mapflags.insert({ std::pair<int16, uint16>(static_cast<int16>(flag), mapflag_index), value });
-			mapflag_index++;
+			bool clear = false;
+
+			if (this->nodeExists(it, "Clear")) {
+				if (!this->asBool(it, "Clear", clear))
+					continue;
+			}
+
+			if (!clear) {
+				zone->mapflags.insert({ std::pair<int16, std::string>(static_cast<int16>(flag), value) });
+			} else {
+				// Get all mapflag keys that match
+				auto mapflagit = zone->mapflags.equal_range(static_cast<int16>(flag));
+
+				// Iterate over the mapflags to get their values
+				for (std::multimap<int16, std::string>::iterator it = mapflagit.first; it != mapflagit.second; ++it) {
+					// Compare parse value with what's already in memory
+					if (it->second.find(value) == 0) {
+						zone->mapflags.erase(it);
+						break;
+					}
+				}
+			}
 		}
 	}
 

+ 2 - 2
src/map/map.hpp

@@ -888,7 +888,7 @@ struct s_map_zone {
 	std::unordered_map<sc_type, uint16> disabled_statuses;
 	std::unordered_map<int32, uint16> restricted_jobs;
 	std::vector<int16> maps;
-	std::map<std::pair<int16, uint16>, std::string> mapflags;
+	std::multimap<int16, std::string> mapflags;
 };
 
 class MapZoneDatabase : public TypesafeYamlDatabase<uint16, s_map_zone> {
@@ -898,7 +898,7 @@ public:
 	}
 
 	const std::string getDefaultLocation() override;
-	uint64 parseBodyNode(const ryml::NodeRef& node) override;
+	uint64 parseBodyNode(const ryml::NodeRef &node) override;
 	void loadingFinished() override;
 };