1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

Refactor BattleHex, remake the use of precomputed neighbouring tiles containers.

- Moved short, frequently used functions to the BattleHex header for inlining
- Made BattleHex a class with a private hex value
- Moved getClosestTile implementation back to BattleHex
- Enabled access to static precomputed data in BattleHexArray via BattleHex
(note: circular dependency prevented static precomputed containers being directly placed in BattleHex)
This commit is contained in:
MichalZr6
2025-01-02 23:56:04 +01:00
parent ac8104d56d
commit dad6437661
27 changed files with 338 additions and 312 deletions

View File

@ -482,7 +482,7 @@ std::vector<std::vector<BattleHex::EDir>> BattleFieldController::getOutsideNeigh
{
// get all neighbours and their directions
const BattleHexArray & neighbouringTiles = BattleHexArray::getAllNeighbouringTiles(hex);
const BattleHexArray & neighbouringTiles = hex.getAllNeighbouringTiles();
std::vector<BattleHex::EDir> outsideNeighbourDirections;
@ -492,9 +492,7 @@ std::vector<std::vector<BattleHex::EDir>> BattleFieldController::getOutsideNeigh
if(!neighbouringTiles[direction].isAvailable())
continue;
auto it = std::find(wholeRangeHexes.begin(), wholeRangeHexes.end(), neighbouringTiles[direction]);
if(it == wholeRangeHexes.end())
if(!wholeRangeHexes.contains(neighbouringTiles[direction]))
outsideNeighbourDirections.push_back(BattleHex::EDir(direction)); // push direction
}
@ -680,7 +678,7 @@ BattleHex BattleFieldController::getHexAtPosition(Point hoverPos)
BattleHex::EDir BattleFieldController::selectAttackDirection(BattleHex myNumber)
{
const bool doubleWide = owner.stacksController->getActiveStack()->doubleWide();
const BattleHexArray & neighbours = BattleHexArray::getAllNeighbouringTiles(myNumber);
const BattleHexArray & neighbours = myNumber.getAllNeighbouringTiles();
// 0 1
// 5 x 2
// 4 3