From 866d1c6e2a0676afc583377b20228e8939f8374f Mon Sep 17 00:00:00 2001 From: Frank Zago Date: Sat, 27 Aug 2011 02:15:58 +0000 Subject: [PATCH] Rewrote CCreature::estimateCreatureCount to fix a compile warning. --- lib/CCreatureHandler.cpp | 29 ++++++----------------------- lib/CCreatureHandler.h | 2 +- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 430a3ba39..dbf10565f 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -77,31 +77,14 @@ int CCreature::getQuantityID(const int & quantity) return 8; } -int CCreature::estimateCreatureCount(int countID) +int CCreature::estimateCreatureCount(unsigned int countID) { - switch(countID) - { - case 0: - return 3; - case 1: - return 8; - case 2: - return 15; - case 3: - return 35; - case 4: - return 75; - case 5: - return 175; - case 6: - return 375; - case 7: - return 750; - case 8: - return 2500; - default: + static const int creature_count[] = { 3, 8, 15, 35, 75, 175, 375, 750, 2500 }; + + if (countID > 8) assert("Wrong countID!"); - } + + return creature_count[countID]; } bool CCreature::isDoubleWide() const diff --git a/lib/CCreatureHandler.h b/lib/CCreatureHandler.h index 549d9dfa8..ce246aac1 100644 --- a/lib/CCreatureHandler.h +++ b/lib/CCreatureHandler.h @@ -58,7 +58,7 @@ public: bool isEvil () const; si32 maxAmount(const std::vector &res) const; //how many creatures can be bought static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion - static int estimateCreatureCount(int countID); //reverse version of above function, returns middle of range + static int estimateCreatureCount(unsigned int countID); //reverse version of above function, returns middle of range bool isMyUpgrade(const CCreature *anotherCre) const; bool valid() const;