1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
/*
* AINodeStorage.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../../../lib/CPathfinder.h"
#include "../../../lib/mapObjects/CGHeroInstance.h"
#include "../AIUtility.h"
#include "Actions/SpecialAction.h"
namespace NKAI
{
extern const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN;
class ChainActor;
class HeroActor;
class Nullkiller;
class HeroExchangeArmy : public CArmedInstance
{
public:
TResources armyCost;
bool requireBuyArmy;
virtual bool needsLastStack() const override;
std::shared_ptr<SpecialAction> getActorAction() const;
HeroExchangeArmy() : CArmedInstance(true), armyCost(), requireBuyArmy(false)
{
}
};
struct ExchangeResult
{
bool lockAcquired;
ChainActor * actor;
ExchangeResult() : lockAcquired(true), actor(nullptr) {}
};
class ChainActor
{
protected:
ChainActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask);
ChainActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * heroArmy);
ChainActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
public:
uint64_t chainMask;
bool isMovable;
bool allowUseResources;
bool allowBattle;
bool allowSpellCast;
std::shared_ptr<SpecialAction> actorAction;
const CGHeroInstance * hero;
HeroRole heroRole;
const CCreatureSet * creatureSet;
const ChainActor * battleActor;
const ChainActor * castActor;
const ChainActor * resourceActor;
const ChainActor * carrierParent;
const ChainActor * otherParent;
const ChainActor * baseActor;
int3 initialPosition;
EPathfindingLayer layer;
uint32_t initialMovement;
uint32_t initialTurn;
uint64_t armyValue;
float heroFightingStrength;
uint8_t actorExchangeCount;
TResources armyCost;
std::shared_ptr<TurnInfo> tiCache;
ChainActor() = default;
virtual ~ChainActor() = default;
virtual std::string toString() const;
ExchangeResult tryExchangeNoLock(const ChainActor * other) const { return tryExchangeNoLock(this, other); }
void setBaseActor(HeroActor * base);
virtual const CGObjectInstance * getActorObject() const { return hero; }
int maxMovePoints(CGPathNode::ELayer layer);
protected:
virtual ExchangeResult tryExchangeNoLock(const ChainActor * specialActor, const ChainActor * other) const;
};
class HeroExchangeMap
{
private:
const HeroActor * actor;
std::map<const ChainActor *, HeroActor *> exchangeMap;
const Nullkiller * ai;
boost::shared_mutex sync;
public:
HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai);
~HeroExchangeMap();
ExchangeResult tryExchangeNoLock(const ChainActor * other);
private:
HeroExchangeArmy * pickBestCreatures(const CCreatureSet * army1, const CCreatureSet * army2) const;
HeroExchangeArmy * tryUpgrade(const CCreatureSet * army, const CGObjectInstance * upgrader, TResources resources) const;
};
class HeroActor : public ChainActor
{
public:
static const int SPECIAL_ACTORS_COUNT = 7;
private:
ChainActor specialActors[SPECIAL_ACTORS_COUNT];
std::unique_ptr<HeroExchangeMap> exchangeMap;
void setupSpecialActors();
public:
std::shared_ptr<SpecialAction> exchangeAction;
// chain flags, can be combined meaning hero exchange and so on
HeroActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask, const Nullkiller * ai);
HeroActor(const ChainActor * carrier, const ChainActor * other, const HeroExchangeArmy * army, const Nullkiller * ai);
protected:
virtual ExchangeResult tryExchangeNoLock(const ChainActor * specialActor, const ChainActor * other) const override;
};
class ObjectActor : public ChainActor
{
private:
const CGObjectInstance * object;
public:
ObjectActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
virtual std::string toString() const override;
const CGObjectInstance * getActorObject() const override;
};
class HillFortActor : public ObjectActor
{
public:
HillFortActor(const CGObjectInstance * hillFort, uint64_t chainMask);
};
class DwellingActor : public ObjectActor
{
private:
const CGDwelling * dwelling;
public:
DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek);
~DwellingActor();
virtual std::string toString() const override;
protected:
int getInitialTurn(bool waitForGrowth, int dayOfWeek);
CCreatureSet * getDwellingCreatures(const CGDwelling * dwelling, bool waitForGrowth);
};
class TownGarrisonActor : public ObjectActor
{
private:
const CGTownInstance * town;
public:
TownGarrisonActor(const CGTownInstance * town, uint64_t chainMask);
virtual std::string toString() const override;
};
}
|