MapObjectsEvaluator.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * MapObjectsEvaluator.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. struct AiMapObjectID
  12. {
  13. int primaryID;
  14. int secondaryID;
  15. AiMapObjectID(int primID, int secID) : primaryID(primID), secondaryID(secID) {};
  16. };
  17. inline bool operator<(const AiMapObjectID& obj1, const AiMapObjectID& obj2)
  18. {
  19. if(obj1.primaryID != obj2.primaryID)
  20. return obj1.primaryID < obj2.primaryID;
  21. else
  22. return obj1.secondaryID < obj2.secondaryID;
  23. }
  24. inline bool operator==(const AiMapObjectID& obj1, const AiMapObjectID& obj2)
  25. {
  26. if(obj1.primaryID == obj2.primaryID)
  27. return obj1.secondaryID == obj2.secondaryID;
  28. return false;
  29. }
  30. class MapObjectsEvaluator
  31. {
  32. private:
  33. std::map<AiMapObjectID, int> objectDatabase; //value for each object type
  34. public:
  35. MapObjectsEvaluator();
  36. static MapObjectsEvaluator & getInstance();
  37. boost::optional<int> getObjectValue(int primaryID, int secondaryID);
  38. void addObjectData(int primaryID, int secondaryID, int value);
  39. void removeObjectData(int primaryID, int secondaryID, int value);
  40. };