1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/AI/Nullkiller/Pathfinding/Actors.h

175 lines
4.7 KiB
C++
Raw Normal View History

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/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
2022-09-26 20:01:07 +02:00
namespace NKAI
{
2021-05-16 14:08:39 +02:00
extern const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN;
class ChainActor;
2021-05-15 19:59:43 +02:00
class HeroActor;
class Nullkiller;
2021-05-15 19:59:43 +02:00
class HeroExchangeArmy : public CArmedInstance
2021-05-15 20:56:08 +02:00
{
public:
TResources armyCost;
bool requireBuyArmy;
bool needsLastStack() const override;
std::shared_ptr<SpecialAction> getActorAction() const;
2024-01-01 16:37:48 +02:00
HeroExchangeArmy(): CArmedInstance(nullptr, true), requireBuyArmy(false) {}
2021-05-15 20:56:08 +02:00
};
struct ExchangeResult
{
bool lockAcquired;
ChainActor * actor;
ExchangeResult() : lockAcquired(true), actor(nullptr) {}
};
2021-05-15 19:59:43 +02:00
class ChainActor
{
protected:
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);
ChainActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
2021-05-15 19:59:43 +02:00
public:
uint64_t chainMask;
2024-02-12 12:31:27 +02:00
bool isMovable = false;
bool allowUseResources = false;
bool allowBattle = false;
bool allowSpellCast = false;
std::shared_ptr<SpecialAction> actorAction;
2021-05-15 19:59:43 +02:00
const CGHeroInstance * hero;
HeroRole heroRole;
2024-02-12 12:31:27 +02:00
const CCreatureSet * creatureSet = nullptr;
const ChainActor * battleActor = nullptr;
const ChainActor * castActor = nullptr;
const ChainActor * resourceActor = nullptr;
const ChainActor * carrierParent = nullptr;
const ChainActor * otherParent = nullptr;
const ChainActor * baseActor = nullptr;
2021-05-15 19:59:43 +02:00
int3 initialPosition;
EPathfindingLayer layer;
2024-02-12 12:31:27 +02:00
uint32_t initialMovement = 0;
uint32_t initialTurn = 0;
2021-05-15 19:59:43 +02:00
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;
std::shared_ptr<TurnInfo> tiCache;
2021-05-15 19:59:43 +02:00
2022-09-22 10:02:16 +02:00
ChainActor() = default;
virtual ~ChainActor() = default;
2021-05-15 20:54:28 +02:00
virtual std::string toString() const;
ExchangeResult tryExchangeNoLock(const ChainActor * other) const { return tryExchangeNoLock(this, other); }
2021-05-15 19:59:43 +02:00
void setBaseActor(HeroActor * base);
virtual const CGObjectInstance * getActorObject() const { return hero; }
int maxMovePoints(EPathfindingLayer layer);
2021-05-15 19:59:43 +02:00
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);
2021-05-15 20:56:08 +02:00
~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;
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];
std::unique_ptr<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
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);
2021-05-15 19:59:43 +02:00
protected:
ExchangeResult tryExchangeNoLock(const ChainActor * specialActor, const ChainActor * other) const override;
2021-05-15 19:59:43 +02:00
};
class ObjectActor : public ChainActor
{
private:
const CGObjectInstance * object;
public:
ObjectActor(const CGObjectInstance * obj, const CCreatureSet * army, uint64_t chainMask, int initialTurn);
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
{
2021-05-15 20:54:28 +02:00
private:
const CGDwelling * dwelling;
public:
DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek);
~DwellingActor();
std::string toString() const override;
protected:
int getInitialTurn(bool waitForGrowth, int dayOfWeek);
CCreatureSet * getDwellingCreatures(const CGDwelling * dwelling, bool waitForGrowth);
};
class TownGarrisonActor : public ObjectActor
{
2021-05-15 20:54:28 +02:00
private:
const CGTownInstance * town;
public:
TownGarrisonActor(const CGTownInstance * town, uint64_t chainMask);
std::string toString() const override;
2022-09-22 10:02:16 +02:00
};
2022-09-26 20:01:07 +02:00
}