patch 751 : add advance from entry in the help system, thanks to jimm

This commit is contained in:
Jérémy Rosen 2007-06-30 10:30:19 +00:00
parent 116285132a
commit aa7368fce9
4 changed files with 59 additions and 3 deletions

View file

@ -8,6 +8,7 @@ Version 1.3.4+svn:
* user interface:
* allow unfocused widgets to steal the focus instead of just borrowing it
* frequency of idle animations halved.
* Help topics for units now have 'advances from' links
Version 1.3.4:
* campaigns

View file

@ -1097,6 +1097,28 @@ public:
ss << "\n";
// Print cross-references to units that this unit advances from.
std::vector<std::string> from_units = type_.advances_from();
if (!from_units.empty())
{
ss << _("Advances from: ");
for (std::vector<std::string>::const_iterator from_iter = from_units.begin();
from_iter != from_units.end();
++from_iter)
{
std::string unit_id = *from_iter;
std::map<std::string,unit_type>::const_iterator from_type = game_info->unit_types.find(unit_id);
if (from_type != game_info->unit_types.end())
{
std::string lang_unit = from_type->second.language_name();
std::string ref_id = std::string("unit_") + from_type->second.id();
ss << "<ref>dst='" << escape(ref_id) << "' text='" << escape(lang_unit) << "'</ref>";
if (from_iter + 1 != from_units.end()) ss << ", ";
}
}
ss << "\n";
}
// Print the units this unit can advance to. Cross reference
// to the topics containing information about those units.
std::vector<std::string> next_units = type_.advances_to();

View file

@ -444,7 +444,7 @@ bool unit_movement_type::is_flying() const
unit_type::unit_type(const unit_type& o)
: variations_(o.variations_), cfg_(o.cfg_), race_(o.race_),
alpha_(o.alpha_), abilities_(o.abilities_),ability_tooltips_(o.ability_tooltips_),
hide_help_(o.hide_help_), advances_to_(o.advances_to_),
hide_help_(o.hide_help_), advances_to_(o.advances_to_), advances_from_(o.advances_from_),
experience_needed_(o.experience_needed_), alignment_(o.alignment_),
movementType_(o.movementType_), possibleTraits_(o.possibleTraits_),
genders_(o.genders_), defensive_animations_(o.defensive_animations_),
@ -931,6 +931,13 @@ const std::string& unit_type::race() const
return race_->name();
}
// Allow storing "advances from" info for convenience in Help.
void unit_type::add_advancesfrom(const unit_type &from_unit)
{
const std::string &from_id = from_unit.cfg_["id"];
advances_from_.push_back(from_id);
}
void unit_type::add_advancement(const unit_type &to_unit,int xp)
{
@ -1023,6 +1030,28 @@ void game_data::set_config(const config& cfg)
increment_set_config_progress();
}
// For all unit types, store what units they advance from
for(unit_type_map::iterator from_unit = unit_types.begin();
from_unit != unit_types.end();
++from_unit)
{
std::vector<std::string> to_units_ids = from_unit->second.advances_to();
for ( std::vector<std::string>::iterator to_unit_id = to_units_ids.begin();
to_unit_id != to_units_ids.end();
++to_unit_id)
{
unit_type_map::iterator to_unit = unit_types.find(*to_unit_id);
if (to_unit != unit_types.end())
{
to_unit->second.add_advancesfrom(from_unit->second);
}
else
{
lg::warn(lg::config) << "unknown unit " << *to_unit_id << " advanced to by unit " << from_unit->first << "\n";
}
}
}
}
void game_data::clear()

View file

@ -153,6 +153,8 @@ public:
// this is used to implement the [advancefrom] tag
void add_advancement(const unit_type &advance_to,int experience);
// Adds units that this unit advances from, for help file purposes.
void add_advancesfrom(const unit_type &advance_from);
const unit_type& get_gender_unit_type(unit_race::GENDER gender) const;
const unit_type& get_variation(const std::string& name) const;
@ -184,6 +186,7 @@ public:
int experience_needed(bool with_acceleration=true) const;
std::vector<std::string> advances_to() const { return advances_to_; }
std::vector<std::string> advances_from() const { return advances_from_; }
const config::child_list& modification_advancements() const { return cfg_.get_children("advancement"); }
const std::string& usage() const { return cfg_["usage"]; }
@ -248,8 +251,9 @@ private:
bool zoc_, hide_help_;
std::vector<std::string> advances_to_;
int experience_needed_;
std::vector<std::string> advances_to_;
std::vector<std::string> advances_from_;
int experience_needed_;
ALIGNMENT alignment_;