Replace all remaining usages if MAKE_ENUM.
This commit is contained in:
parent
f4e4bf6b49
commit
c4c292fa3b
132 changed files with 1153 additions and 1381 deletions
|
@ -1147,8 +1147,6 @@
|
|||
<Unit filename="../../src/utils/irdya_datetime.cpp" />
|
||||
<Unit filename="../../src/utils/irdya_datetime.hpp" />
|
||||
<Unit filename="../../src/utils/iterable_pair.hpp" />
|
||||
<Unit filename="../../src/utils/make_enum.cpp" />
|
||||
<Unit filename="../../src/utils/make_enum.hpp" />
|
||||
<Unit filename="../../src/utils/markov_generator.cpp" />
|
||||
<Unit filename="../../src/utils/markov_generator.hpp" />
|
||||
<Unit filename="../../src/utils/math.hpp" />
|
||||
|
|
|
@ -1162,7 +1162,6 @@
|
|||
<Unit filename="../../src/tests/test_image_modifications.cpp" />
|
||||
<Unit filename="../../src/tests/test_irdya_date.cpp" />
|
||||
<Unit filename="../../src/tests/test_lexical_cast.cpp" />
|
||||
<Unit filename="../../src/tests/test_make_enum.cpp" />
|
||||
<Unit filename="../../src/tests/test_map_location.cpp" />
|
||||
<Unit filename="../../src/tests/test_mp_connect.cpp" />
|
||||
<Unit filename="../../src/tests/test_recall_list.cpp" />
|
||||
|
@ -1238,8 +1237,6 @@
|
|||
<Unit filename="../../src/utils/irdya_datetime.cpp" />
|
||||
<Unit filename="../../src/utils/irdya_datetime.hpp" />
|
||||
<Unit filename="../../src/utils/iterable_pair.hpp" />
|
||||
<Unit filename="../../src/utils/make_enum.cpp" />
|
||||
<Unit filename="../../src/utils/make_enum.hpp" />
|
||||
<Unit filename="../../src/utils/markov_generator.cpp" />
|
||||
<Unit filename="../../src/utils/markov_generator.hpp" />
|
||||
<Unit filename="../../src/utils/math.hpp" />
|
||||
|
|
|
@ -1200,8 +1200,6 @@
|
|||
<Unit filename="../../src/utils/irdya_datetime.cpp" />
|
||||
<Unit filename="../../src/utils/irdya_datetime.hpp" />
|
||||
<Unit filename="../../src/utils/iterable_pair.hpp" />
|
||||
<Unit filename="../../src/utils/make_enum.cpp" />
|
||||
<Unit filename="../../src/utils/make_enum.hpp" />
|
||||
<Unit filename="../../src/utils/markov_generator.cpp" />
|
||||
<Unit filename="../../src/utils/markov_generator.hpp" />
|
||||
<Unit filename="../../src/utils/math.hpp" />
|
||||
|
|
|
@ -740,7 +740,6 @@
|
|||
91A215111CAD677400927AEA /* theme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B559998D0EC62181008DD061 /* theme.cpp */; };
|
||||
91A215121CAD677400927AEA /* time_of_day.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999870EC62181008DD061 /* time_of_day.cpp */; };
|
||||
91A215131CAD677400927AEA /* tooltips.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999830EC62181008DD061 /* tooltips.cpp */; };
|
||||
91A215141CAD677400927AEA /* make_enum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC53B04D1B23BB0E002F758F /* make_enum.cpp */; };
|
||||
91A215151CAD687A00927AEA /* video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999650EC62181008DD061 /* video.cpp */; };
|
||||
91A215211CAD689800927AEA /* wml_exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B55999430EC62181008DD061 /* wml_exception.cpp */; };
|
||||
91A215221CAD696900927AEA /* xbrz.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC2F601F1A0490FC0018C9D6 /* xbrz.cpp */; };
|
||||
|
@ -861,7 +860,6 @@
|
|||
91E3563C1CACC47F00774252 /* test_formula_function.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E3560D1CACA6CB00774252 /* test_formula_function.cpp */; };
|
||||
91E3563D1CACC47F00774252 /* test_image_modifications.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E3560E1CACA6CB00774252 /* test_image_modifications.cpp */; };
|
||||
91E3563E1CACC47F00774252 /* test_lexical_cast.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B597C4AD0FACD42E00CE81F5 /* test_lexical_cast.cpp */; };
|
||||
91E356401CACC47F00774252 /* test_make_enum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E356101CACA6CB00774252 /* test_make_enum.cpp */; };
|
||||
91E356411CACC47F00774252 /* test_map_location.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E356111CACA6CB00774252 /* test_map_location.cpp */; };
|
||||
91E356421CACC47F00774252 /* test_mp_connect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E356121CACA6CB00774252 /* test_mp_connect.cpp */; };
|
||||
91E356441CACC47F00774252 /* test_recall_list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91E356131CACA6CB00774252 /* test_recall_list.cpp */; };
|
||||
|
@ -1244,7 +1242,6 @@
|
|||
EC4E3B1D19B2D7AD0049CBD7 /* map_generator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC4E3B1A19B2D7AD0049CBD7 /* map_generator.cpp */; };
|
||||
EC4E3B2219B2D8880049CBD7 /* simulated_actions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC4E3B2119B2D8880049CBD7 /* simulated_actions.cpp */; };
|
||||
EC51DB7818F8BFA4004621D9 /* playturn_network_adapter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC51DB7618F8BFA4004621D9 /* playturn_network_adapter.cpp */; };
|
||||
EC53B04E1B23BB0E002F758F /* make_enum.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC53B04D1B23BB0E002F758F /* make_enum.cpp */; };
|
||||
EC5401851EBE0C4500AE66EE /* display.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017B1EBE0C4500AE66EE /* display.cpp */; };
|
||||
EC5401861EBE0C4500AE66EE /* editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017D1EBE0C4500AE66EE /* editor.cpp */; };
|
||||
EC5401871EBE0C4500AE66EE /* game.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC54017F1EBE0C4500AE66EE /* game.cpp */; };
|
||||
|
@ -2140,7 +2137,6 @@
|
|||
91B6218F1B76717400B00E0F /* hotkey_handler.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = hotkey_handler.hpp; sourceTree = "<group>"; };
|
||||
91B621901B76717B00B00E0F /* hotkey_handler_sp.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = hotkey_handler_sp.hpp; sourceTree = "<group>"; };
|
||||
91B621921B76718700B00E0F /* hotkey_handler_mp.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = hotkey_handler_mp.hpp; sourceTree = "<group>"; };
|
||||
91B621931B76720B00B00E0F /* make_enum.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = make_enum.hpp; sourceTree = "<group>"; };
|
||||
91B621941B76722E00B00E0F /* mp_ui_alerts.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = mp_ui_alerts.hpp; sourceTree = "<group>"; };
|
||||
91B621951B76723300B00E0F /* mt_rng.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = mt_rng.hpp; sourceTree = "<group>"; };
|
||||
91B621961B76729600B00E0F /* save_index.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = save_index.hpp; sourceTree = "<group>"; };
|
||||
|
@ -2224,7 +2220,6 @@
|
|||
91E3560C1CACA6CB00774252 /* test_filesystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_filesystem.cpp; sourceTree = "<group>"; };
|
||||
91E3560D1CACA6CB00774252 /* test_formula_function.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_formula_function.cpp; sourceTree = "<group>"; };
|
||||
91E3560E1CACA6CB00774252 /* test_image_modifications.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_image_modifications.cpp; sourceTree = "<group>"; };
|
||||
91E356101CACA6CB00774252 /* test_make_enum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_make_enum.cpp; sourceTree = "<group>"; };
|
||||
91E356111CACA6CB00774252 /* test_map_location.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_map_location.cpp; sourceTree = "<group>"; };
|
||||
91E356121CACA6CB00774252 /* test_mp_connect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_mp_connect.cpp; sourceTree = "<group>"; };
|
||||
91E356131CACA6CB00774252 /* test_recall_list.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_recall_list.cpp; sourceTree = "<group>"; };
|
||||
|
@ -2642,7 +2637,6 @@
|
|||
EC5012731E06185600C4DFC6 /* math.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = math.hpp; sourceTree = "<group>"; };
|
||||
EC51DB7618F8BFA4004621D9 /* playturn_network_adapter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = playturn_network_adapter.cpp; sourceTree = "<group>"; };
|
||||
EC51DB7718F8BFA4004621D9 /* playturn_network_adapter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = playturn_network_adapter.hpp; sourceTree = "<group>"; };
|
||||
EC53B04D1B23BB0E002F758F /* make_enum.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = make_enum.cpp; sourceTree = "<group>"; };
|
||||
EC54017B1EBE0C4500AE66EE /* display.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = display.cpp; path = preferences/display.cpp; sourceTree = "<group>"; };
|
||||
EC54017C1EBE0C4500AE66EE /* display.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = display.hpp; path = preferences/display.hpp; sourceTree = "<group>"; };
|
||||
EC54017D1EBE0C4500AE66EE /* editor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = editor.cpp; path = preferences/editor.cpp; sourceTree = "<group>"; };
|
||||
|
@ -4240,8 +4234,6 @@
|
|||
46DF5BCC1F46173700BE6D24 /* irdya_datetime.cpp */,
|
||||
46DF5BCB1F46173700BE6D24 /* irdya_datetime.hpp */,
|
||||
911F471B1CAE5A7E00F47035 /* iterable_pair.hpp */,
|
||||
EC53B04D1B23BB0E002F758F /* make_enum.cpp */,
|
||||
91B621931B76720B00B00E0F /* make_enum.hpp */,
|
||||
91FBBAD91CB6D1B700470BFE /* markov_generator.cpp */,
|
||||
91FBBADA1CB6D1B700470BFE /* markov_generator.hpp */,
|
||||
EC5012731E06185600C4DFC6 /* math.hpp */,
|
||||
|
@ -4600,7 +4592,6 @@
|
|||
91E3560E1CACA6CB00774252 /* test_image_modifications.cpp */,
|
||||
4649B879202886F000827CFB /* test_irdya_date.cpp */,
|
||||
B597C4AD0FACD42E00CE81F5 /* test_lexical_cast.cpp */,
|
||||
91E356101CACA6CB00774252 /* test_make_enum.cpp */,
|
||||
91E356111CACA6CB00774252 /* test_map_location.cpp */,
|
||||
91E356121CACA6CB00774252 /* test_mp_connect.cpp */,
|
||||
91E356131CACA6CB00774252 /* test_recall_list.cpp */,
|
||||
|
@ -5349,7 +5340,6 @@
|
|||
EC5430231A4E6024006D206C /* lua_team.cpp in Sources */,
|
||||
EC5430241A4E6024006D206C /* lua_unit_type.cpp in Sources */,
|
||||
46F92DF72174F6A400602C1C /* unit_attack.cpp in Sources */,
|
||||
EC53B04E1B23BB0E002F758F /* make_enum.cpp in Sources */,
|
||||
46F92E572174F6A400602C1C /* button.cpp in Sources */,
|
||||
46F92DF32174F6A400602C1C /* connect.cpp in Sources */,
|
||||
ECDF18201A3FE0DE00D157A6 /* manager_impl.cpp in Sources */,
|
||||
|
@ -5728,7 +5718,6 @@
|
|||
91E3563C1CACC47F00774252 /* test_formula_function.cpp in Sources */,
|
||||
91E3563D1CACC47F00774252 /* test_image_modifications.cpp in Sources */,
|
||||
91E3563E1CACC47F00774252 /* test_lexical_cast.cpp in Sources */,
|
||||
91E356401CACC47F00774252 /* test_make_enum.cpp in Sources */,
|
||||
91E356411CACC47F00774252 /* test_map_location.cpp in Sources */,
|
||||
46F92E302174F6A400602C1C /* edit_scenario.cpp in Sources */,
|
||||
46F92D8E2174F6A300602C1C /* placer.cpp in Sources */,
|
||||
|
@ -6102,7 +6091,6 @@
|
|||
91A215111CAD677400927AEA /* theme.cpp in Sources */,
|
||||
91A215121CAD677400927AEA /* time_of_day.cpp in Sources */,
|
||||
91A215131CAD677400927AEA /* tooltips.cpp in Sources */,
|
||||
91A215141CAD677400927AEA /* make_enum.cpp in Sources */,
|
||||
469853D024D3560900B0E93B /* server_info_dialog.cpp in Sources */,
|
||||
91A215151CAD687A00927AEA /* video.cpp in Sources */,
|
||||
4649B87F20288DC300827CFB /* random_synced.cpp in Sources */,
|
||||
|
|
|
@ -15,7 +15,6 @@ tests/test_formula_timespan.cpp
|
|||
tests/test_image_modifications.cpp
|
||||
tests/test_irdya_date.cpp
|
||||
tests/test_lexical_cast.cpp
|
||||
tests/test_make_enum.cpp
|
||||
tests/test_map_location.cpp
|
||||
tests/test_mp_connect.cpp
|
||||
tests/test_recall_list.cpp
|
||||
|
|
|
@ -50,7 +50,6 @@ terrain/type_data.cpp
|
|||
theme.cpp
|
||||
time_of_day.cpp
|
||||
tooltips.cpp
|
||||
utils/make_enum.cpp
|
||||
video.cpp
|
||||
widgets/button.cpp
|
||||
widgets/menu.cpp
|
||||
|
|
|
@ -52,10 +52,11 @@
|
|||
#include "units/udisplay.hpp"
|
||||
#include "units/unit.hpp"
|
||||
#include "units/types.hpp"
|
||||
#include <optional>
|
||||
#include "whiteboard/manager.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define DBG_NG LOG_STREAM(debug, log_engine)
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
|
@ -1592,7 +1593,7 @@ int under_leadership(const unit &u, const map_location& loc, const_attack_ptr we
|
|||
int combat_modifier(const unit_map& units,
|
||||
const gamemap& map,
|
||||
const map_location& loc,
|
||||
unit_type::ALIGNMENT alignment,
|
||||
unit_alignments::type alignment,
|
||||
bool is_fearless)
|
||||
{
|
||||
const tod_manager& tod_m = *resources::tod_manager;
|
||||
|
@ -1601,7 +1602,7 @@ int combat_modifier(const unit_map& units,
|
|||
}
|
||||
|
||||
int combat_modifier(const time_of_day& effective_tod,
|
||||
unit_type::ALIGNMENT alignment,
|
||||
unit_alignments::type alignment,
|
||||
bool is_fearless)
|
||||
{
|
||||
const tod_manager& tod_m = *resources::tod_manager;
|
||||
|
@ -1609,21 +1610,21 @@ int combat_modifier(const time_of_day& effective_tod,
|
|||
return generic_combat_modifier(lawful_bonus, alignment, is_fearless, tod_m.get_max_liminal_bonus());
|
||||
}
|
||||
|
||||
int generic_combat_modifier(int lawful_bonus, unit_type::ALIGNMENT alignment, bool is_fearless, int max_liminal_bonus)
|
||||
int generic_combat_modifier(int lawful_bonus, unit_alignments::type alignment, bool is_fearless, int max_liminal_bonus)
|
||||
{
|
||||
int bonus;
|
||||
|
||||
switch(alignment.v) {
|
||||
case unit_type::ALIGNMENT::LAWFUL:
|
||||
switch(alignment) {
|
||||
case unit_alignments::type::lawful:
|
||||
bonus = lawful_bonus;
|
||||
break;
|
||||
case unit_type::ALIGNMENT::NEUTRAL:
|
||||
case unit_alignments::type::neutral:
|
||||
bonus = 0;
|
||||
break;
|
||||
case unit_type::ALIGNMENT::CHAOTIC:
|
||||
case unit_alignments::type::chaotic:
|
||||
bonus = -lawful_bonus;
|
||||
break;
|
||||
case unit_type::ALIGNMENT::LIMINAL:
|
||||
case unit_alignments::type::liminal:
|
||||
bonus = std::max(0, max_liminal_bonus-std::abs(lawful_bonus));
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
#include "ai/lua/aspect_advancements.hpp"
|
||||
#include "attack_prediction.hpp"
|
||||
#include "units/alignment.hpp"
|
||||
#include "units/ptr.hpp"
|
||||
#include "units/unit_alignments.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -288,7 +288,7 @@ int under_leadership(const unit &u, const map_location& loc, const_attack_ptr we
|
|||
int combat_modifier(const unit_map& units,
|
||||
const gamemap& map,
|
||||
const map_location& loc,
|
||||
UNIT_ALIGNMENT alignment,
|
||||
unit_alignments::type alignment,
|
||||
bool is_fearless);
|
||||
|
||||
/**
|
||||
|
@ -296,14 +296,14 @@ int combat_modifier(const unit_map& units,
|
|||
* due to the current time of day.
|
||||
*/
|
||||
int combat_modifier(const time_of_day& effective_tod,
|
||||
UNIT_ALIGNMENT alignment,
|
||||
unit_alignments::type alignment,
|
||||
bool is_fearless);
|
||||
|
||||
/**
|
||||
* Returns the amount that a unit's damage should be multiplied by
|
||||
* due to a given lawful_bonus.
|
||||
*/
|
||||
int generic_combat_modifier(int lawful_bonus, UNIT_ALIGNMENT alignment, bool is_fearless, int max_liminal_bonus);
|
||||
int generic_combat_modifier(int lawful_bonus, unit_alignments::type alignment, bool is_fearless, int max_liminal_bonus);
|
||||
/**
|
||||
* Function to check if an attack will satisfy the requirements for backstab.
|
||||
* Input:
|
||||
|
|
33
src/ai/ai_target.hpp
Normal file
33
src/ai/ai_target.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct ai_target_defines
|
||||
{
|
||||
static constexpr const char* const village = "village";
|
||||
static constexpr const char* const leader = "leader";
|
||||
static constexpr const char* const xplicit = "explicit";
|
||||
static constexpr const char* const threat = "threat";
|
||||
static constexpr const char* const battle_aid = "battle aid";
|
||||
static constexpr const char* const mass = "mass";
|
||||
static constexpr const char* const support = "support";
|
||||
|
||||
ENUM_AND_ARRAY(village, leader, xplicit, threat, battle_aid, mass, support)
|
||||
};
|
||||
using ai_target = string_enums::enum_base<ai_target_defines>;
|
|
@ -138,7 +138,7 @@ void target_unit_goal::add_targets(std::back_insert_iterator< std::vector< targe
|
|||
for (const unit &u : resources::gameboard->units()) {
|
||||
if (ufilt( u )) {
|
||||
LOG_AI_GOAL << "found explicit target unit at ... " << u.get_location() << " with value: " << value() << "\n";
|
||||
*target_list = target(u.get_location(), value(), target::TYPE::EXPLICIT);
|
||||
*target_list = target(u.get_location(), value(), ai_target::type::xplicit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ void target_location_goal::add_targets(std::back_insert_iterator< std::vector< t
|
|||
for (const map_location &loc : items)
|
||||
{
|
||||
LOG_AI_GOAL << "found explicit target location ... " << loc << " with value: " << value() << std::endl;
|
||||
*target_list = target(loc, value(), target::TYPE::EXPLICIT);
|
||||
*target_list = target(loc, value(), ai_target::type::xplicit);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ void protect_goal::add_targets(std::back_insert_iterator< std::vector< target >>
|
|||
DBG_AI_GOAL << "side " << get_side() << ": in " << goal_type << ": found threat target. " << u.get_location() << " is a threat to "<< loc << '\n';
|
||||
*target_list = target(u.get_location(),
|
||||
value_ * static_cast<double>(radius_ - distance) /
|
||||
radius_, target::TYPE::THREAT);
|
||||
radius_, ai_target::type::threat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,17 +313,13 @@ void lua_goal::add_targets(std::back_insert_iterator< std::vector< target >> tar
|
|||
config c(cfg_.child_or_empty("args"));
|
||||
const config empty_cfg;
|
||||
handler_->handle(c, empty_cfg, true, l_obj);
|
||||
try {
|
||||
std::vector < target > targets = *(l_obj->get());
|
||||
|
||||
for (target tg : targets)
|
||||
{
|
||||
*target_list = tg;
|
||||
}
|
||||
} catch(const bad_enum_cast& e) {
|
||||
ERR_AI_GOAL << "A Lua goal returned a target of an unknown type (\"" << e.value() << "\"; unfortunately, the engine cannot recover from this error. As a result, all targets returned by the goal have been lost.\n";
|
||||
std::vector < target > targets = *(l_obj->get());
|
||||
|
||||
for (target tg : targets)
|
||||
{
|
||||
*target_list = tg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This is defined in the source file so that it can easily access the logger
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "time_of_day.hpp" // for time_of_day
|
||||
#include "tod_manager.hpp" // for tod_manager
|
||||
#include "units/unit.hpp" // for unit
|
||||
#include "units/unit_alignments.hpp"
|
||||
#include "units/map.hpp" // for unit_map::iterator_base, etc
|
||||
#include "units/ptr.hpp" // for unit_ptr
|
||||
#include "units/types.hpp" // for attack_type, unit_type, etc
|
||||
|
@ -1031,11 +1032,11 @@ double readonly_context_impl::power_projection(const map_location& loc, const mo
|
|||
// Considering the unit location would be too slow, we only apply the bonus granted by the global ToD
|
||||
const int lawful_bonus = resources::tod_manager->get_time_of_day(attack_turn).lawful_bonus;
|
||||
int tod_modifier = 0;
|
||||
if(un.alignment() == unit_type::ALIGNMENT::LAWFUL) {
|
||||
if(un.alignment() == unit_alignments::type::lawful) {
|
||||
tod_modifier = lawful_bonus;
|
||||
} else if(un.alignment() == unit_type::ALIGNMENT::CHAOTIC) {
|
||||
} else if(un.alignment() == unit_alignments::type::chaotic) {
|
||||
tod_modifier = -lawful_bonus;
|
||||
} else if(un.alignment() == unit_type::ALIGNMENT::LIMINAL) {
|
||||
} else if(un.alignment() == unit_alignments::type::liminal) {
|
||||
tod_modifier = -(std::abs(lawful_bonus));
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ double move_to_targets_phase::rate_target(const target& tg, const unit_map::iter
|
|||
|
||||
//for 'support' targets, they are rated much higher if we can get there within two turns,
|
||||
//otherwise they are worthless to go for at all.
|
||||
if(tg.type == target::TYPE::SUPPORT) {
|
||||
if(tg.type == ai_target::type::support) {
|
||||
if (move_cost <= u->movement_left() * 2) {
|
||||
rating *= 10.0;
|
||||
} else {
|
||||
|
@ -235,7 +235,7 @@ double move_to_targets_phase::rate_target(const target& tg, const unit_map::iter
|
|||
//scouts do not like encountering enemies on their paths
|
||||
if (u->usage() == "scout") {
|
||||
//scouts get a bonus for going after villages
|
||||
if(tg.type == target::TYPE::VILLAGE) {
|
||||
if(tg.type == ai_target::type::village) {
|
||||
rating *= get_scout_village_targeting();
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ std::pair<map_location,map_location> move_to_targets_phase::choose_move(std::vec
|
|||
//if our target is a position to support, then we
|
||||
//see if we can move to a position in support of this target
|
||||
const move_map& srcdst = get_srcdst();
|
||||
if(best_target->type == target::TYPE::SUPPORT) {
|
||||
if(best_target->type == ai_target::type::support) {
|
||||
LOG_AI << "support...\n";
|
||||
|
||||
std::vector<map_location> locs;
|
||||
|
@ -548,7 +548,7 @@ std::pair<map_location,map_location> move_to_targets_phase::choose_move(std::vec
|
|||
for(std::set<map_location>::const_iterator j = mass_locations.begin(); j != mass_locations.end(); ++j) {
|
||||
if(*j != best_loc && distance_between(*j,best_loc) < 3) {
|
||||
LOG_AI << "found mass-to-attack target... " << *j << " with value: " << value*4.0 << "\n";
|
||||
targets.emplace_back(*j,value*4.0,target::TYPE::MASS);
|
||||
targets.emplace_back(*j,value*4.0,ai_target::type::mass);
|
||||
best_target = targets.end() - 1;
|
||||
}
|
||||
}
|
||||
|
@ -572,12 +572,12 @@ std::pair<map_location,map_location> move_to_targets_phase::choose_move(std::vec
|
|||
get_caution())) {
|
||||
double value = best_target->value - best->cost() / 20.0;
|
||||
|
||||
if(value > 0.0 && best_target->type != target::TYPE::MASS) {
|
||||
if(value > 0.0 && best_target->type != ai_target::type::mass) {
|
||||
//there are enemies ahead. Rally troops around us to
|
||||
//try to take the target
|
||||
if(is_dangerous) {
|
||||
LOG_AI << "found reinforcement target... " << its.first->first << " with value: " << value*2.0 << "\n";
|
||||
targets.emplace_back(its.first->first,value*2.0,target::TYPE::BATTLE_AID);
|
||||
targets.emplace_back(its.first->first,value*2.0,ai_target::type::battle_aid);
|
||||
}
|
||||
|
||||
best_target->value = value;
|
||||
|
|
|
@ -159,7 +159,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
const double value = threat/static_cast<double>(threats.size());
|
||||
for(std::set<map_location>::const_iterator i = threats.begin(); i != threats.end(); ++i) {
|
||||
LOG_AI << "found threat target... " << *i << " with value: " << value << "\n";
|
||||
targets.emplace_back(*i,value,target::TYPE::THREAT);
|
||||
targets.emplace_back(*i,value,ai_target::type::threat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
enemy *= 1.7;
|
||||
double our = power_projection(*t, friends_dstsrc);
|
||||
double value = village_value * our / enemy;
|
||||
add_target(target(*t, value, target::TYPE::SUPPORT));
|
||||
add_target(target(*t, value, ai_target::type::support));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
LOG_AI << "found village target... " << *t
|
||||
<< " with value: " << value
|
||||
<< " distance: " << leader_distance << '\n';
|
||||
targets.emplace_back(*t,value,target::TYPE::VILLAGE);
|
||||
targets.emplace_back(*t,value,ai_target::type::village);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ std::vector<target> default_ai_context_impl::find_targets(const move_map& enemy_
|
|||
&& !u->invisible(u->get_location())) {
|
||||
assert(map_.on_board(u->get_location()));
|
||||
LOG_AI << "found enemy leader (side: " << u->side() << ") target... " << u->get_location() << " with value: " << get_leader_value() << "\n";
|
||||
targets.emplace_back(u->get_location(), get_leader_value(), target::TYPE::LEADER);
|
||||
targets.emplace_back(u->get_location(), get_leader_value(), ai_target::type::leader);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,30 +20,20 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "ai/ai_target.hpp"
|
||||
#include "ai/contexts.hpp"
|
||||
#include "formula/callable.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
|
||||
//============================================================================
|
||||
namespace ai {
|
||||
|
||||
struct target {
|
||||
MAKE_ENUM(TYPE,
|
||||
(VILLAGE, "village")
|
||||
(LEADER, "leader")
|
||||
(EXPLICIT, "explicit")
|
||||
(THREAT, "threat")
|
||||
(BATTLE_AID, "battle aid")
|
||||
(MASS, "mass")
|
||||
(SUPPORT, "support")
|
||||
)
|
||||
|
||||
target(const map_location& pos, double val, TYPE target_type=TYPE::VILLAGE) : loc(pos), value(val), type(target_type)
|
||||
target(const map_location& pos, double val, ai_target::type target_type = ai_target::type::village) : loc(pos), value(val), type(target_type)
|
||||
{}
|
||||
map_location loc;
|
||||
double value;
|
||||
|
||||
TYPE type;
|
||||
ai_target::type type;
|
||||
};
|
||||
|
||||
class attack_analysis : public wfl::action_callable
|
||||
|
|
|
@ -334,7 +334,7 @@ static int cfun_ai_get_targets(lua_State *L)
|
|||
lua_createtable(L, 3, 0);
|
||||
|
||||
lua_pushstring(L, "type");
|
||||
lua_pushstring(L, it->type.to_string().c_str());
|
||||
lua_pushstring(L, ai_target::get_string(it->type).c_str());
|
||||
lua_rawset(L, -3);
|
||||
|
||||
lua_pushstring(L, "loc");
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "lua/lua.h"
|
||||
#include "map/location.hpp"
|
||||
#include "resources.hpp"
|
||||
|
@ -34,6 +35,9 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static lg::log_domain log_scripting_lua("scripting/lua");
|
||||
#define ERR_OBJ_LUA LOG_STREAM(err, log_scripting_lua)
|
||||
|
||||
namespace ai {
|
||||
|
||||
class lua_object_base {
|
||||
|
@ -286,11 +290,21 @@ inline std::shared_ptr<std::vector<target> > lua_object< std::vector<target> >::
|
|||
|
||||
lua_pushstring(L, "type"); // st n + 2
|
||||
lua_rawget(L, -2); // st n + 2
|
||||
target::TYPE type = target::TYPE::EXPLICIT;
|
||||
std::optional<ai_target::type> type = ai_target::type::xplicit;
|
||||
if(lua_isnumber(L, -1)) {
|
||||
type = target::TYPE::from_int(static_cast<int>(lua_tointeger(L, -1))); // st n + 2
|
||||
int target = static_cast<int>(lua_tointeger(L, -1));
|
||||
type = ai_target::get_enum(target); // st n + 2
|
||||
if(!type) {
|
||||
ERR_OBJ_LUA << "Failed to convert ai target type of " << target << ", skipping.\n";
|
||||
continue;
|
||||
}
|
||||
} else if(lua_isstring(L, -1)) {
|
||||
type = target::TYPE::string_to_enum(lua_tostring(L, -1)); // st n + 2
|
||||
std::string target = lua_tostring(L, -1);
|
||||
type = ai_target::get_enum(target); // st n + 2
|
||||
if(!type) {
|
||||
ERR_OBJ_LUA << "Failed to convert ai target type of " << target << ", skipping.\n";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1); // st n + 1
|
||||
|
||||
|
@ -300,7 +314,7 @@ inline std::shared_ptr<std::vector<target> > lua_object< std::vector<target> >::
|
|||
|
||||
map_location ml(x, y, wml_loc());
|
||||
|
||||
targets->emplace_back(ml, value, type);
|
||||
targets->emplace_back(ml, value, *type);
|
||||
}
|
||||
|
||||
lua_settop(L, n);
|
||||
|
|
30
src/campaign_type.hpp
Normal file
30
src/campaign_type.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct campaign_type_defines
|
||||
{
|
||||
static constexpr const char* const scenario = "scenario";
|
||||
static constexpr const char* const multiplayer = "multiplayer";
|
||||
static constexpr const char* const test = "test";
|
||||
static constexpr const char* const tutorial = "tutorial";
|
||||
|
||||
ENUM_AND_ARRAY(scenario, multiplayer, test, tutorial)
|
||||
};
|
||||
using campaign_type = string_enums::enum_base<campaign_type_defines>;
|
|
@ -51,7 +51,6 @@ using config_key_type = std::string_view;
|
|||
enum class DEP_LEVEL : uint8_t;
|
||||
|
||||
class config;
|
||||
class enum_tag;
|
||||
|
||||
bool operator==(const config &, const config &);
|
||||
inline bool operator!=(const config &a, const config &b) { return !operator==(a, b); }
|
||||
|
|
|
@ -42,8 +42,6 @@
|
|||
#include <type_traits>
|
||||
#include <memory>
|
||||
|
||||
class enum_tag;
|
||||
|
||||
/**
|
||||
* Variant for storing WML attributes.
|
||||
* The most efficient type is used when assigning a value. For instance,
|
||||
|
@ -140,11 +138,6 @@ public:
|
|||
config_attribute_value& operator=(const std::string &v);
|
||||
config_attribute_value& operator=(const std::string_view &v);
|
||||
config_attribute_value& operator=(const t_string &v);
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_base_of_v<enum_tag, T>, config_attribute_value&> operator=(const T &v)
|
||||
{
|
||||
return operator=(T::enum_to_string(v));
|
||||
}
|
||||
|
||||
/** Calls @ref operator=(const std::string&) if @a v is not empty. */
|
||||
void write_if_not_empty(const std::string& v);
|
||||
|
@ -159,16 +152,6 @@ public:
|
|||
double to_double(double def = 0.) const;
|
||||
std::string str(const std::string& fallback = "") const;
|
||||
t_string t_str() const;
|
||||
/**
|
||||
@tparam T a type created with MAKE_ENUM macro
|
||||
NOTE: since T::VALUE constants is not of type T but of the underlying enum type you must specify the template parameter explicitly
|
||||
TODO: Fix this in c++11 using constexpr types.
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_base_of_v<enum_tag, T>, T> to_enum(const T &v) const
|
||||
{
|
||||
return T::string_to_enum(this->str(), v);
|
||||
}
|
||||
|
||||
// Implicit conversions:
|
||||
operator int() const { return to_int(); }
|
||||
|
|
30
src/defeat_condition.hpp
Normal file
30
src/defeat_condition.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct defeat_condition_defines
|
||||
{
|
||||
static constexpr const char* const no_leader_left = "no_leader_left";
|
||||
static constexpr const char* const no_units_left = "no_units_left";
|
||||
static constexpr const char* const never = "never";
|
||||
static constexpr const char* const always = "always";
|
||||
|
||||
ENUM_AND_ARRAY(no_leader_left, no_units_left, never, always)
|
||||
};
|
||||
using defeat_condition = string_enums::enum_base<defeat_condition_defines>;
|
|
@ -539,7 +539,7 @@ config map_context::to_config()
|
|||
|
||||
side["fog"] = t->uses_fog();
|
||||
side["shroud"] = t->uses_shroud();
|
||||
side["share_vision"] = t->share_vision();
|
||||
side["share_vision"] = team_shared_vision::get_string(t->share_vision());
|
||||
|
||||
side["gold"] = t->gold();
|
||||
side["income"] = t->base_income();
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "map/label.hpp"
|
||||
#include "mp_game_settings.hpp"
|
||||
#include "overlay.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "sound_music_track.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
#include "team.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "units/map.hpp"
|
||||
|
@ -45,7 +45,7 @@ struct editor_team_info {
|
|||
int village_support;
|
||||
bool fog;
|
||||
bool shroud;
|
||||
team::SHARE_VISION share_vision;
|
||||
team_shared_vision::type share_vision;
|
||||
side_controller::type controller;
|
||||
bool no_leader;
|
||||
bool hidden;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace string_enums
|
||||
{
|
||||
|
@ -82,7 +83,8 @@ struct enum_base : public T
|
|||
};
|
||||
|
||||
#define ENUM_AND_ARRAY(...) \
|
||||
static constexpr std::size_t count = std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value; \
|
||||
enum class type { __VA_ARGS__ }; \
|
||||
static constexpr std::array values{ __VA_ARGS__ };
|
||||
static constexpr std::array<const char*, count> values{ __VA_ARGS__ };
|
||||
|
||||
} // namespace string_enums
|
|
@ -285,7 +285,7 @@ variant unit_callable::get_value(const std::string& key) const
|
|||
} else if(key == "zoc") {
|
||||
return variant(u_.get_emit_zoc());
|
||||
} else if(key == "alignment") {
|
||||
return variant(u_.alignment().to_string());
|
||||
return variant(unit_alignments::get_string(u_.alignment()));
|
||||
} else if(key == "facing") {
|
||||
return variant(map_location::write_direction(u_.facing()));
|
||||
} else if(key == "resistance" || key == "movement_cost" || key == "vision_cost" || key == "jamming_cost" || key == "defense") {
|
||||
|
@ -402,7 +402,7 @@ variant unit_type_callable::get_value(const std::string& key) const
|
|||
} else if(key == "type") {
|
||||
return variant(u_.type_name());
|
||||
} else if(key == "alignment") {
|
||||
return variant(u_.alignment().to_string());
|
||||
return variant(unit_alignments::get_string(u_.alignment()));
|
||||
} else if(key == "race") {
|
||||
return variant(u_.race_id());
|
||||
} else if(key == "abilities") {
|
||||
|
@ -765,7 +765,7 @@ variant team_callable::get_value(const std::string& key) const
|
|||
} else if(key == "color") {
|
||||
return variant(team_.color());
|
||||
} else if(key == "share_vision") {
|
||||
return variant(team_.share_vision().to_string());
|
||||
return variant(team_shared_vision::get_string(team_.share_vision()));
|
||||
} else if(key == "carryover_bonus") {
|
||||
return variant(team_.carryover_bonus(), variant::DECIMAL_VARIANT);
|
||||
} else if(key == "carryover_percentage") {
|
||||
|
|
33
src/formula/formula_variant.hpp
Normal file
33
src/formula/formula_variant.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct formula_variant_defines
|
||||
{
|
||||
static constexpr const char* const null = "null";
|
||||
static constexpr const char* const integer = "int";
|
||||
static constexpr const char* const decimal = "decimal";
|
||||
static constexpr const char* const object = "object";
|
||||
static constexpr const char* const list = "list";
|
||||
static constexpr const char* const string = "string";
|
||||
static constexpr const char* const map = "map";
|
||||
|
||||
ENUM_AND_ARRAY(null, integer, decimal, object, list, string, map)
|
||||
};
|
||||
using formula_variant = string_enums::enum_base<formula_variant_defines>;
|
|
@ -40,9 +40,9 @@ namespace wfl
|
|||
// Static value to initialize null variants to ensure its value is never nullptr.
|
||||
static value_base_ptr null_value(new variant_value_base);
|
||||
|
||||
static std::string variant_type_to_string(VARIANT_TYPE type)
|
||||
static std::string variant_type_to_string(formula_variant::type type)
|
||||
{
|
||||
return VARIANT_TYPE::enum_to_string(type);
|
||||
return formula_variant::get_string(type);
|
||||
}
|
||||
|
||||
// Small helper function to get a standard type error message.
|
||||
|
@ -62,7 +62,7 @@ type_error::type_error(const std::string& str) : game::error(str)
|
|||
}
|
||||
|
||||
variant_iterator::variant_iterator()
|
||||
: type_(VARIANT_TYPE::TYPE_NULL)
|
||||
: type_(formula_variant::type::null)
|
||||
, container_(nullptr)
|
||||
, iter_()
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ variant variant::operator[](std::size_t n) const
|
|||
return *this;
|
||||
}
|
||||
|
||||
must_be(VARIANT_TYPE::TYPE_LIST);
|
||||
must_be(formula_variant::type::list);
|
||||
|
||||
try {
|
||||
return value_cast<variant_list>()->get_container().at(n);
|
||||
|
@ -231,7 +231,7 @@ variant variant::operator[](const variant& v) const
|
|||
|
||||
variant variant::get_keys() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_MAP);
|
||||
must_be(formula_variant::type::map);
|
||||
|
||||
std::vector<variant> tmp;
|
||||
for(const auto& i : value_cast<variant_map>()->get_container()) {
|
||||
|
@ -243,7 +243,7 @@ variant variant::get_keys() const
|
|||
|
||||
variant variant::get_values() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_MAP);
|
||||
must_be(formula_variant::type::map);
|
||||
|
||||
std::vector<variant> tmp;
|
||||
for(const auto& i : value_cast<variant_map>()->get_container()) {
|
||||
|
@ -297,7 +297,7 @@ int variant::as_int() const
|
|||
if(is_null()) { return 0; }
|
||||
if(is_decimal()) { return as_decimal() / 1000; }
|
||||
|
||||
must_be(VARIANT_TYPE::TYPE_INT);
|
||||
must_be(formula_variant::type::integer);
|
||||
return value_cast<variant_int>()->get_numeric_value();
|
||||
}
|
||||
|
||||
|
@ -321,19 +321,19 @@ bool variant::as_bool() const
|
|||
|
||||
const std::string& variant::as_string() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_STRING);
|
||||
must_be(formula_variant::type::string);
|
||||
return value_cast<variant_string>()->get_string();
|
||||
}
|
||||
|
||||
const std::vector<variant>& variant::as_list() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_LIST);
|
||||
must_be(formula_variant::type::list);
|
||||
return value_cast<variant_list>()->get_container();
|
||||
}
|
||||
|
||||
const std::map<variant, variant>& variant::as_map() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_MAP);
|
||||
must_be(formula_variant::type::map);
|
||||
return value_cast<variant_map>()->get_container();
|
||||
}
|
||||
|
||||
|
@ -539,32 +539,32 @@ bool variant::operator>(const variant& v) const
|
|||
|
||||
variant variant::list_elements_add(const variant& v) const
|
||||
{
|
||||
must_both_be(VARIANT_TYPE::TYPE_LIST, v);
|
||||
must_both_be(formula_variant::type::list, v);
|
||||
return value_cast<variant_list>()->list_op(v.value_, std::plus<variant>());
|
||||
}
|
||||
|
||||
variant variant::list_elements_sub(const variant& v) const
|
||||
{
|
||||
must_both_be(VARIANT_TYPE::TYPE_LIST, v);
|
||||
must_both_be(formula_variant::type::list, v);
|
||||
return value_cast<variant_list>()->list_op(v.value_, std::minus<variant>());
|
||||
}
|
||||
|
||||
variant variant::list_elements_mul(const variant& v) const
|
||||
{
|
||||
must_both_be(VARIANT_TYPE::TYPE_LIST, v);
|
||||
must_both_be(formula_variant::type::list, v);
|
||||
return value_cast<variant_list>()->list_op(v.value_, std::multiplies<variant>());
|
||||
}
|
||||
|
||||
variant variant::list_elements_div(const variant& v) const
|
||||
{
|
||||
must_both_be(VARIANT_TYPE::TYPE_LIST, v);
|
||||
must_both_be(formula_variant::type::list, v);
|
||||
return value_cast<variant_list>()->list_op(v.value_, std::divides<variant>());
|
||||
}
|
||||
|
||||
variant variant::concatenate(const variant& v) const
|
||||
{
|
||||
if(is_list()) {
|
||||
v.must_be(VARIANT_TYPE::TYPE_LIST);
|
||||
v.must_be(formula_variant::type::list);
|
||||
|
||||
std::vector<variant> res;
|
||||
res.reserve(num_elements() + v.num_elements());
|
||||
|
@ -579,7 +579,7 @@ variant variant::concatenate(const variant& v) const
|
|||
|
||||
return variant(res);
|
||||
} else if(is_string()) {
|
||||
v.must_be(VARIANT_TYPE::TYPE_STRING);
|
||||
v.must_be(formula_variant::type::string);
|
||||
std::string res = as_string() + v.as_string();
|
||||
return variant(res);
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ variant variant::concatenate(const variant& v) const
|
|||
|
||||
variant variant::build_range(const variant& v) const
|
||||
{
|
||||
must_both_be(VARIANT_TYPE::TYPE_INT, v);
|
||||
must_both_be(formula_variant::type::integer, v);
|
||||
|
||||
return value_cast<variant_int>()->build_range_variant(v.as_int());
|
||||
}
|
||||
|
@ -607,14 +607,14 @@ bool variant::contains(const variant& v) const
|
|||
}
|
||||
}
|
||||
|
||||
void variant::must_be(VARIANT_TYPE t) const
|
||||
void variant::must_be(formula_variant::type t) const
|
||||
{
|
||||
if(type() != t) {
|
||||
throw type_error(was_expecting(variant_type_to_string(t), *this));
|
||||
}
|
||||
}
|
||||
|
||||
void variant::must_both_be(VARIANT_TYPE t, const variant& second) const
|
||||
void variant::must_both_be(formula_variant::type t, const variant& second) const
|
||||
{
|
||||
if(type() != t || second.type() != t) {
|
||||
throw type_error(formatter() << "TYPE ERROR: expected two "
|
||||
|
|
|
@ -59,13 +59,13 @@ public:
|
|||
variant get_member(const std::string& name) const;
|
||||
|
||||
/** Functions to test the type of the internal value. */
|
||||
bool is_null() const { return type() == VARIANT_TYPE::TYPE_NULL; }
|
||||
bool is_int() const { return type() == VARIANT_TYPE::TYPE_INT; }
|
||||
bool is_decimal() const { return type() == VARIANT_TYPE::TYPE_DECIMAL; }
|
||||
bool is_callable() const { return type() == VARIANT_TYPE::TYPE_CALLABLE; }
|
||||
bool is_list() const { return type() == VARIANT_TYPE::TYPE_LIST; }
|
||||
bool is_string() const { return type() == VARIANT_TYPE::TYPE_STRING; }
|
||||
bool is_map() const { return type() == VARIANT_TYPE::TYPE_MAP; }
|
||||
bool is_null() const { return type() == formula_variant::type::null; }
|
||||
bool is_int() const { return type() == formula_variant::type::integer; }
|
||||
bool is_decimal() const { return type() == formula_variant::type::decimal; }
|
||||
bool is_callable() const { return type() == formula_variant::type::object; }
|
||||
bool is_list() const { return type() == formula_variant::type::list; }
|
||||
bool is_string() const { return type() == formula_variant::type::string; }
|
||||
bool is_map() const { return type() == formula_variant::type::map; }
|
||||
|
||||
int as_int() const;
|
||||
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
const_formula_callable_ptr as_callable() const
|
||||
{
|
||||
must_be(VARIANT_TYPE::TYPE_CALLABLE);
|
||||
must_be(formula_variant::type::object);
|
||||
return value_cast<variant_callable>()->get_callable();
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ public:
|
|||
/** Gets string name of the current value type */
|
||||
std::string type_string() const
|
||||
{
|
||||
return type().to_string();
|
||||
return formula_variant::get_string(type());
|
||||
}
|
||||
|
||||
variant execute_variant(const variant& to_exec);
|
||||
|
@ -159,11 +159,11 @@ private:
|
|||
return wfl::value_cast<T>(value_);
|
||||
}
|
||||
|
||||
void must_be(VARIANT_TYPE t) const;
|
||||
void must_be(formula_variant::type t) const;
|
||||
|
||||
void must_both_be(VARIANT_TYPE t, const variant& second) const;
|
||||
void must_both_be(formula_variant::type t, const variant& second) const;
|
||||
|
||||
VARIANT_TYPE type() const
|
||||
formula_variant::type type() const
|
||||
{
|
||||
return value_->get_type();
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ public:
|
|||
bool operator==(const variant_iterator& that) const;
|
||||
bool operator!=(const variant_iterator& that) const;
|
||||
private:
|
||||
VARIANT_TYPE type_;
|
||||
formula_variant::type type_;
|
||||
const variant_value_base* container_;
|
||||
boost::any iter_;
|
||||
};
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "exceptions.hpp"
|
||||
#include "formula/callable_fwd.hpp"
|
||||
#include "formula_variant.hpp"
|
||||
#include "utils/general.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
@ -35,17 +35,6 @@ class variant_value_base;
|
|||
class variant_iterator;
|
||||
class variant;
|
||||
|
||||
/** The various types the variant class is designed to handle */
|
||||
MAKE_ENUM(VARIANT_TYPE,
|
||||
(TYPE_NULL, "null")
|
||||
(TYPE_INT, "int")
|
||||
(TYPE_DECIMAL, "decimal")
|
||||
(TYPE_CALLABLE, "object")
|
||||
(TYPE_LIST, "list")
|
||||
(TYPE_STRING, "string")
|
||||
(TYPE_MAP, "map")
|
||||
);
|
||||
|
||||
using variant_vector = std::vector<variant>;
|
||||
using variant_map_raw = std::map<variant, variant>;
|
||||
using value_base_ptr = std::shared_ptr<variant_value_base>;
|
||||
|
@ -145,9 +134,9 @@ public:
|
|||
}
|
||||
|
||||
/** Returns the id of the variant type */
|
||||
virtual const VARIANT_TYPE& get_type() const
|
||||
virtual const formula_variant::type& get_type() const
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_NULL;
|
||||
static formula_variant::type type = formula_variant::type::null;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -259,9 +248,9 @@ public:
|
|||
return string_cast();
|
||||
}
|
||||
|
||||
virtual const VARIANT_TYPE& get_type() const override
|
||||
virtual const formula_variant::type& get_type() const override
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_INT;
|
||||
static formula_variant::type type = formula_variant::type::integer;
|
||||
return type;
|
||||
}
|
||||
};
|
||||
|
@ -300,9 +289,9 @@ public:
|
|||
return to_string_impl(true);
|
||||
}
|
||||
|
||||
virtual const VARIANT_TYPE& get_type() const override
|
||||
virtual const formula_variant::type& get_type() const override
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_DECIMAL;
|
||||
static formula_variant::type type = formula_variant::type::decimal;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -344,9 +333,9 @@ public:
|
|||
virtual bool equals(variant_value_base& other) const override;
|
||||
virtual bool less_than(variant_value_base& other) const override;
|
||||
|
||||
virtual const VARIANT_TYPE& get_type() const override
|
||||
virtual const formula_variant::type& get_type() const override
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_CALLABLE;
|
||||
static formula_variant::type type = formula_variant::type::object;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -410,9 +399,9 @@ public:
|
|||
return string_ < value_ref_cast<variant_string>(other).string_;
|
||||
}
|
||||
|
||||
virtual const VARIANT_TYPE& get_type() const override
|
||||
virtual const formula_variant::type& get_type() const override
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_STRING;
|
||||
static formula_variant::type type = formula_variant::type::string;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -515,9 +504,9 @@ public:
|
|||
virtual bool equals(variant_value_base& other) const override;
|
||||
virtual bool less_than(variant_value_base& other) const override;
|
||||
|
||||
virtual const VARIANT_TYPE& get_type() const override
|
||||
virtual const formula_variant::type& get_type() const override
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_LIST;
|
||||
static formula_variant::type type = formula_variant::type::list;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -541,9 +530,9 @@ public:
|
|||
virtual bool equals(variant_value_base& other) const override;
|
||||
virtual bool less_than(variant_value_base& other) const override;
|
||||
|
||||
virtual const VARIANT_TYPE& get_type() const override
|
||||
virtual const formula_variant::type& get_type() const override
|
||||
{
|
||||
static VARIANT_TYPE type = VARIANT_TYPE::TYPE_MAP;
|
||||
static formula_variant::type type = formula_variant::type::map;
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
@ -126,16 +126,16 @@ void game_board::check_victory(bool& continue_level,
|
|||
for(const unit& i : units()) {
|
||||
DBG_EE << "Found a unit: " << i.id() << " on side " << i.side() << std::endl;
|
||||
const team& tm = get_team(i.side());
|
||||
DBG_EE << "That team's defeat condition is: " << tm.defeat_condition() << std::endl;
|
||||
if(i.can_recruit() && tm.defeat_condition() == team::DEFEAT_CONDITION::NO_LEADER) {
|
||||
DBG_EE << "That team's defeat condition is: " << defeat_condition::get_string(tm.defeat_cond()) << std::endl;
|
||||
if(i.can_recruit() && tm.defeat_cond() == defeat_condition::type::no_leader_left) {
|
||||
not_defeated.insert(i.side());
|
||||
} else if(tm.defeat_condition() == team::DEFEAT_CONDITION::NO_UNITS) {
|
||||
} else if(tm.defeat_cond() == defeat_condition::type::no_units_left) {
|
||||
not_defeated.insert(i.side());
|
||||
}
|
||||
}
|
||||
|
||||
for(team& tm : teams_) {
|
||||
if(tm.defeat_condition() == team::DEFEAT_CONDITION::NEVER) {
|
||||
if(tm.defeat_cond() == defeat_condition::type::never) {
|
||||
not_defeated.insert(tm.side());
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ unit* game_board::get_visible_unit(const map_location& loc, const team& current_
|
|||
return &*ui;
|
||||
}
|
||||
|
||||
void game_board::side_drop_to(int side_num, side_controller::type ctrl, team::PROXY_CONTROLLER proxy)
|
||||
void game_board::side_drop_to(int side_num, side_controller::type ctrl, side_proxy_controller::type proxy)
|
||||
{
|
||||
team& tm = get_team(side_num);
|
||||
|
||||
|
@ -264,18 +264,18 @@ void game_board::side_change_controller(
|
|||
|
||||
bool game_board::team_is_defeated(const team& t) const
|
||||
{
|
||||
switch(t.defeat_condition().v) {
|
||||
case team::DEFEAT_CONDITION::ALWAYS:
|
||||
switch(t.defeat_cond()) {
|
||||
case defeat_condition::type::always:
|
||||
return true;
|
||||
case team::DEFEAT_CONDITION::NO_LEADER:
|
||||
case defeat_condition::type::no_leader_left:
|
||||
return !units_.find_leader(t.side()).valid();
|
||||
case team::DEFEAT_CONDITION::NO_UNITS:
|
||||
case defeat_condition::type::no_units_left:
|
||||
for(const unit& u : units_) {
|
||||
if(u.side() == t.side())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
case team::DEFEAT_CONDITION::NEVER:
|
||||
case defeat_condition::type::never:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "display_context.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "team.hpp"
|
||||
#include "terrain/translation.hpp"
|
||||
#include "terrain/type_data.hpp"
|
||||
#include "units/map.hpp"
|
||||
#include "units/id.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
|
||||
// Manipulator from playturn
|
||||
|
||||
void side_drop_to (int side_num, side_controller::type ctrl, team::PROXY_CONTROLLER proxy = team::PROXY_CONTROLLER::PROXY_HUMAN);
|
||||
void side_drop_to (int side_num, side_controller::type ctrl, side_proxy_controller::type proxy = side_proxy_controller::type::human);
|
||||
void side_change_controller (int side_num, bool is_local, const std::string& pname, const std::string& controller_type);
|
||||
|
||||
// Manipulator from actionwml
|
||||
|
|
|
@ -35,8 +35,7 @@ const std::string DEFAULT_DIFFICULTY("NORMAL");
|
|||
game_classification::game_classification(const config& cfg)
|
||||
: label(cfg["label"])
|
||||
, version(cfg["version"])
|
||||
, campaign_type(
|
||||
cfg["campaign_type"].to_enum<game_classification::CAMPAIGN_TYPE>(game_classification::CAMPAIGN_TYPE::SCENARIO))
|
||||
, type(campaign_type::get_enum(cfg["campaign_type"].str()).value_or(campaign_type::type::scenario))
|
||||
, campaign_define(cfg["campaign_define"])
|
||||
, campaign_xtra_defines(utils::split(cfg["campaign_extra_defines"]))
|
||||
, scenario_define(cfg["scenario_define"])
|
||||
|
@ -61,7 +60,7 @@ config game_classification::to_config() const
|
|||
config cfg;
|
||||
cfg["label"] = label;
|
||||
cfg["version"] = game_config::wesnoth_version.str();
|
||||
cfg["campaign_type"] = campaign_type.to_string();
|
||||
cfg["campaign_type"] = campaign_type::get_string(type);
|
||||
cfg["campaign_define"] = campaign_define;
|
||||
cfg["campaign_extra_defines"] = utils::join(campaign_xtra_defines);
|
||||
cfg["scenario_define"] = scenario_define;
|
||||
|
@ -85,14 +84,14 @@ config game_classification::to_config() const
|
|||
std::string game_classification::get_tagname() const
|
||||
{
|
||||
if(is_multiplayer()) {
|
||||
return campaign.empty() ? "multiplayer" : "scenario";
|
||||
return campaign.empty() ? campaign_type::multiplayer : campaign_type::scenario;
|
||||
}
|
||||
|
||||
if(is_tutorial()) {
|
||||
return "scenario";
|
||||
return campaign_type::scenario;
|
||||
}
|
||||
|
||||
return campaign_type.to_string();
|
||||
return campaign_type::get_string(type);
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "utils/make_enum.hpp"
|
||||
#include "campaign_type.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
@ -34,13 +34,7 @@ public:
|
|||
|
||||
std::string label; /**< Name of the game (e.g. name of save file). */
|
||||
std::string version; /**< Version game was created with. */
|
||||
MAKE_ENUM (CAMPAIGN_TYPE, /**< Type of the game - campaign, multiplayer etc. */
|
||||
(SCENARIO, "scenario")
|
||||
(MULTIPLAYER, "multiplayer")
|
||||
(TEST, "test")
|
||||
(TUTORIAL, "tutorial")
|
||||
)
|
||||
CAMPAIGN_TYPE campaign_type;
|
||||
campaign_type::type type;
|
||||
std::string campaign_define; /**< If there is a define the campaign uses to customize data */
|
||||
std::vector<std::string> campaign_xtra_defines; /**< more customization of data */
|
||||
std::string scenario_define; /**< If there is a define the scenario uses to customize data */
|
||||
|
@ -72,21 +66,21 @@ public:
|
|||
|
||||
bool is_scenario() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::SCENARIO;
|
||||
return type == campaign_type::type::scenario;
|
||||
}
|
||||
|
||||
bool is_multiplayer() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
return type == campaign_type::type::multiplayer;
|
||||
}
|
||||
|
||||
bool is_test() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::TEST;
|
||||
return type == campaign_type::type::test;
|
||||
}
|
||||
|
||||
bool is_tutorial() const
|
||||
{
|
||||
return campaign_type == CAMPAIGN_TYPE::TUTORIAL;
|
||||
return type == campaign_type::type::tutorial;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,9 +14,8 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "game_end_exceptions.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "game_end_exceptions.hpp"
|
||||
|
||||
transient_end_level::transient_end_level()
|
||||
: carryover_report(true)
|
||||
|
@ -29,7 +28,7 @@ end_level_data::end_level_data()
|
|||
, replay_save(true)
|
||||
, proceed_to_next_level(false)
|
||||
, is_victory(true)
|
||||
, test_result(LEVEL_RESULT::enum_to_string(LEVEL_RESULT::TEST_NOT_SET))
|
||||
, test_result(level_result::result_not_set)
|
||||
, transient()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -22,26 +22,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "level_result.hpp"
|
||||
#include "lua_jailbreak_exception.hpp"
|
||||
|
||||
#include "utils/make_enum.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
class config;
|
||||
|
||||
MAKE_ENUM(LEVEL_RESULT,
|
||||
(VICTORY, "victory")
|
||||
(DEFEAT, "defeat")
|
||||
(QUIT, "quit")
|
||||
(OBSERVER_END, "observer_end")
|
||||
(TEST_NOT_SET, "result_not_set")
|
||||
(TEST_PASS, "pass")
|
||||
(TEST_FAIL, "fail")
|
||||
(TEST_INVALID, "test_result_value_invalid")
|
||||
);
|
||||
|
||||
/**
|
||||
* Exception used to escape form the ai or ui code to playsingle_controller::play_side.
|
||||
* Never thrown during replays.
|
||||
|
|
29
src/game_initialization/component_availability.hpp
Normal file
29
src/game_initialization/component_availability.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct component_availability_defines
|
||||
{
|
||||
static constexpr const char* const sp = "sp";
|
||||
static constexpr const char* const mp = "mp";
|
||||
static constexpr const char* const hybrid = "hybrid";
|
||||
|
||||
ENUM_AND_ARRAY(sp, mp, hybrid)
|
||||
};
|
||||
using component_availability = string_enums::enum_base<component_availability_defines>;
|
|
@ -150,10 +150,9 @@ bool configure_engine::shuffle_sides_default() const
|
|||
return preferences::shuffle_sides();
|
||||
}
|
||||
|
||||
mp_game_settings::RANDOM_FACTION_MODE configure_engine::random_faction_mode_default() const
|
||||
random_faction_mode::type configure_engine::random_faction_mode_default() const
|
||||
{
|
||||
return mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(
|
||||
preferences::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT);
|
||||
return random_faction_mode::get_enum(preferences::random_faction_mode()).value_or(random_faction_mode::type::independent);
|
||||
}
|
||||
|
||||
void configure_engine::set_options(const config& cfg)
|
||||
|
|
|
@ -122,9 +122,9 @@ public:
|
|||
return parameters_.shuffle_sides;
|
||||
}
|
||||
|
||||
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode() const
|
||||
random_faction_mode::type mode() const
|
||||
{
|
||||
return parameters_.random_faction_mode;
|
||||
return parameters_.mode;
|
||||
}
|
||||
|
||||
const config& options() const
|
||||
|
@ -231,9 +231,9 @@ public:
|
|||
parameters_.shuffle_sides = val;
|
||||
}
|
||||
|
||||
void set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE val)
|
||||
void set_random_faction_mode(random_faction_mode::type val)
|
||||
{
|
||||
parameters_.random_faction_mode = val;
|
||||
parameters_.mode = val;
|
||||
}
|
||||
|
||||
void set_options(const config& cfg);
|
||||
|
@ -258,7 +258,7 @@ public:
|
|||
bool shroud_game_default() const;
|
||||
bool allow_observers_default() const;
|
||||
bool shuffle_sides_default() const;
|
||||
mp_game_settings::RANDOM_FACTION_MODE random_faction_mode_default() const;
|
||||
random_faction_mode::type random_faction_mode_default() const;
|
||||
const config& options_default() const;
|
||||
|
||||
const mp_game_settings& get_parameters() const
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
#include "log.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include "mt_rng.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "team.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
|
@ -86,7 +86,7 @@ connect_engine::connect_engine(saved_game& state, const bool first_scenario, mp_
|
|||
}
|
||||
|
||||
const bool is_mp = state_.classification().is_normal_mp_game();
|
||||
force_lock_settings_ = (state.mp_settings().saved_game != mp_game_settings::SAVED_GAME_MODE::MIDGAME) && scenario()["force_lock_settings"].to_bool(!is_mp);
|
||||
force_lock_settings_ = (state.mp_settings().saved_game != saved_game_mode::type::midgame) && scenario()["force_lock_settings"].to_bool(!is_mp);
|
||||
|
||||
// Original level sides.
|
||||
config::child_itors sides = current_config()->child_range("side");
|
||||
|
@ -399,14 +399,14 @@ void connect_engine::start_game()
|
|||
std::vector<std::string> avoid_faction_ids;
|
||||
|
||||
// If we aren't resolving random factions independently at random, calculate which factions should not appear for this side.
|
||||
if(params_.random_faction_mode != mp_game_settings::RANDOM_FACTION_MODE::DEFAULT) {
|
||||
if(params_.mode != random_faction_mode::type::independent) {
|
||||
for(side_engine_ptr side2 : side_engines_) {
|
||||
if(!side2->flg().is_random_faction()) {
|
||||
switch(params_.random_faction_mode.v) {
|
||||
case mp_game_settings::RANDOM_FACTION_MODE::NO_MIRROR:
|
||||
switch(params_.mode) {
|
||||
case random_faction_mode::type::no_mirror:
|
||||
avoid_faction_ids.push_back(side2->flg().current_faction()["id"].str());
|
||||
break;
|
||||
case mp_game_settings::RANDOM_FACTION_MODE::NO_ALLY_MIRROR:
|
||||
case random_faction_mode::type::no_ally_mirror:
|
||||
if(side2->team() == side->team()) {// TODO: When the connect engines are fixed to allow multiple teams, this should be changed to "if side1 and side2 are allied, i.e. their list of teams has nonempty intersection"
|
||||
avoid_faction_ids.push_back(side2->flg().current_faction()["id"].str());
|
||||
}
|
||||
|
@ -844,8 +844,8 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine, const
|
|||
, ai_algorithm_()
|
||||
, chose_random_(cfg["chose_random"].to_bool(false))
|
||||
, disallow_shuffle_(cfg["disallow_shuffle"].to_bool(false))
|
||||
, flg_(parent_.era_factions_, cfg_, parent_.force_lock_settings_, parent_.params_.use_map_settings, parent_.params_.saved_game == mp_game_settings::SAVED_GAME_MODE::MIDGAME)
|
||||
, allow_changes_(parent_.params_.saved_game != mp_game_settings::SAVED_GAME_MODE::MIDGAME && !(flg_.choosable_factions().size() == 1 && flg_.choosable_leaders().size() == 1 && flg_.choosable_genders().size() == 1))
|
||||
, flg_(parent_.era_factions_, cfg_, parent_.force_lock_settings_, parent_.params_.use_map_settings, parent_.params_.saved_game == saved_game_mode::type::midgame)
|
||||
, allow_changes_(parent_.params_.saved_game != saved_game_mode::type::midgame && !(flg_.choosable_factions().size() == 1 && flg_.choosable_leaders().size() == 1 && flg_.choosable_genders().size() == 1))
|
||||
, waiting_to_choose_faction_(allow_changes_)
|
||||
, color_options_(game_config::default_colors)
|
||||
//TODO: what should we do if color_ is out of range?
|
||||
|
@ -971,7 +971,7 @@ config side_engine::new_config() const
|
|||
res["side"] = index_ + 1;
|
||||
|
||||
// If the user is allowed to change type, faction, leader etc, then import their new values in the config.
|
||||
if(parent_.params_.saved_game != mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
if(parent_.params_.saved_game != saved_game_mode::type::midgame) {
|
||||
// Merge the faction data to res.
|
||||
config faction = flg_.current_faction();
|
||||
LOG_MP << "side_engine::new_config: side=" << index_ + 1 << " faction=" << faction["id"] << " recruit=" << faction["recruit"] << "\n";
|
||||
|
@ -1016,7 +1016,7 @@ config side_engine::new_config() const
|
|||
// AI algorithm, we do nothing. Otherwise we add the chosen AI and if this
|
||||
// is a saved game, we also remove the old stages from the AI config.
|
||||
if(ai_algorithm_ != "use_saved") {
|
||||
if(parent_.params_.saved_game == mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
if(parent_.params_.saved_game == saved_game_mode::type::midgame) {
|
||||
for (config &ai_config : res.child_range("ai")) {
|
||||
ai_config.clear_children("stage");
|
||||
}
|
||||
|
@ -1048,7 +1048,7 @@ config side_engine::new_config() const
|
|||
res["allow_changes"] = allow_changes_;
|
||||
res["chose_random"] = chose_random_;
|
||||
|
||||
if(parent_.params_.saved_game != mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
if(parent_.params_.saved_game != saved_game_mode::type::midgame) {
|
||||
// Find a config where a default leader is and set a new type and gender values for it.
|
||||
config* leader = &res;
|
||||
|
||||
|
@ -1132,7 +1132,7 @@ config side_engine::new_config() const
|
|||
}
|
||||
|
||||
|
||||
if(parent_.params_.use_map_settings && parent_.params_.saved_game != mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
if(parent_.params_.use_map_settings && parent_.params_.saved_game != saved_game_mode::type::midgame) {
|
||||
if(cfg_.has_attribute("name")){
|
||||
res["name"] = cfg_["name"];
|
||||
}
|
||||
|
@ -1196,7 +1196,7 @@ bool side_engine::available_for_user(const std::string& name) const
|
|||
|
||||
void side_engine::resolve_random(randomness::mt_rng & rng, const std::vector<std::string> & avoid_faction_ids)
|
||||
{
|
||||
if(parent_.params_.saved_game == mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
if(parent_.params_.saved_game == saved_game_mode::type::midgame) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1215,7 +1215,7 @@ void side_engine::reset()
|
|||
set_waiting_to_choose_status(false);
|
||||
set_controller(parent_.default_controller_);
|
||||
|
||||
if(parent_.params_.saved_game != mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
if(parent_.params_.saved_game != saved_game_mode::type::midgame) {
|
||||
flg_.set_current_faction(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "game_config_manager.hpp"
|
||||
#include "preferences/credentials.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
#include "game_initialization/component_availability.hpp"
|
||||
#include "generators/map_create.hpp"
|
||||
#include "gui/dialogs/campaign_difficulty.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -26,8 +27,9 @@
|
|||
#include "map/map.hpp"
|
||||
#include "minimap.hpp"
|
||||
#include "saved_game.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
#include "game_initialization/component_availability.hpp"
|
||||
|
||||
#include "serialization/preprocessor.hpp"
|
||||
#include "serialization/parser.hpp"
|
||||
|
@ -245,20 +247,20 @@ create_engine::create_engine(saved_game& state)
|
|||
, game_config_(game_config_manager::get()->game_config())
|
||||
{
|
||||
// Set up the type map. Do this first!
|
||||
type_map_.emplace(level::TYPE::SCENARIO, type_list());
|
||||
type_map_.emplace(level::TYPE::USER_MAP, type_list());
|
||||
type_map_.emplace(level::TYPE::USER_SCENARIO, type_list());
|
||||
type_map_.emplace(level::TYPE::CAMPAIGN, type_list());
|
||||
type_map_.emplace(level::TYPE::SP_CAMPAIGN, type_list());
|
||||
type_map_.emplace(level::TYPE::RANDOM_MAP, type_list());
|
||||
type_map_.emplace(level_type::type::scenario, type_list());
|
||||
type_map_.emplace(level_type::type::user_map, type_list());
|
||||
type_map_.emplace(level_type::type::user_scenario, type_list());
|
||||
type_map_.emplace(level_type::type::campaign, type_list());
|
||||
type_map_.emplace(level_type::type::sp_campaign, type_list());
|
||||
type_map_.emplace(level_type::type::random_map, type_list());
|
||||
|
||||
DBG_MP << "restoring game config\n";
|
||||
|
||||
// Restore game config for multiplayer.
|
||||
game_classification::CAMPAIGN_TYPE type = state_.classification().campaign_type;
|
||||
campaign_type::type type = state_.classification().type;
|
||||
|
||||
state_.clear();
|
||||
state_.classification().campaign_type = type;
|
||||
state_.classification().type = type;
|
||||
|
||||
game_config_manager::get()->load_game_config_for_create(state_.classification().is_multiplayer());
|
||||
|
||||
|
@ -278,7 +280,7 @@ create_engine::create_engine(saved_game& state)
|
|||
init_extras(ERA);
|
||||
init_extras(MOD);
|
||||
|
||||
state_.mp_settings().saved_game = mp_game_settings::SAVED_GAME_MODE::NONE;
|
||||
state_.mp_settings().saved_game = saved_game_mode::type::no;
|
||||
|
||||
for(const std::string& str : preferences::modifications(state_.classification().is_multiplayer())) {
|
||||
if(game_config_.find_child("modification", "id", str)) {
|
||||
|
@ -472,7 +474,7 @@ void create_engine::prepare_for_saved_game()
|
|||
|
||||
// The save might be a start-of-scenario save so make sure we have the scenario data loaded.
|
||||
state_.expand_scenario();
|
||||
state_.mp_settings().saved_game = state_.is_mid_game_save() ? mp_game_settings::SAVED_GAME_MODE::MIDGAME : mp_game_settings::SAVED_GAME_MODE::SCENARIO_START;
|
||||
state_.mp_settings().saved_game = state_.is_mid_game_save() ? saved_game_mode::type::midgame : saved_game_mode::type::scenaro_start;
|
||||
}
|
||||
|
||||
void create_engine::prepare_for_other()
|
||||
|
@ -506,7 +508,7 @@ void create_engine::reset_level_filters()
|
|||
|
||||
level& create_engine::current_level() const
|
||||
{
|
||||
return *type_map_.at(current_level_type_.v).games[current_level_index_];
|
||||
return *type_map_.at(current_level_type_).games[current_level_index_];
|
||||
}
|
||||
|
||||
const create_engine::extras_metadata& create_engine::current_era() const
|
||||
|
@ -517,12 +519,12 @@ const create_engine::extras_metadata& create_engine::current_era() const
|
|||
void create_engine::set_current_level(const std::size_t index)
|
||||
{
|
||||
try {
|
||||
current_level_index_ = type_map_.at(current_level_type_.v).games_filtered.at(index);
|
||||
current_level_index_ = type_map_.at(current_level_type_).games_filtered.at(index);
|
||||
} catch (const std::out_of_range&) {
|
||||
current_level_index_ = 0u;
|
||||
}
|
||||
|
||||
if(current_level_type_ == level::TYPE::RANDOM_MAP) {
|
||||
if(current_level_type_ == level_type::type::random_map) {
|
||||
random_map* current_random_map = dynamic_cast<random_map*>(¤t_level());
|
||||
|
||||
// If dynamic cast has failed then we somehow have gotten all the pointers mixed together.
|
||||
|
@ -547,7 +549,7 @@ void create_engine::set_current_era_index(const std::size_t index, bool force)
|
|||
|
||||
bool create_engine::toggle_mod(int index, bool force)
|
||||
{
|
||||
force |= state_.classification().campaign_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
force |= state_.classification().type != campaign_type::type::multiplayer;
|
||||
|
||||
bool is_active = dependency_manager_->is_modification_active(index);
|
||||
dependency_manager_->try_modification_by_index(index, !is_active, force);
|
||||
|
@ -572,7 +574,7 @@ void create_engine::generator_user_config()
|
|||
generator_->user_config();
|
||||
}
|
||||
|
||||
std::pair<level::TYPE, int> create_engine::find_level_by_id(const std::string& id) const
|
||||
std::pair<level_type::type, int> create_engine::find_level_by_id(const std::string& id) const
|
||||
{
|
||||
for(const auto& type : type_map_) {
|
||||
int i = 0;
|
||||
|
@ -586,7 +588,7 @@ std::pair<level::TYPE, int> create_engine::find_level_by_id(const std::string& i
|
|||
}
|
||||
}
|
||||
|
||||
return {level::TYPE::SP_CAMPAIGN, -1};
|
||||
return {level_type::type::sp_campaign, -1};
|
||||
}
|
||||
|
||||
int create_engine::find_extra_by_id(const MP_EXTRA extra_type, const std::string& id) const
|
||||
|
@ -670,7 +672,7 @@ void create_engine::init_all_levels()
|
|||
}
|
||||
|
||||
if(add_map) {
|
||||
type_map_[level::TYPE::USER_MAP].games.emplace_back(new user_map(user_map_data, user_map_names_[i], map.get()));
|
||||
type_map_[level_type::type::user_map].games.emplace_back(new user_map(user_map_data, user_map_names_[i], map.get()));
|
||||
|
||||
// Since user maps are treated as scenarios, some dependency info is required
|
||||
config depinfo;
|
||||
|
@ -696,7 +698,7 @@ void create_engine::init_all_levels()
|
|||
scenario_ptr new_scenario(new scenario(data));
|
||||
if(new_scenario->id().empty()) continue;
|
||||
|
||||
type_map_[level::TYPE::USER_SCENARIO].games.push_back(std::move(new_scenario));
|
||||
type_map_[level_type::type::user_scenario].games.push_back(std::move(new_scenario));
|
||||
|
||||
// Since user scenarios are treated as scenarios, some dependency info is required
|
||||
config depinfo;
|
||||
|
@ -716,9 +718,9 @@ void create_engine::init_all_levels()
|
|||
continue;
|
||||
|
||||
if(data.has_attribute("map_generation") || data.has_attribute("scenario_generation")) {
|
||||
type_map_[level::TYPE::RANDOM_MAP].games.emplace_back(new random_map(data));
|
||||
type_map_[level_type::type::random_map].games.emplace_back(new random_map(data));
|
||||
} else {
|
||||
type_map_[level::TYPE::SCENARIO].games.emplace_back(new scenario(data));
|
||||
type_map_[level_type::type::scenario].games.emplace_back(new scenario(data));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -738,18 +740,18 @@ void create_engine::init_all_levels()
|
|||
const bool mp = state_.classification().is_multiplayer();
|
||||
|
||||
if(type == "mp" || (type == "hybrid" && mp)) {
|
||||
type_map_[level::TYPE::CAMPAIGN].games.emplace_back(new campaign(data));
|
||||
type_map_[level_type::type::campaign].games.emplace_back(new campaign(data));
|
||||
}
|
||||
|
||||
if(type == "sp" || type.empty() || (type == "hybrid" && !mp)) {
|
||||
campaign_ptr new_sp_campaign(new campaign(data));
|
||||
new_sp_campaign->mark_if_completed();
|
||||
|
||||
type_map_[level::TYPE::SP_CAMPAIGN].games.push_back(std::move(new_sp_campaign));
|
||||
type_map_[level_type::type::sp_campaign].games.push_back(std::move(new_sp_campaign));
|
||||
}
|
||||
}
|
||||
|
||||
auto& sp_campaigns = type_map_[level::TYPE::SP_CAMPAIGN].games;
|
||||
auto& sp_campaigns = type_map_[level_type::type::sp_campaign].games;
|
||||
|
||||
// Sort sp campaigns by rank.
|
||||
std::stable_sort(sp_campaigns.begin(), sp_campaigns.end(),
|
||||
|
@ -764,17 +766,17 @@ void create_engine::init_extras(const MP_EXTRA extra_type)
|
|||
std::vector<extras_metadata_ptr>& extras = get_extras_by_type(extra_type);
|
||||
const std::string extra_name = (extra_type == ERA) ? "era" : "modification";
|
||||
|
||||
ng::depcheck::component_availability default_availabilty = (extra_type == ERA)
|
||||
? ng::depcheck::component_availability::MP
|
||||
: ng::depcheck::component_availability::HYBRID;
|
||||
component_availability::type default_availabilty = (extra_type == ERA)
|
||||
? component_availability::type::mp
|
||||
: component_availability::type::hybrid;
|
||||
|
||||
std::set<std::string> found_ids;
|
||||
for(const config& extra : game_config_.child_range(extra_name))
|
||||
{
|
||||
ng::depcheck::component_availability type = extra["type"].to_enum(default_availabilty);
|
||||
component_availability::type type = component_availability::get_enum(extra["type"].str()).value_or(default_availabilty);
|
||||
const bool mp = state_.classification().is_multiplayer();
|
||||
|
||||
if((type != ng::depcheck::component_availability::MP || mp) && (type != ng::depcheck::component_availability::SP || !mp) )
|
||||
if((type != component_availability::type::mp || mp) && (type != component_availability::type::sp || !mp) )
|
||||
{
|
||||
if(found_ids.insert(extra["id"]).second) {
|
||||
extras_metadata_ptr new_extras_metadata(new extras_metadata());
|
||||
|
@ -800,19 +802,19 @@ void create_engine::apply_level_filters()
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<create_engine::level_ptr> create_engine::get_levels_by_type_unfiltered(level::TYPE type) const
|
||||
std::vector<create_engine::level_ptr> create_engine::get_levels_by_type_unfiltered(level_type::type type) const
|
||||
{
|
||||
std::vector<level_ptr> levels;
|
||||
for(const level_ptr& lvl : type_map_.at(type.v).games) {
|
||||
for(const level_ptr& lvl : type_map_.at(type).games) {
|
||||
levels.push_back(lvl);
|
||||
}
|
||||
|
||||
return levels;
|
||||
}
|
||||
|
||||
std::vector<create_engine::level_ptr> create_engine::get_levels_by_type(level::TYPE type) const
|
||||
std::vector<create_engine::level_ptr> create_engine::get_levels_by_type(level_type::type type) const
|
||||
{
|
||||
auto& g_list = type_map_.at(type.v);
|
||||
auto& g_list = type_map_.at(type);
|
||||
|
||||
std::vector<level_ptr> levels;
|
||||
for(std::size_t level : g_list.games_filtered) {
|
||||
|
@ -822,9 +824,9 @@ std::vector<create_engine::level_ptr> create_engine::get_levels_by_type(level::T
|
|||
return levels;
|
||||
}
|
||||
|
||||
std::vector<std::size_t> create_engine::get_filtered_level_indices(level::TYPE type) const
|
||||
std::vector<std::size_t> create_engine::get_filtered_level_indices(level_type::type type) const
|
||||
{
|
||||
return type_map_.at(type.v).games_filtered;
|
||||
return type_map_.at(type).games_filtered;
|
||||
}
|
||||
|
||||
const std::vector<create_engine::extras_metadata_ptr>&
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "game_initialization/depcheck.hpp"
|
||||
#include "game_initialization/level_type.hpp"
|
||||
#include "generators/map_generator.hpp"
|
||||
#include "mp_game_settings.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
#include "utils/irdya_datetime.hpp"
|
||||
|
||||
#include <numeric>
|
||||
|
@ -63,15 +63,6 @@ public:
|
|||
level(const config& data);
|
||||
virtual ~level() = default;
|
||||
|
||||
MAKE_ENUM(TYPE,
|
||||
(SCENARIO, "scenario")
|
||||
(USER_MAP, "user_map")
|
||||
(USER_SCENARIO, "user_scenario")
|
||||
(RANDOM_MAP, "random_map")
|
||||
(CAMPAIGN, "campaign")
|
||||
(SP_CAMPAIGN, "sp_campaign")
|
||||
)
|
||||
|
||||
virtual void set_metadata() = 0;
|
||||
|
||||
virtual bool can_launch_game() const = 0;
|
||||
|
@ -338,20 +329,20 @@ public:
|
|||
return player_count_filter_;
|
||||
}
|
||||
|
||||
std::vector<level_ptr> get_levels_by_type_unfiltered(level::TYPE type) const;
|
||||
std::vector<level_ptr> get_levels_by_type(level::TYPE type) const;
|
||||
std::vector<level_ptr> get_levels_by_type_unfiltered(level_type::type type) const;
|
||||
std::vector<level_ptr> get_levels_by_type(level_type::type type) const;
|
||||
|
||||
std::vector<std::size_t> get_filtered_level_indices(level::TYPE type) const;
|
||||
std::vector<std::size_t> get_filtered_level_indices(level_type::type type) const;
|
||||
|
||||
level& current_level() const;
|
||||
const extras_metadata& current_era() const;
|
||||
|
||||
void set_current_level_type(const level::TYPE type)
|
||||
void set_current_level_type(const level_type::type type)
|
||||
{
|
||||
current_level_type_ = type;
|
||||
}
|
||||
|
||||
level::TYPE current_level_type() const
|
||||
level_type::type current_level_type() const
|
||||
{
|
||||
return current_level_type_;
|
||||
}
|
||||
|
@ -359,7 +350,7 @@ public:
|
|||
/** Wrapper to simplify the is-type-campaign-or-sp-campaign check. */
|
||||
bool is_campaign() const
|
||||
{
|
||||
return current_level_type_ == level::TYPE::CAMPAIGN || current_level_type_ == level::TYPE::SP_CAMPAIGN;
|
||||
return current_level_type_ == level_type::type::campaign || current_level_type_ == level_type::type::sp_campaign;
|
||||
}
|
||||
|
||||
void set_current_level(const std::size_t index);
|
||||
|
@ -382,7 +373,7 @@ public:
|
|||
bool generator_has_settings() const;
|
||||
void generator_user_config();
|
||||
|
||||
std::pair<level::TYPE, int> find_level_by_id(const std::string& id) const;
|
||||
std::pair<level_type::type, int> find_level_by_id(const std::string& id) const;
|
||||
int find_extra_by_id(const MP_EXTRA extra_type, const std::string& id) const;
|
||||
|
||||
const depcheck::manager& dependency_manager() const
|
||||
|
@ -412,7 +403,7 @@ private:
|
|||
|
||||
std::size_t map_level_index(std::size_t index) const;
|
||||
|
||||
level::TYPE current_level_type_;
|
||||
level_type::type current_level_type_;
|
||||
std::size_t current_level_index_;
|
||||
|
||||
std::size_t current_era_index_;
|
||||
|
@ -447,7 +438,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
std::map<level::TYPE, type_list> type_map_;
|
||||
std::map<level_type::type, type_list> type_map_;
|
||||
|
||||
std::vector<std::string> user_map_names_;
|
||||
std::vector<std::string> user_scenario_names_;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "game_initialization/component_availability.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "log.hpp"
|
||||
#include "utils/general.hpp"
|
||||
|
@ -69,9 +70,9 @@ manager::manager(const game_config_view& gamecfg, bool mp)
|
|||
DBG_MP << "Initializing the dependency manager" << std::endl;
|
||||
|
||||
for(const config& cfg : gamecfg.child_range("modification")) {
|
||||
component_availability type = cfg["type"].to_enum<component_availability>(component_availability::HYBRID);
|
||||
component_availability::type type = component_availability::get_enum(cfg["type"].str()).value_or(component_availability::type::hybrid);
|
||||
|
||||
if((type != component_availability::MP || mp) && (type != component_availability::SP || !mp)) {
|
||||
if((type != component_availability::type::mp || mp) && (type != component_availability::type::sp || !mp)) {
|
||||
config info;
|
||||
info["id"] = cfg["id"];
|
||||
info["name"] = cfg["name"];
|
||||
|
@ -85,9 +86,9 @@ manager::manager(const game_config_view& gamecfg, bool mp)
|
|||
}
|
||||
|
||||
for(const config& cfg : gamecfg.child_range("era")) {
|
||||
component_availability type = cfg["type"].to_enum<component_availability>(component_availability::MP);
|
||||
component_availability::type type = component_availability::get_enum(cfg["type"].str()).value_or(component_availability::type::mp);
|
||||
|
||||
if((type != component_availability::MP || mp) && (type != component_availability::SP || !mp)) {
|
||||
if((type != component_availability::type::mp || mp) && (type != component_availability::type::sp || !mp)) {
|
||||
config info;
|
||||
info["id"] = cfg["id"];
|
||||
info["name"] = cfg["name"];
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <vector>
|
||||
#include "config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
|
||||
class game_config_view;
|
||||
|
||||
|
@ -36,11 +35,6 @@ enum component_type
|
|||
MODIFICATION
|
||||
};
|
||||
|
||||
MAKE_ENUM(component_availability,
|
||||
(SP, "sp")
|
||||
(MP, "mp")
|
||||
(HYBRID, "hybrid")
|
||||
);
|
||||
/**
|
||||
* Note to all triers:
|
||||
* It's not guaranteed that the specified component will be selected
|
||||
|
|
32
src/game_initialization/level_type.hpp
Normal file
32
src/game_initialization/level_type.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct level_type_defines
|
||||
{
|
||||
static constexpr const char* const scenario = "scenario";
|
||||
static constexpr const char* const user_map = "user_map";
|
||||
static constexpr const char* const user_scenario = "user_scenario";
|
||||
static constexpr const char* const random_map = "random_map";
|
||||
static constexpr const char* const campaign = "campaign";
|
||||
static constexpr const char* const sp_campaign = "sp_campaign";
|
||||
|
||||
ENUM_AND_ARRAY(scenario, user_map, user_scenario, random_map, campaign, sp_campaign)
|
||||
};
|
||||
using level_type = string_enums::enum_base<level_type_defines>;
|
|
@ -129,7 +129,7 @@ game_info::game_info(const config& game, const std::vector<std::string>& install
|
|||
, time_limit()
|
||||
, vacant_slots()
|
||||
, current_turn(0)
|
||||
, reloaded(game["savegame"].to_enum<mp_game_settings::SAVED_GAME_MODE>(mp_game_settings::SAVED_GAME_MODE::NONE) != mp_game_settings::SAVED_GAME_MODE::NONE)
|
||||
, reloaded(saved_game_mode::get_enum(game["savegame"].str()).value_or(saved_game_mode::type::no) != saved_game_mode::type::no)
|
||||
, started(false)
|
||||
, fog(game["mp_fog"].to_bool())
|
||||
, shroud(game["mp_shroud"].to_bool())
|
||||
|
|
|
@ -65,7 +65,7 @@ config initial_level_config(saved_game& state)
|
|||
}
|
||||
|
||||
config& scenario = state.get_starting_point();
|
||||
if(state.mp_settings().saved_game == mp_game_settings::SAVED_GAME_MODE::NONE) {
|
||||
if(state.mp_settings().saved_game == saved_game_mode::type::no) {
|
||||
state.set_random_seed();
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ config initial_level_config(saved_game& state)
|
|||
const config& era_cfg = game_config.find_child("era", "id", era);
|
||||
|
||||
if(!era_cfg) {
|
||||
if(params.saved_game == mp_game_settings::SAVED_GAME_MODE::NONE) {
|
||||
if(params.saved_game == saved_game_mode::type::no) {
|
||||
throw config::error(VGETTEXT("Cannot find era '$era'", {{"era", era}}));
|
||||
}
|
||||
|
||||
|
@ -131,9 +131,9 @@ config initial_level_config(saved_game& state)
|
|||
|
||||
void level_to_gamestate(const config& level, saved_game& state)
|
||||
{
|
||||
game_classification::CAMPAIGN_TYPE type = state.classification().campaign_type;
|
||||
campaign_type::type type = state.classification().type;
|
||||
state = saved_game(level);
|
||||
state.classification().campaign_type = type;
|
||||
state.classification().type = type;
|
||||
}
|
||||
|
||||
} // end namespace mp
|
||||
|
|
|
@ -171,7 +171,7 @@ mp_manager::mp_manager(const std::optional<std::string> host)
|
|||
, lobby_info()
|
||||
, process_handlers()
|
||||
{
|
||||
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
state.classification().type = campaign_type::type::multiplayer;
|
||||
|
||||
if(host) {
|
||||
gui2::dialogs::loading_screen::display([&]() {
|
||||
|
@ -723,7 +723,7 @@ void start_local_game_commandline(const commandline_options& cmdline_opts)
|
|||
|
||||
// Set the default parameters
|
||||
saved_game state;
|
||||
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
state.classification().type = campaign_type::type::multiplayer;
|
||||
|
||||
mp_game_settings& parameters = state.mp_settings();
|
||||
|
||||
|
@ -748,7 +748,7 @@ void start_local_game_commandline(const commandline_options& cmdline_opts)
|
|||
// None of the other parameters need to be set, as their creation values above are good enough for CL mode.
|
||||
// In particular, we do not want to use the preferences values.
|
||||
|
||||
state.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
state.classification().type = campaign_type::type::multiplayer;
|
||||
|
||||
// [era] define.
|
||||
if(cmdline_opts.multiplayer_era) {
|
||||
|
|
|
@ -57,7 +57,7 @@ static lg::log_domain log_enginerefac("enginerefac");
|
|||
#define LOG_RG LOG_STREAM(info, log_enginerefac)
|
||||
|
||||
void campaign_controller::show_carryover_message(
|
||||
playsingle_controller& playcontroller, const end_level_data& end_level, const LEVEL_RESULT res)
|
||||
playsingle_controller& playcontroller, const end_level_data& end_level, const level_result::type res)
|
||||
{
|
||||
// We need to write the carryover amount to the team that's why we need non const
|
||||
std::vector<team>& teams = playcontroller.get_teams();
|
||||
|
@ -74,7 +74,7 @@ void campaign_controller::show_carryover_message(
|
|||
|
||||
if(obs) {
|
||||
title = _("Scenario Report");
|
||||
} else if(res == LEVEL_RESULT::VICTORY) {
|
||||
} else if(res == level_result::type::victory) {
|
||||
title = _("Victory");
|
||||
report << "<b>" << _("You have emerged victorious!") << "</b>";
|
||||
} else {
|
||||
|
@ -179,7 +179,7 @@ void campaign_controller::show_carryover_message(
|
|||
}
|
||||
}
|
||||
|
||||
LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data &end_level)
|
||||
level_result::type campaign_controller::playsingle_scenario(end_level_data &end_level)
|
||||
{
|
||||
const config& starting_point = is_replay_
|
||||
? state_.get_replay_starting_point()
|
||||
|
@ -192,9 +192,9 @@ LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data &end_level)
|
|||
playcontroller.enable_replay(is_unit_test_);
|
||||
}
|
||||
|
||||
LEVEL_RESULT res = playcontroller.play_scenario(starting_point);
|
||||
if(res == LEVEL_RESULT::QUIT) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
level_result::type res = playcontroller.play_scenario(starting_point);
|
||||
if(res == level_result::type::quit) {
|
||||
return level_result::type::quit;
|
||||
}
|
||||
|
||||
if(!is_unit_test_) {
|
||||
|
@ -216,19 +216,19 @@ LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data &end_level)
|
|||
return res;
|
||||
}
|
||||
|
||||
LEVEL_RESULT campaign_controller::playmp_scenario(end_level_data &end_level)
|
||||
level_result::type campaign_controller::playmp_scenario(end_level_data &end_level)
|
||||
{
|
||||
playmp_controller playcontroller(state_.get_starting_point(), state_, mp_info_);
|
||||
LEVEL_RESULT res = playcontroller.play_scenario(state_.get_starting_point());
|
||||
level_result::type res = playcontroller.play_scenario(state_.get_starting_point());
|
||||
|
||||
// Check if the player started as mp client and changed to host
|
||||
if(res == LEVEL_RESULT::QUIT) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
if(res == level_result::type::quit) {
|
||||
return level_result::type::quit;
|
||||
}
|
||||
|
||||
end_level = playcontroller.get_end_level_data();
|
||||
|
||||
if(res != LEVEL_RESULT::OBSERVER_END) {
|
||||
if(res != level_result::type::observer_end) {
|
||||
// We need to call this before linger because it prints the defeated/victory message.
|
||||
//(we want to see that message before entering the linger mode)
|
||||
show_carryover_message(playcontroller, end_level, res);
|
||||
|
@ -246,7 +246,7 @@ LEVEL_RESULT campaign_controller::playmp_scenario(end_level_data &end_level)
|
|||
return res;
|
||||
}
|
||||
|
||||
LEVEL_RESULT campaign_controller::play_game()
|
||||
level_result::type campaign_controller::play_game()
|
||||
{
|
||||
if(is_replay_) {
|
||||
state_.get_replay().set_pos(0);
|
||||
|
@ -257,7 +257,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
state_.expand_scenario();
|
||||
|
||||
while(state_.valid()) {
|
||||
LEVEL_RESULT res = LEVEL_RESULT::VICTORY;
|
||||
level_result::type res = level_result::type::victory;
|
||||
end_level_data end_level;
|
||||
|
||||
try {
|
||||
|
@ -286,34 +286,34 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
}
|
||||
} catch(const leavegame_wesnothd_error&) {
|
||||
LOG_NG << "The game was remotely ended\n";
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} catch(const game::load_game_failed& e) {
|
||||
gui2::show_error_message(_("The game could not be loaded: ") + e.message);
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} catch(const quit_game_exception&) {
|
||||
LOG_NG << "The game was aborted\n";
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} catch(const game::game_error& e) {
|
||||
gui2::show_error_message(_("Error while playing the game: ") + e.message);
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} catch(const incorrect_map_format_error& e) {
|
||||
gui2::show_error_message(_("The game map could not be loaded: ") + e.message);
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} catch(const mapgen_exception& e) {
|
||||
gui2::show_error_message(_("Map generator error: ") + e.message);
|
||||
} catch(const config::error& e) {
|
||||
gui2::show_error_message(_("Error while reading the WML: ") + e.message);
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} catch(const wml_exception& e) {
|
||||
e.show();
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
}
|
||||
|
||||
if(is_unit_test_) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if(res == LEVEL_RESULT::QUIT) {
|
||||
if(res == level_result::type::quit) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
// If there is no next scenario we're done now.
|
||||
if(state_.get_scenario_id().empty()) {
|
||||
// Don't show The End for multiplayer scenarios.
|
||||
if(res == LEVEL_RESULT::VICTORY && !state_.classification().is_normal_mp_game()) {
|
||||
if(res == level_result::type::victory && !state_.classification().is_normal_mp_game()) {
|
||||
preferences::add_completed_campaign(
|
||||
state_.classification().campaign, state_.classification().difficulty);
|
||||
|
||||
|
@ -348,7 +348,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
}
|
||||
|
||||
return res;
|
||||
} else if(res == LEVEL_RESULT::OBSERVER_END && mp_info_ && !mp_info_->is_host) {
|
||||
} else if(res == level_result::type::observer_end && mp_info_ && !mp_info_->is_host) {
|
||||
const int dlg_res = gui2::show_message(_("Game Over"),
|
||||
_("This scenario has ended. Do you want to continue the campaign?"),
|
||||
gui2::dialogs::message::yes_no_buttons);
|
||||
|
@ -360,8 +360,8 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
|
||||
if(mp_info_ && !mp_info_->is_host) {
|
||||
// Opens join game dialog to get a new gamestate.
|
||||
if(!mp::goto_mp_wait(res == LEVEL_RESULT::OBSERVER_END)) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
if(!mp::goto_mp_wait(res == level_result::type::observer_end)) {
|
||||
return level_result::type::quit;
|
||||
}
|
||||
|
||||
// The host should send the complete savegame now that also contains the carryover sides start.
|
||||
|
@ -379,8 +379,8 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
const bool is_mp = state_.classification().is_normal_mp_game();
|
||||
state_.mp_settings().num_turns = starting_pos["turns"].to_int(-1);
|
||||
|
||||
if(state_.mp_settings().saved_game == mp_game_settings::SAVED_GAME_MODE::MIDGAME) {
|
||||
state_.mp_settings().saved_game = mp_game_settings::SAVED_GAME_MODE::SCENARIO_START;
|
||||
if(state_.mp_settings().saved_game == saved_game_mode::type::midgame) {
|
||||
state_.mp_settings().saved_game = saved_game_mode::type::scenaro_start;
|
||||
}
|
||||
|
||||
state_.mp_settings().use_map_settings = starting_pos["force_lock_settings"].to_bool(!is_mp);
|
||||
|
@ -390,7 +390,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
if(!connect_engine.can_start_game() || (game_config::debug && state_.classification().is_multiplayer())) {
|
||||
// Opens staging dialog to allow users to make an adjustments for scenario.
|
||||
if(!mp::goto_mp_staging(connect_engine)) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
}
|
||||
} else {
|
||||
// Start the next scenario immediately.
|
||||
|
@ -422,7 +422,7 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
message = utils::interpolate_variables_into_string(message, &symbols);
|
||||
|
||||
gui2::show_error_message(message);
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
}
|
||||
|
||||
if(state_.classification().is_scenario()) {
|
||||
|
@ -431,5 +431,5 @@ LEVEL_RESULT campaign_controller::play_game()
|
|||
}
|
||||
}
|
||||
|
||||
return LEVEL_RESULT::VICTORY;
|
||||
return level_result::type::victory;
|
||||
}
|
||||
|
|
|
@ -62,8 +62,8 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
LEVEL_RESULT play_game();
|
||||
LEVEL_RESULT play_replay()
|
||||
level_result::type play_game();
|
||||
level_result::type play_replay()
|
||||
{
|
||||
is_replay_ = true;
|
||||
return play_game();
|
||||
|
@ -75,11 +75,11 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
LEVEL_RESULT playsingle_scenario(end_level_data& end_level);
|
||||
LEVEL_RESULT playmp_scenario(end_level_data& end_level);
|
||||
level_result::type playsingle_scenario(end_level_data& end_level);
|
||||
level_result::type playmp_scenario(end_level_data& end_level);
|
||||
|
||||
void show_carryover_message(
|
||||
playsingle_controller& playcontroller, const end_level_data& end_level, LEVEL_RESULT res);
|
||||
playsingle_controller& playcontroller, const end_level_data& end_level, level_result::type res);
|
||||
|
||||
saved_game& state_;
|
||||
const bool is_unit_test_;
|
||||
|
|
29
src/game_initialization/random_faction_mode.hpp
Normal file
29
src/game_initialization/random_faction_mode.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct random_faction_mode_defines
|
||||
{
|
||||
static constexpr const char* const independent = "Independent";
|
||||
static constexpr const char* const no_mirror = "No Mirror";
|
||||
static constexpr const char* const no_ally_mirror = "No Ally Mirror";
|
||||
|
||||
ENUM_AND_ARRAY(independent, no_mirror, no_ally_mirror)
|
||||
};
|
||||
using random_faction_mode = string_enums::enum_base<random_faction_mode_defines>;
|
29
src/game_initialization/saved_game_mode.hpp
Normal file
29
src/game_initialization/saved_game_mode.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct saved_game_mode_defines
|
||||
{
|
||||
static constexpr const char* const no = "no";
|
||||
static constexpr const char* const midgame = "midgame";
|
||||
static constexpr const char* const scenaro_start = "scenaro_start";
|
||||
|
||||
ENUM_AND_ARRAY(no, midgame, scenaro_start)
|
||||
};
|
||||
using saved_game_mode = string_enums::enum_base<saved_game_mode_defines>;
|
|
@ -35,10 +35,10 @@ bool select_campaign(saved_game& state, jump_to_campaign_info jump_to_campaign)
|
|||
{
|
||||
while(true) {
|
||||
ng::create_engine create_eng(state);
|
||||
create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN);
|
||||
create_eng.set_current_level_type(level_type::type::sp_campaign);
|
||||
|
||||
const std::vector<ng::create_engine::level_ptr> campaigns =
|
||||
create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN);
|
||||
create_eng.get_levels_by_type_unfiltered(level_type::type::sp_campaign);
|
||||
|
||||
if(campaigns.empty()) {
|
||||
gui2::show_error_message(_("No campaigns are available."));
|
||||
|
|
|
@ -434,7 +434,7 @@ bool game_launcher::init_lua_script()
|
|||
void game_launcher::set_test(const std::string& id)
|
||||
{
|
||||
state_.clear();
|
||||
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::TEST;
|
||||
state_.classification().type = campaign_type::type::test;
|
||||
state_.classification().campaign_define = "TEST";
|
||||
state_.classification().era_id = "era_default";
|
||||
|
||||
|
@ -553,11 +553,11 @@ game_launcher::unit_test_result game_launcher::single_unit_test()
|
|||
{
|
||||
game_config_manager::get()->load_game_config_for_game(state_.classification(), state_.get_scenario_id());
|
||||
|
||||
LEVEL_RESULT game_res = LEVEL_RESULT::TEST_FAIL;
|
||||
level_result::type game_res = level_result::type::fail;
|
||||
try {
|
||||
campaign_controller ccontroller(state_, true);
|
||||
game_res = ccontroller.play_game();
|
||||
if(game_res == LEVEL_RESULT::TEST_FAIL) {
|
||||
if(game_res == level_result::type::fail) {
|
||||
if(lg::broke_strict()) {
|
||||
return unit_test_result::BROKE_STRICT_TEST_FAIL;
|
||||
} else {
|
||||
|
@ -602,15 +602,15 @@ game_launcher::unit_test_result game_launcher::single_unit_test()
|
|||
return pass_victory_or_defeat(game_res);
|
||||
}
|
||||
|
||||
game_launcher::unit_test_result game_launcher::pass_victory_or_defeat(LEVEL_RESULT res)
|
||||
game_launcher::unit_test_result game_launcher::pass_victory_or_defeat(level_result::type res)
|
||||
{
|
||||
if(res == LEVEL_RESULT::DEFEAT) {
|
||||
if(res == level_result::type::defeat) {
|
||||
if(lg::broke_strict()) {
|
||||
return unit_test_result::BROKE_STRICT_TEST_FAIL_BY_DEFEAT;
|
||||
} else {
|
||||
return unit_test_result::TEST_FAIL_BY_DEFEAT;
|
||||
}
|
||||
} else if(res == LEVEL_RESULT::VICTORY) {
|
||||
} else if(res == level_result::type::victory) {
|
||||
if(lg::broke_strict()) {
|
||||
return unit_test_result::BROKE_STRICT_TEST_PASS_BY_VICTORY;
|
||||
} else {
|
||||
|
@ -645,8 +645,8 @@ bool game_launcher::play_render_image_mode()
|
|||
return true;
|
||||
}
|
||||
|
||||
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl;
|
||||
state_.classification().type = campaign_type::type::multiplayer;
|
||||
DBG_GENERAL << "Current campaign type: " << campaign_type::get_string(state_.classification().type) << std::endl;
|
||||
|
||||
try {
|
||||
game_config_manager::get()->load_game_config_for_game(state_.classification(), state_.get_scenario_id());
|
||||
|
@ -679,7 +679,7 @@ bool game_launcher::load_game()
|
|||
{
|
||||
assert(game_config_manager::get());
|
||||
|
||||
DBG_GENERAL << "Current campaign type: " << state_.classification().campaign_type << std::endl;
|
||||
DBG_GENERAL << "Current campaign type: " << campaign_type::get_string(state_.classification().type) << std::endl;
|
||||
|
||||
savegame::loadgame load(savegame::save_index_class::default_saves_dir(), state_);
|
||||
if(load_data_) {
|
||||
|
@ -753,7 +753,7 @@ bool game_launcher::load_game()
|
|||
bool game_launcher::new_campaign()
|
||||
{
|
||||
state_.clear();
|
||||
state_.classification().campaign_type = game_classification::CAMPAIGN_TYPE::SCENARIO;
|
||||
state_.classification().type = campaign_type::type::scenario;
|
||||
play_replay_ = false;
|
||||
|
||||
return sp::select_campaign(state_, jump_to_campaign_);
|
||||
|
|
|
@ -122,7 +122,7 @@ private:
|
|||
void start_wesnothd();
|
||||
|
||||
editor::EXIT_STATUS start_editor(const std::string& filename);
|
||||
unit_test_result pass_victory_or_defeat(LEVEL_RESULT res);
|
||||
unit_test_result pass_victory_or_defeat(level_result::type res);
|
||||
|
||||
/**
|
||||
* Internal to the implementation of unit_test(). If a single instance of
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "units/unit.hpp"
|
||||
#include "whiteboard/manager.hpp"
|
||||
#include "gui/dialogs/loading_screen.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
#include "side_controller.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
|
|
|
@ -16,26 +16,24 @@
|
|||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/core/placer.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include "gui/core/placer/horizontal_list.hpp"
|
||||
#include "gui/core/placer/vertical_list.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
placer_base* placer_base::build(const grow_direction grow_direction,
|
||||
const unsigned parallel_items)
|
||||
placer_base* placer_base::build(const grow_direction::type grow_dir, const unsigned parallel_items)
|
||||
{
|
||||
switch(grow_direction.v) {
|
||||
case grow_direction::horizontal:
|
||||
switch(grow_dir) {
|
||||
case grow_direction::type::horizontal:
|
||||
return new implementation::placer_horizontal_list(parallel_items);
|
||||
case grow_direction::vertical:
|
||||
case grow_direction::type::vertical:
|
||||
return new implementation::placer_vertical_list(parallel_items);
|
||||
default:
|
||||
throw "UNREACHABLE CODE REACHED"; // TODO: throw std::exception
|
||||
};
|
||||
|
||||
throw "UNREACHABLE CODE REACHED";
|
||||
}
|
||||
|
||||
placer_base::~placer_base()
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "utils/make_enum.hpp"
|
||||
#include "gui/grow_direction.hpp"
|
||||
|
||||
struct point;
|
||||
|
||||
|
@ -51,15 +51,6 @@ namespace gui2
|
|||
class placer_base
|
||||
{
|
||||
public:
|
||||
/***** ***** Types. ***** *****/
|
||||
|
||||
/** The direction the placer should grow towards. */
|
||||
MAKE_ENUM(grow_direction,
|
||||
(horizontal, "horizontal")
|
||||
(vertical, "vertical")
|
||||
);
|
||||
|
||||
|
||||
/***** ***** Constructor, destructor, assignment. ***** *****/
|
||||
|
||||
public:
|
||||
|
@ -68,7 +59,7 @@ public:
|
|||
*
|
||||
* @pre @p parallel_items > 0
|
||||
*
|
||||
* @param grow_direction The direction in which the items will be
|
||||
* @param grow_dir The direction in which the items will be
|
||||
* added.
|
||||
* @param parallel_items The direction perpendicular towards the grow
|
||||
* direction has a fixed number of items. This
|
||||
|
@ -76,8 +67,7 @@ public:
|
|||
* only horizontally or vertically placed items
|
||||
* the value should be 1.
|
||||
*/
|
||||
static placer_base* build(const grow_direction grow_direction,
|
||||
const unsigned parallel_items);
|
||||
static placer_base* build(const grow_direction::type grow_dir, const unsigned parallel_items);
|
||||
|
||||
virtual ~placer_base();
|
||||
|
||||
|
|
|
@ -412,8 +412,7 @@ void addon_manager::pre_show(window& window)
|
|||
order_dropdown.set_values(order_dropdown_entries);
|
||||
{
|
||||
const std::string saved_order_name = preferences::addon_manager_saved_order_name();
|
||||
const preferences::SORT_ORDER saved_order_direction =
|
||||
static_cast<preferences::SORT_ORDER>(preferences::addon_manager_saved_order_direction());
|
||||
const sort_order::type saved_order_direction = preferences::addon_manager_saved_order_direction();
|
||||
|
||||
if(!saved_order_name.empty()) {
|
||||
auto order_it = std::find_if(all_orders_.begin(), all_orders_.end(),
|
||||
|
@ -421,7 +420,7 @@ void addon_manager::pre_show(window& window)
|
|||
if(order_it != all_orders_.end()) {
|
||||
int index = 2 * (std::distance(all_orders_.begin(), order_it));
|
||||
addon_list::addon_sort_func func;
|
||||
if(saved_order_direction == preferences::SORT_ORDER::ASCENDING) {
|
||||
if(saved_order_direction == sort_order::type::ascending) {
|
||||
func = order_it->sort_func_asc;
|
||||
} else {
|
||||
func = order_it->sort_func_desc;
|
||||
|
@ -493,8 +492,7 @@ void addon_manager::pre_show(window& window)
|
|||
window.keyboard_capture(&filter);
|
||||
list.add_list_to_keyboard_chain();
|
||||
|
||||
list.set_callback_order_change(std::bind(&addon_manager::on_order_changed, this,
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
list.set_callback_order_change(std::bind(&addon_manager::on_order_changed, this, std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
// Use handle the special addon_list retval to allow installing addons on double click
|
||||
window.set_exit_hook(std::bind(&addon_manager::exit_hook, this, std::placeholders::_1));
|
||||
|
@ -709,9 +707,9 @@ void addon_manager::order_addons()
|
|||
{
|
||||
const menu_button& order_menu = find_widget<const menu_button>(get_window(), "order_dropdown", false);
|
||||
const addon_order& order_struct = all_orders_.at(order_menu.get_value() / 2);
|
||||
preferences::SORT_ORDER order = order_menu.get_value() % 2 == 0 ? preferences::SORT_ORDER::ASCENDING : preferences::SORT_ORDER::DESCENDING;
|
||||
sort_order::type order = order_menu.get_value() % 2 == 0 ? sort_order::type::ascending : sort_order::type::descending;
|
||||
addon_list::addon_sort_func func;
|
||||
if(order == preferences::SORT_ORDER::ASCENDING) {
|
||||
if(order == sort_order::type::ascending) {
|
||||
func = order_struct.sort_func_asc;
|
||||
} else {
|
||||
func = order_struct.sort_func_desc;
|
||||
|
@ -722,13 +720,13 @@ void addon_manager::order_addons()
|
|||
preferences::set_addon_manager_saved_order_direction(order);
|
||||
}
|
||||
|
||||
void addon_manager::on_order_changed(unsigned int sort_column, preferences::SORT_ORDER order)
|
||||
void addon_manager::on_order_changed(unsigned int sort_column, sort_order::type order)
|
||||
{
|
||||
menu_button& order_menu = find_widget<menu_button>(get_window(), "order_dropdown", false);
|
||||
auto order_it = std::find_if(all_orders_.begin(), all_orders_.end(),
|
||||
[sort_column](const addon_order& order) {return order.column_index == static_cast<int>(sort_column);});
|
||||
int index = 2 * (std::distance(all_orders_.begin(), order_it));
|
||||
if(order == preferences::SORT_ORDER::DESCENDING) {
|
||||
if(order == sort_order::type::descending) {
|
||||
++index;
|
||||
}
|
||||
order_menu.set_value(index);
|
||||
|
|
|
@ -152,7 +152,7 @@ private:
|
|||
|
||||
void apply_filters();
|
||||
void order_addons();
|
||||
void on_order_changed(unsigned int sort_column, preferences::SORT_ORDER order);
|
||||
void on_order_changed(unsigned int sort_column, sort_order::type order);
|
||||
void show_help();
|
||||
|
||||
boost::dynamic_bitset<> get_name_filter_visibility() const;
|
||||
|
|
|
@ -149,7 +149,7 @@ void campaign_selection::sort_campaigns(campaign_selection::CAMPAIGN_ORDER order
|
|||
{
|
||||
using level_ptr = ng::create_engine::level_ptr;
|
||||
|
||||
auto levels = engine_.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN);
|
||||
auto levels = engine_.get_levels_by_type_unfiltered(level_type::type::sp_campaign);
|
||||
|
||||
switch(order) {
|
||||
case RANK: // Already sorted by rank
|
||||
|
@ -313,7 +313,7 @@ void campaign_selection::pre_show(window& window)
|
|||
/***** Setup campaign details. *****/
|
||||
multi_page& pages = find_widget<multi_page>(&window, "campaign_details", false);
|
||||
|
||||
for(const auto& level : engine_.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN)) {
|
||||
for(const auto& level : engine_.get_levels_by_type_unfiltered(level_type::type::sp_campaign)) {
|
||||
const config& campaign = level->data();
|
||||
|
||||
/*** Add tree item ***/
|
||||
|
|
|
@ -52,15 +52,15 @@ editor_edit_side::editor_edit_side(editor::editor_team_info& info)
|
|||
|
||||
void editor_edit_side::pre_show(window& window)
|
||||
{
|
||||
controller_group.add_member(find_widget<toggle_button>(&window, "controller_human", false, true), side_controller::type::HUMAN);
|
||||
controller_group.add_member(find_widget<toggle_button>(&window, "controller_ai", false, true), side_controller::type::AI);
|
||||
controller_group.add_member(find_widget<toggle_button>(&window, "controller_null", false, true), side_controller::type::NONE);
|
||||
controller_group.add_member(find_widget<toggle_button>(&window, "controller_human", false, true), side_controller::type::human);
|
||||
controller_group.add_member(find_widget<toggle_button>(&window, "controller_ai", false, true), side_controller::type::ai);
|
||||
controller_group.add_member(find_widget<toggle_button>(&window, "controller_null", false, true), side_controller::type::none);
|
||||
|
||||
controller_group.set_member_states(controller_);
|
||||
|
||||
vision_group.add_member(find_widget<toggle_button>(&window, "vision_all", false, true), team::SHARE_VISION::ALL);
|
||||
vision_group.add_member(find_widget<toggle_button>(&window, "vision_shroud", false, true), team::SHARE_VISION::SHROUD);
|
||||
vision_group.add_member(find_widget<toggle_button>(&window, "vision_null", false, true), team::SHARE_VISION::NONE);
|
||||
vision_group.add_member(find_widget<toggle_button>(&window, "vision_all", false, true), team_shared_vision::type::all);
|
||||
vision_group.add_member(find_widget<toggle_button>(&window, "vision_shroud", false, true), team_shared_vision::type::shroud);
|
||||
vision_group.add_member(find_widget<toggle_button>(&window, "vision_null", false, true), team_shared_vision::type::none);
|
||||
|
||||
vision_group.set_member_states(share_vision_);
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
#include "editor/map/map_context.hpp"
|
||||
#include "gui/dialogs/modal_dialog.hpp"
|
||||
#include "gui/widgets/group.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "team.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -52,8 +52,8 @@ private:
|
|||
side_controller::type& controller_;
|
||||
group<side_controller::type> controller_group;
|
||||
|
||||
team::SHARE_VISION& share_vision_;
|
||||
group<team::SHARE_VISION> vision_group;
|
||||
team_shared_vision::type& share_vision_;
|
||||
group<team_shared_vision::type> vision_group;
|
||||
|
||||
virtual const std::string& window_id() const override;
|
||||
};
|
||||
|
|
|
@ -364,10 +364,11 @@ void game_load::evaluate_summary_string(std::stringstream& str, const config& cf
|
|||
|
||||
const std::string& campaign_type = cfg_summary["campaign_type"];
|
||||
const std::string campaign_id = cfg_summary["campaign"];
|
||||
auto campaign_type_enum = campaign_type::get_enum(campaign_type);
|
||||
|
||||
try {
|
||||
switch(game_classification::CAMPAIGN_TYPE::string_to_enum(campaign_type).v) {
|
||||
case game_classification::CAMPAIGN_TYPE::SCENARIO: {
|
||||
if(campaign_type_enum) {
|
||||
switch(*campaign_type_enum) {
|
||||
case campaign_type::type::scenario: {
|
||||
const config* campaign = nullptr;
|
||||
if(!campaign_id.empty()) {
|
||||
if(const config& c = cache_config_.find_child("campaign", "id", campaign_id)) {
|
||||
|
@ -391,17 +392,17 @@ void game_load::evaluate_summary_string(std::stringstream& str, const config& cf
|
|||
}
|
||||
break;
|
||||
}
|
||||
case game_classification::CAMPAIGN_TYPE::MULTIPLAYER:
|
||||
case campaign_type::type::multiplayer:
|
||||
str << _("Multiplayer");
|
||||
break;
|
||||
case game_classification::CAMPAIGN_TYPE::TUTORIAL:
|
||||
case campaign_type::type::tutorial:
|
||||
str << _("Tutorial");
|
||||
break;
|
||||
case game_classification::CAMPAIGN_TYPE::TEST:
|
||||
case campaign_type::type::test:
|
||||
str << _("Test scenario");
|
||||
break;
|
||||
}
|
||||
} catch(const bad_enum_cast&) {
|
||||
} else {
|
||||
str << campaign_type;
|
||||
}
|
||||
|
||||
|
@ -416,10 +417,10 @@ void game_load::evaluate_summary_string(std::stringstream& str, const config& cf
|
|||
}
|
||||
|
||||
str << "\n" << _("Difficulty: ");
|
||||
try {
|
||||
switch (game_classification::CAMPAIGN_TYPE::string_to_enum(campaign_type).v) {
|
||||
case game_classification::CAMPAIGN_TYPE::SCENARIO:
|
||||
case game_classification::CAMPAIGN_TYPE::MULTIPLAYER: {
|
||||
if(campaign_type_enum) {
|
||||
switch (*campaign_type_enum) {
|
||||
case campaign_type::type::scenario:
|
||||
case campaign_type::type::multiplayer: {
|
||||
const config* campaign = nullptr;
|
||||
if (!campaign_id.empty()) {
|
||||
if (const config& c = cache_config_.find_child("campaign", "id", campaign_id)) {
|
||||
|
@ -449,13 +450,12 @@ void game_load::evaluate_summary_string(std::stringstream& str, const config& cf
|
|||
|
||||
break;
|
||||
}
|
||||
case game_classification::CAMPAIGN_TYPE::TUTORIAL:
|
||||
case game_classification::CAMPAIGN_TYPE::TEST:
|
||||
case campaign_type::type::tutorial:
|
||||
case campaign_type::type::test:
|
||||
str << "—";
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (const bad_enum_cast&) {
|
||||
} else {
|
||||
str << "—";
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "game_board.hpp"
|
||||
#include "game_data.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "recall_list_manager.hpp"
|
||||
#include "team.hpp"
|
||||
#include "units/unit.hpp"
|
||||
|
|
|
@ -95,12 +95,12 @@ mp_create_game::mp_create_game(saved_game& state, bool local_mode)
|
|||
, local_mode_(local_mode)
|
||||
{
|
||||
level_types_ = {
|
||||
{ng::level::TYPE::SCENARIO, _("Scenarios")},
|
||||
{ng::level::TYPE::CAMPAIGN, _("Multiplayer Campaigns")},
|
||||
{ng::level::TYPE::SP_CAMPAIGN, _("Singleplayer Campaigns")},
|
||||
{ng::level::TYPE::USER_MAP, _("Custom Maps")},
|
||||
{ng::level::TYPE::USER_SCENARIO, _("Custom Scenarios")},
|
||||
{ng::level::TYPE::RANDOM_MAP, _("Random Maps")},
|
||||
{level_type::type::scenario, _("Scenarios")},
|
||||
{level_type::type::campaign, _("Multiplayer Campaigns")},
|
||||
{level_type::type::sp_campaign, _("Singleplayer Campaigns")},
|
||||
{level_type::type::user_map, _("Custom Maps")},
|
||||
{level_type::type::user_scenario, _("Custom Scenarios")},
|
||||
{level_type::type::random_map, _("Random Maps")},
|
||||
};
|
||||
|
||||
level_types_.erase(std::remove_if(level_types_.begin(), level_types_.end(),
|
||||
|
@ -108,18 +108,12 @@ mp_create_game::mp_create_game(saved_game& state, bool local_mode)
|
|||
return create_engine_.get_levels_by_type_unfiltered(type_info.first).empty();
|
||||
}), level_types_.end());
|
||||
|
||||
rfm_types_ = {
|
||||
mp_game_settings::RANDOM_FACTION_MODE::DEFAULT,
|
||||
mp_game_settings::RANDOM_FACTION_MODE::NO_MIRROR,
|
||||
mp_game_settings::RANDOM_FACTION_MODE::NO_ALLY_MIRROR,
|
||||
};
|
||||
|
||||
set_show_even_without_video(true);
|
||||
|
||||
create_engine_.init_active_mods();
|
||||
|
||||
create_engine_.get_state().clear();
|
||||
create_engine_.get_state().classification().campaign_type = game_classification::CAMPAIGN_TYPE::MULTIPLAYER;
|
||||
create_engine_.get_state().classification().type = campaign_type::type::multiplayer;
|
||||
|
||||
// Need to set this in the constructor, pre_show() is too late
|
||||
set_allow_plugin_skip(false);
|
||||
|
@ -181,7 +175,7 @@ void mp_create_game::pre_show(window& win)
|
|||
// Helper to make sure the initially selected level type is valid
|
||||
auto get_initial_type_index = [this]()->int {
|
||||
const auto index = std::find_if(level_types_.begin(), level_types_.end(), [](level_type_info& info) {
|
||||
return info.first == ng::level::TYPE::from_int(preferences::level_type());
|
||||
return info.first == *level_type::get_enum(preferences::level_type());
|
||||
});
|
||||
|
||||
if(index != level_types_.end()) {
|
||||
|
@ -259,23 +253,19 @@ void mp_create_game::pre_show(window& win)
|
|||
//
|
||||
// Set up random faction mode menu_button
|
||||
//
|
||||
static const std::array<t_string, random_faction_mode::size()> names {{_("Independent"), _("No Mirror"), _("No Ally Mirror")}};
|
||||
static const std::array<t_string, random_faction_mode::size()> tooltips {{
|
||||
_("Independent: Random factions assigned independently"),
|
||||
_("No Mirror: No two players will get the same faction"),
|
||||
_("No Ally Mirror: No two allied players will get the same faction")
|
||||
}};
|
||||
std::vector<config> rfm_options;
|
||||
for(const auto& type : rfm_types_) {
|
||||
// HACK: The labels are defined for the wesnoth textdomain in a header,
|
||||
// see mp_game_settings::RANDOM_FACTION_MODE in src/mp_game_settings.hpp
|
||||
rfm_options.emplace_back("label",
|
||||
translation::dsgettext("wesnoth", mp_game_settings::RANDOM_FACTION_MODE::enum_to_string(type).c_str())
|
||||
);
|
||||
for(std::size_t i = 0; i < random_faction_mode::size(); i++) {
|
||||
rfm_options.emplace_back("label", names[i]);
|
||||
rfm_options[i]["tooltip"] = tooltips[i];
|
||||
};
|
||||
|
||||
// Manually insert tooltips. Need to find a better way to do this
|
||||
rfm_options[0]["tooltip"] = _("Independent: Random factions assigned independently");
|
||||
rfm_options[1]["tooltip"] = _("No Mirror: No two players will get the same faction");
|
||||
rfm_options[2]["tooltip"] = _("No Ally Mirror: No two allied players will get the same faction");
|
||||
|
||||
const int initial_index = std::distance(rfm_types_.begin(), std::find(rfm_types_.begin(), rfm_types_.end(),
|
||||
mp_game_settings::RANDOM_FACTION_MODE::string_to_enum(prefs::random_faction_mode(), mp_game_settings::RANDOM_FACTION_MODE::DEFAULT))
|
||||
);
|
||||
const int initial_index = static_cast<int>(random_faction_mode::get_enum(prefs::random_faction_mode()).value_or(random_faction_mode::type::independent));
|
||||
|
||||
menu_button& rfm_menu_button = find_widget<menu_button>(&win, "random_faction_mode", false);
|
||||
|
||||
|
@ -388,7 +378,7 @@ void mp_create_game::pre_show(window& win)
|
|||
}, true);
|
||||
|
||||
plugins_context_->set_callback("select_type", [this](const config& cfg) {
|
||||
create_engine_.set_current_level_type(ng::level::TYPE::string_to_enum(cfg["type"], ng::level::TYPE::SCENARIO)); }, true);
|
||||
create_engine_.set_current_level_type(level_type::get_enum(cfg["type"].str()).value_or(level_type::type::scenario)); }, true);
|
||||
|
||||
plugins_context_->set_callback("select_era", [this](const config& cfg) {
|
||||
create_engine_.set_current_era_index(cfg["index"].to_int()); }, true);
|
||||
|
@ -405,7 +395,7 @@ void mp_create_game::pre_show(window& win)
|
|||
"icon", current_level.icon(),
|
||||
"description", current_level.description(),
|
||||
"allow_era_choice", current_level.allow_era_choice(),
|
||||
"type", create_engine_.current_level_type(),
|
||||
"type", level_type::get_string(create_engine_.current_level_type()),
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -413,7 +403,7 @@ void mp_create_game::pre_show(window& win)
|
|||
const std::string id = cfg["id"].str();
|
||||
return config {
|
||||
"index", create_engine_.find_level_by_id(id).second,
|
||||
"type", create_engine_.find_level_by_id(id).first,
|
||||
"type", level_type::get_string(create_engine_.find_level_by_id(id).first),
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -584,7 +574,7 @@ void mp_create_game::update_games_list()
|
|||
display_games_of_type(level_types_[index].first, create_engine_.current_level().id());
|
||||
}
|
||||
|
||||
void mp_create_game::display_games_of_type(ng::level::TYPE type, const std::string& level)
|
||||
void mp_create_game::display_games_of_type(level_type::type type, const std::string& level)
|
||||
{
|
||||
create_engine_.set_current_level_type(type);
|
||||
|
||||
|
@ -596,7 +586,7 @@ void mp_create_game::display_games_of_type(ng::level::TYPE type, const std::stri
|
|||
std::map<std::string, string_map> data;
|
||||
string_map item;
|
||||
|
||||
if(type == ng::level::TYPE::CAMPAIGN || type == ng::level::TYPE::SP_CAMPAIGN) {
|
||||
if(type == level_type::type::campaign || type == level_type::type::sp_campaign) {
|
||||
item["label"] = game->icon();
|
||||
data.emplace("game_icon", item);
|
||||
}
|
||||
|
@ -618,7 +608,7 @@ void mp_create_game::display_games_of_type(ng::level::TYPE type, const std::stri
|
|||
}
|
||||
}
|
||||
|
||||
const bool is_random_map = type == ng::level::TYPE::RANDOM_MAP;
|
||||
const bool is_random_map = type == level_type::type::random_map;
|
||||
|
||||
find_widget<button>(get_window(), "random_map_regenerate", false).set_active(is_random_map);
|
||||
find_widget<button>(get_window(), "random_map_settings", false).set_active(is_random_map);
|
||||
|
@ -654,7 +644,7 @@ void mp_create_game::update_details()
|
|||
styled_widget& players = find_widget<styled_widget>(get_window(), "map_num_players", false);
|
||||
styled_widget& map_size = find_widget<styled_widget>(get_window(), "map_size", false);
|
||||
|
||||
if(create_engine_.current_level_type() == ng::level::TYPE::RANDOM_MAP) {
|
||||
if(create_engine_.current_level_type() == level_type::type::random_map) {
|
||||
// If the current random map doesn't have data, generate it
|
||||
if(create_engine_.generator_assigned() &&
|
||||
create_engine_.current_level().data()["map_data"].empty() &&
|
||||
|
@ -679,11 +669,11 @@ void mp_create_game::update_details()
|
|||
|
||||
show_description(create_engine_.current_level().description());
|
||||
|
||||
switch(create_engine_.current_level_type().v) {
|
||||
case ng::level::TYPE::SCENARIO:
|
||||
case ng::level::TYPE::USER_MAP:
|
||||
case ng::level::TYPE::USER_SCENARIO:
|
||||
case ng::level::TYPE::RANDOM_MAP: {
|
||||
switch(create_engine_.current_level_type()) {
|
||||
case level_type::type::scenario:
|
||||
case level_type::type::user_map:
|
||||
case level_type::type::user_scenario:
|
||||
case level_type::type::random_map: {
|
||||
ng::scenario* current_scenario = dynamic_cast<ng::scenario*>(&create_engine_.current_level());
|
||||
|
||||
assert(current_scenario);
|
||||
|
@ -704,8 +694,8 @@ void mp_create_game::update_details()
|
|||
|
||||
break;
|
||||
}
|
||||
case ng::level::TYPE::CAMPAIGN:
|
||||
case ng::level::TYPE::SP_CAMPAIGN: {
|
||||
case level_type::type::campaign:
|
||||
case level_type::type::sp_campaign: {
|
||||
ng::campaign* current_campaign = dynamic_cast<ng::campaign*>(&create_engine_.current_level());
|
||||
|
||||
assert(current_campaign);
|
||||
|
@ -856,16 +846,16 @@ void mp_create_game::post_show(window& window)
|
|||
|
||||
if(get_retval() == retval::OK) {
|
||||
prefs::set_modifications(create_engine_.active_mods());
|
||||
prefs::set_level_type(create_engine_.current_level_type().v);
|
||||
prefs::set_level_type(static_cast<int>(create_engine_.current_level_type()));
|
||||
prefs::set_level(create_engine_.current_level().id());
|
||||
prefs::set_era(create_engine_.current_era().id);
|
||||
|
||||
create_engine_.prepare_for_era_and_mods();
|
||||
|
||||
if(create_engine_.current_level_type() == ng::level::TYPE::CAMPAIGN ||
|
||||
create_engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) {
|
||||
if(create_engine_.current_level_type() == level_type::type::campaign ||
|
||||
create_engine_.current_level_type() == level_type::type::sp_campaign) {
|
||||
create_engine_.prepare_for_campaign();
|
||||
} else if(create_engine_.current_level_type() == ng::level::TYPE::SCENARIO) {
|
||||
} else if(create_engine_.current_level_type() == level_type::type::scenario) {
|
||||
create_engine_.prepare_for_scenario();
|
||||
} else {
|
||||
// This means define= doesn't work for randomly generated scenarios
|
||||
|
@ -935,10 +925,11 @@ void mp_create_game::post_show(window& window)
|
|||
config_engine_->set_oos_debug(strict_sync_->get_widget_value(window));
|
||||
config_engine_->set_shuffle_sides(shuffle_sides_->get_widget_value(window));
|
||||
|
||||
config_engine_->set_random_faction_mode(rfm_types_[selected_rfm_index_]);
|
||||
random_faction_mode::type type = random_faction_mode::get_enum(selected_rfm_index_).value_or(random_faction_mode::type::independent);
|
||||
config_engine_->set_random_faction_mode(type);
|
||||
|
||||
// Since we don't have a field handling this option, we need to save the value manually
|
||||
prefs::set_random_faction_mode(mp_game_settings::RANDOM_FACTION_MODE::enum_to_string(rfm_types_[selected_rfm_index_]));
|
||||
prefs::set_random_faction_mode(random_faction_mode::get_string(type));
|
||||
|
||||
// Save custom option settings
|
||||
config_engine_->set_options(options_manager_->get_options_config());
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace dialogs
|
|||
|
||||
class mp_create_game : public modal_dialog, private plugin_executor
|
||||
{
|
||||
typedef std::pair<ng::level::TYPE, std::string> level_type_info;
|
||||
typedef std::pair<level_type::type, std::string> level_type_info;
|
||||
|
||||
public:
|
||||
mp_create_game(saved_game& state, bool local_mode);
|
||||
|
@ -60,23 +60,8 @@ private:
|
|||
|
||||
std::vector<level_type_info> level_types_;
|
||||
|
||||
/* We keep and work with a vector of the RFM types since it's the easiest way to get a value for the
|
||||
* config_engine and preferences setters, since menu_buttons aren't supported by field. Even if they
|
||||
* were, the above functions take a RANDOM_FACTION_MODE value, not an index. Even if we try to keep a
|
||||
* copy of the selected RFM type index in a int value and update it every time you perform a selection,
|
||||
* there's still the problem of getting an initial value from preferences, which again is provided as a
|
||||
* RANDOM_FACTION_MODE value. Comparing strings between the (translated) menu_button values in the WML and
|
||||
* the hardcoded (non-translated) RANDOM_FACTION_MODE string values stored in preferences is a horrible
|
||||
* way to do it and would break in any language other than English. Instead, we'll keep a vector and use
|
||||
* std::find to get the initial index. This method should also allow the values to eventually be translated,
|
||||
* since the string values don't come into consideration at all, save for populating the menu_button.
|
||||
*
|
||||
* - vultraz, 2016-08-21
|
||||
*/
|
||||
std::vector<mp_game_settings::RANDOM_FACTION_MODE> rfm_types_;
|
||||
|
||||
void update_games_list();
|
||||
void display_games_of_type(ng::level::TYPE type, const std::string& level);
|
||||
void display_games_of_type(level_type::type type, const std::string& level);
|
||||
|
||||
void show_generator_settings();
|
||||
void regenerate_random_map();
|
||||
|
|
|
@ -43,11 +43,11 @@
|
|||
#include "mp_ui_alerts.hpp"
|
||||
#include "preferences/credentials.hpp"
|
||||
#include "saved_game.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "statistics.hpp"
|
||||
#include "units/types.hpp"
|
||||
#include "utils/scope_exit.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
|
||||
static lg::log_domain log_mp_connect_engine("mp/connect/engine");
|
||||
#define DBG_MP LOG_STREAM(debug, log_mp_connect_engine)
|
||||
|
@ -312,9 +312,9 @@ bool mp_join_game::show_flg_select(int side_num, bool first_time)
|
|||
const bool is_mp = state_.classification().is_normal_mp_game();
|
||||
const bool lock_settings = get_scenario()["force_lock_settings"].to_bool(!is_mp);
|
||||
const bool use_map_settings = level_.child("multiplayer")["mp_use_map_settings"].to_bool();
|
||||
const mp_game_settings::SAVED_GAME_MODE saved_game = level_.child("multiplayer")["savegame"].to_enum<mp_game_settings::SAVED_GAME_MODE>(mp_game_settings::SAVED_GAME_MODE::NONE);
|
||||
const saved_game_mode::type saved_game = saved_game_mode::get_enum(level_.child("multiplayer")["savegame"].str()).value_or(saved_game_mode::type::no);
|
||||
|
||||
ng::flg_manager flg(era_factions, side_choice, lock_settings, use_map_settings, saved_game == mp_game_settings::SAVED_GAME_MODE::MIDGAME);
|
||||
ng::flg_manager flg(era_factions, side_choice, lock_settings, use_map_settings, saved_game == saved_game_mode::type::midgame);
|
||||
|
||||
{
|
||||
gui2::dialogs::faction_select flg_dialog(flg, color, side_num);
|
||||
|
|
|
@ -193,7 +193,7 @@ void mp_staging::add_side_node(ng::side_engine_ptr side)
|
|||
const bool lock_team = side->cfg()["team_lock"].to_bool(fls);
|
||||
const bool lock_color = side->cfg()["color_lock"].to_bool(fls);
|
||||
|
||||
const bool saved_game = connect_engine_.params().saved_game == mp_game_settings::SAVED_GAME_MODE::MIDGAME;
|
||||
const bool saved_game = connect_engine_.params().saved_game == saved_game_mode::type::midgame;
|
||||
|
||||
//
|
||||
// AI Algorithm
|
||||
|
|
|
@ -721,7 +721,7 @@ void preferences_dialog::post_build(window& window)
|
|||
hotkey_list.register_sorting_option(3, [this](const int i) { return !visible_hotkeys_[i]->scope[hotkey::SCOPE_EDITOR]; });
|
||||
hotkey_list.register_sorting_option(4, [this](const int i) { return !visible_hotkeys_[i]->scope[hotkey::SCOPE_MAIN_MENU]; });
|
||||
|
||||
hotkey_list.set_active_sorting_option({0, preferences::SORT_ORDER::ASCENDING}, true);
|
||||
hotkey_list.set_active_sorting_option({0, sort_order::type::ascending}, true);
|
||||
|
||||
connect_signal_mouse_left_click(
|
||||
find_widget<button>(&window, "btn_add_hotkey", false), std::bind(
|
||||
|
@ -861,7 +861,7 @@ void preferences_dialog::default_hotkey_callback()
|
|||
|
||||
// Set up the list again and reselect the default sorting option.
|
||||
listbox& hotkey_list = setup_hotkey_list();
|
||||
hotkey_list.set_active_sorting_option({0, preferences::SORT_ORDER::ASCENDING}, true);
|
||||
hotkey_list.set_active_sorting_option({0, sort_order::type::ascending}, true);
|
||||
|
||||
find_widget<multimenu_button>(get_window(), "hotkey_category_menu", false).reset_toggle_states();
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ void unit_create::pre_show(window& window)
|
|||
list.register_translatable_sorting_option(1, [this](const int i) { return (*units_[i]).type_name().str(); });
|
||||
|
||||
// Select the first entry on sort if no previous selection was provided.
|
||||
list.set_active_sorting_option({0, preferences::SORT_ORDER::ASCENDING}, choice_.empty());
|
||||
list.set_active_sorting_option({0, sort_order::type::ascending}, choice_.empty());
|
||||
|
||||
list_item_clicked();
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ namespace gui2::dialogs
|
|||
{
|
||||
|
||||
// Index 2 is by-level
|
||||
static listbox::order_pair sort_last {-1, preferences::SORT_ORDER::NONE};
|
||||
static listbox::order_pair sort_default { 2, preferences::SORT_ORDER::DESCENDING};
|
||||
static listbox::order_pair sort_last {-1, sort_order::type::none};
|
||||
static listbox::order_pair sort_default { 2, sort_order::type::descending};
|
||||
|
||||
REGISTER_DIALOG(unit_recall)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2020 - 2021
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
|
@ -14,12 +14,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
#include <array>
|
||||
|
||||
MAKE_ENUM (UNIT_ALIGNMENT,
|
||||
(LAWFUL, N_("lawful"))
|
||||
(NEUTRAL, N_("neutral"))
|
||||
(CHAOTIC, N_("chaotic"))
|
||||
(LIMINAL, N_("liminal"))
|
||||
)
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct grow_direction_defines
|
||||
{
|
||||
static constexpr const char* const horizontal = "horizontal";
|
||||
static constexpr const char* const vertical = "vertical";
|
||||
|
||||
ENUM_AND_ARRAY(horizontal, vertical)
|
||||
};
|
||||
using grow_direction = string_enums::enum_base<grow_direction_defines>;
|
29
src/gui/sort_order.hpp
Normal file
29
src/gui/sort_order.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct sort_order_defines
|
||||
{
|
||||
static constexpr const char* const none = "none";
|
||||
static constexpr const char* const ascending = "ascending";
|
||||
static constexpr const char* const descending = "descending";
|
||||
|
||||
ENUM_AND_ARRAY(none, ascending, descending)
|
||||
};
|
||||
using sort_order = string_enums::enum_base<sort_order_defines>;
|
|
@ -386,7 +386,7 @@ void addon_list::finalize_setup()
|
|||
list.register_sorting_option(3, [this](const int i) { return addon_vector_[i]->downloads; });
|
||||
list.register_translatable_sorting_option(4, [this](const int i) { return addon_vector_[i]->display_type(); });
|
||||
|
||||
auto order = std::pair(0, preferences::SORT_ORDER::ASCENDING);
|
||||
auto order = std::pair(0, sort_order::type::ascending);
|
||||
list.set_active_sorting_option(order);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ public:
|
|||
void add_list_to_keyboard_chain();
|
||||
|
||||
/** Sets up a callback that will be called when the player changes the sorting order. */
|
||||
void set_callback_order_change(std::function<void(unsigned, preferences::SORT_ORDER)> callback) {
|
||||
void set_callback_order_change(std::function<void(unsigned, sort_order::type)> callback) {
|
||||
get_listbox().set_callback_order_change(callback);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
|
||||
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
|
||||
|
||||
using SORT_ORDER = preferences::SORT_ORDER;
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
// ------------ WIDGET -----------{
|
||||
|
@ -596,20 +594,20 @@ void listbox::order_by_column(unsigned column, widget& widget)
|
|||
|
||||
for(auto& pair : orders_) {
|
||||
if(pair.first != nullptr && pair.first != &selectable) {
|
||||
pair.first->set_value(preferences::SORT_ORDER::NONE);
|
||||
pair.first->set_value(static_cast<unsigned int>(sort_order::type::none));
|
||||
}
|
||||
}
|
||||
|
||||
SORT_ORDER order {static_cast<SORT_ORDER::type>(selectable.get_value())};
|
||||
sort_order::type order = sort_order::get_enum(selectable.get_value()).value_or(sort_order::type::none);
|
||||
|
||||
if(static_cast<unsigned int>(order.v) > orders_[column].second.size()) {
|
||||
if(static_cast<unsigned int>(order) > orders_[column].second.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(order == SORT_ORDER::NONE) {
|
||||
if(order == sort_order::type::none) {
|
||||
order_by(std::less<unsigned>());
|
||||
} else {
|
||||
order_by(orders_[column].second[order.v - 1]);
|
||||
order_by(orders_[column].second[static_cast<unsigned int>(order) - 1]);
|
||||
}
|
||||
|
||||
if(callback_order_change_ != nullptr) {
|
||||
|
@ -652,7 +650,7 @@ void listbox::set_active_sorting_option(const order_pair& sort_by, const bool se
|
|||
// Set the sorting toggle widgets' value (in this case, its state) to the given sorting
|
||||
// order. This is necessary since the widget's value is used to determine the order in
|
||||
// @ref order_by_column in lieu of a direction being passed directly.
|
||||
w.set_value(static_cast<int>(sort_by.second.v));
|
||||
w.set_value(static_cast<int>(sort_by.second));
|
||||
|
||||
order_by_column(sort_by.first, dynamic_cast<widget&>(w));
|
||||
|
||||
|
@ -665,20 +663,21 @@ const listbox::order_pair listbox::get_active_sorting_option()
|
|||
{
|
||||
for(unsigned int column = 0; column < orders_.size(); ++column) {
|
||||
selectable_item* w = orders_[column].first;
|
||||
sort_order::type sort = sort_order::get_enum(w->get_value()).value_or(sort_order::type::none);
|
||||
|
||||
if(w && w->get_value() != SORT_ORDER::NONE) {
|
||||
return std::pair(column, static_cast<SORT_ORDER::type>(w->get_value()));
|
||||
if(w && sort != sort_order::type::none) {
|
||||
return std::pair(column, sort);
|
||||
}
|
||||
}
|
||||
|
||||
return std::pair(-1, SORT_ORDER::NONE);
|
||||
return std::pair(-1, sort_order::type::none);
|
||||
}
|
||||
|
||||
void listbox::mark_as_unsorted()
|
||||
{
|
||||
for(auto& pair : orders_) {
|
||||
if(pair.first != nullptr) {
|
||||
pair.first->set_value(SORT_ORDER::NONE);
|
||||
pair.first->set_value(static_cast<unsigned int>(sort_order::type::none));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -282,7 +282,7 @@ public:
|
|||
/** Registers a special sorting function specifically for translatable values. */
|
||||
void register_translatable_sorting_option(const int col, translatable_sorter_func_t f);
|
||||
|
||||
using order_pair = std::pair<int, preferences::SORT_ORDER>;
|
||||
using order_pair = std::pair<int, sort_order::type>;
|
||||
|
||||
/**
|
||||
* Sorts the listbox by a pre-set sorting option. The corresponding header widget will also be toggled.
|
||||
|
@ -303,7 +303,7 @@ public:
|
|||
void mark_as_unsorted();
|
||||
|
||||
/** Registers a callback to be called when the active sorting option changes. */
|
||||
void set_callback_order_change(std::function<void(unsigned, preferences::SORT_ORDER)> callback)
|
||||
void set_callback_order_change(std::function<void(unsigned, sort_order::type)> callback)
|
||||
{
|
||||
callback_order_change_ = callback;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ private:
|
|||
typedef std::vector<std::pair<selectable_item*, generator_sort_array>> torder_list;
|
||||
torder_list orders_;
|
||||
|
||||
std::function<void(unsigned, preferences::SORT_ORDER)> callback_order_change_;
|
||||
std::function<void(unsigned, sort_order::type)> callback_order_change_;
|
||||
|
||||
/**
|
||||
* Resizes the content.
|
||||
|
|
|
@ -110,7 +110,7 @@ pane::pane(const implementation::builder_pane& builder)
|
|||
, items_()
|
||||
, item_builder_(builder.item_definition)
|
||||
, item_id_generator_(0)
|
||||
, placer_(placer_base::build(builder.grow_direction, builder.parallel_items))
|
||||
, placer_(placer_base::build(builder.grow_dir, builder.parallel_items))
|
||||
{
|
||||
connect_signal<event::REQUEST_PLACEMENT>(
|
||||
std::bind(
|
||||
|
@ -375,8 +375,7 @@ namespace implementation
|
|||
|
||||
builder_pane::builder_pane(const config& cfg)
|
||||
: builder_widget(cfg)
|
||||
, grow_direction(
|
||||
lexical_cast<placer_base::grow_direction>(cfg["grow_direction"]))
|
||||
, grow_dir(*grow_direction::get_enum(cfg["grow_direction"].str()))
|
||||
, parallel_items(cfg["parallel_items"])
|
||||
, item_definition(new builder_grid(cfg.child("item_definition", "[pane]")))
|
||||
{
|
||||
|
|
|
@ -209,7 +209,7 @@ struct builder_pane : public builder_widget
|
|||
|
||||
virtual widget* build(const replacements_map& replacements) const override;
|
||||
|
||||
placer_base::grow_direction grow_direction;
|
||||
grow_direction::type grow_dir;
|
||||
|
||||
unsigned parallel_items;
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ void unit_preview_pane::set_displayed_type(const unit_type& type)
|
|||
}
|
||||
|
||||
if(icon_alignment_) {
|
||||
const std::string& alignment_name = type.alignment().to_string();
|
||||
const std::string& alignment_name = unit_alignments::get_string(type.alignment());
|
||||
|
||||
icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
|
||||
icon_alignment_->set_tooltip(unit_type::alignment_description(
|
||||
|
@ -326,7 +326,7 @@ void unit_preview_pane::set_displayed_type(const unit_type& type)
|
|||
std::string l_str = VGETTEXT("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
|
||||
str << l_str << "\n";
|
||||
|
||||
str << type.alignment() << "\n";
|
||||
str << unit_alignments::get_string(type.alignment()) << "\n";
|
||||
|
||||
str << "\n"; // Leave a blank line where traits would be
|
||||
|
||||
|
@ -460,7 +460,7 @@ void unit_preview_pane::set_displayed_unit(const unit& u)
|
|||
}
|
||||
|
||||
if(icon_alignment_) {
|
||||
const std::string& alignment_name = u.alignment().to_string();
|
||||
const std::string& alignment_name = unit_alignments::get_string(u.alignment());
|
||||
|
||||
icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
|
||||
icon_alignment_->set_tooltip(unit_type::alignment_description(
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "hotkey/hotkey_command.hpp" // for is_scope_active, etc
|
||||
#include "picture.hpp" // for get_image, locator
|
||||
#include "log.hpp" // for LOG_STREAM, logger, etc
|
||||
#include "utils/make_enum.hpp" // for operator<<
|
||||
#include "map/map.hpp" // for gamemap
|
||||
#include "font/standard_colors.hpp" // for NORMAL_COLOR
|
||||
#include "font/sdl_ttf_compat.hpp"
|
||||
|
@ -422,10 +421,10 @@ std::vector<topic> generate_time_of_day_topics(const bool /*sort_generated*/)
|
|||
const std::string image_liminal = "<img>src='icons/alignments/alignment_liminal_30.png'</img>";
|
||||
std::stringstream text;
|
||||
|
||||
const int lawful_bonus = generic_combat_modifier(time.lawful_bonus, unit_type::ALIGNMENT::LAWFUL, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int neutral_bonus = generic_combat_modifier(time.lawful_bonus, unit_type::ALIGNMENT::NEUTRAL, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int chaotic_bonus = generic_combat_modifier(time.lawful_bonus, unit_type::ALIGNMENT::CHAOTIC, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int liminal_bonus = generic_combat_modifier(time.lawful_bonus, unit_type::ALIGNMENT::LIMINAL, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int lawful_bonus = generic_combat_modifier(time.lawful_bonus, unit_alignments::type::lawful, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int neutral_bonus = generic_combat_modifier(time.lawful_bonus, unit_alignments::type::neutral, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int chaotic_bonus = generic_combat_modifier(time.lawful_bonus, unit_alignments::type::chaotic, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
const int liminal_bonus = generic_combat_modifier(time.lawful_bonus, unit_alignments::type::liminal, false, resources::tod_manager->get_max_liminal_bonus());
|
||||
|
||||
toplevel << make_link(time.name.str(), id) << jump_to(160) << image << jump(30) <<
|
||||
image_lawful << time_of_day_bonus_colored(lawful_bonus) << jump_to(390) <<
|
||||
|
|
34
src/level_result.hpp
Normal file
34
src/level_result.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct level_result_defines
|
||||
{
|
||||
static constexpr const char* const victory = "victory";
|
||||
static constexpr const char* const defeat = "defeat";
|
||||
static constexpr const char* const quit = "quit";
|
||||
static constexpr const char* const observer_end = "observer_end";
|
||||
static constexpr const char* const result_not_set = "result_not_set";
|
||||
static constexpr const char* const pass = "pass";
|
||||
static constexpr const char* const fail = "fail";
|
||||
static constexpr const char* const test_invalid = "test_invalid";
|
||||
|
||||
ENUM_AND_ARRAY(victory, defeat, quit, observer_end, result_not_set, pass, fail, test_invalid)
|
||||
};
|
||||
using level_result = string_enums::enum_base<level_result_defines>;
|
|
@ -42,6 +42,7 @@
|
|||
#define DEBUG_THROW(id) throw id;
|
||||
#else
|
||||
|
||||
// TODO: delete
|
||||
#ifdef __FreeBSD__
|
||||
#define __LONG_LONG_SUPPORTED
|
||||
#endif
|
||||
|
|
|
@ -1715,7 +1715,7 @@ void console_handler::do_controller()
|
|||
|
||||
std::string report = side_controller::get_string(menu_handler_.board().get_team(side_num).controller());
|
||||
if(!menu_handler_.board().get_team(side_num).is_proxy_human()) {
|
||||
report += " (" + menu_handler_.board().get_team(side_num).proxy_controller().to_string() + ")";
|
||||
report += " (" + side_proxy_controller::get_string(menu_handler_.board().get_team(side_num).proxy_controller()) + ")";
|
||||
}
|
||||
|
||||
if(menu_handler_.board().get_team(side_num).is_network()) {
|
||||
|
@ -1992,8 +1992,8 @@ void console_handler::do_unit()
|
|||
}
|
||||
|
||||
if(parameters[0] == "alignment") {
|
||||
unit_type::ALIGNMENT alignment;
|
||||
if(!alignment.parse(parameters[1])) {
|
||||
auto alignment = unit_alignments::get_enum(parameters[1]);
|
||||
if(!alignment) {
|
||||
utils::string_map symbols;
|
||||
symbols["alignment"] = get_arg(1);
|
||||
command_failed(VGETTEXT(
|
||||
|
|
|
@ -54,8 +54,8 @@ mp_game_settings::mp_game_settings() :
|
|||
allow_observers(true),
|
||||
private_replay(false),
|
||||
shuffle_sides(false),
|
||||
saved_game(SAVED_GAME_MODE::NONE),
|
||||
random_faction_mode(RANDOM_FACTION_MODE::DEFAULT),
|
||||
saved_game(saved_game_mode::type::no),
|
||||
mode(random_faction_mode::type::independent),
|
||||
options(),
|
||||
addons()
|
||||
{}
|
||||
|
@ -85,8 +85,8 @@ mp_game_settings::mp_game_settings(const config& cfg)
|
|||
, allow_observers(cfg["observer"].to_bool())
|
||||
, private_replay(cfg["private_replay"].to_bool())
|
||||
, shuffle_sides(cfg["shuffle_sides"].to_bool())
|
||||
, saved_game(cfg["savegame"].to_enum<SAVED_GAME_MODE>(SAVED_GAME_MODE::NONE))
|
||||
, random_faction_mode(cfg["random_faction_mode"].to_enum<RANDOM_FACTION_MODE>(RANDOM_FACTION_MODE::DEFAULT))
|
||||
, saved_game(saved_game_mode::get_enum(cfg["savegame"].str()).value_or(saved_game_mode::type::no))
|
||||
, mode(random_faction_mode::get_enum(cfg["random_faction_mode"].str()).value_or(random_faction_mode::type::independent))
|
||||
, options(cfg.child_or_empty("options"))
|
||||
, addons()
|
||||
{
|
||||
|
@ -124,8 +124,8 @@ config mp_game_settings::to_config() const
|
|||
cfg["observer"] = allow_observers;
|
||||
cfg["private_replay"] = private_replay;
|
||||
cfg["shuffle_sides"] = shuffle_sides;
|
||||
cfg["random_faction_mode"] = random_faction_mode;
|
||||
cfg["savegame"] = saved_game;
|
||||
cfg["random_faction_mode"] = random_faction_mode::get_string(mode);
|
||||
cfg["savegame"] = saved_game_mode::get_string(saved_game);
|
||||
cfg.add_child("options", options);
|
||||
|
||||
for(auto& p : addons) {
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "game_initialization/random_faction_mode.hpp"
|
||||
#include "game_initialization/saved_game_mode.hpp"
|
||||
#include "game_version.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
||||
struct mp_game_settings
|
||||
|
@ -57,25 +59,9 @@ struct mp_game_settings
|
|||
bool private_replay;
|
||||
bool shuffle_sides;
|
||||
|
||||
MAKE_ENUM(SAVED_GAME_MODE,
|
||||
(NONE, "no")
|
||||
(MIDGAME, "midgame")
|
||||
(SCENARIO_START, "scenaro_start")
|
||||
)
|
||||
saved_game_mode::type saved_game;
|
||||
|
||||
SAVED_GAME_MODE saved_game;
|
||||
|
||||
// HACK: The Create Game dialog has special knowledge of these strings
|
||||
// and the fact that they're placed in the default (wesnoth)
|
||||
// textdomain by xgettext due to the absence of a GETTEXT_DOMAIN
|
||||
// declaration in this file. See gui2::dialogs::mp_create_game::pre_show().
|
||||
MAKE_ENUM(RANDOM_FACTION_MODE,
|
||||
(DEFAULT, N_("Independent"))
|
||||
(NO_MIRROR, N_("No Mirror"))
|
||||
(NO_ALLY_MIRROR, N_("No Ally Mirror"))
|
||||
)
|
||||
|
||||
RANDOM_FACTION_MODE random_faction_mode;
|
||||
random_faction_mode::type mode;
|
||||
|
||||
config options;
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ void playsingle_controller::play_scenario_main_loop()
|
|||
} // end for loop
|
||||
}
|
||||
|
||||
LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
||||
level_result::type playsingle_controller::play_scenario(const config& level)
|
||||
{
|
||||
LOG_NG << "in playsingle_controller::play_scenario()...\n";
|
||||
|
||||
|
@ -292,7 +292,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
saved_game_.set_snapshot(config());
|
||||
|
||||
// this is probably only a story scenario, i.e. has its endlevel in the prestart event
|
||||
return LEVEL_RESULT::VICTORY;
|
||||
return level_result::type::victory;
|
||||
}
|
||||
|
||||
if(linger_) {
|
||||
|
@ -303,14 +303,14 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
persist_.end_transaction();
|
||||
}
|
||||
|
||||
return LEVEL_RESULT::VICTORY;
|
||||
return level_result::type::victory;
|
||||
}
|
||||
|
||||
pump().fire(is_victory ? "local_victory" : "local_defeat");
|
||||
|
||||
{ // Block for set_scontext_synced_base
|
||||
set_scontext_synced_base sync;
|
||||
pump().fire(end_level.proceed_to_next_level ? "victory" : "defeat");
|
||||
pump().fire(end_level.proceed_to_next_level ? level_result::victory : level_result::defeat);
|
||||
pump().fire("scenario_end");
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
|
||||
if(is_observer()) {
|
||||
gui2::show_transient_message(_("Game Over"), _("The game is over."));
|
||||
return LEVEL_RESULT::OBSERVER_END;
|
||||
return level_result::type::observer_end;
|
||||
}
|
||||
|
||||
// If we're a player, and the result is victory/defeat, then send
|
||||
|
@ -329,7 +329,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
"info", config {
|
||||
"type", "termination",
|
||||
"condition", "game over",
|
||||
"result", is_victory ? "victory" : "defeat",
|
||||
"result", is_victory ? level_result::victory : level_result::defeat,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -349,9 +349,9 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
|
||||
persist_.end_transaction();
|
||||
|
||||
LEVEL_RESULT res = LEVEL_RESULT::string_to_enum(end_level.test_result);
|
||||
if(res == LEVEL_RESULT::TEST_NOT_SET) {
|
||||
return is_victory ? LEVEL_RESULT::VICTORY : LEVEL_RESULT::DEFEAT;
|
||||
level_result::type res = level_result::get_enum(end_level.test_result).value_or(level_result::type::test_invalid);
|
||||
if(res == level_result::type::result_not_set) {
|
||||
return is_victory ? level_result::type::victory : level_result::type::defeat;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const config& level)
|
|||
}
|
||||
|
||||
if(dynamic_cast<const ingame_wesnothd_error*>(&e)) {
|
||||
return LEVEL_RESULT::QUIT;
|
||||
return level_result::type::quit;
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
|
@ -439,7 +439,7 @@ void playsingle_controller::play_side_impl()
|
|||
} else {
|
||||
// we should have skipped over empty controllers before so this shouldn't be possible
|
||||
ERR_NG << "Found invalid side controller " << side_controller::get_string(current_team().controller()) << " ("
|
||||
<< current_team().proxy_controller().to_string() << ") for side " << current_team().side() << "\n";
|
||||
<< side_proxy_controller::get_string(current_team().proxy_controller()) << ") for side " << current_team().side() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class playsingle_controller : public play_controller
|
|||
public:
|
||||
playsingle_controller(const config& level, saved_game& state_of_game, bool skip_replay);
|
||||
|
||||
LEVEL_RESULT play_scenario(const config& level);
|
||||
level_result::type play_scenario(const config& level);
|
||||
void play_scenario_init();
|
||||
void play_scenario_main_loop();
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "gettext.hpp" // for _
|
||||
#include "gui/dialogs/simple_item_selector.hpp"
|
||||
#include "log.hpp" // for LOG_STREAM, logger, etc
|
||||
#include "utils/make_enum.hpp" // for bad_enum_cast
|
||||
#include "map/label.hpp"
|
||||
#include "play_controller.hpp" // for play_controller
|
||||
#include "playturn_network_adapter.hpp" // for playturn_network_adapter
|
||||
|
@ -238,12 +237,12 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
throw ingame_wesnothd_error("");
|
||||
}
|
||||
|
||||
if (ctrl == side_controller::type::AI) {
|
||||
if (ctrl == side_controller::type::ai) {
|
||||
resources::gameboard->side_drop_to(side_drop, *ctrl);
|
||||
return restart ? PROCESS_RESTART_TURN:PROCESS_CONTINUE;
|
||||
}
|
||||
//null controlled side cannot be dropped because they aren't controlled by anyone.
|
||||
else if (ctrl != side_controller::type::HUMAN) {
|
||||
else if (ctrl != side_controller::type::human) {
|
||||
ERR_NW << "unknown controller type issued from server on side drop: " << side_controller::get_string(*ctrl) << std::endl;
|
||||
throw ingame_wesnothd_error("");
|
||||
}
|
||||
|
@ -317,7 +316,7 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
|
||||
{
|
||||
// Server thinks this side is ours now so in case of error transferring side we have to make local state to same as what server thinks it is.
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::HUMAN, team::PROXY_CONTROLLER::PROXY_IDLE);
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::human, side_proxy_controller::type::idle);
|
||||
}
|
||||
|
||||
if (action < first_observer_option_idx) {
|
||||
|
@ -336,17 +335,17 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
|
|||
switch(action) {
|
||||
case 0:
|
||||
resources::controller->on_not_observer();
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::HUMAN, team::PROXY_CONTROLLER::PROXY_AI);
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::human, side_proxy_controller::type::ai);
|
||||
|
||||
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
|
||||
|
||||
case 1:
|
||||
resources::controller->on_not_observer();
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::HUMAN, team::PROXY_CONTROLLER::PROXY_HUMAN);
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::human, side_proxy_controller::type::human);
|
||||
|
||||
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
|
||||
case 2:
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::HUMAN, team::PROXY_CONTROLLER::PROXY_IDLE);
|
||||
resources::gameboard->side_drop_to(side_drop, side_controller::type::human, side_proxy_controller::type::idle);
|
||||
|
||||
return restart?PROCESS_RESTART_TURN:PROCESS_CONTINUE;
|
||||
|
||||
|
|
|
@ -976,14 +976,14 @@ void set_addon_manager_saved_order_name(const std::string& value)
|
|||
set("addon_manager_saved_order_name", value);
|
||||
}
|
||||
|
||||
SORT_ORDER addon_manager_saved_order_direction()
|
||||
sort_order::type addon_manager_saved_order_direction()
|
||||
{
|
||||
return SORT_ORDER::string_to_enum(get("addon_manager_saved_order_direction"), SORT_ORDER::NONE);
|
||||
return sort_order::get_enum(get("addon_manager_saved_order_direction")).value_or(sort_order::type::none);
|
||||
}
|
||||
|
||||
void set_addon_manager_saved_order_direction(SORT_ORDER value)
|
||||
void set_addon_manager_saved_order_direction(sort_order::type value)
|
||||
{
|
||||
set("addon_manager_saved_order_direction", SORT_ORDER::enum_to_string(value));
|
||||
set("addon_manager_saved_order_direction", sort_order::get_string(value));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "gui/sort_order.hpp"
|
||||
#include "terrain/translation.hpp"
|
||||
#include "utils/make_enum.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
@ -256,13 +256,7 @@ namespace preferences {
|
|||
std::string addon_manager_saved_order_name();
|
||||
void set_addon_manager_saved_order_name(const std::string& value);
|
||||
|
||||
// Sorting for GUI2 listboxes
|
||||
MAKE_ENUM(SORT_ORDER,
|
||||
(NONE, "none")
|
||||
(ASCENDING, "ascending")
|
||||
(DESCENDING, "descending")
|
||||
)
|
||||
SORT_ORDER addon_manager_saved_order_direction();
|
||||
void set_addon_manager_saved_order_direction(SORT_ORDER value);
|
||||
sort_order::type addon_manager_saved_order_direction();
|
||||
void set_addon_manager_saved_order_direction(sort_order::type value);
|
||||
|
||||
} // end namespace preferences
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "units/unit.hpp"
|
||||
#include "units/helper.hpp"
|
||||
#include "units/types.hpp"
|
||||
#include "units/unit_alignments.hpp"
|
||||
#include "whiteboard/manager.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
@ -370,7 +371,7 @@ static config unit_alignment(reports::context & rc, const unit* u, const map_loc
|
|||
if (!u) return config();
|
||||
std::ostringstream str, tooltip;
|
||||
const std::string align = unit_type::alignment_description(u->alignment(), u->gender());
|
||||
const std::string align_id = u->alignment().to_string();
|
||||
const std::string align_id = unit_alignments::get_string(u->alignment());
|
||||
const time_of_day effective_tod = get_visible_time_of_day_at(rc, hex);
|
||||
int cm = combat_modifier(effective_tod, u->alignment(), u->is_fearless());
|
||||
|
||||
|
@ -1265,7 +1266,7 @@ static config time_of_day_at(reports::context & rc, const map_location& mouseove
|
|||
time_of_day tod = get_visible_time_of_day_at(rc, mouseover_hex);
|
||||
|
||||
int b = tod.lawful_bonus;
|
||||
int l = generic_combat_modifier(b, unit_type::ALIGNMENT::LIMINAL, false, rc.tod().get_max_liminal_bonus());
|
||||
int l = generic_combat_modifier(b, unit_alignments::type::liminal, false, rc.tod().get_max_liminal_bonus());
|
||||
std::string lawful_color("white");
|
||||
std::string chaotic_color("white");
|
||||
std::string liminal_color("white");
|
||||
|
@ -1318,7 +1319,7 @@ static config unit_box_at(reports::context & rc, const map_location& mouseover_h
|
|||
time_of_day local_tod = get_visible_time_of_day_at(rc, mouseover_hex);
|
||||
|
||||
int bonus = local_tod.lawful_bonus;
|
||||
int l = generic_combat_modifier(bonus, unit_type::ALIGNMENT::LIMINAL, false, rc.tod().get_max_liminal_bonus());
|
||||
int l = generic_combat_modifier(bonus, unit_alignments::type::liminal, false, rc.tod().get_max_liminal_bonus());
|
||||
|
||||
std::string lawful_color("white");
|
||||
std::string chaotic_color("white");
|
||||
|
|
|
@ -73,10 +73,10 @@
|
|||
#include "log.hpp"
|
||||
#include "random.hpp"
|
||||
#include "serialization/binary_or_text.hpp"
|
||||
#include "side_controller.hpp"
|
||||
#include "statistics.hpp"
|
||||
#include "variable.hpp" // for config_variable_set
|
||||
#include "variable_info.hpp"
|
||||
#include "string_enums/side_controller.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
|
|
|
@ -323,7 +323,7 @@ bool loadgame::load_multiplayer_game()
|
|||
|
||||
// We want to verify the game classification before setting the data, so we don't check on
|
||||
// gamestate_.classification() and instead construct a game_classification object manually.
|
||||
if(game_classification(load_data_.load_config).campaign_type != game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
|
||||
if(game_classification(load_data_.load_config).type != campaign_type::type::multiplayer) {
|
||||
gui2::show_transient_error_message(_("This is not a multiplayer save."));
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ static int intf_describe_plugins(lua_State * L)
|
|||
std::stringstream line;
|
||||
line << i
|
||||
<< ":\t"
|
||||
<< plugins_manager::get()->get_status(i)
|
||||
<< plugin_manager_status::get_string(plugins_manager::get()->get_status(i))
|
||||
<< "\t\t"
|
||||
<< plugins_manager::get()->get_name(i)
|
||||
<< "\n";
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
#include "game_events/pump.hpp" // for queued_event
|
||||
#include "preferences/game.hpp" // for encountered_units
|
||||
#include "log.hpp" // for LOG_STREAM, logger, etc
|
||||
#include "utils/make_enum.hpp" // for operator<<
|
||||
#include "map/map.hpp" // for gamemap
|
||||
#include "map/label.hpp"
|
||||
#include "map/location.hpp" // for map_location
|
||||
|
@ -269,9 +268,8 @@ static int impl_add_animation(lua_State* L)
|
|||
unit& u = *up;
|
||||
std::string which = luaL_checkstring(L, 3);
|
||||
|
||||
using hit_type = unit_animation::hit_type;
|
||||
std::string hits_str = luaL_checkstring(L, 4);
|
||||
hit_type hits = hit_type::string_to_enum(hits_str, hit_type::INVALID);
|
||||
strike_result::type hits = strike_result::get_enum(hits_str).value_or(strike_result::type::invalid);
|
||||
|
||||
map_location dest;
|
||||
int v1 = 0, v2 = 0;
|
||||
|
@ -1293,8 +1291,8 @@ int game_lua_kernel::impl_game_config_get(lua_State *L)
|
|||
const mp_game_settings& mp_settings = play_controller_.get_mp_settings();
|
||||
const game_classification & classification = play_controller_.get_classification();
|
||||
|
||||
return_string_attrib_deprecated("campaign_type", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.type instead", classification.campaign_type.to_string());
|
||||
if(classification.campaign_type==game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
|
||||
return_string_attrib_deprecated("campaign_type", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.type instead", campaign_type::get_string(classification.type));
|
||||
if(classification.type==campaign_type::type::multiplayer) {
|
||||
return_cfgref_attrib_deprecated("mp_settings", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.mp_settings instead", mp_settings.to_config());
|
||||
return_cfgref_attrib_deprecated("era", "wesnoth.game_config", INDEFINITE, "1.17", "Use wesnoth.scenario.era instead",
|
||||
game_config_manager::get()->game_config().find_child("era","id",classification.era_id));
|
||||
|
@ -1357,7 +1355,7 @@ static int impl_end_level_data_get(lua_State* L)
|
|||
return_bool_attrib("proceed_to_next_level", data.proceed_to_next_level);
|
||||
return_bool_attrib("is_victory", data.is_victory);
|
||||
return_bool_attrib("is_loss", !data.is_victory);
|
||||
return_cstring_attrib("result", data.is_victory ? "victory" : "loss"); // to match wesnoth.end_level()
|
||||
return_cstring_attrib("result", data.is_victory ? level_result::victory : "loss"); // to match wesnoth.end_level()
|
||||
return_string_attrib("test_result", data.test_result);
|
||||
return_cfg_attrib("__cfg", data.to_config_full());
|
||||
|
||||
|
@ -1458,14 +1456,14 @@ static int impl_mp_settings_get(lua_State* L)
|
|||
return_bool_attrib("allow_observers", settings.allow_observers);
|
||||
return_bool_attrib("private_replay", settings.private_replay);
|
||||
return_bool_attrib("shuffle_sides", settings.shuffle_sides);
|
||||
return_string_attrib("random_faction_mode", settings.random_faction_mode.to_string());
|
||||
return_string_attrib("random_faction_mode", random_faction_mode::get_string(settings.mode));
|
||||
return_cfgref_attrib("options", settings.options);
|
||||
if(strcmp(m, "savegame") == 0) {
|
||||
auto savegame = settings.saved_game;
|
||||
if(savegame == mp_game_settings::SAVED_GAME_MODE::NONE) {
|
||||
if(savegame == saved_game_mode::type::no) {
|
||||
lua_pushboolean(L, false);
|
||||
} else {
|
||||
lua_push(L, savegame.to_string());
|
||||
lua_push(L, saved_game_mode::get_string(savegame));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -1555,7 +1553,7 @@ int game_lua_kernel::impl_scenario_get(lua_State *L)
|
|||
}
|
||||
|
||||
const game_classification& classification = play_controller_.get_classification();
|
||||
return_string_attrib("type", classification.campaign_type.to_string());
|
||||
return_string_attrib("type", campaign_type::get_string(classification.type));
|
||||
return_string_attrib("difficulty", classification.difficulty);
|
||||
return_bool_attrib("show_credits", classification.end_credits);
|
||||
return_tstring_attrib("end_text", classification.end_text);
|
||||
|
@ -1643,8 +1641,8 @@ int game_lua_kernel::impl_scenario_set(lua_State *L)
|
|||
data.replay_save = cfg["replay_save"].to_bool(true);
|
||||
data.transient.linger_mode = cfg["linger_mode"].to_bool(true) && !teams().empty();
|
||||
data.transient.reveal_map = cfg["reveal_map"].to_bool(true);
|
||||
data.is_victory = cfg["result"] == "victory";
|
||||
data.test_result = cfg["test_result"].str(LEVEL_RESULT::enum_to_string(LEVEL_RESULT::TEST_NOT_SET));
|
||||
data.is_victory = cfg["result"] == level_result::victory;
|
||||
data.test_result = cfg["test_result"].str(level_result::result_not_set);
|
||||
play_controller_.set_end_level_data(data);
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -82,15 +82,15 @@ static int impl_side_get(lua_State *L)
|
|||
return_string_attrib("color", t.color());
|
||||
return_string_attrib("controller", side_controller::get_string(t.controller()));
|
||||
return_bool_attrib("is_local", t.is_local());
|
||||
return_string_attrib("defeat_condition", t.defeat_condition().to_string());
|
||||
return_string_attrib("share_vision", t.share_vision().to_string());
|
||||
return_string_attrib("defeat_condition", defeat_condition::get_string(t.defeat_cond()));
|
||||
return_string_attrib("share_vision", team_shared_vision::get_string(t.share_vision()));
|
||||
return_float_attrib("carryover_bonus", t.carryover_bonus());
|
||||
return_int_attrib("carryover_percentage", t.carryover_percentage());
|
||||
return_bool_attrib("carryover_add", t.carryover_add());
|
||||
return_bool_attrib("lost", t.lost());
|
||||
return_bool_attrib("persistent", t.persistent());
|
||||
return_bool_attrib("suppress_end_turn_confirmation", t.no_turn_confirmation());
|
||||
return_string_attrib("share_vision", t.share_vision().to_string());
|
||||
return_string_attrib("share_vision", team_shared_vision::get_string(t.share_vision()));
|
||||
return_bool_attrib("share_maps", t.share_maps());
|
||||
return_bool_attrib("share_view", t.share_view());
|
||||
return_bool_attrib("chose_random", t.chose_random());
|
||||
|
@ -208,9 +208,9 @@ static int impl_side_set(lua_State *L)
|
|||
modify_tstring_attrib("side_name", t.set_side_name(value));
|
||||
modify_string_attrib("shroud_data", t.reshroud(); t.merge_shroud_map_data(value));
|
||||
modify_string_attrib("share_vision", {
|
||||
team::SHARE_VISION v;
|
||||
if(v.parse(value)) {
|
||||
t.set_share_vision(v);
|
||||
auto v = team_shared_vision::get_enum(value);
|
||||
if(v) {
|
||||
t.set_share_vision(*v);
|
||||
} else {
|
||||
return luaL_argerror(L, 3, "Invalid share_vision value (should be 'all', 'none', or 'shroud')");
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ static int impl_unit_get(lua_State *L)
|
|||
return_vector_string_attrib("advances_to", u.advances_to());
|
||||
|
||||
if(strcmp(m, "alignment") == 0) {
|
||||
lua_push(L, u.alignment());
|
||||
lua_push(L, unit_alignments::get_string(u.alignment()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -461,7 +461,7 @@ static int impl_unit_set(lua_State *L)
|
|||
modify_vector_string_attrib("extra_recruit", u.set_recruits(value));
|
||||
modify_vector_string_attrib("advances_to", u.set_advances_to(value));
|
||||
if(strcmp(m, "alignment") == 0) {
|
||||
u.set_alignment(lua_check<UNIT_ALIGNMENT>(L, 3));
|
||||
u.set_alignment(lua_enum_check<unit_alignments>(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static int impl_unit_type_get(lua_State *L)
|
|||
// Find the corresponding attribute.
|
||||
return_tstring_attrib("name", ut.type_name());
|
||||
return_string_attrib("id", ut.id());
|
||||
return_string_attrib("alignment", ut.alignment().to_string());
|
||||
return_string_attrib("alignment", unit_alignments::get_string(ut.alignment()));
|
||||
return_string_attrib("race", ut.race_id());
|
||||
return_string_attrib("image", ut.image());
|
||||
return_string_attrib("icon", ut.icon());
|
||||
|
|
29
src/scripting/plugin_manager_status.hpp
Normal file
29
src/scripting/plugin_manager_status.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
Copyright (C) 2008 - 2021
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "enum_base.hpp"
|
||||
|
||||
struct plugin_manager_status_defines
|
||||
{
|
||||
static constexpr const char* const not_created = "not created";
|
||||
static constexpr const char* const running = "running";
|
||||
static constexpr const char* const stopped = "stopped";
|
||||
|
||||
ENUM_AND_ARRAY(not_created, running, stopped)
|
||||
};
|
||||
using plugin_manager_status = string_enums::enum_base<plugin_manager_status_defines>;
|
|
@ -70,12 +70,12 @@ std::size_t plugins_manager::size() {
|
|||
return plugins_.size();
|
||||
}
|
||||
|
||||
plugins_manager::STATUS plugins_manager::get_status(std::size_t idx) {
|
||||
plugin_manager_status::type plugins_manager::get_status(std::size_t idx) {
|
||||
if (idx < plugins_.size()) {
|
||||
if (!plugins_[idx].thread) {
|
||||
return plugins_manager::STATUS::NONE;
|
||||
return plugin_manager_status::type::not_created;
|
||||
} else {
|
||||
return plugins_[idx].thread->is_running() ? plugins_manager::STATUS::RUNNING : plugins_manager::STATUS::STOPPED;
|
||||
return plugins_[idx].thread->is_running() ? plugin_manager_status::type::running : plugin_manager_status::type::stopped;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("index out of bounds");
|
||||
|
@ -208,7 +208,7 @@ bool plugins_manager::any_running()
|
|||
{
|
||||
|
||||
for (std::size_t i = 0; i < size(); ++i) {
|
||||
if (STATUS::RUNNING == get_status(i)) {
|
||||
if (plugin_manager_status::type::running == get_status(i)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue