2
0

CGameStateCampaign.h 2.4 KB

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