Actors.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * AINodeStorage.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 "../../../lib/CPathfinder.h"
  12. #include "../../../lib/mapObjects/CGHeroInstance.h"
  13. #include "../AIUtility.h"
  14. #include "Actions/ISpecialAction.h"
  15. class HeroActor;
  16. class VCAI;
  17. class HeroExchangeArmy : public CCreatureSet
  18. {
  19. public:
  20. virtual bool needsLastStack() const override;
  21. };
  22. class ChainActor
  23. {
  24. protected:
  25. ChainActor(const CGHeroInstance * hero, uint64_t chainMask);
  26. ChainActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * heroArmy);
  27. ChainActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
  28. public:
  29. uint64_t chainMask;
  30. bool isMovable;
  31. bool allowUseResources;
  32. bool allowBattle;
  33. bool allowSpellCast;
  34. const CGHeroInstance * hero;
  35. const CCreatureSet * creatureSet;
  36. const ChainActor * battleActor;
  37. const ChainActor * castActor;
  38. const ChainActor * resourceActor;
  39. const ChainActor * carrierParent;
  40. const ChainActor * otherParent;
  41. const ChainActor * baseActor;
  42. int3 initialPosition;
  43. EPathfindingLayer layer;
  44. uint32_t initialMovement;
  45. uint32_t initialTurn;
  46. uint64_t armyValue;
  47. float heroFightingStrength;
  48. uint8_t actorExchangeCount;
  49. TResources armyCost;
  50. ChainActor(){}
  51. virtual bool canExchange(const ChainActor * other) const;
  52. virtual std::string toString() const;
  53. ChainActor * exchange(const ChainActor * other) const { return exchange(this, other); }
  54. void setBaseActor(HeroActor * base);
  55. protected:
  56. virtual ChainActor * exchange(const ChainActor * specialActor, const ChainActor * other) const;
  57. };
  58. class HeroExchangeMap
  59. {
  60. private:
  61. const HeroActor * actor;
  62. std::map<const ChainActor *, HeroActor *> exchangeMap;
  63. std::map<const ChainActor *, bool> canExchangeCache;
  64. const VCAI * ai;
  65. public:
  66. HeroExchangeMap(const HeroActor * actor, const VCAI * ai)
  67. :actor(actor), ai(ai)
  68. {
  69. }
  70. ~HeroExchangeMap();
  71. HeroActor * exchange(const ChainActor * other);
  72. bool canExchange(const ChainActor * other);
  73. private:
  74. CCreatureSet * pickBestCreatures(const CCreatureSet * army1, const CCreatureSet * army2) const;
  75. };
  76. class HeroActor : public ChainActor
  77. {
  78. public:
  79. static const int SPECIAL_ACTORS_COUNT = 7;
  80. private:
  81. ChainActor specialActors[SPECIAL_ACTORS_COUNT];
  82. HeroExchangeMap * exchangeMap;
  83. void setupSpecialActors();
  84. public:
  85. std::shared_ptr<ISpecialAction> exchangeAction;
  86. // chain flags, can be combined meaning hero exchange and so on
  87. HeroActor(const CGHeroInstance * hero, uint64_t chainMask, const VCAI * ai);
  88. HeroActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * army, const VCAI * ai);
  89. virtual bool canExchange(const ChainActor * other) const override;
  90. protected:
  91. virtual ChainActor * exchange(const ChainActor * specialActor, const ChainActor * other) const override;
  92. };
  93. class DwellingActor : public ChainActor
  94. {
  95. private:
  96. const CGDwelling * dwelling;
  97. public:
  98. DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek);
  99. ~DwellingActor();
  100. virtual std::string toString() const override;
  101. protected:
  102. int getInitialTurn(bool waitForGrowth, int dayOfWeek);
  103. CCreatureSet * getDwellingCreatures(const CGDwelling * dwelling, bool waitForGrowth);
  104. };
  105. class TownGarrisonActor : public ChainActor
  106. {
  107. private:
  108. const CGTownInstance * town;
  109. public:
  110. TownGarrisonActor(const CGTownInstance * town, uint64_t chainMask);
  111. virtual std::string toString() const override;
  112. };