mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 00:15:30 +00:00
WAGE: Implement RandomHat
This commit is contained in:
parent
3906c36898
commit
4665f23c4a
@ -107,7 +107,7 @@ void WageEngine::performCombatAction(Chr *npc, Chr *player) {
|
||||
if (npc->_context._frozen)
|
||||
return;
|
||||
|
||||
RandomHat hat;
|
||||
RandomHat hat(_rnd);
|
||||
|
||||
bool winning = (npc->_context._statVariables[PHYS_HIT_CUR] > player->_context._statVariables[PHYS_HIT_CUR]);
|
||||
int validMoves = getValidMoveDirections(npc);
|
||||
@ -166,6 +166,8 @@ void WageEngine::performCombatAction(Chr *npc, Chr *player) {
|
||||
case kTokOffer:
|
||||
performOffer(npc, player);
|
||||
break;
|
||||
case kTokNone:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
int cnt = 0;
|
||||
|
@ -45,6 +45,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/random.h"
|
||||
|
||||
#include "common/hashmap.h"
|
||||
#include "wage/randomhat.h"
|
||||
|
||||
@ -54,8 +56,28 @@ void RandomHat::addTokens(int type, int count) {
|
||||
_tokens.setVal(type, _tokens.getVal(type, 0) + count);
|
||||
}
|
||||
|
||||
int RandomHat::countTokens() {
|
||||
int count = 0;
|
||||
for (Common::HashMap<int, int>::const_iterator it = _tokens.begin(); it != _tokens.end(); ++it)
|
||||
count += it->_value;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int RandomHat::drawToken() {
|
||||
return 0;
|
||||
int total = countTokens();
|
||||
if (total > 0) {
|
||||
int random = _rnd->getRandomNumber(total - 1);
|
||||
int count = 0;
|
||||
for (Common::HashMap<int, int>::iterator it = _tokens.begin(); it != _tokens.end(); ++it) {
|
||||
if (random >= count && random < count + it->_value) {
|
||||
it->_value--;
|
||||
return it->_key;
|
||||
}
|
||||
count += it->_value;
|
||||
}
|
||||
}
|
||||
return kTokNone;
|
||||
}
|
||||
|
||||
} // End of namespace Wage
|
||||
|
@ -54,18 +54,22 @@ enum {
|
||||
kTokWeapons = -400,
|
||||
kTokMagic = -300,
|
||||
kTokRun = -200,
|
||||
kTokOffer = -100
|
||||
kTokOffer = -100,
|
||||
kTokNone = -100000
|
||||
};
|
||||
|
||||
class RandomHat {
|
||||
public:
|
||||
RandomHat() {}
|
||||
RandomHat(Common::RandomSource *rnd) : _rnd(rnd) {}
|
||||
|
||||
void addTokens(int type, int count);
|
||||
int drawToken();
|
||||
|
||||
private:
|
||||
Common::RandomSource *_rnd;
|
||||
Common::HashMap<int, int> _tokens;
|
||||
|
||||
int countTokens();
|
||||
};
|
||||
|
||||
} // End of namespace Wage
|
||||
|
Loading…
x
Reference in New Issue
Block a user