Merge pull request #463 from CelticMinstrel/effect_apply_to
New possibilities for [effect]
This commit is contained in:
commit
fa5e0f7be2
3 changed files with 201 additions and 1 deletions
12
changelog
12
changelog
|
@ -46,6 +46,18 @@ Version 1.13.1+dev:
|
|||
messages involving macros.
|
||||
* Added WML menu item and event handler views to the Gamestate Inspector
|
||||
dialog.
|
||||
* Added new possibilities for [effect]:
|
||||
* apply_to=alignment - change a unit's alignment
|
||||
* apply_to=attacks_left - change a unit's attacks per turn
|
||||
* apply_to=recall_cost - change a unit's recall cost
|
||||
* apply_to=vision, apply_to=jamming - change a unit's vision/jamming points
|
||||
* apply_to=new_advancement - add new advancement possibilities (either units
|
||||
or AMLAs)
|
||||
* apply_to=remove_advancement - remove advancement possibilities (either units
|
||||
or AMLAs)
|
||||
* apply_to=attack - add set_ versions of all existing increase_ keys
|
||||
* apply_to=attack - add increase_movement_used and set_movement_used to change the
|
||||
number of movement points the attack consumes
|
||||
* Editor:
|
||||
* Added Category field and color sliders to the Edit Label panel.
|
||||
* Miscellaneous and bug fixes:
|
||||
|
|
125
src/unit.cpp
125
src/unit.cpp
|
@ -1771,9 +1771,10 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool
|
|||
const std::string &increase = effect["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times)
|
||||
if (!times) {
|
||||
description += utils::print_modifier(increase) + " " +
|
||||
t_string(N_("moves"), "wesnoth");
|
||||
}
|
||||
|
||||
max_movement_ = utils::apply_modifier(max_movement_, increase, 1);
|
||||
}
|
||||
|
@ -1782,6 +1783,33 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool
|
|||
|
||||
if(movement_ > max_movement_)
|
||||
movement_ = max_movement_;
|
||||
} else if(apply_to == "vision") {
|
||||
const std::string &increase = effect["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times) {
|
||||
description += utils::print_modifier(increase) + " " +
|
||||
t_string(N_("vision"), "wesnoth");
|
||||
}
|
||||
|
||||
const int current_vision = vision_ < 0 ? max_movement_ : vision_;
|
||||
vision_ = utils::apply_modifier(current_vision, increase, 1);
|
||||
}
|
||||
|
||||
vision_ = effect["set"].to_int(vision_);
|
||||
} else if(apply_to == "jamming") {
|
||||
const std::string &increase = effect["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times) {
|
||||
description += utils::print_modifier(increase) + " " +
|
||||
t_string(N_("jamming"), "wesnoth");
|
||||
}
|
||||
|
||||
jamming_ = utils::apply_modifier(jamming_, increase, 1);
|
||||
}
|
||||
|
||||
jamming_ = effect["set"].to_int(jamming_);
|
||||
} else if(apply_to == "experience") {
|
||||
const std::string &increase = effect["increase"];
|
||||
const std::string &set = effect["set"];
|
||||
|
@ -1907,6 +1935,89 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool
|
|||
else if (!replace.empty()) {
|
||||
overlays_ = utils::parenthetical_split(replace, ',');
|
||||
}
|
||||
} else if (apply_to == "new_advancement") {
|
||||
const std::string &types = effect["types"];
|
||||
const bool replace = effect["replace"].to_bool(false);
|
||||
|
||||
if (!types.empty()) {
|
||||
if (replace) {
|
||||
advances_to_ = utils::parenthetical_split(types, ',');
|
||||
} else {
|
||||
std::vector<std::string> temp_advances = utils::parenthetical_split(types, ',');
|
||||
std::copy(temp_advances.begin(), temp_advances.end(), std::back_inserter(advances_to_));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Possible TODO: Honour replace=yes
|
||||
cfg_.add_child("advancement", effect);
|
||||
}
|
||||
} else if (apply_to == "remove_advancement") {
|
||||
const std::string &types = effect["types"];
|
||||
const std::string &amlas = effect["amlas"];
|
||||
|
||||
std::vector<std::string> temp_advances = utils::parenthetical_split(types, ',');
|
||||
std::vector<std::string>::iterator iter;
|
||||
BOOST_FOREACH(const std::string& unit, temp_advances) {
|
||||
iter = std::find(advances_to_.begin(), advances_to_.end(), unit);
|
||||
if (iter != advances_to_.end()) {
|
||||
advances_to_.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
temp_advances = utils::parenthetical_split(amlas, ',');
|
||||
std::vector<size_t> remove_indices;
|
||||
size_t remove_index = 0;
|
||||
BOOST_FOREACH(const config &adv, modification_advancements()) {
|
||||
iter = std::find(temp_advances.begin(), temp_advances.end(), adv["id"]);
|
||||
if (iter != temp_advances.end()) {
|
||||
remove_indices.push_back(remove_index);
|
||||
}
|
||||
remove_index++;
|
||||
}
|
||||
for (size_t i = remove_indices.size(); i > 0; i--) {
|
||||
cfg_.remove_child("advancement", i - 1);
|
||||
}
|
||||
} else if (apply_to == "alignment") {
|
||||
unit_type::ALIGNMENT new_align;
|
||||
if(new_align.parse(effect["set"])) {
|
||||
alignment_ = new_align;
|
||||
}
|
||||
} else if (apply_to == "max_attacks") {
|
||||
const std::string &increase = effect["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times) {
|
||||
description += utils::print_modifier(increase) + " ";
|
||||
const char* const singular = N_("attack per turn");
|
||||
const char* const plural = N_("attacks per turn");
|
||||
if (increase[increase.size()-1] == '%' || abs(lexical_cast<int>(increase)) != 1) {
|
||||
description += t_string(plural, "wesnoth");
|
||||
} else {
|
||||
description += t_string(singular, "wesnoth");
|
||||
}
|
||||
}
|
||||
max_attacks_ = utils::apply_modifier(max_attacks_, increase, 1);
|
||||
}
|
||||
} else if (apply_to == "recall_cost") {
|
||||
const std::string &increase = effect["increase"];
|
||||
const std::string &set = effect["set"];
|
||||
const int recall_cost = recall_cost_ < 0 ? resources::teams->at(side_).recall_cost() : recall_cost_;
|
||||
|
||||
if(set.empty() == false) {
|
||||
if(set[set.size()-1] == '%') {
|
||||
recall_cost_ = lexical_cast_default<int>(set)*recall_cost/100;
|
||||
} else {
|
||||
recall_cost_ = lexical_cast_default<int>(set);
|
||||
}
|
||||
}
|
||||
|
||||
if(increase.empty() == false) {
|
||||
if (!times) {
|
||||
description += utils::print_modifier(increase) + " " +
|
||||
t_string(N_("cost to recall"), "wesnoth");
|
||||
}
|
||||
recall_cost_ = utils::apply_modifier(recall_cost, increase, 1);
|
||||
}
|
||||
}
|
||||
} // end while
|
||||
} else { // for times = per level & level = 0 we still need to rebuild the descriptions
|
||||
|
@ -1941,6 +2052,18 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool
|
|||
if(increase.empty() == false) {
|
||||
description += utils::print_modifier(increase) + t_string(N_(" move"), "wesnoth");
|
||||
}
|
||||
} else if(apply_to == "vision") {
|
||||
const std::string &increase = effect["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
description += utils::print_modifier(increase) + t_string(N_(" vision"), "wesnoth");
|
||||
}
|
||||
} else if(apply_to == "jamming") {
|
||||
const std::string &increase = effect["increase"];
|
||||
|
||||
if(increase.empty() == false) {
|
||||
description += utils::print_modifier(increase) + t_string(N_(" jamming"), "wesnoth");
|
||||
}
|
||||
} else if(apply_to == "max_experience") {
|
||||
const std::string &increase = effect["increase"];
|
||||
|
||||
|
|
|
@ -175,11 +175,17 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||
const std::string& del_specials = cfg["remove_specials"];
|
||||
const config &set_specials = cfg.child("set_specials");
|
||||
const std::string& increase_damage = cfg["increase_damage"];
|
||||
const std::string& set_damage = cfg["set_damage"];
|
||||
const std::string& increase_attacks = cfg["increase_attacks"];
|
||||
const std::string& set_attacks = cfg["set_attacks"];
|
||||
const std::string& set_attack_weight = cfg["attack_weight"];
|
||||
const std::string& set_defense_weight = cfg["defense_weight"];
|
||||
const std::string& increase_accuracy = cfg["increase_accuracy"];
|
||||
const std::string& set_accuracy = cfg["set_accuracy"];
|
||||
const std::string& increase_parry = cfg["increase_parry"];
|
||||
const std::string& set_parry = cfg["set_parry"];
|
||||
const std::string& increase_movement = cfg["increase_movement_used"];
|
||||
const std::string& set_movement = cfg["set_movement_used"];
|
||||
|
||||
std::stringstream desc;
|
||||
|
||||
|
@ -222,6 +228,18 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||
}
|
||||
}
|
||||
|
||||
if(set_damage.empty() == false) {
|
||||
damage_ = lexical_cast<int>(set_damage);
|
||||
if (damage_ < 0) {
|
||||
damage_ = 0;
|
||||
}
|
||||
|
||||
if(description != NULL) {
|
||||
add_and(desc);
|
||||
desc << set_damage << " " << _n("damage","damage", damage_);
|
||||
}
|
||||
}
|
||||
|
||||
if(increase_damage.empty() == false) {
|
||||
damage_ = utils::apply_modifier(damage_, increase_damage, 0);
|
||||
if (damage_ < 0) {
|
||||
|
@ -236,6 +254,15 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||
}
|
||||
}
|
||||
|
||||
if(set_attacks.empty() == false) {
|
||||
num_attacks_ = lexical_cast<int>(set_attacks);
|
||||
|
||||
if(description != NULL) {
|
||||
add_and(desc);
|
||||
desc << set_attacks << " " << _n("strike", "strikes", num_attacks_);
|
||||
}
|
||||
}
|
||||
|
||||
if(increase_attacks.empty() == false) {
|
||||
num_attacks_ = utils::apply_modifier(num_attacks_, increase_attacks, 1);
|
||||
|
||||
|
@ -247,6 +274,16 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||
}
|
||||
}
|
||||
|
||||
if(set_accuracy.empty() == false) {
|
||||
accuracy_ = lexical_cast<int>(set_accuracy);
|
||||
|
||||
if(description != NULL) {
|
||||
add_and(desc);
|
||||
// xgettext:no-c-format
|
||||
desc << accuracy_ << " " << _("% accuracy");
|
||||
}
|
||||
}
|
||||
|
||||
if(increase_accuracy.empty() == false) {
|
||||
accuracy_ = utils::apply_modifier(accuracy_, increase_accuracy, 1);
|
||||
|
||||
|
@ -259,6 +296,15 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||
}
|
||||
}
|
||||
|
||||
if(set_parry.empty() == false) {
|
||||
parry_ = lexical_cast<int>(set_parry);
|
||||
|
||||
if(description != NULL) {
|
||||
add_and(desc);
|
||||
desc << parry_ << _(" parry");
|
||||
}
|
||||
}
|
||||
|
||||
if(increase_parry.empty() == false) {
|
||||
parry_ = utils::apply_modifier(parry_, increase_parry, 1);
|
||||
|
||||
|
@ -270,6 +316,25 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||
}
|
||||
}
|
||||
|
||||
if(set_movement.empty() == false) {
|
||||
movement_used_ = lexical_cast<int>(set_movement);
|
||||
|
||||
if(description != NULL) {
|
||||
add_and(desc);
|
||||
desc << movement_used_ << " " << _n("movement point","movement points",movement_used_);
|
||||
}
|
||||
}
|
||||
|
||||
if(increase_movement.empty() == false) {
|
||||
movement_used_ = utils::apply_modifier(movement_used_, increase_movement, 1);
|
||||
|
||||
if(description != NULL) {
|
||||
add_and(desc);
|
||||
int inc_move = lexical_cast<int>(increase_movement);
|
||||
desc << increase_movement << " " << _n("movement point","movement points",inc_move);
|
||||
}
|
||||
}
|
||||
|
||||
if(set_attack_weight.empty() == false) {
|
||||
attack_weight_ = lexical_cast_default<double>(set_attack_weight,1.0);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue