diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 9b89a6d96..e2a805a8c 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -380,37 +380,32 @@ void CHeroHandler::initHeroClasses() unsigned int CHeroHandler::level(unsigned int experience) { - int add=0; - while(experience>=expPerLevel[expPerLevel.size()-1]) + int i; + if(experience <= expPerLevel.back()) { - experience/=1.2; - add+=1; + for(i = expPerLevel.size()-1; experience < expPerLevel[i]; i--); + return i + 1; } - for(int i=expPerLevel.size()-1; i>=0; --i) + else { - if(experience>=expPerLevel[i]) - return 1+i+add; + for(i = expPerLevel.size(); experience > reqExp(i); i++); + return i - 1; } - return -1; } unsigned int CHeroHandler::reqExp(unsigned int level) { - level-=1; - if(level0) - { - --level; - exp*=1.2; - } - return exp; + return reqExp(level - 1) + (reqExp(level - 1) - reqExp(level - 2)) * 1.2; //inefficient but follows exactly H3 values } - return -1; } void CHeroHandler::initTerrainCosts()