1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Rotation rebase2 (#912)

* Instead of [x][y][z] coordinates, map will be stored as [z][x][y].
* Nullkiller AI can get it too.
* Use boost::multi_array instead of nested vectors
* In MapHandler too
* Rotate foreach algorithms, too
* VCAI gets rotated, too
This commit is contained in:
DjWarmonger
2022-09-18 16:39:10 +02:00
committed by GitHub
parent e85f8a56bb
commit 7ba271edf1
44 changed files with 502 additions and 1015 deletions

View File

@@ -20,7 +20,7 @@
AINodeStorage::AINodeStorage(const int3 & Sizes)
: sizes(Sizes)
{
nodes.resize(boost::extents[sizes.x][sizes.y][sizes.z][EPathfindingLayer::NUM_LAYERS][NUM_CHAINS]);
nodes.resize(boost::extents[EPathfindingLayer::NUM_LAYERS][sizes.z][sizes.x][sizes.y][NUM_CHAINS]);
dangerEvaluator.reset(new FuzzyHelper());
}
@@ -28,8 +28,6 @@ AINodeStorage::~AINodeStorage() = default;
void AINodeStorage::initialize(const PathfinderOptions & options, const CGameState * gs)
{
//TODO: fix this code duplication with NodeStorage::initialize, problem is to keep `resetTile` inline
int3 pos;
const int3 sizes = gs->getMapSize();
const auto & fow = static_cast<const CGameInfoCallback *>(gs)->getPlayerTeam(hero->tempOwner)->fogOfWarMap;
@@ -39,11 +37,11 @@ void AINodeStorage::initialize(const PathfinderOptions & options, const CGameSta
const bool useFlying = options.useFlying;
const bool useWaterWalking = options.useWaterWalking;
for(pos.x=0; pos.x < sizes.x; ++pos.x)
for(pos.z=0; pos.z < sizes.z; ++pos.z)
{
for(pos.y=0; pos.y < sizes.y; ++pos.y)
for(pos.x=0; pos.x < sizes.x; ++pos.x)
{
for(pos.z=0; pos.z < sizes.z; ++pos.z)
for(pos.y=0; pos.y < sizes.y; ++pos.y)
{
const TerrainTile * tile = &gs->map->getTile(pos);
if(!tile->terType.isPassable())
@@ -87,7 +85,7 @@ bool AINodeStorage::isBattleNode(const CGPathNode * node) const
boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, const EPathfindingLayer layer, int chainNumber)
{
auto chains = nodes[pos.x][pos.y][pos.z][layer];
auto chains = nodes[layer][pos.z][pos.x][pos.y];
for(AIPathNode & node : chains)
{
@@ -126,7 +124,7 @@ void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, CGPat
{
for(int i = 0; i < NUM_CHAINS; i++)
{
AIPathNode & heroNode = nodes[coord.x][coord.y][coord.z][layer][i];
AIPathNode & heroNode = nodes[layer][coord.z][coord.x][coord.y][i];
heroNode.chainMask = 0;
heroNode.danger = 0;
@@ -290,7 +288,7 @@ void AINodeStorage::calculateTownPortalTeleportations(
bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const
{
auto pos = destination.coord;
auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND];
auto chains = nodes[EPathfindingLayer::LAND][pos.z][pos.x][pos.y];
auto destinationNode = getAINode(destination.node);
for(const AIPathNode & node : chains)
@@ -323,7 +321,7 @@ bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNode
bool AINodeStorage::isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const
{
const AIPathNode & node = nodes[pos.x][pos.y][pos.z][layer][0];
const AIPathNode & node = nodes[layer][pos.z][pos.x][pos.y][0];
return node.action != CGPathNode::ENodeAction::UNKNOWN;
}
@@ -331,7 +329,7 @@ bool AINodeStorage::isTileAccessible(const int3 & pos, const EPathfindingLayer l
std::vector<AIPath> AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand) const
{
std::vector<AIPath> paths;
auto chains = nodes[pos.x][pos.y][pos.z][isOnLand ? EPathfindingLayer::LAND : EPathfindingLayer::SAIL];
auto chains = nodes[isOnLand ? EPathfindingLayer::LAND : EPathfindingLayer::SAIL][pos.z][pos.x][pos.y];
auto initialPos = hero->visitablePos();
for(const AIPathNode & node : chains)

View File

@@ -17,6 +17,10 @@
#include "../Goals/AbstractGoal.h"
#include "Actions/ISpecialAction.h"
class CCallback;
extern boost::thread_specific_ptr<CCallback> cb; //for templates
struct AIPathNode : public CGPathNode
{
uint32_t chainMask;
@@ -57,7 +61,9 @@ class AINodeStorage : public INodeStorage
private:
int3 sizes;
/// 1-3 - position on map, 4 - layer (air, water, land), 5 - chain (normal, battle, spellcast and combinations)
// 1 - layer (air, water, land)
// 2-4 - position on map[z][x][y]
// 5 - chain (normal, battle, spellcast and combinations)
boost::multi_array<AIPathNode, 5> nodes;
const CPlayerSpecificInfoCallback * cb;
const VCAI * ai;