diff options
author | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-24 21:43:51 +0000 |
---|---|---|
committer | dolorous <dolorous@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-24 21:43:51 +0000 |
commit | 1c5dd2f5fa1e94a5f6017f391e4b1d192b7d706c (patch) | |
tree | be0c9c397bb4428abc4aa148c687db16d14d8b5b /crawl-ref/source/describe.cc | |
parent | 0e3ada71c222f6905af710f63177bbee83bd409b (diff) | |
download | crawl-ref-1c5dd2f5fa1e94a5f6017f391e4b1d192b7d706c.tar.gz crawl-ref-1c5dd2f5fa1e94a5f6017f391e4b1d192b7d706c.zip |
Clean up ability handling to display costs for prayer-activated
abilities (Zin's sustenance and Yred's injury mirror) in a less hackish
way.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7593 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/describe.cc')
-rw-r--r-- | crawl-ref/source/describe.cc | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 5805aa6113..3340fbeaf3 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -365,7 +365,7 @@ static std::vector<std::string> _randart_propnames( const item_def& item ) } std::ostringstream work; - switch ( propanns[i].spell_out ) + switch (propanns[i].spell_out) { case 0: // e.g. AC+4 work << std::showpos << propanns[i].name << val; @@ -2640,7 +2640,25 @@ std::string get_ghost_description(const monsters &mons, bool concise) extern ability_type god_abilities[MAX_NUM_GODS][MAX_GOD_ABILITIES]; -static bool _print_god_abil_desc( int god, int numpower ) +static bool _print_final_god_abil_desc(int god, const std::string &final_msg, + const ability_type abil) +{ + // If no message or ability then no power. + if (!final_msg[0] || abil == ABIL_NON_ABILITY) + return (false); + + std::ostringstream buf; + buf << final_msg; + const int spacesleft = 79 - buf.str().length(); + const std::string cost = "(" + make_cost_description(abil) + ")"; + buf << std::setw(spacesleft) << cost; + + cprintf("%s\n", buf.str().c_str()); + + return (true); +} + +static bool _print_god_abil_desc(int god, int numpower) { const char* pmsg = god_gain_power_messages[god][numpower]; @@ -2648,24 +2666,20 @@ static bool _print_god_abil_desc( int god, int numpower ) if (!pmsg[0]) return (false); - std::ostringstream buf; - + std::string buf; if (isupper(pmsg[0])) - buf << pmsg; // Complete sentence given. + buf = pmsg; // Complete sentence given. else - buf << "You can " << pmsg << "."; + { + buf = "You can "; + buf += pmsg; + buf += "."; + } // This might be ABIL_NON_ABILITY for passive abilities. const ability_type abil = god_abilities[god][numpower]; + _print_final_god_abil_desc(god, buf, abil); - if (abil != ABIL_NON_ABILITY) - { - const int spacesleft = 79 - buf.str().length(); - const std::string cost = "(" + make_cost_description(abil) + ")"; - buf << std::setw(spacesleft) << cost; - } - - cprintf( "%s\n", buf.str().c_str() ); return (true); } @@ -3105,8 +3119,11 @@ void describe_god( god_type which_god, bool give_title ) if (zin_sustenance(false)) { have_any = true; - cprintf("Praying to %s will provide sustenance if starving." - EOL, god_name(which_god).c_str()); + std::string buf = "Praying to "; + buf += god_name(which_god); + buf += " will provide sustenance if starving."; + _print_final_god_abil_desc(which_god, buf, + ABIL_ZIN_SUSTENANCE); } const char *how = (you.piety >= 150) ? "carefully" : // res mut. 3 (you.piety >= 100) ? "often" : @@ -3130,30 +3147,27 @@ void describe_god( god_type which_god, bool give_title ) else if (which_god == GOD_TROG) { have_any = true; - // XXX Mega-hack. Duplicates code in _print_god_abil_desc(). - // FIXME. - std::ostringstream buf; - buf << "You can call upon " << god_name(which_god) - << " to burn books in your surroundings."; - const int spacesleft = 79 - buf.str().length(); - const std::string cost = "(" + make_cost_description( - ABIL_TROG_BURN_BOOKS) + ")"; - buf << std::setw(spacesleft) << cost; - cprintf("%s" EOL, buf.str().c_str()); + std::string buf = "You can call upon "; + buf += god_name(which_god); + buf += " to burn spellbooks in your surroundings."; + _print_final_god_abil_desc(which_god, buf, + ABIL_TROG_BURN_SPELLBOOKS); } else if (which_god == GOD_ELYVILON) { have_any = true; - cprintf("You can call upon %s to destroy weapons " - "lying on the ground." EOL, god_name(which_god).c_str()); + cprintf("You can call upon %s to destroy weapons lying on the " + "ground." EOL, god_name(which_god).c_str()); } else if (which_god == GOD_YREDELEMNUL) { if (yred_injury_mirror(false)) { have_any = true; - cprintf("%s mirrors your injuries on your foes " - "during prayer." EOL, god_name(which_god).c_str()); + std::string buf = god_name(which_god); + buf += " mirrors your injuries on your foes during prayer."; + _print_final_god_abil_desc(which_god, buf, + ABIL_YRED_INJURY_MIRROR); } } |