Sapient had a better idea for the per level bonus, thus :
- reverted my previous *_per_level implementation - implement the new times= [effect] key to apply an effect more than once. The default is to apply the effect once The other possible value is "per level" wich mean the effect will be applied level time, where "level" is the level of the unit.
This commit is contained in:
parent
8102bc7d30
commit
33cbfe8aa7
5 changed files with 36 additions and 40 deletions
|
@ -48,9 +48,9 @@ Version 1.3.4+svn:
|
|||
* now standard unit filter supports [and],[or], and [not] (was just [not])
|
||||
* [unstore_unit] can now try to level a unit and does so by default this
|
||||
time added for real, the replay can also handle it(bug #7426)
|
||||
* [effect] can add an additionnal bonus per level for movement and hitpoints
|
||||
(new keys for hitpoints: increase_per_level and increase_total_per_level
|
||||
new key for movement: increase_per_level)
|
||||
* new times= key to apply [effects] more than once (default=once,
|
||||
other possible value=per level, ie the effect is multiplyed by the level
|
||||
of the unit).
|
||||
* miscellaneous and bug fixes
|
||||
* fix renames causing OOS when made after moves or recruits
|
||||
* fix a minor glitch when selecting the leftmost menu heading
|
||||
|
|
|
@ -109,7 +109,8 @@
|
|||
[/effect]
|
||||
[effect]
|
||||
apply_to=hitpoints
|
||||
increase_total_per_level=1
|
||||
times=per level
|
||||
increase_total=1
|
||||
[/effect]
|
||||
[/trait]
|
||||
#enddef
|
||||
|
|
|
@ -322,13 +322,12 @@ std::string interpolate_variables_into_string(const std::string &str, const vari
|
|||
}
|
||||
|
||||
// modify a number by string representing integer difference, or optionally %
|
||||
int apply_modifier( const int number, const std::string &amount, const int minimum, const int times ) {
|
||||
int apply_modifier( const int number, const std::string &amount, const int minimum ) {
|
||||
// wassert( amount.empty() == false );
|
||||
int value = atoi(amount.c_str());
|
||||
if(amount[amount.size()-1] == '%') {
|
||||
value = div100rounded(number * value);
|
||||
}
|
||||
value *= times;
|
||||
value += number;
|
||||
if (( minimum > 0 ) && ( value < minimum ))
|
||||
value = minimum;
|
||||
|
|
|
@ -54,7 +54,7 @@ std::string join(std::vector< std::string > const &v, char c = ',');
|
|||
std::vector< std::string > quoted_split(std::string const &val, char c= ',',
|
||||
int flags = REMOVE_EMPTY | STRIP_SPACES, char quote = '\\');
|
||||
std::pair< int, int > parse_range(std::string const &str);
|
||||
int apply_modifier( const int number, const std::string &amount, const int minimum = 0, const int times = 1 );
|
||||
int apply_modifier( const int number, const std::string &amount, const int minimum = 0);
|
||||
std::string &escape(std::string &str, const std::string& special_chars);
|
||||
std::string &escape(std::string &str);
|
||||
std::string &unescape(std::string &str);
|
||||
|
|
62
src/unit.cpp
62
src/unit.cpp
|
@ -2344,10 +2344,18 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
}
|
||||
}
|
||||
|
||||
t_string description;
|
||||
|
||||
const std::string& apply_to = (**i.first)["apply_to"];
|
||||
const std::string& apply_times = (**i.first)["times"];
|
||||
int times = 1;
|
||||
if (apply_times == "per level")
|
||||
times = level_;
|
||||
|
||||
while (times > 0) {
|
||||
|
||||
t_string description;
|
||||
|
||||
times--;
|
||||
//apply variations -- only apply if we are adding this
|
||||
//for the first time.
|
||||
if(apply_to == "variation" && no_add == false) {
|
||||
|
@ -2388,19 +2396,19 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
if(first_attack) {
|
||||
first_attack = false;
|
||||
} else {
|
||||
description += t_string(N_("; "), "wesnoth");
|
||||
if (!times)
|
||||
description += t_string(N_("; "), "wesnoth");
|
||||
}
|
||||
|
||||
description += t_string(a->name(), "wesnoth") + " " + desc;
|
||||
if (!times)
|
||||
description += t_string(a->name(), "wesnoth") + " " + desc;
|
||||
}
|
||||
}
|
||||
} else if(apply_to == "hitpoints") {
|
||||
LOG_UT << "applying hitpoint mod..." << hit_points_ << "/" << max_hit_points_ << "\n";
|
||||
const std::string& increase_hp = (**i.first)["increase"];
|
||||
const std::string& increase_hp_level = (**i.first)["increase_per_level"];
|
||||
const std::string& heal_full = (**i.first)["heal_full"];
|
||||
const std::string& increase_total = (**i.first)["increase_total"];
|
||||
const std::string& increase_total_level = (**i.first)["increase_total_per_level"];
|
||||
const std::string& set_hp = (**i.first)["set"];
|
||||
const std::string& set_total = (**i.first)["set_total"];
|
||||
|
||||
|
@ -2423,21 +2431,14 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
}
|
||||
|
||||
if(increase_total.empty() == false) {
|
||||
description += (increase_total[0] != '-' ? "+" : "") + increase_total +
|
||||
" " + t_string(N_("HP"), "wesnoth");
|
||||
if (!times)
|
||||
description += (increase_total[0] != '-' ? "+" : "") + increase_total +
|
||||
" " + t_string(N_("HP"), "wesnoth");
|
||||
|
||||
//a percentage on the end means increase by that many percent
|
||||
max_hit_points_ = utils::apply_modifier(max_hit_points_, increase_total);
|
||||
}
|
||||
|
||||
if(increase_total_level.empty() == false) {
|
||||
description += (increase_total_level[0] != '-' ? "+" : "") + increase_total_level +
|
||||
" " + t_string(N_("HP/level"), "wesnoth");
|
||||
|
||||
//a percentage on the end means increase by that many percent
|
||||
max_hit_points_ = utils::apply_modifier(max_hit_points_, increase_total_level, 0, level_);
|
||||
}
|
||||
|
||||
if(max_hit_points_ < 1)
|
||||
max_hit_points_ = 1;
|
||||
|
||||
|
@ -2449,10 +2450,6 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
hit_points_ = utils::apply_modifier(hit_points_, increase_hp);
|
||||
}
|
||||
|
||||
if(increase_hp_level.empty() == false) {
|
||||
hit_points_ = utils::apply_modifier(hit_points_, increase_hp_level, 0, level_);
|
||||
}
|
||||
|
||||
LOG_UT << "modded to " << hit_points_ << "/" << max_hit_points_ << "\n";
|
||||
if(hit_points_ > max_hit_points_ && violate_max.empty()) {
|
||||
LOG_UT << "resetting hp to max\n";
|
||||
|
@ -2463,23 +2460,16 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
hit_points_ = 1;
|
||||
} else if(apply_to == "movement") {
|
||||
const std::string& increase = (**i.first)["increase"];
|
||||
const std::string& increase_level = (**i.first)["increase_per_level"];
|
||||
const std::string& set_to = (**i.first)["set"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
description += (increase[0] != '-' ? "+" : "") + increase +
|
||||
" " + t_string(N_("Moves"), "wesnoth");
|
||||
if (!times)
|
||||
description += (increase[0] != '-' ? "+" : "") + increase +
|
||||
" " + t_string(N_("Moves"), "wesnoth");
|
||||
|
||||
max_movement_ = utils::apply_modifier(max_movement_, increase, 1);
|
||||
}
|
||||
|
||||
if(increase_level.empty() == false) {
|
||||
description += (increase_level[0] != '-' ? "+" : "") + increase_level +
|
||||
" " + t_string(N_("Moves/level"), "wesnoth");
|
||||
|
||||
max_movement_ = utils::apply_modifier(max_movement_, increase_level, 1, level_);
|
||||
}
|
||||
|
||||
if(set_to.empty() == false) {
|
||||
max_movement_ = atoi(set_to.c_str());
|
||||
}
|
||||
|
@ -2489,10 +2479,11 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
} else if(apply_to == "max_experience") {
|
||||
const std::string& increase = (**i.first)["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
description += (increase[0] != '-' ? "+" : "") +
|
||||
increase + " " +
|
||||
t_string(N_("XP to advance"), "wesnoth");
|
||||
if(increase.empty() == false) {
|
||||
if (!times)
|
||||
description += (increase[0] != '-' ? "+" : "") +
|
||||
increase + " " +
|
||||
t_string(N_("XP to advance"), "wesnoth");
|
||||
|
||||
max_experience_ = utils::apply_modifier(max_experience_, increase);
|
||||
}
|
||||
|
@ -2565,8 +2556,13 @@ void unit::add_modification(const std::string& type, const config& mod,
|
|||
LOG_UT << "applying image_mod \n";
|
||||
}
|
||||
|
||||
if (apply_times == "per level" && !times)
|
||||
description += t_string(N_("/level"), "wesnoth");
|
||||
|
||||
if(!description.empty())
|
||||
effects_description.push_back(description);
|
||||
|
||||
} /* end while */
|
||||
}
|
||||
|
||||
t_string& description = modification_descriptions_[type];
|
||||
|
|
Loading…
Add table
Reference in a new issue