aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorTorbjörn Andersson2005-01-14 10:10:23 +0000
committerTorbjörn Andersson2005-01-14 10:10:23 +0000
commite38b6890784f71d3a38bdc3fe0b46c059b850ea4 (patch)
tree111b66d146152a51bb65e5ef92124adbab457614 /saga
parent4870ab61f2bc34bc3ca9877561769284a82361da (diff)
downloadscummvm-rg350-e38b6890784f71d3a38bdc3fe0b46c059b850ea4.tar.gz
scummvm-rg350-e38b6890784f71d3a38bdc3fe0b46c059b850ea4.tar.bz2
scummvm-rg350-e38b6890784f71d3a38bdc3fe0b46c059b850ea4.zip
Fixed the "random branch" opcode, I hope. I haven't tested it. The first
IHNM script seems to use it, but doesn't get that far because it terminates on an unknown script function. svn-id: r16558
Diffstat (limited to 'saga')
-rw-r--r--saga/sthread.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/saga/sthread.cpp b/saga/sthread.cpp
index 7aa59fa3f2..e4b1f8f5d3 100644
--- a/saga/sthread.cpp
+++ b/saga/sthread.cpp
@@ -486,26 +486,22 @@ void Script::runThread(SCRIPT_THREAD *thread, int instr_limit) {
// (RJMP): Random branch
case 0x24:
{
- int n_branch;
- unsigned int branch_wt;
- unsigned int branch_jmp;
- int rand_sel = 0;
- int branch_found = 0;
-
- // Ignored?
+ // Supposedly the number of possible branches.
+ // The original interpreter ignores it.
scriptS.readUint16LE();
- n_branch = scriptS.readUint16LE();
- for (i = 0; i < n_branch; i++) {
- branch_wt = scriptS.readUint16LE();
- branch_jmp = scriptS.readUint16LE();
- if (rand_sel == i) {
- thread->i_offset = branch_jmp;
- branch_found = 1;
+
+ uint16 probability = _vm->_rnd.getRandomNumber(scriptS.readUint16LE() - 1);
+
+ while (1) {
+ uint16 branch_probability = scriptS.readUint16LE();
+ uint16 offset = scriptS.readUint16LE();
+
+ if (branch_probability > probability) {
+ thread->i_offset = offset;
break;
}
- }
- if (!branch_found) {
- _vm->_console->DebugPrintf(S_ERROR_PREFIX "%X: Random jump target out of bounds.\n", thread->i_offset);
+
+ probability -= branch_probability;
}
}
break;