mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-05 00:49:09 +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:
@ -60,12 +60,10 @@ const BattleHexArray & Unit::getSurroundingHexes(BattleHex assumedPosition) cons
|
||||
|
||||
const BattleHexArray & Unit::getSurroundingHexes(BattleHex position, bool twoHex, BattleSide side)
|
||||
{
|
||||
assert(position.isValid()); // check outside if position isValid
|
||||
|
||||
if(!twoHex)
|
||||
return BattleHexArray::neighbouringTilesCache[position];
|
||||
return position.getNeighbouringTiles();
|
||||
|
||||
return BattleHexArray::neighbouringTilesDblWide.at(side).at(position);
|
||||
return position.getNeighbouringTilesDblWide(side);
|
||||
}
|
||||
|
||||
BattleHexArray Unit::getAttackableHexes(const Unit * attacker) const
|
||||
@ -88,7 +86,7 @@ BattleHexArray Unit::getAttackableHexes(const Unit * attacker) const
|
||||
hexes.pop_back();
|
||||
|
||||
for(auto hex : hexes)
|
||||
targetableHexes.insert(BattleHexArray::neighbouringTilesCache[hex]);
|
||||
targetableHexes.insert(hex.getNeighbouringTiles());
|
||||
}
|
||||
|
||||
return targetableHexes;
|
||||
|
Reference in New Issue
Block a user