Actors.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/SpecialAction.h"
  15. class HeroActor;
  16. class Nullkiller;
  17. class HeroExchangeArmy : public CCreatureSet
  18. {
  19. public:
  20. TResources armyCost;
  21. bool requireBuyArmy;
  22. virtual bool needsLastStack() const override;
  23. std::shared_ptr<SpecialAction> getActorAction() const;
  24. HeroExchangeArmy() : CCreatureSet(), armyCost(), requireBuyArmy(false)
  25. {
  26. }
  27. };
  28. class ChainActor
  29. {
  30. protected:
  31. ChainActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask);
  32. ChainActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * heroArmy);
  33. ChainActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
  34. public:
  35. uint64_t chainMask;
  36. bool isMovable;
  37. bool allowUseResources;
  38. bool allowBattle;
  39. bool allowSpellCast;
  40. std::shared_ptr<SpecialAction> actorAction;
  41. const CGHeroInstance * hero;
  42. HeroRole heroRole;
  43. const CCreatureSet * creatureSet;
  44. const ChainActor * battleActor;
  45. const ChainActor * castActor;
  46. const ChainActor * resourceActor;
  47. const ChainActor * carrierParent;
  48. const ChainActor * otherParent;
  49. const ChainActor * baseActor;
  50. int3 initialPosition;
  51. EPathfindingLayer layer;
  52. uint32_t initialMovement;
  53. uint32_t initialTurn;
  54. uint64_t armyValue;
  55. float heroFightingStrength;
  56. uint8_t actorExchangeCount;
  57. TResources armyCost;
  58. ChainActor(){}
  59. virtual bool canExchange(const ChainActor * other) const;
  60. virtual std::string toString() const;
  61. ChainActor * exchange(const ChainActor * other) const { return exchange(this, other); }
  62. void setBaseActor(HeroActor * base);
  63. virtual const CGObjectInstance * getActorObject() const { return hero; }
  64. protected:
  65. virtual ChainActor * exchange(const ChainActor * specialActor, const ChainActor * other) const;
  66. };
  67. class HeroExchangeMap
  68. {
  69. private:
  70. const HeroActor * actor;
  71. std::map<const ChainActor *, HeroActor *> exchangeMap;
  72. std::map<const ChainActor *, bool> canExchangeCache;
  73. const Nullkiller * ai;
  74. public:
  75. HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai)
  76. :actor(actor), ai(ai)
  77. {
  78. }
  79. ~HeroExchangeMap();
  80. HeroActor * exchange(const ChainActor * other);
  81. bool canExchange(const ChainActor * other);
  82. private:
  83. HeroExchangeArmy * pickBestCreatures(const CCreatureSet * army1, const CCreatureSet * army2) const;
  84. HeroExchangeArmy * tryUpgrade(const CCreatureSet * army, const CGObjectInstance * upgrader, TResources resources) const;
  85. };
  86. class HeroActor : public ChainActor
  87. {
  88. public:
  89. static const int SPECIAL_ACTORS_COUNT = 7;
  90. private:
  91. ChainActor specialActors[SPECIAL_ACTORS_COUNT];
  92. HeroExchangeMap * exchangeMap;
  93. void setupSpecialActors();
  94. public:
  95. std::shared_ptr<SpecialAction> exchangeAction;
  96. // chain flags, can be combined meaning hero exchange and so on
  97. HeroActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask, const Nullkiller * ai);
  98. HeroActor(const ChainActor * carrier, const ChainActor * other, const HeroExchangeArmy * army, const Nullkiller * ai);
  99. virtual bool canExchange(const ChainActor * other) const override;
  100. protected:
  101. virtual ChainActor * exchange(const ChainActor * specialActor, const ChainActor * other) const override;
  102. };
  103. class ObjectActor : public ChainActor
  104. {
  105. private:
  106. const CGObjectInstance * object;
  107. public:
  108. ObjectActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
  109. virtual std::string toString() const override;
  110. const CGObjectInstance * getActorObject() const override;
  111. };
  112. class HillFortActor : public ObjectActor
  113. {
  114. public:
  115. HillFortActor(const CGObjectInstance * hillFort, uint64_t chainMask);
  116. };
  117. class DwellingActor : public ObjectActor
  118. {
  119. private:
  120. const CGDwelling * dwelling;
  121. public:
  122. DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek);
  123. ~DwellingActor();
  124. virtual std::string toString() const override;
  125. protected:
  126. int getInitialTurn(bool waitForGrowth, int dayOfWeek);
  127. CCreatureSet * getDwellingCreatures(const CGDwelling * dwelling, bool waitForGrowth);
  128. };
  129. class TownGarrisonActor : public ObjectActor
  130. {
  131. private:
  132. const CGTownInstance * town;
  133. public:
  134. TownGarrisonActor(const CGTownInstance * town, uint64_t chainMask);
  135. virtual std::string toString() const override;
  136. };