Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions extras/ai-battle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
#include <boost/nowide/args.hpp>
#include <boost/nowide/filesystem.hpp>
#include <boost/nowide/iostream.hpp>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
#if BOOST_VERSION >= 109000
# include <optional>
using std::optional;
#else
# include <boost/optional.hpp>
using boost::optional;
#endif

namespace bnw = boost::nowide;
namespace bfs = boost::filesystem;
Expand All @@ -28,8 +34,8 @@ int main(int argc, char** argv)
bnw::nowide_filesystem();
bnw::args _(argc, argv);

boost::optional<std::string> replay_path;
boost::optional<std::string> savegame_path;
optional<std::string> replay_path;
optional<std::string> savegame_path;
unsigned random_init = static_cast<unsigned>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
unsigned random_ai_init = random_init;

Expand Down
7 changes: 3 additions & 4 deletions libs/common/include/helpers/OptionalEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#pragma once

#include "MaxEnumValue.h"
#include <boost/none.hpp>
#include <boost/optional/bad_optional_access.hpp>
#include <limits>
#include <optional>
#include <type_traits>

namespace helpers {
Expand All @@ -26,7 +25,7 @@ class OptionalEnum
using value_type = T;

constexpr OptionalEnum() noexcept = default;
OptionalEnum(boost::none_t) noexcept {}
OptionalEnum(std::nullopt_t) noexcept {}
constexpr OptionalEnum(const T& value) noexcept : value_(static_cast<underlying_type>(value)) {}
constexpr OptionalEnum& operator=(const T& value) noexcept
{
Expand All @@ -41,7 +40,7 @@ class OptionalEnum
constexpr T value() const
{
if(!has_value())
throw boost::bad_optional_access();
throw std::bad_optional_access();
return **this;
}
constexpr T value_or(T default_value) const { return bool(*this) ? **this : default_value; }
Expand Down
29 changes: 29 additions & 0 deletions libs/common/include/helpers/optional_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <boost/test/tools/detail/print_helper.hpp>
#include <optional>
#include <ostream>

template<class CharType, class CharTrait, class T>
inline std::basic_ostream<CharType, CharTrait>& operator<<(std::basic_ostream<CharType, CharTrait>& out,
std::optional<T> const& v)
{
return out << (v ? *v : "--");
}
namespace boost::test_tools::tt_detail {
template<typename T>
struct print_log_value<std::optional<T>>
{
void operator()(std::ostream& os, std::optional<T> const& v)
{
if(v)
os << *v;
else
os << "<nullopt>";
}
};
} // namespace boost::test_tools::tt_detail
4 changes: 2 additions & 2 deletions libs/s25main/BuildingRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ helpers::EnumArray<uint16_t, BuildingType> BuildingRegister::CalcProductivities(

unsigned BuildingRegister::CalcAverageProductivity(BuildingType bldType) const
{
if(holds_alternative<boost::none_t>(BLD_WORK_DESC[bldType].producedWare))
if(holds_alternative<std::nullopt_t>(BLD_WORK_DESC[bldType].producedWare))
return 0;
unsigned productivity = 0;
const auto& buildings = GetBuildings(bldType);
Expand All @@ -177,7 +177,7 @@ unsigned short BuildingRegister::CalcAverageProductivity() const
unsigned numBlds = 0;
for(const auto bldType : helpers::enumRange<BuildingType>())
{
if(holds_alternative<boost::none_t>(BLD_WORK_DESC[bldType].producedWare))
if(holds_alternative<std::nullopt_t>(BLD_WORK_DESC[bldType].producedWare))
continue;

const auto& buildings = GetBuildings(bldType);
Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/EconomyModeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "gameTypes/JobTypes.h"
#include "gameData/GoodConsts.h"
#include "gameData/JobConsts.h"
#include <boost/optional.hpp>
#include <array>
#include <optional>

EconomyModeHandler::EconomyModeHandler(unsigned endFrame) : endFrame(endFrame), gfLastUpdated(0)
{
Expand Down Expand Up @@ -151,7 +151,7 @@ unsigned EconomyModeHandler::SumUpGood(GoodType good, const Inventory& Inventory
// Add the tools used by workers to the good totals
for(const auto j : helpers::enumRange<Job>())
{
boost::optional<GoodType> tool = JOB_CONSTS[j].tool;
std::optional<GoodType> tool = JOB_CONSTS[j].tool;
if(tool == good)
{
retVal += Inventory.people[j];
Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "lua/LuaInterfaceGame.h"
#include "network/GameClient.h"
#include "gameData/GameConsts.h"
#include <boost/optional.hpp>
#include <optional>

Game::Game(GlobalGameSettings settings, unsigned startGF, const std::vector<PlayerInfo>& players)
: Game(std::move(settings), std::make_unique<EventManager>(startGF), players)
Expand Down Expand Up @@ -113,7 +113,7 @@ void Game::CheckObjective()
return;

unsigned maxPoints = 0, maxTeamPoints = 0, totalPoints = 0, bestPlayer = 0;
boost::optional<unsigned> bestTeam;
std::optional<unsigned> bestTeam;

const auto getPlayerMask = [](unsigned playerId) { return 1u << playerId; };

Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/GameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#include "FrameCounter.h"
#include <boost/optional.hpp>
#include <optional>

class Log;
class Settings;
Expand Down Expand Up @@ -46,7 +46,7 @@ class GameManager
{
unsigned time, gf;
};
boost::optional<SkipReport> lastSkipReport;
std::optional<SkipReport> lastSkipReport;
};

GameManager& getGlobalGameManager();
Expand Down
8 changes: 4 additions & 4 deletions libs/s25main/Pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ helpers::OptionalEnum<Direction> GameWorldBase::FindHumanPath(const MapPoint sta
PathConditionHuman(*this)))
return first_dir;
else
return boost::none;
return std::nullopt;
}

/// Wegfindung für Menschen im Straßennetz
Expand Down Expand Up @@ -102,19 +102,19 @@ helpers::OptionalEnum<Direction> GameWorld::FindTradePath(const MapPoint start,
{
unsigned char owner = GetNode(dest).owner;
if(owner != 0 && !GetPlayer(player).IsAlly(owner - 1))
return boost::none;
return std::nullopt;

RTTR_Assert(GetNO(dest)->GetType() == NodalObjectType::Flag); // Goal should be the flag of a wh

if(!PathConditionHuman(*this).IsNodeOk(dest))
return boost::none;
return std::nullopt;

Direction first_dir{};
if(GetFreePathFinder().FindPath(start, dest, random_route, max_route, route, length, &first_dir,
PathConditionTrade(*this, player)))
return first_dir;
else
return boost::none;
return std::nullopt;
}

bool GameWorld::CheckTradeRoute(const MapPoint start, const std::vector<Direction>& route, unsigned pos,
Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ const std::map<GUI_ID, std::string> persistentWindows = {{CGI_CHAT, "wnd_chat"},
{CGI_MERCHANDISE_STATISTICS, "wnd_merchandise_statistics"}};

namespace validate {
boost::optional<uint16_t> checkPort(const std::string& port)
std::optional<uint16_t> checkPort(const std::string& port)
{
int32_t iPort;
if((helpers::tryFromString(port, iPort) || s25util::tryFromStringClassic(port, iPort)) && checkPort(iPort))
return static_cast<uint16_t>(iPort);
else
return boost::none;
return std::nullopt;
}
bool checkPort(int port)
{
Expand Down Expand Up @@ -309,7 +309,7 @@ void Settings::Load()
// server
// {
server.lastIP = iniServer->getValue("last_ip");
boost::optional<uint16_t> port = validate::checkPort(iniServer->getValue("local_port"));
std::optional<uint16_t> port = validate::checkPort(iniServer->getValue("local_port"));
server.localPort = port.value_or(3665);
server.ipv6 = iniServer->getBoolValue("ipv6");
// }
Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
#include "driver/VideoMode.h"
#include "s25util/ProxySettings.h"
#include "s25util/Singleton.h"
#include <boost/optional.hpp>
#include <array>
#include <cstdint>
#include <gameData/const_gui_ids.h>
#include <map>
#include <optional>
#include <string>

#undef interface

namespace validate {
boost::optional<uint16_t> checkPort(const std::string& port);
std::optional<uint16_t> checkPort(const std::string& port);
bool checkPort(int port);
} // namespace validate

Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void Timer::start()

void Timer::stop()
{
startTime = boost::none;
startTime = std::nullopt;
}

void Timer::restart()
Expand Down
4 changes: 2 additions & 2 deletions libs/s25main/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#include "Clock.h"
#include <boost/optional.hpp>
#include <optional>

/// Timer class for measuring time periods
class Timer
Expand All @@ -29,5 +29,5 @@ class Timer
bool isRunning() const { return !!startTime; }

private:
boost::optional<Clock::time_point> startTime;
std::optional<Clock::time_point> startTime;
};
14 changes: 7 additions & 7 deletions libs/s25main/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include "gameTypes/Nation.h"
#include "gameTypes/TextureColor.h"
#include "s25util/colors.h"
#include <boost/optional/optional_fwd.hpp>
#include <boost/range/adaptor/map.hpp>
#include <chrono>
#include <map>
#include <memory>
#include <optional>
#include <vector>

class ctrlBuildingIcon;
Expand Down Expand Up @@ -250,10 +250,10 @@ class Window
virtual void Msg_ScrollShow(unsigned /*ctrl_id*/, bool /*visible*/) {}
virtual void Msg_OptionGroupChange(unsigned /*ctrl_id*/, unsigned /*selection*/) {}
virtual void Msg_Timer(unsigned /*ctrl_id*/) {}
virtual void Msg_TableSelectItem(unsigned /*ctrl_id*/, const boost::optional<unsigned>& /*selection*/) {}
virtual void Msg_TableSelectItem(unsigned /*ctrl_id*/, const std::optional<unsigned>& /*selection*/) {}
virtual void Msg_TableChooseItem(unsigned /*ctrl_id*/, unsigned /*selection*/) {}
virtual void Msg_TableRightButton(unsigned /*ctrl_id*/, const boost::optional<unsigned>& /*selection*/) {}
virtual void Msg_TableLeftButton(unsigned /*ctrl_id*/, const boost::optional<unsigned>& /*selection*/) {}
virtual void Msg_TableRightButton(unsigned /*ctrl_id*/, const std::optional<unsigned>& /*selection*/) {}
virtual void Msg_TableLeftButton(unsigned /*ctrl_id*/, const std::optional<unsigned>& /*selection*/) {}

/// Callback of a message box when closed
virtual void Msg_MsgBoxResult(unsigned /*msgbox_id*/, MsgboxResult /*mbr*/) {}
Expand All @@ -271,13 +271,13 @@ class Window
virtual void Msg_Group_OptionGroupChange(unsigned /*group_id*/, unsigned /*ctrl_id*/, unsigned /*selection*/) {}
virtual void Msg_Group_Timer(unsigned /*group_id*/, unsigned /*ctrl_id*/) {}
virtual void Msg_Group_TableSelectItem(unsigned /*group_id*/, unsigned /*ctrl_id*/,
const boost::optional<unsigned>& /*selection*/)
const std::optional<unsigned>& /*selection*/)
{}
virtual void Msg_Group_TableRightButton(unsigned /*group_id*/, unsigned /*ctrl_id*/,
const boost::optional<unsigned>& /*selection*/)
const std::optional<unsigned>& /*selection*/)
{}
virtual void Msg_Group_TableLeftButton(unsigned /*group_id*/, unsigned /*ctrl_id*/,
const boost::optional<unsigned>& /*selection*/)
const std::optional<unsigned>& /*selection*/)
{}

protected:
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/addons/AddonList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ unsigned AddonList::Gui::getStatus(const Window& window)
{
const auto* cb = window.GetCtrl<ctrlComboBox>(2);
RTTR_Assert(cb);
return cb->GetSelection().get();
return *cb->GetSelection();
}
2 changes: 1 addition & 1 deletion libs/s25main/ai/AIInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AIInterface : public GameCommandFactory
AISurfaceResource GetSurfaceResource(MapPoint pt) const;
/// Calculate the surface resource value on a given spot (wood/ stones/ farmland)
/// when given a direction and lastvalue the calculation will be much faster O(n) vs O(n^2)
int CalcResourceValue(MapPoint pt, AIResource res, helpers::OptionalEnum<Direction> direction = boost::none,
int CalcResourceValue(MapPoint pt, AIResource res, helpers::OptionalEnum<Direction> direction = std::nullopt,
int lastval = 0xffff) const;
/// Calculate the resource value for a given point
int GetResourceRating(MapPoint pt, AIResource res) const;
Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/ai/aijh/AIConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ helpers::OptionalEnum<BuildingType> AIConstruction::GetSmallestAllowedMilBuildin
if(aii.CanBuildBuildingtype(bld))
return bld;
}
return boost::none;
return std::nullopt;
}

helpers::OptionalEnum<BuildingType> AIConstruction::GetBiggestAllowedMilBuilding() const
Expand All @@ -446,7 +446,7 @@ helpers::OptionalEnum<BuildingType> AIConstruction::GetBiggestAllowedMilBuilding
if(aii.CanBuildBuildingtype(bld))
return bld;
}
return boost::none;
return std::nullopt;
}

helpers::OptionalEnum<BuildingType> AIConstruction::ChooseMilitaryBuilding(const MapPoint pt)
Expand All @@ -461,7 +461,7 @@ helpers::OptionalEnum<BuildingType> AIConstruction::ChooseMilitaryBuilding(const
auto bld = GetSmallestAllowedMilBuilding();
// If we are not allowed to build a military building, return early
if(!bld)
return boost::none;
return std::nullopt;

const BuildingType biggestBld = GetBiggestAllowedMilBuilding().value();

Expand Down
6 changes: 3 additions & 3 deletions libs/s25main/ai/aijh/AIPlayerJH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ void AIPlayerJH::HandleRoadConstructionFailed(const MapPoint pt, Direction)
if(flag->GetPlayer() != playerId)
return;
// if it isnt a useless flag AND it has no current road connection then retry to build a road.
if(RemoveUnusedRoad(*flag, boost::none, true, false))
if(RemoveUnusedRoad(*flag, std::nullopt, true, false))
construction->AddConnectFlagJob(flag);
}

Expand Down Expand Up @@ -1845,7 +1845,7 @@ void AIPlayerJH::RemoveAllUnusedRoads(const MapPoint pt)
std::vector<const noFlag*> reconnectflags;
for(const noFlag* flag : flags)
{
if(RemoveUnusedRoad(*flag, boost::none, true, false))
if(RemoveUnusedRoad(*flag, std::nullopt, true, false))
reconnectflags.push_back(flag);
}
UpdateNodesAround(pt, 25);
Expand Down Expand Up @@ -1913,7 +1913,7 @@ bool AIPlayerJH::RemoveUnusedRoad(const noFlag& startFlag, helpers::OptionalEnum
{
if(allowcircle)
{
if(!IsFlagPartofCircle(startFlag, 10, startFlag, boost::none, {}))
if(!IsFlagPartofCircle(startFlag, 10, startFlag, std::nullopt, {}))
return false;
if(!firstflag)
return false;
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/buildings/nobBaseMilitary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ MapPoint nobBaseMilitary::FindAnAttackerPlace(unsigned short& ret_radius, const
// Also check if we can reach this.
// If not, still consider the other points as the flag could become reachable by then.
// TODO(Replay) Limit distance by MAX_ATTACKING_RUN_DISTANCE
if(soldierPos == flagPos || world->FindHumanPath(soldierPos, flagPos) != boost::none)
if(soldierPos == flagPos || world->FindHumanPath(soldierPos, flagPos) != std::nullopt)
{
ret_radius = 0;
return flagPos;
Expand Down
Loading
Loading