Skip to content

Commit

Permalink
make the help smarter -- musthave traits without filters are applied
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbeck88 committed Jul 17, 2014
1 parent 5560628 commit c39fdae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/help.cpp
Expand Up @@ -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<t_string>::const_iterator ability_it = type_.abilities().begin(),
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<header>text='" << escape(_("Resistances"))
<< "'</header>\n\n";
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/movetype.cpp
Expand Up @@ -26,6 +26,7 @@
#include "terrain_translation.hpp"
#include "unit_types.hpp" // for attack_type

#include <boost/assign.hpp>
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp>

Expand Down Expand Up @@ -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<std::string> movetype::effects = boost::assign::list_of("movement_costs")
("vision_costs")("jamming_costs")("defense")("resistance");

/**
* Writes the movement type data to the provided config.
Expand Down
3 changes: 3 additions & 0 deletions src/movetype.hpp
Expand Up @@ -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<std::string> effects;

/// Writes the movement type data to the provided config.
void write(config & cfg) const;

Expand Down

0 comments on commit c39fdae

Please sign in to comment.