[Scummvm-cvs-logs] CVS: scummvm/saga sthread.cpp,1.57,1.58
Torbjörn Andersson
eriktorbjorn at users.sourceforge.net
Fri Jan 14 02:11:20 CET 2005
Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22219
Modified Files:
sthread.cpp
Log Message:
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.
Index: sthread.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sthread.cpp,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- sthread.cpp 11 Jan 2005 21:10:36 -0000 1.57
+++ sthread.cpp 14 Jan 2005 10:10:23 -0000 1.58
@@ -486,26 +486,22 @@
// (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;
More information about the Scummvm-git-logs
mailing list