CTownHandler.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef CTOWNHANDLER_H
  2. #define CTOWNHANDLER_H
  3. #include "../global.h"
  4. #include <set>
  5. class CBuilding;
  6. class CSpell;
  7. class CHero;
  8. class CGTownInstance;
  9. class DLL_EXPORT CTown
  10. {
  11. std::string name; //name of type
  12. public:
  13. std::vector<std::string> names; //names of the town instances
  14. std::vector<int> basicCreatures; //level (from 0) -> ID
  15. std::vector<int> upgradedCreatures; //level (from 0) -> ID
  16. std::map<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
  17. ui32 mageLevel; //max available mage guild level
  18. int bonus; //pic number
  19. ui16 primaryRes, warMachine;
  20. ui8 typeID;
  21. const std::vector<std::string> & Names() const;
  22. const std::string & Name() const;
  23. void Name(const std::string & val) { name = val; }
  24. template <typename Handler> void serialize(Handler &h, const int version)
  25. {
  26. h & names & basicCreatures & upgradedCreatures & hordeLvl & mageLevel & bonus
  27. & primaryRes & warMachine & typeID;
  28. }
  29. };
  30. struct DLL_EXPORT Structure
  31. {
  32. int ID;
  33. int3 pos;
  34. std::string defName, borderName, areaName, name;
  35. int townID, group;
  36. bool operator<(const Structure & p2) const
  37. {
  38. if(pos.z != p2.pos.z)
  39. return (pos.z) < (p2.pos.z);
  40. else
  41. return (ID) < (p2.ID);
  42. }
  43. };
  44. class DLL_EXPORT CTownHandler
  45. {
  46. public:
  47. std::vector<CTown> towns;
  48. std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
  49. std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
  50. CTownHandler();
  51. ~CTownHandler();
  52. void loadNames();
  53. void loadStructures();
  54. template <typename Handler> void serialize(Handler &h, const int version)
  55. {
  56. h & towns & requirements;
  57. if(!h.saving)
  58. loadStructures();
  59. }
  60. };
  61. #endif //CTOWNHANDLER_H