[Scummvm-git-logs] scummvm master -> 00b83c2ff7a0738b7811a06459145a758bc12871

peterkohaut peterkohaut at users.noreply.github.com
Sat Feb 23 12:57:05 CET 2019


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f70251819a BLADERUNNER: Fixed CppCheck warnings
29f2406f14 BLADERUNNER: Cleanup of McCoy script
00b83c2ff7 BLADERUNNER: Cleanup of Zuben script


Commit: f70251819aa2e5e9715a25bf8c4ed26394a164cf
    https://github.com/scummvm/scummvm/commit/f70251819aa2e5e9715a25bf8c4ed26394a164cf
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2019-02-23T11:39:54+01:00

Commit Message:
BLADERUNNER: Fixed CppCheck warnings

Rat interaction at UG15 is now working exactly as in the original game.
Before the bridge didn't break if player shot the rat on it.

Changed paths:
    engines/bladerunner/actor.cpp
    engines/bladerunner/audio_player.cpp
    engines/bladerunner/decompress_lcw.cpp
    engines/bladerunner/fog.cpp
    engines/bladerunner/game_info.cpp
    engines/bladerunner/light.cpp
    engines/bladerunner/screen_effects.cpp
    engines/bladerunner/script/ai/free_slot_a.cpp
    engines/bladerunner/script/ai/officer_leary.cpp
    engines/bladerunner/script/ai_script.h
    engines/bladerunner/script/scene/ar01.cpp
    engines/bladerunner/script/scene/nr07.cpp
    engines/bladerunner/script/script.cpp
    engines/bladerunner/set.cpp
    engines/bladerunner/slice_renderer.cpp
    engines/bladerunner/ui/kia.cpp
    engines/bladerunner/ui/kia_section_save.cpp
    engines/bladerunner/ui/ui_check_box.cpp
    engines/bladerunner/ui/ui_container.cpp
    engines/bladerunner/vqa_decoder.cpp
    engines/bladerunner/vqa_player.cpp


diff --git a/engines/bladerunner/actor.cpp b/engines/bladerunner/actor.cpp
index 6403eab..b884fe7 100644
--- a/engines/bladerunner/actor.cpp
+++ b/engines/bladerunner/actor.cpp
@@ -285,7 +285,6 @@ void Actor::timerUpdate(int timerId) {
 
 void Actor::movementTrackNext(bool omitAiScript) {
 	bool hasNextMovement;
-	int waypointSetId;
 	bool running;
 	int angle;
 	int delay;
@@ -302,7 +301,7 @@ void Actor::movementTrackNext(bool omitAiScript) {
 		if (angle == -1) {
 			angle = 0;
 		}
-		waypointSetId = _vm->_waypoints->getSetId(waypointId);
+		int waypointSetId = _vm->_waypoints->getSetId(waypointId);
 		_vm->_waypoints->getXYZ(waypointId, &waypointPosition.x, &waypointPosition.y, &waypointPosition.z);
 		if (_setId == waypointSetId && waypointSetId == _vm->_actors[0]->_setId) {
 			stopWalking(false);
@@ -545,8 +544,8 @@ bool Actor::loopWalkToSceneObject(const Common::String &objectName, int proximit
 	if (d < closestDistance) {
 		closestX = x0;
 		closestZ = z1;
-		closestDistance = d;
 	}
+
 	bool inWalkbox;
 	float y = _vm->_scene->_set->getAltitudeAtXZ(closestX, closestZ, &inWalkbox);
 	Vector3 destination(closestX, y, closestZ);
diff --git a/engines/bladerunner/audio_player.cpp b/engines/bladerunner/audio_player.cpp
index df92be2..4507506 100644
--- a/engines/bladerunner/audio_player.cpp
+++ b/engines/bladerunner/audio_player.cpp
@@ -76,8 +76,8 @@ void AudioPlayer::adjustVolume(int track, int volume, int delay, bool overrideVo
 		actualVolume = actualVolume * _sfxVolume / 100;
 	}
 
-	_tracks[track].volume = volume;
-	_vm->_audioMixer->adjustVolume(_tracks[track].channel, volume, 60 * delay);
+	_tracks[track].volume = actualVolume;
+	_vm->_audioMixer->adjustVolume(_tracks[track].channel, actualVolume, 60 * delay);
 }
 
 void AudioPlayer::adjustPan(int track, int pan, int delay) {
diff --git a/engines/bladerunner/decompress_lcw.cpp b/engines/bladerunner/decompress_lcw.cpp
index 9fc4640..7f96fa8 100644
--- a/engines/bladerunner/decompress_lcw.cpp
+++ b/engines/bladerunner/decompress_lcw.cpp
@@ -28,7 +28,7 @@ namespace BladeRunner {
 
 uint32 decompress_lcw(uint8 *inBuf, uint32 inLen, uint8 *outBuf, uint32 outLen) {
 	int version = 1;
-	int count, i, color, pos, relpos, out_remain;
+	int count, i, color, pos, relpos;
 
 	uint8 *src = inBuf;
 	uint8 *dst = outBuf;
@@ -40,7 +40,7 @@ uint32 decompress_lcw(uint8 *inBuf, uint32 inLen, uint8 *outBuf, uint32 outLen)
 	}
 
 	while (src < inBuf + inLen && dst < outEnd && src[0] != 0x80) {
-		out_remain = (int)(outEnd - dst);
+		int out_remain = (int)(outEnd - dst);
 
 		if (src[0] == 0xff) {     // 0b11111111
 			count = src[1] | (src[2] << 8);
diff --git a/engines/bladerunner/fog.cpp b/engines/bladerunner/fog.cpp
index edebc94..4856f1d 100644
--- a/engines/bladerunner/fog.cpp
+++ b/engines/bladerunner/fog.cpp
@@ -78,17 +78,17 @@ void Fog::readAnimationData(Common::ReadStream *stream, int size) {
 	}
 
 	_m11ptr = _animationData;
-	_m12ptr = _m11ptr + (_animatedParameters &   0x1 ? _frameCount : 1);
-	_m13ptr = _m12ptr + (_animatedParameters &   0x2 ? _frameCount : 1);
-	_m14ptr = _m13ptr + (_animatedParameters &   0x4 ? _frameCount : 1);
-	_m21ptr = _m14ptr + (_animatedParameters &   0x8 ? _frameCount : 1);
-	_m22ptr = _m21ptr + (_animatedParameters &  0x10 ? _frameCount : 1);
-	_m23ptr = _m22ptr + (_animatedParameters &  0x20 ? _frameCount : 1);
-	_m24ptr = _m23ptr + (_animatedParameters &  0x40 ? _frameCount : 1);
-	_m31ptr = _m24ptr + (_animatedParameters &  0x80 ? _frameCount : 1);
-	_m32ptr = _m31ptr + (_animatedParameters & 0x100 ? _frameCount : 1);
-	_m33ptr = _m32ptr + (_animatedParameters & 0x200 ? _frameCount : 1);
-	_m34ptr = _m33ptr + (_animatedParameters & 0x400 ? _frameCount : 1);
+	_m12ptr = _m11ptr + ((_animatedParameters &   0x1) ? _frameCount : 1);
+	_m13ptr = _m12ptr + ((_animatedParameters &   0x2) ? _frameCount : 1);
+	_m14ptr = _m13ptr + ((_animatedParameters &   0x4) ? _frameCount : 1);
+	_m21ptr = _m14ptr + ((_animatedParameters &   0x8) ? _frameCount : 1);
+	_m22ptr = _m21ptr + ((_animatedParameters &  0x10) ? _frameCount : 1);
+	_m23ptr = _m22ptr + ((_animatedParameters &  0x20) ? _frameCount : 1);
+	_m24ptr = _m23ptr + ((_animatedParameters &  0x40) ? _frameCount : 1);
+	_m31ptr = _m24ptr + ((_animatedParameters &  0x80) ? _frameCount : 1);
+	_m32ptr = _m31ptr + ((_animatedParameters & 0x100) ? _frameCount : 1);
+	_m33ptr = _m32ptr + ((_animatedParameters & 0x200) ? _frameCount : 1);
+	_m34ptr = _m33ptr + ((_animatedParameters & 0x400) ? _frameCount : 1);
 
 	setupFrame(0);
 }
@@ -98,18 +98,18 @@ void Fog::reset() {
 
 void Fog::setupFrame(int frame) {
 	int offset = frame % _frameCount;
-	_matrix._m[0][0] = (_animatedParameters &   0x1 ? _m11ptr[offset] : *_m11ptr);
-	_matrix._m[0][1] = (_animatedParameters &   0x2 ? _m12ptr[offset] : *_m12ptr);
-	_matrix._m[0][2] = (_animatedParameters &   0x4 ? _m13ptr[offset] : *_m13ptr);
-	_matrix._m[0][3] = (_animatedParameters &   0x8 ? _m14ptr[offset] : *_m14ptr);
-	_matrix._m[1][0] = (_animatedParameters &  0x10 ? _m21ptr[offset] : *_m21ptr);
-	_matrix._m[1][1] = (_animatedParameters &  0x20 ? _m22ptr[offset] : *_m22ptr);
-	_matrix._m[1][2] = (_animatedParameters &  0x40 ? _m23ptr[offset] : *_m23ptr);
-	_matrix._m[1][3] = (_animatedParameters &  0x80 ? _m24ptr[offset] : *_m24ptr);
-	_matrix._m[2][0] = (_animatedParameters & 0x100 ? _m31ptr[offset] : *_m31ptr);
-	_matrix._m[2][1] = (_animatedParameters & 0x200 ? _m32ptr[offset] : *_m32ptr);
-	_matrix._m[2][2] = (_animatedParameters & 0x400 ? _m33ptr[offset] : *_m33ptr);
-	_matrix._m[2][3] = (_animatedParameters & 0x800 ? _m34ptr[offset] : *_m34ptr);
+	_matrix._m[0][0] = ((_animatedParameters &   0x1) ? _m11ptr[offset] : *_m11ptr);
+	_matrix._m[0][1] = ((_animatedParameters &   0x2) ? _m12ptr[offset] : *_m12ptr);
+	_matrix._m[0][2] = ((_animatedParameters &   0x4) ? _m13ptr[offset] : *_m13ptr);
+	_matrix._m[0][3] = ((_animatedParameters &   0x8) ? _m14ptr[offset] : *_m14ptr);
+	_matrix._m[1][0] = ((_animatedParameters &  0x10) ? _m21ptr[offset] : *_m21ptr);
+	_matrix._m[1][1] = ((_animatedParameters &  0x20) ? _m22ptr[offset] : *_m22ptr);
+	_matrix._m[1][2] = ((_animatedParameters &  0x40) ? _m23ptr[offset] : *_m23ptr);
+	_matrix._m[1][3] = ((_animatedParameters &  0x80) ? _m24ptr[offset] : *_m24ptr);
+	_matrix._m[2][0] = ((_animatedParameters & 0x100) ? _m31ptr[offset] : *_m31ptr);
+	_matrix._m[2][1] = ((_animatedParameters & 0x200) ? _m32ptr[offset] : *_m32ptr);
+	_matrix._m[2][2] = ((_animatedParameters & 0x400) ? _m33ptr[offset] : *_m33ptr);
+	_matrix._m[2][3] = ((_animatedParameters & 0x800) ? _m34ptr[offset] : *_m34ptr);
 	_inverted = invertMatrix(_matrix);
 }
 
diff --git a/engines/bladerunner/game_info.cpp b/engines/bladerunner/game_info.cpp
index f777a86..e610dc9 100644
--- a/engines/bladerunner/game_info.cpp
+++ b/engines/bladerunner/game_info.cpp
@@ -56,7 +56,6 @@ bool GameInfo::open(const Common::String &name) {
 		return false;
 	}
 
-	uint32 unk;
 	_actorCount           = s->readUint32LE();   /* 00 */
 	_playerId             = s->readUint32LE();   /* 01 */
 	_flagCount            = s->readUint32LE();   /* 02 */
@@ -64,9 +63,9 @@ bool GameInfo::open(const Common::String &name) {
 	_globalVarCount       = s->readUint32LE();   /* 04 */
 	_sceneNamesCount      = s->readUint32LE();   /* 05 */
 	_initialSceneId       = s->readUint32LE();   /* 06 */
-	unk                   = s->readUint32LE();   /* 07 */
+	                        s->skip(4);          /* 07 */
 	_initialSetId         = s->readUint32LE();   /* 08 */
-	unk                   = s->readUint32LE();   /* 09 */
+	                        s->skip(4);          /* 09 */
 	_waypointCount        = s->readUint32LE();   /* 10 */
 	_sfxTrackCount        = s->readUint32LE();   /* 11 */
 	_musicTrackCount      = s->readUint32LE();   /* 12 */
@@ -76,8 +75,6 @@ bool GameInfo::open(const Common::String &name) {
 	_coverWaypointCount   = s->readUint32LE();   /* 16 */
 	_fleeWaypointCount    = s->readUint32LE();   /* 17 */
 
-	(void)unk;
-
 	char buf[9];
 
 	_sceneNames.resize(_sceneNamesCount);
diff --git a/engines/bladerunner/light.cpp b/engines/bladerunner/light.cpp
index 2231e04..0590630 100644
--- a/engines/bladerunner/light.cpp
+++ b/engines/bladerunner/light.cpp
@@ -85,24 +85,24 @@ void Light::read(Common::ReadStream *stream, int frameCount, int frame, int anim
 	}
 
 	_m11ptr          = _animationData;
-	_m12ptr          = _m11ptr          + (_animatedParameters &     0x1 ? frameCount : 1);
-	_m13ptr          = _m12ptr          + (_animatedParameters &     0x2 ? frameCount : 1);
-	_m14ptr          = _m13ptr          + (_animatedParameters &     0x4 ? frameCount : 1);
-	_m21ptr          = _m14ptr          + (_animatedParameters &     0x8 ? frameCount : 1);
-	_m22ptr          = _m21ptr          + (_animatedParameters &    0x10 ? frameCount : 1);
-	_m23ptr          = _m22ptr          + (_animatedParameters &    0x20 ? frameCount : 1);
-	_m24ptr          = _m23ptr          + (_animatedParameters &    0x40 ? frameCount : 1);
-	_m31ptr          = _m24ptr          + (_animatedParameters &    0x80 ? frameCount : 1);
-	_m32ptr          = _m31ptr          + (_animatedParameters &   0x100 ? frameCount : 1);
-	_m33ptr          = _m32ptr          + (_animatedParameters &   0x200 ? frameCount : 1);
-	_m34ptr          = _m33ptr          + (_animatedParameters &   0x400 ? frameCount : 1);
-	_colorRPtr       = _m34ptr          + (_animatedParameters &   0x800 ? frameCount : 1);
-	_colorGPtr       = _colorRPtr       + (_animatedParameters &  0x1000 ? frameCount : 1);
-	_colorBPtr       = _colorGPtr       + (_animatedParameters &  0x2000 ? frameCount : 1);
-	_falloffStartPtr = _colorBPtr       + (_animatedParameters &  0x4000 ? frameCount : 1);
-	_falloffEndPtr   = _falloffStartPtr + (_animatedParameters &  0x8000 ? frameCount : 1);
-	_angleStartPtr   = _falloffEndPtr   + (_animatedParameters & 0x10000 ? frameCount : 1);
-	_angleEndPtr     = _angleStartPtr   + (_animatedParameters & 0x20000 ? frameCount : 1);
+	_m12ptr          = _m11ptr          + ((_animatedParameters &     0x1) ? frameCount : 1);
+	_m13ptr          = _m12ptr          + ((_animatedParameters &     0x2) ? frameCount : 1);
+	_m14ptr          = _m13ptr          + ((_animatedParameters &     0x4) ? frameCount : 1);
+	_m21ptr          = _m14ptr          + ((_animatedParameters &     0x8) ? frameCount : 1);
+	_m22ptr          = _m21ptr          + ((_animatedParameters &    0x10) ? frameCount : 1);
+	_m23ptr          = _m22ptr          + ((_animatedParameters &    0x20) ? frameCount : 1);
+	_m24ptr          = _m23ptr          + ((_animatedParameters &    0x40) ? frameCount : 1);
+	_m31ptr          = _m24ptr          + ((_animatedParameters &    0x80) ? frameCount : 1);
+	_m32ptr          = _m31ptr          + ((_animatedParameters &   0x100) ? frameCount : 1);
+	_m33ptr          = _m32ptr          + ((_animatedParameters &   0x200) ? frameCount : 1);
+	_m34ptr          = _m33ptr          + ((_animatedParameters &   0x400) ? frameCount : 1);
+	_colorRPtr       = _m34ptr          + ((_animatedParameters &   0x800) ? frameCount : 1);
+	_colorGPtr       = _colorRPtr       + ((_animatedParameters &  0x1000) ? frameCount : 1);
+	_colorBPtr       = _colorGPtr       + ((_animatedParameters &  0x2000) ? frameCount : 1);
+	_falloffStartPtr = _colorBPtr       + ((_animatedParameters &  0x4000) ? frameCount : 1);
+	_falloffEndPtr   = _falloffStartPtr + ((_animatedParameters &  0x8000) ? frameCount : 1);
+	_angleStartPtr   = _falloffEndPtr   + ((_animatedParameters & 0x10000) ? frameCount : 1);
+	_angleEndPtr     = _angleStartPtr   + ((_animatedParameters & 0x20000) ? frameCount : 1);
 
 	setupFrame(frame);
 }
@@ -126,49 +126,49 @@ void Light::readVqa(Common::ReadStream *stream, int frameCount, int frame, int a
 	}
 
 	_m11ptr          = _animationData;
-	_m12ptr          = _m11ptr          + (_animatedParameters &     0x1 ? frameCount : 1);
-	_m13ptr          = _m12ptr          + (_animatedParameters &     0x2 ? frameCount : 1);
-	_m14ptr          = _m13ptr          + (_animatedParameters &     0x4 ? frameCount : 1);
-	_m21ptr          = _m14ptr          + (_animatedParameters &     0x8 ? frameCount : 1);
-	_m22ptr          = _m21ptr          + (_animatedParameters &    0x10 ? frameCount : 1);
-	_m23ptr          = _m22ptr          + (_animatedParameters &    0x20 ? frameCount : 1);
-	_m24ptr          = _m23ptr          + (_animatedParameters &    0x40 ? frameCount : 1);
-	_m31ptr          = _m24ptr          + (_animatedParameters &    0x80 ? frameCount : 1);
-	_m32ptr          = _m31ptr          + (_animatedParameters &   0x100 ? frameCount : 1);
-	_m33ptr          = _m32ptr          + (_animatedParameters &   0x200 ? frameCount : 1);
-	_m34ptr          = _m33ptr          + (_animatedParameters &   0x400 ? frameCount : 1);
-	_colorRPtr       = _m34ptr          + (_animatedParameters &   0x800 ? frameCount : 1);
-	_colorGPtr       = _colorRPtr       + (_animatedParameters &  0x1000 ? frameCount : 1);
-	_colorBPtr       = _colorGPtr       + (_animatedParameters &  0x2000 ? frameCount : 1);
-	_falloffStartPtr = _colorBPtr       + (_animatedParameters &  0x4000 ? frameCount : 1);
-	_falloffEndPtr   = _falloffStartPtr + (_animatedParameters &  0x8000 ? frameCount : 1);
-	_angleStartPtr   = _falloffEndPtr   + (_animatedParameters & 0x10000 ? frameCount : 1);
-	_angleEndPtr     = _angleStartPtr   + (_animatedParameters & 0x20000 ? frameCount : 1);
+	_m12ptr          = _m11ptr          + ((_animatedParameters &     0x1) ? frameCount : 1);
+	_m13ptr          = _m12ptr          + ((_animatedParameters &     0x2) ? frameCount : 1);
+	_m14ptr          = _m13ptr          + ((_animatedParameters &     0x4) ? frameCount : 1);
+	_m21ptr          = _m14ptr          + ((_animatedParameters &     0x8) ? frameCount : 1);
+	_m22ptr          = _m21ptr          + ((_animatedParameters &    0x10) ? frameCount : 1);
+	_m23ptr          = _m22ptr          + ((_animatedParameters &    0x20) ? frameCount : 1);
+	_m24ptr          = _m23ptr          + ((_animatedParameters &    0x40) ? frameCount : 1);
+	_m31ptr          = _m24ptr          + ((_animatedParameters &    0x80) ? frameCount : 1);
+	_m32ptr          = _m31ptr          + ((_animatedParameters &   0x100) ? frameCount : 1);
+	_m33ptr          = _m32ptr          + ((_animatedParameters &   0x200) ? frameCount : 1);
+	_m34ptr          = _m33ptr          + ((_animatedParameters &   0x400) ? frameCount : 1);
+	_colorRPtr       = _m34ptr          + ((_animatedParameters &   0x800) ? frameCount : 1);
+	_colorGPtr       = _colorRPtr       + ((_animatedParameters &  0x1000) ? frameCount : 1);
+	_colorBPtr       = _colorGPtr       + ((_animatedParameters &  0x2000) ? frameCount : 1);
+	_falloffStartPtr = _colorBPtr       + ((_animatedParameters &  0x4000) ? frameCount : 1);
+	_falloffEndPtr   = _falloffStartPtr + ((_animatedParameters &  0x8000) ? frameCount : 1);
+	_angleStartPtr   = _falloffEndPtr   + ((_animatedParameters & 0x10000) ? frameCount : 1);
+	_angleEndPtr     = _angleStartPtr   + ((_animatedParameters & 0x20000) ? frameCount : 1);
 
 	setupFrame(frame);
 }
 
 void Light::setupFrame(int frame) {
 	int offset = frame % _frameCount;
-	_matrix._m[0][0] = (_animatedParameters &     0x1 ? _m11ptr[offset]          : *_m11ptr);
-	_matrix._m[0][1] = (_animatedParameters &     0x2 ? _m12ptr[offset]          : *_m12ptr);
-	_matrix._m[0][2] = (_animatedParameters &     0x4 ? _m13ptr[offset]          : *_m13ptr);
-	_matrix._m[0][3] = (_animatedParameters &     0x8 ? _m14ptr[offset]          : *_m14ptr);
-	_matrix._m[1][0] = (_animatedParameters &    0x10 ? _m21ptr[offset]          : *_m21ptr);
-	_matrix._m[1][1] = (_animatedParameters &    0x20 ? _m22ptr[offset]          : *_m22ptr);
-	_matrix._m[1][2] = (_animatedParameters &    0x40 ? _m23ptr[offset]          : *_m23ptr);
-	_matrix._m[1][3] = (_animatedParameters &    0x80 ? _m24ptr[offset]          : *_m24ptr);
-	_matrix._m[2][0] = (_animatedParameters &   0x100 ? _m31ptr[offset]          : *_m31ptr);
-	_matrix._m[2][1] = (_animatedParameters &   0x200 ? _m32ptr[offset]          : *_m32ptr);
-	_matrix._m[2][2] = (_animatedParameters &   0x400 ? _m33ptr[offset]          : *_m33ptr);
-	_matrix._m[2][3] = (_animatedParameters &   0x800 ? _m34ptr[offset]          : *_m34ptr);
-	_color.r         = (_animatedParameters &  0x1000 ? _colorRPtr[offset]       : *_colorRPtr);
-	_color.g         = (_animatedParameters &  0x2000 ? _colorGPtr[offset]       : *_colorGPtr);
-	_color.b         = (_animatedParameters &  0x4000 ? _colorBPtr[offset]       : *_colorBPtr);
-	_falloffStart    = (_animatedParameters &  0x8000 ? _falloffStartPtr[offset] : *_falloffStartPtr);
-	_falloffEnd      = (_animatedParameters & 0x10000 ? _falloffEndPtr[offset]   : *_falloffEndPtr);
-	_angleStart      = (_animatedParameters & 0x20000 ? _angleStartPtr[offset]   : *_angleStartPtr);
-	_angleEnd        = (_animatedParameters & 0x40000 ? _angleEndPtr[offset]     : *_angleEndPtr);
+	_matrix._m[0][0] = ((_animatedParameters &     0x1) ? _m11ptr[offset]          : *_m11ptr);
+	_matrix._m[0][1] = ((_animatedParameters &     0x2) ? _m12ptr[offset]          : *_m12ptr);
+	_matrix._m[0][2] = ((_animatedParameters &     0x4) ? _m13ptr[offset]          : *_m13ptr);
+	_matrix._m[0][3] = ((_animatedParameters &     0x8) ? _m14ptr[offset]          : *_m14ptr);
+	_matrix._m[1][0] = ((_animatedParameters &    0x10) ? _m21ptr[offset]          : *_m21ptr);
+	_matrix._m[1][1] = ((_animatedParameters &    0x20) ? _m22ptr[offset]          : *_m22ptr);
+	_matrix._m[1][2] = ((_animatedParameters &    0x40) ? _m23ptr[offset]          : *_m23ptr);
+	_matrix._m[1][3] = ((_animatedParameters &    0x80) ? _m24ptr[offset]          : *_m24ptr);
+	_matrix._m[2][0] = ((_animatedParameters &   0x100) ? _m31ptr[offset]          : *_m31ptr);
+	_matrix._m[2][1] = ((_animatedParameters &   0x200) ? _m32ptr[offset]          : *_m32ptr);
+	_matrix._m[2][2] = ((_animatedParameters &   0x400) ? _m33ptr[offset]          : *_m33ptr);
+	_matrix._m[2][3] = ((_animatedParameters &   0x800) ? _m34ptr[offset]          : *_m34ptr);
+	_color.r         = ((_animatedParameters &  0x1000) ? _colorRPtr[offset]       : *_colorRPtr);
+	_color.g         = ((_animatedParameters &  0x2000) ? _colorGPtr[offset]       : *_colorGPtr);
+	_color.b         = ((_animatedParameters &  0x4000) ? _colorBPtr[offset]       : *_colorBPtr);
+	_falloffStart    = ((_animatedParameters &  0x8000) ? _falloffStartPtr[offset] : *_falloffStartPtr);
+	_falloffEnd      = ((_animatedParameters & 0x10000) ? _falloffEndPtr[offset]   : *_falloffEndPtr);
+	_angleStart      = ((_animatedParameters & 0x20000) ? _angleStartPtr[offset]   : *_angleStartPtr);
+	_angleEnd        = ((_animatedParameters & 0x40000) ? _angleEndPtr[offset]     : *_angleEndPtr);
 }
 
 float Light::calculate(Vector3 start, Vector3 end) const {
diff --git a/engines/bladerunner/screen_effects.cpp b/engines/bladerunner/screen_effects.cpp
index a65d4ed..eae7681 100644
--- a/engines/bladerunner/screen_effects.cpp
+++ b/engines/bladerunner/screen_effects.cpp
@@ -50,7 +50,7 @@ void ScreenEffects::readVqa(Common::SeekableReadStream *stream) {
 	entryCount = MIN(entryCount, 7);
 	_entries.resize(entryCount);
 
-	for (Common::Array<Entry>::iterator entry = _entries.begin(); entry != _entries.end(); entry++) {
+	for (Common::Array<Entry>::iterator entry = _entries.begin(); entry != _entries.end(); ++entry) {
 		stream->read(&entry->palette, sizeof(Color256) * 16);
 
 		entry->x      = stream->readUint16LE();
@@ -123,7 +123,7 @@ void ScreenEffects::readVqa(Common::SeekableReadStream *stream) {
 
 void ScreenEffects::getColor(Color256 *outColor, uint16 x, uint16 y, uint16 z) const {
 	Color256 color = { 0, 0, 0 };
-	for (Common::Array<const Entry>::iterator entry = _entries.begin(); entry != _entries.end(); entry++) {
+	for (Common::Array<const Entry>::iterator entry = _entries.begin(); entry != _entries.end(); ++entry) {
 		uint16 x1 = (x / 2) - entry->x;
 		uint16 y1 = (y / 2) - entry->y;
 		if (x1 < entry->width && y1 < entry->height && z > entry->z) {
diff --git a/engines/bladerunner/script/ai/free_slot_a.cpp b/engines/bladerunner/script/ai/free_slot_a.cpp
index f31fbaa..c80b4da 100644
--- a/engines/bladerunner/script/ai/free_slot_a.cpp
+++ b/engines/bladerunner/script/ai/free_slot_a.cpp
@@ -202,13 +202,14 @@ void AIScriptFreeSlotA::OtherAgentEnteredCombatMode(int otherActorId, int combat
 }
 
 void AIScriptFreeSlotA::ShotAtAndMissed() {
-	if (Actor_Query_In_Set(kActorFreeSlotA, kSetUG15))
-		calcHit();
+	if (Actor_Query_In_Set(kActorFreeSlotA, kSetUG15)) {
+		checkIfOnBridge();
+	}
 }
 
 bool AIScriptFreeSlotA::ShotAtAndHit() {
 	if (Actor_Query_In_Set(kActorFreeSlotA, kSetUG15)) {
-		calcHit();
+		checkIfOnBridge();
 		Actor_Set_Goal_Number(kActorFreeSlotA, kGoalFreeSlotAUG15Die);
 		return true;
 	}
@@ -539,14 +540,11 @@ void AIScriptFreeSlotA::FledCombat() {
 	// return false;
 }
 
-void AIScriptFreeSlotA::calcHit() {
+void AIScriptFreeSlotA::checkIfOnBridge() {
 	float x, y, z;
-
 	Actor_Query_XYZ(kActorFreeSlotA, &x, &y, &z);
-
-	if (x >= -30.0f
-	 && x < -150.0f
-	) {
+	// bug? this should probably check if McCoy is close enough because bridge will break long after rat died and player tries to walk through
+	if (-150.0 <= x && x < -30.0f) {
 		Game_Flag_Set(kFlagUG15BridgeWillBreak);
 	}
 }
diff --git a/engines/bladerunner/script/ai/officer_leary.cpp b/engines/bladerunner/script/ai/officer_leary.cpp
index 69ec583..d1e7eea 100644
--- a/engines/bladerunner/script/ai/officer_leary.cpp
+++ b/engines/bladerunner/script/ai/officer_leary.cpp
@@ -539,9 +539,6 @@ bool AIScriptOfficerLeary::GoalChanged(int currentGoalNumber, int newGoalNumber)
 }
 
 bool AIScriptOfficerLeary::UpdateAnimation(int *animation, int *frame) {
-	int v57;
-	int a1;
-
 	switch (_animationState) {
 	case 32:
 		*animation = 603;
@@ -872,10 +869,8 @@ bool AIScriptOfficerLeary::UpdateAnimation(int *animation, int *frame) {
 				*animation = 591;
 			}
 			if (_animationFrame > Slice_Animation_Query_Number_Of_Frames(*animation) / 2) {
-				a1 = *animation;
 				_animationFrame += 3;
-				v57 = _animationFrame;
-				if (v57 > Slice_Animation_Query_Number_Of_Frames(a1) - 1) {
+				if (_animationFrame > Slice_Animation_Query_Number_Of_Frames(*animation) - 1) {
 					_animationFrame = 0;
 					_animationState = _animationStateNext;
 					*animation = _animationNext;
diff --git a/engines/bladerunner/script/ai_script.h b/engines/bladerunner/script/ai_script.h
index 5c5a774..6c857da 100644
--- a/engines/bladerunner/script/ai_script.h
+++ b/engines/bladerunner/script/ai_script.h
@@ -462,7 +462,7 @@ DECLARE_SCRIPT(FreeSlotA)
 	float _fallHeightCurrent;
 	float _fallHeightTarget;
 
-	void calcHit();
+	void checkIfOnBridge();
 	void goToRandomUGxx();
 END_SCRIPT
 
diff --git a/engines/bladerunner/script/scene/ar01.cpp b/engines/bladerunner/script/scene/ar01.cpp
index 1213f47..6c6067d 100644
--- a/engines/bladerunner/script/scene/ar01.cpp
+++ b/engines/bladerunner/script/scene/ar01.cpp
@@ -111,7 +111,7 @@ void SceneScriptAR01::InitializeScene() {
 	        &&  Game_Flag_Query(kFlagHC01toAR01)
 	) {
 		Scene_Loop_Set_Default(kAR01LoopMainLoopNoSpinner);
-	} else {
+	} else { // bug? branch content is equal to previous branch
 		Scene_Loop_Set_Default(kAR01LoopMainLoopNoSpinner);
 	}
 }
diff --git a/engines/bladerunner/script/scene/nr07.cpp b/engines/bladerunner/script/scene/nr07.cpp
index 6fbebd2..02224d0 100644
--- a/engines/bladerunner/script/scene/nr07.cpp
+++ b/engines/bladerunner/script/scene/nr07.cpp
@@ -241,7 +241,7 @@ void SceneScriptNR07::clickedOnVase() {
 			int friendliness = Actor_Query_Friendliness_To_Other(kActorDektora, kActorMcCoy);
 			if (friendliness > 50) {
 				Actor_Modify_Friendliness_To_Other(kActorDektora, kActorMcCoy, 2);
-			} else if (friendliness <= 50) {
+			} else {
 				Actor_Modify_Friendliness_To_Other(kActorDektora, kActorMcCoy, -2);
 			}
 			Actor_Says(kActorMcCoy, 3600, 19);
diff --git a/engines/bladerunner/script/script.cpp b/engines/bladerunner/script/script.cpp
index 9e2097b2..e38477d 100644
--- a/engines/bladerunner/script/script.cpp
+++ b/engines/bladerunner/script/script.cpp
@@ -96,8 +96,6 @@ bool ScriptBase::Region_Check(int left, int top, int right, int down) {
 		&& _vm->_sceneScript->_mouseY >= top
 		&& _vm->_sceneScript->_mouseX <= right
 		&& _vm->_sceneScript->_mouseY <= down;
-
-	return false;
 }
 
 bool ScriptBase::Object_Query_Click(const char *objectName1, const char *objectName2) {
diff --git a/engines/bladerunner/set.cpp b/engines/bladerunner/set.cpp
index 227dd81..f53a635 100644
--- a/engines/bladerunner/set.cpp
+++ b/engines/bladerunner/set.cpp
@@ -94,8 +94,6 @@ bool Set::open(const Common::String &name) {
 	assert(_walkboxCount <= 95);
 
 	for (int i = 0; i < _walkboxCount; ++i) {
-		float x, z;
-
 		s->read(buf, sizeof(buf));
 		_walkboxes[i].name = buf;
 
@@ -105,8 +103,8 @@ bool Set::open(const Common::String &name) {
 		assert(_walkboxes[i].vertexCount <= 8);
 
 		for (int j = 0; j < _walkboxes[i].vertexCount; ++j) {
-			x = s->readFloatLE();
-			z = s->readFloatLE();
+			float x = s->readFloatLE();
+			float z = s->readFloatLE();
 
 			_walkboxes[i].vertices[j] = Vector3(x, _walkboxes[i].altitude, z);
 		}
diff --git a/engines/bladerunner/slice_renderer.cpp b/engines/bladerunner/slice_renderer.cpp
index 1fd0030..73d0cef 100644
--- a/engines/bladerunner/slice_renderer.cpp
+++ b/engines/bladerunner/slice_renderer.cpp
@@ -298,7 +298,7 @@ struct SliceLineIterator {
 	           float startScreenX, float startScreenY, float startScreenZ,
 	           float endSlice,     float startSlice,
 	           Matrix3x2 m);
-	float line();
+	float line() const;
 	void advance();
 };
 
@@ -340,7 +340,7 @@ void SliceLineIterator::setup(
 	_sliceMatrix = mScale * (mTranslate * m);
 }
 
-float SliceLineIterator::line() {
+float SliceLineIterator::line() const {
 	float var_0 = 0.0f;
 
 	if (_currentZ != 0.0f)
diff --git a/engines/bladerunner/ui/kia.cpp b/engines/bladerunner/ui/kia.cpp
index c889890..2cc978f 100644
--- a/engines/bladerunner/ui/kia.cpp
+++ b/engines/bladerunner/ui/kia.cpp
@@ -524,13 +524,12 @@ void KIA::handleKeyDown(const Common::KeyState &kbd) {
 
 void KIA::playerReset() {
 	if (_playerActorDialogueQueueSize != _playerActorDialogueQueuePosition) {
-		if (_playerActorDialogueQueueSize != _playerActorDialogueQueuePosition) {
-			int actorId = _playerActorDialogueQueue[_playerActorDialogueQueuePosition].actorId;
-			if (_vm->_actors[actorId]->isSpeeching()) {
-				_vm->_actors[actorId]->speechStop();
-			}
+		int actorId = _playerActorDialogueQueue[_playerActorDialogueQueuePosition].actorId;
+		if (_vm->_actors[actorId]->isSpeeching()) {
+			_vm->_actors[actorId]->speechStop();
 		}
 	}
+
 	_playerActorDialogueQueueSize = _playerActorDialogueQueuePosition;
 	_playerSliceModelId = -1;
 	if (_playerPhotographId != -1) {
diff --git a/engines/bladerunner/ui/kia_section_save.cpp b/engines/bladerunner/ui/kia_section_save.cpp
index 46ee038..0dbd603 100644
--- a/engines/bladerunner/ui/kia_section_save.cpp
+++ b/engines/bladerunner/ui/kia_section_save.cpp
@@ -389,7 +389,7 @@ void KIASectionSave::save() {
 	Common::OutSaveFile *saveFile = BladeRunner::SaveFileManager::openForSaving(_vm->getTargetName(), slot);
 	if (saveFile == nullptr || saveFile->err()) {
 		delete saveFile;
-		error("Can not open savegame file for writing");
+		warning("KIASectionSave::save(): Can not open savegame file for writing");
 		return;
 	}
 
diff --git a/engines/bladerunner/ui/ui_check_box.cpp b/engines/bladerunner/ui/ui_check_box.cpp
index 510d6e6..0e572c2 100644
--- a/engines/bladerunner/ui/ui_check_box.cpp
+++ b/engines/bladerunner/ui/ui_check_box.cpp
@@ -55,8 +55,9 @@ UICheckBox::UICheckBox(BladeRunnerEngine *vm, UIComponentCallback *valueChangedC
 
 
 void UICheckBox::draw(Graphics::Surface &surface) {
-	int shapeId;
 	if (_rect.right > _rect.left && _rect.bottom > _rect.top) {
+		int shapeId;
+
 		uint timeNow = _vm->_time->currentSystem();
 		if (timeNow - _timeLast > 67) {
 			int frameDelta = (timeNow - _timeLast) / 67u;
diff --git a/engines/bladerunner/ui/ui_container.cpp b/engines/bladerunner/ui/ui_container.cpp
index 34a8cec..eed1bcd 100644
--- a/engines/bladerunner/ui/ui_container.cpp
+++ b/engines/bladerunner/ui/ui_container.cpp
@@ -27,37 +27,37 @@
 namespace BladeRunner {
 
 void UIContainer::draw(Graphics::Surface &surface) {
-	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); component++) {
+	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); ++component) {
 		(*component)->draw(surface);
 	}
 }
 
 void UIContainer::handleMouseMove(int mouseX, int mouseY) {
-	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); component++) {
+	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); ++component) {
 		(*component)->handleMouseMove(mouseX, mouseY);
 	}
 }
 
 void UIContainer::handleMouseDown(bool alternateButton) {
-	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); component++) {
+	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); ++component) {
 		(*component)->handleMouseDown(alternateButton);
 	}
 }
 
 void UIContainer::handleMouseUp(bool alternateButton) {
-	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); component++) {
+	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); ++component) {
 		(*component)->handleMouseUp(alternateButton);
 	}
 }
 
 void UIContainer::handleKeyUp(const Common::KeyState &kbd) {
-	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); component++) {
+	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); ++component) {
 		(*component)->handleKeyUp(kbd);
 	}
 }
 
 void UIContainer::handleKeyDown(const Common::KeyState &kbd) {
-	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); component++) {
+	for (Common::Array<UIComponent*>::iterator component = _components.begin(); component != _components.end(); ++component) {
 		(*component)->handleKeyDown(kbd);
 	}
 }
diff --git a/engines/bladerunner/vqa_decoder.cpp b/engines/bladerunner/vqa_decoder.cpp
index 05cabfc..96746b6 100644
--- a/engines/bladerunner/vqa_decoder.cpp
+++ b/engines/bladerunner/vqa_decoder.cpp
@@ -166,7 +166,6 @@ bool VQADecoder::loadStream(Common::SeekableReadStream *s) {
 
 	IFFChunkHeader chd;
 	uint32 type;
-	bool rc;
 
 	readIFFChunkHeader(s, &chd);
 	if (chd.id != kFORM || !chd.size)
@@ -181,7 +180,7 @@ bool VQADecoder::loadStream(Common::SeekableReadStream *s) {
 		if (!readIFFChunkHeader(_s, &chd))
 			return false;
 
-		rc = false;
+		bool rc = false;
 		switch (chd.id) {
 		case kCINF: rc = readCINF(s, chd.size); break;
 		case kCLIP: rc = readCLIP(s, chd.size); break;
@@ -238,14 +237,13 @@ void VQADecoder::readPacket(uint readFlags) {
 	IFFChunkHeader chd;
 
 	if (remain(_s) < 8) {
-		warning("VQADecoder::readPacket: remain: %d", remain(_s));
+		warning("VQADecoder::readPacket(): remain: %d", remain(_s));
 		assert(remain(_s) < 8);
 	}
 
 	do {
 		if (!readIFFChunkHeader(_s, &chd)) {
-			error("VQADecoder::readPacket: Error reading chunk header");
-			return;
+			error("VQADecoder::readPacket(): Error reading chunk header");
 		}
 
 		bool rc = false;
@@ -266,7 +264,7 @@ void VQADecoder::readPacket(uint readFlags) {
 		}
 
 		if (!rc) {
-			warning("VQADecoder::readPacket: Error handling chunk %s", strTag(chd.id));
+			warning("VQADecoder::readPacket(): Error handling chunk %s", strTag(chd.id));
 			return;
 		}
 	} while (chd.id != kVQFR);
@@ -274,7 +272,7 @@ void VQADecoder::readPacket(uint readFlags) {
 
 void VQADecoder::readFrame(int frame, uint readFlags) {
 	if (frame < 0 || frame >= numFrames()) {
-		error("VQADecoder::readFrame: frame %d out of bounds, frame count is %d", frame, numFrames());
+		error("VQADecoder::readFrame(): frame %d out of bounds, frame count is %d", frame, numFrames());
 	}
 
 	uint32 frameOffset = 2 * (_frameInfo[frame] & 0x0FFFFFFF);
@@ -364,7 +362,7 @@ bool VQADecoder::VQAVideoTrack::readVQFR(Common::SeekableReadStream *s, uint32 s
 		}
 
 		if (!rc) {
-			warning("VQFR: error handling chunk %s", strTag(chd.id));
+			error("VQADecoder::VQAVideoTrack::readVQFR(): error handling chunk %s", strTag(chd.id));
 			return false;
 		}
 	}
diff --git a/engines/bladerunner/vqa_player.cpp b/engines/bladerunner/vqa_player.cpp
index f073895..9a1c89a 100644
--- a/engines/bladerunner/vqa_player.cpp
+++ b/engines/bladerunner/vqa_player.cpp
@@ -114,9 +114,8 @@ int VQAPlayer::update(bool forceDraw, bool advanceFrame, bool useTime, Graphics:
 		_decoder.readFrame(_frameNext, kVQAReadVideo);
 		_decoder.decodeVideoFrame(customSurface != nullptr ? customSurface : _surface, _frameNext);
 
-		int audioPreloadFrames = 14;
-
 		if (_hasAudio) {
+			int audioPreloadFrames = 14;
 			if (!_audioStarted) {
 				for (int i = 0; i < audioPreloadFrames; i++) {
 					if (_frameNext + i < _frameEnd) {


Commit: 29f2406f14ef2cda4634d5318522289c5703707b
    https://github.com/scummvm/scummvm/commit/29f2406f14ef2cda4634d5318522289c5703707b
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2019-02-23T11:39:54+01:00

Commit Message:
BLADERUNNER: Cleanup of McCoy script

Changed paths:
    engines/bladerunner/script/ai/mccoy.cpp
    engines/bladerunner/script/ai_script.h


diff --git a/engines/bladerunner/script/ai/mccoy.cpp b/engines/bladerunner/script/ai/mccoy.cpp
index b5ba454..0fe9f84 100644
--- a/engines/bladerunner/script/ai/mccoy.cpp
+++ b/engines/bladerunner/script/ai/mccoy.cpp
@@ -25,12 +25,11 @@
 namespace BladeRunner {
 
 AIScriptMcCoy::AIScriptMcCoy(BladeRunnerEngine *vm) : AIScriptBase(vm) {
-	dword_45A0D8 = 0;
-	dword_45A0DC = 0;
-	_animationFrameDelta = 0;
-	dword_45A0E4 = 0;
-	off_45A0EC = 0.0f;
-	dword_45A0E8 = 0;
+	_animationLoopCounter = 0;
+	_animationLoopLength = 0;
+	_animationLoopDirection = 0;
+	_animationLoopFrameMin = 0;
+	_animationLoopFrameMax = 0;
 	_animationStateNextSpecial = 0;
 	_animationNextSpecial = 0;
 	_nextSoundId = 0;
@@ -43,12 +42,11 @@ AIScriptMcCoy::AIScriptMcCoy(BladeRunnerEngine *vm) : AIScriptBase(vm) {
 void AIScriptMcCoy::Initialize() {
 	_animationState = 0;
 	_animationFrame = 0;
-	dword_45A0D8 = 0;
-	dword_45A0DC = 30;
-	_animationFrameDelta = 1;
-	dword_45A0E4 = 0;
-	off_45A0EC = 0;
-	dword_45A0E8 = 3;
+	_animationLoopCounter = 0;
+	_animationLoopLength = 30;
+	_animationLoopDirection = 1;
+	_animationLoopFrameMin = 0;
+	_animationLoopFrameMax = 3;
 	_animationStateNextSpecial = 3;
 	_animationNextSpecial = 20;
 	_nextSoundId = -1;
@@ -546,762 +544,812 @@ bool AIScriptMcCoy::GoalChanged(int currentGoalNumber, int newGoalNumber) {
 }
 
 bool AIScriptMcCoy::UpdateAnimation(int *animation, int *frame) {
-	int v7, v18, v19, v46;
+	int v7;
 	switch (_animationState) {
-	case 71:
-		*animation = 52;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(52)) {
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+	case 0:
+		*animation = 19;
+		if (_animationLoopCounter < _animationLoopLength) {
+			_animationFrame += _animationLoopDirection;
+			if (_animationFrame > _animationLoopFrameMax) {
+				_animationFrame = _animationLoopFrameMax;
+				_animationLoopDirection = -1;
+			} else if (_animationFrame < _animationLoopFrameMin) {
+				_animationFrame = _animationLoopFrameMin;
+				_animationLoopDirection = 1;
+			}
+			_animationLoopCounter++;
+		} else {
+			_animationFrame += _animationLoopDirection;
+			_animationLoopLength = 0;
+			if (_animationFrame == 18 && Random_Query(0, 2)) {
+				_animationLoopDirection = -1;
+				_animationLoopCounter   = 0;
+				_animationLoopFrameMin  = 14;
+				_animationLoopFrameMax  = 18;
+				_animationLoopLength    = Random_Query(0, 30);
+			}
+			if (_animationFrame == 26) {
+				if (Random_Query(0, 2)) {
+					_animationLoopDirection = -1;
+					_animationLoopCounter   = 0;
+					_animationLoopFrameMin  = 23;
+					_animationLoopFrameMax  = 26;
+					_animationLoopLength    = Random_Query(0, 30);
+				}
+			}
+			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+				_animationFrame = 0;
+				if (Random_Query(0, 2)) {
+					_animationLoopCounter  = 0;
+					_animationLoopFrameMin = 0;
+					_animationLoopFrameMax = 3;
+					_animationLoopLength   = Random_Query(0, 45);
+				}
+			}
+			if (_animationFrame < 0) {
+				_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
+			}
+		}
+		break;
+
+	case 3:
+	case 4:
+		if (_animationFrame == 0 && !Game_Flag_Query(kFlagMcCoyAnimation1)) {
+			_animationFrame = 1;
+			_animationState = _animationStateNextSpecial;
+			*animation = _animationNextSpecial;
+			_animationStateNextSpecial = 4;
+			_animationNextSpecial = 20;
+		} else if (_animationFrame <= 4 && Game_Flag_Query(kFlagMcCoyAnimation1)) {
+			Game_Flag_Reset(kFlagMcCoyAnimation1);
 			*animation = 19;
 			_animationFrame = 0;
 			_animationState = 0;
-			Player_Gains_Control();
+		} else {
+			*animation = 20;
+			_animationFrame++;
+			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+				_animationFrame = 0;
+			}
 		}
 		break;
-	case 70:
-		*animation = 51;
+
+	case 5:
+		*animation = 21;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(51)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 69:
-		*animation = 50;
+
+	case 6:
+		*animation = 27;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(50)) {
-			Actor_Change_Animation_Mode(kActorMcCoy, 53);
-			*animation = 51;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = 0;
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 68:
-		*animation = 18;
-		v7 = Slice_Animation_Query_Number_Of_Frames(*animation) - 1 - Global_Variable_Query(kVariableNR01GetUpCounter);
-		if (_animationFrame < v7) {
-			_animationFrame++;
-		} else if (_animationFrame > v7) {
-			_animationFrame--;
+
+	case 7:
+		*animation = 22;
+		_animationFrame++;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = 0;
+			_animationState = 3;
+			*animation = 20;
 		}
-		if (_animationFrame <= 0) {
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
-			*animation = 19;
-			_animationState = 0;
+		break;
+
+	case 8:
+		*animation = 23;
+		_animationFrame++;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			Game_Flag_Reset(kFlagNR01McCoyIsDrugged);
-			Scene_Exits_Enable();
-			Player_Set_Combat_Mode_Access(true);
-			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 67:
-		*animation = 53;
+
+	case 9:
+		*animation = 24;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(53)) {
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
-			*animation = 19;
-			_animationState = 0;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR04Drink) {
-				Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeDie);
-			}
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 66:
-		*animation = 40;
+
+	case 10:
+		*animation = 25;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(40)) {
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
-			*animation = 19;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 0;
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 65:
-		*animation = 45;
+
+	case 11:
+		*animation = 26;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(45)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 14;
-			*animation = 0;
-			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 64:
-		*animation = 44;
+
+	case 12:
+		*animation = 27;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(44)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 63;
-			*animation = 43;
+			_animationState = 3;
+			*animation = 20;
 		}
 		break;
-	case 63:
-		*animation = 43;
+
+	case 13:
+		*animation = 19;
+		if (_animationFrame < Slice_Animation_Query_Number_Of_Frames(*animation) / 2) {
+			_animationFrame -= 3;
+			if (_animationFrame <= 0) {
+				_animationFrame = 0;
+				*animation = _animationNext;
+				_animationState = _animationStateNext;
+			}
+		} else {
+			_animationFrame += 3;
+			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+				_animationFrame = 0;
+				*animation = _animationNext;
+				_animationState = _animationStateNext;
+			}
+		}
+		break;
+
+	case 14:
+		*animation = 0;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(43)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationState = 14;
 			_animationFrame = 0;
 		}
 		break;
-	case 62:
-		*animation = 42;
+
+	case 15:
+		*animation = 8;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(42)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 63;
-			*animation = 43;
+			_animationState = 14;
+			*animation = 0;
 		}
 		break;
-	case 61:
-		*animation = 41;
-		_animationFrame--;
-		if (_animationFrame <= 0) {
+
+	case 16:
+		*animation = 9;
+		_animationFrame++;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			*animation = 19;
 			_animationFrame = 0;
 			_animationState = 0;
-			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNRxxSitAtTable) {
-				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyNRxxStandUp);
-			}
 		}
 		break;
-	case 60:
-		*animation = 41;
-		if (_animationFrame < Slice_Animation_Query_Number_Of_Frames(41) - 1) {
-			_animationFrame++;
+
+	case 17:
+		*animation = 12;
+		_animationFrame = 0;
+		// weird, but thats in game code
+		if (Slice_Animation_Query_Number_Of_Frames(*animation) <= 0) {
+			_animationFrame = 0;
+			_animationState = 17;
 		}
 		break;
-	case 59:
-		*animation = 48;
+
+	case 18:
+		*animation = 10;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(48)) {
-			*animation = 19;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			dword_45A0DC = 0;
-			_animationState = 0;
-			Player_Gains_Control();
-			Item_Add_To_World(kItemChair, 982, kSetCT08_CT51_UG12, -110.0, 0.0, -192.0, 0, 48, 32, false, true, false, false);
+			_animationState = 17;
+			*animation = 12;
 		}
 		break;
-	case 58:
-		*animation = 47;
+
+	case 19:
+		*animation = 11;
 		_animationFrame++;
-		if (_animationFrame == 6) {
-			v18 = Random_Query(0, 2);
-			v19 = 0;
-			if (v18 == 0) {
-				v19 = 595;
-			} else if (v18 == 1) {
-				v19 = 594;
-			} else if (v18 == 2) {
-				v19 = 593;
-			}
-			Ambient_Sounds_Play_Sound(v19, 39, 0, 0, 99);
-		}
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation) - 1) { //why -1?
+		if (_animationFrame >= 12) {
 			_animationFrame = 0;
+			_animationState = 14;
+			*animation = 0;
 		}
 		break;
-	case 57:
-		*animation = 46;
+
+	case 21:
+		*animation = 12;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(46)) {
-			_animationFrame = 0;
+		if (_animationFrame == 1
+		 && Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR11Shoot
+		 && _NR10SteeleShooting
+		) {
+			_nextSoundId = 27;
 		}
-		if (!Game_Flag_Query(kFlagMcCoyTiedDown)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationState = 17;
 			_animationFrame = 0;
-			_animationState = 59;
-			*animation = 48;
+			*animation = 12;
+			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR11Shoot) {
+				_animationFrame = 0;
+				_animationState = 21;
+				_NR10SteeleShooting = true;
+				*animation = 12;
+			}
 		}
 		break;
-	case 56:
-		*animation = 49;
+
+	case 22:
+		_animationFrame = 0;
+		_animationState = 17;
+		*animation = 12;
+		break;
+
+	case 23:
+		*animation = 1;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(49)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			if (Actor_Query_Which_Set_In(kActorMcCoy) == kSetUG15) {
-				_animationState = 27;
-			} else {
-				*animation = 19;
-				_animationState = 0;
-				Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
-			}
+			_animationState = 14;
+			*animation = 0;
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeCombatIdle);
 		}
 		break;
-	case 55:
-		*animation = 32;
+
+	case 24:
+		*animation = 1;
 		_animationFrame++;
-		if (_animationFrame == 7) {
-			Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeFeeding);
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = 0;
+			_animationState = 14;
+			*animation = 0;
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeCombatIdle);
 		}
+		break;
+
+	case 25:
+		*animation = 17;
+		_animationFrame++;
 		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			*animation = 19;
+			_animationFrame = 0;
 			_animationState = 0;
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
 		}
 		break;
-	case 53:
-		*animation = 18;
-		_animationFrame--;
-		if (_animationFrame <= 0) {
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+
+	case 26:
+		*animation = 17;
+		_animationFrame++;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			*animation = 19;
 			_animationFrame = 0;
 			_animationState = 0;
-			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyBB11GetUp) {
-				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyBB11PrepareToRunAway);
-			}
-			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR01ThrownOut) {
-				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyNR01GetUp);
-			}
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
 		}
 		break;
-	case 52:
-		*animation = 31;
+
+	case 27:
+		*animation = 18;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(31)) {
-			_animationFrame = Slice_Animation_Query_Number_Of_Frames(31) - 1;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
 			_animationState = 50;
+			UG15fall();
+			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR04Drink) {
+				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyNR04PassOut);
+			}
 		}
 		break;
-	case 51:
-		*animation = 28;
+
+	case 28:
+		*animation = 5;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(28)) {
-			Player_Set_Combat_Mode(true);
-			sub_405800();
-			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
-			_animationFrame = 0;
-			Player_Gains_Control();
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
+			_animationState = 50;
+			UG15fall();
 		}
 		break;
-	case 50:
+
+	case 29:
 		*animation = 18;
-		_animationFrame = Slice_Animation_Query_Number_Of_Frames(18) - 1;
-		break;
-	case 49:
-		*animation = 34;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(34)) {
-			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
-			*animation = 19;
-			_animationFrame = 0;
-			sub_405660();
+		_animationFrame += _animationLoopDirection;
+		if (_animationFrame < 14) {
+			_animationLoopDirection = 1;
 		}
-		break;
-	case 48:
-		*animation = 33;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(33)) {
-			_animationFrame = 0;
-			_animationState = 49;
-			*animation = 34;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeDie);
+			*animation = 18;
+			_animationState = 27;
+			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
 		}
 		break;
-	case 47:
-		*animation = 29;
+
+	case 30:
+		*animation = 13;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(29)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 48;
-			*animation = 33;
 		}
-		break;
-	case 46:
-		Actor_Set_Invisible(kActorMcCoy, false);
-		*animation = 36;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(36)) {
-			*animation = 19;
-			_animationFrame = 0;
-			Player_Gains_Control();
-			sub_405660();
-			Actor_Face_Heading(kActorMcCoy, (Actor_Query_Facing_1024(kActorMcCoy) + 512) & 1023, false);
+		if (_animationFrame == 2) {
+			Sound_Right_Footstep_Walk(kActorMcCoy);
+		} else if (_animationFrame == 10) {
+			Sound_Left_Footstep_Walk(kActorMcCoy);
 		}
 		break;
-	case 45:
-		*animation = 35;
+
+	case 31:
+		*animation = 14;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(35)) {
-			Actor_Set_Invisible(kActorMcCoy, true);
-			*animation = 19;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			sub_405660();
-		}
-		break;
-	case 44:
-		*animation = 30;
-		if (_animationFrame++ == 127) {
-			Game_Flag_Set(kFlagCT04BodyDumped);
 		}
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(30)) {
-			*animation = 19;
-			sub_405660();
-			Actor_Set_At_XYZ(kActorMcCoy, -203.41f, -621.3f, 724.57f, 538);
-			Player_Gains_Control();
+		if (_animationFrame == 5) {
+			Sound_Left_Footstep_Run(kActorMcCoy);
+		} else if (_animationFrame == 12) {
+			Sound_Right_Footstep_Run(kActorMcCoy);
 		}
 		break;
-	case 43:
-		*animation = 38;
+
+	case 32:
+		_animationFrame = 1;
+		_animationState = 30;
+		*animation = 13;
+		break;
+
+	case 36:
+		*animation = 3;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(38) - 1) { //why -1?
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
-		switch (_animationFrame) {
-		case 9:
+		if (_animationFrame == 15) {
 			Sound_Left_Footstep_Walk(kActorMcCoy);
-			break;
-		case 4:
-			Sound_Right_Footstep_Walk(kActorMcCoy);
-			break;
-		case 1:
+		}
+		if (_animationFrame == 6) {
 			Sound_Right_Footstep_Walk(kActorMcCoy);
-			break;
 		}
 		break;
-	case 42:
-		*animation = 37;
+
+	case 37:
+		*animation = 4;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(37) - 1) { //why -1?
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
-		switch (_animationFrame) {
-		case 9:
-			Sound_Left_Footstep_Walk(kActorMcCoy);
-			break;
-		case 4:
-			Sound_Right_Footstep_Walk(kActorMcCoy);
-			break;
-		case 1:
-			Sound_Right_Footstep_Walk(kActorMcCoy);
-			break;
+		if (_animationFrame == 6) {
+			Sound_Left_Footstep_Run(kActorMcCoy);
+		}
+		if (_animationFrame == 0) {
+			Sound_Right_Footstep_Run(kActorMcCoy);
 		}
 		break;
-	case 41:
-		*animation = 7;
+
+	case 38:
+		*animation = 15;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(7)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			++off_45A0EC;
 		}
 		if (_animationFrame == 9) {
 			Sound_Left_Footstep_Walk(kActorMcCoy);
 		} else if (_animationFrame == 4) {
 			Sound_Right_Footstep_Walk(kActorMcCoy);
 		}
-		if (Game_Flag_Query(kFlagHF05toHF07)) {
-			sub_4059D0(-0.2f);
+		if (Game_Flag_Query(kFlagHF07toHF05)) {
+			walkStairsLeft(0.5f);
 		}
 		break;
-	case 40:
-		*animation = 6;
+
+	case 39:
+		*animation = 16;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(6)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			++off_45A0EC;
 		}
 		if (_animationFrame == 8) {
 			Sound_Left_Footstep_Walk(kActorMcCoy);
 		} else if (_animationFrame == 3) {
 			Sound_Right_Footstep_Walk(kActorMcCoy);
 		}
-		if (Game_Flag_Query(kFlagHF07toHF05)) {
-			sub_405940(0.5f);
+		if (Game_Flag_Query(kFlagHF05toHF07)) {
+			walkStairsRight(-0.2f);
 		}
 		break;
-	case 39:
-		*animation = 16;
+
+	case 40:
+		*animation = 6;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(16)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			++off_45A0EC;
 		}
 		if (_animationFrame == 8) {
 			Sound_Left_Footstep_Walk(kActorMcCoy);
 		} else if (_animationFrame == 3) {
 			Sound_Right_Footstep_Walk(kActorMcCoy);
 		}
-		if (Game_Flag_Query(kFlagHF05toHF07)) {
-			sub_4059D0(-0.2f);
+		if (Game_Flag_Query(kFlagHF07toHF05)) {
+			walkStairsLeft(0.5f);
 		}
 		break;
-	case 38:
-		*animation = 15;
+
+	case 41:
+		*animation = 7;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(15)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			++off_45A0EC;
 		}
 		if (_animationFrame == 9) {
 			Sound_Left_Footstep_Walk(kActorMcCoy);
 		} else if (_animationFrame == 4) {
 			Sound_Right_Footstep_Walk(kActorMcCoy);
 		}
-		if (Game_Flag_Query(kFlagHF07toHF05)) {
-			sub_405940(0.5f);
+		if (Game_Flag_Query(kFlagHF05toHF07)) {
+			walkStairsRight(-0.2f);
 		}
 		break;
-	case 37:
+
+	case 42:
+		*animation = 37;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(4)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation) - 1) { //why -1?
 			_animationFrame = 0;
 		}
-		*animation = 4;
-		if (_animationFrame == 6) {
-			Sound_Left_Footstep_Run(kActorMcCoy);
-		}
-		if (_animationFrame == 0) {
-			Sound_Right_Footstep_Run(kActorMcCoy);
+		switch (_animationFrame) {
+		case 9:
+			Sound_Left_Footstep_Walk(kActorMcCoy);
+			break;
+		case 4:
+			Sound_Right_Footstep_Walk(kActorMcCoy);
+			break;
+		case 1:
+			Sound_Right_Footstep_Walk(kActorMcCoy);
+			break;
 		}
 		break;
-	case 36:
+
+	case 43:
+		*animation = 38;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(3)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation) - 1) { //why -1?
 			_animationFrame = 0;
 		}
-		*animation = 3;
-		if (_animationFrame == 15) {
-			Sound_Left_Footstep_Walk(kActorMcCoy);
-		}
-		if (_animationFrame == 6) {
+		switch (_animationFrame) {
+		case 1:
+			Sound_Right_Footstep_Walk(kActorMcCoy);
+			break;
+		case 4:
 			Sound_Right_Footstep_Walk(kActorMcCoy);
+			break;
+		case 9:
+			Sound_Left_Footstep_Walk(kActorMcCoy);
+			break;
 		}
 		break;
-	case 32:
-		_animationFrame = 1;
-		_animationState = 30;
-		*animation = 13;
-		break;
-	case 31:
+
+	case 44:
+		*animation = 30;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(14)) {
-			_animationFrame = 0;
+		if (_animationFrame == 127) {
+			Game_Flag_Set(kFlagCT04BodyDumped);
 		}
-		*animation = 14;
-		if (_animationFrame == 5) {
-			Sound_Left_Footstep_Run(kActorMcCoy);
-		} else if (_animationFrame == 12) {
-			Sound_Right_Footstep_Run(kActorMcCoy);
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			*animation = 19;
+			_animationFrame = 0;
+			ChangeAnimationMode(kAnimationModeIdle);
+			Actor_Set_At_XYZ(kActorMcCoy, -203.41f, -621.3f, 724.57f, 538);
+			Player_Gains_Control();
 		}
 		break;
-	case 30:
-		*animation = 13;
+
+	case 45:
+		*animation = 35;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(13)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Set_Invisible(kActorMcCoy, true);
+			*animation = 19;
 			_animationFrame = 0;
-		}
-		if (_animationFrame == 2) {
-			Sound_Right_Footstep_Walk(kActorMcCoy);
-		} else if (_animationFrame == 10) {
-			Sound_Left_Footstep_Walk(kActorMcCoy);
+			ChangeAnimationMode(kAnimationModeIdle);
 		}
 		break;
-	case 29:
-		v46 = _animationFrame + _animationFrameDelta;
-		*animation = 18;
-		_animationFrame = v46;
-		if (v46 < 14) {
-			_animationFrameDelta = 1;
-		}
+
+	case 46:
+		Actor_Set_Invisible(kActorMcCoy, false);
+		*animation = 36;
+		_animationFrame++;
 		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
-			Actor_Change_Animation_Mode(kActorMcCoy, 48);
-			*animation = 18;
-			_animationState = 27;
-			_animationFrame = Slice_Animation_Query_Number_Of_Frames(18) - 1;
+			*animation = 19;
+			_animationFrame = 0;
+			Player_Gains_Control();
+			ChangeAnimationMode(kAnimationModeIdle);
+			Actor_Face_Heading(kActorMcCoy, (Actor_Query_Facing_1024(kActorMcCoy) + 512) & 1023, false);
 		}
 		break;
-	case 28:
-		*animation = 5;
+
+	case 47:
+		*animation = 29;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(5)) {
-			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
-			_animationState = 50;
-			UG15fall();
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = 0;
+			_animationState = 48;
+			*animation = 33;
 		}
 		break;
-	case 27:
-		*animation = 18;
+
+	case 48:
+		*animation = 33;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(18)) {
-			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
-			_animationState = 50;
-			UG15fall();
-			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR04Drink) {
-				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyNR04PassOut);
-			}
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = 0;
+			_animationState = 49;
+			*animation = 34;
 		}
 		break;
-	case 26:
-		*animation = 17;
+
+	case 49:
+		*animation = 34;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(17)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
 			*animation = 19;
 			_animationFrame = 0;
-			_animationState = 0;
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			ChangeAnimationMode(kAnimationModeIdle);
 		}
 		break;
-	case 25:
-		*animation = 17;
+
+	case 50:
+		*animation = 18;
+		_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
+		break;
+
+	case 51:
+		*animation = 28;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(17)) {
-			*animation = 19;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Player_Set_Combat_Mode(true);
+			ChangeAnimationMode(kAnimationModeCombatIdle);
+			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
 			_animationFrame = 0;
-			_animationState = 0;
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			Player_Gains_Control();
 		}
 		break;
-	case 24:
-		*animation = 1;
+
+	case 52:
+		*animation = 31;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(1)) {
-			_animationFrame = 0;
-			_animationState = 14;
-			*animation = 0;
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeCombatIdle);
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
+			_animationState = 50;
 		}
 		break;
-	case 23:
-		*animation = 1;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(1)) {
+
+	case 53:
+		*animation = 18;
+		_animationFrame--;
+		if (_animationFrame <= 0) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			*animation = 19;
 			_animationFrame = 0;
-			_animationState = 14;
-			*animation = 0;
-			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeCombatIdle);
+			_animationState = 0;
+			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyBB11GetUp) {
+				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyBB11PrepareToRunAway);
+			}
+			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR01ThrownOut) {
+				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyNR01GetUp);
+			}
 		}
 		break;
-	case 22:
-		_animationFrame = 0;
-		_animationState = 17;
-		*animation = 12;
-		break;
-	case 21:
-		*animation = 12;
+
+	case 55:
+		*animation = 32;
 		_animationFrame++;
-		if (_animationFrame == 1
-		 && Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR11Shoot
-		 && _NR10SteeleShooting
-		) {
-			_nextSoundId = 27;
+		if (_animationFrame == 7) {
+			Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeFeeding);
 		}
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(12)) {
-			_animationState = 17;
-			_animationFrame = 0;
-			*animation = 12;
-			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR11Shoot) {
-				_animationFrame = 0;
-				_animationState = 21;
-				_NR10SteeleShooting = true;
-				*animation = 12;
-			}
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			*animation = 19;
+			_animationState = 0;
 		}
 		break;
-	case 19:
-		*animation = 11;
+
+	case 56:
+		*animation = 49;
 		_animationFrame++;
-		if (_animationFrame >= 12) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 14;
-			*animation = 0;
+			if (Actor_Query_Which_Set_In(kActorMcCoy) == kSetUG15) {
+				_animationState = 27;
+			} else {
+				*animation = 19;
+				_animationState = 0;
+				Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			}
 		}
 		break;
-	case 18:
-		*animation = 10;
+
+	case 57:
+		*animation = 46;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(10)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 17;
-			*animation = 12;
+		}
+		if (!Game_Flag_Query(kFlagMcCoyTiedDown)) {
+			_animationFrame = 0;
+			_animationState = 59;
+			*animation = 48;
 		}
 		break;
-	case 17:
-		*animation = 12;
-		_animationFrame = 0;
-		// weird, but thats in game code
-		if (Slice_Animation_Query_Number_Of_Frames(12) <= 0) {
+
+	case 58:
+		*animation = 47;
+		_animationFrame++;
+		if (_animationFrame == 6) {
+			Ambient_Sounds_Play_Sound(Random_Query(593, 595), 39, 0, 0, 99);
+		}
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation) - 1) { //why -1?
 			_animationFrame = 0;
-			_animationState = 17;
 		}
 		break;
-	case 16:
-		*animation = 9;
+
+	case 59:
+		*animation = 48;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(9)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			*animation = 19;
 			_animationFrame = 0;
+			_animationLoopLength = 0;
 			_animationState = 0;
+			Player_Gains_Control();
+			Item_Add_To_World(kItemChair, 982, kSetCT08_CT51_UG12, -110.0, 0.0, -192.0, 0, 48, 32, false, true, false, false);
 		}
 		break;
-	case 15:
-		*animation = 8;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(8)) {
-			_animationFrame = 0;
-			_animationState = 14;
-			*animation = 0;
+
+	case 60:
+		*animation = 41;
+		if (_animationFrame < Slice_Animation_Query_Number_Of_Frames(*animation) - 1) {
+			_animationFrame++;
 		}
 		break;
-	case 14:
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(0)) {
-			_animationState = 14;
+
+	case 61:
+		*animation = 41;
+		_animationFrame--;
+		if (_animationFrame <= 0) {
+			*animation = 19;
 			_animationFrame = 0;
-		}
-		*animation = 0;
-		break;
-	case 13:
-		*animation = 19;
-		if (_animationFrame < Slice_Animation_Query_Number_Of_Frames(19) / 2) {
-			_animationFrame -= 3;
-			if (_animationFrame <= 0) {
-				_animationFrame = 0;
-				*animation = _animationNext;
-				_animationState = _animationStateNext;
-			}
-		} else {
-			_animationFrame += 3;
-			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(19)) {
-				_animationFrame = 0;
-				*animation = _animationNext;
-				_animationState = _animationStateNext;
+			_animationState = 0;
+			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNRxxSitAtTable) {
+				Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyNRxxStandUp);
 			}
 		}
 		break;
-	case 12:
-		*animation = 27;
+
+	case 62:
+		*animation = 42;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(27)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
+			_animationState = 63;
+			*animation = 43;
 		}
 		break;
-	case 11:
-		*animation = 26;
+
+	case 63:
+		*animation = 43;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(26)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
 		}
 		break;
-	case 10:
-		*animation = 25;
+
+	case 64:
+		*animation = 44;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(25)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
+			_animationState = 63;
+			*animation = 43;
 		}
 		break;
-	case 9:
-		*animation = 24;
+
+	case 65:
+		*animation = 45;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(24)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
+			_animationState = 14;
+			*animation = 0;
+			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
 		}
 		break;
-	case 8:
-		*animation = 23;
+
+	case 66:
+		*animation = 40;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(23)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			*animation = 19;
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
+			_animationState = 0;
 		}
 		break;
-	case 7:
-		*animation = 22;
+
+	case 67:
+		*animation = 53;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(22)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			*animation = 19;
+			_animationState = 0;
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
+			if (Actor_Query_Goal_Number(kActorMcCoy) == kGoalMcCoyNR04Drink) {
+				Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeDie);
+			}
 		}
 		break;
-	case 6:
-		*animation = 27;
-		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(27)) {
+
+	case 68:
+		*animation = 18;
+		v7 = Slice_Animation_Query_Number_Of_Frames(*animation) - 1 - Global_Variable_Query(kVariableNR01GetUpCounter);
+		if (_animationFrame < v7) {
+			_animationFrame++;
+		} else if (_animationFrame > v7) {
+			_animationFrame--;
+		}
+		if (_animationFrame <= 0) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
+			*animation = 19;
+			_animationState = 0;
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
+			Game_Flag_Reset(kFlagNR01McCoyIsDrugged);
+			Scene_Exits_Enable();
+			Player_Set_Combat_Mode_Access(true);
+			Actor_Set_Goal_Number(kActorMcCoy, kGoalMcCoyDefault);
 		}
 		break;
-	case 5:
-		*animation = 21;
+
+	case 69:
+		*animation = 50;
+		_animationFrame++;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeSit);
+			*animation = 51;
+		}
+		break;
+
+	case 70:
+		*animation = 51;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(21)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
-			_animationState = 3;
-			*animation = 20;
 		}
 		break;
-	case 3:
-	case 4:
-		if (_animationFrame == 0 && !Game_Flag_Query(kFlagMcCoyAnimation1)) {
-			_animationFrame = 1;
-			_animationState = _animationStateNextSpecial;
-			*animation = _animationNextSpecial;
-			_animationStateNextSpecial = 4;
-			_animationNextSpecial = 20;
-		} else if (_animationFrame <= 4 && Game_Flag_Query(kFlagMcCoyAnimation1)) {
-			Game_Flag_Reset(kFlagMcCoyAnimation1);
+
+	case 71:
+		*animation = 52;
+		_animationFrame++;
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
+			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeIdle);
 			*animation = 19;
 			_animationFrame = 0;
 			_animationState = 0;
-		} else {
-			*animation = 20;
-			_animationFrame++;
-			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(20)) {
-				_animationFrame = 0;
-			}
-		}
-		break;
-	case 0:
-		*animation = 19;
-		if (dword_45A0D8 < dword_45A0DC) {
-			//*frame = dword_45A0E8;
-			_animationFrame += _animationFrameDelta;
-			if (_animationFrame > dword_45A0E8) {
-				_animationFrame = dword_45A0E8;
-				_animationFrameDelta = -1;
-			} else if (_animationFrame < dword_45A0E4) {
-				_animationFrame = dword_45A0E4;
-				_animationFrameDelta = 1;
-			}
-			dword_45A0D8++;
-		} else {
-			_animationFrame += _animationFrameDelta;
-			dword_45A0DC = 0;
-			if (_animationFrame == 18 && Random_Query(0, 2)) {
-				_animationFrameDelta = -1;
-				dword_45A0D8 = 0;
-				dword_45A0E4 = 14;
-				dword_45A0E8 = 18;
-				dword_45A0DC = Random_Query(0, 30);
-			}
-			if (_animationFrame == 26) {
-				if (Random_Query(0, 2)) {
-					_animationFrameDelta = -1;
-					dword_45A0D8 = 0;
-					dword_45A0E4 = 23;
-					dword_45A0E8 = 26;
-					dword_45A0DC = Random_Query(0, 30);
-				}
-			}
-			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(19)) {
-				_animationFrame = 0;
-				if (Random_Query(0, 2)) {
-					dword_45A0D8 = 0;
-					dword_45A0E4 = 0;
-					dword_45A0E8 = 3;
-					dword_45A0DC = Random_Query(0, 45);
-				}
-			}
-			if (_animationFrame < 0) {
-				_animationFrame = Slice_Animation_Query_Number_Of_Frames(19) - 1;
-			}
+			Player_Gains_Control();
 		}
 		break;
 	}
@@ -1314,16 +1362,7 @@ bool AIScriptMcCoy::ChangeAnimationMode(int mode) {
 	case kAnimationModeIdle:
 		if (Game_Flag_Query(kFlagMcCoyTiedDown)) {
 			if (_animationFrame <= 6) {
-				int random = Random_Query(0, 2);
-				int soundId = 0;
-				if (random == 0) {
-					soundId = 595;
-				} else if (random == 1) {
-					soundId = 594;
-				} else if (random == 2) {
-					soundId = 593;
-				}
-				Ambient_Sounds_Play_Sound(soundId, 39, 0, 0, 99);
+				Ambient_Sounds_Play_Sound(Random_Query(593, 595), 39, 0, 0, 99);
 			}
 			_animationState = 57;
 			_animationFrame = 0;
@@ -1341,11 +1380,11 @@ bool AIScriptMcCoy::ChangeAnimationMode(int mode) {
 		case 11:
 		case 12:
 			Game_Flag_Set(kFlagMcCoyAnimation1);
-			dword_45A0D8 = 0;
-			dword_45A0DC = 30;
-			dword_45A0E4 = 0;
-			_animationFrameDelta = 1;
-			dword_45A0E8 = 3;
+			_animationLoopCounter = 0;
+			_animationLoopLength = 30;
+			_animationLoopFrameMin = 0;
+			_animationLoopDirection = 1;
+			_animationLoopFrameMax = 3;
 			return true;
 		case 14:
 		case 17:
@@ -1370,7 +1409,7 @@ bool AIScriptMcCoy::ChangeAnimationMode(int mode) {
 		default:
 			_animationState = 0;
 			_animationFrame = 0;
-			dword_45A0DC = 0;
+			_animationLoopLength = 0;
 			return true;
 		}
 		break;
@@ -1663,12 +1702,12 @@ bool AIScriptMcCoy::ChangeAnimationMode(int mode) {
 		_animationFrame = 0;
 		break;
 
-	case 41:
+	case kAnimationModeSpinnerGetIn:
 		_animationState = 45;
 		_animationFrame = 0;
 		break;
 
-	case 42:
+	case kAnimationModeSpinnerGetOut:
 		_animationState = 46;
 		_animationFrame = 0;
 		Player_Loses_Control();
@@ -1751,7 +1790,7 @@ bool AIScriptMcCoy::ChangeAnimationMode(int mode) {
 	case 68:
 		_animationState = 29;
 		_animationFrame = Slice_Animation_Query_Number_Of_Frames(18) - 1;
-		_animationFrameDelta = -1;
+		_animationLoopDirection = -1;
 		break;
 	case 75:
 		_animationState = 67;
@@ -1826,110 +1865,6 @@ void AIScriptMcCoy::UG15fall() {
 	}
 }
 
-void AIScriptMcCoy::sub_405660() {
-	if (Game_Flag_Query(kFlagMcCoyTiedDown)) {
-		if (_animationFrame <= 6) {
-			int v1 = Random_Query(0, 2);
-			int v2 = 0;
-			if (v1 == 0) {
-				v2 = 595;
-			} else if (v1 == 1) {
-				v2 = 594;
-			} else if (v1 == 2) {
-				v2 = 593;
-			}
-			Ambient_Sounds_Play_Sound(v2, 39, 0, 0, 99);
-		}
-		_animationState = 57;
-		_animationFrame = 0;
-		return;
-	}
-	switch (_animationState) {
-	case 3:
-	case 4:
-	case 5:
-	case 6:
-	case 7:
-	case 8:
-	case 9:
-	case 10:
-	case 11:
-	case 12:
-		Game_Flag_Set(kFlagMcCoyAnimation1);
-		dword_45A0D8 = 0;
-		dword_45A0DC = 30;
-		dword_45A0E4 = 0;
-		_animationFrameDelta = 1;
-		dword_45A0E8 = 3;
-		break;
-	case 14:
-		_animationState = 16;
-		_animationFrame = 0;
-		break;
-	case 15:
-		_animationState = 16;
-		_animationFrame = 16 - 16 * _animationFrame / 12;
-		break;
-	case 17:
-	case 20:
-	case 21:
-	case 36:
-		_animationState = 16;
-		_animationFrame = 0;
-		break;
-	case 16:
-	case 25:
-	case 26:
-		break;
-	case 60:
-		_animationState = 61;
-		break;
-	default:
-		_animationState = 0;
-		_animationFrame = 0;
-		dword_45A0DC = 0;
-	}
-}
-
-void AIScriptMcCoy::sub_405800() {
-	switch (_animationState) {
-	case 36:
-	case 37:
-	case 40:
-	case 41:
-	case 51:
-		_animationState = 14;
-		_animationFrame = 0;
-		break;
-	case 22:
-		_animationState = 19;
-		_animationFrame = 41;
-		break;
-	case 18:
-		_animationState = 19;
-		_animationFrame = 13 * ((8 - _animationFrame) / 8);
-		break;
-	case 17:
-	case 20:
-		_animationState = 19;
-		_animationFrame = 0;
-		break;
-	case 16:
-		_animationFrame = 12 - 12 * _animationFrame / 16;
-		_animationState = 15;
-		break;
-	case 14:
-	case 15:
-	case 19:
-	case 21:
-		break;
-	default:
-		_animationState = 15;
-		_animationFrame = 0;
-		break;
-	}
-}
-
 void AIScriptMcCoy::dodge() {
 	int setId = Actor_Query_Which_Set_In(kActorMcCoy);
 	if (setId == kSetCT02) {
@@ -1943,34 +1878,32 @@ void AIScriptMcCoy::dodge() {
 	}
 }
 
-void AIScriptMcCoy::sub_405940(float a1) {
+void AIScriptMcCoy::walkStairsLeft(float stepHeight) {
 	float x, y, z;
 	int currentAngle = Actor_Query_Facing_1024(kActorMcCoy);
 	Actor_Query_XYZ(kActorMcCoy, &x, &y, &z);
 	int angle = currentAngle - 12;
-	y = y + a1;
 	if (angle < 0) {
 		angle = currentAngle + 1012;
 	}
 	if (angle > 1023) {
 		angle -= 1024;
 	}
-	Actor_Set_At_XYZ(kActorMcCoy, x, y, z, angle);
+	Actor_Set_At_XYZ(kActorMcCoy, x, y + stepHeight, z, angle);
 }
 
-void AIScriptMcCoy::sub_4059D0(float a1) {
+void AIScriptMcCoy::walkStairsRight(float stepHeight) {
 	float x, y, z;
 	int currentAngle = Actor_Query_Facing_1024(kActorMcCoy);
 	Actor_Query_XYZ(kActorMcCoy, &x, &y, &z);
 	int angle = currentAngle + 15;
-	y = y + a1;
 	if (angle < 0) {
 		angle = currentAngle + 1039;
 	}
 	if (angle > 1023) {
 		angle -= 1024;
 	}
-	return Actor_Set_At_XYZ(kActorMcCoy, x, y, z, angle);
+	return Actor_Set_At_XYZ(kActorMcCoy, x, y + stepHeight, z, angle);
 }
 
 } // End of namespace BladeRunner
diff --git a/engines/bladerunner/script/ai_script.h b/engines/bladerunner/script/ai_script.h
index 6c857da..7710288 100644
--- a/engines/bladerunner/script/ai_script.h
+++ b/engines/bladerunner/script/ai_script.h
@@ -96,12 +96,11 @@ private:
 #define END_SCRIPT };
 
 DECLARE_SCRIPT(McCoy)
-	int dword_45A0D8;
-	int dword_45A0DC;
-	int _animationFrameDelta;
-	int dword_45A0E4;
-	float off_45A0EC;
-	int dword_45A0E8;
+	int _animationLoopCounter;
+	int _animationLoopLength;
+	int _animationLoopDirection;
+	int _animationLoopFrameMin;
+	int _animationLoopFrameMax;
 	int _animationStateNextSpecial;
 	int _animationNextSpecial;
 	int _nextSoundId;
@@ -112,11 +111,9 @@ DECLARE_SCRIPT(McCoy)
 
 	void fallDown();
 	void UG15fall();
-	void sub_405660();
-	void sub_405800();
 	void dodge();
-	void sub_405940(float a1);
-	void sub_4059D0(float a1);
+	void walkStairsLeft(float stepHeight);
+	void walkStairsRight(float stepHeight);
 END_SCRIPT
 
 DECLARE_SCRIPT(Steele)


Commit: 00b83c2ff7a0738b7811a06459145a758bc12871
    https://github.com/scummvm/scummvm/commit/00b83c2ff7a0738b7811a06459145a758bc12871
Author: Peter Kohaut (peter.kohaut at gmail.com)
Date: 2019-02-23T11:39:55+01:00

Commit Message:
BLADERUNNER: Cleanup of Zuben script

Changed paths:
    engines/bladerunner/script/ai/zuben.cpp
    engines/bladerunner/script/ai_script.h


diff --git a/engines/bladerunner/script/ai/zuben.cpp b/engines/bladerunner/script/ai/zuben.cpp
index 8e25da0..4428b90 100644
--- a/engines/bladerunner/script/ai/zuben.cpp
+++ b/engines/bladerunner/script/ai/zuben.cpp
@@ -25,21 +25,21 @@
 namespace BladeRunner {
 
 AIScriptZuben::AIScriptZuben(BladeRunnerEngine *vm) : AIScriptBase(vm) {
-	_var_45D258 = 0;
-	_var_45D25C = 0;
-	_animationFrameTarget2 = 0;
-	_animationFrameDelta = 0;
-	_animationFrameTarget1 = 0;
+	_animationLoopCounter = 0;
+	_animationLoopLength = 0;
+	_animationLoopFrameMin = 0;
+	_animationLoopDirection = 0;
+	_animationLoopFrameMax = 0;
 }
 
 void AIScriptZuben::Initialize() {
 	_animationState = 0;
 	_animationFrame = 0;
-	_var_45D258 = 0;
-	_var_45D25C = 30;
-	_animationFrameTarget2 = 0;
-	_animationFrameDelta = 1;
-	_animationFrameTarget1 = 2;
+	_animationLoopCounter = 0;
+	_animationLoopLength = 30;
+	_animationLoopFrameMin = 0;
+	_animationLoopDirection = 1;
+	_animationLoopFrameMax = 2;
 	Actor_Put_In_Set(kActorZuben, kSetCT01_CT12);
 	Actor_Set_At_XYZ(kActorZuben, -165.01f, -6.5f, 413.12f, 103);
 	Actor_Set_Goal_Number(kActorZuben, kGoalZubenDefault);
@@ -637,46 +637,50 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 	case 0:
 		if (Actor_Query_Goal_Number(kActorZuben) != kGoalZubenDefault) {
 			*animation = 408;
-			if (_var_45D258 < _var_45D25C) {
-				_animationFrame += _animationFrameDelta;
-				if (_animationFrame > _animationFrameTarget1) {
-					_animationFrame = _animationFrameTarget1;
-					_animationFrameDelta = -1;
-				} else if (_animationFrame < _animationFrameTarget2) {
-					_animationFrame = _animationFrameTarget2;
-					_animationFrameDelta = 1;
+			if (_animationLoopCounter < _animationLoopLength) {
+				_animationFrame += _animationLoopDirection;
+				if (_animationFrame > _animationLoopFrameMax) {
+					_animationFrame = _animationLoopFrameMax;
+					_animationLoopDirection = -1;
+				} else if (_animationFrame < _animationLoopFrameMin) {
+					_animationFrame = _animationLoopFrameMin;
+					_animationLoopDirection = 1;
 				}
-				_var_45D258++;
+				_animationLoopCounter++;
 			} else {
-				_animationFrame += _animationFrameDelta;
-				_var_45D25C = 0;
+				_animationFrame += _animationLoopDirection;
+				_animationLoopLength = 0;
+
 				if (_animationFrame == 13 && Random_Query(0, 1)) {
-					_animationFrameDelta = -1;
-					_var_45D258 = 0;
-					_animationFrameTarget2 = 8;
-					_animationFrameTarget1 = 13;
-					_var_45D25C = Random_Query(0, 30);
+					_animationLoopDirection = -1;
+					_animationLoopCounter = 0;
+					_animationLoopFrameMin = 8;
+					_animationLoopFrameMax = 13;
+					_animationLoopLength = Random_Query(0, 30);
 				}
+
 				if (_animationFrame == 23) {
 					if (Random_Query(0, 1)) {
-						_animationFrameDelta = -1;
-						_var_45D258 = 0;
-						_animationFrameTarget2 = 20;
-						_animationFrameTarget1 = 23;
-						_var_45D25C = Random_Query(0, 30);
+						_animationLoopDirection = -1;
+						_animationLoopCounter = 0;
+						_animationLoopFrameMin = 20;
+						_animationLoopFrameMax = 23;
+						_animationLoopLength = Random_Query(0, 30);
 					}
 				}
-				if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(408)) {
+
+				if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 					_animationFrame = 0;
 					if (Random_Query(0, 1)) {
-						_var_45D258 = 0;
-						_animationFrameTarget2 = 0;
-						_animationFrameTarget1 = 2;
-						_var_45D25C = Random_Query(0, 45);
+						_animationLoopCounter = 0;
+						_animationLoopFrameMin = 0;
+						_animationLoopFrameMax = 2;
+						_animationLoopLength = Random_Query(0, 45);
 					}
 				}
+
 				if (_animationFrame < 0) {
-					_animationFrame = Slice_Animation_Query_Number_Of_Frames(408) - 1;
+					_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
 				}
 			}
 		} else {
@@ -688,38 +692,43 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			*frame = _animationFrame;
 		}
 		break;
+
 	case 1:
 		*animation = 399;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(399)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
 		break;
+
 	case 2:
 		*animation = 391;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(391)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
 		break;
+
 	case 3:
 		*animation = 400;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(400)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
 		break;
+
 	case 4:
 		*animation = 392;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(392)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
 		break;
+
 	case 5:
 		*animation = 396;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(396)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			if (Actor_Query_Goal_Number(kActorZuben) == kGoalZubenCT02PotDodgeCheck) {
 				_animationState = 8;
@@ -728,21 +737,24 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 		}
 		break;
+
 	case 6:
 		*animation = 397;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(397)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 0;
 		}
 		break;
+
 	case 7:
 		*animation = 388;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(388)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
 		break;
+
 	case 8:
 		*animation = 398;
 		_animationFrame++;
@@ -755,10 +767,12 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 			Sound_Play_Speech_Line(kActorZuben, sentenceId, 75, 0, 99);
 		}
+
 		if (_animationFrame == 11) {
 			Actor_Combat_AI_Hit_Attempt(kActorZuben);
 		}
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(398)) {
+
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			if (Actor_Query_Goal_Number(kActorZuben) == kGoalZubenCT02PotDodgeCheck) {
 				Actor_Set_Goal_Number(kActorZuben, kGoalZubenCT02RunToDoor);
 				_animationFrame = 0;
@@ -771,10 +785,11 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 		}
 		break;
+
 	case 9:
 		*animation = 403;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(403)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			if (Actor_Query_Goal_Number(kActorZuben) == 99) {
 				_animationFrame = 0;
 				_animationState = 13;
@@ -788,10 +803,11 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 		}
 		break;
+
 	case 10:
 		*animation = 404;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(404)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			if (Actor_Query_Goal_Number(kActorZuben) == 99) {
 				_animationFrame = 0;
 				_animationState = 13;
@@ -805,10 +821,11 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 		}
 		break;
+
 	case 11:
 		*animation = 389;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(389)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			if (Actor_Query_Goal_Number(kActorZuben) == 99) {
 				_animationFrame = 0;
 				_animationState = 14;
@@ -822,10 +839,11 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 		}
 		break;
+
 	case 12:
 		*animation = 390;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(390)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			if (Actor_Query_Goal_Number(kActorZuben) == 99) {
 				_animationFrame = 0;
 				_animationState = 14;
@@ -839,6 +857,7 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			}
 		}
 		break;
+
 	case 13:
 		*animation = 405;
 		_animationFrame++;
@@ -852,6 +871,7 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			Actor_Set_Targetable(kActorZuben, false);
 		}
 		break;
+
 	case 14:
 		*animation = 393;
 		_animationFrame++;
@@ -862,102 +882,114 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			Actor_Set_Goal_Number(kActorZuben, kGoalZubenDie);
 			_animationState = 16;
 			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
-			Actor_Set_Targetable(kActorZuben, 0);
+			Actor_Set_Targetable(kActorZuben, false);
 		}
 		break;
+
 	case 15:
 		*animation = 405;
-		_animationFrame = Slice_Animation_Query_Number_Of_Frames(405) - 1;
+		_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
 		Scene_Exits_Enable();
 		break;
+
 	case 16:
 		*animation = 393;
-		_animationFrame = Slice_Animation_Query_Number_Of_Frames(393) - 1;
+		_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
 		break;
+
 	case 17:
 		*animation = 409;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(409)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 		}
 		break;
+
 	case 18:
 		*animation = 410;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(410)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 19:
 		*animation = 411;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(411)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 20:
 		*animation = 412;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(412)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 21:
 		*animation = 413;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(413)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 22:
 		*animation = 414;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(414)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 23:
 		*animation = 415;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(415)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 24:
 		*animation = 416;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(416)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 25:
 		*animation = 417;
 		 _animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(417)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 17;
 			*animation = 409;
 		}
 		break;
+
 	case 26:
 		Actor_Set_Frame_Rate_FPS(kActorZuben, -1);
 		*animation = 419;
 		_animationFrame++;
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(419)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			// Time for McCoy to react and avoid tipping pot
 			Actor_Set_Frame_Rate_FPS(kActorZuben, -2);
 			_animationState = 0;
@@ -965,6 +997,7 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 			Actor_Set_Goal_Number(kActorZuben, kGoalZubenCT02PotDodgeCheck);
 		}
 		break;
+
 	case 27:  // Opening the door
 		Actor_Set_Frame_Rate_FPS(kActorZuben, -1);
 		*animation = 420;
@@ -975,26 +1008,28 @@ bool AIScriptZuben::UpdateAnimation(int *animation, int *frame) {
 		if (_animationFrame == 6) {
 			Sound_Play(201, 40, 0, 0, 50);
 		}
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(420)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			Actor_Set_Frame_Rate_FPS(kActorZuben, -2);
 			_animationState = 0;
 			_animationFrame = 0;
 			Actor_Set_Goal_Number(kActorZuben, kGoalZubenCT02RunToFreeSlotG);
 		}
 		break;
+
 	case 28:
 		*animation = 421;
 		_animationFrame++;
 		if (_animationFrame == 1) {
 			Sound_Play(206, 80, 0, 0, 50);
 		}
-		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(421)) {
+		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
 			_animationFrame = 0;
 			_animationState = 5;
 			*animation = 396;
 			Actor_Set_Goal_Number(kActorZuben, kGoalZubenCT06AttackMcCoy);
 		}
 		break;
+
 	default:
 		*animation = 399;
 		break;
diff --git a/engines/bladerunner/script/ai_script.h b/engines/bladerunner/script/ai_script.h
index 7710288..edbe5f6 100644
--- a/engines/bladerunner/script/ai_script.h
+++ b/engines/bladerunner/script/ai_script.h
@@ -248,11 +248,11 @@ DECLARE_SCRIPT(EarlyQ)
 END_SCRIPT
 
 DECLARE_SCRIPT(Zuben)
-	int _var_45D258;
-	int _var_45D25C;
-	int _animationFrameTarget2;
-	int _animationFrameDelta;
-	int _animationFrameTarget1;
+	int _animationLoopCounter;
+	int _animationLoopLength;
+	int _animationLoopFrameMin;
+	int _animationLoopDirection;
+	int _animationLoopFrameMax;
 
 	void dialogue();
 END_SCRIPT





More information about the Scummvm-git-logs mailing list