Generate trait help instead of hardcoding

Introduces a new key "help_text=" in [trait]
This commit is contained in:
Bär Halberkamp 2016-07-26 22:52:43 -04:00
parent 95c4556a59
commit 4e71bbe448
5 changed files with 112 additions and 127 deletions

View file

@ -1,4 +1,9 @@
Version 1.13.5+dev:
* User Interface:
* Trait descriptions in the help are now generated. (This makes user-defined
traits show up in the help as well.)
* WML Engine:
* New help_text= key for [trait] to set the description displayed in the help.
Version 1.13.5:
* Campaigns:

View file

@ -27,10 +27,9 @@
[section]
id=traits_section
title= _ "Traits"
topics=..traits_section,traits_fearless,traits_intelligent,traits_resilient,traits_strong,traits_quick,traits_dextrous,traits_healthy,traits_dim,traits_slow,traits_weak,traits_feral,traits_loyal,traits_undead,traits_mechanical,traits_elemental,traits_aged
# Not used since generated text was not really suitable.
#generator=traits
sort_topics=no
topics=..traits_section
generator=traits
sort_topics=generated
[/section]
[section]
@ -396,7 +395,7 @@ Unlike other forms of healing, the heals ability will not take effect on the hea
[topic]
id=..traits_section
title= _ "Traits"
generator="contents:traits_section"
generator="contents:generated"
text= _ "Traits are modifications that change a units attributes slightly. They are usually randomly assigned to a unit when it is recruited. The traits available to a unit are largely determined by its <italic>text='race'</italic>." + _ "
Most units have two traits. However, goblins have only one trait, undead units are always assigned the single trait <italic>text='undead'</italic> and in some cases <italic>text='fearless'</italic>, and woses do not receive any traits. " + _ "
@ -407,129 +406,7 @@ Elves may also receive <ref>dst='traits_dextrous' text='dextrous'</ref>, and dwa
"
[/topic]
# wmllint: markcheck on
[topic]
id=traits_intelligent
title= _ "Intelligent"
text= _ "Intelligent units require 20% less experience than usual to advance." + _ "
<italic>text='Intelligent'</italic> units are very useful at the beginning of a campaign as they can advance to higher levels more quickly. Later in campaigns Intelligent is not quite as useful because the <italic>text='After Maximum Level Advancement'</italic> (AMLA) is not as significant a change as advancing a level. If you have many maximum level units you may wish to recall units with more desirable traits."
[/topic]
[topic]
id=traits_quick
title= _ "Quick"
text= _ "<italic>text='Quick'</italic> units have 1 extra movement point, but 5% less hitpoints than usual." + _ "
Quick is the most noticeable trait, particularly in slower moving units such as trolls or heavy infantry. Units with the quick trait often have greatly increased mobility in rough terrain, which can be important to consider when deploying your forces. Also, quick units arent quite as tough as units without this trait and are subsequently less good at holding contested positions."
[/topic]
[topic]
id=traits_resilient
title= _ "Resilient"
text= _ "<italic>text='Resilient'</italic> units have an additional 4 hitpoints, and gain 1 more per level." + _ "
Resilient units can be useful at all stages of a campaign, and this is a useful trait for all units. Resilient is often most helpful as a trait when it occurs in a unit that has some combination of low hitpoints, good defense, or high resistances. Resilient units are especially useful for holding strategic positions against opponents."
[/topic]
[topic]
id=traits_strong
title= _ "Strong"
text= _ "<italic>text='Strong'</italic> units do 1 more damage for every successful strike in melee combat, and have 1 additional hitpoint." + _ "
While useful for any close-combat unit, strong is most effective for units who have a high number of swings such as the elvish fighter. Strong units can be very useful when a tiny bit of extra damage is all that is needed to turn a damaging stroke into a killing blow."
[/topic]
[topic]
id=traits_fearless
title= _ "Fearless"
text= _ "Aversion to light and dark holds no sway over these brave individuals."
[/topic]
[topic]
id=traits_feral
title= _ "Feral"
text= _ "Dwellings of sentient beings are not easily used for cover by feral creatures of low intelligence. As a result, <italic>text='feral'</italic> units receive a maximum of 50% defense in any land-based village regardless of base terrain."
[/topic]
[topic]
id=traits_loyal
title= _ "Loyal"
text= _ "<italic>text='Loyal'</italic> units dont incur upkeep. Most units incur an upkeep cost at the end of every turn, which is equal to their level. Loyal units do not incur this cost." + _ "
During campaigns, certain units may opt to join the players forces of their own volition. These units are marked with the loyal trait. Although they may require payment to be recalled, they never incur any upkeep costs. This can make them invaluable during a long campaign, when gold is in short supply. This trait is never given to recruited units, so it may be unwise to dismiss such units or to send them to a foolish death."
[/topic]
[topic]
id=traits_undead
title= _ "trait^Undead" # wmllint: no spellcheck
text= _ "<italic>text='Undead'</italic> units are immune to poison, drain, and plague." + _ "
Undead units generally have undead as their only trait. Since undead units are the bodies of the dead, risen to fight again, poison has no effect upon them. This can make them invaluable in dealing with foes who use poison in conjunction with their attacks."
[/topic]
[topic]
id=traits_mechanical
title= _ "trait^Mechanical" # wmllint: no spellcheck
text= _ "<italic>text='Mechanical'</italic> units are immune to poison, drain, and plague." + _ "
Mechanical units generally have mechanical as their only trait. Since mechanical units dont really have life, drain, poison, and plague have no effect upon them."
[/topic]
[topic]
id=traits_elemental
title= _ "trait^Elemental"
text= _ "<italic>text='Elemental'</italic> units are immune to poison, drain, and plague." + _ "
Elemental units generally have elemental as their only trait. Since elemental units are energy-based beings, drain, poison, and plague have no effect upon them."
[/topic]
[topic]
id=traits_dextrous
title= _ "Dextrous" # wmllint: no spellcheck
text= _ "<italic>text='Dextrous'</italic> units do 1 more damage for every successful strike in ranged combat." + _ "
Dextrous is a trait possessed only by elves. The elven people are known for their uncanny grace, and their great facility with the bow. Some, however, are gifted with natural talent that exceeds their brethren. These elves inflict an additional point of damage with each arrow."
[/topic]
[topic]
id=traits_healthy
title= _ "Healthy"
text= _ "Renowned for their vitality, some dwarves are sturdier than others and can rest even when traveling." + _ "
<italic>text='Healthy'</italic> units have 1 additional hitpoint, and gain 1 more per level. They will also heal 2 hitpoints each turn, regardless of whether they engaged in combat the turn before."
[/topic]
[topic]
id=traits_dim
title= _ "Dim"
text= _ "Units with trait <italic>text='dim'</italic> suffer a 20% increase in experience required to advance." + _ "
Dim is a trait all too common in goblins and other lesser species. There are reasons these species are lesser, and this is one of them."
[/topic]
[topic]
id=traits_slow
title= _ "Slow"
text= _ "<italic>text='Slow'</italic> units have 1 less movement point but 5% more hitpoints." + _ "
Thick-bodied and clumsy, slow individuals of goblins and other species take a movement penalty but are compensated for it with a slight increase in endurance."
[/topic]
[topic]
id=traits_weak
title= _ "Weak"
text= _ "Units with the <italic>text='weak'</italic> trait receive a 1 point decrease in hitpoints and melee damage."
[/topic]
[topic]
id=traits_aged
title= _ "trait^Aged"
text= _ "Units with the <italic>text='aged'</italic> trait have 8 hitpoints less and suffer from a 1 point decrease in movement and melee damage."
[/topic]
# wmllint: markcheck off
[topic]
id=..terrains_section
title= _ "Terrains"

View file

@ -8,6 +8,9 @@
male_name= _ "loyal"
female_name= _ "female^loyal"
description= _ "Zero upkeep"
help_text= _ "<italic>text='Loyal'</italic> units dont incur upkeep. Most units incur an upkeep cost at the end of every turn, which is equal to their level. Loyal units do not incur this cost." + _ "
During campaigns, certain units may opt to join the players forces of their own volition. These units are marked with the loyal trait. Although they may require payment to be recalled, they never incur any upkeep costs. This can make them invaluable during a long campaign, when gold is in short supply. This trait is never given to recruited units, so it may be unwise to dismiss such units or to send them to a foolish death."
[effect]
apply_to=loyal
[/effect]
@ -22,6 +25,9 @@
male_name= _ "undead"
female_name= _ "female^undead"
description= _ "Immune to drain, poison, and plague"
help_text= _ "<italic>text='Undead'</italic> units are immune to poison, drain, and plague." + _ "
Undead units generally have undead as their only trait. Since undead units are the bodies of the dead, risen to fight again, poison has no effect upon them. This can make them invaluable in dealing with foes who use poison in conjunction with their attacks."
[effect]
apply_to=status
add=unpoisonable
@ -45,6 +51,9 @@
male_name= _ "mechanical"
female_name= _ "female^mechanical"
description= _ "Immune to drain, poison, and plague"
help_text= _ "<italic>text='Mechanical'</italic> units are immune to poison, drain, and plague." + _ "
Mechanical units generally have mechanical as their only trait. Since mechanical units dont really have life, drain, poison, and plague have no effect upon them."
[effect]
apply_to=status
add=unpoisonable
@ -68,6 +77,9 @@
male_name= _ "elemental"
female_name= _ "female^elemental"
description= _ "Immune to drain, poison, and plague"
help_text= _ "<italic>text='Elemental'</italic> units are immune to poison, drain, and plague." + _ "
Elemental units generally have elemental as their only trait. Since elemental units are energy-based beings, drain, poison, and plague have no effect upon them."
[effect]
apply_to=status
add=unpoisonable
@ -89,6 +101,9 @@
id=strong
male_name= _ "strong"
female_name= _ "female^strong"
help_text= _ "<italic>text='Strong'</italic> units do 1 more damage for every successful strike in melee combat, and have 1 additional hitpoint." + _ "
While useful for any close-combat unit, strong is most effective for units who have a high number of swings such as the elvish fighter. Strong units can be very useful when a tiny bit of extra damage is all that is needed to turn a damaging stroke into a killing blow."
[effect]
apply_to=attack
range=melee
@ -107,6 +122,9 @@
id=dextrous
male_name= _ "dextrous"
female_name= _ "female^dextrous"
help_text= _ "<italic>text='Dextrous'</italic> units do 1 more damage for every successful strike in ranged combat." + _ "
Dextrous is a trait possessed only by elves. The elven people are known for their uncanny grace, and their great facility with the bow. Some, however, are gifted with natural talent that exceeds their brethren. These elves inflict an additional point of damage with each arrow."
[effect]
apply_to=attack
range=ranged
@ -121,6 +139,9 @@
id=quick
male_name= _ "quick"
female_name= _ "female^quick"
help_text= _ "<italic>text='Quick'</italic> units have 1 extra movement point, but 5% less hitpoints than usual." + _ "
Quick is the most noticeable trait, particularly in slower moving units such as trolls or heavy infantry. Units with the quick trait often have greatly increased mobility in rough terrain, which can be important to consider when deploying your forces. Also, quick units arent quite as tough as units without this trait and are subsequently less good at holding contested positions."
[effect]
apply_to=movement
increase=1
@ -138,6 +159,9 @@
id=intelligent
male_name= _ "intelligent"
female_name= _ "female^intelligent"
help_text= _ "Intelligent units require 20% less experience than usual to advance." + _ "
<italic>text='Intelligent'</italic> units are very useful at the beginning of a campaign as they can advance to higher levels more quickly. Later in campaigns Intelligent is not quite as useful because the <italic>text='After Maximum Level Advancement'</italic> (AMLA) is not as significant a change as advancing a level. If you have many maximum level units you may wish to recall units with more desirable traits."
[effect]
apply_to=max_experience
increase=-20%
@ -151,6 +175,9 @@
id=resilient
male_name= _ "resilient"
female_name= _ "female^resilient"
help_text= _ "<italic>text='Resilient'</italic> units have an additional 4 hitpoints, and gain 1 more per level." + _ "
Resilient units can be useful at all stages of a campaign, and this is a useful trait for all units. Resilient is often most helpful as a trait when it occurs in a unit that has some combination of low hitpoints, good defense, or high resistances. Resilient units are especially useful for holding strategic positions against opponents."
[effect]
apply_to=hitpoints
increase_total=4
@ -170,6 +197,9 @@
male_name= _ "healthy"
female_name= _ "female^healthy"
description= _ "Always rest heals"
help_text= _ "Renowned for their vitality, some dwarves are sturdier than others and can rest even when traveling." + _ "
<italic>text='Healthy'</italic> units have 1 additional hitpoint, and gain 1 more per level. They will also heal 2 hitpoints each turn, regardless of whether they engaged in combat the turn before."
[effect]
apply_to="healthy"
[/effect]
@ -192,6 +222,7 @@
male_name= _ "fearless"
female_name= _ "female^fearless"
description= _ "Fights normally during unfavorable times of day/night"
help_text= _ "Aversion to light and dark holds no sway over these brave individuals."
[effect]
apply_to="fearless"
[/effect]
@ -208,6 +239,7 @@
male_name= _ "fearless"
female_name= _ "female^fearless"
description= _ "Fights normally during unfavorable times of day/night"
help_text= _ "Aversion to light and dark holds no sway over these brave individuals."
[effect]
apply_to="fearless"
[/effect]
@ -223,6 +255,7 @@
male_name= _ "feral"
female_name= _ "female^feral"
description= _ "Receives only 50% defense in land-based villages"
help_text= _ "Dwellings of sentient beings are not easily used for cover by feral creatures of low intelligence. As a result, <italic>text='feral'</italic> units receive a maximum of 50% defense in any land-based village regardless of base terrain."
[effect]
apply_to=defense
replace=true
@ -240,6 +273,7 @@
id=weak
male_name= _ "weak"
female_name= _ "female^weak"
help_text= _ "Units with the <italic>text='weak'</italic> trait receive a 1 point decrease in hitpoints and melee damage."
[effect]
apply_to=attack
range=melee
@ -258,6 +292,9 @@
id=slow
male_name= _ "slow"
female_name= _ "female^slow"
help_text= _ "<italic>text='Slow'</italic> units have 1 less movement point but 5% more hitpoints." + _ "
Thick-bodied and clumsy, slow individuals of goblins and other species take a movement penalty but are compensated for it with a slight increase in endurance."
[effect]
apply_to=movement
increase=-1
@ -275,6 +312,9 @@
id=dim
male_name= _ "dim"
female_name= _ "female^dim"
help_text= _ "Units with trait <italic>text='dim'</italic> suffer a 20% increase in experience required to advance." + _ "
Dim is a trait all too common in goblins and other lesser species. There are reasons these species are lesser, and this is one of them."
[effect]
apply_to=max_experience
increase=20%
@ -288,6 +328,7 @@
id=aged
male_name= _ "aged"
female_name= _ "female^aged"
help_text= _ "Units with the <italic>text='aged'</italic> trait have 8 hitpoints less and suffer from a 1 point decrease in movement and melee damage."
[effect]
apply_to=hitpoints
increase_total=-8

View file

@ -270,6 +270,8 @@ std::vector<topic> generate_topics(const bool sort_generated,const std::string &
res = generate_weapon_special_topics(sort_generated);
} else if (generator == "time_of_days") {
res = generate_time_of_day_topics(sort_generated);
} else if (generator == "traits") {
res = generate_trait_topics(sort_generated);
} else {
std::vector<std::string> parts = utils::split(generator, ':', utils::STRIP_SPACES);
if (parts[0] == "units" && parts.size()>1) {
@ -623,6 +625,65 @@ std::vector<topic> generate_faction_topics(const config & era, const bool sort_g
return topics;
}
std::vector<topic> generate_trait_topics(const bool sort_generated)
{
std::vector<topic> topics;
std::map<t_string, const config> trait_list;
for (const config & trait : unit_types.traits()) {
const std::string trait_id = trait["id"];
trait_list.insert(std::make_pair(trait_id, trait));
}
for (const unit_type_data::unit_type_map::value_type &i : unit_types.types())
{
const unit_type &type = i.second;
if (description_type(type) == FULL_DESCRIPTION) {
config::const_child_itors traits = type.possible_traits();
if (traits.first != traits.second && type.num_traits() > 0) {
for (const config & trait : traits) {
const std::string trait_id = trait["id"];
trait_list.insert(std::make_pair(trait_id, trait));
}
}
if (const unit_race *r = unit_types.find_race(type.race_id())) {
for (const config & trait : r->additional_traits()) {
const std::string trait_id = trait["id"];
trait_list.insert(std::make_pair(trait_id, trait));
}
}
}
}
for (std::map<t_string, const config>::iterator a = trait_list.begin(); a != trait_list.end(); ++a) {
std::string id = "traits_" + a->first;
const config trait = a->second;
std::stringstream text;
if (trait["help_text"].empty()) {
text << trait["description"];
} else {
text << trait["help_text"];
}
text << "\n\n";
if (trait["availability"] == "musthave") {
text << _("Availability: ") << _("Must-have") << "\n";
} else if (trait["availability"] == "none") {
text << _("Availability: ") << _("Unavailable") << "\n";
}
std::string name = trait["male_name"].str();
if (name.empty()) name = trait["female_name"].str();
if (name.empty()) name = trait["name"].str();
topics.push_back( topic(name, id, text.str()) );
}
if (sort_generated)
std::sort(topics.begin(), topics.end(), title_less());
return topics;
}
std::string make_unit_link(const std::string& type_id)
{
std::string link;

View file

@ -260,6 +260,7 @@ std::vector<topic> generate_weapon_special_topics(const bool);
void generate_era_sections(const config *help_cfg, section &sec, int level);
std::vector<topic> generate_faction_topics(const config &, const bool);
std::vector<topic> generate_era_topics(const bool, const std::string & era_id);
std::vector<topic> generate_trait_topics(const bool);
/// Parse a help config, return the top level section. Return an empty
/// section if cfg is nullptr.