CGameStateCampaign.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * CGameStateCampaign.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. #include "../GameConstants.h"
  12. #include "../campaign/CampaignConstants.h"
  13. #include "../serializer/Serializeable.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct CampaignBonus;
  16. struct CampaignTravel;
  17. class CGHeroInstance;
  18. class CGameState;
  19. class CMap;
  20. struct CampaignHeroReplacement
  21. {
  22. CampaignHeroReplacement(std::shared_ptr<CGHeroInstance> hero, const ObjectInstanceID & heroPlaceholderId);
  23. std::shared_ptr<CGHeroInstance> hero;
  24. ObjectInstanceID heroPlaceholderId;
  25. std::vector<ArtifactPosition> transferrableArtifacts;
  26. };
  27. class CGameStateCampaign : public Serializeable
  28. {
  29. CGameState * gameState = nullptr;
  30. /// Contains list of heroes that may be available in this scenario
  31. /// temporary helper for game initialization, not serialized
  32. std::vector<CampaignHeroReplacement> campaignHeroReplacements;
  33. /// Returns ID of scenario from which hero placeholders should be selected
  34. std::optional<CampaignScenarioID> getHeroesSourceScenario() const;
  35. /// returns heroes and placeholders in where heroes will be put
  36. void generateCampaignHeroesToReplace();
  37. std::optional<CampaignBonus> currentBonus() const;
  38. /// Trims hero parameters that should not transfer between scenarios according to travelOptions flags
  39. void trimCrossoverHeroesParameters(const CampaignTravel & travelOptions);
  40. void replaceHeroesPlaceholders();
  41. void transferMissingArtifacts(const CampaignTravel & travelOptions);
  42. void giveCampaignBonusToHero(CGHeroInstance * hero);
  43. public:
  44. CGameStateCampaign();
  45. CGameStateCampaign(CGameState * owner);
  46. void setGamestate(CGameState * owner);
  47. void placeCampaignHeroes();
  48. void initStartingResources();
  49. void initHeroes();
  50. void initTowns();
  51. bool playerHasStartingHero(PlayerColor player) const;
  52. std::unique_ptr<CMap> getCurrentMap();
  53. template <typename Handler> void serialize(Handler &h)
  54. {
  55. if (h.saving || h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
  56. {
  57. // no-op, but needed to auto-create this class if gamestate had it during serialization
  58. }
  59. else
  60. {
  61. bool dummyA = false;
  62. uint32_t dummyB = 0;
  63. uint16_t dummyC = 0;
  64. h & dummyA;
  65. h & dummyB;
  66. h & dummyC;
  67. }
  68. }
  69. };
  70. VCMI_LIB_NAMESPACE_END