diff --git a/scumm/akos.cpp b/scumm/akos.cpp index bf4f4500cdc..cfced1bc87d 100644 --- a/scumm/akos.cpp +++ b/scumm/akos.cpp @@ -1464,7 +1464,7 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int switch (code) { case AKC_StartAnimInActor: - akos_queCommand(4, derefActorSafe(a->getAnimVar(GB(2)), "akos_increaseAnim:29"), a->getAnimVar(GB(3)), 0); + akos_queCommand(4, derefActor(a->getAnimVar(GB(2)), "akos_increaseAnim:29"), a->getAnimVar(GB(3)), 0); continue; case AKC_Random: @@ -1510,7 +1510,7 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int akos_queCommand(4, a, a->getAnimVar(GB(2)), 0); continue; case AKC_SetVarInActor: - derefActorSafe(a->getAnimVar(GB(2)), "akos_increaseAnim:9")->setAnimVar(GB(3), GW(4)); + derefActor(a->getAnimVar(GB(2)), "akos_increaseAnim:9")->setAnimVar(GB(3), GW(4)); continue; case AKC_HideActor: akos_queCommand(1, a, 0, 0); diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp index 50fc505d51d..f59dfae6bf7 100644 --- a/scumm/gfx.cpp +++ b/scumm/gfx.cpp @@ -665,7 +665,7 @@ void Scumm::drawFlashlight() { x = _virtualMouse.x; y = _virtualMouse.y; } else { - Actor *a = a = derefActorSafe(VAR(VAR_EGO), "drawFlashlight"); + Actor *a = derefActor(VAR(VAR_EGO), "drawFlashlight"); x = a->x; y = a->y; } @@ -2062,7 +2062,6 @@ void Scumm::setCameraAt(int pos_x, int pos_y) { } void Scumm::setCameraFollows(Actor *a) { - assert(a != NULL); if (_features & GF_AFTER_V7) { byte oldfollow = camera._follows; @@ -2103,9 +2102,8 @@ void Scumm::setCameraFollows(Actor *a) { setCameraAt(a->x, 0); for (i = 1; i < _numActors; i++) { - a = derefActor(i); - if (a->isInCurrentRoom()) - a->needRedraw = true; + if (_actors[i].isInCurrentRoom()) + _actors[i].needRedraw = true; } runHook(0); } @@ -2131,7 +2129,7 @@ void Scumm::moveCamera() { Actor *a = NULL; if (camera._follows) { - a = derefActorSafe(camera._follows, "moveCamera"); + a = derefActor(camera._follows, "moveCamera"); if (abs(camera._cur.x - a->x) > VAR(VAR_CAMERA_THRESHOLD_X) || abs(camera._cur.y - a->y) > VAR(VAR_CAMERA_THRESHOLD_Y)) { camera._movingToActor = true; @@ -2234,7 +2232,7 @@ void Scumm::moveCamera() { } if (camera._mode == CM_FOLLOW_ACTOR) { - a = derefActorSafe(camera._follows, "moveCamera"); + a = derefActor(camera._follows, "moveCamera"); actorx = a->x; t = (actorx >> 3) - _screenStartStrip; @@ -2251,7 +2249,7 @@ void Scumm::moveCamera() { } if (camera._movingToActor) { - a = derefActorSafe(camera._follows, "moveCamera(2)"); + a = derefActor(camera._follows, "moveCamera(2)"); camera._dest.x = a->x; } @@ -2344,7 +2342,7 @@ void Scumm::actorFollowCamera(int act) { } old = camera._follows; - setCameraFollows(derefActorSafe(act, "actorFollowCamera")); + setCameraFollows(derefActor(act, "actorFollowCamera")); if (camera._follows != old) runHook(0); diff --git a/scumm/object.cpp b/scumm/object.cpp index c803dac9604..42a7f124979 100644 --- a/scumm/object.cpp +++ b/scumm/object.cpp @@ -879,7 +879,7 @@ byte *Scumm::getObjOrActorName(int obj) { int i; if (obj < _numActors) - return derefActorSafe(obj, "getObjOrActorName")->getActorName(); + return derefActor(obj, "getObjOrActorName")->getActorName(); if (_features & GF_SMALL_HEADER) { byte offset = 0; @@ -1179,7 +1179,7 @@ int Scumm::getObjX(int obj) { if (obj < _numActors) { if (obj < 1) return 0; /* fix for indy4's map */ - return derefActorSafe(obj, "getObjX")->x; + return derefActor(obj, "getObjX")->x; } else { if (whereIsObject(obj) == WIO_NOT_FOUND) return -1; @@ -1193,7 +1193,7 @@ int Scumm::getObjY(int obj) { if (obj < _numActors) { if (obj < 1) return 0; /* fix for indy4's map */ - return derefActorSafe(obj, "getObjY")->y; + return derefActor(obj, "getObjY")->y; } else { if (whereIsObject(obj) == WIO_NOT_FOUND) return -1; @@ -1210,7 +1210,7 @@ int Scumm::getObjOldDir(int obj) { int Scumm::getObjNewDir(int obj) { int dir; if (obj < _numActors) { - dir = derefActorSafe(obj, "getObjNewDir")->facing; + dir = derefActor(obj, "getObjNewDir")->facing; } else { int x, y; getObjectXYPos(obj, x, y, dir); @@ -1276,7 +1276,7 @@ int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e, if (getObjectOrActorXY(b, x, y) == -1) return -1; if (b < _numActors) - i = derefActorSafe(b, "unkObjProc1")->scalex; + i = derefActor(b, "unkObjProc1")->scalex; } else { x = b; y = c; @@ -1286,7 +1286,7 @@ int Scumm::getDistanceBetween(bool is_obj_1, int b, int c, bool is_obj_2, int e, if (getObjectOrActorXY(e, x2, y2) == -1) return -1; if (e < _numActors) - j = derefActorSafe(e, "unkObjProc1(2)")->scalex; + j = derefActor(e, "unkObjProc1(2)")->scalex; } else { x2 = e; y2 = f; diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp index c9d4353cbbb..8fc7a0e26f2 100644 --- a/scumm/script_v2.cpp +++ b/scumm/script_v2.cpp @@ -642,8 +642,7 @@ void Scumm_v2::o2_subtract() { } void Scumm_v2::o2_waitForActor() { - Actor *a = derefActorSafe(getVarOrDirectByte(0x80), "o2_waitForActor"); - assert(a); + Actor *a = derefActor(getVarOrDirectByte(0x80), "o2_waitForActor"); if (a->moving) { _scriptPointer -= 2; o5_breakHere(); @@ -679,8 +678,7 @@ void Scumm_v2::o2_actorSet() { return; } - a = derefActorSafe(act, "actorSet"); - assert(a); + a = derefActor(act, "actorSet"); switch (_opcode) { case 1: // Actor Sound @@ -989,8 +987,7 @@ void Scumm_v2::o2_ifClassOfIs() { void Scumm_v2::o2_walkActorTo() { int x, y; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o2_walkActorTo"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o2_walkActorTo"); x = getVarOrDirectByte(0x40) * 8; y = getVarOrDirectByte(0x20) * 2; @@ -1003,8 +1000,7 @@ void Scumm_v2::o2_putActor() { int x, y; Actor *a; - a = derefActorSafe(act, "o2_putActor"); - assert(a); + a = derefActor(act, "o2_putActor"); x = getVarOrDirectByte(0x40) * 8; y = getVarOrDirectByte(0x20) * 2; @@ -1025,8 +1021,7 @@ void Scumm_v2::o2_walkActorToObject() { int obj; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o2_walkActorToObject"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o2_walkActorToObject"); obj = getVarOrDirectWord(0x40); if (whereIsObject(obj) != WIO_NOT_FOUND) { int x, y, dir; @@ -1039,8 +1034,7 @@ void Scumm_v2::o2_putActorAtObject() { int obj, x, y; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o2_putActorAtObject"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o2_putActorAtObject"); obj = getVarOrDirectByte(0x40); if (whereIsObject(obj) != WIO_NOT_FOUND) @@ -1057,8 +1051,7 @@ void Scumm_v2::o2_setActorElevation() { int act = getVarOrDirectByte(0x80); int elevation = getVarOrDirectByte(0x40); - Actor *a = derefActorSafe(act, "o2_setActorElevation"); - assert(a); + Actor *a = derefActor(act, "o2_setActorElevation"); a->elevation = elevation; } @@ -1066,8 +1059,7 @@ void Scumm_v2::o2_animateActor() { int act = getVarOrDirectByte(0x80); int anim = getVarOrDirectByte(0x40); - Actor *a = derefActorSafe(act, "o2_animateActor"); - assert(a); + Actor *a = derefActor(act, "o2_animateActor"); a->animateActor(anim); } @@ -1117,8 +1109,7 @@ void Scumm_v2::o2_loadRoomWithEgo() { obj = getVarOrDirectWord(0x80); room = getVarOrDirectByte(0x40); - a = derefActorSafe(VAR(VAR_EGO), "o2_loadRoomWithEgo"); - assert(a); + a = derefActor(VAR(VAR_EGO), "o2_loadRoomWithEgo"); a->putActor(0, 0, room); _egoPositioned = false; @@ -1368,8 +1359,7 @@ void Scumm_v2::o2_cursorCommand() { // TODO: Define the magic numbers void Scumm_v2::o2_getActorWalkBox() { Actor *a; getResultPos(); - a = derefActorSafe(getVarOrDirectByte(0x80), "o2_getActorWalkbox"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o2_getActorWalkbox"); setResult(a->walkbox); } diff --git a/scumm/script_v5.cpp b/scumm/script_v5.cpp index 3f332e75e43..bef146cf0cf 100644 --- a/scumm/script_v5.cpp +++ b/scumm/script_v5.cpp @@ -412,8 +412,7 @@ void Scumm_v5::o5_actorSet() { ss->number, _scriptPointer - _scriptOrgPointer); } - a = derefActorSafe(act, "actorSet"); - assert(a); + a = derefActor(act, "o5_actorSet"); while ((_opcode = fetchScriptByte()) != 0xFF) { if (_features & GF_SMALL_HEADER) @@ -545,8 +544,7 @@ void Scumm_v5::o5_setClass() { // Class '0' means: clean all class data _classData[obj] = 0; if ((_features & GF_SMALL_HEADER) && obj <= _numActors) { - Actor *a = derefActorSafe(obj, "setClass"); - assert(a); + Actor *a = derefActor(obj, "o5_setClass"); a->ignoreBoxes = false; a->forceClip = 0; } @@ -572,13 +570,7 @@ void Scumm_v5::o5_and() { void Scumm_v5::o5_animateActor() { int act = getVarOrDirectByte(0x80); int anim = getVarOrDirectByte(0x40); - - Actor *a = derefActorSafe(act, "o5_animateActor"); - if (!a) { - warning("Invalid actor %d in o5_animateActor", act); - return; - } - + Actor *a = derefActor(act, "o5_animateActor"); a->animateActor(anim); } @@ -890,17 +882,9 @@ void Scumm_v5::o5_expression() { } void Scumm_v5::o5_faceActor() { - int act, obj; - Actor *a; - act = getVarOrDirectByte(0x80); - obj = getVarOrDirectWord(0x40); - - a = derefActorSafe(act, "o5_faceActor"); - if (!a) { - warning("Invalid actor %d in o5_faceActor", act); - return; - } - + int act = getVarOrDirectByte(0x80); + int obj = getVarOrDirectWord(0x40); + Actor *a = derefActor(act, "o5_faceActor"); a->faceToObject(obj); } @@ -928,82 +912,37 @@ void Scumm_v5::o5_freezeScripts() { } void Scumm_v5::o5_getActorCostume() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getActorCostume"); - if (!a) { - warning("Invalid actor %d in o5_getActorCostume", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorCostume"); setResult(a->costume); } void Scumm_v5::o5_getActorElevation() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getActorElevation"); - if (!a) { - warning("Invalid actor %d in o5_getActorElevation", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorElevation"); setResult(a->elevation); } void Scumm_v5::o5_getActorFacing() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getActorFacing"); - if (!a) { - warning("Invalid actor %d in o5_getActorFacing", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorFacing"); setResult(newDirToOldDir(a->facing)); } void Scumm_v5::o5_getActorMoving() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getActorMoving"); - if (!a) { - warning("Invalid actor %d in o5_getActorMoving", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorMoving"); setResult(a->moving); } void Scumm_v5::o5_getActorRoom() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getActorRoom"); - if (!a) { - warning("Invalid actor %d in o5_getActorRoom", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorRoom"); setResult(a->room); } @@ -1017,8 +956,7 @@ void Scumm_v5::o5_getActorScale() { // INDY3 uses this opcode as a wait_for_actor(); if ((_gameId == GID_INDY3_256) || (_gameId == GID_INDY3)) { const byte *oldaddr = _scriptPointer - 1; - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorScale (wait)"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o5_getActorScale (wait)"); if (a->moving) { _scriptPointer = oldaddr; o5_breakHere(); @@ -1027,32 +965,22 @@ void Scumm_v5::o5_getActorScale() { } getResultPos(); - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorScale"); - assert(a); + int act = getVarOrDirectByte(0x80); + a = derefActor(act, "o5_getActorScale"); setResult(a->scalex); } void Scumm_v5::o5_getActorWalkBox() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getActorWalkbox"); - if (!a) { // FIXME - bug 572977 workaround - warning("Invalid actor %d in o5_getActorWalkbox", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorWalkBox"); setResult(a->walkbox); } void Scumm_v5::o5_getActorWidth() { - Actor *a; getResultPos(); - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_getActorWidth"); - assert(a); + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getActorWidth"); setResult(a->width); } @@ -1087,18 +1015,9 @@ void Scumm_v5::o5_getActorY() { } void Scumm_v5::o5_getAnimCounter() { - int act; - Actor *a; getResultPos(); - act = getVarOrDirectByte(0x80); - - a = derefActorSafe(act, "o5_getAnimCounter"); - if (!a) { - warning("Invalid actor %d in o5_getAnimCounter", act); - setResult(0); - return; - } - + int act = getVarOrDirectByte(0x80); + Actor *a = derefActor(act, "o5_getAnimCounter"); setResult(a->cost.animCounter1); } @@ -1229,12 +1148,9 @@ void Scumm_v5::o5_increment() { } void Scumm_v5::o5_isActorInBox() { - int box; - Actor *a; - - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_isActorInBox"); - assert(a); - box = getVarOrDirectByte(0x40); + int act = getVarOrDirectByte(0x80); + int box = getVarOrDirectByte(0x40); + Actor *a = derefActor(act, "o5_isActorInBox"); if (!checkXYInBoxBounds(box, a->x, a->y)) o5_jumpRelative(); @@ -1370,8 +1286,7 @@ void Scumm_v5::o5_loadRoomWithEgo() { obj = getVarOrDirectWord(0x80); room = getVarOrDirectByte(0x40); - a = derefActorSafe(VAR(VAR_EGO), "o5_loadRoomWithEgo"); - assert(a); + a = derefActor(VAR(VAR_EGO), "o5_loadRoomWithEgo"); a->putActor(0, 0, room); _egoPositioned = false; @@ -1502,11 +1417,9 @@ void Scumm_v5::o5_putActor() { int x, y; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_putActor"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o5_putActor"); x = getVarOrDirectWord(0x40); y = getVarOrDirectWord(0x20); - a->putActor(x, y, a->room); } @@ -1514,8 +1427,7 @@ void Scumm_v5::o5_putActorAtObject() { int obj, x, y; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_putActorAtObject"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o5_putActorAtObject"); obj = getVarOrDirectWord(0x40); if (whereIsObject(obj) != WIO_NOT_FOUND) getObjectXYPos(obj, x, y); @@ -1531,12 +1443,7 @@ void Scumm_v5::o5_putActorInRoom() { int act = getVarOrDirectByte(0x80); int room = getVarOrDirectByte(0x40); - a = derefActorSafe(act, "o5_putActorInRoom"); - - if (!a) { // FIXME - yet another null dref hack, see bug 639201 - warning("Invalid actor %d in o5_putActorInRoom", act); - return; - } + a = derefActor(act, "o5_putActorInRoom"); if (a->visible && _currentRoom != room && VAR(VAR_TALK_ACTOR) == a->number) { clearMsgQueue(); @@ -2386,8 +2293,8 @@ void Scumm_v5::o5_wait() { void Scumm_v5::o5_walkActorTo() { int x, y; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_walkActorTo"); - assert(a); + + a = derefActor(getVarOrDirectByte(0x80), "o5_walkActorTo"); x = getVarOrDirectWord(0x40); y = getVarOrDirectWord(0x20); a->startWalkActor(x, y, -1); @@ -2405,13 +2312,11 @@ void Scumm_v5::o5_walkActorToActor() { return; } - a = derefActorSafe(nr, "o5_walkActorToActor"); - assert(a); + a = derefActor(nr, "o5_walkActorToActor"); if (!a->isInCurrentRoom()) return; - a2 = derefActorSafe(nr2, "o5_walkActorToActor(2)"); - assert(a2); + a2 = derefActor(nr2, "o5_walkActorToActor(2)"); if (!a2->isInCurrentRoom()) return; @@ -2434,8 +2339,7 @@ void Scumm_v5::o5_walkActorToObject() { int obj; Actor *a; - a = derefActorSafe(getVarOrDirectByte(0x80), "o5_walkActorToObject"); - assert(a); + a = derefActor(getVarOrDirectByte(0x80), "o5_walkActorToObject"); obj = getVarOrDirectWord(0x40); if (whereIsObject(obj) != WIO_NOT_FOUND) { int x, y, dir; diff --git a/scumm/script_v6.cpp b/scumm/script_v6.cpp index 4443e432b3a..38b330a15a5 100644 --- a/scumm/script_v6.cpp +++ b/scumm/script_v6.cpp @@ -951,7 +951,7 @@ void Scumm_v6::o6_panCameraTo() { void Scumm_v6::o6_actorFollowCamera() { if (_features & GF_AFTER_V7) - setCameraFollows(derefActorSafe(pop(), "actorFollowCamera")); + setCameraFollows(derefActor(pop(), "actorFollowCamera")); else actorFollowCamera(pop()); } @@ -987,15 +987,14 @@ void Scumm_v6::o6_stopScript() { } void Scumm_v6::o6_walkActorToObj() { - int obj, dist; + int act, obj, dist; Actor *a, *a2; int x; dist = pop(); obj = pop(); - a = derefActorSafe(pop(), "o6_walkActorToObj"); - if (!a) - return; + act = pop(); + a = derefActor(act, "o6_walkActorToObj"); if (obj >= _numActors) { if (whereIsObject(obj) == WIO_NOT_FOUND) @@ -1004,9 +1003,7 @@ void Scumm_v6::o6_walkActorToObj() { getObjectXYPos(obj, x, y, dir); a->startWalkActor(x, y, dir); } else { - a2 = derefActorSafe(obj, "o6_walkActorToObj(2)"); - if (!a2) - return; + a2 = derefActor(obj, "o6_walkActorToObj(2)"); if (!a->isInCurrentRoom() || !a2->isInCurrentRoom()) return; if (dist == 0) { @@ -1026,21 +1023,19 @@ void Scumm_v6::o6_walkActorTo() { int x, y; y = pop(); x = pop(); - Actor *a = derefActorSafe(pop(), "o6_walkActorTo"); - assert(a); + Actor *a = derefActor(pop(), "o6_walkActorTo"); a->startWalkActor(x, y, -1); } void Scumm_v6::o6_putActorInRoom() { - int room, x, y; + int room, x, y, act; Actor *a; room = pop(); y = pop(); x = pop(); - a = derefActorSafe(pop(), "o6_putActorInRoom"); - if (!a) - return; + act = pop(); + a = derefActor(act, "o6_putActorInRoom"); if (room == 0xFF || room == 0x7FFFFFFF) { room = a->room; @@ -1061,7 +1056,7 @@ void Scumm_v6::o6_putActorAtObject() { obj = popRoomAndObj(&room); - a = derefActorSafe(pop(), "o6_putActorAtObject"); + a = derefActor(pop(), "o6_putActorAtObject"); if (whereIsObject(obj) != WIO_NOT_FOUND) { getObjectXYPos(obj, x, y); } else { @@ -1075,18 +1070,13 @@ void Scumm_v6::o6_putActorAtObject() { void Scumm_v6::o6_faceActor() { int obj = pop(); - Actor *a = derefActorSafe(pop(), "o6_faceActor"); - assert(a); - + Actor *a = derefActor(pop(), "o6_faceActor"); a->faceToObject(obj); } void Scumm_v6::o6_animateActor() { int anim = pop(); - Actor *a = derefActorSafe(pop(), "o6_animateActor"); - if (!a) - return; - + Actor *a = derefActor(pop(), "o6_animateActor"); a->animateActor(anim); } @@ -1136,9 +1126,7 @@ void Scumm_v6::o6_loadRoomWithEgo() { obj = popRoomAndObj(&room); - a = derefActorSafe(VAR(VAR_EGO), "o6_loadRoomWithEgo"); - assert(a); - + a = derefActor(VAR(VAR_EGO), "o6_loadRoomWithEgo"); a->putActor(0, 0, room); _egoPositioned = false; @@ -1188,74 +1176,68 @@ void Scumm_v6::o6_isRoomScriptRunning() { } void Scumm_v6::o6_getActorMoving() { - Actor *a = derefActorSafe(pop(), "o6_getActorMoving"); - if (a) - push(a->moving); - else - push(0); + Actor *a = derefActor(pop(), "o6_getActorMoving"); + push(a->moving); } void Scumm_v6::o6_getActorRoom() { - Actor *a = derefActorSafe(pop(), "o6_getActorRoom"); - if (a) - push(a->room); - else + int act = pop(); + Actor *a = derefActorSafe(act, "o6_getActorRoom"); + if (!a) { + // FIXME: We got called with act = 0. This happens *a lot* in COMI. + // But why? Is that just normal, or due to a bug in ScummVM? + //warning("Invalid actor %d in o6_getActorRoom", act); push(0); + return; + } + + push(a->room); } void Scumm_v6::o6_getActorWalkBox() { - Actor *a = derefActorSafe(pop(), "o6_getActorWalkBox"); - assert(a); + Actor *a = derefActor(pop(), "o6_getActorWalkBox"); push(a->ignoreBoxes ? 0 : a->walkbox); } void Scumm_v6::o6_getActorCostume() { - Actor *a = derefActorSafe(pop(), "o6_getActorCostume"); - assert(a); + Actor *a = derefActor(pop(), "o6_getActorCostume"); push(a->costume); } void Scumm_v6::o6_getActorElevation() { - Actor *a = derefActorSafe(pop(), "o6_getActorElevation"); - assert(a); + Actor *a = derefActor(pop(), "o6_getActorElevation"); push(a->elevation); } void Scumm_v6::o6_getActorWidth() { - Actor *a = derefActorSafe(pop(), "o6_getActorWidth"); - assert(a); + Actor *a = derefActor(pop(), "o6_getActorWidth"); push(a->width); } void Scumm_v6::o6_getActorScaleX() { - Actor *a = derefActorSafe(pop(), "o6_getActorScale"); - assert(a); + Actor *a = derefActor(pop(), "o6_getActorScale"); push(a->scalex); } void Scumm_v6::o6_getActorAnimCounter1() { - Actor *a = derefActorSafe(pop(), "o6_getActorAnimCounter"); - assert(a); + Actor *a = derefActor(pop(), "o6_getActorAnimCounter"); push(a->cost.animCounter1); } void Scumm_v6::o6_getAnimateVariable() { int var = pop(); - Actor *a = derefActorSafe(pop(), "o6_getAnimateVariable"); - assert(a); + Actor *a = derefActor(pop(), "o6_getAnimateVariable"); push(a->getAnimVar(var)); } void Scumm_v6::o6_isActorInBox() { int box = pop(); - Actor *a = derefActorSafe(pop(), "o6_isActorInBox"); - assert(a); + Actor *a = derefActor(pop(), "o6_isActorInBox"); push(checkXYInBoxBounds(box, a->x, a->y)); } void Scumm_v6::o6_getActorLayer() { - Actor *a = derefActorSafe(pop(), "getActorLayer"); - assert(a); + Actor *a = derefActor(pop(), "getActorLayer"); push(a->layer); } @@ -2454,10 +2436,10 @@ void Scumm_v6::o6_kernelSetFunctions() { setCursorImg(args[1], (uint) - 1, args[2]); break; case 13: - derefActorSafe(args[1], "o6_kernelSetFunctions:14")->remapActorPalette(args[2], args[3], args[4], -1); + derefActor(args[1], "o6_kernelSetFunctions:14")->remapActorPalette(args[2], args[3], args[4], -1); break; case 14: - derefActorSafe(args[1], "o6_kernelSetFunctions:14")->remapActorPalette(args[2], args[3], args[4], args[5]); + derefActor(args[1], "o6_kernelSetFunctions:14")->remapActorPalette(args[2], args[3], args[4], args[5]); break; case 15: _smushFrameRate = args[1]; @@ -2507,7 +2489,7 @@ void Scumm_v6::o6_kernelSetFunctions() { warning("o6_kernelSetFunctions: stub18(%d,%d)", args[1], args[2]); break; case 107: - a = derefActorSafe(args[1], "o6_kernelSetFunctions: 107"); + a = derefActor(args[1], "o6_kernelSetFunctions: 107"); a->scalex = (unsigned char)args[2]; a->needBgReset = true; a->needRedraw = true; @@ -2572,7 +2554,7 @@ void Scumm_v6::o6_kernelSetFunctions() { break; case 107: /* set actor scale */ - a = derefActorSafe(args[1], "o6_kernelSetFunctions: 107"); + a = derefActor(args[1], "o6_kernelSetFunctions: 107"); a->scalex = (unsigned char)args[2]; a->needBgReset = true; a->needRedraw = true; @@ -2589,7 +2571,7 @@ void Scumm_v6::o6_kernelSetFunctions() { break; case 111: - a = derefActorSafe(args[1], "o6_kernelSetFunctions: 111"); + a = derefActor(args[1], "o6_kernelSetFunctions: 111"); a->shadow_mode = args[2] + args[3]; break; @@ -2740,7 +2722,7 @@ void Scumm_v6::o6_kernelGetFunctions() { push(0); break; case 212: - a = derefActorSafe(args[1], "o6_kernelGetFunctions:212"); + a = derefActor(args[1], "o6_kernelGetFunctions:212"); // This is used by walk scripts push(a->frame); break; @@ -2809,7 +2791,7 @@ void Scumm_v6::o6_stampObject() { state = 255; } warning("o6_stampObject: (%d at (%d,%d) scale %d)", object, x, y, state); - Actor *a = derefActor(object); + Actor *a = derefActor(object, "o6_stampObject"); a->scalex = state; a->scaley = state; a->putActor(x, y, _currentRoom); // TODO diff --git a/scumm/script_v8.cpp b/scumm/script_v8.cpp index d2f816afa3f..56e745abcb1 100644 --- a/scumm/script_v8.cpp +++ b/scumm/script_v8.cpp @@ -639,8 +639,7 @@ void Scumm_v8::o8_wait() { case 0x1E: // SO_WAIT_FOR_ACTOR Wait for actor (to finish current action?) offs = fetchScriptWordSigned(); actnum = pop(); - a = derefActorSafe(actnum, "o8_wait:SO_WAIT_FOR_ACTOR"); - assert(a); + a = derefActor(actnum, "o8_wait:SO_WAIT_FOR_ACTOR"); if (a->moving) { _scriptPointer += offs; o6_breakHere(); @@ -666,8 +665,7 @@ void Scumm_v8::o8_wait() { case 0x22: // SO_WAIT_FOR_ANIMATION offs = fetchScriptWordSigned(); actnum = pop(); - a = derefActorSafe(actnum, "o8_wait:SO_WAIT_FOR_ANIMATION"); - assert(a); + a = derefActor(actnum, "o8_wait:SO_WAIT_FOR_ANIMATION"); if (a->isInCurrentRoom() && a->needRedraw) { _scriptPointer += offs; o6_breakHere(); @@ -676,8 +674,7 @@ void Scumm_v8::o8_wait() { case 0x23: // SO_WAIT_FOR_TURN offs = fetchScriptWordSigned(); actnum = pop(); - a = derefActorSafe(actnum, "o8_wait:SO_WAIT_FOR_TURN"); - assert(a); + a = derefActor(actnum, "o8_wait:SO_WAIT_FOR_TURN"); if (a->isInCurrentRoom() && a->moving & MF_TURN) { _scriptPointer += offs; o6_breakHere(); @@ -1388,13 +1385,11 @@ void Scumm_v8::o8_kernelSetFunctions() { break; } case 13: // remapCostume - a = derefActorSafe(args[1], "o8_kernelSetFunctions:remapCostume"); - assert(a); + a = derefActor(args[1], "o8_kernelSetFunctions:remapCostume"); a->remapActorPalette(args[2], args[3], args[4], -1); break; case 14: // remapCostumeInsert - a = derefActorSafe(args[1], "o8_kernelSetFunctions:remapCostumeInsert"); - assert(a); + a = derefActor(args[1], "o8_kernelSetFunctions:remapCostumeInsert"); a->remapActorPalette(args[2], args[3], args[4], args[5]); break; case 15: // setVideoFrameRate @@ -1416,8 +1411,7 @@ void Scumm_v8::o8_kernelSetFunctions() { // lipSyncWidth and lipSyncHeight, which we currently don't support. As a result, // actors will currently not move their mouth at all! // warning("o8_kernelSetFunctions: setActorChoreLimbFrame(%d, %d, %d, %d)", args[1], args[2], args[3], args[4]); - a = derefActorSafe(args[1], "o8_kernelSetFunctions:setActorChoreLimbFrame"); - assert(a); + a = derefActor(args[1], "o8_kernelSetFunctions:setActorChoreLimbFrame"); a->startAnimActor(args[2]); a->animateLimb(args[3], args[4]); @@ -1553,8 +1547,7 @@ void Scumm_v8::o8_kernelGetFunctions() { case 0xD9: { // actorHit - used, for example, to detect ship collision // during ship-to-ship combat. #if 0 - Actor *a = derefActorSafe(args[1], "actorHit"); - assert(a); + Actor *a = derefActor(args[1], "actorHit"); int x = args[2]; int y = args[3]; @@ -1609,8 +1602,7 @@ void Scumm_v8::o8_kernelGetFunctions() { break; case 0xDC: // actorTalkAnimation { - Actor *a = derefActorSafe(args[1], "actorTalkAnimation"); - assert(a); + Actor *a = derefActor(args[1], "actorTalkAnimation"); push(a->talkStartFrame); } break; @@ -1655,8 +1647,7 @@ void Scumm_v8::o8_kernelGetFunctions() { void Scumm_v8::o8_getActorChore() { int actnum = pop(); - Actor *a = derefActorSafe(actnum, "o8_getActorChore"); - assert(a); + Actor *a = derefActor(actnum, "o8_getActorChore"); // FIXME: This is a hack for the cannon scene, as something isn't quite right // here yet.. @@ -1670,8 +1661,7 @@ void Scumm_v8::o8_getActorChore() { void Scumm_v8::o8_getActorZPlane() { int actnum = pop(); - Actor *a = derefActorSafe(actnum, "o8_getActorChore"); - assert(a); + Actor *a = derefActor(actnum, "o8_getActorChore"); int z = a->forceClip; if (z == 100) { diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 8520e31c830..bc0bbcb9bba 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -489,7 +489,7 @@ void Sound::processSfxQueues() { if (act != 0 && (uint) act < 0x80 && !_scumm->_string[0].no_talk_anim) { - a = _scumm->derefActorSafe(act, "processSfxQueues"); + a = _scumm->derefActor(act, "processSfxQueues"); if (a->room == _scumm->_currentRoom && (finished || !_endOfMouthSync)) { b = true; if (!finished)