Add size and id modifications in formulas
while waiting for the release of the use of the number of advancement or their identity to be decided, I added both in the formulas
This commit is contained in:
parent
08ee0dddd1
commit
5f857f3dfc
3 changed files with 80 additions and 7 deletions
|
@ -191,6 +191,7 @@ unit_callable::unit_callable(const unit& u) : loc_(u.get_location()), u_(u)
|
|||
|
||||
variant unit_callable::get_value(const std::string& key) const
|
||||
{
|
||||
|
||||
if(key == "x") {
|
||||
if(loc_ == map_location::null_location()) {
|
||||
return variant();
|
||||
|
@ -256,6 +257,16 @@ variant unit_callable::get_value(const std::string& key) const
|
|||
return variant(u_.max_attacks());
|
||||
} else if(key == "traits") {
|
||||
return formula_callable::convert_vector(u_.get_traits_list());
|
||||
} else if(key == "advancements_taken") {
|
||||
return formula_callable::convert_vector(u_.get_advancements_list());
|
||||
} else if(key == "objects") {
|
||||
return formula_callable::convert_vector(u_.get_objects_list());
|
||||
} else if(key == "traits_count") {
|
||||
return variant(u_.traits_count());
|
||||
} else if(key == "advancements_taken_count") {
|
||||
return variant(u_.advancements_count());
|
||||
} else if(key == "objects_count") {
|
||||
return variant(u_.objects_count());
|
||||
} else if(key == "extra_recruit") {
|
||||
return formula_callable::convert_vector(u_.recruits());
|
||||
} else if(key == "advances_to") {
|
||||
|
@ -353,6 +364,11 @@ void unit_callable::get_inputs(formula_input_vector& inputs) const
|
|||
add_input(inputs, "canrecruit");
|
||||
add_input(inputs, "undead");
|
||||
add_input(inputs, "traits");
|
||||
add_input(inputs, "advancements_taken");
|
||||
add_input(inputs, "objects");
|
||||
add_input(inputs, "traits_count");
|
||||
add_input(inputs, "advancements_taken_count");
|
||||
add_input(inputs, "objects_count");
|
||||
add_input(inputs, "attacks");
|
||||
add_input(inputs, "abilities");
|
||||
add_input(inputs, "hitpoints");
|
||||
|
|
|
@ -888,16 +888,31 @@ void unit::generate_traits(bool must_have_only)
|
|||
random_traits_ = false;
|
||||
}
|
||||
|
||||
std::vector<std::string> unit::get_traits_list() const
|
||||
std::vector<std::string> unit::get_modifications_list(const std::string& mod_type) const
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
|
||||
for(const config& mod : modifications_.child_range("trait"))
|
||||
{
|
||||
// Make sure to return empty id trait strings as otherwise
|
||||
// names will not match in length (Bug #21967)
|
||||
res.push_back(mod["id"]);
|
||||
for(const config& mod : modifications_.child_range(mod_type)){
|
||||
// Make sure to return empty id trait strings as otherwise
|
||||
// names will not match in length (Bug #21967)
|
||||
res.push_back(mod["id"]);
|
||||
}
|
||||
if(mod_type == "advancement"){
|
||||
for(const config& mod : modifications_.child_range("advance")){
|
||||
res.push_back(mod["id"]);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::size_t unit::modification_count(const std::string& type) const
|
||||
{
|
||||
//return numbers of modifications of same type, same without ID.
|
||||
std::size_t res = modifications_.child_range(type).size();
|
||||
if(type == "advancement"){
|
||||
res += modification_count("advance");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -1115,12 +1115,31 @@ public:
|
|||
return trait_nonhidden_ids_;
|
||||
}
|
||||
|
||||
/** Gets a list of the modification this unit currently has.
|
||||
* @param mod_type type of modification.
|
||||
* @returns A list of modification IDs.
|
||||
*/
|
||||
std::vector<std::string> get_modifications_list(const std::string& mod_type) const;
|
||||
|
||||
/**
|
||||
* Gets a list of the traits this unit currently has, including hidden traits.
|
||||
*
|
||||
* @returns A list of trait IDs.
|
||||
*/
|
||||
std::vector<std::string> get_traits_list() const;
|
||||
std::vector<std::string> get_traits_list() const
|
||||
{
|
||||
return get_modifications_list("trait");
|
||||
}
|
||||
|
||||
std::vector<std::string> get_objects_list() const
|
||||
{
|
||||
return get_modifications_list("object");
|
||||
}
|
||||
|
||||
std::vector<std::string> get_advancements_list() const
|
||||
{
|
||||
return get_modifications_list("advancement");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a trait's name and its description for the UI's use.
|
||||
|
@ -1516,6 +1535,29 @@ public:
|
|||
*/
|
||||
std::size_t modification_count(const std::string& type, const std::string& id) const;
|
||||
|
||||
/**
|
||||
* Count modifications of a particular type.
|
||||
* @param type The type of modification to count.
|
||||
* Valid values are "advancement", "trait", "object"
|
||||
* @return The total number of modifications of that type.
|
||||
*/
|
||||
std::size_t modification_count(const std::string& type) const;
|
||||
|
||||
std::size_t traits_count() const
|
||||
{
|
||||
return modification_count("trait");
|
||||
}
|
||||
|
||||
std::size_t objects_count() const
|
||||
{
|
||||
return modification_count("object");
|
||||
}
|
||||
|
||||
std::size_t advancements_count() const
|
||||
{
|
||||
return modification_count("advancement");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new modification to the unit.
|
||||
* @param type The type of modification to add.
|
||||
|
|
Loading…
Add table
Reference in a new issue