Store trait descriptions in a vector...

...instead of paking/unpacking them all in one string
This commit is contained in:
Ali El Gariani 2010-05-15 12:42:14 +00:00
parent 1b07c6e43f
commit 57f9151afd
5 changed files with 9 additions and 24 deletions

View file

@ -869,7 +869,7 @@ const unit_preview_pane::details units_list_preview_pane::get_details() const
}
det.level = u.level();
det.alignment = unit_type::alignment_description(u.alignment(), u.gender());
det.traits = u.traits_description();
det.traits = utils::join(u.traits_description(), ", ");
//we filter to remove the tooltips (increment by 2)
const std::vector<std::string> &abilities = u.ability_tooltips(true);

View file

@ -148,7 +148,7 @@ report generate_report(TYPE type,
case UNIT_TRAITS: {
tooltip << _("Traits: ") << "\n"
<< u->modification_description("trait");
return report(u->traits_description(), "", tooltip.str());
return report(utils::join(u->traits_description(), ", "), "", tooltip.str());
}
case UNIT_STATUS: {
report res;

View file

@ -295,7 +295,7 @@ void menu_handler::unit_list()
row << COLUMN_SEPARATOR;
// TODO: show 'loyal' in green / xxx in red // how to handle translations ??
row << i->traits_description();
row << utils::join(i->traits_description(), ", ");
items.push_back(row.str());
locations_list.push_back(i->get_location());
@ -892,9 +892,7 @@ void menu_handler::recall(int side_num, const map_location &last_hex)
#ifndef USE_TINY_GUI
option << COLUMN_SEPARATOR;
const std::vector<std::string> traits =
utils::split(u.traits_description(), ',');
foreach (const std::string &trait, traits) {
foreach (const t_string& trait, u.traits_description()) {
option << trait << '\n';
option_to_filter << " " << trait;
}

View file

@ -791,7 +791,7 @@ void unit::advance_to(const unit_type* t, bool use_traits, game_state* state)
t = &t->get_gender_unit_type(gender_).get_variation(variation_);
// Reset the scalar values first
traits_description_ = "";
traits_description_.clear();
is_fearless_ = false;
is_healthy_ = false;
@ -2610,12 +2610,12 @@ void unit::apply_modifications()
const char *gender_string = gender_ == unit_race::FEMALE ? "female_name" : "male_name";
t_string const &gender_specific_name = m[gender_string];
if (!gender_specific_name.empty()) {
traits.push_back(gender_specific_name);
traits_description_.push_back(gender_specific_name);
m["name"] = gender_specific_name;
} else {
t_string const &name = m["name"];
if (!name.empty()) {
traits.push_back(name);
traits_description_.push_back(name);
}
}
}
@ -2628,19 +2628,6 @@ void unit::apply_modifications()
}
}
std::vector< t_string >::iterator k = traits.begin(), k_end = traits.end();
if (k != k_end) {
// We want to make sure the traits always have a consistent ordering.
// Try out not sorting, since quick,resilient can give different HP
// to resilient,quick so rather preserve order
// std::sort(k, k_end);
for(;;) {
traits_description_ += *(k++);
if (k == k_end) break;
traits_description_ += ", ";
}
}
//apply the experience acceleration last
int exp_accel = unit_type::experience_accelerator::get_acceleration();
max_experience_ = std::max<int>(1, (max_experience_ * exp_accel + 50)/100);

View file

@ -207,7 +207,7 @@ public:
map_location::DIRECTION facing() const { return facing_; }
bool invalidate(const map_location &loc);
const t_string& traits_description() const { return traits_description_; }
const std::vector<t_string>& traits_description() const { return traits_description_; }
std::vector<std::string> get_traits_list() const;
int cost () const { return unit_value_; }
@ -412,7 +412,7 @@ private:
std::vector<attack_type> attacks_;
map_location::DIRECTION facing_;
t_string traits_description_;
std::vector<t_string> traits_description_;
int unit_value_;
map_location goto_, interrupted_move_;
std::vector<map_location> waypoints_;