From dbed606480148f0d686521e701d438eeb3b60212 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 27 Jul 2014 19:04:13 +0000 Subject: Added faction reputation information to the list_faction engine function. --- src/game/base/faction.cc | 31 ++++++++++++++++++++++++++++++- src/game/base/faction.h | 30 +++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/game/base/faction.cc b/src/game/base/faction.cc index 5b89e8c..07c0a3a 100644 --- a/src/game/base/faction.cc +++ b/src/game/base/faction.cc @@ -9,6 +9,8 @@ #include "core/range.h" #include "base/faction.h" +#include + #include namespace game { @@ -18,7 +20,24 @@ Faction *Faction::faction_default = 0; void func_list_faction(const std::string &args) { - Faction::list(); + if (args.size()) + { + std::istringstream is(args); + std::string label; + + if (is >> label) { + aux::to_label(label); + Faction *faction = Faction::find(label); + if (!faction) { + con_warn << "Unknown faction '" << label << "'" << std::endl; + } else { + faction->print(); + } + } + } else { + Faction::list(); + return; + } } Faction *Faction::find(const std::string & label) @@ -35,6 +54,16 @@ void Faction::list() core::Info::list(faction_infotype); } +void Faction::print() const +{ + core::Info::print(); + + con_print << " ^BFaction repution" << std::endl; + for (core::Reputation::FactionReps::const_iterator rip = reputation().factionreps().begin(); rip != reputation().factionreps().end(); ++rip) { + con_print << " ^B" << std::setw(4) << (*rip)->reputation() << " ^N" << (*rip)->faction()->label() << std::endl; + } +} + bool Faction::init() { // initialize faction InfoType diff --git a/src/game/base/faction.h b/src/game/base/faction.h index 551ce7b..0513bc3 100644 --- a/src/game/base/faction.h +++ b/src/game/base/faction.h @@ -24,25 +24,37 @@ public: /* --- inspectors ------------------------------------------------- */ - inline const math::Color & color() const { + inline const math::Color & color() const + { return faction_color; } - inline const math::Color & color_second() const { + inline const math::Color & color_second() const + { return faction_color_second; } - + + /** + * @brief faction reputation + * */ + inline const core::Reputation & reputation() const + { + return faction_reputation; + } + /** * @brief faction reputation * */ - inline core::Reputation & reputation() { + inline core::Reputation & reputation() + { return faction_reputation; } /** * @brief player reputation with a specific faction * */ - inline const float reputation(const core::Info *faction) const { + inline const float reputation(const core::Info *faction) const + { if (faction == this) { return 100.0f; } else { @@ -59,11 +71,13 @@ public: /* --- mutators --------------------------------------------------- */ - inline void set_color(const math::Color &color) { + inline void set_color(const math::Color &color) + { faction_color.assign(color); } - inline void set_color_second(const math::Color &color_second) { + inline void set_color_second(const math::Color &color_second) + { faction_color_second.assign(color_second); } @@ -77,6 +91,8 @@ public: */ void apply_sale(core::Player *player, const float amount) const; + virtual void print() const; + /* --- static ----------------------------------------------------- */ /** -- cgit v1.2.3