- Multiple traits conditions:
has_trait("MUZZLE") || has_trait("MUZZLE_BEAR") || has_trait("MUZZLE_LONG") || has_trait("MUZZLE_RAT")
Decision: Add method “has_trait_flag(std::string flag)” and one or more flags for traits.
- Traits stat bonuses
if (has_trait("HOLLOW_BONES")) {
movecost *= .8f;
}
...
int player::rust_rate(bool return_stat_effect) const
...
if (has_trait("FORGETFUL")) {
ret *= 1.33;
}
...
Decision: add next structure to trait:
map<string, stat_bonus> bonuses;
where stat_bonus is
struct stat_bonus {string stat (str, dex, rust_rate etc), bool increase (+/-), bool multiply, (* or not), int i, float f, int order};
Next, if you need get movecost mod from traits you do something like
int movecost = 100;
calc_stat_bonus("movecost",&movecost);
method calc_stat_bonus run over all stats, get all that have stat “movecost”, reorder them and calculate bonus. All information about stat bonuses can be store in jsons.
3. Harcoded effects
For penalty/bonuses way like traits
For code :
- Add proceed_effect_player() virtual method.
- Add player *p; field to effect.
- Make class for each effect inherited from this.
- Remove huge part of code from player.cpp to small classes
- Conditions for effects. Parser for simply conditions like (str > 10), (str > 6 && dex > 4) + methods get_stat(string/enum stat_name), set_stat(string/enum stat_name, string/int/float value)