mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 21:35:42 +00:00
Mark hex map query helpers nodiscard
This commit is contained in:
@@ -36,7 +36,7 @@ struct alignas(16) AdjacentTile {
|
||||
|
||||
AdjacentTile(const Coords co, const HexMapDirection dir) : directionTo(dir), coords(co) {}
|
||||
|
||||
auto operator==(const AdjacentTile &rhs) const -> bool {
|
||||
[[nodiscard]] auto operator==(const AdjacentTile &rhs) const -> bool {
|
||||
return coords == rhs.coords && directionTo == rhs.directionTo;
|
||||
}
|
||||
};
|
||||
@@ -73,21 +73,21 @@ public:
|
||||
|
||||
[[nodiscard]] auto AllCastleCoords(const HexMap *hexMap) -> CoordsSet;
|
||||
|
||||
auto HasForestAccess(
|
||||
[[nodiscard]] auto HasForestAccess(
|
||||
const Coords &coords,
|
||||
const Units *units,
|
||||
const HexMap *hexMap,
|
||||
const std::vector<PlayerId> &allyPids,
|
||||
PlayerId player) -> bool;
|
||||
|
||||
auto GetTerrain(const HexMap *map, const Coords &coords) -> const Terrain *;
|
||||
auto GetMutableTerrain(HexMap *map, const Coords &coords) -> Terrain *;
|
||||
[[nodiscard]] auto GetTerrain(const HexMap *map, const Coords &coords) -> const Terrain *;
|
||||
[[nodiscard]] auto GetMutableTerrain(HexMap *map, const Coords &coords) -> Terrain *;
|
||||
// Overload for const HexMap - uses const_cast internally. Safe when the underlying buffer is
|
||||
// mutable.
|
||||
auto GetMutableTerrain(const HexMap *map, const Coords &coords) -> Terrain *;
|
||||
[[nodiscard]] auto GetMutableTerrain(const HexMap *map, const Coords &coords) -> Terrain *;
|
||||
|
||||
auto CoordsAreValid(const HexMap *map, const Coords &coords) -> bool;
|
||||
auto CoordsAreValid(int rowCount, int columnCount, const Coords &coords) -> bool;
|
||||
[[nodiscard]] auto CoordsAreValid(const HexMap *map, const Coords &coords) -> bool;
|
||||
[[nodiscard]] auto CoordsAreValid(int rowCount, int columnCount, const Coords &coords) -> bool;
|
||||
|
||||
[[nodiscard]] auto GetTilesAcrossWater(const HexMap *map, const Coords &coords) -> CoordsSet;
|
||||
|
||||
@@ -100,7 +100,8 @@ auto CoordsAreValid(int rowCount, int columnCount, const Coords &coords) -> bool
|
||||
[[nodiscard]] auto TwoAwayTilesUnblockedByMountains(const HexMap *map, const Coords &coords)
|
||||
-> CoordsSet;
|
||||
|
||||
static inline auto Occupant(const Units *units, const Coords &coords) -> const Unit * {
|
||||
[[nodiscard]] static inline auto Occupant(const Units *units, const Coords &coords)
|
||||
-> const Unit * {
|
||||
for (const auto &unit : *units) {
|
||||
if (unit->status() == net::eagle0::shardok::storage::fb::UnitStatus_NORMAL_UNIT &&
|
||||
unit->location() == coords) {
|
||||
@@ -111,7 +112,8 @@ static inline auto Occupant(const Units *units, const Coords &coords) -> const U
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline auto Occupant(const Units &units, const Coords &coords) -> const Unit * {
|
||||
[[nodiscard]] static inline auto Occupant(const Units &units, const Coords &coords)
|
||||
-> const Unit * {
|
||||
for (const auto &unit : units) {
|
||||
if (unit->status() == net::eagle0::shardok::storage::fb::UnitStatus_NORMAL_UNIT &&
|
||||
unit->location() == coords) {
|
||||
@@ -122,7 +124,7 @@ static inline auto Occupant(const Units &units, const Coords &coords) -> const U
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline auto Occupants(
|
||||
[[nodiscard]] static inline auto Occupants(
|
||||
const std::vector<const Unit *> &units,
|
||||
const int rowCount,
|
||||
const int columnCount) -> std::vector<const Unit *> {
|
||||
@@ -138,7 +140,7 @@ static inline auto Occupants(
|
||||
return positions;
|
||||
}
|
||||
|
||||
static inline auto Occupants(
|
||||
[[nodiscard]] static inline auto Occupants(
|
||||
const flatbuffers::Vector<const Unit *> &units,
|
||||
const int rowCount,
|
||||
const int columnCount) -> std::vector<const Unit *> {
|
||||
@@ -154,8 +156,9 @@ static inline auto Occupants(
|
||||
return positions;
|
||||
}
|
||||
|
||||
static inline auto Occupant(const std::vector<const Unit *> &units, const Coords &coords)
|
||||
-> const Unit * {
|
||||
[[nodiscard]] static inline auto Occupant(
|
||||
const std::vector<const Unit *> &units,
|
||||
const Coords &coords) -> const Unit * {
|
||||
for (const auto &unit : units) {
|
||||
if (unit->status() == net::eagle0::shardok::storage::fb::UnitStatus_NORMAL_UNIT &&
|
||||
unit->location() == coords) {
|
||||
@@ -167,7 +170,7 @@ static inline auto Occupant(const std::vector<const Unit *> &units, const Coords
|
||||
}
|
||||
|
||||
template<class UnitContainer>
|
||||
auto Occupant(const UnitContainer &units, const Coords &coords)
|
||||
[[nodiscard]] auto Occupant(const UnitContainer &units, const Coords &coords)
|
||||
-> std::optional<typename UnitContainer::value_type> {
|
||||
for (const auto &unit : units) {
|
||||
if (unit.location() == coords) { return unit; }
|
||||
@@ -177,7 +180,8 @@ auto Occupant(const UnitContainer &units, const Coords &coords)
|
||||
}
|
||||
|
||||
template<class U>
|
||||
auto Occupant(const std::map<UnitId, U> &units, const Coords &coords) -> std::optional<U> {
|
||||
[[nodiscard]] auto Occupant(const std::map<UnitId, U> &units, const Coords &coords)
|
||||
-> std::optional<U> {
|
||||
for (const auto &[unitId, unit] : units) {
|
||||
if (unit.location() == coords) { return unit; }
|
||||
}
|
||||
@@ -186,7 +190,7 @@ auto Occupant(const std::map<UnitId, U> &units, const Coords &coords) -> std::op
|
||||
}
|
||||
|
||||
template<class U>
|
||||
auto Occupant(const ::google::protobuf::Map<UnitId, U> &units, const Coords &coords)
|
||||
[[nodiscard]] auto Occupant(const ::google::protobuf::Map<UnitId, U> &units, const Coords &coords)
|
||||
-> std::optional<U> {
|
||||
for (const auto &[unitId, unit] : units) {
|
||||
if (unit.location() == coords) { return unit; }
|
||||
@@ -196,7 +200,7 @@ auto Occupant(const ::google::protobuf::Map<UnitId, U> &units, const Coords &coo
|
||||
}
|
||||
|
||||
template<class U, class UnitContainer>
|
||||
auto Occupant(const UnitContainer &units, const Coords &coords) -> std::optional<U> {
|
||||
[[nodiscard]] auto Occupant(const UnitContainer &units, const Coords &coords) -> std::optional<U> {
|
||||
for (const auto &unit : units) {
|
||||
if (unit.location() == coords) { return unit; }
|
||||
}
|
||||
@@ -204,7 +208,7 @@ auto Occupant(const UnitContainer &units, const Coords &coords) -> std::optional
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static inline auto FriendlyOccupant(
|
||||
[[nodiscard]] static inline auto FriendlyOccupant(
|
||||
const PlayerId pid,
|
||||
const Units *units,
|
||||
const std::vector<PlayerId> &allyPids,
|
||||
@@ -221,7 +225,7 @@ static inline auto FriendlyOccupant(
|
||||
}
|
||||
|
||||
template<class U, class UnitContainer>
|
||||
auto FriendlyOccupant(
|
||||
[[nodiscard]] auto FriendlyOccupant(
|
||||
PlayerId pid,
|
||||
const UnitContainer &units,
|
||||
const std::vector<PlayerId> &allyPids,
|
||||
@@ -237,14 +241,14 @@ auto FriendlyOccupant(
|
||||
return {};
|
||||
}
|
||||
|
||||
auto KnownEnemyOccupant(
|
||||
[[nodiscard]] auto KnownEnemyOccupant(
|
||||
PlayerId playerId,
|
||||
const Units *units,
|
||||
const std::vector<PlayerId> &allyPids,
|
||||
const Coords &coords) -> const Unit *;
|
||||
|
||||
template<class UnitContainer>
|
||||
auto KnownEnemyOccupant(
|
||||
[[nodiscard]] auto KnownEnemyOccupant(
|
||||
PlayerId playerId,
|
||||
const UnitContainer &units,
|
||||
const std::vector<PlayerId> &allyPids,
|
||||
@@ -277,31 +281,35 @@ auto KnownEnemyOccupant(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto KnownAdjacentEnemies(
|
||||
[[nodiscard]] auto KnownAdjacentEnemies(
|
||||
PlayerId playerId,
|
||||
const Units *units,
|
||||
const HexMap *map,
|
||||
const std::vector<PlayerId> &allyPids,
|
||||
const Coords &coords) -> std::vector<const Unit *>;
|
||||
|
||||
auto DirectionsTo(int columnCount, const Coords &origin, const Coords &destination)
|
||||
[[nodiscard]] auto DirectionsTo(int columnCount, const Coords &origin, const Coords &destination)
|
||||
-> HexMapDirectionsTo;
|
||||
|
||||
static inline auto DirectionsTo(const HexMap *map, const Coords &origin, const Coords &destination)
|
||||
-> HexMapDirectionsTo {
|
||||
[[nodiscard]] static inline auto DirectionsTo(
|
||||
const HexMap *map,
|
||||
const Coords &origin,
|
||||
const Coords &destination) -> HexMapDirectionsTo {
|
||||
return DirectionsTo(map->column_count(), origin, destination);
|
||||
}
|
||||
|
||||
auto MaybeTileInDirection(const HexMap *map, const Coords &inCoords, HexMapDirection orientation)
|
||||
-> std::optional<Coords>;
|
||||
[[nodiscard]] auto MaybeTileInDirection(
|
||||
const HexMap *map,
|
||||
const Coords &inCoords,
|
||||
HexMapDirection orientation) -> std::optional<Coords>;
|
||||
|
||||
auto MaybeOccupantInDirection(
|
||||
[[nodiscard]] auto MaybeOccupantInDirection(
|
||||
const HexMap *map,
|
||||
const Units *units,
|
||||
const Coords &coords,
|
||||
HexMapDirection direction) -> const Unit *;
|
||||
|
||||
auto GetAllCoords(const HexMap *hexMap) -> CoordsSet;
|
||||
[[nodiscard]] auto GetAllCoords(const HexMap *hexMap) -> CoordsSet;
|
||||
|
||||
void MutatingSetTileModifier(
|
||||
HexMapT *hexMap,
|
||||
@@ -318,9 +326,10 @@ void MutatingSetTileModifier(
|
||||
const CoordsProto &coords,
|
||||
const TileModifierProto &TileModifierProto);
|
||||
|
||||
auto GetCriticalTileLocations(const HexMap *hexMap) -> CoordsSet;
|
||||
[[nodiscard]] auto GetCriticalTileLocations(const HexMap *hexMap) -> CoordsSet;
|
||||
|
||||
auto IsBelievedEmpty(PlayerId playerId, const Coords &coords, const Units *units) -> bool;
|
||||
[[nodiscard]] auto IsBelievedEmpty(PlayerId playerId, const Coords &coords, const Units *units)
|
||||
-> bool;
|
||||
|
||||
} // namespace shardok
|
||||
|
||||
|
||||
Reference in New Issue
Block a user