2018-08-12 13:31:31 +02:00
|
|
|
/*
|
2018-12-01 10:30:37 +02:00
|
|
|
* AINodeStorage.h, part of VCMI engine
|
2018-08-12 13:31:31 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2018-10-10 15:07:28 +02:00
|
|
|
#include "../AIUtility.h"
|
2018-12-01 10:30:37 +02:00
|
|
|
#include "../Goals/AbstractGoal.h"
|
2018-08-12 13:31:31 +02:00
|
|
|
|
2018-12-09 15:20:46 +02:00
|
|
|
class AIPathNode;
|
|
|
|
|
2018-10-09 21:31:44 +02:00
|
|
|
class ISpecialAction
|
2018-08-12 13:31:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-10-09 21:31:44 +02:00
|
|
|
virtual Goals::TSubgoal whatToDo(HeroPtr hero) const = 0;
|
2018-12-09 15:20:46 +02:00
|
|
|
|
|
|
|
virtual void applyOnDestination(
|
|
|
|
HeroPtr hero,
|
|
|
|
CDestinationNodeInfo & destination,
|
|
|
|
const PathNodeInfo & source,
|
|
|
|
AIPathNode * dstMode,
|
|
|
|
const AIPathNode * srcNode) const
|
|
|
|
{
|
|
|
|
}
|
2018-08-12 13:31:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AIPathNode : public CGPathNode
|
|
|
|
{
|
|
|
|
uint32_t chainMask;
|
|
|
|
uint64_t danger;
|
2018-12-09 15:20:46 +02:00
|
|
|
uint32_t manaCost;
|
2018-10-09 21:31:44 +02:00
|
|
|
std::shared_ptr<const ISpecialAction> specialAction;
|
2018-08-12 13:31:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AIPathNodeInfo
|
|
|
|
{
|
|
|
|
uint32_t movementPointsLeft;
|
|
|
|
uint32_t movementPointsUsed;
|
|
|
|
int turns;
|
|
|
|
int3 coord;
|
|
|
|
uint64_t danger;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AIPath
|
|
|
|
{
|
|
|
|
std::vector<AIPathNodeInfo> nodes;
|
2018-10-09 21:31:44 +02:00
|
|
|
std::shared_ptr<const ISpecialAction> specialAction;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
|
|
|
AIPath();
|
|
|
|
|
|
|
|
/// Gets danger of path excluding danger of visiting the target object like creature bank
|
|
|
|
uint64_t getPathDanger() const;
|
|
|
|
|
|
|
|
/// Gets danger of path including danger of visiting the target object like creature bank
|
|
|
|
uint64_t getTotalDanger(HeroPtr hero) const;
|
|
|
|
|
|
|
|
int3 firstTileToGet() const;
|
|
|
|
|
|
|
|
uint32_t movementCost() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AINodeStorage : public INodeStorage
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int3 sizes;
|
|
|
|
|
|
|
|
/// 1-3 - position on map, 4 - layer (air, water, land), 5 - chain (normal, battle, spellcast and combinations)
|
|
|
|
boost::multi_array<AIPathNode, 5> nodes;
|
|
|
|
const CGHeroInstance * hero;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// more than 1 chain layer allows us to have more than 1 path to each tile so we can chose more optimal one.
|
2018-10-09 21:31:44 +02:00
|
|
|
static const int NUM_CHAINS = 3;
|
|
|
|
|
|
|
|
// chain flags, can be combined
|
|
|
|
static const int NORMAL_CHAIN = 1;
|
|
|
|
static const int BATTLE_CHAIN = 2;
|
|
|
|
static const int CAST_CHAIN = 4;
|
|
|
|
static const int RESOURCE_CHAIN = 8;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
|
|
|
AINodeStorage(const int3 & sizes);
|
|
|
|
~AINodeStorage();
|
|
|
|
|
|
|
|
virtual CGPathNode * getInitialNode() override;
|
|
|
|
virtual void resetTile(const int3 & tile, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility) override;
|
|
|
|
|
|
|
|
virtual std::vector<CGPathNode *> calculateNeighbours(
|
2018-10-07 13:51:27 +02:00
|
|
|
const PathNodeInfo & source,
|
|
|
|
const PathfinderConfig * pathfinderConfig,
|
|
|
|
const CPathfinderHelper * pathfinderHelper) override;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
|
|
|
virtual std::vector<CGPathNode *> calculateTeleportations(
|
2018-10-07 13:51:27 +02:00
|
|
|
const PathNodeInfo & source,
|
|
|
|
const PathfinderConfig * pathfinderConfig,
|
|
|
|
const CPathfinderHelper * pathfinderHelper) override;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
2018-10-07 13:51:27 +02:00
|
|
|
virtual void commit(CDestinationNodeInfo & destination, const PathNodeInfo & source) override;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
2018-10-07 13:51:27 +02:00
|
|
|
const AIPathNode * getAINode(const CGPathNode * node) const;
|
|
|
|
void updateAINode(CGPathNode * node, std::function<void (AIPathNode *)> updater);
|
|
|
|
|
|
|
|
bool isBattleNode(const CGPathNode * node) const;
|
|
|
|
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
|
2018-10-09 21:31:44 +02:00
|
|
|
boost::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber);
|
2018-10-28 15:03:40 +02:00
|
|
|
std::vector<AIPath> getChainInfo(int3 pos, bool isOnLand) const;
|
2018-12-29 15:55:20 +02:00
|
|
|
bool isTileAccessible(int3 pos, const EPathfindingLayer layer) const;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
|
|
|
void setHero(HeroPtr heroPtr)
|
|
|
|
{
|
|
|
|
hero = heroPtr.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * getHero() const
|
|
|
|
{
|
|
|
|
return hero;
|
|
|
|
}
|
|
|
|
};
|