Use occupancy fast path for adjacent enemies (#8792)

This commit is contained in:
2026-07-26 07:04:39 -07:00
committed by GitHub
parent 9dba9deaa1
commit 0f72494fef
4 changed files with 31 additions and 2 deletions
@@ -57,7 +57,7 @@ auto shardok::MoveCommand::InternalExecute(
const auto* destinationTerrain = GetTerrain(map, destination);
bool startedInEnemyZoc = enemyZocCoords.Contains(origin);
vector<const Unit*> knownAdjacentEnemies =
KnownAdjacentEnemies(player, allUnits, map, allyPids, origin);
KnownAdjacentEnemies(player, currentState, allyPids, origin);
MutatingSpendActionPoints(
&mover,
@@ -132,7 +132,7 @@ auto shardok::MoveCommand::InternalExecute(
if (!startedInEnemyZoc) {
vector<const Unit*> newAdjacentEnemies =
KnownAdjacentEnemies(player, allUnits, map, allyPids, destination);
KnownAdjacentEnemies(player, currentState, allyPids, destination);
for (const Unit* possibleChargee : newAdjacentEnemies) {
if (std::ranges::find_if(
@@ -42,6 +42,7 @@ cc_library(
deps = [
":hex_cube_utils",
"//src/main/cpp/net/eagle0/common:filesystem_utils",
"//src/main/cpp/net/eagle0/shardok/library:game_state_w",
"//src/main/cpp/net/eagle0/shardok/library/map:coordinates",
"//src/main/cpp/net/eagle0/shardok/library/map:coords_set",
"//src/main/cpp/net/eagle0/shardok/library/map:hex_map_direction",
@@ -15,6 +15,7 @@
#include "HexCubeUtils.hpp"
#include "src/main/cpp/net/eagle0/common/FilesystemUtils.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/GameStateW.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/map/CoordsSet.hpp"
namespace shardok {
@@ -694,6 +695,25 @@ auto KnownAdjacentEnemies(
return knownAdjacentEnemies;
}
auto KnownAdjacentEnemies(
const PlayerId playerId,
const GameStateW &gameState,
const std::vector<PlayerId> &allyPids,
const Coords &coords) -> std::vector<const Unit *> {
const CoordsSet &adjacentCoords = HexMapUtils::GetAdjacentCoords(gameState->hex_map(), coords);
std::vector<const Unit *> knownAdjacentEnemies{};
knownAdjacentEnemies.reserve(adjacentCoords.size());
for (const Coords &adjCoords : adjacentCoords) {
if (const auto *possibleEnemy =
gameState.GetKnownEnemyOccupant(playerId, allyPids, adjCoords)) {
knownAdjacentEnemies.push_back(possibleEnemy);
}
}
return knownAdjacentEnemies;
}
auto KnownEnemyOccupant(
const PlayerId playerId,
const Units *units,
@@ -22,6 +22,8 @@
#include "src/main/protobuf/net/eagle0/shardok/api/unit_view.pb.h"
namespace shardok {
class GameStateW;
using Coords = net::eagle0::shardok::storage::fb::Coords;
using HexMap = net::eagle0::shardok::storage::fb::HexMap;
using HexMapT = net::eagle0::shardok::storage::fb::HexMapT;
@@ -288,6 +290,12 @@ template<class UnitContainer>
const std::vector<PlayerId> &allyPids,
const Coords &coords) -> std::vector<const Unit *>;
[[nodiscard]] auto KnownAdjacentEnemies(
PlayerId playerId,
const GameStateW &gameState,
const std::vector<PlayerId> &allyPids,
const Coords &coords) -> std::vector<const Unit *>;
[[nodiscard]] auto DirectionsTo(int columnCount, const Coords &origin, const Coords &destination)
-> HexMapDirectionsTo;