2021-05-15 19:59:43 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2021-05-16 13:38:53 +02:00
|
|
|
#include "Actions/SpecialAction.h"
|
2021-05-15 19:59:43 +02:00
|
|
|
|
|
|
|
class HeroActor;
|
2020-05-04 17:58:43 +02:00
|
|
|
class Nullkiller;
|
2021-05-15 19:59:43 +02:00
|
|
|
|
2021-05-15 20:56:08 +02:00
|
|
|
class HeroExchangeArmy : public CCreatureSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool needsLastStack() const override;
|
|
|
|
};
|
|
|
|
|
2021-05-15 19:59:43 +02:00
|
|
|
class ChainActor
|
|
|
|
{
|
|
|
|
protected:
|
2021-05-16 13:56:13 +02:00
|
|
|
ChainActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask);
|
2021-05-15 19:59:43 +02:00
|
|
|
ChainActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * heroArmy);
|
2019-03-17 23:27:09 +02:00
|
|
|
ChainActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
|
2021-05-15 19:59:43 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
uint64_t chainMask;
|
|
|
|
bool isMovable;
|
|
|
|
bool allowUseResources;
|
|
|
|
bool allowBattle;
|
|
|
|
bool allowSpellCast;
|
|
|
|
const CGHeroInstance * hero;
|
2021-05-16 13:56:13 +02:00
|
|
|
HeroRole heroRole;
|
2021-05-15 19:59:43 +02:00
|
|
|
const CCreatureSet * creatureSet;
|
|
|
|
const ChainActor * battleActor;
|
|
|
|
const ChainActor * castActor;
|
|
|
|
const ChainActor * resourceActor;
|
|
|
|
const ChainActor * carrierParent;
|
|
|
|
const ChainActor * otherParent;
|
2019-03-17 23:27:09 +02:00
|
|
|
const ChainActor * baseActor;
|
2021-05-15 19:59:43 +02:00
|
|
|
int3 initialPosition;
|
|
|
|
EPathfindingLayer layer;
|
|
|
|
uint32_t initialMovement;
|
|
|
|
uint32_t initialTurn;
|
|
|
|
uint64_t armyValue;
|
2021-05-15 20:54:58 +02:00
|
|
|
float heroFightingStrength;
|
|
|
|
uint8_t actorExchangeCount;
|
2021-05-15 20:55:29 +02:00
|
|
|
TResources armyCost;
|
2021-05-15 19:59:43 +02:00
|
|
|
|
|
|
|
ChainActor(){}
|
2019-03-17 23:27:09 +02:00
|
|
|
|
|
|
|
virtual bool canExchange(const ChainActor * other) const;
|
2021-05-15 20:54:28 +02:00
|
|
|
virtual std::string toString() const;
|
2019-03-17 23:27:09 +02:00
|
|
|
ChainActor * exchange(const ChainActor * other) const { return exchange(this, other); }
|
2021-05-15 19:59:43 +02:00
|
|
|
void setBaseActor(HeroActor * base);
|
2021-05-16 13:19:00 +02:00
|
|
|
virtual const CGObjectInstance * getActorObject() const { return hero; }
|
2021-05-15 19:59:43 +02:00
|
|
|
|
2019-03-17 23:27:09 +02:00
|
|
|
protected:
|
|
|
|
virtual ChainActor * exchange(const ChainActor * specialActor, const ChainActor * other) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class HeroExchangeMap
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const HeroActor * actor;
|
|
|
|
std::map<const ChainActor *, HeroActor *> exchangeMap;
|
|
|
|
std::map<const ChainActor *, bool> canExchangeCache;
|
2020-05-04 17:58:43 +02:00
|
|
|
const Nullkiller * ai;
|
2019-03-17 23:27:09 +02:00
|
|
|
|
|
|
|
public:
|
2020-05-04 17:58:43 +02:00
|
|
|
HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai)
|
2019-03-17 23:27:09 +02:00
|
|
|
:actor(actor), ai(ai)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-15 20:56:08 +02:00
|
|
|
~HeroExchangeMap();
|
|
|
|
|
2019-03-17 23:27:09 +02:00
|
|
|
HeroActor * exchange(const ChainActor * other);
|
|
|
|
bool canExchange(const ChainActor * other);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CCreatureSet * pickBestCreatures(const CCreatureSet * army1, const CCreatureSet * army2) const;
|
2021-05-16 13:19:00 +02:00
|
|
|
CCreatureSet * tryUpgrade(const CCreatureSet * army, const CGObjectInstance * upgrader, TResources resources) const;
|
2021-05-15 19:59:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class HeroActor : public ChainActor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const int SPECIAL_ACTORS_COUNT = 7;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ChainActor specialActors[SPECIAL_ACTORS_COUNT];
|
2019-03-17 23:27:09 +02:00
|
|
|
HeroExchangeMap * exchangeMap;
|
2021-05-15 19:59:43 +02:00
|
|
|
|
|
|
|
void setupSpecialActors();
|
|
|
|
|
|
|
|
public:
|
2021-05-16 13:38:53 +02:00
|
|
|
std::shared_ptr<SpecialAction> exchangeAction;
|
2021-05-15 19:59:43 +02:00
|
|
|
// chain flags, can be combined meaning hero exchange and so on
|
|
|
|
|
2021-05-16 13:56:13 +02:00
|
|
|
HeroActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask, const Nullkiller * ai);
|
2020-05-04 17:58:43 +02:00
|
|
|
HeroActor(const ChainActor * carrier, const ChainActor * other, const CCreatureSet * army, const Nullkiller * ai);
|
2021-05-15 19:59:43 +02:00
|
|
|
|
2019-03-17 23:27:09 +02:00
|
|
|
virtual bool canExchange(const ChainActor * other) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ChainActor * exchange(const ChainActor * specialActor, const ChainActor * other) const override;
|
2021-05-15 19:59:43 +02:00
|
|
|
};
|
2019-03-17 23:27:09 +02:00
|
|
|
|
2021-05-16 13:19:00 +02:00
|
|
|
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
|
2019-03-17 23:27:09 +02:00
|
|
|
{
|
2021-05-15 20:54:28 +02:00
|
|
|
private:
|
|
|
|
const CGDwelling * dwelling;
|
|
|
|
|
2019-03-17 23:27:09 +02:00
|
|
|
public:
|
|
|
|
DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek);
|
|
|
|
~DwellingActor();
|
2021-05-15 20:54:28 +02:00
|
|
|
virtual std::string toString() const override;
|
2019-03-17 23:27:09 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int getInitialTurn(bool waitForGrowth, int dayOfWeek);
|
|
|
|
CCreatureSet * getDwellingCreatures(const CGDwelling * dwelling, bool waitForGrowth);
|
|
|
|
};
|
|
|
|
|
2021-05-16 13:19:00 +02:00
|
|
|
class TownGarrisonActor : public ObjectActor
|
2019-03-17 23:27:09 +02:00
|
|
|
{
|
2021-05-15 20:54:28 +02:00
|
|
|
private:
|
|
|
|
const CGTownInstance * town;
|
|
|
|
|
2019-03-17 23:27:09 +02:00
|
|
|
public:
|
|
|
|
TownGarrisonActor(const CGTownInstance * town, uint64_t chainMask);
|
2021-05-15 20:54:28 +02:00
|
|
|
virtual std::string toString() const override;
|
2019-03-17 23:27:09 +02:00
|
|
|
};
|