From a33ad3c3e6b0bf53a63554e96eb52db78b4a48f0 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Tue, 26 May 2009 13:47:37 +0000 Subject: Run some sanity checks when loading ghosts. If anything seems fishy * don't load the ghost(s) * print an error message mentioning the bones file * don't delete the bones file, so players can attach it to a bug report The last point means that the player (or admin, in the case of the servers) has to delete a buggy bones file themselves, but the benefits of making tracking down bugs easier should outweigh that inconvenience. Add a new wizmode command that calls debug_stethoscope even if the game is not compiled in debugging mode. Also, Stone Soup 0.5 bones files are now officially incompatible with 0.4. (The changes to the spell ids cause ghosts casting spells to crash the game.) git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9832 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/ghost.cc | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'crawl-ref/source/ghost.cc') diff --git a/crawl-ref/source/ghost.cc b/crawl-ref/source/ghost.cc index 38a3546d49..3b68663bd1 100644 --- a/crawl-ref/source/ghost.cc +++ b/crawl-ref/source/ghost.cc @@ -25,6 +25,10 @@ REVISION("$Rev$"); #include "religion.h" #include +#define MAX_GHOST_DAMAGE 50 +#define MAX_GHOST_HP 400 +#define MAX_GHOST_EVASION 60 + std::vector ghosts; // Order for looking for conjurations for the 1st & 2nd spell slots, @@ -293,12 +297,12 @@ void ghost_demon::init_random_demon() void ghost_demon::init_player_ghost() { name = you.your_name; - max_hp = ((you.hp_max >= 400) ? 400 : you.hp_max); + max_hp = ((you.hp_max >= MAX_GHOST_HP) ? MAX_GHOST_HP : you.hp_max); ev = player_evasion(); ac = player_AC(); - if (ev > 60) - ev = 60; + if (ev > MAX_GHOST_EVASION) + ev = MAX_GHOST_EVASION; see_invis = player_see_invis(); resists.fire = player_res_fire(); @@ -344,8 +348,8 @@ void ghost_demon::init_player_ghost() damage += you.strength / 4; - if (damage > 50) - damage = 50; + if (damage > MAX_GHOST_DAMAGE) + damage = MAX_GHOST_DAMAGE; species = you.species; job = you.char_class; @@ -526,7 +530,7 @@ void ghost_demon::find_transiting_ghosts( void ghost_demon::announce_ghost(const ghost_demon &g) { -#ifdef DEBUG_DIAGNOSTICS +#if DEBUG_BONES | DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Saving ghost: %s", g.name.c_str()); #endif } @@ -589,3 +593,27 @@ int ghost_demon::n_extra_ghosts() return (1 + x_chance_in_y(lev, 20) + x_chance_in_y(lev, 40)); } + +// Sanity checks for some ghost values. +bool debug_check_ghosts() +{ + for (unsigned int k = 0; k < ghosts.size(); ++k) + { + ghost_demon ghost = ghosts[k]; + // Values greater than the allowed maximum signalize bugginess. + if (ghost.damage > MAX_GHOST_DAMAGE) + return (false); + if (ghost.max_hp > MAX_GHOST_HP) + return (false); + if (ghost.xl > 27) + return (false); + if (ghost.ev > MAX_GHOST_EVASION) + return (false); + + // Check for non-existing spells. + for (int sp = 0; sp < NUM_MONSTER_SPELL_SLOTS; ++sp) + if (ghost.spells[sp] < 0 || ghost.spells[sp] >= NUM_SPELLS) + return (false); + } + return (true); +} -- cgit v1.2.3-54-g00ecf