Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 1, 2020
1 parent 79410ea commit 11d75a2
Show file tree
Hide file tree
Showing 42 changed files with 158 additions and 145 deletions.
7 changes: 4 additions & 3 deletions src/actions/attack.cpp
Expand Up @@ -50,6 +50,7 @@
#include "units/udisplay.hpp"
#include "units/unit.hpp"
#include "units/types.hpp"
#include "utils/optional_fwd.hpp"
#include "whiteboard/manager.hpp"
#include "wml_exception.hpp"

Expand Down Expand Up @@ -135,7 +136,7 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up,

// Get the weapon characteristics as appropriate.
auto ctx = weapon->specials_context(up, oppp, u_loc, opp_loc, attacking, opp_weapon);
boost::optional<decltype(ctx)> opp_ctx;
utils::optional<decltype(ctx)> opp_ctx;

if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(oppp, up, opp_loc, u_loc, !attacking, weapon));
Expand Down Expand Up @@ -297,7 +298,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,

// Get the weapon characteristics as appropriate.
auto ctx = weapon->specials_context(*u_type, map_location::null_location(), attacking);
boost::optional<decltype(ctx)> opp_ctx;
utils::optional<decltype(ctx)> opp_ctx;

if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(*opp_type, map_location::null_location(), !attacking));
Expand Down Expand Up @@ -877,7 +878,7 @@ void attack::fire_event(const std::string& n)
config& d_weapon_cfg = ev_data.add_child("second");

// Need these to ensure weapon filters work correctly
boost::optional<attack_type::specials_context_t> a_ctx, d_ctx;
utils::optional<attack_type::specials_context_t> a_ctx, d_ctx;

if(a_stats_->weapon != nullptr && a_.valid()) {
if(d_stats_->weapon != nullptr && d_.valid()) {
Expand Down
13 changes: 6 additions & 7 deletions src/editor/map/map_context.hpp
Expand Up @@ -14,18 +14,17 @@

#pragma once

#include "display_context.hpp"
#include "editor/map/editor_map.hpp"
#include "game_classification.hpp"
#include "map/label.hpp"
#include "mp_game_settings.hpp"
#include "overlay.hpp"
#include "sound_music_track.hpp"
#include "team.hpp"
#include "tod_manager.hpp"
#include "units/map.hpp"
#include "overlay.hpp"
#include "display_context.hpp"

#include <boost/optional.hpp>
#include "utils/optional_fwd.hpp"

#include <vector>
class game_config_view;
Expand Down Expand Up @@ -314,7 +313,7 @@ class map_context : public display_context

const t_string get_default_context_name() const;

boost::optional<int> get_xp_mod() const { return xp_mod_; }
utils::optional<int> get_xp_mod() const { return xp_mod_; }

bool random_start_time() const { return random_time_; }
bool victory_defeated() const { return !victory_defeated_ || *victory_defeated_; }
Expand Down Expand Up @@ -496,8 +495,8 @@ class map_context : public display_context

std::string scenario_id_, scenario_name_, scenario_description_;

boost::optional<int> xp_mod_;
boost::optional<bool> victory_defeated_;
utils::optional<int> xp_mod_;
utils::optional<bool> victory_defeated_;
bool random_time_;

int active_area_;
Expand Down
6 changes: 3 additions & 3 deletions src/font/font_description.hpp
Expand Up @@ -17,8 +17,8 @@
#include "config.hpp"
#include "lexical_cast.hpp"
#include "serialization/string_utils.hpp"
#include "utils/optional_fwd.hpp"

#include <boost/optional.hpp>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -53,8 +53,8 @@ struct subset_descriptor
}

std::string name;
boost::optional<std::string> bold_name; //If we are using another font for styled characters in this font, rather than SDL TTF method
boost::optional<std::string> italic_name;
utils::optional<std::string> bold_name; //If we are using another font for styled characters in this font, rather than SDL TTF method
utils::optional<std::string> italic_name;
};

} // end namespace font
6 changes: 3 additions & 3 deletions src/game_board.cpp
Expand Up @@ -258,8 +258,8 @@ bool game_board::try_add_unit_to_recall_list(const map_location&, const unit_ptr
return true;
}

boost::optional<std::string> game_board::replace_map(const gamemap & newmap) {
boost::optional<std::string> ret = boost::optional<std::string> ();
utils::optional<std::string> game_board::replace_map(const gamemap & newmap) {
utils::optional<std::string> ret;

/* Remember the locations where a village is owned by a side. */
std::map<map_location, int> villages;
Expand All @@ -273,7 +273,7 @@ boost::optional<std::string> game_board::replace_map(const gamemap & newmap) {
for (unit_map::iterator itor = units_.begin(); itor != units_.end(); ) {
if (!newmap.on_board(itor->get_location())) {
if (!try_add_unit_to_recall_list(itor->get_location(), itor.get_shared_ptr())) {
*ret = std::string("replace_map: Cannot add a unit that would become off-map to the recall list\n");
ret = std::string("replace_map: Cannot add a unit that would become off-map to the recall list\n");
}
units_.erase(itor++);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/game_board.hpp
Expand Up @@ -19,8 +19,8 @@
#include "terrain/type_data.hpp"
#include "units/map.hpp"
#include "units/id.hpp"
#include "utils/optional_fwd.hpp"

#include <boost/optional.hpp>
#include <set>
#include <vector>

Expand Down Expand Up @@ -160,7 +160,7 @@ class game_board : public display_context
// Manipulator from actionwml

bool try_add_unit_to_recall_list(const map_location& loc, const unit_ptr u);
boost::optional<std::string> replace_map(const gamemap & r);
utils::optional<std::string> replace_map(const gamemap & r);

bool change_terrain(const map_location &loc, const std::string &t,
const std::string & mode, bool replace_if_failed); //used only by lua and debug commands
Expand Down
4 changes: 2 additions & 2 deletions src/game_config_manager.cpp
Expand Up @@ -131,7 +131,7 @@ bool map_includes(const preproc_map& general, const preproc_map& special)

void game_config_manager::load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG force_reload,
game_classification const*,
boost::optional<std::set<std::string>> active_addons)
utils::optional<std::set<std::string>> active_addons)
{
if (!lg::info().dont_log(log_config)) {
auto out = formatter();
Expand All @@ -150,7 +150,7 @@ void game_config_manager::load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG f
}
out << "\n";
FORCE_LOG_TO(lg::info(), log_config) << out.str();
}
}


game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
Expand Down
11 changes: 5 additions & 6 deletions src/game_config_manager.hpp
Expand Up @@ -14,14 +14,13 @@

#pragma once

#include <boost/optional.hpp>

#include "commandline_options.hpp"
#include "config.hpp"
#include "config_cache.hpp"
#include "filesystem.hpp"
#include "terrain/type_data.hpp"
#include "config.hpp"
#include "game_config_view.hpp"
#include "terrain/type_data.hpp"
#include "utils/optional_fwd.hpp"

class game_classification;
class game_config_manager
Expand Down Expand Up @@ -63,7 +62,7 @@ class game_config_manager
void load_game_config(bool reload_everything);

void load_game_config_with_loadscreen(FORCE_RELOAD_CONFIG force_reload,
game_classification const* classification = nullptr, boost::optional<std::set<std::string>> active_addons = boost::optional<std::set<std::string>>());
game_classification const* classification = nullptr, utils::optional<std::set<std::string>> active_addons = utils::nullopt);

// load_game_config() helper functions.
void load_addons_cfg();
Expand All @@ -77,7 +76,7 @@ class game_config_manager
game_config_view game_config_view_;

std::map<std::string, config> addon_cfgs_;
boost::optional<std::set<std::string>> active_addons_;
utils::optional<std::set<std::string>> active_addons_;

preproc_map old_defines_map_;

Expand Down
2 changes: 1 addition & 1 deletion src/game_events/action_wml.cpp
Expand Up @@ -627,7 +627,7 @@ WML_HANDLER_FUNCTION(replace_map,, cfg)
}
}

boost::optional<std::string> errmsg = resources::gameboard->replace_map(map);
utils::optional<std::string> errmsg = resources::gameboard->replace_map(map);

if (errmsg) {
lg::wml_error() << *errmsg << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/game_state.cpp
Expand Up @@ -273,7 +273,7 @@ void game_state::write(config& cfg) const
// Preserve the undo stack so that fog/shroud clearing is kept accurate.
undo_stack_->write(cfg.add_child("undo_stack"));

if(end_level_data_.get_ptr() != nullptr) {
if(end_level_data_) {
end_level_data_->write(cfg.add_child("end_level_data"));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_state.hpp
Expand Up @@ -59,7 +59,7 @@ class game_state : public filter_context
/// True if healing should be done at the beginning of the next side turn
bool do_healing_;

boost::optional<end_level_data> end_level_data_;
utils::optional<end_level_data> end_level_data_;
bool init_side_done_;
bool start_event_fired_;
// used to sync with the mpserver
Expand Down
8 changes: 4 additions & 4 deletions src/generators/cave_map_generator.cpp
Expand Up @@ -69,19 +69,19 @@ std::size_t cave_map_generator::cave_map_generator_job::translate_y(std::size_t
return y;
}

std::string cave_map_generator::create_map(boost::optional<uint32_t> randomseed)
std::string cave_map_generator::create_map(utils::optional<uint32_t> randomseed)
{
const config res = create_scenario(randomseed);
return res["map_data"];
}

config cave_map_generator::create_scenario(boost::optional<uint32_t> randomseed)
config cave_map_generator::create_scenario(utils::optional<uint32_t> randomseed)
{
cave_map_generator_job job(*this, randomseed);
return job.res_;
}

cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, boost::optional<uint32_t> randomseed)
cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_map_generator& pparams, utils::optional<uint32_t> randomseed)
: params(pparams)
, flipx_(false)
, flipy_(false)
Expand All @@ -101,7 +101,7 @@ cave_map_generator::cave_map_generator_job::cave_map_generator_job(const cave_ma
"message", "Use the Lua cave generator instead, with scenario_generation=lua and create_scenario= (see wiki for details).",
},
});
uint32_t seed = randomseed.get_ptr() ? *randomseed.get_ptr() : seed_rng::next_seed();
uint32_t seed = randomseed ? randomseed.value() : seed_rng::next_seed();
rng_.seed(seed);
LOG_NG << "creating random cave with seed: " << seed << '\n';
flipx_ = static_cast<int>(rng_() % 100) < params.flipx_chance_;
Expand Down
8 changes: 4 additions & 4 deletions src/generators/cave_map_generator.hpp
Expand Up @@ -19,9 +19,9 @@
#include "config.hpp"
#include "generators/map_generator.hpp"
#include "terrain/translation.hpp"
#include "utils/optional_fwd.hpp"

#include <set>
#include <boost/optional.hpp>
#include <random>

class cave_map_generator : public map_generator
Expand All @@ -33,13 +33,13 @@ class cave_map_generator : public map_generator

std::string config_name() const;

std::string create_map(boost::optional<uint32_t> randomseed = boost::none);
config create_scenario(boost::optional<uint32_t> randomseed = boost::none);
std::string create_map(utils::optional<uint32_t> randomseed = utils::nullopt);
config create_scenario(utils::optional<uint32_t> randomseed = utils::nullopt);

private:
struct cave_map_generator_job
{
cave_map_generator_job(const cave_map_generator& params, boost::optional<uint32_t> randomseed = boost::none);
cave_map_generator_job(const cave_map_generator& params, utils::optional<uint32_t> randomseed = utils::nullopt);

struct chamber {
chamber()
Expand Down
10 changes: 5 additions & 5 deletions src/generators/default_map_generator.cpp
Expand Up @@ -72,16 +72,16 @@ std::string default_map_generator::config_name() const
return std::string();
}

std::string default_map_generator::create_map(boost::optional<uint32_t> randomseed)
std::string default_map_generator::create_map(utils::optional<uint32_t> randomseed)
{
return generate_map(nullptr, randomseed);
}

std::string default_map_generator::generate_map(std::map<map_location,std::string>* labels, boost::optional<uint32_t> randomseed)
std::string default_map_generator::generate_map(std::map<map_location,std::string>* labels, utils::optional<uint32_t> randomseed)
{
uint32_t seed;
if(const uint32_t* pseed = randomseed.get_ptr()) {
seed = *pseed;
if(randomseed) {
seed = randomseed.value();
} else {
seed = seed_rng::next_seed();
}
Expand Down Expand Up @@ -165,7 +165,7 @@ std::string default_map_generator::generate_map(std::map<map_location,std::strin
return map;
}

config default_map_generator::create_scenario(boost::optional<uint32_t> randomseed)
config default_map_generator::create_scenario(utils::optional<uint32_t> randomseed)
{
DBG_NG << "creating scenario...\n";

Expand Down
6 changes: 3 additions & 3 deletions src/generators/default_map_generator.hpp
Expand Up @@ -49,11 +49,11 @@ class default_map_generator : public map_generator

std::string config_name() const override;

std::string create_map(boost::optional<uint32_t> randomseed) override;
config create_scenario(boost::optional<uint32_t> randomseed) override;
std::string create_map(utils::optional<uint32_t> randomseed) override;
config create_scenario(utils::optional<uint32_t> randomseed) override;

private:
std::string generate_map(std::map<map_location,std::string>* labels, boost::optional<uint32_t> randomseed);
std::string generate_map(std::map<map_location,std::string>* labels, utils::optional<uint32_t> randomseed);

config cfg_;

Expand Down
4 changes: 2 additions & 2 deletions src/generators/lua_map_generator.cpp
Expand Up @@ -58,7 +58,7 @@ void lua_map_generator::user_config()
}
}

std::string lua_map_generator::create_map(boost::optional<uint32_t> seed)
std::string lua_map_generator::create_map(utils::optional<uint32_t> seed)
{
if(create_map_.empty()) {
return map_generator::create_map(seed);
Expand All @@ -74,7 +74,7 @@ std::string lua_map_generator::create_map(boost::optional<uint32_t> seed)
}
}

config lua_map_generator::create_scenario(boost::optional<uint32_t> seed)
config lua_map_generator::create_scenario(utils::optional<uint32_t> seed)
{
if(create_scenario_.empty()) {
return map_generator::create_scenario(seed);
Expand Down
4 changes: 2 additions & 2 deletions src/generators/lua_map_generator.hpp
Expand Up @@ -34,8 +34,8 @@ class lua_map_generator : public map_generator {
std::string config_name() const override { return config_name_; }

virtual void user_config() override;
virtual std::string create_map(boost::optional<uint32_t> randomseed) override;
virtual config create_scenario(boost::optional<uint32_t> randomseed) override;
virtual std::string create_map(utils::optional<uint32_t> randomseed) override;
virtual config create_scenario(utils::optional<uint32_t> randomseed) override;

private:
std::string id_, config_name_;
Expand Down
4 changes: 2 additions & 2 deletions src/generators/map_generator.cpp
Expand Up @@ -27,13 +27,13 @@ static lg::log_domain log_mapgen("mapgen");
#define ERR_NG LOG_STREAM(err, log_mapgen)
#define LOG_NG LOG_STREAM(info, log_mapgen)

config map_generator::create_scenario(boost::optional<uint32_t> randomseed)
config map_generator::create_scenario(utils::optional<uint32_t> randomseed)
{
config res;
res["map_data"] = create_map(randomseed);
return res;
}
std::string map_generator::create_map(boost::optional<uint32_t> randomseed)
std::string map_generator::create_map(utils::optional<uint32_t> randomseed)
{
return create_scenario(randomseed)["map_data"];
}
Expand Down
6 changes: 3 additions & 3 deletions src/generators/map_generator.hpp
Expand Up @@ -20,8 +20,8 @@ class config;

#include "exceptions.hpp"
#include "map/location.hpp"
#include "utils/optional_fwd.hpp"

#include <boost/optional.hpp>
#include <cstdint>

struct mapgen_exception : public game::error
Expand Down Expand Up @@ -65,7 +65,7 @@ class map_generator
* Creates a new map and returns it.
* args may contain arguments to the map generator.
*/
virtual std::string create_map(boost::optional<uint32_t> randomseed = boost::none) = 0;
virtual std::string create_map(utils::optional<uint32_t> randomseed = utils::nullopt) = 0;

virtual config create_scenario(boost::optional<uint32_t> randomseed = boost::none);
virtual config create_scenario(utils::optional<uint32_t> randomseed = utils::nullopt);
};
2 changes: 1 addition & 1 deletion src/gui/dialogs/attack_predictions.cpp
Expand Up @@ -128,7 +128,7 @@ void attack_predictions::set_data(window& window, const combatant_data& attacker
// Set specials context (for safety, it should not have changed normally).
const_attack_ptr weapon = attacker.stats_.weapon, opp_weapon = defender.stats_.weapon;
auto ctx = weapon->specials_context(attacker.unit_, defender.unit_, attacker.unit_->get_location(), defender.unit_->get_location(), attacker.stats_.is_attacker, opp_weapon);
boost::optional<decltype(ctx)> opp_ctx;
utils::optional<decltype(ctx)> opp_ctx;

if(opp_weapon) {
opp_ctx.emplace(opp_weapon->specials_context(defender.unit_, attacker.unit_, defender.unit_->get_location(), attacker.unit_->get_location(), defender.stats_.is_attacker, weapon));
Expand Down

0 comments on commit 11d75a2

Please sign in to comment.