From af65a4e054eb0cb18f736776f7fa3bcc29e4eb9c Mon Sep 17 00:00:00 2001 From: haranp Date: Sat, 4 Aug 2007 21:43:38 +0000 Subject: Minor code review of the Beogh idol revenge and Trog/Ely destruction stuff. Xom won't protect you from Beogh revenge, too capricious for that. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1969 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 80 +++++++++++++++++----------------------- crawl-ref/source/direct.cc | 2 +- crawl-ref/source/ghost.cc | 15 +++----- crawl-ref/source/religion.cc | 88 ++++++++++++++++++++++---------------------- crawl-ref/source/religion.h | 2 +- 5 files changed, 84 insertions(+), 103 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index ae53d55904..b49295aa11 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -927,7 +927,6 @@ static bool do_ability(const ability_def& abil) } case ABIL_DELAYED_FIREBALL: - { if ( !spell_direction(spd, beam, DIR_NONE, TARG_ENEMY) ) return (false); @@ -937,7 +936,6 @@ static bool do_ability(const ability_def& abil) // only one allowed since this is instantaneous -- bwr you.attribute[ ATTR_DELAYED_FIREBALL ] = 0; break; - } case ABIL_GLAMOUR: if (you.duration[DUR_GLAMOUR]) @@ -1511,16 +1509,10 @@ static bool do_ability(const ability_def& abil) break; case ABIL_ELYVILON_DESTROY_WEAPONS: - { - int i = igrd[you.x_pos][you.y_pos]; - if (i != NON_ITEM) - { - ely_destroy_weapons(); - break; - } - mpr("There are no items here."); + if ( !ely_destroy_weapons() ) + return false; break; - } + case ABIL_ELYVILON_LESSER_HEALING: if (!cast_healing( 3 + (you.skills[SK_INVOCATIONS] / 6) )) break; @@ -1794,7 +1786,7 @@ int choose_ability_menu(const std::vector& talents) if ( Options.tutorial_left ) { - // XXX This could be buggy if manage to pick up lots and lots + // XXX This could be buggy if you manage to pick up lots and lots // of abilities during the tutorial. abil_menu.set_more(tut_abilities_info()); abil_menu.set_flags(MF_SINGLESELECT | MF_ANYPRINTABLE | @@ -1846,24 +1838,21 @@ std::vector your_talents( bool check_confused ) { std::vector talents; - // first we do the racial abilities: + // Species-based abilities if (you.species == SP_MUMMY && you.experience_level >= 13) add_talent(talents, ABIL_MUMMY_RESTORATION, check_confused); - // checking for species-related abilities and mutagenic counterparts {dlb}: - if (you.attribute[ATTR_TRANSFORMATION] == TRAN_NONE - && ((you.species == SP_GREY_ELF && you.experience_level >= 5) - || (you.species == SP_HIGH_ELF && you.experience_level >= 15))) + if ( ((you.species == SP_GREY_ELF && you.experience_level >= 5) || + (you.species == SP_HIGH_ELF && you.experience_level >= 15)) && + you.attribute[ATTR_TRANSFORMATION] == TRAN_NONE ) { add_talent(talents, ABIL_GLAMOUR, check_confused); } if (you.species == SP_NAGA) { - if (you.mutation[MUT_BREATHE_POISON]) - add_talent(talents, ABIL_BREATHE_POISON, check_confused ); - else - add_talent(talents, ABIL_SPIT_POISON, check_confused ); + add_talent(talents, you.mutation[MUT_BREATHE_POISON] ? + ABIL_BREATHE_POISON : ABIL_SPIT_POISON, check_confused); } else if (you.mutation[MUT_SPIT_POISON]) { @@ -1895,22 +1884,6 @@ std::vector your_talents( bool check_confused ) add_talent(talents, ABIL_TRAN_BAT, check_confused ); } - if (you.religion == GOD_ELYVILON) - { - add_talent(talents, ABIL_ELYVILON_DESTROY_WEAPONS, check_confused ); - } - else if (you.religion == GOD_TROG) - { - add_talent(talents, ABIL_TROG_BURN_BOOKS, check_confused ); - } - - //jmf: alternately put check elsewhere - if ((you.level_type == LEVEL_DUNGEON && you.mutation[MUT_MAPPING]) || - (you.level_type == LEVEL_PANDEMONIUM && you.mutation[MUT_MAPPING]==3)) - { - add_talent(talents, ABIL_MAPPING, check_confused ); - } - if (!you.duration[DUR_CONTROLLED_FLIGHT] && !player_is_levitating()) { // kenku can fly, but only from the ground @@ -1922,7 +1895,13 @@ std::vector your_talents( bool check_confused ) add_talent(talents, ABIL_FLY_II, check_confused ); } - // demonic powers {dlb}: + // Mutations + if ((you.level_type == LEVEL_DUNGEON && you.mutation[MUT_MAPPING]) || + (you.level_type == LEVEL_PANDEMONIUM && you.mutation[MUT_MAPPING]==3)) + { + add_talent(talents, ABIL_MAPPING, check_confused ); + } + if (you.mutation[MUT_SUMMON_MINOR_DEMONS]) add_talent(talents, ABIL_SUMMON_MINOR_DEMON, check_confused ); @@ -1965,6 +1944,16 @@ std::vector your_talents( bool check_confused ) if (you.mutation[MUT_TELEPORT_AT_WILL]) add_talent(talents, ABIL_TELEPORTATION, check_confused ); + // Religious abilities + if (you.religion == GOD_ELYVILON) + { + add_talent(talents, ABIL_ELYVILON_DESTROY_WEAPONS, check_confused ); + } + else if (you.religion == GOD_TROG) + { + add_talent(talents, ABIL_TROG_BURN_BOOKS, check_confused ); + } + // gods take abilities away until penance completed -- bwr if (!player_under_penance() && !silenced( you.x_pos, you.y_pos )) { @@ -1990,16 +1979,14 @@ std::vector your_talents( bool check_confused ) add_talent(talents, ABIL_BREATHE_HELLFIRE, check_confused ); } else if (you.attribute[ATTR_TRANSFORMATION] == TRAN_DRAGON - || you.mutation[MUT_BREATHE_FLAMES]) + || you.mutation[MUT_BREATHE_FLAMES]) { add_talent(talents, ABIL_BREATHE_FIRE, check_confused ); } // checking for unreleased delayed fireball if (you.attribute[ ATTR_DELAYED_FIREBALL ]) - { add_talent(talents, ABIL_DELAYED_FIREBALL, check_confused ); - } // evocations from items: if (scan_randarts(RAP_BLINK)) @@ -2016,8 +2003,8 @@ std::vector your_talents( bool check_confused ) || scan_randarts( RAP_INVISIBLE )) { // Now you can only turn invisibility off if you have an - // activatable item. Wands and potions allow will have - // to time out. -- bwr + // activatable item. Wands and potions will have to time + // out. -- bwr if (you.duration[DUR_INVIS]) add_talent(talents, ABIL_EVOKE_TURN_VISIBLE, check_confused ); else @@ -2034,10 +2021,9 @@ std::vector your_talents( bool check_confused ) // activatable item. Potions and miscast effects will // have to time out (this makes the miscast effect actually // a bit annoying). -- bwr - if (you.duration[DUR_LEVITATION]) - add_talent(talents, ABIL_EVOKE_STOP_LEVITATING, check_confused ); - else - add_talent(talents, ABIL_EVOKE_LEVITATE, check_confused ); + add_talent(talents, you.duration[DUR_LEVITATION] ? + ABIL_EVOKE_STOP_LEVITATING : ABIL_EVOKE_LEVITATE, + check_confused); } if (player_equip( EQ_RINGS, RING_TELEPORTATION ) diff --git a/crawl-ref/source/direct.cc b/crawl-ref/source/direct.cc index c08a7fa406..d8dcb66f74 100644 --- a/crawl-ref/source/direct.cc +++ b/crawl-ref/source/direct.cc @@ -302,7 +302,7 @@ void direction(dist& moves, targeting_type restricts, } bool show_prompt = true; - while (1) + while (true) { // Prompts might get scrolled off if you have too few lines available. // We'll live with that. diff --git a/crawl-ref/source/ghost.cc b/crawl-ref/source/ghost.cc index 8a9e69a612..bd4f3b84b7 100644 --- a/crawl-ref/source/ghost.cc +++ b/crawl-ref/source/ghost.cc @@ -189,30 +189,27 @@ void ghost_demon::init_random_demon() for the demon, then converts those spells to the monster spell indices. Some special monster-only spells are at the end. */ if (values[ GVAL_DEMONLORD_SPELLCASTER ] == 1) - { -#define RANDOM_ARRAY_ELEMENT(x) x[random2(sizeof(x) / sizeof(x[0]))] - + { if (coinflip()) - values[GVAL_SPELL_1]=RANDOM_ARRAY_ELEMENT(search_order_conj); + values[GVAL_SPELL_1] = RANDOM_ELEMENT(search_order_conj); // Might duplicate the first spell, but that isn't a problem. if (coinflip()) - values[GVAL_SPELL_2]=RANDOM_ARRAY_ELEMENT(search_order_conj); + values[GVAL_SPELL_2] = RANDOM_ELEMENT(search_order_conj); if (!one_chance_in(4)) - values[GVAL_SPELL_3]=RANDOM_ARRAY_ELEMENT(search_order_third); + values[GVAL_SPELL_3] = RANDOM_ELEMENT(search_order_third); if (coinflip()) { - values[GVAL_SPELL_4]=RANDOM_ARRAY_ELEMENT(search_order_misc); + values[GVAL_SPELL_4] = RANDOM_ELEMENT(search_order_misc); if ( values[GVAL_SPELL_4] == SPELL_DIG ) values[GVAL_SPELL_4] = SPELL_NO_SPELL; } if (coinflip()) - values[GVAL_SPELL_5]=RANDOM_ARRAY_ELEMENT(search_order_misc); + values[GVAL_SPELL_5] = RANDOM_ELEMENT(search_order_misc); -#undef RANDOM_ARRAY_ELEMENT if (coinflip()) values[ GVAL_SPELL_6 ] = SPELL_BLINK; diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index d9ace426eb..63d312a21a 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -1482,10 +1482,10 @@ static bool need_water_walking() grd[you.x_pos][you.y_pos] == DNGN_DEEP_WATER; } -void ely_destroy_weapons() +bool ely_destroy_weapons() { if (you.religion != GOD_ELYVILON) - return; + return false; bool success; int i = igrd[you.x_pos][you.y_pos]; @@ -1499,14 +1499,13 @@ void ely_destroy_weapons() i = next; continue; } - - const char *ssuffix = mitm[i].quantity == 1? "s" : ""; - std::string text = mitm[i].name(DESC_CAP_THE); - text += " shimmer"; text += ssuffix; - text += " and break"; text += ssuffix; - text += " into pieces."; - mpr(text.c_str()); + std::ostream& strm = msg::streams(MSGCH_GOD); + strm << mitm[i].name(DESC_CAP_THE); + if ( mitm[i].quantity == 1 ) + strm << " shimmers and breaks into pieces." << std::endl; + else + strm << " shimmer and break into pieces." << std::endl; const int value = item_value( mitm[i], true ); #ifdef DEBUG_DIAGNOSTICS @@ -1517,17 +1516,20 @@ void ely_destroy_weapons() || (mitm[i].base_type == OBJ_WEAPONS && (you.piety < 30 || player_under_penance()))) { - gain_piety(1); + gain_piety(1); } destroy_item(i); success = true; i = next; } + if (!success) { mpr("There are no weapons here to destroy!"); } + + return success; } void trog_burn_books() @@ -1548,6 +1550,9 @@ void trog_burn_books() } i = next; } + + // From now on, it will always cost a turn, to prevent leaking + // information about whether books exist (not that it matters much.) int totalpiety = 0; for (int xpos = you.x_pos - 8; xpos < you.x_pos + 8; xpos++) @@ -1627,14 +1632,8 @@ void trog_burn_books() place_cloud( CLOUD_FIRE, xpos, ypos, durat, KC_YOU ); - const char *plural = count == 1? "" : "s"; - const char *ssuffix = count == 1? "s" : ""; - - std::string text = "The book"; text += plural; - text += " burst"; text += ssuffix; - text += " into flames."; - - mpr(text.c_str()); + mpr(count == 1 ? "The book bursts into flames." + : "The books burst into flames.", MSGCH_GOD); } } @@ -1697,7 +1696,7 @@ void lose_piety(int pgn) { // every piety level change also affects AC from // orcish gear - you.redraw_armour_class = 1; + you.redraw_armour_class = true; } } } @@ -2434,15 +2433,15 @@ bool followers_abandon_you() return false; } -// Destroying orcish idols (a.k.a. idols of Beogh) -// may anger Beogh +// Destroying orcish idols (a.k.a. idols of Beogh) may anger Beogh void beogh_idol_revenge() { // Beogh watches his charges closely, but for others doesn't always notice - if (you.religion == GOD_BEOGH || you.species == SP_HILL_ORC && coinflip() + if (you.religion == GOD_BEOGH + || (you.species == SP_HILL_ORC && coinflip()) || one_chance_in(3)) { - if (you.religion != GOD_BEOGH && + if (you.religion != GOD_BEOGH && you.religion != GOD_XOM && !player_under_penance() && you.piety > random2(400)) { snprintf(info, INFO_SIZE, "Mortal, I have averted the wrath " @@ -2453,32 +2452,28 @@ void beogh_idol_revenge() { if (you.religion == GOD_BEOGH) { - switch(random2(3)) - { - case 0: - snprintf(info, INFO_SIZE, " fumes, \"This is no small sin, orc. Repent!\""); - break; - case 1: - snprintf(info, INFO_SIZE, " whispers, \"You will pay for this transgression.\""); - break; - default: - snprintf(info, INFO_SIZE, " rages, \"Eye for an eye...\""); - } - simple_god_message(info, GOD_BEOGH); + const char* messages[3] = { + " fumes, \"This is no small sin, orc. Repent!\"", + " whispers, \"You will pay for this transgression.\"", + " rages, \"An eye for an eye...\"" + }; + simple_god_message(RANDOM_ELEMENT(messages), GOD_BEOGH); } else if (you.species == SP_HILL_ORC) { - if (coinflip()) - simple_god_message("'s voice booms out: \"Heretic, die!\"", GOD_BEOGH); - else - god_speaks(GOD_BEOGH, "You hear Beogh's thundering voice: \"Suffer, infidel!\""); + const char* messages[2] = { + "Beogh's voice booms out: \"Heretic, die!\"", + "You hear Beogh's thundering voice: \"Suffer, infidel!\"" + }; + god_speaks(GOD_BEOGH, RANDOM_ELEMENT(messages)); } else { - if (coinflip()) - simple_god_message(" is not amused about the destruction of his idols.", GOD_BEOGH); - else - simple_god_message(" seems highly displeased.", GOD_BEOGH); + const char* messages[2] = { + " is not amused about the destruction of his idols.", + " seems highly displeased." + }; + simple_god_message(RANDOM_ELEMENT(messages), GOD_BEOGH); } int divine_hurt = 10 + random2(10); @@ -2489,6 +2484,7 @@ void beogh_idol_revenge() simple_god_message( " smites you!", GOD_BEOGH ); ouch( divine_hurt, 0, KILLED_BY_BEOGH_SMITING ); } + if (you.religion == GOD_BEOGH) { // comes closest and same result (penance + piety loss) @@ -2889,11 +2885,13 @@ void god_pitch(god_type which_god) if (you.religion == GOD_ELYVILON) { - mpr("You can now call upon Elyvilon to destroy weapons lying on the ground."); + mpr("You can now call upon Elyvilon to destroy weapons " + "lying on the ground.", MSGCH_GOD); } else if (you.religion == GOD_TROG) { - mpr("You can now call upon Trog to burn books in your surroundings."); + mpr("You can now call upon Trog to burn books in your surroundings.", + MSGCH_GOD); } if (you.worshipped[you.religion] < 100) diff --git a/crawl-ref/source/religion.h b/crawl-ref/source/religion.h index 7b8eacc1ec..b07f1cff08 100644 --- a/crawl-ref/source/religion.h +++ b/crawl-ref/source/religion.h @@ -46,7 +46,7 @@ const char *describe_xom_favour(); bool beogh_water_walk(); void beogh_idol_revenge(); -void ely_destroy_weapons(); +bool ely_destroy_weapons(); void trog_burn_books(); inline void xom_acts(int sever) -- cgit v1.2.3-54-g00ecf