From b3ba50a0dfcba435c3936f5e826329f0067709c5 Mon Sep 17 00:00:00 2001 From: haranp Date: Wed, 27 Jun 2007 17:35:16 +0000 Subject: Various cleanups and goto elimination. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1667 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/beam.cc | 13 +- crawl-ref/source/describe.cc | 6 +- crawl-ref/source/dungeon.cc | 173 ++++++++-------------- crawl-ref/source/newgame.cc | 9 +- crawl-ref/source/randart.cc | 339 ++++++++++++++++++++++--------------------- crawl-ref/source/spl-book.cc | 4 +- crawl-ref/source/spl-book.h | 4 +- 7 files changed, 254 insertions(+), 294 deletions(-) diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index 692bbd8143..ad8ebf0fd8 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -3718,6 +3718,8 @@ static int affect_monster(bolt &beam, monsters *mon) static int affect_monster_enchantment(bolt &beam, monsters *mon) { + bool death_check = false; + if (beam.flavour == BEAM_TELEPORT) // teleportation { if (check_mons_resist_magic( mon, beam.ench_power ) @@ -3806,7 +3808,7 @@ static int affect_monster_enchantment(bolt &beam, monsters *mon) hurt_monster( mon, roll_dice( beam.damage ) ); - goto deathCheck; + death_check = true; } if (beam.flavour == BEAM_ENSLAVE_UNDEAD @@ -3885,7 +3887,7 @@ static int affect_monster_enchantment(bolt &beam, monsters *mon) hurt_monster( mon, roll_dice( beam.damage ) ); } - goto deathCheck; + death_check = true; } if (beam.flavour == BEAM_DISINTEGRATION) /* disrupt/disintegrate */ @@ -3895,7 +3897,7 @@ static int affect_monster_enchantment(bolt &beam, monsters *mon) hurt_monster( mon, roll_dice( beam.damage ) ); - goto deathCheck; + death_check = true; } @@ -3933,9 +3935,8 @@ static int affect_monster_enchantment(bolt &beam, monsters *mon) } // everything else? - return (mons_ench_f2(mon, beam)); - -deathCheck: + if ( !death_check ) + return (mons_ench_f2(mon, beam)); if (mon->hit_points < 1) monster_die(mon, beam); diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 9fc424c628..1bb2ab3626 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -5040,7 +5040,8 @@ void describe_god( god_type which_god, bool give_title ) if (which_god == GOD_NO_GOD) //mv:no god -> say it and go away { cprintf( EOL "You are not religious." ); - goto end_god_info; + getch(); + return; } colour = god_colour(which_god); @@ -5323,8 +5324,5 @@ void describe_god( god_type which_god, bool give_title ) cprintf( "None." EOL ); } - -end_god_info: //end of everything (life, world, universe etc.) - getch(); // wait until keypressed } //mv: That's all folks. diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index e566927fb7..0e8ca8c4b4 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -703,17 +703,29 @@ static void place_ellipse(int x, int y, int a, int b, grd[i][j] = feat; } -// count how many neighbours of grd[x][y] are the feature feat. -static int count_neighbours(int x, int y, int feat) +static int count_feature_in_box(int x0, int y0, int x1, int y1, + dungeon_feature_type feat) { int result = 0; - for ( int i = -1; i <= 1; ++i ) - for ( int j = -1; j <= 1; ++j ) - if ( grd[x+i][y+j] == feat ) + for ( int i = x0; i < x1; ++i ) + for ( int j = y0; j < y1; ++j ) + if ( grd[i][j] == feat ) ++result; return result; } +static int count_antifeature_in_box(int x0, int y0, int x1, int y1, + dungeon_feature_type feat) +{ + return (x1-x0)*(y1-y0) - count_feature_in_box(x0,y0,x1,y1,feat); +} + +// count how many neighbours of grd[x][y] are the feature feat. +static int count_neighbours(int x, int y, dungeon_feature_type feat) +{ + return count_feature_in_box(x-1, y-1, x+2, y+2, feat); +} + static void replace_in_grid(int x1, int y1, int x2, int y2, dungeon_feature_type oldfeat, dungeon_feature_type newfeat) @@ -3747,45 +3759,28 @@ static void place_pool(dungeon_feature_type pool_type, unsigned char pool_x1, static void many_pools(dungeon_feature_type pool_type) { - int pools = 0; - int i = 0, j = 0, k = 0, l = 0; - int m = 0, n = 0; - int no_pools = 20 + random2avg(9, 2); - int timeout = 0; if (player_in_branch( BRANCH_COCYTUS )) pool_type = DNGN_DEEP_WATER; else if (player_in_branch( BRANCH_GEHENNA )) pool_type = DNGN_LAVA; - do - { - timeout++; - - if (timeout >= 30000) - break; + const int num_pools = 20 + random2avg(9, 2); + int pools = 0; - i = 6 + random2( GXM - 26 ); - j = 6 + random2( GYM - 26 ); - k = i + 2 + roll_dice( 2, 9 ); - l = j + 2 + roll_dice( 2, 9 ); + for ( int timeout = 0; pools < num_pools && timeout < 30000; ++timeout ) + { + const int i = 6 + random2( GXM - 26 ); + const int j = 6 + random2( GYM - 26 ); + const int k = i + 2 + roll_dice( 2, 9 ); + const int l = j + 2 + roll_dice( 2, 9 ); - for (m = i; m < k; m++) + if ( count_antifeature_in_box(i, j, k, l, DNGN_FLOOR) == 0 ) { - for (n = j; n < l; n++) - { - if (grd[m][n] != DNGN_FLOOR) - goto continue_pools; - } + place_pool(pool_type, i, j, k, l); + pools++; } - - place_pool(pool_type, i, j, k, l); - pools++; - - continue_pools: - continue; } - while (pools < no_pools); } // end many_pools() //jmf: generate altar based on where you are, or possibly randomly @@ -3882,56 +3877,37 @@ static dungeon_feature_type pick_an_altar() static void place_altar() { - int px, py; - int i, j; - int k = 0, l = 0; - const dungeon_feature_type altar_type = pick_an_altar(); - - while(true) + for ( int numtry = 0; numtry < 5000; ++numtry ) { - rand_px: + int px = 15 + random2(55); + int py = 15 + random2(45); - px = 15 + random2(55); - py = 15 + random2(45); - k++; + const int numfloors = count_feature_in_box(px-2, py-2, px+3, py+3, + DNGN_FLOOR); + const int numgood = + count_feature_in_box(px-2, py-2, px+3, py+3, DNGN_ROCK_WALL) + + count_feature_in_box(px-2, py-2, px+3, py+3, DNGN_CLOSED_DOOR) + + count_feature_in_box(px-2, py-2, px+3, py+3, DNGN_SECRET_DOOR) + + count_feature_in_box(px-2, py-2, px+3, py+3, DNGN_FLOOR); - if (k == 5000) - return; + if ( numgood < 5*5 || numfloors == 0 ) + continue; - l = 0; + bool mon_there; - for (i = px - 2; i < px + 3; i++) - { - for (j = py - 2; j < py + 3; j++) - { - if (grd[i][j] == DNGN_FLOOR) - l++; - - if ((grd[i][j] != DNGN_ROCK_WALL - && grd[i][j] != DNGN_CLOSED_DOOR - && grd[i][j] != DNGN_SECRET_DOOR - && grd[i][j] != DNGN_FLOOR) - || mgrd[i][j] != NON_MONSTER) - { - goto rand_px; - } - } - } + for (int i = px - 2; i <= px + 2; i++) + for (int j = py - 2; j <= py + 2; j++) + if (mgrd[i][j] != NON_MONSTER) + mon_there = true; - if (l == 0) - goto rand_px; + if ( mon_there ) + continue; - for (i = px - 2; i < px + 3; i++) - { - for (j = py - 2; j < py + 3; j++) - { + for (int i = px - 2; i <= px + 2; i++) + for (int j = py - 2; j <= py + 2; j++) grd[i][j] = DNGN_FLOOR; - } - } - - grd[px][py] = altar_type; - - return; + grd[px][py] = pick_an_altar(); + break; } } // end place_altar() @@ -4397,7 +4373,6 @@ static char plan_3() Of course, this can easily end up looking just like a make_trail level. */ int i; - char cnx, cny; int roomsss = 30 + random2(90); bool exclusive = (one_chance_in(10) ? false : true); @@ -4416,20 +4391,13 @@ static char plan_3() if (exclusive) { - for (cnx = romx1[which_room] - 1; cnx < romx2[which_room] + 1; - cnx++) - { - for (cny = romy1[which_room] - 1; cny < romy2[which_room] + 1; - cny++) - { - if (grd[cnx][cny] != DNGN_ROCK_WALL) - goto continuing; - } - } + int bx = romx1[which_room], by = romy1[which_room]; + if (count_antifeature_in_box(bx-1,by-1,bx+2,by+2,DNGN_ROCK_WALL)) + continue; } replace_area(romx1[which_room], romy1[which_room], romx2[which_room], - romy2[which_room], DNGN_ROCK_WALL, DNGN_FLOOR); + romy2[which_room], DNGN_ROCK_WALL, DNGN_FLOOR); if (which_room > 0 && !exclusive2) { @@ -4455,8 +4423,6 @@ static char plan_3() if (which_room >= 29) break; - continuing: - continue; } if (exclusive2) @@ -4497,7 +4463,6 @@ static char plan_4(char forbid_x1, char forbid_y1, char forbid_x2, int number_boxes = 5000; dungeon_feature_type drawing = DNGN_ROCK_WALL; char b1x, b1y, b2x, b2y; - char cnx, cny; int i; temp_rand = random2(81); @@ -4534,26 +4499,17 @@ static char plan_4(char forbid_x1, char forbid_y1, char forbid_x2, if (forbid_x1 != 0 || forbid_x2 != 0) { if (b1x <= forbid_x2 && b1x >= forbid_x1 - && b1y <= forbid_y2 && b1y >= forbid_y1) - { - goto continuing; - } - else if (b2x <= forbid_x2 && b2x >= forbid_x1 - && b2y <= forbid_y2 && b2y >= forbid_y1) - { - goto continuing; - } - } + && b1y <= forbid_y2 && b1y >= forbid_y1) + continue; - for (cnx = b1x - 1; cnx < b2x + 1; cnx++) - { - for (cny = b1y - 1; cny < b2y + 1; cny++) - { - if (grd[cnx][cny] != DNGN_FLOOR) - goto continuing; - } + if (b2x <= forbid_x2 && b2x >= forbid_x1 + && b2y <= forbid_y2 && b2y >= forbid_y1) + continue; } + if (count_antifeature_in_box(b1x-1, b1y-1, b2x+1, b2y+1, DNGN_FLOOR)) + continue; + if (force_wall == NUM_FEATURES) { // NB: comparison reversal here - combined @@ -4574,9 +4530,6 @@ static char plan_4(char forbid_x1, char forbid_y1, char forbid_x2, replace_area(b1x, b1y, b2x, b2y, DNGN_FLOOR, drawing); else // odds: 72 in 210 {dlb} box_room(b1x, b2x - 1, b1y, b2y - 1, drawing); - - continuing: - continue; } if (forbid_x1 == 0 && one_chance_in(4)) // a market square diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 6bb4b85c49..50ffe912aa 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -133,6 +133,11 @@ static god_type ng_pr; static int ng_weapon; static int ng_book; +static species_type random_draconian_species() +{ + return static_cast(SP_RED_DRACONIAN + random2(9)); +} + static void reset_newgame_options(void) { ng_race = ng_cls = 0; @@ -273,7 +278,7 @@ static void pick_random_species_and_class( void ) // return draconian variety here if (species == SP_RED_DRACONIAN) - you.species = static_cast(SP_RED_DRACONIAN + random2(9)); + you.species = random_draconian_species(); else you.species = species; @@ -2879,7 +2884,7 @@ static species_type letter_to_species(int keyn) if ( offset + SP_HUMAN < SP_RED_DRACONIAN ) rc = offset + SP_HUMAN; else if ( offset + SP_HUMAN == SP_RED_DRACONIAN ) // random draco - rc = SP_RED_DRACONIAN + random2(9); + rc = random_draconian_species(); else // skip over draconian species rc = offset + (SP_BASE_DRACONIAN - SP_RED_DRACONIAN) + 1; return static_cast(rc); diff --git a/crawl-ref/source/randart.cc b/crawl-ref/source/randart.cc index 0682a26c0e..d719501136 100644 --- a/crawl-ref/source/randart.cc +++ b/crawl-ref/source/randart.cc @@ -856,17 +856,16 @@ void randart_wpn_properties( const item_def &item, { ASSERT( is_random_artefact( item ) ); - const int aclass = item.base_type; + const object_class_type aclass = item.base_type; const int atype = item.sub_type; - int i = 0; int power_level = 0; if (is_unrandom_artefact( item )) { struct unrandart_entry *unrand = seekunrandart( item ); - for (i = 0; i < RA_PROPERTIES; i++) + for (int i = 0; i < RA_PROPERTIES; i++) proprt[i] = unrand->prpty[i]; return; @@ -886,8 +885,7 @@ void randart_wpn_properties( const item_def &item, if (power_level < 0) power_level = 0; - for (i = 0; i < RA_PROPERTIES; i++) - proprt[i] = 0; + proprt.init(0); if (aclass == OBJ_WEAPONS) /* Only weapons get brands, of course */ { @@ -943,7 +941,6 @@ void randart_wpn_properties( const item_def &item, } } - if (is_demonic(item)) { switch (random2(9)) @@ -980,112 +977,112 @@ void randart_wpn_properties( const item_def &item, power_level++; } - if (one_chance_in(5)) - goto skip_mods; - - /* AC mod - not for armours or rings of protection */ - if (one_chance_in(4 + power_level) - && aclass != OBJ_ARMOUR - && (aclass != OBJ_JEWELLERY || atype != RING_PROTECTION)) + if (!one_chance_in(5)) { - proprt[RAP_AC] = 1 + random2(3) + random2(3) + random2(3); - power_level++; - if (one_chance_in(4)) + /* AC mod - not for armours or rings of protection */ + if (one_chance_in(4 + power_level) + && aclass != OBJ_ARMOUR + && (aclass != OBJ_JEWELLERY || atype != RING_PROTECTION)) { - proprt[RAP_AC] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_AC] = 1 + random2(3) + random2(3) + random2(3); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_AC] -= 1 + random2(3) + random2(3) + random2(3); + power_level--; + } } - } - /* ev mod - not for rings of evasion */ - if (one_chance_in(4 + power_level) - && (aclass != OBJ_JEWELLERY || atype != RING_EVASION)) - { - proprt[RAP_EVASION] = 1 + random2(3) + random2(3) + random2(3); - power_level++; - if (one_chance_in(4)) + /* ev mod - not for rings of evasion */ + if (one_chance_in(4 + power_level) + && (aclass != OBJ_JEWELLERY || atype != RING_EVASION)) { - proprt[RAP_EVASION] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_EVASION] = 1 + random2(3) + random2(3) + random2(3); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_EVASION] -= 1 + random2(3) + random2(3) + + random2(3); + power_level--; + } } - } - /* str mod - not for rings of strength */ - if (one_chance_in(4 + power_level) - && (aclass != OBJ_JEWELLERY || atype != RING_STRENGTH)) - { - proprt[RAP_STRENGTH] = 1 + random2(3) + random2(2); - power_level++; - if (one_chance_in(4)) + /* str mod - not for rings of strength */ + if (one_chance_in(4 + power_level) + && (aclass != OBJ_JEWELLERY || atype != RING_STRENGTH)) { - proprt[RAP_STRENGTH] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_STRENGTH] = 1 + random2(3) + random2(2); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_STRENGTH] -= 1 + random2(3) + random2(3) + + random2(3); + power_level--; + } } - } - /* int mod - not for rings of intelligence */ - if (one_chance_in(4 + power_level) - && (aclass != OBJ_JEWELLERY || atype != RING_INTELLIGENCE)) - { - proprt[RAP_INTELLIGENCE] = 1 + random2(3) + random2(2); - power_level++; - if (one_chance_in(4)) + /* int mod - not for rings of intelligence */ + if (one_chance_in(4 + power_level) + && (aclass != OBJ_JEWELLERY || atype != RING_INTELLIGENCE)) { - proprt[RAP_INTELLIGENCE] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_INTELLIGENCE] = 1 + random2(3) + random2(2); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_INTELLIGENCE] -= 1 + random2(3) + random2(3) + + random2(3); + power_level--; + } } - } - /* dex mod - not for rings of dexterity */ - if (one_chance_in(4 + power_level) - && (aclass != OBJ_JEWELLERY || atype != RING_DEXTERITY)) - { - proprt[RAP_DEXTERITY] = 1 + random2(3) + random2(2); - power_level++; - if (one_chance_in(4)) + /* dex mod - not for rings of dexterity */ + if (one_chance_in(4 + power_level) + && (aclass != OBJ_JEWELLERY || atype != RING_DEXTERITY)) { - proprt[RAP_DEXTERITY] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_DEXTERITY] = 1 + random2(3) + random2(2); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_DEXTERITY] -= 1 + random2(3) + random2(3) + + random2(3); + power_level--; + } } } - skip_mods: - if (random2(15) < power_level - || aclass == OBJ_WEAPONS - || (aclass == OBJ_JEWELLERY && atype == RING_SLAYING)) + if (random2(15) >= power_level && aclass != OBJ_WEAPONS && + (aclass != OBJ_JEWELLERY || atype != RING_SLAYING)) { - goto skip_combat; - } - - /* Weapons and rings of slaying can't get these */ - if (one_chance_in(4 + power_level)) /* to-hit */ - { - proprt[RAP_ACCURACY] = 1 + random2(3) + random2(2); - power_level++; - if (one_chance_in(4)) + /* Weapons and rings of slaying can't get these */ + if (one_chance_in(4 + power_level)) /* to-hit */ { - proprt[RAP_ACCURACY] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_ACCURACY] = 1 + random2(3) + random2(2); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_ACCURACY] -= 1 + random2(3) + random2(3) + + random2(3); + power_level--; + } } - } - if (one_chance_in(4 + power_level)) /* to-dam */ - { - proprt[RAP_DAMAGE] = 1 + random2(3) + random2(2); - power_level++; - if (one_chance_in(4)) + if (one_chance_in(4 + power_level)) /* to-dam */ { - proprt[RAP_DAMAGE] -= 1 + random2(3) + random2(3) + random2(3); - power_level--; + proprt[RAP_DAMAGE] = 1 + random2(3) + random2(2); + power_level++; + if (one_chance_in(4)) + { + proprt[RAP_DAMAGE] -= 1 + random2(3) + random2(3) + random2(3); + power_level--; + } } } - skip_combat: - if (random2(12) < power_level) - goto finished_powers; - + bool done_powers = (random2(12 < power_level)); + /* res_fire */ - if (one_chance_in(4 + power_level) + if (!done_powers + && one_chance_in(4 + power_level) && (aclass != OBJ_JEWELLERY || (atype != RING_PROTECTION_FROM_FIRE && atype != RING_FIRE @@ -1102,7 +1099,8 @@ void randart_wpn_properties( const item_def &item, } /* res_cold */ - if (one_chance_in(4 + power_level) + if (!done_powers + && one_chance_in(4 + power_level) && (aclass != OBJ_JEWELLERY || (atype != RING_PROTECTION_FROM_COLD && atype != RING_FIRE @@ -1119,18 +1117,20 @@ void randart_wpn_properties( const item_def &item, } if (random2(12) < power_level || power_level > 7) - goto finished_powers; + done_powers = true; /* res_elec */ - if (one_chance_in(4 + power_level) + if (!done_powers + && one_chance_in(4 + power_level) && (aclass != OBJ_ARMOUR || atype != ARM_STORM_DRAGON_ARMOUR)) { proprt[RAP_ELECTRICITY] = 1; power_level++; } -/* res_poison */ - if (one_chance_in(5 + power_level) + /* res_poison */ + if (!done_powers + && one_chance_in(5 + power_level) && (aclass != OBJ_JEWELLERY || atype != RING_POISON_RESISTANCE) && (aclass != OBJ_ARMOUR || atype != ARM_GOLD_DRAGON_ARMOUR @@ -1141,7 +1141,8 @@ void randart_wpn_properties( const item_def &item, } /* prot_life - no necromantic brands on weapons allowed */ - if (one_chance_in(4 + power_level) + if (!done_powers + && one_chance_in(4 + power_level) && (aclass != OBJ_JEWELLERY || atype != RING_TELEPORTATION) && proprt[RAP_BRAND] != SPWPN_DRAINING && proprt[RAP_BRAND] != SPWPN_VAMPIRICISM @@ -1152,7 +1153,8 @@ void randart_wpn_properties( const item_def &item, } /* res magic */ - if (one_chance_in(4 + power_level) + if (!done_powers + && one_chance_in(4 + power_level) && (aclass != OBJ_JEWELLERY || atype != RING_PROTECTION_FROM_MAGIC)) { proprt[RAP_MAGIC] = 35 + random2(65); @@ -1160,7 +1162,8 @@ void randart_wpn_properties( const item_def &item, } /* see_invis */ - if (one_chance_in(4 + power_level) + if (!done_powers + && one_chance_in(4 + power_level) && (aclass != OBJ_JEWELLERY || atype != RING_INVISIBILITY)) { proprt[RAP_EYESIGHT] = 1; @@ -1168,10 +1171,11 @@ void randart_wpn_properties( const item_def &item, } if (random2(12) < power_level || power_level > 10) - goto finished_powers; + done_powers = true; /* turn invis */ - if (one_chance_in(10) + if (!done_powers + && one_chance_in(10) && (aclass != OBJ_JEWELLERY || atype != RING_INVISIBILITY)) { proprt[RAP_INVISIBLE] = 1; @@ -1179,21 +1183,23 @@ void randart_wpn_properties( const item_def &item, } /* levitate */ - if (one_chance_in(10) + if (!done_powers + && one_chance_in(10) && (aclass != OBJ_JEWELLERY || atype != RING_LEVITATION)) { proprt[RAP_LEVITATE] = 1; power_level++; } - if (one_chance_in(10)) /* blink */ + if (!done_powers && one_chance_in(10)) /* blink */ { proprt[RAP_BLINK] = 1; power_level++; } /* teleport */ - if (one_chance_in(10) + if (!done_powers + && one_chance_in(10) && (aclass != OBJ_JEWELLERY || atype != RING_TELEPORTATION)) { proprt[RAP_CAN_TELEPORT] = 1; @@ -1201,98 +1207,95 @@ void randart_wpn_properties( const item_def &item, } /* go berserk */ - if (one_chance_in(10) && (aclass != OBJ_JEWELLERY || atype != AMU_RAGE)) + if (!done_powers + && one_chance_in(10) + && (aclass != OBJ_JEWELLERY || atype != AMU_RAGE)) { proprt[RAP_BERSERK] = 1; power_level++; } - if (one_chance_in(10)) /* sense surr */ + if (!done_powers && one_chance_in(10)) /* sense surr */ { proprt[RAP_MAPPING] = 1; power_level++; } - - finished_powers: /* Armours get less powers, and are also less likely to be cursed that wpns */ if (aclass == OBJ_ARMOUR) power_level -= 4; - if (random2(17) >= power_level || power_level < 2) - goto finished_curses; - - switch (random2(9)) + if (power_level >= 2 && random2(17) < power_level) { - case 0: /* makes noise */ - if (aclass != OBJ_WEAPONS) + switch (random2(9)) + { + case 0: /* makes noise */ + if (aclass != OBJ_WEAPONS) + break; + proprt[RAP_NOISES] = 1 + random2(4); break; - proprt[RAP_NOISES] = 1 + random2(4); - break; - case 1: /* no magic */ - proprt[RAP_PREVENT_SPELLCASTING] = 1; - break; - case 2: /* random teleport */ - if (aclass != OBJ_WEAPONS) + case 1: /* no magic */ + proprt[RAP_PREVENT_SPELLCASTING] = 1; break; - proprt[RAP_CAUSE_TELEPORTATION] = 5 + random2(15); - break; - case 3: /* no teleport - doesn't affect some instantaneous teleports */ - if (aclass == OBJ_JEWELLERY && atype == RING_TELEPORTATION) - break; /* already is a ring of tport */ - if (aclass == OBJ_JEWELLERY && atype == RING_TELEPORT_CONTROL) - break; /* already is a ring of tport ctrl */ - proprt[RAP_BLINK] = 0; - proprt[RAP_CAN_TELEPORT] = 0; - proprt[RAP_PREVENT_TELEPORTATION] = 1; - break; - case 4: /* berserk on attack */ - if (aclass != OBJ_WEAPONS) + case 2: /* random teleport */ + if (aclass != OBJ_WEAPONS) + break; + proprt[RAP_CAUSE_TELEPORTATION] = 5 + random2(15); break; - proprt[RAP_ANGRY] = 1 + random2(8); - break; - case 5: /* susceptible to fire */ - if (aclass == OBJ_JEWELLERY - && (atype == RING_PROTECTION_FROM_FIRE || atype == RING_FIRE - || atype == RING_ICE)) - break; /* already does this or something */ - if (aclass == OBJ_ARMOUR - && (atype == ARM_DRAGON_ARMOUR || atype == ARM_ICE_DRAGON_ARMOUR - || atype == ARM_GOLD_DRAGON_ARMOUR)) + case 3: /* no teleport - doesn't affect some instantaneous + * teleports */ + if (aclass == OBJ_JEWELLERY && atype == RING_TELEPORTATION) + break; /* already is a ring of tport */ + if (aclass == OBJ_JEWELLERY && atype == RING_TELEPORT_CONTROL) + break; /* already is a ring of tport ctrl */ + proprt[RAP_BLINK] = 0; + proprt[RAP_CAN_TELEPORT] = 0; + proprt[RAP_PREVENT_TELEPORTATION] = 1; break; - proprt[RAP_FIRE] = -1; - break; - case 6: /* susceptible to cold */ - if (aclass == OBJ_JEWELLERY - && (atype == RING_PROTECTION_FROM_COLD || atype == RING_FIRE - || atype == RING_ICE)) - break; /* already does this or something */ - if (aclass == OBJ_ARMOUR - && (atype == ARM_DRAGON_ARMOUR || atype == ARM_ICE_DRAGON_ARMOUR - || atype == ARM_GOLD_DRAGON_ARMOUR)) + case 4: /* berserk on attack */ + if (aclass != OBJ_WEAPONS) + break; + proprt[RAP_ANGRY] = 1 + random2(8); break; - proprt[RAP_COLD] = -1; - break; - case 7: /* speed metabolism */ - if (aclass == OBJ_JEWELLERY && atype == RING_HUNGER) - break; /* already is a ring of hunger */ - if (aclass == OBJ_JEWELLERY && atype == RING_SUSTENANCE) - break; /* already is a ring of sustenance */ - proprt[RAP_METABOLISM] = 1 + random2(3); - break; - case 8: /* emits mutagenic radiation - increases magic_contamination */ - /* property is chance (1 in ...) of increasing magic_contamination */ - proprt[RAP_MUTAGENIC] = 2 + random2(4); - break; + case 5: /* susceptible to fire */ + if (aclass == OBJ_JEWELLERY + && (atype == RING_PROTECTION_FROM_FIRE || atype == RING_FIRE + || atype == RING_ICE)) + break; /* already does this or something */ + if (aclass == OBJ_ARMOUR + && (atype == ARM_DRAGON_ARMOUR || atype == ARM_ICE_DRAGON_ARMOUR + || atype == ARM_GOLD_DRAGON_ARMOUR)) + break; + proprt[RAP_FIRE] = -1; + break; + case 6: /* susceptible to cold */ + if (aclass == OBJ_JEWELLERY + && (atype == RING_PROTECTION_FROM_COLD || atype == RING_FIRE + || atype == RING_ICE)) + break; /* already does this or something */ + if (aclass == OBJ_ARMOUR + && (atype == ARM_DRAGON_ARMOUR || atype == ARM_ICE_DRAGON_ARMOUR + || atype == ARM_GOLD_DRAGON_ARMOUR)) + break; + proprt[RAP_COLD] = -1; + break; + case 7: /* speed metabolism */ + if (aclass == OBJ_JEWELLERY && atype == RING_HUNGER) + break; /* already is a ring of hunger */ + if (aclass == OBJ_JEWELLERY && atype == RING_SUSTENANCE) + break; /* already is a ring of sustenance */ + proprt[RAP_METABOLISM] = 1 + random2(3); + break; + case 8: + /* emits mutagenic radiation - increases + magic_contamination. property is chance (1 in ...) of + increasing magic_contamination */ + proprt[RAP_MUTAGENIC] = 2 + random2(4); + break; + } } -/* - 26 - +to-hit (no wpns) - 27 - +to-dam (no wpns) - */ - -finished_curses: if (one_chance_in(10) && (aclass != OBJ_ARMOUR || atype != ARM_CLOAK diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index 81b2b20cda..a4bc67ef4a 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -685,7 +685,7 @@ spell_type which_spell_in_book(int sbook_type, int spl) // If fs is not NULL, updates will be to the formatted_string instead of // the display. -int spellbook_contents( item_def &book, int action, +int spellbook_contents( item_def &book, read_book_action_type action, formatted_string *fs ) { int spelcount = 0; @@ -1010,7 +1010,7 @@ static bool player_can_read_spellbook( const item_def &book ) return (true); } -unsigned char read_book( item_def &book, int action ) +unsigned char read_book( item_def &book, read_book_action_type action ) { unsigned char key2 = 0; diff --git a/crawl-ref/source/spl-book.h b/crawl-ref/source/spl-book.h index a118b0b370..b3b213c461 100644 --- a/crawl-ref/source/spl-book.h +++ b/crawl-ref/source/spl-book.h @@ -32,7 +32,7 @@ bool is_valid_spell_in_book( int splbook, int spell ); /* *********************************************************************** * called from: it_use3 - item_use - spl-book * *********************************************************************** */ -unsigned char read_book( item_def &item, int action ); +unsigned char read_book( item_def &item, read_book_action_type action ); // updated 24may2000 {dlb} @@ -48,7 +48,7 @@ int staff_spell( int zap_device_2 ); bool undead_cannot_memorise(spell_type spell, char being); -int spellbook_contents( item_def &book, int action, +int spellbook_contents( item_def &book, read_book_action_type action, formatted_string *fs = NULL ); int count_staff_spells(const item_def &item, bool need_id); -- cgit v1.2.3-54-g00ecf