From 3d8076086374c98bb2e90d342803f173d7cffd87 Mon Sep 17 00:00:00 2001 From: dolorous Date: Sat, 7 Jun 2008 17:50:50 +0000 Subject: Start cleaning up summoning routines in a better way. Sorry for the mess in the meantime. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5545 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/abl-show.cc | 3 +- crawl-ref/source/effects.cc | 3 +- crawl-ref/source/religion.cc | 4 +- crawl-ref/source/spells2.cc | 275 ++++++++++++++++++++++++------------------- crawl-ref/source/spells2.h | 9 +- crawl-ref/source/spells3.cc | 63 +++++----- crawl-ref/source/spells3.h | 2 +- crawl-ref/source/spl-cast.cc | 18 ++- 8 files changed, 211 insertions(+), 166 deletions(-) diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc index 244ad339b8..e6992af2e8 100644 --- a/crawl-ref/source/abl-show.cc +++ b/crawl-ref/source/abl-show.cc @@ -1634,8 +1634,7 @@ static bool _do_ability(const ability_def& abil) case ABIL_TROG_BROTHERS_IN_ARMS: // Trog abilities don't use or train invocations. summon_berserker(you.piety + - random2(you.piety/4) - random2(you.piety/4), - BEH_FRIENDLY, true); + random2(you.piety/4) - random2(you.piety/4)); break; case ABIL_SIF_MUNA_FORGET_SPELL: diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index dce6b0d93b..b4d918c1fe 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -52,7 +52,6 @@ #include "skills2.h" #include "spells2.h" #include "spells3.h" -#include "spells4.h" #include "spl-book.h" #include "spl-cast.h" #include "spl-util.h" @@ -789,7 +788,7 @@ void random_uselessness(int scroll_slot) case 6: mpr("You hear the tinkle of a tiny bell.", MSGCH_SOUND); - your_spells(SPELL_SUMMON_BUTTERFLIES, 100, false); + cast_summon_butterflies(100); break; case 7: diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 65b2dc65a5..be64bf1df9 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -3133,7 +3133,7 @@ static bool _zin_retribution() else { bool success = summon_swarm(you.experience_level * 20, - BEH_HOSTILE, true); + true, true, true); simple_god_message(success ? " sends a plague down upon you!" : "'s plague fails to arrive.", @@ -3421,7 +3421,7 @@ static bool _trog_retribution() points -= cost; - if (summon_berserker(cost * 20, BEH_HOSTILE, true)) + if (summon_berserker(cost * 20, true)) count++; } } diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index 365311d2af..0e4d767e12 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -1660,21 +1660,161 @@ void summon_animals(int pow) } } +bool cast_summon_butterflies(int pow, bool god_gift) +{ + bool success = false; + + const int how_many = std::max(15, 4 + random2(3) + random2(pow) / 10); + + for (int i = 0; i < how_many; ++i) + { + if (create_monster( + mgen_data(MONS_BUTTERFLY, BEH_FRIENDLY, 3, + you.pos(), you.pet_target, + god_gift ? MF_GOD_GIFT : 0)) != -1) + { + success = true; + } + } + + if (!success) + canned_msg(MSG_NOTHING_HAPPENS); + + return (success); +} + +bool cast_summon_scorpions(int pow, bool god_gift) +{ + bool success = false; + + const int how_many = stepdown_value(1 + random2(pow)/10 + random2(pow)/10, + 2, 2, 6, 8); + + for (int i = 0; i < how_many; ++i) + { + bool friendly = (random2(pow) > 3); + + if (create_monster( + mgen_data(MONS_SCORPION, + friendly ? BEH_FRIENDLY : BEH_HOSTILE, + 3, you.pos(), + friendly ? you.pet_target : MHITYOU, + god_gift ? MF_GOD_GIFT : 0)) != -1) + { + success = true; + + mprf("A scorpion appears.%s", + friendly ? "" : " It doesn't look very happy."); + } + } + + if (!success) + canned_msg(MSG_NOTHING_HAPPENS); + + return (success); +} + +bool summon_swarm(int pow, bool god_gift, bool force_hostile, + bool quiet) +{ + bool success = false; + + monster_type mon = MONS_PROGRAM_BUG; + + const int dur = std::min(2 + (random2(pow) / 4), 6); + + const int how_many = stepdown_value(2 + random2(pow)/10 + random2(pow)/25, + 2, 2, 6, 8); + + for (int i = 0; i < how_many; ++i) + { + switch (random2(14)) + { + case 0: + case 1: // prototypical swarming creature {dlb} + mon = MONS_KILLER_BEE; + break; + + case 2: // comment said "larva", code read scorpion {dlb} + mon = MONS_SCORPION; + break; // think: "The Arrival" {dlb} + + case 3: //jmf: technically not insects but still cool + mon = MONS_WORM; + break; // but worms kinda "swarm" so s'ok {dlb} + + case 4: // comment read "larva", code was for scorpion + mon = MONS_GIANT_MOSQUITO; + break; // changed into giant mosquito 12jan2000 {dlb} + + case 5: // think: scarabs in "The Mummy" {dlb} + mon = MONS_GIANT_BEETLE; + break; + + case 6: //jmf: blowfly instead of queen bee + mon = MONS_GIANT_BLOWFLY; + break; + + // queen bee added if more than x bees in swarm? {dlb} + // the above would require code rewrite - worth it? {dlb} + + case 8: //jmf: changed to red wasp; was wolf spider + mon = MONS_WOLF_SPIDER; //jmf: spiders aren't insects + break; // think: "Kingdom of the Spiders" {dlb} + // not just insects!!! - changed back {dlb} + + case 9: + mon = MONS_BUTTERFLY; // comic relief? {dlb} + break; + + case 10: // change into some kind of snake -- {dlb} + mon = MONS_YELLOW_WASP; // do wasps swarm? {dlb} + break; // think: "Indiana Jones" and snakepit? {dlb} + + default: // 3 in 14 chance, 12jan2000 {dlb} + mon = MONS_GIANT_ANT; + break; + } // end switch + + bool friendly = (god_gift) ? !force_hostile + : (random2(pow) > 7); + + if (create_monster( + mgen_data(mon, + friendly ? BEH_FRIENDLY : BEH_HOSTILE, + dur, you.pos(), + friendly ? you.pet_target : MHITYOU, + god_gift ? MF_GOD_GIFT : 0)) != -1) + { + success = true; + + if (!god_gift && !quiet) + { + mprf("A swarming creature appears!%s", + friendly ? "" : " It doesn't look very happy."); + } + } + } + + if (!god_gift && !quiet && !success) + canned_msg(MSG_NOTHING_HAPPENS); + + return (success); +} + bool summon_general_creature_spell(spell_type spell, int pow, bool god_gift) { bool success = false; - bool quiet = (spell == SPELL_SUMMON_BUTTERFLIES - || spell == SPELL_CALL_CANINE_FAMILIAR); + bool quiet = (spell == SPELL_CALL_CANINE_FAMILIAR); monster_type mon = MONS_PROGRAM_BUG; beh_type beha = (spell == SPELL_SUMMON_GREATER_DEMON) ? BEH_CHARMED : BEH_FRIENDLY; - int hostile = (spell == SPELL_SUMMON_SCORPIONS - || spell == SPELL_SUMMON_DEMON + int hostile = (spell == SPELL_SUMMON_DEMON || spell == SPELL_DEMONIC_HORDE || spell == SPELL_CALL_CANINE_FAMILIAR || spell == SPELL_SUMMON_UGLY_THING) ? 3 : @@ -1683,18 +1823,11 @@ bool summon_general_creature_spell(spell_type spell, int pow, || spell == SPELL_SUMMON_DRAGON) ? 5 : -1; - int dur = (spell == SPELL_SUMMON_BUTTERFLIES - || spell == SPELL_SUMMON_SCORPIONS) ? 3 : - (spell == SPELL_SUMMON_GREATER_DEMON + int dur = (spell == SPELL_SUMMON_GREATER_DEMON || spell == SPELL_SUMMON_WRAITHS) ? 5 : -1; - int how_many = (spell == SPELL_SUMMON_BUTTERFLIES) ? - std::max(15, 4 + random2(3) + random2(pow) / 10) : - (spell == SPELL_SUMMON_SCORPIONS) ? - stepdown_value(1 + random2(pow) / 10 + random2(pow) / 10, - 2, 2, 6, 8) : - (spell == SPELL_DEMONIC_HORDE) ? + int how_many = (spell == SPELL_DEMONIC_HORDE) ? 7 + random2(5) : (spell == SPELL_SUMMON_WRAITHS) ? stepdown_value(1 + random2(pow) / 30 + random2(pow) / 30, @@ -1705,14 +1838,6 @@ bool summon_general_creature_spell(spell_type spell, int pow, { switch (spell) { - case SPELL_SUMMON_BUTTERFLIES: - mon = MONS_BUTTERFLY; - break; - - case SPELL_SUMMON_SCORPIONS: - mon = MONS_SCORPION; - break; - case SPELL_CALL_IMP: mon = (one_chance_in(3)) ? MONS_WHITE_IMP : (one_chance_in(7)) ? MONS_SHADOW_IMP @@ -1946,7 +2071,7 @@ bool summon_general_creature(int pow, bool quiet, monster_type mon, } // Trog sends some fighting buddies (or enemies) for his followers. -bool summon_berserker(int pow, beh_type beha, bool god_gift) +bool summon_berserker(int pow, bool force_hostile) { bool success = false; @@ -1954,15 +2079,10 @@ bool summon_berserker(int pow, beh_type beha, bool god_gift) int dur = std::min(2 + (random2(pow) / 4), 6); - unsigned short hitting = (beha == BEH_FRIENDLY) ? you.pet_target : MHITYOU; - if (pow <= 100) { // bears - if (coinflip()) - mon = MONS_BLACK_BEAR; - else - mon = MONS_GRIZZLY_BEAR; + mon = (coinflip()) ? MONS_BLACK_BEAR : MONS_GRIZZLY_BEAR; } else if (pow <= 140) { @@ -1996,17 +2116,16 @@ bool summon_berserker(int pow, beh_type beha, bool god_gift) else { // giants - if (coinflip()) - mon = MONS_HILL_GIANT; - else - mon = MONS_STONE_GIANT; + mon = (coinflip()) ? MONS_HILL_GIANT : MONS_STONE_GIANT; } int monster = create_monster( - mgen_data(mon, beha, dur, - you.pos(), hitting, - god_gift ? MF_GOD_GIFT : 0)); + mgen_data(mon, + !force_hostile ? BEH_FRIENDLY : BEH_HOSTILE, + dur, you.pos(), + !force_hostile ? you.pet_target : MHITYOU, + MF_GOD_GIFT)); if (monster != -1) { @@ -2018,8 +2137,8 @@ bool summon_berserker(int pow, beh_type beha, bool god_gift) mon_enchant berserk = summon->get_ench(ENCH_BERSERK); mon_enchant abj = summon->get_ench(ENCH_ABJ); - // Let Trog gifts berserk longer, and set abj timeout == - // berserk timeout. + // Let Trog's gifts berserk longer, and set the abjuration + // timeout to the berserk timeout. berserk.duration = berserk.duration * 3 / 2; berserk.maxduration = berserk.duration; abj.duration = abj.maxduration = berserk.duration; @@ -2030,88 +2149,6 @@ bool summon_berserker(int pow, beh_type beha, bool god_gift) return (success); } -bool summon_swarm(int pow, beh_type beha, bool god_gift) -{ - bool success = false; - - monster_type mon = MONS_PROGRAM_BUG; - - int dur = std::min(2 + (random2(pow) / 4), 6); - - unsigned short hitting = (beha == BEH_FRIENDLY) ? you.pet_target : MHITYOU; - - int how_many = stepdown_value(2 + random2(pow) / 10 + random2(pow) / 25, - 2, 2, 6, 8); - - for (int scount = 0; scount < how_many; ++scount) - { - switch (random2(14)) - { - case 0: - case 1: // prototypical swarming creature {dlb} - mon = MONS_KILLER_BEE; - break; - - case 2: // comment said "larva", code read scorpion {dlb} - mon = MONS_SCORPION; - break; // think: "The Arrival" {dlb} - - case 3: //jmf: technically not insects but still cool - mon = MONS_WORM; - break; // but worms kinda "swarm" so s'ok {dlb} - - case 4: // comment read "larva", code was for scorpion - mon = MONS_GIANT_MOSQUITO; - break; // changed into giant mosquito 12jan2000 {dlb} - - case 5: // think: scarabs in "The Mummy" {dlb} - mon = MONS_GIANT_BEETLE; - break; - - case 6: //jmf: blowfly instead of queen bee - mon = MONS_GIANT_BLOWFLY; - break; - - // queen bee added if more than x bees in swarm? {dlb} - // the above would require code rewrite - worth it? {dlb} - - case 8: //jmf: changed to red wasp; was wolf spider - mon = MONS_WOLF_SPIDER; //jmf: spiders aren't insects - break; // think: "Kingdom of the Spiders" {dlb} - // not just insects!!! - changed back {dlb} - - case 9: - mon = MONS_BUTTERFLY; // comic relief? {dlb} - break; - - case 10: // change into some kind of snake -- {dlb} - mon = MONS_YELLOW_WASP; // do wasps swarm? {dlb} - break; // think: "Indiana Jones" and snakepit? {dlb} - - default: // 3 in 14 chance, 12jan2000 {dlb} - mon = MONS_GIANT_ANT; - break; - } // end switch - - // If it's not a god gift, it's from a spell. - if (!god_gift && random2(pow) > 7) - { - beha = BEH_FRIENDLY; - hitting = you.pet_target; - } - - if (create_monster( - mgen_data(mon, beha, dur, - you.pos(), hitting, - god_gift ? MF_GOD_GIFT : 0)) != -1) - { - success = true; - } - } - - return (success); -} - void summon_things(int pow) { int big_things = 0; diff --git a/crawl-ref/source/spells2.h b/crawl-ref/source/spells2.h index cd7a368d0d..d06a3b2e3b 100644 --- a/crawl-ref/source/spells2.h +++ b/crawl-ref/source/spells2.h @@ -132,6 +132,10 @@ bool restore_stat(unsigned char which_stat, unsigned char stat_gain, /* *********************************************************************** * called from: ability - spell * *********************************************************************** */ +bool cast_summon_butterflies(int pow, bool god_gift = false); + +bool cast_summon_scorpions(int pow, bool god_gift = false); + bool summon_general_creature_spell(spell_type spell, int pow, bool god_gift = false); @@ -153,13 +157,14 @@ void summon_animals(int pow); * *********************************************************************** */ void summon_small_mammals(int pow); -bool summon_berserker(int pow, beh_type beha, bool god_gift); +bool summon_berserker(int pow, bool force_hostile = false); // last updated 24may2000 {dlb} /* *********************************************************************** * called from: ability - religion - spell * *********************************************************************** */ -bool summon_swarm(int pow, beh_type beha, bool god_gift); +bool summon_swarm(int pow, bool god_gift = false, bool force_hostile = false, + bool quiet = false); // last updated 24may2000 {dlb} diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc index 92d13c2a26..210628e0e1 100644 --- a/crawl-ref/source/spells3.cc +++ b/crawl-ref/source/spells3.cc @@ -472,16 +472,15 @@ void simulacrum(int power) } } -bool dancing_weapon(int pow, bool force_hostile, bool silent) +bool dancing_weapon(int pow, bool force_hostile, bool quiet) { - int numsc = std::min(2 + (random2(pow) / 5), 6); - int summs = 0; + bool success = true; - bool failed = false; - const int wpn = you.equip[EQ_WEAPON]; + int monster; + + const int dur = std::min(2 + (random2(pow) / 5), 6); - beh_type beha = BEH_FRIENDLY; - unsigned short hitting = you.pet_target; + const int wpn = you.equip[EQ_WEAPON]; // See if wielded item is appropriate: if (wpn == -1 @@ -489,36 +488,35 @@ bool dancing_weapon(int pow, bool force_hostile, bool silent) || is_range_weapon(you.inv[wpn]) || is_fixed_artefact( you.inv[wpn])) { - failed = true; + success = false; } // See if we can get an mitm for the dancing weapon: int i = get_item_slot(); if (i == NON_ITEM) - failed = true; + success = false; - if (!failed) + if (success) { - // cursed weapons become hostile - if (item_cursed( you.inv[wpn] ) || force_hostile) - { - beha = BEH_HOSTILE; - hitting = MHITYOU; - } + // Cursed weapons become hostile. + bool friendly = (!force_hostile && !item_cursed(you.inv[wpn])); - summs = + monster = create_monster( - mgen_data(MONS_DANCING_WEAPON, beha, numsc, - you.pos(), hitting)); - if (summs == -1) - failed = true; + mgen_data(MONS_DANCING_WEAPON, + friendly ? BEH_FRIENDLY : BEH_HOSTILE, + dur, you.pos(), + friendly ? you.pet_target : MHITYOU)); + + if (monster == -1) + success = false; } - if (failed) + if (!success) { destroy_item(i); - if (!silent) + if (!quiet) { if (wpn != -1) mpr("Your weapon vibrates crazily for a second."); @@ -527,32 +525,33 @@ bool dancing_weapon(int pow, bool force_hostile, bool silent) << std::endl; } - return false; + return (false); } - // We are successful: - unwield_item(); // unwield the weapon (including removing wield effects) + // We are successful. Unwield the weapon, removing any wield effects. + unwield_item(); - // copy item (done here after any wield effects are removed) + // Copy the unwielded item. mitm[i] = you.inv[wpn]; mitm[i].quantity = 1; mitm[i].x = 0; mitm[i].y = 0; mitm[i].link = NON_ITEM; - // Mark the weapon as thrown so we'll autograb it when the tango's done. + // Mark the weapon as thrown, so that we'll autograb it when the + // tango's done. mitm[i].flags |= ISFLAG_THROWN; mprf("%s dances into the air!", you.inv[wpn].name(DESC_CAP_YOUR).c_str()); you.inv[wpn].quantity = 0; - menv[summs].inv[MSLOT_WEAPON] = i; - menv[summs].colour = mitm[i].colour; + menv[monster].inv[MSLOT_WEAPON] = i; + menv[monster].colour = mitm[i].colour; burden_change(); - return true; -} // end dancing_weapon() + return (true); +} // // This function returns true if the player can use controlled diff --git a/crawl-ref/source/spells3.h b/crawl-ref/source/spells3.h index d758b40308..5d55317366 100644 --- a/crawl-ref/source/spells3.h +++ b/crawl-ref/source/spells3.h @@ -82,7 +82,7 @@ bool project_noise(void); /* *********************************************************************** * called from: religion - spell * *********************************************************************** */ -bool dancing_weapon(int pow, bool force_hostile, bool silent = false); +bool dancing_weapon(int pow, bool force_hostile = false, bool quiet = false); // updated 24may2000 {dlb} diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 155e585109..a561062fbc 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -1388,10 +1388,6 @@ spret_type your_spells(spell_type spell, int powc, bool allow_fail) return (SPRET_ABORT); break; - case SPELL_SUMMON_SWARM: - summon_swarm(powc, BEH_FRIENDLY, false); - break; - case SPELL_SUMMON_HORRIBLE_THINGS: summon_things(powc); break; @@ -1479,9 +1475,19 @@ spret_type your_spells(spell_type spell, int powc, bool allow_fail) return (SPRET_ABORT); break; - // Remember that most holy spells don't yet use powc! case SPELL_SUMMON_BUTTERFLIES: + cast_summon_butterflies(powc); + break; + case SPELL_SUMMON_SCORPIONS: + cast_summon_scorpions(powc); + break; + + case SPELL_SUMMON_SWARM: + summon_swarm(powc); + break; + + // Remember that most holy spells don't yet use powc! case SPELL_CALL_IMP: case SPELL_SUMMON_DEMON: case SPELL_DEMONIC_HORDE: @@ -1562,7 +1568,7 @@ spret_type your_spells(spell_type spell, int powc, bool allow_fail) case SPELL_TUKIMAS_DANCE: crawl_state.cant_cmd_repeat("You can't repeat dancing weapon."); - dancing_weapon(powc, false); + dancing_weapon(powc); break; case SPELL_HELLFIRE: -- cgit v1.2.3-54-g00ecf