Split [effect]apply_to=advances_to into separate "new" and "remove" effects

It now also supports adding and removing AMLAs.
This commit is contained in:
Celtic Minstrel 2015-08-18 11:39:39 -04:00
parent a62eeaa65d
commit 3223df3453

View File

@ -1934,27 +1934,47 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool
else if (!replace.empty()) { else if (!replace.empty()) {
overlays_ = utils::parenthetical_split(replace, ','); overlays_ = utils::parenthetical_split(replace, ',');
} }
} else if (apply_to == "advances_to") { } else if (apply_to == "new_advancement") {
const std::string &add = effect["add"]; const std::string &types = effect["types"];
const std::string &remove = effect["remove"]; const bool replace = effect["replace"].to_bool(false);
const std::string &replace = effect["replace"];
if (!add.empty()) { if (!types.empty()) {
std::vector<std::string> temp_advances = utils::parenthetical_split(add, ','); if (replace) {
std::copy(temp_advances.begin(), temp_advances.end(), std::back_inserter(advances_to_)); advances_to_ = utils::parenthetical_split(types, ',');
} } else {
else if (!remove.empty()) { std::vector<std::string> temp_advances = utils::parenthetical_split(types, ',');
std::vector<std::string> temp_advances = utils::parenthetical_split(remove, ','); std::copy(temp_advances.begin(), temp_advances.end(), std::back_inserter(advances_to_));
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);
}
} }
} }
else if (!replace.empty()) { else {
advances_to_ = utils::parenthetical_split(add, ','); // 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") { } else if (apply_to == "alignment") {
unit_type::ALIGNMENT new_align; unit_type::ALIGNMENT new_align;