From 05f88f06a2e406d12ce5acecf52764406e31cb2c Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Thu, 26 Jun 2008 18:56:45 +0000 Subject: Fix a bug in monster summoning that was causing crashes, for example when attempting to cast Shadow Creatures in a bazaar (which is bound to fail, anyway). I guess it would have also caused crashes anywhere else where the level was devoid of monsters and creating one failed - for whatever reason. I don't actually know how likely that combination is. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6151 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/monplace.cc | 25 +++++++++++++------------ crawl-ref/source/monplace.h | 9 +++++---- crawl-ref/source/newgame.cc | 3 +++ crawl-ref/source/spells3.cc | 18 +++++++----------- 4 files changed, 28 insertions(+), 27 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc index 7bbe489f2d..40ab8e00a8 100644 --- a/crawl-ref/source/monplace.cc +++ b/crawl-ref/source/monplace.cc @@ -261,12 +261,14 @@ void spawn_random_monsters() // No monsters in the Labyrinth, or the Ecumenical Temple, or in Bazaars. } -monster_type pick_random_monster(const level_id &place, - int power, +monster_type pick_random_monster(const level_id &place, int power, int &lev_mons) { - if (place.level_type == LEVEL_LABYRINTH) + if (place.level_type == LEVEL_LABYRINTH + || place.level_type == LEVEL_PORTAL_VAULT) + { return (MONS_PROGRAM_BUG); + } monster_type mon_type = MONS_PROGRAM_BUG; @@ -425,11 +427,12 @@ static monster_type _resolve_monster_type(monster_type mon_type, if (mon_type == RANDOM_MONSTER) { level_id place = level_id::current(); - // respect destination level for staircases + + // Respect destination level for staircases. if (proximity == PROX_NEAR_STAIRS) { int tries = 0; - int pval = 0; + int pval = 0; while (++tries <= 320) { pos = random_in_bounds(); @@ -469,7 +472,7 @@ static monster_type _resolve_monster_type(monster_type mon_type, } else { - if ( *stair_type == DCHAR_STAIRS_DOWN ) // deeper level + if (*stair_type == DCHAR_STAIRS_DOWN) // deeper level ++*lev_mons; else if (*stair_type == DCHAR_STAIRS_UP) // higher level { @@ -547,7 +550,7 @@ int place_monster(mgen_data mg, bool force_pos) &stair_type, &mg.power); if (mg.cls == MONS_PROGRAM_BUG) - return (false); + return (-1); // (3) Decide on banding (good lord!) band_size = 1; @@ -1862,8 +1865,6 @@ int mons_place( mgen_data mg ) if (mg.cls == RANDOM_MONSTER || mg.level_type == LEVEL_PANDEMONIUM) mg.flags |= MG_PERMIT_BANDS; - int mid = -1; - // Translate level_type. switch (mg.level_type) { @@ -1879,7 +1880,7 @@ int mons_place( mgen_data mg ) break; } - mid = place_monster(mg); + int mid = place_monster(mg); if (mid == -1) return (-1); @@ -2093,7 +2094,7 @@ bool player_angers_monster(monsters *mon) return (false); } -int create_monster( mgen_data mg ) +int create_monster( mgen_data mg, bool fail_msg ) { int summd = -1; int type = (mons_class_is_zombified(mg.cls) ? mg.base_type @@ -2113,7 +2114,7 @@ int create_monster( mgen_data mg ) // Determine whether creating a monster is successful (summd != -1) {dlb}: // then handle the outcome. {dlb}: - if (summd == -1 && see_grid( mg.pos )) + if (fail_msg && summd == -1 && see_grid( mg.pos )) mpr("You see a puff of smoke."); // The return value is either -1 (failure of some sort) diff --git a/crawl-ref/source/monplace.h b/crawl-ref/source/monplace.h index bbba9f3c3f..ab03196433 100644 --- a/crawl-ref/source/monplace.h +++ b/crawl-ref/source/monplace.h @@ -21,7 +21,7 @@ enum band_type { BAND_NO_BAND = 0, - BAND_KOBOLDS = 1, + BAND_KOBOLDS, BAND_ORCS, BAND_ORC_WARRIOR, BAND_ORC_KNIGHT, @@ -35,6 +35,7 @@ enum band_type BAND_HELL_KNIGHTS, BAND_ORC_HIGH_PRIEST, BAND_GNOLLS, // 14 + // 15 BAND_BUMBLEBEES = 16, BAND_CENTAURS, BAND_YAKTAURS, @@ -63,9 +64,9 @@ enum band_type BAND_GIANT_MOSQUITOES, BAND_BOGGARTS, BAND_BLINK_FROGS, - BAND_SKELETAL_WARRIORS, // 44 + BAND_SKELETAL_WARRIORS, BAND_DRACONIAN, // 45 - BAND_PANDEMONIUM_DEMON, + BAND_PANDEMONIUM_DEMON, // 46 NUM_BANDS // always last }; @@ -234,7 +235,7 @@ struct mgen_data * used for summons and other monsters that want to appear near a given * position like a summon. * *********************************************************************** */ -int create_monster( mgen_data mg ); +int create_monster( mgen_data mg, bool fail_msg = true ); /* *********************************************************************** * Primary function to create monsters. See mgen_data for details on monster diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 11a99c47b4..e941a984c3 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -1917,6 +1917,9 @@ static bool _choose_book( item_def& book, int firstbook, int numbooks ) switch (you.species) { case SP_OGRE: + // Ogres are, of course, really bad at Fire and Ice, so it's usually + // restricted, but if the summoning book comes into play unrestrict + // those two because ogres are even *worse* at Summonings. if (numbooks < 3) book_restrictions[0] = CC_RESTRICTED; // else fall-through diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc index d3b5ae799a..524cf1f790 100644 --- a/crawl-ref/source/spells3.cc +++ b/crawl-ref/source/spells3.cc @@ -563,26 +563,22 @@ bool cast_summon_greater_demon(int pow, god_type god) bool cast_shadow_creatures(god_type god) { - bool success = false; - mpr("Wisps of shadow whirl around you..."); const int monster = create_monster( mgen_data(RANDOM_MONSTER, BEH_FRIENDLY, 2, you.pos(), you.pet_target, - MG_FORCE_BEH, god)); + MG_FORCE_BEH, god), false); - if (monster != -1) + if (monster == -1) { - success = true; - - player_angers_monster(&menv[monster]); + mpr("The shadows disperse without effect."); + return (false); } - else - canned_msg(MSG_NOTHING_HAPPENS); - return (success); + player_angers_monster(&menv[monster]); + return (true); } bool cast_summon_horrible_things(int pow, god_type god) @@ -640,7 +636,7 @@ bool cast_summon_horrible_things(int pow, god_type god) if (count > 0) { - mprf("Some Thing%s answered your call!", + mprf("Some thing%s answered your call!", count > 1 ? "s" : ""); return (true); } -- cgit v1.2.3-54-g00ecf