From af03dc9c1dfd431269fecd7dee8f27a7292ba3f0 Mon Sep 17 00:00:00 2001 From: haranp Date: Fri, 1 Aug 2008 11:02:51 +0000 Subject: Minor cleanups. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6746 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/fight.cc | 4 +- crawl-ref/source/spells2.cc | 126 +++++++++++++++---------------------------- crawl-ref/source/spl-cast.cc | 59 ++++---------------- 3 files changed, 54 insertions(+), 135 deletions(-) diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index b5c480db48..1b1017f371 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -3422,9 +3422,7 @@ std::string melee_attack::mons_weapon_desc() const item_def wpn = *weapon; if (get_weapon_brand(wpn) == SPWPN_REACHING) { - int dx = abs(attacker->pos().x - defender->pos().x); - int dy = abs(attacker->pos().y - defender->pos().y); - if (dx == 2 && dy <= 2 || dy == 2 && dx <= 2) + if ( grid_distance(attacker->pos(), defender->pos()) == 2 ) result += " from afar"; } diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index 8e034b8f7f..569bda24fd 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -237,59 +237,29 @@ int corpse_rot(int power) { UNUSED( power ); - int adx = 0; - int ady = 0; - - int minx = you.pos().x - 6; - int maxx = you.pos().x + 7; - int miny = you.pos().y - 6; - int maxy = you.pos().y + 7; - int xinc = 1; - int yinc = 1; - - if (coinflip()) - { - minx = you.pos().x + 6; - maxx = you.pos().x - 7; - xinc = -1; - } - - if (coinflip()) + for (radius_iterator ri(you.pos(), 6); ri; ++ri) { - miny = you.pos().y + 6; - maxy = you.pos().y - 7; - yinc = -1; - } - - for (adx = minx; adx != maxx; adx += xinc) - for (ady = miny; ady != maxy; ady += yinc) + if (see_grid_no_trans(*ri) && !is_sanctuary(*ri) + && env.cgrid(*ri) == EMPTY_CLOUD) { - coord_def ad(adx, ady); - if (see_grid_no_trans(ad) && !is_sanctuary(ad)) + for ( stack_iterator si(*ri); si; ++si ) { - if (env.cgrid(ad) != EMPTY_CLOUD) - continue; - - for ( stack_iterator si(ad); si; ++si ) + if (si->base_type == OBJ_CORPSES && si->sub_type == CORPSE_BODY) { - if (si->base_type == OBJ_CORPSES - && si->sub_type == CORPSE_BODY) - { - // Found a corpse. Skeletify it if possible. - if (!mons_skeleton(si->plus)) - destroy_item(si->index()); - else - turn_corpse_into_skeleton(*si); - - place_cloud(CLOUD_MIASMA, ad, - 4 + random2avg(16, 3), KC_YOU); - - // Don't look for more corpses here. - break; - } + // Found a corpse. Skeletify it if possible. + if (!mons_skeleton(si->plus)) + destroy_item(si->index()); + else + turn_corpse_into_skeleton(*si); + + place_cloud(CLOUD_MIASMA, *ri, 4+random2avg(16, 3), KC_YOU); + + // Don't look for more corpses here. + break; } } } + } if (player_can_smell()) mpr("You smell decay."); @@ -297,7 +267,7 @@ int corpse_rot(int power) // Should make zombies decay into skeletons? return 0; -} // end corpse_rot() +} bool brand_weapon(brand_type which_brand, int power) { @@ -506,13 +476,11 @@ bool restore_stat(unsigned char which_stat, unsigned char stat_gain, void turn_undead(int pow) { - struct monsters *monster; - mpr("You attempt to repel the undead."); - for (int tu = 0; tu < MAX_MONSTERS; tu++) + for (int i = 0; i < MAX_MONSTERS; i++) { - monster = &menv[tu]; + monsters* const monster = &menv[i]; if (monster->type == -1 || !mons_near(monster)) continue; @@ -674,14 +642,7 @@ void cast_toxic_radiance(void) void cast_refrigeration(int pow) { - struct monsters *monster = 0; // NULL {dlb} - int hurted = 0; - struct bolt beam; - int toxy; - - beam.flavour = BEAM_COLD; - - const dice_def dam_dice( 3, 5 + pow / 10 ); + const dice_def dam_dice( 3, 5 + pow / 10 ); mpr("The heat is drained from your surroundings."); @@ -690,9 +651,8 @@ void cast_refrigeration(int pow) more(); mesclr(); - // Do the player: - hurted = roll_dice( dam_dice ); - hurted = check_your_resists( hurted, beam.flavour ); + // Handle the player. + const int hurted = check_your_resists(roll_dice( dam_dice ), BEAM_COLD); if (hurted > 0) { @@ -706,9 +666,12 @@ void cast_refrigeration(int pow) } // Now do the monsters: - for (toxy = 0; toxy < MAX_MONSTERS; toxy++) + bolt beam; + beam.flavour = BEAM_COLD; + beam.thrower = KILL_YOU; + for (int i = 0; i < MAX_MONSTERS; i++) { - monster = &menv[toxy]; + monsters* const monster = &menv[i]; if (monster->type == -1) continue; @@ -718,35 +681,31 @@ void cast_refrigeration(int pow) mprf("You freeze %s.", monster->name(DESC_NOCAP_THE).c_str()); - hurted = roll_dice( dam_dice ); - hurted = mons_adjust_flavoured( monster, beam, hurted ); + int hurt = mons_adjust_flavoured(monster,beam,roll_dice(dam_dice)); - if (hurted > 0) + if (hurt > 0) { - hurt_monster( monster, hurted ); + hurt_monster( monster, hurt ); if (monster->hit_points < 1) monster_die(monster, KILL_YOU, 0); else - { - const monsters *mons = static_cast(monster); - print_wounds(mons); + { + print_wounds(monster); - //jmf: "slow snakes" finally available - if (mons_class_flag( monster->type, M_COLD_BLOOD ) && coinflip()) + if (mons_class_flag(monster->type, M_COLD_BLOOD) + && coinflip()) + { monster->add_ench(ENCH_SLOW); + } } } } } -} // end cast_refrigeration() +} void drain_life(int pow) { - int hp_gain = 0; - int hurted = 0; - struct monsters *monster = 0; // NULL {dlb} - mpr("You draw life from your surroundings."); // Incoming power to this function is skill in INVOCATIONS, so @@ -759,9 +718,11 @@ void drain_life(int pow) more(); mesclr(); - for (int toxy = 0; toxy < MAX_MONSTERS; toxy++) + int hp_gain = 0; + + for (int i = 0; i < MAX_MONSTERS; i++) { - monster = &menv[toxy]; + monsters* monster = &menv[i]; if (monster->type == -1) continue; @@ -777,12 +738,9 @@ void drain_life(int pow) mprf("You draw life from %s.", monster->name(DESC_NOCAP_THE).c_str()); - hurted = 3 + random2(7) + random2(pow); - + const int hurted = 3 + random2(7) + random2(pow); behaviour_event(monster, ME_WHACK, MHITYOU, you.pos()); - hurt_monster(monster, hurted); - hp_gain += hurted; if (monster->hit_points < 1) diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 8416d55c61..c9e0482dfc 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -400,54 +400,17 @@ int spell_fail(spell_type spell) chance2 = chance; - if (chance < 45) - chance2 = 45; - if (chance < 42) - chance2 = 43; - if (chance < 38) - chance2 = 41; - if (chance < 35) - chance2 = 40; - if (chance < 32) - chance2 = 38; - if (chance < 28) - chance2 = 36; - if (chance < 22) - chance2 = 34; - if (chance < 16) - chance2 = 32; - if (chance < 10) - chance2 = 30; - if (chance < 2) - chance2 = 28; - if (chance < -7) - chance2 = 26; - if (chance < -12) - chance2 = 24; - if (chance < -18) - chance2 = 22; - if (chance < -24) - chance2 = 20; - if (chance < -30) - chance2 = 18; - if (chance < -38) - chance2 = 16; - if (chance < -46) - chance2 = 14; - if (chance < -60) - chance2 = 12; - if (chance < -80) - chance2 = 10; - if (chance < -100) - chance2 = 8; - if (chance < -120) - chance2 = 6; - if (chance < -140) - chance2 = 4; - if (chance < -160) - chance2 = 2; - if (chance < -180) - chance2 = 0; + const int chance_breaks[][2] = { + {45, 45}, {42, 43}, {38, 41}, {35, 40}, {32, 38}, {28, 36}, + {22, 34}, {16, 32}, {10, 30}, {2, 28}, {-7, 26}, {-12, 24}, + {-18, 22}, {-24, 20}, {-30, 18}, {-38, 16}, {-46, 14}, + {-60, 12}, {-80, 10}, {-100, 8}, {-120, 6}, {-140, 4}, + {-160, 2}, {-180, 0} + }; + + for ( unsigned int i = 0; i < ARRAYSZ(chance_breaks); ++i ) + if ( chance < chance_breaks[i][0] ) + chance2 = chance_breaks[i][1]; if (you.duration[DUR_TRANSFORMATION] > 0) { -- cgit v1.2.3-54-g00ecf