1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-13 22:06:58 +02:00

Merge remote-tracking branch 'upstream/develop' into boats

# Conflicts:
#	AI/VCAI/Pathfinding/AINodeStorage.cpp
This commit is contained in:
nordsoft 2023-04-19 02:22:19 +04:00
commit 0a28262c15
164 changed files with 1947 additions and 1406 deletions

View File

@ -134,7 +134,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
//evaluate casting spell for spellcasting stack //evaluate casting spell for spellcasting stack
boost::optional<PossibleSpellcast> bestSpellcast(boost::none); std::optional<PossibleSpellcast> bestSpellcast(std::nullopt);
//TODO: faerie dragon type spell should be selected by server //TODO: faerie dragon type spell should be selected by server
SpellID creatureSpellToCast = cb->battleGetRandomStackSpell(CRandomGenerator::getDefault(), stack, CBattleInfoCallback::RANDOM_AIMED); SpellID creatureSpellToCast = cb->battleGetRandomStackSpell(CRandomGenerator::getDefault(), stack, CBattleInfoCallback::RANDOM_AIMED);
if(stack->hasBonusOfType(Bonus::SPELLCASTER) && stack->canCast() && creatureSpellToCast != SpellID::NONE) if(stack->hasBonusOfType(Bonus::SPELLCASTER) && stack->canCast() && creatureSpellToCast != SpellID::NONE)
@ -157,7 +157,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
std::sort(possibleCasts.begin(), possibleCasts.end(), [&](const PossibleSpellcast & lhs, const PossibleSpellcast & rhs) { return lhs.value > rhs.value; }); std::sort(possibleCasts.begin(), possibleCasts.end(), [&](const PossibleSpellcast & lhs, const PossibleSpellcast & rhs) { return lhs.value > rhs.value; });
if(!possibleCasts.empty() && possibleCasts.front().value > 0) if(!possibleCasts.empty() && possibleCasts.front().value > 0)
{ {
bestSpellcast = boost::optional<PossibleSpellcast>(possibleCasts.front()); bestSpellcast = std::optional<PossibleSpellcast>(possibleCasts.front());
} }
} }
} }
@ -180,7 +180,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
auto & bestAttack = evaluationResult.bestAttack; auto & bestAttack = evaluationResult.bestAttack;
//TODO: consider more complex spellcast evaluation, f.e. because "re-retaliation" during enemy move in same turn for melee attack etc. //TODO: consider more complex spellcast evaluation, f.e. because "re-retaliation" during enemy move in same turn for melee attack etc.
if(bestSpellcast.is_initialized() && bestSpellcast->value > bestAttack.damageDiff()) if(bestSpellcast.has_value() && bestSpellcast->value > bestAttack.damageDiff())
{ {
// return because spellcast value is damage dealt and score is dps reduce // return because spellcast value is damage dealt and score is dps reduce
movesSkippedByDefense = 0; movesSkippedByDefense = 0;
@ -219,7 +219,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
); );
} }
} }
else if(bestSpellcast.is_initialized()) else if(bestSpellcast.has_value())
{ {
movesSkippedByDefense = 0; movesSkippedByDefense = 0;
return BattleAction::makeCreatureSpellcast(stack, bestSpellcast->dest, bestSpellcast->spell->id); return BattleAction::makeCreatureSpellcast(stack, bestSpellcast->dest, bestSpellcast->spell->id);
@ -801,7 +801,7 @@ void CBattleAI::print(const std::string &text) const
logAi->trace("%s Battle AI[%p]: %s", playerID.getStr(), this, text); logAi->trace("%s Battle AI[%p]: %s", playerID.getStr(), this, text);
} }
boost::optional<BattleAction> CBattleAI::considerFleeingOrSurrendering() std::optional<BattleAction> CBattleAI::considerFleeingOrSurrendering()
{ {
BattleStateInfoForRetreat bs; BattleStateInfoForRetreat bs;
@ -829,7 +829,7 @@ boost::optional<BattleAction> CBattleAI::considerFleeingOrSurrendering()
if(!bs.canFlee || !bs.canSurrender) if(!bs.canFlee || !bs.canSurrender)
{ {
return boost::none; return std::nullopt;
} }
auto result = cb->makeSurrenderRetreatDecision(bs); auto result = cb->makeSurrenderRetreatDecision(bs);

View File

@ -73,7 +73,7 @@ public:
BattleAction activeStack(const CStack * stack) override; //called when it's turn of that stack BattleAction activeStack(const CStack * stack) override; //called when it's turn of that stack
boost::optional<BattleAction> considerFleeingOrSurrendering(); std::optional<BattleAction> considerFleeingOrSurrendering();
void print(const std::string &text) const; void print(const std::string &text) const;
BattleAction useCatapult(const CStack *stack); BattleAction useCatapult(const CStack *stack);

View File

@ -501,8 +501,7 @@ void AIGateway::showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositio
NET_EVENT_HANDLER; NET_EVENT_HANDLER;
} }
boost::optional<BattleAction> AIGateway::makeSurrenderRetreatDecision( std::optional<BattleAction> AIGateway::makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState)
const BattleStateInfoForRetreat & battleState)
{ {
LOG_TRACE(logAi); LOG_TRACE(logAi);
NET_EVENT_HANDLER; NET_EVENT_HANDLER;
@ -516,7 +515,7 @@ boost::optional<BattleAction> AIGateway::makeSurrenderRetreatDecision(
return BattleAction::makeRetreat(battleState.ourSide); return BattleAction::makeRetreat(battleState.ourSide);
} }
return boost::none; return std::nullopt;
} }

View File

@ -166,7 +166,7 @@ public:
void heroBonusChanged(const CGHeroInstance * hero, const Bonus & bonus, bool gain) override; void heroBonusChanged(const CGHeroInstance * hero, const Bonus & bonus, bool gain) override;
void showMarketWindow(const IMarket * market, const CGHeroInstance * visitor) override; void showMarketWindow(const IMarket * market, const CGHeroInstance * visitor) override;
void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain) override; void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain) override;
boost::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) override; std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) override;
void battleStart(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance * hero1, const CGHeroInstance * hero2, bool side) override; void battleStart(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance * hero1, const CGHeroInstance * hero2, bool side) override;
void battleEnd(const BattleResult * br, QueryID queryID) override; void battleEnd(const BattleResult * br, QueryID queryID) override;

View File

@ -42,10 +42,10 @@ TGoalVec Build::getAllPossibleSubgoals()
auto expensiveBuilding = ai->ah->expensiveBuilding(); auto expensiveBuilding = ai->ah->expensiveBuilding();
//handling for early town development to save money and focus on income //handling for early town development to save money and focus on income
if(!t->hasBuilt(ai->ah->getMaxPossibleGoldBuilding(t)) && expensiveBuilding.is_initialized()) if(!t->hasBuilt(ai->ah->getMaxPossibleGoldBuilding(t)) && expensiveBuilding.has_value())
{ {
auto potentialBuilding = expensiveBuilding.get(); auto potentialBuilding = expensiveBuilding.value();
switch(expensiveBuilding.get().bid) switch(expensiveBuilding.value().bid)
{ {
case BuildingID::TOWN_HALL: case BuildingID::TOWN_HALL:
case BuildingID::CITY_HALL: case BuildingID::CITY_HALL:
@ -61,15 +61,15 @@ TGoalVec Build::getAllPossibleSubgoals()
} }
} }
if(immediateBuilding.is_initialized()) if(immediateBuilding.has_value())
{ {
ret.push_back(sptr(BuildThis(immediateBuilding.get().bid, t).setpriority(2))); //prioritize buildings we can build quick ret.push_back(sptr(BuildThis(immediateBuilding.value().bid, t).setpriority(2))); //prioritize buildings we can build quick
} }
else //try build later else //try build later
{ {
if(expensiveBuilding.is_initialized()) if(expensiveBuilding.has_value())
{ {
auto potentialBuilding = expensiveBuilding.get(); //gather resources for any we can't afford auto potentialBuilding = expensiveBuilding.value(); //gather resources for any we can't afford
auto goal = ai->ah->whatToDo(potentialBuilding.price, sptr(BuildThis(potentialBuilding.bid, t).setpriority(0.5))); auto goal = ai->ah->whatToDo(potentialBuilding.price, sptr(BuildThis(potentialBuilding.bid, t).setpriority(0.5)));
ret.push_back(goal); ret.push_back(goal);
} }

View File

@ -97,7 +97,7 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
//Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm //Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm
/*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 1); /*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + ARRAY_COUNT(unitsSource)), 1);
if (bid.is_initialized()) if (bid.has_value())
{ {
auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority)); auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority));
if (!ai->ah->containsObjective(goal)) //avoid loops caused by reserving same objective twice if (!ai->ah->containsObjective(goal)) //avoid loops caused by reserving same objective twice

View File

@ -120,7 +120,7 @@ void AINodeStorage::clear()
turnDistanceLimit[HeroRole::SCOUT] = 255; turnDistanceLimit[HeroRole::SCOUT] = 255;
} }
boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode( std::optional<AIPathNode *> AINodeStorage::getOrCreateNode(
const int3 & pos, const int3 & pos,
const EPathfindingLayer layer, const EPathfindingLayer layer,
const ChainActor * actor) const ChainActor * actor)
@ -131,7 +131,7 @@ boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(
if(chains[0].blocked()) if(chains[0].blocked())
{ {
return boost::none; return std::nullopt;
} }
for(auto i = AIPathfinding::BUCKET_SIZE - 1; i >= 0; i--) for(auto i = AIPathfinding::BUCKET_SIZE - 1; i >= 0; i--)
@ -151,7 +151,7 @@ boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(
} }
} }
return boost::none; return std::nullopt;
} }
std::vector<CGPathNode *> AINodeStorage::getInitialNodes() std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
@ -175,7 +175,7 @@ std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
if(!allocated) if(!allocated)
continue; continue;
AIPathNode * initialNode = allocated.get(); AIPathNode * initialNode = allocated.value();
initialNode->inPQ = false; initialNode->inPQ = false;
initialNode->pq = nullptr; initialNode->pq = nullptr;
@ -289,10 +289,10 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
{ {
auto nextNode = getOrCreateNode(neighbour, i, srcNode->actor); auto nextNode = getOrCreateNode(neighbour, i, srcNode->actor);
if(!nextNode || nextNode.get()->accessible == CGPathNode::NOT_SET) if(!nextNode || nextNode.value()->accessible == CGPathNode::NOT_SET)
continue; continue;
neighbours.push_back(nextNode.get()); neighbours.push_back(nextNode.value());
} }
} }
@ -722,7 +722,7 @@ void HeroChainCalculationTask::addHeroChain(const std::vector<ExchangeCandidate>
continue; continue;
} }
auto exchangeNode = chainNodeOptional.get(); auto exchangeNode = chainNodeOptional.value();
if(exchangeNode->action != CGPathNode::ENodeAction::UNKNOWN) if(exchangeNode->action != CGPathNode::ENodeAction::UNKNOWN)
{ {
@ -946,7 +946,7 @@ std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
if(!node) if(!node)
continue; continue;
neighbours.push_back(node.get()); neighbours.push_back(node.value());
} }
} }
@ -1017,19 +1017,19 @@ struct TowmPortalFinder
return nullptr; return nullptr;
} }
boost::optional<AIPathNode *> createTownPortalNode(const CGTownInstance * targetTown) std::optional<AIPathNode *> createTownPortalNode(const CGTownInstance * targetTown)
{ {
auto bestNode = getBestInitialNodeForTownPortal(targetTown); auto bestNode = getBestInitialNodeForTownPortal(targetTown);
if(!bestNode) if(!bestNode)
return boost::none; return std::nullopt;
auto nodeOptional = nodeStorage->getOrCreateNode(targetTown->visitablePos(), EPathfindingLayer::LAND, actor->castActor); auto nodeOptional = nodeStorage->getOrCreateNode(targetTown->visitablePos(), EPathfindingLayer::LAND, actor->castActor);
if(!nodeOptional) if(!nodeOptional)
return boost::none; return std::nullopt;
AIPathNode * node = nodeOptional.get(); AIPathNode * node = nodeOptional.value();
float movementCost = (float)movementNeeded / (float)hero->maxMovePoints(EPathfindingLayer::LAND); float movementCost = (float)movementNeeded / (float)hero->maxMovePoints(EPathfindingLayer::LAND);
movementCost += bestNode->getCost(); movementCost += bestNode->getCost();
@ -1095,7 +1095,7 @@ void AINodeStorage::calculateTownPortal(
#if NKAI_PATHFINDER_TRACE_LEVEL >= 1 #if NKAI_PATHFINDER_TRACE_LEVEL >= 1
logAi->trace("Adding town portal node at %s", targetTown->name); logAi->trace("Adding town portal node at %s", targetTown->name);
#endif #endif
output.push_back(nodeOptional.get()); output.push_back(nodeOptional.value());
} }
} }
} }

View File

@ -232,7 +232,7 @@ public:
const AIPathNode * destinationNode, const AIPathNode * destinationNode,
const NodeRange & chains) const; const NodeRange & chains) const;
boost::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, const ChainActor * actor); std::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, const ChainActor * actor);
std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const; std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const;
bool isTileAccessible(const HeroPtr & hero, const int3 & pos, const EPathfindingLayer layer) const; bool isTileAccessible(const HeroPtr & hero, const int3 & pos, const EPathfindingLayer layer) const;
void setHeroes(std::map<const CGHeroInstance *, HeroRole> heroes); void setHeroes(std::map<const CGHeroInstance *, HeroRole> heroes);

View File

@ -131,7 +131,7 @@ namespace AIPathfinding
if(boatNodeOptional) if(boatNodeOptional)
{ {
AIPathNode * boatNode = boatNodeOptional.get(); AIPathNode * boatNode = boatNodeOptional.value();
if(boatNode->action == CGPathNode::UNKNOWN) if(boatNode->action == CGPathNode::UNKNOWN)
{ {

View File

@ -139,17 +139,17 @@ namespace AIPathfinding
{ {
if(!destinationNode->actor->allowUseResources) if(!destinationNode->actor->allowUseResources)
{ {
boost::optional<AIPathNode *> questNode = nodeStorage->getOrCreateNode( std::optional<AIPathNode *> questNode = nodeStorage->getOrCreateNode(
destination.coord, destination.coord,
destination.node->layer, destination.node->layer,
destinationNode->actor->resourceActor); destinationNode->actor->resourceActor);
if(!questNode || questNode.get()->getCost() < destination.cost) if(!questNode || questNode.value()->getCost() < destination.cost)
{ {
return false; return false;
} }
destination.node = questNode.get(); destination.node = questNode.value();
nodeStorage->commit(destination, source); nodeStorage->commit(destination, source);
AIPreviousNodeRule(nodeStorage).process(source, destination, pathfinderConfig, pathfinderHelper); AIPreviousNodeRule(nodeStorage).process(source, destination, pathfinderConfig, pathfinderHelper);
@ -259,7 +259,7 @@ namespace AIPathfinding
return false; return false;
} }
AIPathNode * battleNode = battleNodeOptional.get(); auto * battleNode = battleNodeOptional.value();
if(battleNode->locked) if(battleNode->locked)
{ {

View File

@ -50,17 +50,17 @@ BuildingID AIhelper::getMaxPossibleGoldBuilding(const CGTownInstance * t)
return buildingManager->getMaxPossibleGoldBuilding(t); return buildingManager->getMaxPossibleGoldBuilding(t);
} }
boost::optional<PotentialBuilding> AIhelper::immediateBuilding() const std::optional<PotentialBuilding> AIhelper::immediateBuilding() const
{ {
return buildingManager->immediateBuilding(); return buildingManager->immediateBuilding();
} }
boost::optional<PotentialBuilding> AIhelper::expensiveBuilding() const std::optional<PotentialBuilding> AIhelper::expensiveBuilding() const
{ {
return buildingManager->expensiveBuilding(); return buildingManager->expensiveBuilding();
} }
boost::optional<BuildingID> AIhelper::canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const std::optional<BuildingID> AIhelper::canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const
{ {
return buildingManager->canBuildAnyStructure(t, buildList, maxDays); return buildingManager->canBuildAnyStructure(t, buildList, maxDays);
} }

View File

@ -52,9 +52,9 @@ public:
bool getBuildingOptions(const CGTownInstance * t) override; bool getBuildingOptions(const CGTownInstance * t) override;
BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t); BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
boost::optional<PotentialBuilding> immediateBuilding() const override; std::optional<PotentialBuilding> immediateBuilding() const override;
boost::optional<PotentialBuilding> expensiveBuilding() const override; std::optional<PotentialBuilding> expensiveBuilding() const override;
boost::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override; std::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override;
Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override; Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override;
Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override; Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override;

View File

@ -99,7 +99,7 @@ bool BuildingManager::tryBuildAnyStructure(const CGTownInstance * t, std::vector
return false; //Can't build anything return false; //Can't build anything
} }
boost::optional<BuildingID> BuildingManager::canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const std::optional<BuildingID> BuildingManager::canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const
{ {
for (const auto & building : buildList) for (const auto & building : buildList)
{ {
@ -109,11 +109,11 @@ boost::optional<BuildingID> BuildingManager::canBuildAnyStructure(const CGTownIn
{ {
case EBuildingState::ALLOWED: case EBuildingState::ALLOWED:
case EBuildingState::NO_RESOURCES: //TODO: allow this via optional parameter? case EBuildingState::NO_RESOURCES: //TODO: allow this via optional parameter?
return boost::optional<BuildingID>(building); return std::optional<BuildingID>(building);
break; break;
} }
} }
return boost::optional<BuildingID>(); //Can't build anything return std::optional<BuildingID>(); //Can't build anything
} }
bool BuildingManager::tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays) bool BuildingManager::tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingID> buildList, unsigned int maxDays)
@ -240,18 +240,18 @@ BuildingID BuildingManager::getMaxPossibleGoldBuilding(const CGTownInstance * t)
return BuildingID::VILLAGE_HALL; return BuildingID::VILLAGE_HALL;
} }
boost::optional<PotentialBuilding> BuildingManager::immediateBuilding() const std::optional<PotentialBuilding> BuildingManager::immediateBuilding() const
{ {
if (immediateBuildings.size()) if (immediateBuildings.size())
return boost::optional<PotentialBuilding>(immediateBuildings.front()); //back? whatever return std::optional<PotentialBuilding>(immediateBuildings.front()); //back? whatever
else else
return boost::optional<PotentialBuilding>(); return std::optional<PotentialBuilding>();
} }
boost::optional<PotentialBuilding> BuildingManager::expensiveBuilding() const std::optional<PotentialBuilding> BuildingManager::expensiveBuilding() const
{ {
if (expensiveBuildings.size()) if (expensiveBuildings.size())
return boost::optional<PotentialBuilding>(expensiveBuildings.front()); return std::optional<PotentialBuilding>(expensiveBuildings.front());
else else
return boost::optional<PotentialBuilding>(); return std::optional<PotentialBuilding>();
} }

View File

@ -33,9 +33,9 @@ public:
virtual void setAI(VCAI * AI) = 0; virtual void setAI(VCAI * AI) = 0;
virtual bool getBuildingOptions(const CGTownInstance * t) = 0; virtual bool getBuildingOptions(const CGTownInstance * t) = 0;
virtual boost::optional<PotentialBuilding> immediateBuilding() const = 0; virtual std::optional<PotentialBuilding> immediateBuilding() const = 0;
virtual boost::optional<PotentialBuilding> expensiveBuilding() const = 0; virtual std::optional<PotentialBuilding> expensiveBuilding() const = 0;
virtual boost::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const = 0; virtual std::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays) const = 0;
}; };
class DLL_EXPORT BuildingManager : public IBuildingManager class DLL_EXPORT BuildingManager : public IBuildingManager
@ -52,9 +52,9 @@ public:
//try build anything in given town, and execute resulting Goal if any //try build anything in given town, and execute resulting Goal if any
bool getBuildingOptions(const CGTownInstance * t) override; bool getBuildingOptions(const CGTownInstance * t) override;
BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t); BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
boost::optional<PotentialBuilding> immediateBuilding() const override; std::optional<PotentialBuilding> immediateBuilding() const override;
boost::optional<PotentialBuilding> expensiveBuilding() const override; std::optional<PotentialBuilding> expensiveBuilding() const override;
boost::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override; std::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override;
protected: protected:

View File

@ -399,12 +399,12 @@ float VisitObjEngine::evaluate(Goals::VisitObj & goal)
return -100; // FIXME: Added check when goal was used for hero instead of VisitHero, but crashes are bad anyway return -100; // FIXME: Added check when goal was used for hero instead of VisitHero, but crashes are bad anyway
} }
boost::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj); std::optional<int> objValueKnownByAI = MapObjectsEvaluator::getInstance().getObjectValue(obj);
int objValue = 0; int objValue = 0;
if(objValueKnownByAI != boost::none) //consider adding value manipulation based on object instances on map if(objValueKnownByAI != std::nullopt) //consider adding value manipulation based on object instances on map
{ {
objValue = std::min(std::max(objValueKnownByAI.get(), 0), 20000); objValue = std::min(std::max(objValueKnownByAI.value(), 0), 20000);
} }
else else
{ {

View File

@ -39,10 +39,10 @@ TGoalVec Build::getAllPossibleSubgoals()
auto expensiveBuilding = ai->ah->expensiveBuilding(); auto expensiveBuilding = ai->ah->expensiveBuilding();
//handling for early town development to save money and focus on income //handling for early town development to save money and focus on income
if(!t->hasBuilt(ai->ah->getMaxPossibleGoldBuilding(t)) && expensiveBuilding.is_initialized()) if(!t->hasBuilt(ai->ah->getMaxPossibleGoldBuilding(t)) && expensiveBuilding.has_value())
{ {
auto potentialBuilding = expensiveBuilding.get(); auto potentialBuilding = expensiveBuilding.value();
switch(expensiveBuilding.get().bid) switch(expensiveBuilding.value().bid)
{ {
case BuildingID::TOWN_HALL: case BuildingID::TOWN_HALL:
case BuildingID::CITY_HALL: case BuildingID::CITY_HALL:
@ -58,15 +58,15 @@ TGoalVec Build::getAllPossibleSubgoals()
} }
} }
if(immediateBuilding.is_initialized()) if(immediateBuilding.has_value())
{ {
ret.push_back(sptr(BuildThis(immediateBuilding.get().bid, t).setpriority(2))); //prioritize buildings we can build quick ret.push_back(sptr(BuildThis(immediateBuilding.value().bid, t).setpriority(2))); //prioritize buildings we can build quick
} }
else //try build later else //try build later
{ {
if(expensiveBuilding.is_initialized()) if(expensiveBuilding.has_value())
{ {
auto potentialBuilding = expensiveBuilding.get(); //gather resources for any we can't afford auto potentialBuilding = expensiveBuilding.value(); //gather resources for any we can't afford
auto goal = ai->ah->whatToDo(potentialBuilding.price, sptr(BuildThis(potentialBuilding.bid, t).setpriority(0.5))); auto goal = ai->ah->whatToDo(potentialBuilding.price, sptr(BuildThis(potentialBuilding.bid, t).setpriority(0.5)));
ret.push_back(goal); ret.push_back(goal);
} }

View File

@ -94,7 +94,7 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
//Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm //Do not use below code for now, rely on generic Build. Code below needs to know a lot of town/resource context to do more good than harm
/*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + std::size(unitsSource)), 1); /*auto bid = ai->ah->canBuildAnyStructure(t, std::vector<BuildingID>(unitsSource, unitsSource + std::size(unitsSource)), 1);
if (bid.is_initialized()) if (bid.has_value())
{ {
auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority)); auto goal = sptr(BuildThis(bid.get(), t).setpriority(priority));
if (!ai->ah->containsObjective(goal)) //avoid loops caused by reserving same objective twice if (!ai->ah->containsObjective(goal)) //avoid loops caused by reserving same objective twice

View File

@ -96,7 +96,18 @@ TGoalVec GatherTroops::getAllPossibleSubgoals()
auto creature = VLC->creatures()->getByIndex(objid); auto creature = VLC->creatures()->getByIndex(objid);
if(t->subID == creature->getFaction()) //TODO: how to force AI to build unupgraded creatures? :O if(t->subID == creature->getFaction()) //TODO: how to force AI to build unupgraded creatures? :O
{ {
auto creatures = vstd::tryAt(t->town->creatures, creature->getLevel() - 1); auto tryFindCreature = [&]() -> std::optional<std::vector<CreatureID>>
{
if(vstd::isValidIndex(t->town->creatures, creature->getLevel() - 1))
{
auto itr = t->town->creatures.begin();
std::advance(itr, creature->getLevel() - 1);
return make_optional(*itr);
}
return std::nullopt;
};
auto creatures = tryFindCreature();
if(!creatures) if(!creatures)
continue; continue;

View File

@ -28,9 +28,9 @@ MapObjectsEvaluator::MapObjectsEvaluator()
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID); auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
if(handler && !handler->isStaticObject()) if(handler && !handler->isStaticObject())
{ {
if(handler->getAiValue() != boost::none) if(handler->getAiValue() != std::nullopt)
{ {
objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = handler->getAiValue().get(); objectDatabase[CompoundMapObjectID(primaryID, secondaryID)] = handler->getAiValue().value();
} }
else //some default handling when aiValue not found, objects that require advanced properties (unavailable from handler) get their value calculated in getObjectValue else //some default handling when aiValue not found, objects that require advanced properties (unavailable from handler) get their value calculated in getObjectValue
{ {
@ -41,7 +41,7 @@ MapObjectsEvaluator::MapObjectsEvaluator()
} }
} }
boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int secondaryID) const std::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int secondaryID) const
{ {
CompoundMapObjectID internalIdentifier = CompoundMapObjectID(primaryID, secondaryID); CompoundMapObjectID internalIdentifier = CompoundMapObjectID(primaryID, secondaryID);
auto object = objectDatabase.find(internalIdentifier); auto object = objectDatabase.find(internalIdentifier);
@ -49,10 +49,10 @@ boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int seco
return object->second; return object->second;
logGlobal->trace("Unknown object for AI, ID: " + std::to_string(primaryID) + ", SubID: " + std::to_string(secondaryID)); logGlobal->trace("Unknown object for AI, ID: " + std::to_string(primaryID) + ", SubID: " + std::to_string(secondaryID));
return boost::optional<int>(); return std::optional<int>();
} }
boost::optional<int> MapObjectsEvaluator::getObjectValue(const CGObjectInstance * obj) const std::optional<int> MapObjectsEvaluator::getObjectValue(const CGObjectInstance * obj) const
{ {
if(obj->ID == Obj::HERO) if(obj->ID == Obj::HERO)
{ {

View File

@ -18,8 +18,8 @@ private:
public: public:
MapObjectsEvaluator(); MapObjectsEvaluator();
static MapObjectsEvaluator & getInstance(); static MapObjectsEvaluator & getInstance();
boost::optional<int> getObjectValue(int primaryID, int secondaryID) const; std::optional<int> getObjectValue(int primaryID, int secondaryID) const;
boost::optional<int> getObjectValue(const CGObjectInstance * obj) const; std::optional<int> getObjectValue(const CGObjectInstance * obj) const;
void addObjectData(int primaryID, int secondaryID, int value); void addObjectData(int primaryID, int secondaryID, int value);
void removeObjectData(int primaryID, int secondaryID); void removeObjectData(int primaryID, int secondaryID);
}; };

View File

@ -83,7 +83,7 @@ bool AINodeStorage::isBattleNode(const CGPathNode * node) const
return (getAINode(node)->chainMask & BATTLE_CHAIN) > 0; return (getAINode(node)->chainMask & BATTLE_CHAIN) > 0;
} }
boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, const EPathfindingLayer layer, int chainNumber) std::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, const EPathfindingLayer layer, int chainNumber)
{ {
auto chains = nodes[layer][pos.z][pos.x][pos.y]; auto chains = nodes[layer][pos.z][pos.x][pos.y];
@ -102,15 +102,13 @@ boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(const int3 & pos, c
} }
} }
return boost::none; return std::nullopt;
} }
std::vector<CGPathNode *> AINodeStorage::getInitialNodes() std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
{ {
auto hpos = hero->visitablePos(); auto hpos = hero->visitablePos();
auto initialNode = auto initialNode = getOrCreateNode(hpos, hero->boat ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND, NORMAL_CHAIN).value();
getOrCreateNode(hpos, hero->boat ? hero->boat->layer : EPathfindingLayer::LAND, NORMAL_CHAIN)
.get();
initialNode->turns = 0; initialNode->turns = 0;
initialNode->moveRemains = hero->movement; initialNode->moveRemains = hero->movement;
@ -171,10 +169,10 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
{ {
auto nextNode = getOrCreateNode(neighbour, i, srcNode->chainMask); auto nextNode = getOrCreateNode(neighbour, i, srcNode->chainMask);
if(!nextNode || nextNode.get()->accessible == CGPathNode::NOT_SET) if(!nextNode || nextNode.value()->accessible == CGPathNode::NOT_SET)
continue; continue;
neighbours.push_back(nextNode.get()); neighbours.push_back(nextNode.value());
} }
} }
@ -207,7 +205,7 @@ std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
if(!node) if(!node)
continue; continue;
neighbours.push_back(node.get()); neighbours.push_back(node.value());
} }
} }
@ -273,7 +271,7 @@ void AINodeStorage::calculateTownPortalTeleportations(
logAi->trace("Adding town portal node at %s", targetTown->name); logAi->trace("Adding town portal node at %s", targetTown->name);
#endif #endif
AIPathNode * node = nodeOptional.get(); AIPathNode * node = nodeOptional.value();
node->theNodeBefore = source.node; node->theNodeBefore = source.node;
node->specialAction.reset(new AIPathfinding::TownPortalAction(targetTown)); node->specialAction.reset(new AIPathfinding::TownPortalAction(targetTown));

View File

@ -107,7 +107,7 @@ public:
bool isBattleNode(const CGPathNode * node) const; bool isBattleNode(const CGPathNode * node) const;
bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const; bool hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const;
boost::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber); std::optional<AIPathNode *> getOrCreateNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber);
std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const; std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const;
bool isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const; bool isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const;

View File

@ -114,7 +114,7 @@ Goals::TGoalVec PathfindingManager::findPath(
const std::function<Goals::TSubgoal(int3)> doVisitTile) const const std::function<Goals::TSubgoal(int3)> doVisitTile) const
{ {
Goals::TGoalVec result; Goals::TGoalVec result;
boost::optional<uint64_t> armyValueRequired; std::optional<uint64_t> armyValueRequired;
uint64_t danger; uint64_t danger;
std::vector<AIPath> chainInfo = pathfinder->getPathInfo(hero, dest); std::vector<AIPath> chainInfo = pathfinder->getPathInfo(hero, dest);
@ -165,12 +165,12 @@ Goals::TGoalVec PathfindingManager::findPath(
if(!armyValueRequired || armyValueRequired > danger) if(!armyValueRequired || armyValueRequired > danger)
{ {
armyValueRequired = boost::make_optional(danger); armyValueRequired = std::make_optional(danger);
} }
} }
} }
danger = armyValueRequired.get_value_or(0); danger = armyValueRequired.value_or(0);
if(allowGatherArmy && danger > 0) if(allowGatherArmy && danger > 0)
{ {

View File

@ -120,7 +120,7 @@ namespace AIPathfinding
if(boatNodeOptional) if(boatNodeOptional)
{ {
AIPathNode * boatNode = boatNodeOptional.get(); AIPathNode * boatNode = boatNodeOptional.value();
if(boatNode->action == CGPathNode::UNKNOWN) if(boatNode->action == CGPathNode::UNKNOWN)
{ {

View File

@ -106,7 +106,7 @@ namespace AIPathfinding
return; return;
} }
AIPathNode * battleNode = battleNodeOptional.get(); auto * battleNode = battleNodeOptional.value();
if(battleNode->locked) if(battleNode->locked)
{ {

View File

@ -1241,14 +1241,14 @@ void VCAI::recruitCreatures(const CGDwelling * d, const CArmedInstance * recruit
} }
} }
bool VCAI::isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, boost::optional<float> movementCostLimit) bool VCAI::isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, std::optional<float> movementCostLimit)
{ {
int3 op = obj->visitablePos(); int3 op = obj->visitablePos();
auto paths = ah->getPathsToTile(h, op); auto paths = ah->getPathsToTile(h, op);
for(const auto & path : paths) for(const auto & path : paths)
{ {
if(movementCostLimit && movementCostLimit.get() < path.movementCost()) if(movementCostLimit && movementCostLimit.value() < path.movementCost())
return false; return false;
if(isGoodForVisit(obj, h, path)) if(isGoodForVisit(obj, h, path))
@ -1363,18 +1363,13 @@ void VCAI::wander(HeroPtr h)
}); });
int pass = 0; int pass = 0;
std::vector<boost::optional<float>> distanceLimits = std::vector<std::optional<float>> distanceLimits = {1.0, 2.0, std::nullopt};
{
1.0,
2.0,
boost::none
};
while(!dests.size() && pass < distanceLimits.size()) while(!dests.size() && pass < distanceLimits.size())
{ {
auto & distanceLimit = distanceLimits[pass]; auto & distanceLimit = distanceLimits[pass];
logAi->debug("Looking for wander destination pass=%i, cost limit=%f", pass, distanceLimit.get_value_or(-1.0)); logAi->debug("Looking for wander destination pass=%i, cost limit=%f", pass, distanceLimit.value_or(-1.0));
vstd::copy_if(visitableObjs, std::back_inserter(dests), [&](ObjectIdRef obj) -> bool vstd::copy_if(visitableObjs, std::back_inserter(dests), [&](ObjectIdRef obj) -> bool
{ {

View File

@ -217,7 +217,7 @@ public:
void completeGoal(Goals::TSubgoal goal); //safely removes goal from reserved hero void completeGoal(Goals::TSubgoal goal); //safely removes goal from reserved hero
void recruitHero(const CGTownInstance * t, bool throwing = false); void recruitHero(const CGTownInstance * t, bool throwing = false);
bool isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, boost::optional<float> movementCostLimit = boost::none); bool isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, std::optional<float> movementCostLimit = std::nullopt);
bool isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, const AIPath & path) const; bool isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, const AIPath & path) const;
//void recruitCreatures(const CGTownInstance * t); //void recruitCreatures(const CGTownInstance * t);
void recruitCreatures(const CGDwelling * d, const CArmedInstance * recruiter); void recruitCreatures(const CGDwelling * d, const CArmedInstance * recruiter);

View File

@ -90,7 +90,7 @@ bool CCallback::upgradeCreature(const CArmedInstance *obj, SlotID stackPos, Crea
void CCallback::endTurn() void CCallback::endTurn()
{ {
logGlobal->trace("Player %d ended his turn.", player.get().getNum()); logGlobal->trace("Player %d ended his turn.", player->getNum());
EndTurn pack; EndTurn pack;
sendRequest(&pack); sendRequest(&pack);
} }
@ -306,8 +306,8 @@ void CCallback::buildBoat( const IShipyard *obj )
sendRequest(&bb); sendRequest(&bb);
} }
CCallback::CCallback(CGameState * GS, boost::optional<PlayerColor> Player, CClient * C) CCallback::CCallback(CGameState * GS, std::optional<PlayerColor> Player, CClient * C):
: CBattleCallback(Player, C) CBattleCallback(Player, C)
{ {
gs = GS; gs = GS;
@ -380,7 +380,7 @@ scripting::Pool * CBattleCallback::getContextPool() const
} }
#endif #endif
CBattleCallback::CBattleCallback(boost::optional<PlayerColor> Player, CClient *C ) CBattleCallback::CBattleCallback(std::optional<PlayerColor> Player, CClient * C)
{ {
player = Player; player = Player;
cl = C; cl = C;
@ -395,8 +395,7 @@ bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
return true; return true;
} }
boost::optional<BattleAction> CBattleCallback::makeSurrenderRetreatDecision( std::optional<BattleAction> CBattleCallback::makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState)
const BattleStateInfoForRetreat & battleState)
{ {
return cl->playerint[getPlayerID().get()]->makeSurrenderRetreatDecision(battleState); return cl->playerint[getPlayerID().value()]->makeSurrenderRetreatDecision(battleState);
} }

View File

@ -54,7 +54,7 @@ public:
//battle //battle
virtual int battleMakeAction(const BattleAction * action) = 0;//for casting spells by hero - DO NOT use it for moving active stack virtual int battleMakeAction(const BattleAction * action) = 0;//for casting spells by hero - DO NOT use it for moving active stack
virtual bool battleMakeTacticAction(BattleAction * action) = 0; // performs tactic phase actions virtual bool battleMakeTacticAction(BattleAction * action) = 0; // performs tactic phase actions
virtual boost::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) = 0; virtual std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) = 0;
}; };
class IGameActionCallback class IGameActionCallback
@ -113,10 +113,10 @@ protected:
CClient *cl; CClient *cl;
public: public:
CBattleCallback(boost::optional<PlayerColor> Player, CClient *C); CBattleCallback(std::optional<PlayerColor> Player, CClient * C);
int battleMakeAction(const BattleAction * action) override;//for casting spells by hero - DO NOT use it for moving active stack int battleMakeAction(const BattleAction * action) override;//for casting spells by hero - DO NOT use it for moving active stack
bool battleMakeTacticAction(BattleAction * action) override; // performs tactic phase actions bool battleMakeTacticAction(BattleAction * action) override; // performs tactic phase actions
boost::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) override; std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) override;
#if SCRIPTING_ENABLED #if SCRIPTING_ENABLED
scripting::Pool * getContextPool() const override; scripting::Pool * getContextPool() const override;
@ -131,7 +131,7 @@ class CCallback : public CPlayerSpecificInfoCallback,
public CBattleCallback public CBattleCallback
{ {
public: public:
CCallback(CGameState * GS, boost::optional<PlayerColor> Player, CClient *C); CCallback(CGameState * GS, std::optional<PlayerColor> Player, CClient * C);
virtual ~CCallback(); virtual ~CCallback();
//client-specific functionalities (pathfinding) //client-specific functionalities (pathfinding)

View File

@ -101,6 +101,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <algorithm> #include <algorithm>
#include <any>
#include <array> #include <array>
#include <atomic> #include <atomic>
#include <bitset> #include <bitset>
@ -144,14 +145,13 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#endif #endif
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/any.hpp>
#include <boost/current_function.hpp>
#include <boost/crc.hpp> #include <boost/crc.hpp>
#include <boost/current_function.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp> #include <boost/date_time/posix_time/posix_time_io.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
@ -159,14 +159,11 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
#include <boost/locale/generator.hpp> #include <boost/locale/generator.hpp>
#endif #endif
#include <boost/logic/tribool.hpp> #include <boost/logic/tribool.hpp>
#include <boost/optional.hpp> #include <boost/multi_array.hpp>
#include <boost/optional/optional_io.hpp>
#include <boost/range/adaptor/filtered.hpp> #include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm.hpp> #include <boost/range/algorithm.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/variant.hpp>
#include <boost/multi_array.hpp>
#ifndef M_PI #ifndef M_PI
# define M_PI 3.14159265358979323846 # define M_PI 3.14159265358979323846
@ -576,28 +573,6 @@ namespace vstd
return i >= 0 && i < c.size(); return i >= 0 && i < c.size();
} }
template <typename Container, typename Index>
boost::optional<typename Container::const_reference> tryAt(const Container &c, Index i)
{
if(isValidIndex(c, i))
{
auto itr = c.begin();
std::advance(itr, i);
return *itr;
}
return boost::none;
}
template <typename Container, typename Pred>
static boost::optional<typename Container::const_reference> tryFindIf(const Container &r, const Pred &t)
{
auto pos = range::find_if(r, t);
if(pos == boost::end(r))
return boost::none;
else
return *pos;
}
template <typename Container> template <typename Container>
typename Container::const_reference atOrDefault(const Container &r, size_t index, const typename Container::const_reference &defaultValue) typename Container::const_reference atOrDefault(const Container &r, size_t index, const typename Container::const_reference &defaultValue)
{ {
@ -669,7 +644,7 @@ namespace vstd
} }
template<class M, class Key, class F> template<class M, class Key, class F>
typename M::mapped_type & getOrCompute(M & m, Key const & k, F f) typename M::mapped_type & getOrCompute(M & m, const Key & k, F f)
{ {
typedef typename M::mapped_type V; typedef typename M::mapped_type V;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -403,9 +403,15 @@ endif()
#install icons and desktop file on Linux #install icons and desktop file on Linux
if(NOT WIN32 AND NOT APPLE AND NOT ANDROID) if(NOT WIN32 AND NOT APPLE AND NOT ANDROID)
#FIXME: move to client makefile? #FIXME: move to client makefile?
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.64x64.png" DESTINATION share/icons/hicolor/64x64/apps RENAME vcmiclient.png) install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.16x16.png" DESTINATION share/icons/hicolor/16x16/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.48x48.png" DESTINATION share/icons/hicolor/48x48/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.32x32.png" DESTINATION share/icons/hicolor/32x32/apps RENAME vcmiclient.png) install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.32x32.png" DESTINATION share/icons/hicolor/32x32/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.48x48.png" DESTINATION share/icons/hicolor/48x48/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.64x64.png" DESTINATION share/icons/hicolor/64x64/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.128x128.png" DESTINATION share/icons/hicolor/128x128/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.256x256.png" DESTINATION share/icons/hicolor/256x256/apps RENAME vcmiclient.png) install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.256x256.png" DESTINATION share/icons/hicolor/256x256/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.512x512.png" DESTINATION share/icons/hicolor/512x512/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.1024x1024.png" DESTINATION share/icons/hicolor/1024x1024/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.2048x2048.png" DESTINATION share/icons/hicolor/2048x2048/apps RENAME vcmiclient.png)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.svg" DESTINATION share/icons/hicolor/scalable/apps RENAME vcmiclient.svg)
install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.desktop" DESTINATION share/applications) install(FILES "${CMAKE_SOURCE_DIR}/client/icons/vcmiclient.desktop" DESTINATION share/applications)
endif() endif()

View File

@ -103,7 +103,7 @@ std::shared_ptr<BattleInterface> CPlayerInterface::battleInt;
enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE}; enum EMoveState {STOP_MOVE, WAITING_MOVE, CONTINUE_MOVE, DURING_MOVE};
CondSh<EMoveState> stillMoveHero(STOP_MOVE); //used during hero movement CondSh<EMoveState> stillMoveHero(STOP_MOVE); //used during hero movement
struct HeroObjectRetriever : boost::static_visitor<const CGHeroInstance *> struct HeroObjectRetriever
{ {
const CGHeroInstance * operator()(const ConstTransitivePtr<CGHeroInstance> &h) const const CGHeroInstance * operator()(const ConstTransitivePtr<CGHeroInstance> &h) const
{ {
@ -328,7 +328,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
if (details.result == TryMoveHero::EMBARK || details.result == TryMoveHero::DISEMBARK) if (details.result == TryMoveHero::EMBARK || details.result == TryMoveHero::DISEMBARK)
{ {
if(hero->getRemovalSound() && hero->tempOwner == playerID) if(hero->getRemovalSound() && hero->tempOwner == playerID)
CCS->soundh->playSound(hero->getRemovalSound().get()); CCS->soundh->playSound(hero->getRemovalSound().value());
} }
adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.start)); adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.start));
@ -463,7 +463,7 @@ void CPlayerInterface::heroVisit(const CGHeroInstance * visitor, const CGObjectI
if(start && visitedObj) if(start && visitedObj)
{ {
if(visitedObj->getVisitSound()) if(visitedObj->getVisitSound())
CCS->soundh->playSound(visitedObj->getVisitSound().get()); CCS->soundh->playSound(visitedObj->getVisitSound().value());
} }
} }
@ -1530,7 +1530,7 @@ void CPlayerInterface::objectRemoved(const CGObjectInstance * obj)
if(LOCPLINT->cb->getCurrentPlayer() == playerID && obj->getRemovalSound()) if(LOCPLINT->cb->getCurrentPlayer() == playerID && obj->getRemovalSound())
{ {
waitWhileDialog(); waitWhileDialog();
CCS->soundh->playSound(obj->getRemovalSound().get()); CCS->soundh->playSound(obj->getRemovalSound().value());
} }
CGI->mh->waitForOngoingAnimations(); CGI->mh->waitForOngoingAnimations();
@ -1758,7 +1758,7 @@ void CPlayerInterface::acceptTurn()
if(optDaysWithoutCastle) if(optDaysWithoutCastle)
{ {
auto daysWithoutCastle = optDaysWithoutCastle.get(); auto daysWithoutCastle = optDaysWithoutCastle.value();
if (daysWithoutCastle < 6) if (daysWithoutCastle < 6)
{ {
text.addTxt(MetaString::ARRAY_TXT,128); //%s, you only have %d days left to capture a town or you will be banished from this land. text.addTxt(MetaString::ARRAY_TXT,128); //%s, you only have %d days left to capture a town or you will be banished from this land.
@ -1915,7 +1915,7 @@ void CPlayerInterface::requestReturningToMainMenu(bool won)
void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al) void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
{ {
auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
if(hero) if(hero)
{ {
auto art = hero->getArt(al.slot); auto art = hero->getArt(al.slot);
@ -1932,14 +1932,14 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
void CPlayerInterface::artifactPut(const ArtifactLocation &al) void CPlayerInterface::artifactPut(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
updateInfo(hero); updateInfo(hero);
} }
void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
updateInfo(hero); updateInfo(hero);
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {
@ -1954,7 +1954,7 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst) void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = boost::apply_visitor(HeroObjectRetriever(), dst.artHolder); auto hero = std::visit(HeroObjectRetriever(), dst.artHolder);
updateInfo(hero); updateInfo(hero);
bool redraw = true; bool redraw = true;
@ -1983,7 +1983,7 @@ void CPlayerInterface::bulkArtMovementStart(size_t numOfArts)
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
updateInfo(hero); updateInfo(hero);
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {
@ -1996,7 +1996,7 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
auto hero = boost::apply_visitor(HeroObjectRetriever(), al.artHolder); auto hero = std::visit(HeroObjectRetriever(), al.artHolder);
updateInfo(hero); updateInfo(hero);
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {

View File

@ -421,7 +421,7 @@ void CClient::initPlayerEnvironments()
if(settings["session"]["spectate"].Bool()) if(settings["session"]["spectate"].Bool())
{ {
playerEnvironments[PlayerColor::SPECTATOR] = std::make_shared<CPlayerEnvironment>(PlayerColor::SPECTATOR, this, std::make_shared<CCallback>(gs, boost::none, this)); playerEnvironments[PlayerColor::SPECTATOR] = std::make_shared<CPlayerEnvironment>(PlayerColor::SPECTATOR, this, std::make_shared<CCallback>(gs, std::nullopt, this));
} }
} }
@ -626,7 +626,7 @@ void CClient::commenceTacticPhaseForInt(std::shared_ptr<CBattleGameInterface> ba
battleInt->yourTacticPhase(gs->curB->tacticDistance); battleInt->yourTacticPhase(gs->curB->tacticDistance);
if(gs && !!gs->curB && gs->curB->tacticDistance) //while awaiting for end of tactics phase, many things can happen (end of battle... or game) if(gs && !!gs->curB && gs->curB->tacticDistance) //while awaiting for end of tactics phase, many things can happen (end of battle... or game)
{ {
MakeAction ma(BattleAction::makeEndOFTacticPhase(gs->curB->playerToSide(battleInt->playerID).get())); MakeAction ma(BattleAction::makeEndOFTacticPhase(gs->curB->playerToSide(battleInt->playerID).value()));
sendRequest(&ma, battleInt->playerID); sendRequest(&ma, battleInt->playerID);
} }
} }

View File

@ -140,7 +140,7 @@ public:
std::map<PlayerColor, std::vector<std::shared_ptr<IBattleEventsReceiver>>> additionalBattleInts; std::map<PlayerColor, std::vector<std::shared_ptr<IBattleEventsReceiver>>> additionalBattleInts;
boost::optional<BattleAction> curbaction; std::optional<BattleAction> curbaction;
CClient(); CClient();
~CClient(); ~CClient();

View File

@ -42,7 +42,34 @@
#include <SDL_surface.h> #include <SDL_surface.h>
void ClientCommandManager::handleGoSolo() void ClientCommandManager::handleQuitCommand()
{
exit(EXIT_SUCCESS);
}
void ClientCommandManager::handleSaveCommand(std::istringstream & singleWordBuffer)
{
if(!CSH->client)
{
printCommandMessage("Game is not in playing state");
return;
}
std::string saveFilename;
singleWordBuffer >> saveFilename;
CSH->client->save(saveFilename);
printCommandMessage("Game saved as: " + saveFilename);
}
void ClientCommandManager::handleLoadCommand(std::istringstream& singleWordBuffer)
{
// TODO: this code should end the running game and manage to call startGame instead
//std::string fname;
//singleWordBuffer >> fname;
//CSH->client->loadGame(fname);
}
void ClientCommandManager::handleGoSoloCommand()
{ {
Settings session = settings.write["session"]; Settings session = settings.write["session"];
@ -80,21 +107,33 @@ void ClientCommandManager::handleGoSolo()
session["aiSolo"].Bool() = !session["aiSolo"].Bool(); session["aiSolo"].Bool() = !session["aiSolo"].Bool();
} }
void ClientCommandManager::handleControlAi(const std::string &colorName) void ClientCommandManager::handleAutoskipCommand()
{ {
Settings session = settings.write["session"];
session["autoSkip"].Bool() = !session["autoSkip"].Bool();
}
void ClientCommandManager::handleControlaiCommand(std::istringstream& singleWordBuffer)
{
std::string colorName;
singleWordBuffer >> colorName;
boost::to_lower(colorName);
boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim); boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim);
if(!CSH->client) if(!CSH->client)
{ {
printCommandMessage("Game is not in playing state"); printCommandMessage("Game is not in playing state");
return; return;
} }
PlayerColor color; PlayerColor color;
if(LOCPLINT) if(LOCPLINT)
color = LOCPLINT->playerID; color = LOCPLINT->playerID;
for(auto & elem : CSH->client->gameState()->players) for(auto & elem : CSH->client->gameState()->players)
{ {
if(elem.second.human || (colorName.length() && if(elem.second.human ||
elem.first.getNum() != vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, colorName))) (colorName.length() && elem.first.getNum() != vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, colorName)))
{ {
continue; continue;
} }
@ -102,28 +141,40 @@ void ClientCommandManager::handleControlAi(const std::string &colorName)
CSH->client->removeGUI(); CSH->client->removeGUI();
CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first); CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
} }
GH.totalRedraw(); GH.totalRedraw();
if(color != PlayerColor::NEUTRAL) if(color != PlayerColor::NEUTRAL)
giveTurn(color); giveTurn(color);
} }
void ClientCommandManager::processCommand(const std::string &message, bool calledFromIngameConsole) void ClientCommandManager::handleSetBattleAICommand(std::istringstream& singleWordBuffer)
{ {
std::istringstream singleWordBuffer; std::string aiName;
singleWordBuffer.str(message); singleWordBuffer >> aiName;
std::string commandName;
singleWordBuffer >> commandName;
currentCallFromIngameConsole = calledFromIngameConsole;
if(message==std::string("die, fool")) printCommandMessage("Will try loading that AI to see if it is correct name...\n");
try
{ {
exit(EXIT_SUCCESS); if(auto ai = CDynLibHandler::getNewBattleAI(aiName)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game
{
Settings neutralAI = settings.write["server"]["neutralAI"];
neutralAI->String() = aiName;
printCommandMessage("Setting changed, from now the battle ai will be " + aiName + "!\n");
} }
else if(commandName == "redraw") }
catch(std::exception &e)
{
printCommandMessage("Failed opening " + aiName + ": " + e.what(), ELogLevel::WARN);
printCommandMessage("Setting not changed, AI not found or invalid!", ELogLevel::WARN);
}
}
void ClientCommandManager::handleRedrawCommand()
{ {
GH.totalRedraw(); GH.totalRedraw();
} }
else if(commandName == "screen")
void ClientCommandManager::handleScreenCommand()
{ {
printCommandMessage("Screenbuf points to "); printCommandMessage("Screenbuf points to ");
@ -137,25 +188,25 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
SDL_SaveBMP(screen, "Screen_c.bmp"); SDL_SaveBMP(screen, "Screen_c.bmp");
SDL_SaveBMP(screen2, "Screen2_c.bmp"); SDL_SaveBMP(screen2, "Screen2_c.bmp");
} }
else if(commandName == "save")
void ClientCommandManager::handleNotDialogCommand()
{ {
if(!CSH->client) LOCPLINT->showingDialog->setn(false);
}
void ClientCommandManager::handleGuiCommand()
{ {
printCommandMessage("Game is not in playing state"); for(const auto & child : GH.listInt)
return; {
const auto childPtr = child.get();
if(const CIntObject * obj = dynamic_cast<const CIntObject*>(childPtr))
printInfoAboutInterfaceObject(obj, 0);
else
printCommandMessage(std::string(typeid(childPtr).name()) + "\n");
} }
std::string fname;
singleWordBuffer >> fname;
CSH->client->save(fname);
} }
// else if(commandName=="load")
// { void ClientCommandManager::handleConvertTextCommand()
// // TODO: this code should end the running game and manage to call startGame instead
// std::string fname;
// singleWordBuffer >> fname;
// CSH->client->loadGame(fname);
// }
else if(message=="convert txt")
{ {
logGlobal->info("Searching for available maps"); logGlobal->info("Searching for available maps");
std::unordered_set<ResourceID> mapList = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident) std::unordered_set<ResourceID> mapList = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident)
@ -194,12 +245,12 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
VLC->generaltexth->dumpAllTexts(); VLC->generaltexth->dumpAllTexts();
} }
else if(message=="get config")
void ClientCommandManager::handleGetConfigCommand()
{ {
printCommandMessage("Command accepted.\t"); printCommandMessage("Command accepted.\t");
const boost::filesystem::path outPath = const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "configuration";
VCMIDirs::get().userExtractedPath() / "configuration";
boost::filesystem::create_directories(outPath); boost::filesystem::create_directories(outPath);
@ -234,13 +285,13 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
printCommandMessage("\rExtracting done :)\n"); printCommandMessage("\rExtracting done :)\n");
printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n"); printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n");
} }
#if SCRIPTING_ENABLED
else if(message=="get scripts") void ClientCommandManager::handleGetScriptsCommand()
{ {
#if SCRIPTING_ENABLED
printCommandMessage("Command accepted.\t"); printCommandMessage("Command accepted.\t");
const boost::filesystem::path outPath = const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "scripts";
VCMIDirs::get().userExtractedPath() / "scripts";
boost::filesystem::create_directories(outPath); boost::filesystem::create_directories(outPath);
@ -256,9 +307,10 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
} }
printCommandMessage("\rExtracting done :)\n"); printCommandMessage("\rExtracting done :)\n");
printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n"); printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n");
}
#endif #endif
else if(message=="get txt") }
void ClientCommandManager::handleGetTextCommand()
{ {
printCommandMessage("Command accepted.\t"); printCommandMessage("Command accepted.\t");
@ -286,24 +338,51 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
printCommandMessage("\rExtracting done :)\n"); printCommandMessage("\rExtracting done :)\n");
printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n"); printCommandMessage("Extracted files can be found in " + outPath.string() + " directory\n");
} }
else if(commandName == "crash")
void ClientCommandManager::handleDef2bmpCommand(std::istringstream& singleWordBuffer)
{ {
int *ptr = nullptr; std::string URI;
*ptr = 666; singleWordBuffer >> URI;
//disaster! std::unique_ptr<CAnimation> anim = std::make_unique<CAnimation>(URI);
anim->preload();
anim->exportBitmaps(VCMIDirs::get().userExtractedPath());
} }
else if(commandName == "mp" && adventureInt)
void ClientCommandManager::handleExtractCommand(std::istringstream& singleWordBuffer)
{ {
if(const CGHeroInstance *h = adventureInt->curHero()) std::string URI;
printCommandMessage(std::to_string(h->movement) + "; max: " + std::to_string(h->maxMovePoints(true)) + "/" + std::to_string(h->maxMovePoints(false)) + "\n"); singleWordBuffer >> URI;
if(CResourceHandler::get()->existsResource(ResourceID(URI)))
{
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / URI;
auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll();
boost::filesystem::create_directories(outPath.parent_path());
boost::filesystem::ofstream outFile(outPath, boost::filesystem::ofstream::binary);
outFile.write((char*)data.first.get(), data.second);
} }
else if(commandName == "bonuses") else
printCommandMessage("File not found!", ELogLevel::ERROR);
}
void ClientCommandManager::handleBonusesCommand(std::istringstream & singleWordBuffer)
{ {
bool jsonFormat = (message == "bonuses json"); if(currentCallFromIngameConsole)
auto format = [jsonFormat](const BonusList & b) -> std::string
{ {
if(jsonFormat) printCommandMessage("Output for this command is too large for ingame chat! Please run it from client console.\n");
return;
}
std::string outputFormat;
singleWordBuffer >> outputFormat;
auto format = [outputFormat](const BonusList & b) -> std::string
{
if(outputFormat == "json")
return b.toJsonNode().toJson(true); return b.toJsonNode().toJson(true);
std::ostringstream ss; std::ostringstream ss;
ss << b; ss << b;
return ss.str(); return ss.str();
@ -319,26 +398,13 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
printCommandMessage(std::string("\nBonuses from ") + typeid(*parent).name() + "\n" + format(*parent->getAllBonuses(Selector::all, Selector::all)) + "\n"); printCommandMessage(std::string("\nBonuses from ") + typeid(*parent).name() + "\n" + format(*parent->getAllBonuses(Selector::all, Selector::all)) + "\n");
} }
} }
else if(commandName == "not dialog")
{ void ClientCommandManager::handleTellCommand(std::istringstream& singleWordBuffer)
LOCPLINT->showingDialog->setn(false);
}
else if(commandName == "gui")
{
for(auto & child : GH.listInt)
{
const auto childPtr = child.get();
if(const CIntObject * obj = dynamic_cast<const CIntObject *>(childPtr))
printInfoAboutInterfaceObject(obj, 0);
else
printCommandMessage(std::string(typeid(childPtr).name()) + "\n");
}
}
else if(commandName == "tell")
{ {
std::string what; std::string what;
int id1, id2; int id1, id2;
singleWordBuffer >> what >> id1 >> id2; singleWordBuffer >> what >> id1 >> id2;
if(what == "hs") if(what == "hs")
{ {
for(const CGHeroInstance* h : LOCPLINT->cb->getHeroesInfo()) for(const CGHeroInstance* h : LOCPLINT->cb->getHeroesInfo())
@ -347,7 +413,14 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
printCommandMessage(a->nodeName()); printCommandMessage(a->nodeName());
} }
} }
else if (commandName == "set")
void ClientCommandManager::handleMpCommand()
{
if(const CGHeroInstance* h = adventureInt->curHero())
printCommandMessage(std::to_string(h->movement) + "; max: " + std::to_string(h->maxMovePoints(true)) + "/" + std::to_string(h->maxMovePoints(false)) + "\n");
}
void ClientCommandManager::handleSetCommand(std::istringstream& singleWordBuffer)
{ {
std::string what, value; std::string what, value;
singleWordBuffer >> what; singleWordBuffer >> what;
@ -367,121 +440,20 @@ void ClientCommandManager::processCommand(const std::string &message, bool calle
printCommandMessage("Option " + what + " disabled!", ELogLevel::INFO); printCommandMessage("Option " + what + " disabled!", ELogLevel::INFO);
} }
} }
else if(commandName == "unlock")
void ClientCommandManager::handleUnlockCommand(std::istringstream& singleWordBuffer)
{ {
std::string mxname; std::string mxname;
singleWordBuffer >> mxname; singleWordBuffer >> mxname;
if(mxname == "pim" && LOCPLINT) if(mxname == "pim" && LOCPLINT)
LOCPLINT->pim->unlock(); LOCPLINT->pim->unlock();
} }
else if(commandName == "def2bmp")
{
std::string URI;
singleWordBuffer >> URI;
std::unique_ptr<CAnimation> anim = std::make_unique<CAnimation>(URI);
anim->preload();
anim->exportBitmaps(VCMIDirs::get().userExtractedPath());
}
else if(commandName == "extract")
{
std::string URI;
singleWordBuffer >> URI;
if (CResourceHandler::get()->existsResource(ResourceID(URI))) void ClientCommandManager::handleCrashCommand()
{ {
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / URI; int* ptr = nullptr;
*ptr = 666;
auto data = CResourceHandler::get()->load(ResourceID(URI))->readAll(); //disaster!
boost::filesystem::create_directories(outPath.parent_path());
boost::filesystem::ofstream outFile(outPath, boost::filesystem::ofstream::binary);
outFile.write((char*)data.first.get(), data.second);
}
else
printCommandMessage("File not found!", ELogLevel::ERROR);
}
else if(commandName == "setBattleAI")
{
std::string fname;
singleWordBuffer >> fname;
printCommandMessage("Will try loading that AI to see if it is correct name...\n");
try
{
if(auto ai = CDynLibHandler::getNewBattleAI(fname)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game
{
Settings neutralAI = settings.write["server"]["neutralAI"];
neutralAI->String() = fname;
printCommandMessage("Setting changed, from now the battle ai will be " + fname + "!\n");
}
}
catch(std::exception &e)
{
printCommandMessage("Failed opening " + fname + ": " + e.what(), ELogLevel::WARN);
printCommandMessage("Setting not changed, AI not found or invalid!", ELogLevel::WARN);
}
}
else if(commandName == "autoskip")
{
Settings session = settings.write["session"];
session["autoSkip"].Bool() = !session["autoSkip"].Bool();
}
else if(commandName == "gosolo")
{
ClientCommandManager::handleGoSolo();
}
else if(commandName == "controlai")
{
std::string colorName;
singleWordBuffer >> colorName;
boost::to_lower(colorName);
ClientCommandManager::handleControlAi(colorName);
}
else
{
if (!commandName.empty() && !vstd::iswithin(commandName[0], 0, ' ')) // filter-out debugger/IDE noise
printCommandMessage("Command not found :(", ELogLevel::ERROR);
}
}
void ClientCommandManager::giveTurn(const PlayerColor &colorIdentifier)
{
YourTurn yt;
yt.player = colorIdentifier;
yt.daysWithoutCastle = CSH->client->getPlayerState(colorIdentifier)->daysWithoutCastle;
ApplyClientNetPackVisitor visitor(*CSH->client, *CSH->client->gameState());
yt.visit(visitor);
}
void ClientCommandManager::printInfoAboutInterfaceObject(const CIntObject *obj, int level)
{
std::stringstream sbuffer;
sbuffer << std::string(level, '\t');
sbuffer << typeid(*obj).name() << " *** ";
if (obj->active)
{
#define PRINT(check, text) if (obj->active & CIntObject::check) sbuffer << text
PRINT(LCLICK, 'L');
PRINT(RCLICK, 'R');
PRINT(HOVER, 'H');
PRINT(MOVE, 'M');
PRINT(KEYBOARD, 'K');
PRINT(TIME, 'T');
PRINT(GENERAL, 'A');
PRINT(WHEEL, 'W');
PRINT(DOUBLECLICK, 'D');
#undef PRINT
}
else
sbuffer << "inactive";
sbuffer << " at " << obj->pos.x <<"x"<< obj->pos.y;
sbuffer << " (" << obj->pos.w <<"x"<< obj->pos.h << ")";
printCommandMessage(sbuffer.str(), ELogLevel::INFO);
for(const CIntObject *child : obj->children)
printInfoAboutInterfaceObject(child, level+1);
} }
void ClientCommandManager::printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType) void ClientCommandManager::printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType)
@ -520,3 +492,131 @@ void ClientCommandManager::printCommandMessage(const std::string &commandMessage
} }
} }
} }
void ClientCommandManager::printInfoAboutInterfaceObject(const CIntObject *obj, int level)
{
std::stringstream sbuffer;
sbuffer << std::string(level, '\t');
sbuffer << typeid(*obj).name() << " *** ";
if (obj->active)
{
#define PRINT(check, text) if (obj->active & CIntObject::check) sbuffer << text
PRINT(LCLICK, 'L');
PRINT(RCLICK, 'R');
PRINT(HOVER, 'H');
PRINT(MOVE, 'M');
PRINT(KEYBOARD, 'K');
PRINT(TIME, 'T');
PRINT(GENERAL, 'A');
PRINT(WHEEL, 'W');
PRINT(DOUBLECLICK, 'D');
#undef PRINT
}
else
sbuffer << "inactive";
sbuffer << " at " << obj->pos.x <<"x"<< obj->pos.y;
sbuffer << " (" << obj->pos.w <<"x"<< obj->pos.h << ")";
printCommandMessage(sbuffer.str(), ELogLevel::INFO);
for(const CIntObject *child : obj->children)
printInfoAboutInterfaceObject(child, level+1);
}
void ClientCommandManager::giveTurn(const PlayerColor &colorIdentifier)
{
YourTurn yt;
yt.player = colorIdentifier;
yt.daysWithoutCastle = CSH->client->getPlayerState(colorIdentifier)->daysWithoutCastle;
ApplyClientNetPackVisitor visitor(*CSH->client, *CSH->client->gameState());
yt.visit(visitor);
}
void ClientCommandManager::processCommand(const std::string & message, bool calledFromIngameConsole)
{
// split the message into individual words
std::istringstream singleWordBuffer;
singleWordBuffer.str(message);
// get command name, to be used for single word commands
std::string commandName;
singleWordBuffer >> commandName;
currentCallFromIngameConsole = calledFromIngameConsole;
if(message == std::string("die, fool"))
handleQuitCommand();
else if(commandName == "save")
handleSaveCommand(singleWordBuffer);
else if(commandName=="load")
handleLoadCommand(singleWordBuffer); // not implemented
else if(commandName == "gosolo")
handleGoSoloCommand();
else if(commandName == "autoskip")
handleAutoskipCommand();
else if(commandName == "controlai")
handleControlaiCommand(singleWordBuffer);
else if(commandName == "setBattleAI")
handleSetBattleAICommand(singleWordBuffer);
else if(commandName == "redraw")
handleRedrawCommand();
else if(commandName == "screen")
handleScreenCommand();
else if(commandName == "not dialog")
handleNotDialogCommand();
else if(commandName == "gui")
handleGuiCommand();
else if(message=="convert txt")
handleConvertTextCommand();
else if(message=="get config")
handleGetConfigCommand();
else if(message=="get scripts")
handleGetScriptsCommand();
else if(message=="get txt")
handleGetTextCommand();
else if(commandName == "def2bmp")
handleDef2bmpCommand(singleWordBuffer);
else if(commandName == "extract")
handleExtractCommand(singleWordBuffer);
else if(commandName == "bonuses")
handleBonusesCommand(singleWordBuffer);
else if(commandName == "tell")
handleTellCommand(singleWordBuffer);
else if(commandName == "mp" && adventureInt)
handleMpCommand();
else if (commandName == "set")
handleSetCommand(singleWordBuffer);
else if(commandName == "unlock")
handleUnlockCommand(singleWordBuffer);
else if(commandName == "crash")
handleCrashCommand();
else
{
if (!commandName.empty() && !vstd::iswithin(commandName[0], 0, ' ')) // filter-out debugger/IDE noise
printCommandMessage("Command not found :(", ELogLevel::ERROR);
}
}

View File

@ -17,13 +17,83 @@ class CIntObject;
class ClientCommandManager //take mantis #2292 issue about account if thinking about handling cheats from command-line class ClientCommandManager //take mantis #2292 issue about account if thinking about handling cheats from command-line
{ {
bool currentCallFromIngameConsole = false; bool currentCallFromIngameConsole = false; // commands can come from 2 sources: ingame console (chat) and client console
void giveTurn(const PlayerColor &color); // Quits the game (die, fool command)
void printInfoAboutInterfaceObject(const CIntObject *obj, int level); void handleQuitCommand();
// Saves current game under the given filename
void handleSaveCommand(std::istringstream & singleWordBuffer);
// Loads a game with the given filename
void handleLoadCommand(std::istringstream & singleWordBuffer);
// AI takes over until the end of turn (unlike original H3 currently causes AI to take over until typed again)
void handleGoSoloCommand();
// Toggles autoskip mode on and off. In this mode, player turns are automatically skipped and only AI moves.
// However, GUI is still present and allows to observe AI moves. After this option is activated, you need to end first turn manually.
// Press [Shift] before your turn starts to not skip it.
void handleAutoskipCommand();
// Gives you control over specified AI player. If none is specified gives you control over all AI players
void handleControlaiCommand(std::istringstream& singleWordBuffer);
// Change battle AI used by neutral creatures to the one specified. Persists through game quit
void handleSetBattleAICommand(std::istringstream& singleWordBuffer);
// Redraw the current screen
void handleRedrawCommand();
// Prints information about current screen, and saves both screens as .bmp in root folder
void handleScreenCommand();
// Set the state indicating if dialog box is active to "no"
void handleNotDialogCommand();
// Displays tree view of currently present VCMI common GUI elements
void handleGuiCommand();
// Dumps all game text, maps text and campaign maps text into Client log between BEGIN TEXT EXPORT and END TEXT EXPORT
void handleConvertTextCommand();
// Saves current game configuration into extracted/configuration folder
void handleGetConfigCommand();
// Dumps all scripts in Extracted/Scripts
void handleGetScriptsCommand();
// Dumps all .txt files from DATA into Extracted/DATA
void handleGetTextCommand();
// Extract .def animation as BMP files
void handleDef2bmpCommand(std::istringstream& singleWordBuffer);
// Export file into Extracted directory
void handleExtractCommand(std::istringstream& singleWordBuffer);
// Print in console the current bonuses for curent army
void handleBonusesCommand(std::istringstream & singleWordBuffer);
// Get what artifact is present on artifact slot with specified ID for hero with specified ID
void handleTellCommand(std::istringstream& singleWordBuffer);
// Show current movement points, max movement points on land / max movement points on water.
void handleMpCommand();
// set <command> <on/off> - sets special temporary settings that reset on game quit.
void handleSetCommand(std::istringstream& singleWordBuffer);
// Unlocks specific mutex known in VCMI code as "pim"
void handleUnlockCommand(std::istringstream& singleWordBuffer);
// Crashes the game forcing an exception
void handleCrashCommand();
// Prints in Chat the given message
void printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType = ELogLevel::NOT_SET); void printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType = ELogLevel::NOT_SET);
void handleGoSolo(); void printInfoAboutInterfaceObject(const CIntObject *obj, int level);
void handleControlAi(const std::string &colorName); void giveTurn(const PlayerColor &color);
public: public:
ClientCommandManager() = default; ClientCommandManager() = default;

View File

@ -762,7 +762,7 @@ void ApplyClientNetPackVisitor::visitBattleAttack(BattleAttack & pack)
void ApplyFirstClientNetPackVisitor::visitStartAction(StartAction & pack) void ApplyFirstClientNetPackVisitor::visitStartAction(StartAction & pack)
{ {
cl.curbaction = boost::make_optional(pack.ba); cl.curbaction = std::make_optional(pack.ba);
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::actionStarted, pack.ba); callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::actionStarted, pack.ba);
} }

View File

@ -853,7 +853,7 @@ void CAdvMapInt::keyPressed(const SDL_Keycode & key)
} }
} }
boost::optional<Point> CAdvMapInt::keyToMoveDirection(const SDL_Keycode & key) std::optional<Point> CAdvMapInt::keyToMoveDirection(const SDL_Keycode & key)
{ {
switch (key) { switch (key) {
case SDLK_DOWN: return Point( 0, +1); case SDLK_DOWN: return Point( 0, +1);
@ -871,7 +871,7 @@ boost::optional<Point> CAdvMapInt::keyToMoveDirection(const SDL_Keycode & key)
case SDLK_KP_8: return Point( 0, -1); case SDLK_KP_8: return Point( 0, -1);
case SDLK_KP_9: return Point(+1, -1); case SDLK_KP_9: return Point(+1, -1);
} }
return boost::none; return std::nullopt;
} }
void CAdvMapInt::select(const CArmedInstance *sel, bool centerView) void CAdvMapInt::select(const CArmedInstance *sel, bool centerView)

View File

@ -143,7 +143,7 @@ private:
const CGObjectInstance *getActiveObject(const int3 &tile); const CGObjectInstance *getActiveObject(const int3 &tile);
boost::optional<Point> keyToMoveDirection(const SDL_Keycode & key); std::optional<Point> keyToMoveDirection(const SDL_Keycode & key);
public: public:
CAdvMapInt(); CAdvMapInt();

View File

@ -136,7 +136,7 @@ std::vector<std::string> MapAudioPlayer::getAmbientSounds(const int3 & tile)
logGlobal->warn("Already removed object %d found on tile! (%d %d %d)", objectID.getNum(), tile.x, tile.y, tile.z); logGlobal->warn("Already removed object %d found on tile! (%d %d %d)", objectID.getNum(), tile.x, tile.y, tile.z);
if(object && object->getAmbientSound()) if(object && object->getAmbientSound())
result.push_back(object->getAmbientSound().get()); result.push_back(object->getAmbientSound().value());
} }
if(CGI->mh->getMap()->isCoastalTile(tile)) if(CGI->mh->getMap()->isCoastalTile(tile))

View File

@ -252,7 +252,7 @@ void BattleInterface::giveCommand(EActionType action, BattleHex tile, si32 addit
} }
auto ba = new BattleAction(); //is deleted in CPlayerInterface::stacksController->getActiveStack()() auto ba = new BattleAction(); //is deleted in CPlayerInterface::stacksController->getActiveStack()()
ba->side = side.get(); ba->side = side.value();
ba->actionType = action; ba->actionType = action;
ba->aimToHex(tile); ba->aimToHex(tile);
ba->actionSubtype = additional; ba->actionSubtype = additional;

View File

@ -68,7 +68,7 @@ void BattleConsole::showAll(SDL_Surface * to)
std::vector<std::string> BattleConsole::getVisibleText() std::vector<std::string> BattleConsole::getVisibleText()
{ {
// high priority texts that hide battle log entries // high priority texts that hide battle log entries
for (auto const & text : {consoleText, hoverText} ) for(const auto & text : {consoleText, hoverText})
{ {
if (text.empty()) if (text.empty())
continue; continue;
@ -94,7 +94,7 @@ std::vector<std::string> BattleConsole::splitText(const std::string &text)
boost::split(lines, text, boost::is_any_of("\n")); boost::split(lines, text, boost::is_any_of("\n"));
for (auto const & line : lines) for(const auto & line : lines)
{ {
if (graphics->fonts[FONT_SMALL]->getStringWidth(text) < pos.w) if (graphics->fonts[FONT_SMALL]->getStringWidth(text) < pos.w)
{ {
@ -679,7 +679,7 @@ int32_t StackQueue::getSiegeShooterIconID()
return owner.siegeController->getSiegedTown()->town->faction->getIndex(); return owner.siegeController->getSiegedTown()->town->faction->getIndex();
} }
boost::optional<uint32_t> StackQueue::getHoveredUnitIdIfAny() const std::optional<uint32_t> StackQueue::getHoveredUnitIdIfAny() const
{ {
for(const auto & stackBox : stackBoxes) for(const auto & stackBox : stackBoxes)
{ {
@ -689,7 +689,7 @@ boost::optional<uint32_t> StackQueue::getHoveredUnitIdIfAny() const
} }
} }
return boost::none; return std::nullopt;
} }
StackQueue::StackBox::StackBox(StackQueue * owner): StackQueue::StackBox::StackBox(StackQueue * owner):
@ -758,7 +758,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
} }
else else
{ {
boundUnitID = boost::none; boundUnitID = std::nullopt;
background->colorize(PlayerColor::NEUTRAL); background->colorize(PlayerColor::NEUTRAL);
icon->visible = false; icon->visible = false;
icon->setFrame(0); icon->setFrame(0);
@ -769,7 +769,7 @@ void StackQueue::StackBox::setUnit(const battle::Unit * unit, size_t turn)
} }
} }
boost::optional<uint32_t> StackQueue::StackBox::getBoundUnitID() const std::optional<uint32_t> StackQueue::StackBox::getBoundUnitID() const
{ {
return boundUnitID; return boundUnitID;
} }

View File

@ -166,7 +166,7 @@ class StackQueue : public CIntObject
class StackBox : public CIntObject class StackBox : public CIntObject
{ {
StackQueue * owner; StackQueue * owner;
boost::optional<uint32_t> boundUnitID; std::optional<uint32_t> boundUnitID;
bool highlighted = false; bool highlighted = false;
public: public:
@ -178,7 +178,7 @@ class StackQueue : public CIntObject
StackBox(StackQueue * owner); StackBox(StackQueue * owner);
void setUnit(const battle::Unit * unit, size_t turn = 0); void setUnit(const battle::Unit * unit, size_t turn = 0);
void toggleHighlight(bool value); void toggleHighlight(bool value);
boost::optional<uint32_t> getBoundUnitID() const; std::optional<uint32_t> getBoundUnitID() const;
void show(SDL_Surface * to) override; void show(SDL_Surface * to) override;
}; };
@ -197,7 +197,7 @@ public:
StackQueue(bool Embedded, BattleInterface & owner); StackQueue(bool Embedded, BattleInterface & owner);
void update(); void update();
boost::optional<uint32_t> getHoveredUnitIdIfAny() const; std::optional<uint32_t> getHoveredUnitIdIfAny() const;
void show(SDL_Surface * to) override; void show(SDL_Surface * to) override;
}; };

View File

@ -66,7 +66,7 @@ void BattleObstacleController::loadObstacleImage(const CObstacleInstance & oi)
void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges> & obstacles) void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges> & obstacles)
{ {
for (auto const & oi : obstacles) for(const auto & oi : obstacles)
{ {
auto & obstacle = oi.data["obstacle"]; auto & obstacle = oi.data["obstacle"];
@ -97,11 +97,11 @@ void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges
void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & obstacles) void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & obstacles)
{ {
for (auto const & oi : obstacles) for(const auto & oi : obstacles)
{ {
auto side = owner.curInt->cb->playerToSide(owner.curInt->playerID); auto side = owner.curInt->cb->playerToSide(owner.curInt->playerID);
if(!oi->visibleForSide(side.get(),owner.curInt->cb->battleHasNativeStack(side.get()))) if(!oi->visibleForSide(side.value(), owner.curInt->cb->battleHasNativeStack(side.value())))
continue; continue;
auto animation = std::make_shared<CAnimation>(oi->getAppearAnimation()); auto animation = std::make_shared<CAnimation>(oi->getAppearAnimation());

View File

@ -281,7 +281,7 @@ std::shared_ptr<IImage> BattleStacksController::getStackAmountBox(const CStack *
int effectsPositivness = 0; int effectsPositivness = 0;
for ( auto const & spellID : activeSpells) for(const auto & spellID : activeSpells)
effectsPositivness += CGI->spellh->objects.at(spellID)->positiveness; effectsPositivness += CGI->spellh->objects.at(spellID)->positiveness;
if (effectsPositivness > 0) if (effectsPositivness > 0)
@ -336,7 +336,7 @@ void BattleStacksController::showStackAmountBox(Canvas & canvas, const CStack *
void BattleStacksController::showStack(Canvas & canvas, const CStack * stack) void BattleStacksController::showStack(Canvas & canvas, const CStack * stack)
{ {
ColorFilter fullFilter = ColorFilter::genEmptyShifter(); ColorFilter fullFilter = ColorFilter::genEmptyShifter();
for (auto const & filter : stackFilterEffects) for(const auto & filter : stackFilterEffects)
{ {
if (filter.target == stack) if (filter.target == stack)
fullFilter = ColorFilter::genCombined(fullFilter, filter.effect); fullFilter = ColorFilter::genCombined(fullFilter, filter.effect);
@ -814,7 +814,7 @@ void BattleStacksController::updateHoveredStacks()
{ {
auto newStacks = selectHoveredStacks(); auto newStacks = selectHoveredStacks();
for (auto const * stack : mouseHoveredStacks) for(const auto * stack : mouseHoveredStacks)
{ {
if (vstd::contains(newStacks, stack)) if (vstd::contains(newStacks, stack))
continue; continue;
@ -825,7 +825,7 @@ void BattleStacksController::updateHoveredStacks()
stackAnimation[stack->ID]->setBorderColor(AnimationControls::getNoBorder()); stackAnimation[stack->ID]->setBorderColor(AnimationControls::getNoBorder());
} }
for (auto const * stack : newStacks) for(const auto * stack : newStacks)
{ {
if (vstd::contains(mouseHoveredStacks, stack)) if (vstd::contains(mouseHoveredStacks, stack))
continue; continue;
@ -848,7 +848,7 @@ std::vector<const CStack *> BattleStacksController::selectHoveredStacks()
return {}; return {};
auto hoveredQueueUnitId = owner.windowObject->getQueueHoveredUnitId(); auto hoveredQueueUnitId = owner.windowObject->getQueueHoveredUnitId();
if(hoveredQueueUnitId.is_initialized()) if(hoveredQueueUnitId.has_value())
{ {
return { owner.curInt->cb->battleGetStackByID(hoveredQueueUnitId.value(), true) }; return { owner.curInt->cb->battleGetStackByID(hoveredQueueUnitId.value(), true) };
} }
@ -889,7 +889,7 @@ std::vector<const CStack *> BattleStacksController::selectHoveredStacks()
const std::vector<uint32_t> BattleStacksController::getHoveredStacksUnitIds() const const std::vector<uint32_t> BattleStacksController::getHoveredStacksUnitIds() const
{ {
auto result = std::vector<uint32_t>(); auto result = std::vector<uint32_t>();
for (auto const * stack : mouseHoveredStacks) for(const auto * stack : mouseHoveredStacks)
{ {
result.push_back(stack->unitId()); result.push_back(stack->unitId());
} }

View File

@ -590,7 +590,7 @@ void BattleWindow::blockUI(bool on)
} }
} }
boost::optional<uint32_t> BattleWindow::getQueueHoveredUnitId() std::optional<uint32_t> BattleWindow::getQueueHoveredUnitId()
{ {
return queue->getHoveredUnitIdIfAny(); return queue->getHoveredUnitIdIfAny();
} }

View File

@ -80,7 +80,7 @@ public:
void updateQueue(); void updateQueue();
/// Get mouse-hovered battle queue unit ID if any found /// Get mouse-hovered battle queue unit ID if any found
boost::optional<uint32_t> getQueueHoveredUnitId(); std::optional<uint32_t> getQueueHoveredUnitId();
void activate() override; void activate() override;
void deactivate() override; void deactivate() override;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 KiB

After

Width:  |  Height:  |  Size: 239 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

401
client/icons/vcmiclient.svg Normal file
View File

@ -0,0 +1,401 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="1671.788"
height="1671.788"
viewBox="0 0 442.32723 442.32723"
version="1.1"
id="svg8061"
sodipodi:docname="VCMI-logo.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview71"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
showguides="true"
inkscape:zoom="0.61431235"
inkscape:cx="835.89398"
inkscape:cy="835.08006"
inkscape:window-width="2560"
inkscape:window-height="1372"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg8061" />
<defs
id="defs8058">
<filter
style="color-interpolation-filters:sRGB"
id="filter5509"
x="-0.049653775"
y="-0.046298778"
width="1.0993076"
height="1.0925976">
<feFlood
flood-opacity="0.741176"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood5499" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite5501" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur5503" />
<feOffset
dx="0"
dy="0"
result="offset"
id="feOffset5505" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite5507" />
</filter>
<linearGradient
xlink:href="#b"
id="linearGradient6733"
x1="142.42035"
y1="742.36987"
x2="894.56238"
y2="-43.642666"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="b">
<stop
style="stop-color:#413c35;stop-opacity:1;"
offset="0"
id="stop6727" />
<stop
style="stop-color:#e1dfde;stop-opacity:1;"
offset="0.25866053"
id="stop23920" />
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0.34411085"
id="stop17103" />
<stop
style="stop-color:#343131;stop-opacity:1;"
offset="0.45496535"
id="stop19868" />
<stop
style="stop-color:#676565;stop-opacity:1;"
offset="0.60739028"
id="stop23916" />
<stop
style="stop-color:#bab9b9;stop-opacity:1;"
offset="0.69515014"
id="stop21700" />
<stop
style="stop-color:#bab9b9;stop-opacity:1;"
offset="0.80369514"
id="stop23918" />
<stop
style="stop-color:#87837d;stop-opacity:1;"
offset="1"
id="stop6729" />
</linearGradient>
<linearGradient
xlink:href="#b"
id="linearGradient23922"
gradientUnits="userSpaceOnUse"
x1="214.29761"
y1="742.36987"
x2="709.07269"
y2="-78.421982" />
<linearGradient
xlink:href="#linearGradient6731"
id="linearGradient13982"
x1="284.41074"
y1="647.30627"
x2="722.42993"
y2="-25.09388"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient6731">
<stop
style="stop-color:#644d40;stop-opacity:1;"
offset="0"
id="stop14834" />
<stop
style="stop-color:#492e1e;stop-opacity:1;"
offset="0.34180138"
id="stop14836" />
<stop
style="stop-color:#2d0e00;stop-opacity:1;"
offset="0.44341803"
id="stop14838" />
<stop
style="stop-color:#2d0e00;stop-opacity:1;"
offset="0.57999998"
id="stop14840" />
<stop
style="stop-color:#7d6456;stop-opacity:1;"
offset="0.68000001"
id="stop14842" />
<stop
style="stop-color:#d2c3ba;stop-opacity:1;"
offset="1"
id="stop14844" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient942"
id="linearGradient944"
x1="827.46008"
y1="110.79597"
x2="827.46008"
y2="208.54196"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-805.23573,44.793022)" />
<linearGradient
id="linearGradient942">
<stop
style="stop-color:#f8c52d;stop-opacity:1;"
offset="0"
id="stop938" />
<stop
style="stop-color:#8b6d05;stop-opacity:1;"
offset="1"
id="stop940" />
</linearGradient>
<filter
style="color-interpolation-filters:sRGB"
id="filter6247"
x="-0.27160581"
y="-0.20290551"
width="1.5432116"
height="1.405811">
<feFlood
flood-opacity="0.741176"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood6237" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite6239" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur6241" />
<feOffset
dx="0"
dy="0"
result="offset"
id="feOffset6243" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite6245" />
</filter>
<linearGradient
xlink:href="#linearGradient942"
id="linearGradient4820"
x1="931.25116"
y1="108.46269"
x2="931.25116"
y2="208.13298"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-805.23573,44.793022)" />
<filter
style="color-interpolation-filters:sRGB"
id="filter6259"
x="-0.22545054"
y="-0.20290551"
width="1.4509011"
height="1.405811">
<feFlood
flood-opacity="0.741176"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood6249" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite6251" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur6253" />
<feOffset
dx="0"
dy="0"
result="offset"
id="feOffset6255" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite6257" />
</filter>
<linearGradient
xlink:href="#linearGradient942"
id="linearGradient4816"
x1="1047.7046"
y1="112.43189"
x2="1047.7046"
y2="207.724"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-805.23573,44.793022)" />
<filter
style="color-interpolation-filters:sRGB"
id="filter6271"
x="-0.17643958"
y="-0.20290551"
width="1.3528792"
height="1.405811">
<feFlood
flood-opacity="0.741176"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood6261" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite6263" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur6265" />
<feOffset
dx="0"
dy="0"
result="offset"
id="feOffset6267" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite6269" />
</filter>
<linearGradient
xlink:href="#linearGradient942"
id="linearGradient4818"
x1="1192.9985"
y1="110.38699"
x2="1192.9985"
y2="208.13298"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-805.23573,44.793022)" />
<filter
style="color-interpolation-filters:sRGB"
id="filter6283"
x="-0.90773429"
y="-0.20290551"
width="2.8154686"
height="1.405811">
<feFlood
flood-opacity="0.741176"
flood-color="rgb(0,0,0)"
result="flood"
id="feFlood6273" />
<feComposite
in="flood"
in2="SourceGraphic"
operator="in"
result="composite1"
id="feComposite6275" />
<feGaussianBlur
in="composite1"
stdDeviation="5"
result="blur"
id="feGaussianBlur6277" />
<feOffset
dx="0"
dy="0"
result="offset"
id="feOffset6279" />
<feComposite
in="SourceGraphic"
in2="offset"
operator="over"
result="composite2"
id="feComposite6281" />
</filter>
<linearGradient
xlink:href="#linearGradient6731"
id="linearGradient8804"
gradientUnits="userSpaceOnUse"
x1="284.41074"
y1="647.30627"
x2="722.42993"
y2="-25.09388" />
</defs>
<g
id="g959">
<g
id="g1382"
transform="matrix(1.3884149,0,0,1.3884149,42.02983,5.902602)"
style="filter:url(#filter5509)">
<g
style="fill:url(#linearGradient6733);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:8.50394;stroke-dasharray:none;stroke-opacity:0.603133;paint-order:stroke fill markers"
id="g1233"
transform="matrix(0.35277778,0,0,0.35277778,-47.966154,35.473965)">
<path
style="fill:url(#linearGradient23922);fill-opacity:1;stroke:#000000;stroke-width:8.50394;stroke-dasharray:none;stroke-opacity:0.603133;paint-order:stroke fill markers"
d="m 170.868,-74.3394 c 0,0 167.34,37.2314 333.221,37.2314 174.565,0 348.114,-37.2314 348.114,-37.2314 32.9,0 44.678,8.0547 44.678,40.9545 0,0 -111.694,785.5839 -390.93,785.5839 -279.236,0 -379.761,-785.5839 -379.761,-785.5839 0,-32.8998 11.778,-40.9545 44.678,-40.9545 z"
id="path1221" />
</g>
<g
style="fill:url(#linearGradient13982);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:8.50394;stroke-dasharray:none;stroke-opacity:0.349869;paint-order:stroke fill markers"
id="g194"
transform="matrix(0.35277778,0,0,0.35277778,-47.966154,35.474023)">
<path
style="fill:url(#linearGradient8804);fill-opacity:1;stroke:#000000;stroke-width:8.50394;stroke-dasharray:none;stroke-opacity:0.349869;paint-order:stroke fill markers"
d="m 239.001,8.31427 c 0,0 133.873,29.78523 266.578,29.78523 139.652,0 278.491,-29.78523 278.491,-29.78523 26.32,0 35.742,6.44393 35.742,32.76363 0,0 -89.356,628.4671 -312.744,628.4671 -223.389,0 -303.809,-628.4671 -303.809,-628.4671 0,-26.3197 9.423,-32.76363 35.742,-32.76363 z"
id="path182" />
</g>
</g>
<g
id="g947">
<path
style="fill:url(#linearGradient944);fill-opacity:1;stroke:#282828;stroke-width:15.90145826;stroke-linecap:square;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter6247);paint-order:stroke fill markers"
d="m 22.35664,154.68591 h 21.40019 v 26.89484 h 12.72445 v 39.33009 h 5.20546 v -39.33009 h 13.3028 v -26.89484 h 20.82182 v 31.8111 H 83.08693 v 40.19766 h -13.8812 v 26.31646 H 48.0947 V 226.69467 H 35.37028 V 186.49701 H 22.35664 Z"
id="path104" />
<path
style="fill:url(#linearGradient4820);fill-opacity:1;stroke:#282828;stroke-width:15.90145826;stroke-linecap:square;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter6259);paint-order:stroke fill markers"
d="m 125.01976,168.56711 h 14.4596 v -13.8812 h 60.44111 v 13.8812 h 13.592 v 17.9299 h -21.11101 v -13.30283 h -45.1139 v 61.16408 h 45.1139 v -13.44742 h 21.11101 v 18.50827 h -13.592 v 13.59202 h -60.44111 v -13.59202 h -14.4596 v -70.852 0"
id="path1189" />
<path
style="fill:url(#linearGradient4816);fill-opacity:1;stroke:#282828;stroke-width:15.90145826;stroke-linecap:square;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter6271);paint-order:stroke fill markers"
d="m 243.01007,154.68591 h 34.4138 v 26.89484 h 12.7244 v 27.18403 h 18.5083 v -27.18403 h 13.4474 v -26.89484 h 33.9801 v 98.32522 h -19.9543 v -66.51412 h -6.3622 v 27.18403 h -13.0136 v 25.73807 h -34.1247 v -25.73807 h -13.3028 v -27.18403 h -6.073 v 66.51412 h -20.2434 v -98.32522"
id="path1228" />
<path
style="fill:url(#linearGradient4818);fill-opacity:1;stroke:#282828;stroke-width:15.90145826;stroke-linecap:square;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1;filter:url(#filter6283);paint-order:stroke fill markers"
d="m 387.89507,154.68591 h 21.9786 v 98.32522 h -21.9786 z"
id="path1263" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -1,226 +1,238 @@
/* XPM */ /* XPM */
static char *vcmiclient[] = { static char *x[] = {
/* columns rows colors chars-per-pixel */ /* columns rows colors chars-per-pixel */
"32 32 188 2 ", "32 32 200 2 ",
" c #010101", " c gray11",
". c #090909", ". c #161616",
"X c #140600", "X c #2C0E00",
"o c #180700", "o c #2D1003",
"O c #140A06", "O c #25140C",
"+ c #1B0901", "+ c #28130A",
"@ c #1E120C", "@ c #311305",
"# c #161414", "# c #331609",
"$ c #1C1C1B", "$ c #34190C",
"% c #220B01", "% c #391C0D",
"& c #2B0E00", "& c #241610",
"* c #2E1002", "* c #241A16",
"= c #2C140A", "= c #251E1A",
"- c #331507", "- c #2C1C14",
"; c #341609", "; c #391E11",
": c #35180B", ": c #2A241D",
"> c #221612", "> c #20201F",
", c #221915", ", c #3D2112",
"< c #2C1C15", "< c #38231B",
"1 c #281F1A", "1 c #3C351E",
"2 c #351C10", "2 c #242323",
"3 c #391E11", "3 c #2C2B2B",
"4 c #3D2214", "4 c #282625",
"5 c #3C2519", "5 c #332E20",
"6 c #252424", "6 c #362D29",
"7 c #2D2D2C", "7 c #302620",
"8 c #3B2B24", "8 c #363122",
"9 c #3C302B", "9 c #3C3521",
"0 c #343333", "0 c #3E352C",
"q c #3F3036", "q c #36302D",
"w c #393837", "w c #353433",
"e c #3D3C3B", "e c #3D3B3B",
"r c #402215", "r c #3B3431",
"t c #422618", "t c #412516",
"y c #442B1E", "y c #462A1B",
"u c #482D1F", "u c #492E1E",
"i c #452D21", "i c #45271B",
"p c #4A2F21", "p c #443A1B",
"a c #4D3325", "a c #4A3F1C",
"s c #4E372C", "s c #4A2F20",
"d c #503729", "d c #4D3323",
"f c #52392C", "f c #423B24",
"g c #423433", "g c #48372E",
"h c #483C35", "h c #483F25",
"j c #443438", "j c #503627",
"k c #443B3E", "k c #513728",
"l c #533E32", "l c #543B2C",
"z c #41403F", "z c #593D2F",
"x c #4B433E", "x c #483D37",
"c c #514037", "c c #473C37",
"v c #5D4236", "v c #573E30",
"b c #53433B", "b c #583F31",
"n c #5E4438", "n c #5A4C1D",
"m c #634F3F", "m c #63531C",
"M c #695337", "M c #6F5C18",
"N c #67523F", "N c #725D13",
"B c #6A543D", "B c #7D6515",
"V c #6C583B", "V c #4E4426",
"C c #795F36", "C c #514623",
"Z c #725A3E", "Z c #44423F",
"A c #795F3E", "A c #5C4234",
"S c #413741", "S c #5A4438",
"D c #473C46", "D c #625220",
"F c #444242", "F c #6C5A24",
"G c #4A4845", "G c #6B5A29",
"H c #4C4B4B", "H c #715E26",
"J c #5A4D46", "J c #674D3F",
"K c #54524F", "K c #604537",
"L c #5B504C", "L c #7A6525",
"P c #555454", "P c #746129",
"I c #5A5956", "I c #444242",
"U c #5B5B5B", "U c #494645",
"Y c #645143", "Y c #4C4B4A",
"T c #6B5544", "T c #4A4845",
"R c #6F5A45", "R c #554A46",
"E c #65544C", "E c #5B4D45",
"W c #6D564B", "W c #514742",
"Q c #6A594F", "Q c #555352",
"! c #735D46", "! c #595757",
"~ c #6B5655", "~ c #5D5B5A",
"^ c #6D5A53", "^ c #694E40",
"/ c #655D58", "/ c #6B5549",
"( c #6C595B", "( c #775D4F",
") c #755E56", ") c #705648",
"_ c #735F59", "_ c #6B5F58",
"` c #796143", "` c #755E52",
"' c #75624E", "' c #62605E",
"] c #7B624C", "] c #7E6557",
"[ c #67625D", "[ c #7A665A",
"{ c #7B6356", "{ c #666564",
"} c #71645E", "} c #696766",
"| c #7B665A", "| c #6D6B6A",
" . c #7E695E", " . c #6A6865",
".. c #715E60", ".. c #7B6B62",
"X. c #656362", "X. c #726D69",
"o. c #6A6762", "o. c #7A7674",
"O. c #6D6A66", "O. c #7D7B7B",
"+. c #6A6168", "+. c #767471",
"@. c #6D6B6B", "@. c #95750A",
"#. c #726C67", "#. c #98770A",
"$. c #726E6A", "$. c #846B1B",
"%. c #76726F", "%. c #876D17",
"&. c #79726D", "&. c #8E731E",
"*. c #716F70", "*. c #93761D",
"=. c #747473", "=. c #96781C",
"-. c #7B7671", "-. c #9B7B10",
";. c #7D7976", ";. c #A07F0F",
":. c #7E7D7B", ":. c #A07D10",
">. c #80673C", ">. c #836C22",
",. c #8D713F", ",. c #866F29",
"<. c #9F7E37", "<. c #8C7324",
"1. c #816843", "1. c #997D22",
"2. c #886D41", "2. c #967A28",
"3. c #927745", "3. c #826A5D",
"4. c #826B5E", "4. c #80675A",
"5. c #836E62", "5. c #856D60",
"6. c #877166", "6. c #897164",
"7. c #887266", "7. c #8C7569",
"8. c #8B756A", "8. c #8F786C",
"9. c #8F796E", "9. c #927C6F",
"0. c #907A6F", "0. c #827D79",
"q. c #857A73", "q. c #937E72",
"w. c #827E79", "w. c #A7840F",
"e. c #927D73", "e. c #AE8A16",
"r. c #A38234", "r. c #A5831A",
"t. c #A58439", "t. c #B08C1C",
"y. c #AF8B3E", "y. c #B79015",
"u. c #B08E39", "u. c #BD961A",
"i. c #BD9738", "i. c #A88825",
"p. c #E3B101", "p. c #B08E23",
"a. c #CAA021", "a. c #BB9624",
"s. c #CEA43F", "s. c #BB9626",
"d. c #E4B437", "d. c #C69D1B",
"f. c #E4B53E", "f. c #C29B22",
"g. c #F4C23D", "g. c #C29C2A",
"h. c #A28343", "h. c #CCA220",
"j. c #A88741", "j. c #CDA42A",
"k. c #B39040", "k. c #D9AD26",
"l. c #BF9940", "l. c #D2A726",
"z. c #86837E", "z. c #E6B726",
"x. c #948177", "x. c #86827D",
"c. c #94867E", "c. c #8A847F",
"v. c #99847A", "v. c #978175",
"b. c #9D897E", "b. c #94867D",
"n. c #BE9C6E", "n. c #9B867A",
"m. c #D3AB6D", "m. c #9E897D",
"M. c #E3B76C", "M. c #998377",
"N. c #F0C26B", "N. c #848383",
"B. c #F0C273", "B. c #8A8680",
"V. c #858482", "V. c #8F8B86",
"C. c #888682", "C. c #9B8D85",
"Z. c #8C8985", "Z. c #938E89",
"A. c #8E8D8D", "A. c #918984",
"S. c #928C86", "S. c #96928E",
"D. c #918F8C", "D. c #9A9693",
"F. c #95918D", "F. c #9C9996",
"G. c #959492", "G. c #9D9B99",
"H. c #9A9792", "H. c #939292",
"J. c #9B9995", "J. c #A28E82",
"K. c #9E9B99", "K. c #A69287",
"L. c #A18D82", "L. c #A5948A",
"P. c #A39086", "P. c #AC988D",
"I. c #A6948A", "I. c #A9958A",
"U. c #A9968C", "U. c #A69C96",
"Y. c #AB988E", "Y. c #AD9C93",
"T. c #AF9C92", "T. c #A29D99",
"R. c #A19E9A", "R. c #A89F99",
"E. c #A4A29E", "E. c #B19E93",
"W. c #B4A298", "W. c #A5A29F",
"Q. c #A5A4A1", "Q. c #B3A196",
"!. c #A9A7A3", "!. c #B8A69C",
"~. c #ACA9A6", "~. c #B9A69C",
"^. c #ADACAB", "^. c #A4A3A2",
"/. c #B1AEAB", "/. c #A9A6A3",
"(. c #B2B0AD", "(. c #ADABA9",
"). c #B5B4B2", "). c #ABA8A5",
"_. c #BAB9B7", "_. c #BCABA1",
"`. c #BDBCBB", "`. c #B2AEAC",
"'. c #C4C3C3", "'. c #B5A9A3",
"]. c #C8C8C8", "]. c #B3B2AF",
"[. c #D1D0CE", "[. c #B3B2B2",
"{. c #D4D3D3", "{. c #B9B5B3",
"}. c #DADADA", "}. c #BAB9B9",
"|. c #E8E7E6", "|. c #BBB9B6",
" X c #EBEBEA", " X c #C0AFA5",
".X c gray96", ".X c #C4B3AA",
"XX c #FDFDFC", "XX c #C8B8AE",
"oX c None", "oX c #C1BFBE",
"OX c #CDBDB4",
"+X c #CCC9C7",
"@X c #CFCCCB",
"#X c #C5C3C1",
"$X c #D3D1CF",
"%X c #D6D3D2",
"&X c #DDDBDA",
"*X c #EDECEB",
"=X c #E4E3E3",
"-X c #F3F3F3",
";X c #F9F9F9",
":X c None",
/* pixels */ /* pixels */
"oXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoX", ":X:X:XO.V.| Q :X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:XZ Q ' T :X:X",
"oXoXoXoX0 I 0 oXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXw H oXoXoXoX", ":X:XI G.(.}.}.}.(.^.H.N.O.| } ~ ! ' { { } X.o.0.B.x.x.x.x.x.:X:X",
"oXoXoXoX'.'.'.`.Q.D.:.+.P F F 6 6 w e H I @.:.Z.K.E.R.H.$.oXoXoX", ":X:X3 N.H.^.[.}.}.}.}.}.}.}.}.[.`.(./.^.T.T.D.S.Z.V.B.x.x.o.:X:X",
"oXoXoXoX).).`.`.`._.)./.(.(.(.(.(./.~.!.E.R.H.G.D.Z.S.C.o.oXoXoX", ":X:X:X| O. .^ ..b.D./.[.{.}.}.}.{.[.`.(.^.F.S.D.W.'.'.c.c.' :X:X",
"oXoXoXoXV.A.G.*.Z.K.^.).).^.~.Q.Q.E.K.K.J.F.C.-.$.$.S.S.K oXoXoX", ":X:X:X! { c % s b ^ ( 5.7.q.b.C.C.L.L.I.Y.E.~. X XXXOXZ.V.~ :X:X",
"oXoXoXoXX.@.P & : f E } #.&.q.&.-.&.&.&.&.q.c.I.W.S.z.G.w oXoXoX", ":X:X:XU ~ c X @ t j K ) [ 3.6.7.q.b.n.J.L.P.E.E.~. XXXZ.D.Y :X:X",
"oXoXoXoXH X.H = & * r n { 5.7.8.0.x.v.b.L.P.I.Y.T.q.G.H.$ oXoXoX", ":X:X:Xw Q Z X X X % y v ^ ( ] 5.6.8.q.M.C.J.I.E.Q.~.~.F.F.:X:X:X",
"oXoXoXoX7 X.H = * & & : a W 5.6.7.9.x.x.x.L.L.I.U.q.R.F.oXoXoXoX", ":X:X:X4 Y U X X X X @ t d A ) ] 3.6.7.9.q.n.J.K.P.E.W.W.D.:X:X:X",
"oXoXoXoXoXX.F , * & & & * 3 l { 5.6.8.0.x.x.b.L.P.-.Q.;.oXoXoXoX", ":X:X:X:XI U @ X X X X X % i z ^ ( 4.3.6.8.q.M.n.m.I.U.(.x.:X:X:X",
"oXoXoXoXoXI e 1 & & & & & & ; p T | .5.8.0.0.x.x.V.Q.U oXoXoXoX", ":X . w 3 * + X + O & & & - d K g x Z ^ 7...U E R N.N.e :X:X",
"oXoXoXoX F 0 # o & % o o o o & 3 8 g h ^ 5.J b x C.G.$ oXoXoXoX", ":XG j.9 2 ,.s.* + = s.j.j.j.P * i F j.j.0 [ R i.l.i.' Y g.2.:X:X",
"oXoXoXB.4.7 6 B.{ % X N.g.g.] o % { g.B.g Q 4.g.B.U U B.4.oXoXoX", ":XH z.f 2 2.k.* * p.f.,.,.2.l.G X L z.z.8 x q p.z.s.{ Y k.i.:X:X",
"oXoXoXf.>.. $ d.` + M.y.A C f.) % A p.d.> 9 1.p.f.e e f.1.oXoXoX", ":Xh i.f.>.d.L : = h.1.O X : L V X H k.p.a.4 <.f.a.p.{ e h.1.:X:X",
"oXoXoX| s._ m.h.k @ s.Z + o ) g + Z a.<.m._ s.t.s.7 6 s.] oXoXoX", ":X:XF d.<.d.w k = d.&.+ X X X X o F d.B d.2 <.t.<.r.{ w u.*.:X:X",
"oXoXoX i.V i.' k > l.B = % o o % B l.B i.M l.R l.6 . i.! oXoXoX", ":X:XF y.$.y.I ' : e.$.- # & = * X D y.V =.e.e.D %.=.{ 2 e.$.:X:X",
"oXoXoXoX_ u.3.+.C.1 k.B @ O n.^ % N y.g ,.u.Q N y.$ k.! oXoXoX", ":X:X9 %.w.n Q G.: -.B : : 1 w.n X n w.: M w.-.2 B %.Y > -.B :X:X",
"oXoXoXoX j.Y '.}.F ^ j.j.t.2.j % Y j.o m j.X J j.. j.W oXoXoX", ":X:X:Xm #. -X-X6 a @.@.@.#.M 5 o n @.: 1 a a = N B w @.N :X:X",
"oXoXoXoXoX..S Q..XK.< ( Y Y k 5 2 j ~ o q ~ O S ( oX..D oXoXoX", ":X:X:X8 a #X;XC.7 p p p p 8 , # 8 p * X X X + 1 p p 9 :X:X",
"oXoXoXoXoXoXoXK |.{.b i i y y i y 5 : * & & , 7 6 oXoXoXoXoXoXoX", ":X:X:X:X:X:XO.*X@Xk d h u u u y t % # o X X X < Q Y :X:X:X:X:X:X",
"oXoXoXoXoXoXoXoX_.[.&.a d a a a p p y 4 - - F e $ oXoXoXoXoXoXoX", ":X:X:X:X:X:X:X&X*X[ d j j d s u u t , % @ o X r Y 3 :X:X:X:X:X:X",
"oXoXoXoXoXoXoXoX@.(.H.c f d d a a p p u t L G.*.oXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:XF.&XW.z k k j j s d u y , , # - c I :X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXE.E./ f f d d a a a a c ].}.*.oXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X$X%X/ z l k k d d d u u t , 6 w 3 :X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXo.G.C.b f f f s d a s R.XX XoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:XF.@XT.v l l l k d d d d u S .Y :X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXZ.Z.#.c f f f d f $.{. X=.oXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:XI |.#X..A z l l k j j d v F.F.! :X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXe z.w.O.c l f l [ E.).K.oXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:XO.{.]./ A z l z l j z {.=X}.:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXP -.&.&.o.o.;.G.J.D.oXoXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:X:XF.].).` A A z l S `.-X;XO.:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXoXK $.$.%.-.z.z.w.$ oXoXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:X:Xe G.).].V.....b.$X=X*X^.:X:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXoXoX7 I o.O.$.G oXoXoXoXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:X:X:XT D.W.(.{.}.+X%X&X/.:X:X:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoX# oXoXoXoXoXoXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:X:X:X:Xe x.T./.].|.}.O.:X:X:X:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoX", ":X:X:X:X:X:X:X:X:X:X:X:X:X:XY | o. .:X:X:X:X:X:X:X:X:X:X:X:X:X:X",
"oXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoXoX" ":X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X:X"
}; };

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@ -57,15 +57,15 @@ void CButton::update()
redraw(); redraw();
} }
void CButton::setBorderColor(boost::optional<SDL_Color> borderColor) void CButton::setBorderColor(std::optional<SDL_Color> borderColor)
{ {
setBorderColor(borderColor, borderColor, borderColor, borderColor); setBorderColor(borderColor, borderColor, borderColor, borderColor);
} }
void CButton::setBorderColor(boost::optional<SDL_Color> normalBorderColor, void CButton::setBorderColor(std::optional<SDL_Color> normalBorderColor,
boost::optional<SDL_Color> pressedBorderColor, std::optional<SDL_Color> pressedBorderColor,
boost::optional<SDL_Color> blockedBorderColor, std::optional<SDL_Color> blockedBorderColor,
boost::optional<SDL_Color> highlightedBorderColor) std::optional<SDL_Color> highlightedBorderColor)
{ {
stateToBorderColor[NORMAL] = normalBorderColor; stateToBorderColor[NORMAL] = normalBorderColor;
stateToBorderColor[PRESSED] = pressedBorderColor; stateToBorderColor[PRESSED] = pressedBorderColor;
@ -591,7 +591,7 @@ void CSlider::setScrollBounds(const Rect & bounds )
void CSlider::clearScrollBounds() void CSlider::clearScrollBounds()
{ {
scrollBounds = boost::none; scrollBounds = std::nullopt;
} }
int CSlider::getAmount() const int CSlider::getAmount() const

View File

@ -52,7 +52,7 @@ private:
std::array<int, 4> stateToIndex; // mapping of button state to index of frame in animation std::array<int, 4> stateToIndex; // mapping of button state to index of frame in animation
std::array<std::string, 4> hoverTexts; //texts for statusbar, if empty - first entry will be used std::array<std::string, 4> hoverTexts; //texts for statusbar, if empty - first entry will be used
std::array<boost::optional<SDL_Color>, 4> stateToBorderColor; // mapping of button state to border color std::array<std::optional<SDL_Color>, 4> stateToBorderColor; // mapping of button state to border color
std::string helpBox; //for right-click help std::string helpBox; //for right-click help
std::shared_ptr<CAnimImage> image; //image for this button std::shared_ptr<CAnimImage> image; //image for this button
@ -73,13 +73,13 @@ public:
// sets border color for each button state; // sets border color for each button state;
// if it's set, the button will have 1-px border around it with this color // if it's set, the button will have 1-px border around it with this color
void setBorderColor(boost::optional<SDL_Color> normalBorderColor, void setBorderColor(std::optional<SDL_Color> normalBorderColor,
boost::optional<SDL_Color> pressedBorderColor, std::optional<SDL_Color> pressedBorderColor,
boost::optional<SDL_Color> blockedBorderColor, std::optional<SDL_Color> blockedBorderColor,
boost::optional<SDL_Color> highlightedBorderColor); std::optional<SDL_Color> highlightedBorderColor);
// sets the same border color for all button states. // sets the same border color for all button states.
void setBorderColor(boost::optional<SDL_Color> borderColor); void setBorderColor(std::optional<SDL_Color> borderColor);
/// adds one more callback to on-click actions /// adds one more callback to on-click actions
void addCallback(std::function<void()> callback); void addCallback(std::function<void()> callback);
@ -229,7 +229,7 @@ class CSlider : public CIntObject
std::shared_ptr<CButton> right; std::shared_ptr<CButton> right;
std::shared_ptr<CButton> slider; std::shared_ptr<CButton> slider;
boost::optional<Rect> scrollBounds; std::optional<Rect> scrollBounds;
int capacity;//how many elements can be active at same time (e.g. hero list = 5) int capacity;//how many elements can be active at same time (e.g. hero list = 5)
int positions; //number of highest position (0 if there is only one) int positions; //number of highest position (0 if there is only one)

View File

@ -85,7 +85,7 @@ void CPicture::show(SDL_Surface * to)
void CPicture::showAll(SDL_Surface * to) void CPicture::showAll(SDL_Surface * to)
{ {
if(bg && visible) if(bg && visible)
bg->draw(to, pos.x, pos.y, srcRect.get_ptr()); bg->draw(to, pos.x, pos.y, srcRect.has_value() ? &srcRect.value() : nullptr);
} }
void CPicture::setAlpha(int value) void CPicture::setAlpha(int value)

View File

@ -30,7 +30,7 @@ class CPicture : public CIntObject
public: public:
/// if set, only specified section of internal image will be rendered /// if set, only specified section of internal image will be rendered
boost::optional<Rect> srcRect; std::optional<Rect> srcRect;
/// If set to true, iamge will be redrawn on each frame /// If set to true, iamge will be redrawn on each frame
bool needRefresh; bool needRefresh;

View File

@ -64,9 +64,9 @@ public:
const CGHeroInstance * owner; const CGHeroInstance * owner;
// temporary objects which should be kept as copy if needed // temporary objects which should be kept as copy if needed
boost::optional<CommanderLevelInfo> levelupInfo; std::optional<CommanderLevelInfo> levelupInfo;
boost::optional<StackDismissInfo> dismissInfo; std::optional<StackDismissInfo> dismissInfo;
boost::optional<StackUpgradeInfo> upgradeInfo; std::optional<StackUpgradeInfo> upgradeInfo;
// misc fields // misc fields
unsigned int creatureCount; unsigned int creatureCount;
@ -246,8 +246,8 @@ CStackWindow::BonusLineSection::BonusLineSection(CStackWindow * owner, size_t li
} }
} }
CStackWindow::BonusesSection::BonusesSection(CStackWindow * owner, int yOffset, boost::optional<size_t> preferredSize) CStackWindow::BonusesSection::BonusesSection(CStackWindow * owner, int yOffset, std::optional<size_t> preferredSize):
: CWindowSection(owner, "", yOffset) CWindowSection(owner, "", yOffset)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
@ -255,7 +255,7 @@ CStackWindow::BonusesSection::BonusesSection(CStackWindow * owner, int yOffset,
static const int itemHeight = 59; static const int itemHeight = 59;
size_t totalSize = (owner->activeBonuses.size() + 1) / 2; size_t totalSize = (owner->activeBonuses.size() + 1) / 2;
size_t visibleSize = preferredSize ? preferredSize.get() : std::min<size_t>(3, totalSize); size_t visibleSize = preferredSize.value_or(std::min<size_t>(3, totalSize));
pos.w = owner->pos.w; pos.w = owner->pos.w;
pos.h = itemHeight * (int)visibleSize; pos.h = itemHeight * (int)visibleSize;
@ -292,7 +292,7 @@ CStackWindow::ButtonsSection::ButtonsSection(CStackWindow * owner, int yOffset)
// used space overlaps with commander switch button // used space overlaps with commander switch button
// besides - should commander really be upgradeable? // besides - should commander really be upgradeable?
UnitView::StackUpgradeInfo & upgradeInfo = parent->info->upgradeInfo.get(); auto & upgradeInfo = parent->info->upgradeInfo.value();
const size_t buttonsToCreate = std::min<size_t>(upgradeInfo.info.newID.size(), upgrade.size()); const size_t buttonsToCreate = std::min<size_t>(upgradeInfo.info.newID.size(), upgrade.size());
for(size_t buttonIndex = 0; buttonIndex < buttonsToCreate; buttonIndex++) for(size_t buttonIndex = 0; buttonIndex < buttonsToCreate; buttonIndex++)
@ -686,8 +686,8 @@ CStackWindow::CStackWindow(const CStackInstance * stack, std::function<void()> d
info->creature = stack->type; info->creature = stack->type;
info->creatureCount = stack->count; info->creatureCount = stack->count;
info->upgradeInfo = boost::make_optional(UnitView::StackUpgradeInfo()); info->upgradeInfo = std::make_optional(UnitView::StackUpgradeInfo());
info->dismissInfo = boost::make_optional(UnitView::StackDismissInfo()); info->dismissInfo = std::make_optional(UnitView::StackDismissInfo());
info->upgradeInfo->info = upgradeInfo; info->upgradeInfo->info = upgradeInfo;
info->upgradeInfo->callback = callback; info->upgradeInfo->callback = callback;
info->dismissInfo->callback = dismiss; info->dismissInfo->callback = dismiss;
@ -716,7 +716,7 @@ CStackWindow::CStackWindow(const CCommanderInstance * commander, std::vector<ui3
info->creature = commander->type; info->creature = commander->type;
info->commander = commander; info->commander = commander;
info->creatureCount = 1; info->creatureCount = 1;
info->levelupInfo = boost::make_optional(UnitView::CommanderLevelInfo()); info->levelupInfo = std::make_optional(UnitView::CommanderLevelInfo());
info->levelupInfo->skills = skills; info->levelupInfo->skills = skills;
info->levelupInfo->callback = callback; info->levelupInfo->callback = callback;
info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj); info->owner = dynamic_cast<const CGHeroInstance *> (commander->armyObj);
@ -814,7 +814,7 @@ void CStackWindow::initSections()
commanderMainSection = std::make_shared<CommanderMainSection>(this, 0); commanderMainSection = std::make_shared<CommanderMainSection>(this, 0);
auto size = boost::make_optional<size_t>((info->levelupInfo) ? 4 : 3); auto size = std::make_optional<size_t>((info->levelupInfo) ? 4 : 3);
commanderBonusesSection = std::make_shared<BonusesSection>(this, 0, size); commanderBonusesSection = std::make_shared<BonusesSection>(this, 0, size);
deactivateObj(commanderBonusesSection); deactivateObj(commanderBonusesSection);

View File

@ -83,7 +83,7 @@ class CStackWindow : public CWindowObject
{ {
std::shared_ptr<CListBox> lines; std::shared_ptr<CListBox> lines;
public: public:
BonusesSection(CStackWindow * owner, int yOffset, boost::optional<size_t> preferredSize = boost::optional<size_t>()); BonusesSection(CStackWindow * owner, int yOffset, std::optional<size_t> preferredSize = std::optional<size_t>());
}; };
class ButtonsSection : public CWindowSection class ButtonsSection : public CWindowSection

View File

@ -740,15 +740,28 @@ void CArtHandler::erasePickedArt(const ArtifactID & id)
{ {
CArtifact *art = objects[id]; CArtifact *art = objects[id];
if(auto artifactList = listFromClass(art->aClass)) if(!(art->aClass & CArtifact::ART_SPECIAL))
{ {
if(artifactList->empty()) auto & artifactList = treasures;
fillList(*artifactList, art->aClass); switch(art->aClass)
{
case CArtifact::ART_MINOR:
artifactList = minors;
break;
case CArtifact::ART_MAJOR:
artifactList = majors;
break;
case CArtifact::ART_RELIC:
artifactList = relics;
break;
}
if(artifactList.empty())
fillList(artifactList, art->aClass);
auto itr = vstd::find(*artifactList, art); auto itr = vstd::find(artifactList, art);
if(itr != artifactList->end()) if(itr != artifactList.end())
{ {
artifactList->erase(itr); artifactList.erase(itr);
} }
else else
logMod->warn("Problem: cannot erase artifact %s from list, it was not present", art->getNameTranslated()); logMod->warn("Problem: cannot erase artifact %s from list, it was not present", art->getNameTranslated());
@ -758,23 +771,6 @@ void CArtHandler::erasePickedArt(const ArtifactID & id)
logMod->warn("Problem: cannot find list for artifact %s, strange class. (special?)", art->getNameTranslated()); logMod->warn("Problem: cannot find list for artifact %s, strange class. (special?)", art->getNameTranslated());
} }
boost::optional<std::vector<CArtifact*>&> CArtHandler::listFromClass( CArtifact::EartClass artifactClass )
{
switch(artifactClass)
{
case CArtifact::ART_TREASURE:
return treasures;
case CArtifact::ART_MINOR:
return minors;
case CArtifact::ART_MAJOR:
return majors;
case CArtifact::ART_RELIC:
return relics;
default: //special artifacts should not be erased
return boost::optional<std::vector<CArtifact*>&>();
}
}
void CArtHandler::fillList( std::vector<CArtifact*> &listToBeFilled, CArtifact::EartClass artifactClass ) void CArtHandler::fillList( std::vector<CArtifact*> &listToBeFilled, CArtifact::EartClass artifactClass )
{ {
assert(listToBeFilled.empty()); assert(listToBeFilled.empty());

View File

@ -244,8 +244,6 @@ public:
void fillList(std::vector<CArtifact*> &listToBeFilled, CArtifact::EartClass artifactClass); //fills given empty list with allowed artifacts of given class. No side effects void fillList(std::vector<CArtifact*> &listToBeFilled, CArtifact::EartClass artifactClass); //fills given empty list with allowed artifacts of given class. No side effects
boost::optional<std::vector<CArtifact*>&> listFromClass(CArtifact::EartClass artifactClass);
static CArtifact::EartClass stringToClass(const std::string & className); //TODO: rework EartClass to make this a constructor static CArtifact::EartClass stringToClass(const std::string & className); //TODO: rework EartClass to make this a constructor
/// Gets a artifact ID randomly and removes the selected artifact from this handler. /// Gets a artifact ID randomly and removes the selected artifact from this handler.

View File

@ -408,7 +408,7 @@ CCreatureHandler::CCreatureHandler()
const CCreature * CCreatureHandler::getCreature(const std::string & scope, const std::string & identifier) const const CCreature * CCreatureHandler::getCreature(const std::string & scope, const std::string & identifier) const
{ {
boost::optional<si32> index = VLC->modh->identifiers.getIdentifier(scope, "creature", identifier); std::optional<si32> index = VLC->modh->identifiers.getIdentifier(scope, "creature", identifier);
if(!index) if(!index)
throw std::runtime_error("Creature not found "+identifier); throw std::runtime_error("Creature not found "+identifier);

View File

@ -624,7 +624,7 @@ void CCreatureSet::armyChanged()
} }
void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName, const boost::optional<int> fixedSize) void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName, const std::optional<int> fixedSize)
{ {
if(handler.saving && stacks.empty()) if(handler.saving && stacks.empty())
return; return;
@ -640,7 +640,7 @@ void CCreatureSet::serializeJson(JsonSerializeFormat & handler, const std::strin
vstd::amax(sz, p.first.getNum()+1); vstd::amax(sz, p.first.getNum()+1);
if(fixedSize) if(fixedSize)
vstd::amax(sz, fixedSize.get()); vstd::amax(sz, fixedSize.value());
a.resize(sz, JsonNode::JsonType::DATA_STRUCT); a.resize(sz, JsonNode::JsonType::DATA_STRUCT);

View File

@ -75,7 +75,7 @@ public:
uint8_t upgrade; uint8_t upgrade;
}; };
// helper variable used during loading map, when object (hero or town) have creatures that must have same alignment. // helper variable used during loading map, when object (hero or town) have creatures that must have same alignment.
boost::optional<RandomStackInfo> randomStack; std::optional<RandomStackInfo> randomStack;
const CArmedInstance * const & armyObj; //stack must be part of some army, army must be part of some object const CArmedInstance * const & armyObj; //stack must be part of some army, army must be part of some object
TExpType experience;//commander needs same amount of exp as hero TExpType experience;//commander needs same amount of exp as hero
@ -286,7 +286,7 @@ public:
h & formation; h & formation;
} }
void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName, const boost::optional<int> fixedSize = boost::none); void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName, const std::optional<int> fixedSize = std::nullopt);
operator bool() const operator bool() const
{ {

View File

@ -401,7 +401,7 @@ int CGameInfoCallback::getDate(Date::EDateType mode) const
return gs->getDate(mode); return gs->getDate(mode);
} }
bool CGameInfoCallback::isVisible(int3 pos, const boost::optional<PlayerColor> & Player) const bool CGameInfoCallback::isVisible(int3 pos, const std::optional<PlayerColor> & Player) const
{ {
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->isVisible(pos, Player); return gs->isVisible(pos, Player);
@ -412,7 +412,7 @@ bool CGameInfoCallback::isVisible(int3 pos) const
return isVisible(pos, player); return isVisible(pos, player);
} }
bool CGameInfoCallback::isVisible( const CGObjectInstance *obj,const boost::optional<PlayerColor> & Player) const bool CGameInfoCallback::isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const
{ {
return gs->isVisible(obj, Player); return gs->isVisible(obj, Player);
} }
@ -521,8 +521,8 @@ EDiggingStatus CGameInfoCallback::getTileDigStatus(int3 tile, bool verbose) cons
//TODO: typedef? //TODO: typedef?
std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> CGameInfoCallback::getAllVisibleTiles() const std::shared_ptr<const boost::multi_array<TerrainTile*, 3>> CGameInfoCallback::getAllVisibleTiles() const
{ {
assert(player.is_initialized()); assert(player.has_value());
const auto * team = getPlayerTeam(player.get()); const auto * team = getPlayerTeam(player.value());
size_t width = gs->map->width; size_t width = gs->map->width;
size_t height = gs->map->height; size_t height = gs->map->height;
@ -619,9 +619,9 @@ const CMapHeader * CGameInfoCallback::getMapHeader() const
return gs->map; return gs->map;
} }
bool CGameInfoCallback::hasAccess(boost::optional<PlayerColor> playerId) const bool CGameInfoCallback::hasAccess(std::optional<PlayerColor> playerId) const
{ {
return !player || player.get().isSpectator() || gs->getPlayerRelations( *playerId, *player ) != PlayerRelations::ENEMIES; return !player || player->isSpectator() || gs->getPlayerRelations(*playerId, *player) != PlayerRelations::ENEMIES;
} }
EPlayerStatus::EStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbose) const EPlayerStatus::EStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbose) const
@ -703,7 +703,7 @@ PlayerColor CGameInfoCallback::getCurrentPlayer() const
return gs->currentPlayer; return gs->currentPlayer;
} }
CGameInfoCallback::CGameInfoCallback(CGameState * GS, boost::optional<PlayerColor> Player): CGameInfoCallback::CGameInfoCallback(CGameState * GS, std::optional<PlayerColor> Player):
gs(GS) gs(GS)
{ {
player = std::move(Player); player = std::move(Player);
@ -754,7 +754,7 @@ std::vector < const CGHeroInstance *> CPlayerSpecificInfoCallback::getHeroesInfo
return ret; return ret;
} }
boost::optional<PlayerColor> CPlayerSpecificInfoCallback::getMyColor() const std::optional<PlayerColor> CPlayerSpecificInfoCallback::getMyColor() const
{ {
return player; return player;
} }
@ -882,7 +882,7 @@ const TeamState * CGameInfoCallback::getTeam( TeamID teamID ) const
if (team != gs->teams.end()) if (team != gs->teams.end())
{ {
const TeamState *ret = &team->second; const TeamState *ret = &team->second;
if (!player.is_initialized()) //neutral (or invalid) player if(!player.has_value()) //neutral (or invalid) player
return ret; return ret;
else else
{ {

View File

@ -133,8 +133,8 @@ protected:
CGameState * gs;//todo: replace with protected const getter, only actual Server and Client objects should hold game state CGameState * gs;//todo: replace with protected const getter, only actual Server and Client objects should hold game state
CGameInfoCallback() = default; CGameInfoCallback() = default;
CGameInfoCallback(CGameState *GS, boost::optional<PlayerColor> Player); CGameInfoCallback(CGameState * GS, std::optional<PlayerColor> Player);
bool hasAccess(boost::optional<PlayerColor> playerId) const; bool hasAccess(std::optional<PlayerColor> playerId) const;
bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode bool canGetFullInfo(const CGObjectInstance *obj) const; //true we player owns obj or ally owns obj or privileged mode
bool isOwnedOrVisited(const CGObjectInstance *obj) const; bool isOwnedOrVisited(const CGObjectInstance *obj) const;
@ -157,8 +157,8 @@ public:
virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const; virtual const PlayerSettings * getPlayerSettings(PlayerColor color) const;
//map //map
virtual bool isVisible(int3 pos, const boost::optional<PlayerColor> & Player) const; virtual bool isVisible(int3 pos, const std::optional<PlayerColor> & Player) const;
virtual bool isVisible(const CGObjectInstance *obj, const boost::optional<PlayerColor> & Player) const; virtual bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & Player) const;
virtual bool isVisible(const CGObjectInstance * obj) const; virtual bool isVisible(const CGObjectInstance * obj) const;
virtual bool isVisible(int3 pos) const; virtual bool isVisible(int3 pos) const;
@ -234,7 +234,7 @@ public:
virtual int howManyTowns() const; virtual int howManyTowns() const;
virtual int howManyHeroes(bool includeGarrisoned = true) const; virtual int howManyHeroes(bool includeGarrisoned = true) const;
virtual int3 getGrailPos(double *outKnownRatio); virtual int3 getGrailPos(double *outKnownRatio);
virtual boost::optional<PlayerColor> getMyColor() const; virtual std::optional<PlayerColor> getMyColor() const;
virtual std::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible virtual std::vector <const CGTownInstance *> getTownsInfo(bool onlyOur = true) const; //true -> only owned; false -> all visible
virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const; virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;

View File

@ -110,9 +110,9 @@ public:
virtual void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain){}; virtual void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain){};
virtual boost::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState) virtual std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleStateInfoForRetreat & battleState)
{ {
return boost::none; return std::nullopt;
} }
virtual void saveGame(BinarySerializer & h, const int version) = 0; virtual void saveGame(BinarySerializer & h, const int version) = 0;

View File

@ -925,7 +925,7 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
void CGameState::initCampaign() void CGameState::initCampaign()
{ {
logGlobal->info("Open campaign map file: %d", scenarioOps->campState->currentMap.get()); logGlobal->info("Open campaign map file: %d", scenarioOps->campState->currentMap.value());
map = scenarioOps->campState->getMap(); map = scenarioOps->campState->getMap();
} }
@ -1068,7 +1068,7 @@ void CGameState::placeCampaignHeroes()
{ {
// place bonus hero // place bonus hero
auto campaignBonus = scenarioOps->campState->getBonusForCurrentMap(); auto campaignBonus = scenarioOps->campState->getBonusForCurrentMap();
bool campaignGiveHero = campaignBonus && campaignBonus.get().type == CScenarioTravel::STravelBonus::HERO; bool campaignGiveHero = campaignBonus && campaignBonus->type == CScenarioTravel::STravelBonus::HERO;
if(campaignGiveHero) if(campaignGiveHero)
{ {
@ -1568,7 +1568,7 @@ void CGameState::initHeroes()
void CGameState::giveCampaignBonusToHero(CGHeroInstance * hero) void CGameState::giveCampaignBonusToHero(CGHeroInstance * hero)
{ {
const boost::optional<CScenarioTravel::STravelBonus> & curBonus = scenarioOps->campState->getBonusForCurrentMap(); const std::optional<CScenarioTravel::STravelBonus> & curBonus = scenarioOps->campState->getBonusForCurrentMap();
if(!curBonus) if(!curBonus)
return; return;
@ -2234,7 +2234,7 @@ void CGameState::updateRumor()
while(!rumor.update(rumorId, rumorExtra)); while(!rumor.update(rumorId, rumorExtra));
} }
bool CGameState::isVisible(int3 pos, const boost::optional<PlayerColor> & player) const bool CGameState::isVisible(int3 pos, const std::optional<PlayerColor> & player) const
{ {
if (!map->isInTheMap(pos)) if (!map->isInTheMap(pos))
return false; return false;
@ -2248,7 +2248,7 @@ bool CGameState::isVisible(int3 pos, const boost::optional<PlayerColor> & player
return (*getPlayerTeam(*player)->fogOfWarMap)[pos.z][pos.x][pos.y]; return (*getPlayerTeam(*player)->fogOfWarMap)[pos.z][pos.x][pos.y];
} }
bool CGameState::isVisible( const CGObjectInstance *obj, const boost::optional<PlayerColor> & player) const bool CGameState::isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const
{ {
if(!player) if(!player)
return true; return true;
@ -2433,7 +2433,7 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
case EventCondition::DAYS_WITHOUT_TOWN: case EventCondition::DAYS_WITHOUT_TOWN:
{ {
if (p->daysWithoutCastle) if (p->daysWithoutCastle)
return p->daysWithoutCastle.get() >= condition.value; return p->daysWithoutCastle >= condition.value;
else else
return false; return false;
} }

View File

@ -202,9 +202,8 @@ public:
void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
std::map<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns std::map<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
bool isVisible(int3 pos, const std::optional<PlayerColor> & player) const override;
bool isVisible(int3 pos, const boost::optional<PlayerColor> & player) const override; bool isVisible(const CGObjectInstance * obj, const std::optional<PlayerColor> & player) const override;
bool isVisible(const CGObjectInstance *obj, const boost::optional<PlayerColor> & player) const override;
int getDate(Date::EDateType mode=Date::DAY) const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month int getDate(Date::EDateType mode=Date::DAY) const override; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month

View File

@ -156,7 +156,7 @@ void CIdentifierStorage::tryRequestIdentifier(const std::string & type, const Js
requestIdentifier(ObjectCallback::fromNameAndType(name.meta, type, name.String(), callback, true)); requestIdentifier(ObjectCallback::fromNameAndType(name.meta, type, name.String(), callback, true));
} }
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent) std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent)
{ {
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(scope, type, name, std::function<void(si32)>(), silent)); auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(scope, type, name, std::function<void(si32)>(), silent));
@ -165,10 +165,10 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scop
if (!silent) if (!silent)
logMod->error("Failed to resolve identifier %s of type %s from mod %s", name , type ,scope); logMod->error("Failed to resolve identifier %s of type %s from mod %s", name , type ,scope);
return boost::optional<si32>(); return std::optional<si32>();
} }
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type, const JsonNode & name, bool silent) std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type, const JsonNode & name, bool silent)
{ {
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(name.meta, type, name.String(), std::function<void(si32)>(), silent)); auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(name.meta, type, name.String(), std::function<void(si32)>(), silent));
@ -177,10 +177,10 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type
if (!silent) if (!silent)
logMod->error("Failed to resolve identifier %s of type %s from mod %s", name.String(), type, name.meta); logMod->error("Failed to resolve identifier %s of type %s from mod %s", name.String(), type, name.meta);
return boost::optional<si32>(); return std::optional<si32>();
} }
boost::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, bool silent) std::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, bool silent)
{ {
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameWithType(name.meta, name.String(), std::function<void(si32)>(), silent)); auto idList = getPossibleIdentifiers(ObjectCallback::fromNameWithType(name.meta, name.String(), std::function<void(si32)>(), silent));
@ -189,10 +189,10 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, b
if (!silent) if (!silent)
logMod->error("Failed to resolve identifier %s from mod %s", name.String(), name.meta); logMod->error("Failed to resolve identifier %s from mod %s", name.String(), name.meta);
return boost::optional<si32>(); return std::optional<si32>();
} }
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & fullName, bool silent) std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & fullName, bool silent)
{ {
auto idList = getPossibleIdentifiers(ObjectCallback::fromNameWithType(scope, fullName, std::function<void(si32)>(), silent)); auto idList = getPossibleIdentifiers(ObjectCallback::fromNameWithType(scope, fullName, std::function<void(si32)>(), silent));
@ -201,7 +201,7 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scop
if (!silent) if (!silent)
logMod->error("Failed to resolve identifier %s from mod %s", fullName, scope); logMod->error("Failed to resolve identifier %s from mod %s", fullName, scope);
return boost::optional<si32>(); return std::optional<si32>();
} }
void CIdentifierStorage::registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier) void CIdentifierStorage::registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier)

View File

@ -99,10 +99,10 @@ public:
void tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback); void tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback);
/// get identifier immediately. If identifier is not know and not silent call will result in error message /// get identifier immediately. If identifier is not know and not silent call will result in error message
boost::optional<si32> getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent = false); std::optional<si32> getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent = false);
boost::optional<si32> getIdentifier(const std::string & type, const JsonNode & name, bool silent = false); std::optional<si32> getIdentifier(const std::string & type, const JsonNode & name, bool silent = false);
boost::optional<si32> getIdentifier(const JsonNode & name, bool silent = false); std::optional<si32> getIdentifier(const JsonNode & name, bool silent = false);
boost::optional<si32> getIdentifier(const std::string & scope, const std::string & fullName, bool silent = false); std::optional<si32> getIdentifier(const std::string & scope, const std::string & fullName, bool silent = false);
/// registers new object /// registers new object
void registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier); void registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier);

View File

@ -897,7 +897,7 @@ void CPathfinderHelper::initializePatrol()
if(hero->patrol.patrolRadius) if(hero->patrol.patrolRadius)
{ {
state = PATROL_RADIUS; state = PATROL_RADIUS;
gs->getTilesInRange(patrolTiles, hero->patrol.initialPos, hero->patrol.patrolRadius, boost::optional<PlayerColor>(), 0, int3::DIST_MANHATTAN); gs->getTilesInRange(patrolTiles, hero->patrol.initialPos, hero->patrol.patrolRadius, std::optional<PlayerColor>(), 0, int3::DIST_MANHATTAN);
} }
else else
state = PATROL_LOCKED; state = PATROL_LOCKED;
@ -1106,8 +1106,12 @@ void TurnInfo::updateHeroBonuses(Bonus::BonusType type, const CSelector& sel) co
} }
} }
CPathfinderHelper::CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options) CPathfinderHelper::CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options):
: CGameInfoCallback(gs, boost::optional<PlayerColor>()), turn(-1), hero(Hero), options(Options), owner(Hero->tempOwner) CGameInfoCallback(gs, std::optional<PlayerColor>()),
turn(-1),
hero(Hero),
options(Options),
owner(Hero->tempOwner)
{ {
turnsInfo.reserve(16); turnsInfo.reserve(16);
updateTurnInfo(); updateTurnInfo();

View File

@ -38,7 +38,7 @@ public:
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
EPlayerStatus::EStatus status; EPlayerStatus::EStatus status;
boost::optional<ui8> daysWithoutCastle; std::optional<ui8> daysWithoutCastle;
PlayerState(); PlayerState();
PlayerState(PlayerState && other) noexcept; PlayerState(PlayerState && other) noexcept;

View File

@ -262,7 +262,7 @@ si32 CSkillHandler::decodeSkill(const std::string & identifier)
{ {
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "skill", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "skill", identifier);
if(rawId) if(rawId)
return rawId.get(); return rawId.value();
else else
return -1; return -1;
} }

View File

@ -1151,7 +1151,7 @@ void CTownHandler::initializeRequirements()
logMod->warn("Entry contains: "); logMod->warn("Entry contains: ");
logMod->warn(node.toJson()); logMod->warn(node.toJson());
} }
return BuildingID(VLC->modh->identifiers.getIdentifier(requirement.town->getBuildingScope(), node.Vector()[0]).get()); return BuildingID(VLC->modh->identifiers.getIdentifier(requirement.town->getBuildingScope(), node.Vector()[0]).value());
}); });
} }
requirementsToLoad.clear(); requirementsToLoad.clear();
@ -1166,7 +1166,7 @@ void CTownHandler::initializeOverridden()
for(const auto & b : jsonNode.Vector()) for(const auto & b : jsonNode.Vector())
{ {
auto bid = BuildingID(VLC->modh->identifiers.getIdentifier(scope, b).get()); auto bid = BuildingID(VLC->modh->identifiers.getIdentifier(scope, b).value());
bidHelper.building->overrideBids.insert(bid); bidHelper.building->overrideBids.insert(bid);
} }
} }

View File

@ -64,7 +64,7 @@ si32 HeroTypeID::decode(const std::string & identifier)
{ {
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "hero", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "hero", identifier);
if(rawId) if(rawId)
return rawId.get(); return rawId.value();
else else
return -1; return -1;
} }
@ -88,7 +88,7 @@ si32 ArtifactID::decode(const std::string & identifier)
{ {
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "artifact", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "artifact", identifier);
if(rawId) if(rawId)
return rawId.get(); return rawId.value();
else else
return -1; return -1;
} }
@ -112,7 +112,7 @@ si32 CreatureID::decode(const std::string & identifier)
{ {
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "creature", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "creature", identifier);
if(rawId) if(rawId)
return rawId.get(); return rawId.value();
else else
return -1; return -1;
} }
@ -141,7 +141,7 @@ si32 SpellID::decode(const std::string & identifier)
{ {
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "spell", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "spell", identifier);
if(rawId) if(rawId)
return rawId.get(); return rawId.value();
else else
return -1; return -1;
} }
@ -204,7 +204,7 @@ si32 FactionID::decode(const std::string & identifier)
{ {
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "faction", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "faction", identifier);
if(rawId) if(rawId)
return rawId.get(); return rawId.value();
else else
return FactionID::DEFAULT; return FactionID::DEFAULT;
} }
@ -292,7 +292,7 @@ BattleField BattleField::fromString(const std::string & identifier)
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeBuiltin(), "battlefield", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeBuiltin(), "battlefield", identifier);
if(rawId) if(rawId)
return BattleField(rawId.get()); return BattleField(rawId.value());
else else
return BattleField::NONE; return BattleField::NONE;
} }
@ -312,7 +312,7 @@ Obstacle Obstacle::fromString(const std::string & identifier)
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeBuiltin(), "obstacle", identifier); auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeBuiltin(), "obstacle", identifier);
if(rawId) if(rawId)
return Obstacle(rawId.get()); return Obstacle(rawId.value());
else else
return Obstacle(-1); return Obstacle(-1);
} }

View File

@ -1520,7 +1520,7 @@ int64_t CBonusSystemNode::getTreeVersion() const
return treeChanged; return treeChanged;
} }
std::string Bonus::Description(boost::optional<si32> customValue) const std::string Bonus::Description(std::optional<si32> customValue) const
{ {
std::ostringstream str; std::ostringstream str;

View File

@ -533,7 +533,7 @@ struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
return sid & 0x0000FFFF; return sid & 0x0000FFFF;
} }
std::string Description(boost::optional<si32> customValue = {}) const; std::string Description(std::optional<si32> customValue = {}) const;
JsonNode toJsonNode() const; JsonNode toJsonNode() const;
std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct

View File

@ -66,7 +66,7 @@ void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const
void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles, void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
const int3 & pos, const int3 & pos,
int radious, int radious,
boost::optional<PlayerColor> player, std::optional<PlayerColor> player,
int mode, int mode,
int3::EDistanceFormula distanceFormula) const int3::EDistanceFormula distanceFormula) const
{ {
@ -100,7 +100,7 @@ void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set<int3, ShashInt3
} }
} }
void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3, ShashInt3> & tiles, boost::optional<PlayerColor> Player, int level, MapTerrainFilterMode tileFilterMode) const void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3, ShashInt3> & tiles, std::optional<PlayerColor> Player, int level, MapTerrainFilterMode tileFilterMode) const
{ {
if(!!Player && *Player >= PlayerColor::PLAYER_LIMIT) if(!!Player && *Player >= PlayerColor::PLAYER_LIMIT)
{ {

View File

@ -62,12 +62,12 @@ public:
void getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles, void getTilesInRange(std::unordered_set<int3, ShashInt3> & tiles,
const int3 & pos, const int3 & pos,
int radious, int radious,
boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), std::optional<PlayerColor> player = std::optional<PlayerColor>(),
int mode = 0, int mode = 0,
int3::EDistanceFormula formula = int3::DIST_2D) const; int3::EDistanceFormula formula = int3::DIST_2D) const;
//returns all tiles on given level (-1 - both levels, otherwise number of level) //returns all tiles on given level (-1 - both levels, otherwise number of level)
void getAllTiles(std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), void getAllTiles(std::unordered_set<int3, ShashInt3> &tiles, std::optional<PlayerColor> player = std::optional<PlayerColor>(),
int level = -1, MapTerrainFilterMode tileFilterMode = MapTerrainFilterMode::NONE) const; int level = -1, MapTerrainFilterMode tileFilterMode = MapTerrainFilterMode::NONE) const;
//gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant

View File

@ -21,7 +21,7 @@ namespace LogicalExpressionDetail
class ExpressionBase class ExpressionBase
{ {
public: public:
/// Possible logical operations, mostly needed to create different types for boost::variant /// Possible logical operations, mostly needed to create different types for std::variant
enum EOperations enum EOperations
{ {
ANY_OF, ANY_OF,
@ -37,7 +37,7 @@ namespace LogicalExpressionDetail
typedef ContainedClass Value; typedef ContainedClass Value;
/// Variant that contains all possible elements from logical expression /// Variant that contains all possible elements from logical expression
typedef boost::variant< typedef std::variant<
OperatorAll, OperatorAll,
OperatorAny, OperatorAny,
OperatorNone, OperatorNone,
@ -71,7 +71,7 @@ namespace LogicalExpressionDetail
/// Visitor to test result (true/false) of the expression /// Visitor to test result (true/false) of the expression
template<typename ContainedClass> template<typename ContainedClass>
class TestVisitor : public boost::static_visitor<bool> class TestVisitor
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
@ -81,7 +81,7 @@ namespace LogicalExpressionDetail
{ {
return boost::range::count_if(element, [&](const typename Base::Variant & expr) return boost::range::count_if(element, [&](const typename Base::Variant & expr)
{ {
return boost::apply_visitor(*this, expr); return std::visit(*this, expr);
}); });
} }
public: public:
@ -117,7 +117,7 @@ namespace LogicalExpressionDetail
class FalsifiabilityVisitor; class FalsifiabilityVisitor;
template<typename ContainedClass> template<typename ContainedClass>
class PossibilityVisitor : public boost::static_visitor<bool> class PossibilityVisitor
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
@ -131,7 +131,7 @@ namespace LogicalExpressionDetail
{ {
return boost::range::count_if(element, [&](const typename Base::Variant & expr) return boost::range::count_if(element, [&](const typename Base::Variant & expr)
{ {
return boost::apply_visitor(*satisfiabilityVisitor, expr); return std::visit(*satisfiabilityVisitor, expr);
}); });
} }
@ -139,7 +139,7 @@ namespace LogicalExpressionDetail
{ {
return boost::range::count_if(element, [&](const typename Base::Variant & expr) return boost::range::count_if(element, [&](const typename Base::Variant & expr)
{ {
return boost::apply_visitor(*falsifiabilityVisitor, expr); return std::visit(*falsifiabilityVisitor, expr);
}); });
} }
@ -236,7 +236,7 @@ namespace LogicalExpressionDetail
/// visitor that is trying to generates candidates that must be fulfilled /// visitor that is trying to generates candidates that must be fulfilled
/// to complete this expression /// to complete this expression
template<typename ContainedClass> template<typename ContainedClass>
class CandidatesVisitor : public boost::static_visitor<std::vector<ContainedClass> > class CandidatesVisitor
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
typedef std::vector<typename Base::Value> TValueList; typedef std::vector<typename Base::Value> TValueList;
@ -254,7 +254,7 @@ namespace LogicalExpressionDetail
if (!classTest(element)) if (!classTest(element))
{ {
for (auto & elem : element.expressions) for (auto & elem : element.expressions)
boost::range::copy(boost::apply_visitor(*this, elem), std::back_inserter(ret)); boost::range::copy(std::visit(*this, elem), std::back_inserter(ret));
} }
return ret; return ret;
} }
@ -265,7 +265,7 @@ namespace LogicalExpressionDetail
if (!classTest(element)) if (!classTest(element))
{ {
for (auto & elem : element.expressions) for (auto & elem : element.expressions)
boost::range::copy(boost::apply_visitor(*this, elem), std::back_inserter(ret)); boost::range::copy(std::visit(*this, elem), std::back_inserter(ret));
} }
return ret; return ret;
} }
@ -286,7 +286,7 @@ namespace LogicalExpressionDetail
/// Simple foreach visitor /// Simple foreach visitor
template<typename ContainedClass> template<typename ContainedClass>
class ForEachVisitor : public boost::static_visitor<typename ExpressionBase<ContainedClass>::Variant> class ForEachVisitor
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
@ -306,14 +306,14 @@ namespace LogicalExpressionDetail
typename Base::Variant operator()(Type element) const typename Base::Variant operator()(Type element) const
{ {
for (auto & entry : element.expressions) for (auto & entry : element.expressions)
entry = boost::apply_visitor(*this, entry); entry = std::visit(*this, entry);
return element; return element;
} }
}; };
/// Minimizing visitor that removes all redundant elements from variant (e.g. AllOf inside another AllOf can be merged safely) /// Minimizing visitor that removes all redundant elements from variant (e.g. AllOf inside another AllOf can be merged safely)
template<typename ContainedClass> template<typename ContainedClass>
class MinimizingVisitor : public boost::static_visitor<typename ExpressionBase<ContainedClass>::Variant> class MinimizingVisitor
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
@ -330,15 +330,15 @@ namespace LogicalExpressionDetail
for (auto & entryRO : element.expressions) for (auto & entryRO : element.expressions)
{ {
auto entry = boost::apply_visitor(*this, entryRO); auto entry = std::visit(*this, entryRO);
try try
{ {
// copy entries from child of this type // copy entries from child of this type
auto sublist = boost::get<Type>(entry).expressions; auto sublist = std::get<Type>(entry).expressions;
std::move(sublist.begin(), sublist.end(), std::back_inserter(ret.expressions)); std::move(sublist.begin(), sublist.end(), std::back_inserter(ret.expressions));
} }
catch (boost::bad_get &) catch (std::bad_variant_access &)
{ {
// different type (e.g. allOf vs oneOf) just copy // different type (e.g. allOf vs oneOf) just copy
ret.expressions.push_back(entry); ret.expressions.push_back(entry);
@ -398,7 +398,7 @@ namespace LogicalExpressionDetail
/// Serializes expression in JSON format. Part of map format. /// Serializes expression in JSON format. Part of map format.
template<typename ContainedClass> template<typename ContainedClass>
class Writer : public boost::static_visitor<JsonNode> class Writer
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
@ -410,7 +410,7 @@ namespace LogicalExpressionDetail
ret.Vector().resize(1); ret.Vector().resize(1);
ret.Vector().back().String() = name; ret.Vector().back().String() = name;
for (auto & expr : element) for (auto & expr : element)
ret.Vector().push_back(boost::apply_visitor(*this, expr)); ret.Vector().push_back(std::visit(*this, expr));
return ret; return ret;
} }
public: public:
@ -443,7 +443,7 @@ namespace LogicalExpressionDetail
/// Prints expression in human-readable format /// Prints expression in human-readable format
template<typename ContainedClass> template<typename ContainedClass>
class Printer : public boost::static_visitor<std::string> class Printer
{ {
typedef ExpressionBase<ContainedClass> Base; typedef ExpressionBase<ContainedClass> Base;
@ -465,7 +465,7 @@ namespace LogicalExpressionDetail
std::string ret; std::string ret;
prefix.push_back('\t'); prefix.push_back('\t');
for (auto & expr : element) for (auto & expr : element)
ret += prefix + boost::apply_visitor(*this, expr) + "\n"; ret += prefix + std::visit(*this, expr) + "\n";
prefix.pop_back(); prefix.pop_back();
return ret; return ret;
} }
@ -552,14 +552,14 @@ public:
Variant morph(std::function<Variant(const Value &)> morpher) const Variant morph(std::function<Variant(const Value &)> morpher) const
{ {
LogicalExpressionDetail::ForEachVisitor<Value> visitor(morpher); LogicalExpressionDetail::ForEachVisitor<Value> visitor(morpher);
return boost::apply_visitor(visitor, data); return std::visit(visitor, data);
} }
/// Minimizes expression, removing any redundant elements /// Minimizes expression, removing any redundant elements
void minimize() void minimize()
{ {
LogicalExpressionDetail::MinimizingVisitor<Value> visitor; LogicalExpressionDetail::MinimizingVisitor<Value> visitor;
data = boost::apply_visitor(visitor, data); data = std::visit(visitor, data);
} }
/// calculates if expression evaluates to "true". /// calculates if expression evaluates to "true".
@ -567,7 +567,7 @@ public:
bool test(std::function<bool(const Value &)> toBool) const bool test(std::function<bool(const Value &)> toBool) const
{ {
LogicalExpressionDetail::TestVisitor<Value> testVisitor(toBool); LogicalExpressionDetail::TestVisitor<Value> testVisitor(toBool);
return boost::apply_visitor(testVisitor, data); return std::visit(testVisitor, data);
} }
/// calculates if expression can evaluate to "true". /// calculates if expression can evaluate to "true".
@ -579,7 +579,7 @@ public:
satisfiabilityVisitor.setFalsifiabilityVisitor(&falsifiabilityVisitor); satisfiabilityVisitor.setFalsifiabilityVisitor(&falsifiabilityVisitor);
falsifiabilityVisitor.setSatisfiabilityVisitor(&satisfiabilityVisitor); falsifiabilityVisitor.setSatisfiabilityVisitor(&satisfiabilityVisitor);
return boost::apply_visitor(satisfiabilityVisitor, data); return std::visit(satisfiabilityVisitor, data);
} }
/// calculates if expression can evaluate to "false". /// calculates if expression can evaluate to "false".
@ -591,14 +591,14 @@ public:
satisfiabilityVisitor.setFalsifiabilityVisitor(&falsifiabilityVisitor); satisfiabilityVisitor.setFalsifiabilityVisitor(&falsifiabilityVisitor);
falsifiabilityVisitor.setFalsifiabilityVisitor(&satisfiabilityVisitor); falsifiabilityVisitor.setFalsifiabilityVisitor(&satisfiabilityVisitor);
return boost::apply_visitor(falsifiabilityVisitor, data); return std::visit(falsifiabilityVisitor, data);
} }
/// generates list of candidates that can be fulfilled by caller (like AI) /// generates list of candidates that can be fulfilled by caller (like AI)
std::vector<Value> getFulfillmentCandidates(std::function<bool(const Value &)> toBool) const std::vector<Value> getFulfillmentCandidates(std::function<bool(const Value &)> toBool) const
{ {
LogicalExpressionDetail::CandidatesVisitor<Value> candidateVisitor(toBool); LogicalExpressionDetail::CandidatesVisitor<Value> candidateVisitor(toBool);
return boost::apply_visitor(candidateVisitor, data); return std::visit(candidateVisitor, data);
} }
/// Converts expression in human-readable form /// Converts expression in human-readable form
@ -607,18 +607,18 @@ public:
std::string toString(std::function<std::string(const Value &)> toStr) const std::string toString(std::function<std::string(const Value &)> toStr) const
{ {
LogicalExpressionDetail::Printer<Value> printVisitor(toStr); LogicalExpressionDetail::Printer<Value> printVisitor(toStr);
return boost::apply_visitor(printVisitor, data); return std::visit(printVisitor, data);
} }
std::string toString(std::function<std::string(const Value &)> toStr, std::function<bool(const Value &)> toBool) const std::string toString(std::function<std::string(const Value &)> toStr, std::function<bool(const Value &)> toBool) const
{ {
LogicalExpressionDetail::Printer<Value> printVisitor(toStr, toBool); LogicalExpressionDetail::Printer<Value> printVisitor(toStr, toBool);
return boost::apply_visitor(printVisitor, data); return std::visit(printVisitor, data);
} }
JsonNode toJson(std::function<JsonNode(const Value &)> toJson) const JsonNode toJson(std::function<JsonNode(const Value &)> toJson) const
{ {
LogicalExpressionDetail::Writer<Value> writeVisitor(toJson); LogicalExpressionDetail::Writer<Value> writeVisitor(toJson);
return boost::apply_visitor(writeVisitor, data); return std::visit(writeVisitor, data);
} }
template <typename Handler> template <typename Handler>

View File

@ -145,7 +145,7 @@ struct DLL_LINKAGE YourTurn : public CPackForClient
void applyGs(CGameState * gs) const; void applyGs(CGameState * gs) const;
PlayerColor player; PlayerColor player;
boost::optional<ui8> daysWithoutCastle; std::optional<ui8> daysWithoutCastle;
virtual void visitTyped(ICPackVisitor & visitor) override; virtual void visitTyped(ICPackVisitor & visitor) override;
@ -591,7 +591,7 @@ struct DLL_LINKAGE TryMoveHero : public CPackForClient
EResult result = FAILED; //uses EResult EResult result = FAILED; //uses EResult
int3 start, end; //h3m format int3 start, end; //h3m format
std::unordered_set<int3, ShashInt3> fowRevealed; //revealed tiles std::unordered_set<int3, ShashInt3> fowRevealed; //revealed tiles
boost::optional<int3> attackedFrom; // Set when stepping into endangered tile. std::optional<int3> attackedFrom; // Set when stepping into endangered tile.
virtual void visitTyped(ICPackVisitor & visitor) override; virtual void visitTyped(ICPackVisitor & visitor) override;
@ -930,17 +930,17 @@ struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
} }
}; };
struct GetEngagedHeroIds : boost::static_visitor<boost::optional<ObjectInstanceID>> struct GetEngagedHeroIds
{ {
boost::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CGHeroInstance> & h) const std::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CGHeroInstance> & h) const
{ {
return h->id; return h->id;
} }
boost::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CStackInstance> & s) const std::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CStackInstance> & s) const
{ {
if(s->armyObj && s->armyObj->ID == Obj::HERO) if(s->armyObj && s->armyObj->ID == Obj::HERO)
return s->armyObj->id; return s->armyObj->id;
return boost::optional<ObjectInstanceID>(); return std::optional<ObjectInstanceID>();
} }
}; };

View File

@ -233,7 +233,7 @@ struct Component
} }
}; };
using TArtHolder = boost::variant<ConstTransitivePtr<CGHeroInstance>, ConstTransitivePtr<CStackInstance>>; using TArtHolder = std::variant<ConstTransitivePtr<CGHeroInstance>, ConstTransitivePtr<CStackInstance>>;
struct ArtifactLocation struct ArtifactLocation
{ {
@ -259,9 +259,9 @@ struct ArtifactLocation
template <typename T> template <typename T>
bool isHolder(const T *t) const bool isHolder(const T *t) const
{ {
if(auto ptrToT = boost::get<ConstTransitivePtr<T> >(&artHolder)) if(auto ptrToT = std::get<ConstTransitivePtr<T>>(artHolder))
{ {
return ptrToT->get() == t; return ptrToT == t;
} }
return false; return false;
} }

View File

@ -1535,7 +1535,7 @@ const CStackInstance * StackLocation::getStack()
return &army->getStack(slot); return &army->getStack(slot);
} }
struct ObjectRetriever : boost::static_visitor<const CArmedInstance *> struct ObjectRetriever
{ {
const CArmedInstance * operator()(const ConstTransitivePtr<CGHeroInstance> &h) const const CArmedInstance * operator()(const ConstTransitivePtr<CGHeroInstance> &h) const
{ {
@ -1547,7 +1547,7 @@ struct ObjectRetriever : boost::static_visitor<const CArmedInstance *>
} }
}; };
template<typename T> template<typename T>
struct GetBase : boost::static_visitor<T*> struct GetBase
{ {
template <typename TArg> template <typename TArg>
T * operator()(TArg &arg) const T * operator()(TArg &arg) const
@ -1566,7 +1566,7 @@ void ArtifactLocation::removeArtifact()
const CArmedInstance * ArtifactLocation::relatedObj() const const CArmedInstance * ArtifactLocation::relatedObj() const
{ {
return boost::apply_visitor(ObjectRetriever(), artHolder); return std::visit(ObjectRetriever(), artHolder);
} }
PlayerColor ArtifactLocation::owningPlayer() const PlayerColor ArtifactLocation::owningPlayer() const
@ -1577,12 +1577,12 @@ PlayerColor ArtifactLocation::owningPlayer() const
CArtifactSet *ArtifactLocation::getHolderArtSet() CArtifactSet *ArtifactLocation::getHolderArtSet()
{ {
return boost::apply_visitor(GetBase<CArtifactSet>(), artHolder); return std::visit(GetBase<CArtifactSet>(), artHolder);
} }
CBonusSystemNode *ArtifactLocation::getHolderNode() CBonusSystemNode *ArtifactLocation::getHolderNode()
{ {
return boost::apply_visitor(GetBase<CBonusSystemNode>(), artHolder); return std::visit(GetBase<CBonusSystemNode>(), artHolder);
} }
const CArtifactInstance *ArtifactLocation::getArt() const const CArtifactInstance *ArtifactLocation::getArt() const
@ -2053,11 +2053,11 @@ void NewTurn::applyGs(CGameState *gs)
if (playerState.daysWithoutCastle) if (playerState.daysWithoutCastle)
++(*playerState.daysWithoutCastle); ++(*playerState.daysWithoutCastle);
else else
playerState.daysWithoutCastle = boost::make_optional(0); playerState.daysWithoutCastle = std::make_optional(0);
} }
else else
{ {
playerState.daysWithoutCastle = boost::none; playerState.daysWithoutCastle = std::nullopt;
} }
} }
} }
@ -2088,7 +2088,7 @@ void SetObjectProperty::applyGs(CGameState * gs) const
//reset counter before NewTurn to avoid no town message if game loaded at turn when one already captured //reset counter before NewTurn to avoid no town message if game loaded at turn when one already captured
if(p->daysWithoutCastle) if(p->daysWithoutCastle)
p->daysWithoutCastle = boost::none; p->daysWithoutCastle = std::nullopt;
} }
} }
@ -2536,12 +2536,12 @@ const CArtifactInstance * ArtSlotInfo::getArt() const
CArtifactSet * BulkMoveArtifacts::getSrcHolderArtSet() CArtifactSet * BulkMoveArtifacts::getSrcHolderArtSet()
{ {
return boost::apply_visitor(GetBase<CArtifactSet>(), srcArtHolder); return std::visit(GetBase<CArtifactSet>(), srcArtHolder);
} }
CArtifactSet * BulkMoveArtifacts::getDstHolderArtSet() CArtifactSet * BulkMoveArtifacts::getDstHolderArtSet()
{ {
return boost::apply_visitor(GetBase<CArtifactSet>(), dstArtHolder); return std::visit(GetBase<CArtifactSet>(), dstArtHolder);
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -29,7 +29,7 @@ namespace GameConstants
const int BFIELD_SIZE = BFIELD_WIDTH * BFIELD_HEIGHT; const int BFIELD_SIZE = BFIELD_WIDTH * BFIELD_HEIGHT;
} }
using BattleSideOpt = boost::optional<ui8>; using BattleSideOpt = std::optional<ui8>;
// for battle stacks' positions // for battle stacks' positions
struct DLL_LINKAGE BattleHex //TODO: decide if this should be changed to class for better code design struct DLL_LINKAGE BattleHex //TODO: decide if this should be changed to class for better code design

View File

@ -106,7 +106,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(con
const auto side = playerToSide(player); const auto side = playerToSide(player);
if(!side) if(!side)
return ESpellCastProblem::INVALID; return ESpellCastProblem::INVALID;
if(!battleDoWeKnowAbout(side.get())) if(!battleDoWeKnowAbout(side.value()))
{ {
logGlobal->warn("You can't check if enemy can cast given spell!"); logGlobal->warn("You can't check if enemy can cast given spell!");
return ESpellCastProblem::INVALID; return ESpellCastProblem::INVALID;
@ -119,7 +119,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(con
{ {
case spells::Mode::HERO: case spells::Mode::HERO:
{ {
if(battleCastSpells(side.get()) > 0) if(battleCastSpells(side.value()) > 0)
return ESpellCastProblem::CASTS_PER_TURN_LIMIT; return ESpellCastProblem::CASTS_PER_TURN_LIMIT;
const auto * hero = dynamic_cast<const CGHeroInstance *>(caster); const auto * hero = dynamic_cast<const CGHeroInstance *>(caster);
@ -229,7 +229,7 @@ std::vector<PossiblePlayerBattleAction> CBattleInfoCallback::getClientActionsFor
{ {
if(stack->hasBonusOfType(Bonus::SPELLCASTER)) if(stack->hasBonusOfType(Bonus::SPELLCASTER))
{ {
for (auto const & spellID : data.creatureSpellsToCast) for(const auto & spellID : data.creatureSpellsToCast)
{ {
const CSpell *spell = spellID.toSpell(); const CSpell *spell = spellID.toSpell();
PossiblePlayerBattleAction act = getCasterAction(spell, stack, spells::Mode::CREATURE_ACTIVE); PossiblePlayerBattleAction act = getCasterAction(spell, stack, spells::Mode::CREATURE_ACTIVE);
@ -767,7 +767,7 @@ DamageEstimation CBattleInfoCallback::battleEstimateDamage(const BattleAttackInf
//TODO: rewrite using boost::numeric::interval //TODO: rewrite using boost::numeric::interval
//TODO: rewire once more using interval-based fuzzy arithmetic //TODO: rewire once more using interval-based fuzzy arithmetic
auto const & estimateRetaliation = [&]( int64_t damage) const auto & estimateRetaliation = [&](int64_t damage)
{ {
auto retaliationAttack = bai.reverse(); auto retaliationAttack = bai.reverse();
auto state = retaliationAttack.attacker->acquireState(); auto state = retaliationAttack.attacker->acquireState();
@ -1763,7 +1763,7 @@ int CBattleInfoCallback::battleGetSurrenderCost(const PlayerColor & Player) cons
const auto sideOpt = playerToSide(Player); const auto sideOpt = playerToSide(Player);
if(!sideOpt) if(!sideOpt)
return -1; return -1;
const auto side = sideOpt.get(); const auto side = sideOpt.value();
int ret = 0; int ret = 0;
double discount = 0; double discount = 0;
@ -1816,7 +1816,7 @@ si8 CBattleInfoCallback::battleMaxSpellLevel(ui8 side) const
return GameConstants::SPELL_LEVELS; return GameConstants::SPELL_LEVELS;
} }
boost::optional<int> CBattleInfoCallback::battleIsFinished() const std::optional<int> CBattleInfoCallback::battleIsFinished() const
{ {
auto units = battleGetUnitsIf([=](const battle::Unit * unit) auto units = battleGetUnitsIf([=](const battle::Unit * unit)
{ {
@ -1831,7 +1831,7 @@ boost::optional<int> CBattleInfoCallback::battleIsFinished() const
hasUnit.at(unit->unitSide()) = true; hasUnit.at(unit->unitSide()) = true;
if(hasUnit[0] && hasUnit[1]) if(hasUnit[0] && hasUnit[1])
return boost::none; return std::nullopt;
} }
hasUnit = {false, false}; hasUnit = {false, false};

View File

@ -58,7 +58,7 @@ public:
RANDOM_GENIE, RANDOM_AIMED RANDOM_GENIE, RANDOM_AIMED
}; };
boost::optional<int> battleIsFinished() const override; //return none if battle is ongoing; otherwise the victorious side (0/1) or 2 if it is a draw std::optional<int> battleIsFinished() const override; //return none if battle is ongoing; otherwise the victorious side (0/1) or 2 if it is a draw
std::vector<std::shared_ptr<const CObstacleInstance>> battleGetAllObstaclesOnPos(BattleHex tile, bool onlyBlocking = true) const override; std::vector<std::shared_ptr<const CObstacleInstance>> battleGetAllObstaclesOnPos(BattleHex tile, bool onlyBlocking = true) const override;
std::vector<std::shared_ptr<const CObstacleInstance>> getAllAffectedObstaclesByStack(const battle::Unit * unit, const std::set<BattleHex> & passed) const override; std::vector<std::shared_ptr<const CObstacleInstance>> getAllAffectedObstaclesByStack(const battle::Unit * unit, const std::set<BattleHex> & passed) const override;

Some files were not shown because too many files have changed in this diff Show More