diff options
author | Travis Howell | 2009-07-09 00:19:00 +0000 |
---|---|---|
committer | Travis Howell | 2009-07-09 00:19:00 +0000 |
commit | bffeaaae76ebe5b5e981f5157e9b806f48c29a4f (patch) | |
tree | e87a4f9827568c7dac1d4ec933e0b54f9f601262 /engines/kyra | |
parent | 828ed66555b99363fed62b4cbb83c36de68c3024 (diff) | |
parent | c7eedb573ac3ac1bd4c8f8e64d75ee8ee931bc50 (diff) | |
download | scummvm-rg350-bffeaaae76ebe5b5e981f5157e9b806f48c29a4f.tar.gz scummvm-rg350-bffeaaae76ebe5b5e981f5157e9b806f48c29a4f.tar.bz2 scummvm-rg350-bffeaaae76ebe5b5e981f5157e9b806f48c29a4f.zip |
Merged revisions 42252,42255-42263,42269-42271 via svnmerge from
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk
........
r42252 | Kirben | 2009-07-08 11:07:41 +1000 (Wed, 08 Jul 2009) | 1 line
Fix recent regression in vc61().
........
r42255 | thebluegr | 2009-07-08 17:09:03 +1000 (Wed, 08 Jul 2009) | 1 line
Synced the MSVC project files of the gob engine
........
r42256 | thebluegr | 2009-07-08 17:11:43 +1000 (Wed, 08 Jul 2009) | 1 line
Updated the MSVC project files of the scummvm project (added graphics/sjis.*)
........
r42257 | thebluegr | 2009-07-08 17:13:56 +1000 (Wed, 08 Jul 2009) | 1 line
The ENABLE_* flags are only checked for *.cpp files in MSVC, so move the ENABLE_* checks to sjis.cpp to fix compilation under MSVC
........
r42258 | thebluegr | 2009-07-08 17:25:09 +1000 (Wed, 08 Jul 2009) | 1 line
Also added the ENABLE_IHNM and ENABLE_SAGA2 preprocessor definitions to the scummvm project files, not only the saga project files
........
r42259 | thebluegr | 2009-07-08 17:28:13 +1000 (Wed, 08 Jul 2009) | 1 line
Added guards to only include the Shorten audio code when the SAGA2 code in the SAGA engine is enabled
........
r42260 | thebluegr | 2009-07-08 20:25:37 +1000 (Wed, 08 Jul 2009) | 3 lines
Some cleanup for the script debugger code:
- Renamed struct DebugState to ScriptState and r_amp_rest to restAdjust inside EngineState. Changed restAdjust to be a uint16 (actually it is a uint16, but it was being casted back and forth from an unsigned integer, so this clears up its type and size)
- Moved the script state variables from inside the run_vm() into the ScriptState struct, so that they can be accessed by the console commands and the script debugger all the time, and removed the weird isValid code
........
r42261 | thebluegr | 2009-07-08 20:35:51 +1000 (Wed, 08 Jul 2009) | 1 line
Fixed saving/loading again (broken with the latest changes for game feature auto-detection)
........
r42262 | thebluegr | 2009-07-08 20:44:25 +1000 (Wed, 08 Jul 2009) | 1 line
Only the kernel needs to be initialized before anything else, when saving/loading
........
r42263 | thebluegr | 2009-07-08 23:08:51 +1000 (Wed, 08 Jul 2009) | 2 lines
- Moved printObject inside the Console class
- Enabled the parts where disassemble() is called
........
r42269 | athrxx | 2009-07-09 06:19:23 +1000 (Thu, 09 Jul 2009) | 1 line
LOL: fix long standing bugs in the battle system (hit chance, damage, etc) by adapting original style random number generator
........
r42270 | athrxx | 2009-07-09 06:32:34 +1000 (Thu, 09 Jul 2009) | 1 line
LOL: rename new function in last commit according to LordHoto's suggestion
........
r42271 | athrxx | 2009-07-09 07:12:03 +1000 (Thu, 09 Jul 2009) | 1 line
LOL: cleanup
........
svn-id: r42275
Diffstat (limited to 'engines/kyra')
-rw-r--r-- | engines/kyra/lol.cpp | 48 | ||||
-rw-r--r-- | engines/kyra/lol.h | 5 | ||||
-rw-r--r-- | engines/kyra/scene_lol.cpp | 4 | ||||
-rw-r--r-- | engines/kyra/script_lol.cpp | 19 | ||||
-rw-r--r-- | engines/kyra/sprites_lol.cpp | 8 | ||||
-rw-r--r-- | engines/kyra/timer_lol.cpp | 4 |
6 files changed, 55 insertions, 33 deletions
diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp index 7c4b073f29..f2617dc8b4 100644 --- a/engines/kyra/lol.cpp +++ b/engines/kyra/lol.cpp @@ -214,8 +214,6 @@ LoLEngine::LoLEngine(OSystem *system, const GameFlags &flags) : KyraEngine_v1(sy _compassBroken = _drainMagic = 0; _dialogueField = false; - _rndSpecial = 0x12349876; - _buttonData = 0; _activeButtons = 0; gui_resetButtonList(); @@ -1082,7 +1080,7 @@ bool LoLEngine::addCharacter(int id) { loadCharFaceShapes(numChars, id); - _characters[numChars].nextAnimUpdateCountdown = (int16) _rnd.getRandomNumberRng(1, 12) + 6; + _characters[numChars].nextAnimUpdateCountdown = rollDice(1, 12) + 6; for (i = 0; i < 11; i++) { if (_characters[numChars].items[i]) { @@ -1176,7 +1174,7 @@ void LoLEngine::updatePortraitSpeechAnim() { } } - int f = _rnd.getRandomNumberRng(1, 6) - 1; + int f = rollDice(1, 6) - 1; if (f == _characters[_updateCharNum].curFaceFrame) f++; if (f > 5) @@ -1404,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 = _rnd.getRandomNumberRng(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 = _rnd.getRandomNumberRng(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] * (_rnd.getRandomNumberRng(1, 8) + 17)) >> 8; + inc = (_characters[charNum].defaultModifiers[6] * (rollDice(1, 8) + 17)) >> 8; _characters[charNum].magicPointsCur += inc; _characters[charNum].magicPointsMax += inc; - inc = _rnd.getRandomNumberRng(1, 6); + inc = rollDice(1, 6); _characters[charNum].hitPointsCur += inc; _characters[charNum].hitPointsMax += inc; break; @@ -1874,6 +1872,24 @@ void LoLEngine::delay(uint32 millis, bool doUpdate, bool) { } } +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) * pips) / 0x8000) + 1; + if (val > pips) + val -= pips; + res += val; + d++; + } while (d < times); + + return res; +} + void LoLEngine::updateEnvironmentalSfx(int soundId) { snd_processEnvironmentalSoundEffect(soundId, _currentBlock); } @@ -2260,7 +2276,7 @@ int LoLEngine::processMagicIce(int charNum, int spellLevel) { } else { uint16 o = _levelBlockProperties[calcNewBlockPosition(_currentBlock, _currentDirection)].assignedObjects; while (o & 0x8000) { - int might = _rnd.getRandomNumberRng(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]; @@ -3192,7 +3208,7 @@ int LoLEngine::battleHitSkillTest(int16 attacker, int16 target, int skill) { evadeChanceModifier = _characters[target].defaultModifiers[3]; } - int r = _rnd.getRandomNumberRng(1, 100); + int r = rollDice(1, 100); if (r >= sk) return 2; @@ -3230,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 = _rnd.getRandomNumberRng(1, 24); + m->hitOffsX = rollDice(1, 24); m->hitOffsX -= 12; - m->hitOffsY = _rnd.getRandomNumberRng(1, 24); + m->hitOffsY = rollDice(1, 24); m->hitOffsY -= 12; m->hitPoints = CLIP<int16>(m->hitPoints, 0, m->properties->hitPoints); @@ -3436,7 +3452,7 @@ void LoLEngine::checkForPartyDeath() { } void LoLEngine::applyMonsterAttackSkill(MonsterInPlay *monster, int16 target, int16 damage) { - if (_rnd.getRandomNumberRng(1, 100) > monster->properties->attackSkillChance) + if (rollDice(1, 100) > monster->properties->attackSkillChance) return; int t = 0; @@ -3506,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 (_rnd.getRandomNumberRng(1, 100) > monster->properties->defenseSkillChance) + if (rollDice(1, 100) > monster->properties->defenseSkillChance) return; int itm = 0; @@ -3593,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)_rnd.getRandomNumberRng(1, 100) > hitChance) + if (rollDice(1, 100) > hitChance) return 0; int r = 0; @@ -3711,7 +3727,7 @@ void LoLEngine::launchMagicViper() { _screen->copyPage(12, 0); _screen->copyPage(12, 2); - int t = _rnd.getRandomNumberRng(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 12000c31fa..f4ac597b5c 100644 --- a/engines/kyra/lol.h +++ b/engines/kyra/lol.h @@ -642,6 +642,7 @@ private: int olol_setWallType(EMCState *script); int olol_getWallType(EMCState *script); int olol_drawScene(EMCState *script); + int olol_rollDice(EMCState *script); int olol_moveParty(EMCState *script); int olol_delay(EMCState *script); int olol_setGameFlag(EMCState *script); @@ -1313,6 +1314,7 @@ private: // misc void delay(uint32 millis, bool doUpdate = false, bool isMainLoop = false); + int rollDice(int times, int pips); uint8 _compassBroken; uint8 _drainMagic; @@ -1320,8 +1322,7 @@ private: uint8 *_pageBuffer1; uint8 *_pageBuffer2; - uint32 _rndSpecial; - + // spells typedef Common::Functor1Mem<ActiveSpell*, int, LoLEngine> SpellProc; Common::Array<const SpellProc*> _spellProcs; diff --git a/engines/kyra/scene_lol.cpp b/engines/kyra/scene_lol.cpp index 945495517f..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 + _rnd.getRandomNumberRng(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 + _rnd.getRandomNumberRng(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 a606419722..611ad8f9ef 100644 --- a/engines/kyra/script_lol.cpp +++ b/engines/kyra/script_lol.cpp @@ -135,6 +135,11 @@ int LoLEngine::olol_drawScene(EMCState *script) { return 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) { debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_moveParty(%p) (%d)", (const void *)script, stackPos(0)); int mode = stackPos(0); @@ -831,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 * (_rnd.getRandomNumberRng(1, 128) + 192)) >> 8; + l->hitPoints = (l->hitPoints * (rollDice(1, 128) + 192)) >> 8; l->numDistAttacks = l->properties->numDistAttacks; - l->distAttackTick = _rnd.getRandomNumberRng(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; @@ -1366,18 +1371,18 @@ int LoLEngine::olol_characterSkillTest(EMCState *script){ debugC(3, kDebugLevelScriptFuncs, "LoLEngine::olol_characterSkillTest(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); int skill = stackPos(0); int n = countActiveCharacters(); - uint m = 0; + int m = 0; int c = 0; for (int i = 0; i < n ; i++) { - uint v = _characters[i].skillModifiers[skill] + _characters[i].skillLevels[skill] + 25; + int v = _characters[i].skillModifiers[skill] + _characters[i].skillLevels[skill] + 25; if (v > m) { m = v; c = i; } } - return (_rnd.getRandomNumberRng(1, 100) > m) ? -1 : c; + return (rollDice(1, 100) > m) ? -1 : c; } int LoLEngine::olol_countAllMonsters(EMCState *script){ @@ -1440,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 mx ? _rnd.getRandomNumberRng(2, mx) : 0; + return rollDice(2, mx); } int LoLEngine::olol_checkForCertainPartyMember(EMCState *script) { @@ -2617,7 +2622,7 @@ void LoLEngine::setupOpcodeTable() { Opcode(olol_setWallType); Opcode(olol_getWallType); Opcode(olol_drawScene); - Opcode(o1_getRand); + Opcode(olol_rollDice); // 0x04 Opcode(olol_moveParty); diff --git a/engines/kyra/sprites_lol.cpp b/engines/kyra/sprites_lol.cpp index 8cee1dc5fc..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 += _rnd.getRandomNumberRng(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 ? _rnd.getRandomNumberRng(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 = mx ? _rnd.getRandomNumberRng(2, mx) : 0; + 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, (_rnd.getRandomNumberRng(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 84c4f8b19d..0e43487217 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 = _rnd.getRandomNumberRng(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) _rnd.getRandomNumberRng(1, 12) + 6; + _characters[i].nextAnimUpdateCountdown = rollDice(1, 12) + 6; } } } |