diff options
-rw-r--r-- | engines/kyra/lol.cpp | 45 | ||||
-rw-r--r-- | engines/kyra/lol.h | 4 | ||||
-rw-r--r-- | engines/kyra/scene_lol.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/script_lol.cpp | 16 | ||||
-rw-r--r-- | engines/kyra/sprites_lol.cpp | 8 | ||||
-rw-r--r-- | engines/kyra/timer_lol.cpp | 4 |
6 files changed, 38 insertions, 43 deletions
diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp index 8f00708e43..33ba2bff7e 100644 --- a/engines/kyra/lol.cpp +++ b/engines/kyra/lol.cpp @@ -1080,7 +1080,7 @@ bool LoLEngine::addCharacter(int id) { loadCharFaceShapes(numChars, id); - _characters[numChars].nextAnimUpdateCountdown = (int16) generateRandomNumber(1, 12) + 6; + _characters[numChars].nextAnimUpdateCountdown = (int16) rollDice(1, 12) + 6; for (i = 0; i < 11; i++) { if (_characters[numChars].items[i]) { @@ -1174,7 +1174,7 @@ void LoLEngine::updatePortraitSpeechAnim() { } } - int f = generateRandomNumber(1, 6) - 1; + int f = rollDice(1, 6) - 1; if (f == _characters[_updateCharNum].curFaceFrame) f++; if (f > 5) @@ -1402,24 +1402,24 @@ void LoLEngine::increaseExperience(int charNum, int skill, uint32 points) { switch (skill) { case 0: _txt->printMessage(0x8003, getLangString(0x4023), _characters[charNum].name); - inc = generateRandomNumber(4, 6); + inc = rollDice(4, 6); _characters[charNum].hitPointsCur += inc; _characters[charNum].hitPointsMax += inc; break; case 1: _txt->printMessage(0x8003, getLangString(0x4025), _characters[charNum].name); - inc = generateRandomNumber(2, 6); + inc = rollDice(2, 6); _characters[charNum].hitPointsCur += inc; _characters[charNum].hitPointsMax += inc; break; case 2: _txt->printMessage(0x8003, getLangString(0x4024), _characters[charNum].name); - inc = (_characters[charNum].defaultModifiers[6] * (generateRandomNumber(1, 8) + 17)) >> 8; + inc = (_characters[charNum].defaultModifiers[6] * (rollDice(1, 8) + 17)) >> 8; _characters[charNum].magicPointsCur += inc; _characters[charNum].magicPointsMax += inc; - inc = generateRandomNumber(1, 6); + inc = rollDice(1, 6); _characters[charNum].hitPointsCur += inc; _characters[charNum].hitPointsMax += inc; break; @@ -1872,25 +1872,20 @@ void LoLEngine::delay(uint32 millis, bool doUpdate, bool) { } } -int LoLEngine::generateRandomNumber(int min, int max) { - // The output produced by this random number generator - // differs a lot from _rnd.getRandomNumberRng(). Using - // _rnd.getRandomNumberRng() instead of this function - // here will break the fighting system! - - if (min <= 0 || max <= 0) +int LoLEngine::rollDice(int times, int pips) { + if (times <= 0 || pips <= 0) return 0; int res = 0; int d = 0; do { - int val = (((int)_rnd.getRandomNumber(0x7fff) * max) / 0x8000) + 1; - if (val > max) - val -= max; + int val = (((int)_rnd.getRandomNumber(0x7fff) * pips) / 0x8000) + 1; + if (val > pips) + val -= pips; res += val; d++; - } while (d < min); + } while (d < times); return res; } @@ -2281,7 +2276,7 @@ int LoLEngine::processMagicIce(int charNum, int spellLevel) { } else { uint16 o = _levelBlockProperties[calcNewBlockPosition(_currentBlock, _currentDirection)].assignedObjects; while (o & 0x8000) { - int might = generateRandomNumber(iceDamageMin[spellLevel], iceDamageMax[spellLevel]) + iceDamageAdd[spellLevel]; + int might = rollDice(iceDamageMin[spellLevel], iceDamageMax[spellLevel]) + iceDamageAdd[spellLevel]; int dmg = calcInflictableDamagePerItem(charNum, 0, might, 3, 2); MonsterInPlay *m = &_monsters[o & 0x7fff]; @@ -3213,7 +3208,7 @@ int LoLEngine::battleHitSkillTest(int16 attacker, int16 target, int skill) { evadeChanceModifier = _characters[target].defaultModifiers[3]; } - int r = generateRandomNumber(1, 100); + int r = rollDice(1, 100); if (r >= sk) return 2; @@ -3251,9 +3246,9 @@ int LoLEngine::inflictDamage(uint16 target, int damage, uint16 attacker, int ski m->hitPoints -= damage; m->damageReceived = 0x8000 | damage; m->flags |= 0x10; - m->hitOffsX = generateRandomNumber(1, 24); + m->hitOffsX = rollDice(1, 24); m->hitOffsX -= 12; - m->hitOffsY = generateRandomNumber(1, 24); + m->hitOffsY = rollDice(1, 24); m->hitOffsY -= 12; m->hitPoints = CLIP<int16>(m->hitPoints, 0, m->properties->hitPoints); @@ -3457,7 +3452,7 @@ void LoLEngine::checkForPartyDeath() { } void LoLEngine::applyMonsterAttackSkill(MonsterInPlay *monster, int16 target, int16 damage) { - if (generateRandomNumber(1, 100) > monster->properties->attackSkillChance) + if (rollDice(1, 100) > monster->properties->attackSkillChance) return; int t = 0; @@ -3527,7 +3522,7 @@ void LoLEngine::applyMonsterAttackSkill(MonsterInPlay *monster, int16 target, in } void LoLEngine::applyMonsterDefenseSkill(MonsterInPlay *monster, int16 attacker, int flags, int skill, int damage) { - if (generateRandomNumber(1, 100) > monster->properties->defenseSkillChance) + if (rollDice(1, 100) > monster->properties->defenseSkillChance) return; int itm = 0; @@ -3614,7 +3609,7 @@ int LoLEngine::paralyzePoisonCharacter(int charNum, int typeFlag, int immunityFl if (!(_characters[charNum].flags & 1) || (_characters[charNum].flags & immunityFlags)) return 0; - if ((int)generateRandomNumber(1, 100) > hitChance) + if ((int)rollDice(1, 100) > hitChance) return 0; int r = 0; @@ -3732,7 +3727,7 @@ void LoLEngine::launchMagicViper() { _screen->copyPage(12, 0); _screen->copyPage(12, 2); - int t = generateRandomNumber(1, 4); + int t = rollDice(1, 4); for (int i = 0; i < 4; i++) { if (!(_characters[i].flags & 1)) { diff --git a/engines/kyra/lol.h b/engines/kyra/lol.h index 8fafa450b3..f4ac597b5c 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -642,7 +642,7 @@ private: int olol_setWallType(EMCState *script); int olol_getWallType(EMCState *script); int olol_drawScene(EMCState *script); - int olol_getRand(EMCState *script); + int olol_rollDice(EMCState *script); int olol_moveParty(EMCState *script); int olol_delay(EMCState *script); int olol_setGameFlag(EMCState *script); @@ -1314,7 +1314,7 @@ private: // misc void delay(uint32 millis, bool doUpdate = false, bool isMainLoop = false); - int generateRandomNumber(int min, int max); + int rollDice(int times, int pips); uint8 _compassBroken; uint8 _drainMagic; diff --git a/engines/kyra/scene_lol.cpp b/engines/kyra/scene_lol.cpp index 403b4cc69c..32ee7a4d77 100644 --- a/engines/kyra/scene_lol.cpp +++ b/engines/kyra/scene_lol.cpp @@ -552,14 +552,14 @@ void LoLEngine::updateLampStatus() { if (_lampEffect == -1) { if (_screen->_fadeFlag == 0) setPaletteBrightness(_screen->getPalette(0), _brightness, newLampEffect); - _lampStatusTimer = _system->getMillis() + (10 + generateRandomNumber(1, 30)) * _tickLength; + _lampStatusTimer = _system->getMillis() + (10 + rollDice(1, 30)) * _tickLength; } else { if ((_lampEffect & 0xfe) == (newLampEffect & 0xfe)) { if (_system->getMillis() <= _lampStatusTimer) { newLampEffect = _lampEffect; } else { newLampEffect = _lampEffect ^ 1; - _lampStatusTimer = _system->getMillis() + (10 + generateRandomNumber(1, 30)) * _tickLength; + _lampStatusTimer = _system->getMillis() + (10 + rollDice(1, 30)) * _tickLength; } } else { if (_screen->_fadeFlag == 0) diff --git a/engines/kyra/script_lol.cpp b/engines/kyra/script_lol.cpp index 18b8d81ef9..611ad8f9ef 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -135,9 +135,9 @@ int LoLEngine::olol_drawScene(EMCState *script) { return 1; } -int LoLEngine::olol_getRand(EMCState *script) { - debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_getRand(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); - return generateRandomNumber(stackPos(0), stackPos(1)); +int LoLEngine::olol_rollDice(EMCState *script) { + debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_rollDice(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); + return rollDice(stackPos(0), stackPos(1)); } int LoLEngine::olol_moveParty(EMCState *script) { @@ -836,10 +836,10 @@ int LoLEngine::olol_initMonster(EMCState *script) { l->hitPoints = (l->properties->hitPoints * _monsterModifiers[_monsterDifficulty]) >> 8; if (_currentLevel == 12 && l->type == 2) - l->hitPoints = (l->hitPoints * (generateRandomNumber(1, 128) + 192)) >> 8; + l->hitPoints = (l->hitPoints * (rollDice(1, 128) + 192)) >> 8; l->numDistAttacks = l->properties->numDistAttacks; - l->distAttackTick = generateRandomNumber(1, calcMonsterSkillLevel(l->id | 0x8000, 8)) - 1; + l->distAttackTick = rollDice(1, calcMonsterSkillLevel(l->id | 0x8000, 8)) - 1; l->flyingHeight = 2; l->flags = stackPos(5); l->assignedItems = 0; @@ -1382,7 +1382,7 @@ int LoLEngine::olol_characterSkillTest(EMCState *script){ } } - return (generateRandomNumber(1, 100) > m) ? -1 : c; + return (rollDice(1, 100) > m) ? -1 : c; } int LoLEngine::olol_countAllMonsters(EMCState *script){ @@ -1445,7 +1445,7 @@ int LoLEngine::olol_calcInflictableDamage(EMCState *script) { int LoLEngine::olol_getInflictedDamage(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_getInflictedDamage(%p) (%d)", (const void *)script, stackPos(0)); int mx = stackPos(0); - return generateRandomNumber(2, mx); + return rollDice(2, mx); } int LoLEngine::olol_checkForCertainPartyMember(EMCState *script) { @@ -2622,7 +2622,7 @@ void LoLEngine::setupOpcodeTable() { Opcode(olol_setWallType); Opcode(olol_getWallType); Opcode(olol_drawScene); - Opcode(olol_getRand); + Opcode(olol_rollDice); // 0x04 Opcode(olol_moveParty); diff --git a/engines/kyra/sprites_lol.cpp b/engines/kyra/sprites_lol.cpp index b1edecb318..f644feeb65 100644 --- a/engines/kyra/sprites_lol.cpp +++ b/engines/kyra/sprites_lol.cpp @@ -1071,7 +1071,7 @@ void LoLEngine::updateMonster(MonsterInPlay *monster) { monster->speedTick = 0; if (monster->properties->flags & 0x40) { - monster->hitPoints += generateRandomNumber(1, 8); + monster->hitPoints += rollDice(1, 8); if (monster->hitPoints > monster->properties->hitPoints) monster->hitPoints = monster->properties->hitPoints; } @@ -1264,7 +1264,7 @@ bool LoLEngine::chasePartyWithDistanceAttacks(MonsterInPlay *monster) { int s = 0; if (monster->flags & 0x10) { - s = monster->properties->numDistWeapons ? generateRandomNumber(1, monster->properties->numDistWeapons) : 0; + s = monster->properties->numDistWeapons ? rollDice(1, monster->properties->numDistWeapons) : 0; } else { s = monster->curDistWeapon++; if (monster->curDistWeapon >= monster->properties->numDistWeapons) @@ -1344,7 +1344,7 @@ void LoLEngine::chasePartyWithCloseAttacks(MonsterInPlay *monster) { if (hit) { int mx = calcInflictableDamage(m, dst, hit); - int dmg = generateRandomNumber(2, mx ); + int dmg = rollDice(2, mx ); inflictDamage(dst, dmg, m, 0, 0); applyMonsterAttackSkill(monster, dst, dmg); } @@ -1364,7 +1364,7 @@ void LoLEngine::chasePartyWithCloseAttacks(MonsterInPlay *monster) { walkMonster(monster); } else { setMonsterDirection(monster, monster->destDirection); - setMonsterMode(monster, (generateRandomNumber(1, 100) <= 50) ? 4 : 3); + setMonsterMode(monster, (rollDice(1, 100) <= 50) ? 4 : 3); } } diff --git a/engines/kyra/timer_lol.cpp b/engines/kyra/timer_lol.cpp index 0a17c0993c..fb3a7c2565 100644 --- a/engines/kyra/timer_lol.cpp +++ b/engines/kyra/timer_lol.cpp @@ -147,7 +147,7 @@ void LoLEngine::timerSpecialCharacterUpdate(int timerNum) { break; case 3: - v = generateRandomNumber(1, 2); + v = rollDice(1, 2); if (inflictDamage(i, v, 0x8000, 0, 0x80)) { _txt->printMessage(2, getLangString(0x4022), _characters[i].name); _characters[i].characterUpdateDelay[ii] = 10; @@ -241,7 +241,7 @@ void LoLEngine::timerUpdatePortraitAnimations(int skipUpdate) { } else { _characters[i].curFaceFrame = 0; gui_drawCharPortraitWithStats(i); - _characters[i].nextAnimUpdateCountdown = (int16) generateRandomNumber(1, 12) + 6; + _characters[i].nextAnimUpdateCountdown = (int16) rollDice(1, 12) + 6; } } } |