CTownHandler.h 2.0 KB

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