summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/food.cc
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-31 21:39:37 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-31 21:39:37 +0000
commit0179b500e318584289c2719994e2e744864cb9cb (patch)
tree33482fc332aa6ac26509da8c3a3c120e7ffacb45 /crawl-ref/source/food.cc
parente1a0e734343b84f169d86ffc4ac85cc78f5c2753 (diff)
downloadcrawl-ref-0179b500e318584289c2719994e2e744864cb9cb.tar.gz
crawl-ref-0179b500e318584289c2719994e2e744864cb9cb.zip
More type safety.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8869 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/food.cc')
-rw-r--r--crawl-ref/source/food.cc66
1 files changed, 35 insertions, 31 deletions
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index e18ebf0403..b25b538ddf 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -14,8 +14,6 @@ REVISION("$Rev$");
#include <sstream>
#include <string.h>
-// required for abs() {dlb}:
-#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
@@ -54,8 +52,10 @@ REVISION("$Rev$");
#include "tutorial.h"
#include "xom.h"
-static int _determine_chunk_effect(int which_chunk_type, bool rotten_chunk);
-static void _eat_chunk(int chunk_effect, bool cannibal, int mon_intel = 0);
+static corpse_effect_type _determine_chunk_effect(corpse_effect_type chunktype,
+ bool rotten_chunk);
+static void _eat_chunk(corpse_effect_type chunk_effect, bool cannibal,
+ int mon_intel = 0);
static void _eating(unsigned char item_class, int item_type);
static void _describe_food_change(int hunger_increment);
static bool _vampire_consume_corpse(int slot, bool invent);
@@ -119,7 +119,7 @@ void set_hunger(int new_hunger_level, bool suppress_msg)
int hunger_difference = (new_hunger_level - you.hunger);
if (hunger_difference < 0)
- make_hungry(abs(hunger_difference), suppress_msg);
+ make_hungry(-hunger_difference, suppress_msg);
else if (hunger_difference > 0)
lessen_hunger(hunger_difference, suppress_msg);
}
@@ -1105,8 +1105,8 @@ void eat_inventory_item(int which_inventory_slot)
const int mons_type = food.plus;
const bool cannibal = is_player_same_species(mons_type);
const int intel = mons_class_intel(mons_type) - I_ANIMAL;
- const int chunk_type = mons_corpse_effect(mons_type);
const bool rotten = food_is_rotten(food);
+ const corpse_effect_type chunk_type = mons_corpse_effect(mons_type);
if (rotten && !_player_can_eat_rotten_meat(true))
return;
@@ -1136,10 +1136,10 @@ void eat_floor_item(int item_link)
}
else if (food.sub_type == FOOD_CHUNK)
{
- const int chunk_type = mons_corpse_effect(food.plus);
const int intel = mons_class_intel(food.plus) - I_ANIMAL;
const bool cannibal = is_player_same_species(food.plus);
const bool rotten = food_is_rotten(food);
+ const corpse_effect_type chunk_type = mons_corpse_effect(food.plus);
if (rotten && !_player_can_eat_rotten_meat(true))
return;
@@ -1722,7 +1722,8 @@ static void _say_chunk_flavour(bool likes_chunks)
// Never called directly - chunk_effect values must pass
// through food::_determine_chunk_effect() first. {dlb}:
-static void _eat_chunk(int chunk_effect, bool cannibal, int mon_intel)
+static void _eat_chunk(corpse_effect_type chunk_effect, bool cannibal,
+ int mon_intel)
{
bool likes_chunks = (you.omnivorous()
|| player_mutation_level(MUT_CARNIVOROUS));
@@ -1787,7 +1788,6 @@ static void _eat_chunk(int chunk_effect, bool cannibal, int mon_intel)
break;
case CE_CLEAN:
- {
if (player_mutation_level(MUT_SAPROVOROUS) == 3)
{
mpr("This raw flesh tastes good.");
@@ -1803,7 +1803,12 @@ static void _eat_chunk(int chunk_effect, bool cannibal, int mon_intel)
do_eat = true;
break;
- }
+
+ case CE_MUTAGEN_GOOD:
+ case CE_NOCORPSE:
+ case CE_RANDOM:
+ mprf(MSGCH_ERROR, "This flesh (%d) tastes buggy!", chunk_effect);
+ break;
}
if (cannibal)
@@ -2644,22 +2649,21 @@ bool can_ingest(int what_isit, int kindof_thing, bool suppress_msg, bool reqid,
// See if you can follow along here -- except for the amulet of the gourmand
// addition (long missing and requested), what follows is an expansion of how
// chunks were handled in the codebase up to this date ... {dlb}
-static int _determine_chunk_effect(int which_chunk_type, bool rotten_chunk)
+static corpse_effect_type _determine_chunk_effect(corpse_effect_type chunktype,
+ bool rotten_chunk)
{
- int this_chunk_effect = which_chunk_type;
-
// Determine the initial effect of eating a particular chunk. {dlb}
- switch (this_chunk_effect)
+ switch (chunktype)
{
case CE_HCL:
case CE_MUTAGEN_RANDOM:
if (you.species == SP_GHOUL)
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
case CE_POISONOUS:
if (player_res_poison() > 0)
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
case CE_CONTAMINATED:
@@ -2667,17 +2671,17 @@ static int _determine_chunk_effect(int which_chunk_type, bool rotten_chunk)
{
case 1:
if (!one_chance_in(15))
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
case 2:
if (!one_chance_in(45))
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
default:
if (!one_chance_in(3))
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
}
break;
@@ -2689,14 +2693,14 @@ static int _determine_chunk_effect(int which_chunk_type, bool rotten_chunk)
// Determine effects of rotting on base chunk effect {dlb}:
if (rotten_chunk)
{
- switch (this_chunk_effect)
+ switch (chunktype)
{
case CE_CLEAN:
case CE_CONTAMINATED:
- this_chunk_effect = CE_ROTTEN;
+ chunktype = CE_ROTTEN;
break;
case CE_MUTAGEN_RANDOM:
- this_chunk_effect = CE_MUTAGEN_BAD;
+ chunktype = CE_MUTAGEN_BAD;
break;
default:
break;
@@ -2704,18 +2708,18 @@ static int _determine_chunk_effect(int which_chunk_type, bool rotten_chunk)
}
// One last chance for some species to safely eat rotten food. {dlb}
- if (this_chunk_effect == CE_ROTTEN)
+ if (chunktype == CE_ROTTEN)
{
switch (player_mutation_level(MUT_SAPROVOROUS))
{
case 1:
if (!one_chance_in(5))
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
case 2:
if (!one_chance_in(15))
- this_chunk_effect = CE_CLEAN;
+ chunktype = CE_CLEAN;
break;
default:
@@ -2733,22 +2737,22 @@ static int _determine_chunk_effect(int which_chunk_type, bool rotten_chunk)
if (player_mutation_level(MUT_SAPROVOROUS) == 3)
{
// [dshaligram] Level 3 saprovores relish contaminated meat.
- if (this_chunk_effect == CE_CLEAN)
- this_chunk_effect = CE_CONTAMINATED;
+ if (chunktype == CE_CLEAN)
+ chunktype = CE_CONTAMINATED;
}
else
{
// [dshaligram] New AotG behaviour - contaminated chunks become
// clean, but rotten chunks remain rotten.
- if (this_chunk_effect == CE_CONTAMINATED)
- this_chunk_effect = CE_CLEAN;
+ if (chunktype == CE_CONTAMINATED)
+ chunktype = CE_CLEAN;
}
}
- return (this_chunk_effect);
+ return (chunktype);
}
-static bool _vampire_consume_corpse(const int slot, bool invent)
+static bool _vampire_consume_corpse(int slot, bool invent)
{
ASSERT(you.species == SP_VAMPIRE);