From 9f713a09142852c109ec0121a84c7ced9fd14a42 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 28 Feb 2025 19:56:43 +0000 Subject: [PATCH] Rename int3::valid to isValid for consistency --- AI/Nullkiller/AIGateway.cpp | 6 +++--- AI/Nullkiller/Analyzers/ObjectClusterizer.cpp | 2 +- AI/Nullkiller/Goals/ExploreNeighbourTile.cpp | 2 +- AI/Nullkiller/Pathfinding/GraphPaths.h | 2 +- AI/Nullkiller/Pathfinding/ObjectGraphCalculator.cpp | 6 +++--- AI/VCAI/Pathfinding/PathfindingManager.cpp | 2 +- AI/VCAI/VCAI.cpp | 8 ++++---- client/HeroMovementController.cpp | 6 +++--- client/windows/CCastleInterface.cpp | 2 +- lib/gameState/CGameState.cpp | 4 ++-- lib/int3.h | 2 +- lib/mapObjects/IObjectInterface.cpp | 2 +- lib/mapping/MapFormatH3M.cpp | 2 +- lib/mapping/MapFormatJson.cpp | 6 +++--- lib/mapping/ObstacleProxy.cpp | 4 ++-- lib/pathfinder/CGPathNode.cpp | 4 ++-- lib/pathfinder/NodeStorage.cpp | 4 ++-- lib/pathfinder/PathfinderUtil.h | 2 +- lib/rmg/RmgObject.cpp | 2 +- lib/rmg/RmgPath.cpp | 2 +- lib/rmg/Zone.cpp | 2 +- lib/rmg/modificators/ConnectionsPlacer.cpp | 2 +- lib/rmg/modificators/ObjectManager.cpp | 4 ++-- lib/spells/AdventureSpellMechanics.cpp | 2 +- server/CGameHandler.cpp | 2 +- server/processors/NewTurnProcessor.cpp | 2 +- 26 files changed, 42 insertions(+), 42 deletions(-) diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index dd776b1b2..2ca18187c 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -645,7 +645,7 @@ void AIGateway::showBlockingDialog(const std::string & text, const std::vectorgetVisitableObjs(target); - if(hero.validAndSet() && target.valid() && objects.size()) + if(hero.validAndSet() && target.isValid() && objects.size()) { auto topObj = objects.front()->id == hero->id ? objects.back() : objects.front(); auto objType = topObj->ID; // top object should be our hero @@ -722,7 +722,7 @@ void AIGateway::showTeleportDialog(const CGHeroInstance * hero, TeleportChannelI { nullkiller->memory->knownTeleportChannels[channel]->passability = TeleportChannel::IMPASSABLE; } - else if(destinationTeleport != ObjectInstanceID() && destinationTeleportPos.valid()) + else if(destinationTeleport != ObjectInstanceID() && destinationTeleportPos.isValid()) { auto neededExit = std::make_pair(destinationTeleport, destinationTeleportPos); if(destinationTeleport != ObjectInstanceID() && vstd::contains(exits, neededExit)) @@ -1352,7 +1352,7 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h) } destinationTeleport = exitId; - if(exitPos.valid()) + if(exitPos.isValid()) destinationTeleportPos = exitPos; cb->moveHero(*h, h->pos, false); destinationTeleport = ObjectInstanceID(); diff --git a/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp b/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp index c224903ea..701a145bb 100644 --- a/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp +++ b/AI/Nullkiller/Analyzers/ObjectClusterizer.cpp @@ -100,7 +100,7 @@ std::optional ObjectClusterizer::getBlocker(const AIPa if (ai->cb->isVisible(node.coord)) blockers = ai->cb->getVisitableObjs(node.coord); - if(guardPos.valid() && ai->cb->isVisible(guardPos)) + if(guardPos.isValid() && ai->cb->isVisible(guardPos)) { auto guard = ai->cb->getTopObj(ai->cb->getGuardingCreaturePosition(node.coord)); diff --git a/AI/Nullkiller/Goals/ExploreNeighbourTile.cpp b/AI/Nullkiller/Goals/ExploreNeighbourTile.cpp index 99dd54da8..108c59f3b 100644 --- a/AI/Nullkiller/Goals/ExploreNeighbourTile.cpp +++ b/AI/Nullkiller/Goals/ExploreNeighbourTile.cpp @@ -54,7 +54,7 @@ void ExploreNeighbourTile::accept(AIGateway * ai) } }); - if(!target.valid()) + if(!target.isValid()) { return; } diff --git a/AI/Nullkiller/Pathfinding/GraphPaths.h b/AI/Nullkiller/Pathfinding/GraphPaths.h index a41781f68..28dca8b1d 100644 --- a/AI/Nullkiller/Pathfinding/GraphPaths.h +++ b/AI/Nullkiller/Pathfinding/GraphPaths.h @@ -41,7 +41,7 @@ struct GraphPathNodePointer bool valid() const { - return coord.valid(); + return coord.isValid(); } }; diff --git a/AI/Nullkiller/Pathfinding/ObjectGraphCalculator.cpp b/AI/Nullkiller/Pathfinding/ObjectGraphCalculator.cpp index 8905572c9..a32c04421 100644 --- a/AI/Nullkiller/Pathfinding/ObjectGraphCalculator.cpp +++ b/AI/Nullkiller/Pathfinding/ObjectGraphCalculator.cpp @@ -97,7 +97,7 @@ void ObjectGraphCalculator::addMinimalDistanceJunctions() if(target->hasNodeAt(pos)) return; - if(ai->cb->getGuardingCreaturePosition(pos).valid()) + if(ai->cb->getGuardingCreaturePosition(pos).isValid()) return; ConnectionCostInfo currentCost = getConnectionsCost(paths); @@ -200,7 +200,7 @@ void ObjectGraphCalculator::calculateConnections(const int3 & pos, std::vectorvisitablePos(); auto pos2 = path2.targetHero->visitablePos(); - if(guardPos.valid() && guardPos != pos1 && guardPos != pos2) + if(guardPos.isValid() && guardPos != pos1 && guardPos != pos2) continue; auto obj1 = actorObjectMap[path1.targetHero]; @@ -310,7 +310,7 @@ void ObjectGraphCalculator::addObjectActor(const CGObjectInstance * obj) auto shipyard = dynamic_cast(obj); - if(shipyard && shipyard->bestLocation().valid()) + if(shipyard && shipyard->bestLocation().isValid()) { int3 virtualBoat = shipyard->bestLocation(); diff --git a/AI/VCAI/Pathfinding/PathfindingManager.cpp b/AI/VCAI/Pathfinding/PathfindingManager.cpp index c983150bc..34c9cc521 100644 --- a/AI/VCAI/Pathfinding/PathfindingManager.cpp +++ b/AI/VCAI/Pathfinding/PathfindingManager.cpp @@ -130,7 +130,7 @@ Goals::TGoalVec PathfindingManager::findPath( #ifdef VCMI_TRACE_PATHFINDER logAi->trace("Path found size=%i, first tile=%s", path.nodes.size(), firstTileToGet.toString()); #endif - if(firstTileToGet.valid() && ai->isTileNotReserved(hero.get(), firstTileToGet)) + if(firstTileToGet.isValid() && ai->isTileNotReserved(hero.get(), firstTileToGet)) { danger = path.getTotalDanger(hero); diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index b8f123098..e12a744dd 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -699,7 +699,7 @@ void VCAI::showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID cha { knownTeleportChannels[channel]->passability = TeleportChannel::IMPASSABLE; } - else if(destinationTeleport != ObjectInstanceID() && destinationTeleportPos.valid()) + else if(destinationTeleport != ObjectInstanceID() && destinationTeleportPos.isValid()) { auto neededExit = std::make_pair(destinationTeleport, destinationTeleportPos); if(destinationTeleport != ObjectInstanceID() && vstd::contains(exits, neededExit)) @@ -1291,7 +1291,7 @@ bool VCAI::isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, const AIPath { const int3 pos = obj->visitablePos(); const int3 targetPos = path.firstTileToGet(); - if (!targetPos.valid()) + if (!targetPos.isValid()) return false; if (!isTileNotReserved(h.get(), targetPos)) return false; @@ -1320,7 +1320,7 @@ bool VCAI::isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, const AIPath bool VCAI::isTileNotReserved(const CGHeroInstance * h, int3 t) const { - if(t.valid()) + if(t.isValid()) { auto obj = cb->getTopObj(t); if(obj && vstd::contains(ai->reservedObjs, obj) @@ -1900,7 +1900,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h) auto doTeleportMovement = [&](ObjectInstanceID exitId, int3 exitPos) { destinationTeleport = exitId; - if(exitPos.valid()) + if(exitPos.isValid()) destinationTeleportPos = exitPos; cb->moveHero(*h, h->pos, false); destinationTeleport = ObjectInstanceID(); diff --git a/client/HeroMovementController.cpp b/client/HeroMovementController.cpp index deada2e41..ef3e1ab7b 100644 --- a/client/HeroMovementController.cpp +++ b/client/HeroMovementController.cpp @@ -120,7 +120,7 @@ void HeroMovementController::updatePath(const CGHeroInstance * hero, const TryMo assert(GAME->interface()->makingTurn); - bool directlyAttackingCreature = details.attackedFrom.has_value() && GAME->interface()->localState->getPath(hero).lastNode().coord == details.attackedFrom; + bool directlyAttackingCreature = details.attackedFrom.isValid() && GAME->interface()->localState->getPath(hero).lastNode().coord == details.attackedFrom; int3 desiredTarget = GAME->interface()->localState->getPath(hero).nextNode().coord; int3 actualTarget = hero->convertToVisitablePos(details.end); @@ -163,7 +163,7 @@ void HeroMovementController::onTryMoveHero(const CGHeroInstance * hero, const Tr } bool directlyAttackingCreature = - details.attackedFrom.has_value() && + details.attackedFrom.isValid() && GAME->interface()->localState->hasPath(hero) && GAME->interface()->localState->getPath(hero).lastNode().coord == details.attackedFrom; @@ -194,7 +194,7 @@ void HeroMovementController::onTryMoveHero(const CGHeroInstance * hero, const Tr if(directlyAttackingCreature) { // Get direction to attacker. - int3 posOffset = *details.attackedFrom - details.end + int3(2, 1, 0); + int3 posOffset = details.attackedFrom - details.end + int3(2, 1, 0); static const ui8 dirLookup[3][3] = { { 1, 2, 3 }, diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 98a6abac3..77badbcc1 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -675,7 +675,7 @@ void CCastleBuildings::recreate() if(town->hasBuilt(BuildingID::SHIPYARD)) { auto bayPos = town->bestLocation(); - if(!bayPos.valid()) + if(!bayPos.isValid()) logGlobal->warn("Shipyard in non-coastal town!"); std::vector vobjs = GAME->interface()->cb->getVisitableObjs(bayPos, false); //there is visitable obj at shipyard output tile and it's a boat or hero (on boat) diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 4b6f902f6..587569996 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -1051,9 +1051,9 @@ BattleInfo * CGameState::getBattle(const BattleID & battle) BattleField CGameState::battleGetBattlefieldType(int3 tile, vstd::RNG & rand) { - assert(tile.valid()); + assert(tile.isValid()); - if(!tile.valid()) + if(!tile.isValid()) return BattleField::NONE; const TerrainTile &t = map->getTile(tile); diff --git a/lib/int3.h b/lib/int3.h index 1307255d0..5f10d03e3 100644 --- a/lib/int3.h +++ b/lib/int3.h @@ -158,7 +158,7 @@ public: return result; } - constexpr bool valid() const //Should be named "isValid"? + constexpr bool isValid() const //Should be named "isValid"? { return z >= 0; //minimal condition that needs to be fulfilled for tiles in the map } diff --git a/lib/mapObjects/IObjectInterface.cpp b/lib/mapObjects/IObjectInterface.cpp index acf4eed14..b5de13513 100644 --- a/lib/mapObjects/IObjectInterface.cpp +++ b/lib/mapObjects/IObjectInterface.cpp @@ -112,7 +112,7 @@ IBoatGenerator::EGeneratorState IBoatGenerator::shipyardStatus() const { int3 tile = bestLocation(); - if(!tile.valid()) + if(!tile.isValid()) return TILE_BLOCKED; //no available water const TerrainTile *t = getObject()->cb->getTile(tile); diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index ced95876f..b661c411f 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -2749,7 +2749,7 @@ void CMapLoaderH3M::afterRead() for(auto & p : map->players) { int3 posOfMainTown = p.posOfMainTown; - if(posOfMainTown.valid() && map->isInTheMap(posOfMainTown)) + if(posOfMainTown.isValid() && map->isInTheMap(posOfMainTown)) { const TerrainTile & t = map->getTile(posOfMainTown); diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index 4e40244f3..da3e0d784 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -401,7 +401,7 @@ void CMapFormatJson::serializePlayerInfo(JsonSerializeFormat & handler) } //saving whole structure only if position is valid - if(!handler.saving || info.posOfMainTown.valid()) + if(!handler.saving || info.posOfMainTown.isValid()) { auto mainTown = handler.enterStruct("mainTown"); handler.serializeBool("generateHero", info.generateHeroAtMainTown); @@ -411,7 +411,7 @@ void CMapFormatJson::serializePlayerInfo(JsonSerializeFormat & handler) } if(!handler.saving) { - info.hasMainTown = info.posOfMainTown.valid(); + info.hasMainTown = info.posOfMainTown.isValid(); } handler.serializeString("mainHero", info.mainHeroInstance);//must be before "heroes" @@ -1315,7 +1315,7 @@ void CMapSaverJson::writeObjects() obj->serializeJson(handler); } - if(map->grailPos.valid()) + if(map->grailPos.isValid()) { JsonNode grail; grail["type"].String() = "grail"; diff --git a/lib/mapping/ObstacleProxy.cpp b/lib/mapping/ObstacleProxy.cpp index 8bfd1c421..bcf47769b 100644 --- a/lib/mapping/ObstacleProxy.cpp +++ b/lib/mapping/ObstacleProxy.cpp @@ -34,7 +34,7 @@ void ObstacleProxy::collectPossibleObstacles(TerrainId terrain) { for(const auto & temp : handler->getTemplates()) { - if(temp->canBePlacedAt(terrain) && temp->getBlockMapOffset().valid()) + if(temp->canBePlacedAt(terrain) && temp->getBlockMapOffset().isValid()) obstaclesBySize[temp->getBlockedOffsets().size()].push_back(temp); } } @@ -193,7 +193,7 @@ bool ObstacleProxy::prepareBiome(const ObstacleSetFilter & filter, vstd::RNG & r { for (const auto & temp : os->getObstacles()) { - if(temp->getBlockMapOffset().valid()) + if(temp->getBlockMapOffset().isValid()) { obstaclesBySize[temp->getBlockedOffsets().size()].push_back(temp); } diff --git a/lib/pathfinder/CGPathNode.cpp b/lib/pathfinder/CGPathNode.cpp index 9cdc20808..29f6ca0ac 100644 --- a/lib/pathfinder/CGPathNode.cpp +++ b/lib/pathfinder/CGPathNode.cpp @@ -106,7 +106,7 @@ void PathNodeInfo::setNode(CGameState * gs, CGPathNode * n) if(coord != node->coord) { - assert(node->coord.valid()); + assert(node->coord.isValid()); coord = node->coord; tile = gs->getTile(coord); @@ -131,7 +131,7 @@ void PathNodeInfo::setNode(CGameState * gs, CGPathNode * n) void PathNodeInfo::updateInfo(CPathfinderHelper * hlp, CGameState * gs) { - if(gs->guardingCreaturePosition(node->coord).valid() && !isInitialPosition) + if(gs->guardingCreaturePosition(node->coord).isValid() && !isInitialPosition) { guarded = true; } diff --git a/lib/pathfinder/NodeStorage.cpp b/lib/pathfinder/NodeStorage.cpp index dd9c7a198..29ad23387 100644 --- a/lib/pathfinder/NodeStorage.cpp +++ b/lib/pathfinder/NodeStorage.cpp @@ -100,7 +100,7 @@ std::vector NodeStorage::calculateTeleportations( { auto * node = getNode(neighbour, source.node->layer); - if(!node->coord.valid()) + if(!node->coord.isValid()) { logAi->debug("Teleportation exit is blocked " + neighbour.toString()); continue; @@ -132,7 +132,7 @@ std::vector NodeStorage::getInitialNodes() initialNode->moveRemains = out.hero->movementPointsRemaining(); initialNode->setCost(0.0); - if(!initialNode->coord.valid()) + if(!initialNode->coord.isValid()) { initialNode->coord = out.hpos; } diff --git a/lib/pathfinder/PathfinderUtil.h b/lib/pathfinder/PathfinderUtil.h index 10cfab9c3..65d56c66d 100644 --- a/lib/pathfinder/PathfinderUtil.h +++ b/lib/pathfinder/PathfinderUtil.h @@ -63,7 +63,7 @@ namespace PathfinderUtil { return EPathAccessibility::BLOCKED; } - else if(gs->guardingCreaturePosition(pos).valid()) + else if(gs->guardingCreaturePosition(pos).isValid()) { // Monster close by; blocked visit for battle return EPathAccessibility::GUARDED; diff --git a/lib/rmg/RmgObject.cpp b/lib/rmg/RmgObject.cpp index d1fd542ec..f7a623d64 100644 --- a/lib/rmg/RmgObject.cpp +++ b/lib/rmg/RmgObject.cpp @@ -96,7 +96,7 @@ void Object::Instance::setPosition(const int3 & position) void Object::Instance::setPositionRaw(const int3 & position) { - if(!dObject.anchorPos().valid()) + if(!dObject.anchorPos().isValid()) { dObject.setAnchorPos(dPosition + dParent.getPosition()); dBlockedAreaCache.clear(); diff --git a/lib/rmg/RmgPath.cpp b/lib/rmg/RmgPath.cpp index e9ffdcc48..a504f1165 100644 --- a/lib/rmg/RmgPath.cpp +++ b/lib/rmg/RmgPath.cpp @@ -99,7 +99,7 @@ Path Path::search(const Tileset & dst, bool straight, std::function()); auto & manager = *zone.getModificator(); diff --git a/lib/rmg/modificators/ObjectManager.cpp b/lib/rmg/modificators/ObjectManager.cpp index a23c05921..c8eacbed4 100644 --- a/lib/rmg/modificators/ObjectManager.cpp +++ b/lib/rmg/modificators/ObjectManager.cpp @@ -242,7 +242,7 @@ int3 ObjectManager::findPlaceForObject(const rmg::Area & searchArea, rmg::Object } } - if(result.valid()) + if(result.isValid()) obj.setPosition(result); return result; } @@ -348,7 +348,7 @@ rmg::Path ObjectManager::placeAndConnectObject(const rmg::Area & searchArea, rmg while(true) { pos = findPlaceForObject(possibleArea, obj, weightFunction, optimizer); - if(!pos.valid()) + if(!pos.isValid()) { return rmg::Path::invalid(); } diff --git a/lib/spells/AdventureSpellMechanics.cpp b/lib/spells/AdventureSpellMechanics.cpp index bc6e1025e..01d8eea55 100644 --- a/lib/spells/AdventureSpellMechanics.cpp +++ b/lib/spells/AdventureSpellMechanics.cpp @@ -603,7 +603,7 @@ ESpellCastResult TownPortalMechanics::beginCast(SpellCastEnvironment * env, cons return ESpellCastResult::CANCEL; } - if(!parameters.pos.valid() && parameters.caster->getSpellSchoolLevel(owner) >= 2) + if(!parameters.pos.isValid() && parameters.caster->getSpellSchoolLevel(owner) >= 2) { auto queryCallback = [this, env, parameters](std::optional reply) -> void { diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index bb75c586b..846129354 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -924,7 +924,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, EMovementMode moveme leaveTile(); if (lookForGuards == CHECK_FOR_GUARDS && isInTheMap(guardPos)) - tmh.attackedFrom = std::make_optional(guardPos); + tmh.attackedFrom = guardPos; tmh.result = result; sendAndApply(tmh); diff --git a/server/processors/NewTurnProcessor.cpp b/server/processors/NewTurnProcessor.cpp index 6b68e63f0..e3b7a0f37 100644 --- a/server/processors/NewTurnProcessor.cpp +++ b/server/processors/NewTurnProcessor.cpp @@ -436,7 +436,7 @@ RumorState NewTurnProcessor::pickNewRumor() static const std::vector rumorTypes = {RumorState::TYPE_MAP, RumorState::TYPE_SPECIAL, RumorState::TYPE_RAND, RumorState::TYPE_RAND}; std::vector sRumorTypes = { RumorState::RUMOR_OBELISKS, RumorState::RUMOR_ARTIFACTS, RumorState::RUMOR_ARMY, RumorState::RUMOR_INCOME}; - if(gameHandler->gameState()->map->grailPos.valid()) // Grail should always be on map, but I had related crash I didn't manage to reproduce + if(gameHandler->gameState()->map->grailPos.isValid()) // Grail should always be on map, but I had related crash I didn't manage to reproduce sRumorTypes.push_back(RumorState::RUMOR_GRAIL); int rumorId = -1;