CTownHandler.h 2.1 KB

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