From f599c77783fb79faf14339ee976aaa58d2c08209 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Fri, 4 Sep 2020 17:52:17 +0200 Subject: [PATCH] Add 'Delay Advancements [modification] Depsite being a [modification] this is actuall implemented in the C++ code the [modification] just sets a flag. This is meant as an alterntive to the preset advancement type of mod, i want to play around with it a bit in 1.15 maybe we will remove it later. The problbme this is supposed to fix is that advancemnts are done randomly during the enemeies turn. It has a few advantages over the preset advancemnt approach: 1) It can easily handle amlas and normal advancement 2) It doesn't need special code to handle the case that A unit advances multiple times. 3) It doesn't break in case that other wml code changed The advancements of a unit after the preselected advancement was chosen 4) The user never needs to think about an advancement of a unit that might not even advance It also has a disadvantage: it changes the rules of the game quite a bit, in partiucar if the units heals form an adcancement (which us usally the case), since now with this 'healing the unit on advancement by retaliation' during the enemies turn can no longer happen. I still think its wirth to think about this and test it though. --- data/_main.cfg | 1 + data/modifications.cfg | 5 +++++ src/play_controller.cpp | 11 +++++++++++ src/units/helper.cpp | 15 ++++++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 data/modifications.cfg diff --git a/data/_main.cfg b/data/_main.cfg index bbaf0472cdf..34d83c7f493 100644 --- a/data/_main.cfg +++ b/data/_main.cfg @@ -37,6 +37,7 @@ {campaigns/} +{modifications.cfg} [ais] default_ai_algorithm=ai_default_rca [default_config] diff --git a/data/modifications.cfg b/data/modifications.cfg new file mode 100644 index 00000000000..24984fb1bb0 --- /dev/null +++ b/data/modifications.cfg @@ -0,0 +1,5 @@ +[modification] + id = "delay_advancements" + name = _ "Delay Advancements" + type = "hybrid" +[/modification] diff --git a/src/play_controller.cpp b/src/play_controller.cpp index d7ca9dc2847..8027975186f 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -20,6 +20,7 @@ #include "play_controller.hpp" +#include "actions/advancement.hpp" #include "actions/create.hpp" #include "actions/heal.hpp" #include "actions/undo.hpp" @@ -528,6 +529,16 @@ void play_controller::do_init_side() // Make sure vision is accurate. actions::clear_shroud(current_side(), true); + { + const auto& active_mods = get_saved_game().classification().active_mods; + bool delay_advancements = std::find(active_mods.begin(), active_mods.end(), "delay_advancements") != active_mods.end(); + + for(unit &u : resources::gameboard->units()) { + if(u.side() == current_side()) { + advance_unit_at(u.get_location()); + } + } + } init_side_end(); check_victory(); sync.do_final_checkup(); diff --git a/src/units/helper.cpp b/src/units/helper.cpp index e77e9177472..b37eba1fa41 100644 --- a/src/units/helper.cpp +++ b/src/units/helper.cpp @@ -20,6 +20,9 @@ #include "units/unit.hpp" #include "units/helper.hpp" #include "units/types.hpp" +#include "resources.hpp" +#include "play_controller.hpp" +#include "saved_game.hpp" namespace unit_helper { @@ -30,7 +33,17 @@ int number_of_possible_advances(const unit &u) bool will_certainly_advance(const unit_map::iterator &u) { - return u.valid() && u->advances() && number_of_possible_advances(*u) > 0; + if(!u.valid()) { + return false; + } + if(resources::controller) { + const auto& active_mods = resources::controller->get_saved_game().classification().active_mods; + bool delay_advancements = std::find(active_mods.begin(), active_mods.end(), "delay_advancements") != active_mods.end(); + if(delay_advancements && resources::controller->current_side() != u->side()) { + return false; + } + } + return u->advances() && number_of_possible_advances(*u) > 0; } std::string resistance_color(const int resistance)