From ab9e5b3a883d8b42d96e76b1540c333f59400dd8 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Sat, 30 May 2009 22:51:06 +0000 Subject: Stricter sanity checking of player ghosts. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9855 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/ghost.cc | 70 +++++++++++++++++++++++++++++++++++++++++---- crawl-ref/source/newgame.cc | 15 ++++++---- crawl-ref/source/newgame.h | 2 ++ crawl-ref/source/player.cc | 22 -------------- crawl-ref/source/player.h | 2 -- 5 files changed, 77 insertions(+), 34 deletions(-) diff --git a/crawl-ref/source/ghost.cc b/crawl-ref/source/ghost.cc index 3b68663bd1..31f9f96fca 100644 --- a/crawl-ref/source/ghost.cc +++ b/crawl-ref/source/ghost.cc @@ -16,6 +16,7 @@ REVISION("$Rev$"); #include "externs.h" #include "itemname.h" #include "itemprop.h" +#include "newgame.h" #include "randart.h" #include "skills2.h" #include "stuff.h" @@ -28,6 +29,8 @@ REVISION("$Rev$"); #define MAX_GHOST_DAMAGE 50 #define MAX_GHOST_HP 400 #define MAX_GHOST_EVASION 60 +#define MIN_GHOST_SPEED 6 +#define MAX_GHOST_SPEED 13 std::vector ghosts; @@ -294,6 +297,27 @@ void ghost_demon::init_random_demon() } } +// Returns the movement speed for a player ghost. Note that this is a real +// speed, not a movement cost, so higher is better. +static int _player_ghost_base_movement_speed() +{ + int speed = (you.species == SP_NAGA ? 8 : 10); + + if (player_mutation_level(MUT_FAST)) + speed += player_mutation_level(MUT_FAST) + 1; + + if (player_equip_ego_type(EQ_BOOTS, SPARM_RUNNING)) + speed += 2; + + // Cap speeds. + if (speed < MIN_GHOST_SPEED) + speed = MIN_GHOST_SPEED; + else if (speed > MAX_GHOST_SPEED) + speed = MAX_GHOST_SPEED; + + return (speed); +} + void ghost_demon::init_player_ghost() { name = you.your_name; @@ -308,7 +332,7 @@ void ghost_demon::init_player_ghost() resists.fire = player_res_fire(); resists.cold = player_res_cold(); resists.elec = player_res_electricity(); - speed = player_ghost_base_movement_speed(); + speed = _player_ghost_base_movement_speed(); damage = 4; brand = SPWPN_NORMAL; @@ -600,15 +624,51 @@ 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) + // Values greater than the allowed maximum or less then the allowed + // minimum signalize bugginess. + if (ghost.damage < 0 || ghost.damage > MAX_GHOST_DAMAGE) return (false); - if (ghost.max_hp > MAX_GHOST_HP) + if (ghost.max_hp < 1 || ghost.max_hp > MAX_GHOST_HP) return (false); - if (ghost.xl > 27) + if (ghost.xl < 1 || ghost.xl > 27) return (false); if (ghost.ev > MAX_GHOST_EVASION) return (false); + if (ghost.speed < MIN_GHOST_SPEED || ghost.speed > MAX_GHOST_SPEED) + return (false); + if (ghost.resists.fire < -3 || ghost.resists.fire > 3) + return (false); + if (ghost.resists.cold < -3 || ghost.resists.cold > 3) + return (false); + if (ghost.resists.elec < 0) + return (false); + if (ghost.brand < SPWPN_NORMAL || ghost.brand > MAX_PAN_LORD_BRANDS) + return (false); + if (ghost.species < SP_HUMAN || ghost.species >= NUM_SPECIES) + return (false); + if (ghost.job < JOB_FIGHTER || ghost.job >= NUM_JOBS) + return (false); + if (ghost.best_skill < SK_FIGHTING || ghost.best_skill >= NUM_SKILLS) + return (false); + if (ghost.best_skill_level < 0 || ghost.best_skill_level > 27) + return (false); + if (ghost.religion < GOD_NO_GOD || ghost.religion >= NUM_GODS) + return (false); + + if (ghost.brand == SPWPN_HOLY_WRATH || is_good_god(ghost.religion)) + return (false); + + // Only Pandemonium lords cycle colours. + if (ghost.cycle_colours) + return (false); + + // Name validation. + if (!validate_player_name(ghost.name.c_str(), false)) + return (false); + if (ghost.name.length() > (kNameLen - 1) || ghost.name.length() == 0) + return (false); + if (ghost.name != trimmed_string(ghost.name)) + return (false); // Check for non-existing spells. for (int sp = 0; sp < NUM_MONSTER_SPELL_SLOTS; ++sp) diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index 343ce30af1..7cc59df69c 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -3293,13 +3293,18 @@ static void _enter_player_name(bool blankOK) } // end enter_player_name() static bool _validate_player_name(bool verbose) +{ + return validate_player_name(you.your_name, verbose); +} + +bool validate_player_name(const char* name, bool verbose) { #if defined(DOS) || defined(WIN32CONSOLE) || defined(WIN32TILES) // Quick check for CON -- blows up real good under DOS/Windows. - if (stricmp(you.your_name, "con") == 0 - || stricmp(you.your_name, "nul") == 0 - || stricmp(you.your_name, "prn") == 0 - || strnicmp(you.your_name, "LPT", 3) == 0) + if (stricmp(name, "con") == 0 + || stricmp(name, "nul") == 0 + || stricmp(name, "prn") == 0 + || strnicmp(name, "LPT", 3) == 0) { if (verbose) cprintf(EOL "Sorry, that name gives your OS a headache." EOL); @@ -3307,7 +3312,7 @@ static bool _validate_player_name(bool verbose) } #endif - for (const char *pn = you.your_name; *pn; ++pn) + for (const char *pn = name; *pn; ++pn) { char c = *pn; // Note that this includes systems which may be using the diff --git a/crawl-ref/source/newgame.h b/crawl-ref/source/newgame.h index 129f199116..1516f075ef 100644 --- a/crawl-ref/source/newgame.h +++ b/crawl-ref/source/newgame.h @@ -48,4 +48,6 @@ bool choose_class(void); * *********************************************************************** */ void give_basic_mutations(species_type speci); +bool validate_player_name(const char *name, bool verbose); + #endif diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index f0c4d437c7..d986ff62be 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -1876,28 +1876,6 @@ int player_prot_life(bool calc_unid, bool temp, bool items) return (pl); } -// Returns the movement speed for a player ghost. Note that this is a real -// speed, not a movement cost, so higher is better. -int player_ghost_base_movement_speed() -{ - int speed = (you.species == SP_NAGA ? 8 : 10); - - if (player_mutation_level(MUT_FAST)) - speed += player_mutation_level(MUT_FAST) + 1; - - if (player_equip_ego_type(EQ_BOOTS, SPARM_RUNNING)) - speed += 2; - - // Cap speeds. - if (speed < 6) - speed = 6; - - if (speed > 13) - speed = 13; - - return (speed); -} - // New player movement speed system... allows for a bit more that // "player runs fast" and "player walks slow" in that the speed is // actually calculated (allowing for centaurs to get a bonus from diff --git a/crawl-ref/source/player.h b/crawl-ref/source/player.h index 386834a8c1..e9d8e3b2ea 100644 --- a/crawl-ref/source/player.h +++ b/crawl-ref/source/player.h @@ -414,8 +414,6 @@ bool is_grid_dangerous(int grid); void run_macro(const char *macroname = NULL); -int player_ghost_base_movement_speed(); - int count_worn_ego(int which_ego); int stat_modifier(stat_type stat); -- cgit v1.2.3-54-g00ecf