From c39fdae486221a1c8593c0675310dcbb7987b901 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Thu, 17 Jul 2014 18:46:32 -0400 Subject: [PATCH] make the help smarter -- musthave traits without filters are applied When a unit type has "musthave" traits which always apply, by virtue of not having a filter, and they affect movement type, resistance, or jamming / vision data, the "base" unit type data is updated with these effects when displayed in the help. The only mainline example I know of where this makes a change is that the "feral" trait results in a "defense capped" column being generated by the help. But it can be tested that if core files are modified so that a musthave trait which always applies makes a change to the movement type or resistances, then this will be displayed in the help page for that unit type. It might also be handy for certain UMC which makes use of racial traits to modify stats. Note that we don't at the moment: - Update health or mp of the unit, or it's experience, according to such trait effects. - Update the unit with added / removed abilities due to such trait effects. So the help could be smarter still. --- src/help.cpp | 20 ++++++++++++++++++-- src/movetype.cpp | 6 ++++++ src/movetype.hpp | 3 +++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/help.cpp b/src/help.cpp index 6f8fd05b28aa..9ee060cb82d4 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -1570,7 +1570,7 @@ class unit_topic_generator: public topic_generator } // Print the abilities the units has, cross-reference them - // to their respective topics. + // to their respective topics. TODO: Update this according to musthave trait effects, similar to movetype below if (!type_.abilities().empty()) { ss << _("Abilities: "); for(std::vector::const_iterator ability_it = type_.abilities().begin(), @@ -1602,6 +1602,7 @@ class unit_topic_generator: public topic_generator } // Print some basic information such as HP and movement points. + // TODO: Make this info update according to musthave traits, similar to movetype below. ss << _("HP: ") << type_.hitpoints() << jump(30) << _("Moves: ") << type_.movement() << jump(30); if (type_.vision() != type_.movement()) @@ -1681,6 +1682,22 @@ class unit_topic_generator: public topic_generator ss << generate_table(table); } + // Generate the movement type of the unit, with resistance, defense, movement, jamming and vision data updated according to any 'musthave' traits which always apply + movetype movement_type = type_.movement_type(); + traits = type_.possible_traits(); + if (traits.first != traits.second && type_.num_traits() > 0) { + BOOST_FOREACH(const config & t, traits) { + if (t["availability"].str() == "musthave") { + BOOST_FOREACH (const config & effect, t.child_range("effect")) { + if (!effect.child("filter") // If this is musthave but has a unit filter, it might not always apply, so don't apply it in the help. + && movetype::effects.find(effect["apply_to"].str()) != movetype::effects.end()) { + movement_type.merge(effect, effect["replace"].to_bool()); + } + } + } + } + } + // Print the resistance table of the unit. ss << "\n\n
text='" << escape(_("Resistances")) << "'
\n\n"; @@ -1689,7 +1706,6 @@ class unit_topic_generator: public topic_generator push_header(first_res_row, _("Attack Type")); push_header(first_res_row, _("Resistance")); resistance_table.push_back(first_res_row); - const movetype &movement_type = type_.movement_type(); utils::string_map dam_tab = movement_type.damage_table(); for(utils::string_map::const_iterator dam_it = dam_tab.begin(), dam_end = dam_tab.end(); dam_it != dam_end; ++dam_it) { diff --git a/src/movetype.cpp b/src/movetype.cpp index 3a39d5b4a47e..626e8ae2ccd5 100644 --- a/src/movetype.cpp +++ b/src/movetype.cpp @@ -26,6 +26,7 @@ #include "terrain_translation.hpp" #include "unit_types.hpp" // for attack_type +#include #include #include @@ -768,6 +769,11 @@ void movetype::merge(const config & new_cfg, bool overwrite) flying_ = new_cfg["flying"].to_bool(flying_); } +/** + * The set of strings defining effects which apply to movetypes. + */ +const std::set movetype::effects = boost::assign::list_of("movement_costs") + ("vision_costs")("jamming_costs")("defense")("resistance"); /** * Writes the movement type data to the provided config. diff --git a/src/movetype.hpp b/src/movetype.hpp index 74e4580af819..a31be7571a13 100644 --- a/src/movetype.hpp +++ b/src/movetype.hpp @@ -229,6 +229,9 @@ class movetype /// Merges the given config over the existing data. void merge(const config & new_cfg, bool overwrite=true); + /// The set of applicable effects for movement types + static const std::set effects; + /// Writes the movement type data to the provided config. void write(config & cfg) const;