Skip to content

Commit

Permalink
BLADERUNNER: Remove simple walking hack
Browse files Browse the repository at this point in the history
Rename previously unnamed walking parameter 'interruptible'
  • Loading branch information
madmoose committed Jan 29, 2018
1 parent a4229c9 commit 270b691
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 129 deletions.
184 changes: 81 additions & 103 deletions engines/bladerunner/actor.cpp
Expand Up @@ -314,7 +314,7 @@ void Actor::movementTrackUnpause() {

void Actor::movementTrackWaypointReached() {
int seconds;
if (!_movementTrack->isPaused() && _id != 0) {
if (!_movementTrack->isPaused() && _id != kActorMcCoy) {
if (_movementTrackWalkingToWaypointId >= 0 && _movementTrackDelayOnNextWaypoint) {
if (!_movementTrackDelayOnNextWaypoint) {
_movementTrackDelayOnNextWaypoint = 1;
Expand Down Expand Up @@ -358,112 +358,90 @@ void Actor::setAtWaypoint(int waypointId, int angle, int moving, bool retired) {
setAtXYZ(waypointPosition, angle, true, moving, retired);
}

bool Actor::loopWalk(const Vector3 &destination, int destinationOffset, bool a3, bool run, const Vector3 &start, float targetWidth, float targetSize, bool a8, bool *flagIsRunning, bool async) {
if (true) { // simple walking
*flagIsRunning = false;
bool arrived;
_walkInfo->setup(_id, false, _position, destination, false, &arrived);
bool Actor::loopWalk(const Vector3 &destination, int destinationOffset, bool interruptible, bool run, const Vector3 &start, float targetWidth, float targetSize, bool a8, bool *flagIsRunning, bool async) {
*flagIsRunning = false;

if (async) {
if (destinationOffset > 0) {
float dist = distance(_position, destination);
if (dist - targetSize <= destinationOffset) {
return false;
}
while (true) {
_vm->gameTick();
if (!_walkInfo->isWalking() && !_walkInfo->isRunning()) {
break;
}
if (!_vm->_gameIsRunning) {
break;
}
}
return false;
} else {
//TODO:
// original code, not yet working
*flagIsRunning = false;

if (destinationOffset > 0) {
float dist = distance(_position, destination);
if (dist - targetSize <= destinationOffset) {
return false;
}
}
}

if (a8 && !async && _id && destinationOffset <= 24) {
if (distance(_vm->_playerActor->_position, destination) <= 24.0f) {
_vm->_playerActor->walkToNearestPoint(destination, 48.0f);
}
if (a8 && !async && _id != kActorMcCoy && destinationOffset <= 24) {
if (distance(_vm->_playerActor->_position, destination) <= 24.0f) {
_vm->_playerActor->walkToNearestPoint(destination, 48.0f);
}
}

if (_id) {
a3 = false;
}
if (_id != kActorMcCoy) {
interruptible = false;
}

Vector3 destinationX(destination);
Vector3 destinationX(destination);

if (destinationOffset > 0) {
walkFindU2(&destinationX, targetWidth, destinationOffset, targetSize, _position, destination);
}
if (destinationOffset > 0) {
walkFindU2(&destinationX, targetWidth, destinationOffset, targetSize, _position, destination);
}

bool walking = walkTo(run, destinationX, a8);
bool walking = walkTo(run, destinationX, a8);

if (async) {
return false;
}
if (async) {
return false;
}

if (!walking && destinationOffset > 0) {
walking = walkTo(run, destination, a8);
}
if (!walking && destinationOffset > 0) {
walking = walkTo(run, destination, a8);
}

if (!walking) {
return false;
}
if (!walking) {
faceXYZ(destination.x, destination.y, destination.z, false);
return false;
}

if (async) {
return false;
}
if (_id) {
_vm->_mouse->disable();
}
if (a3) {
// TODO:
// dword_482990 = 1;
// dword_482994 = 0;
} else {
_vm->playerLosesControl();
}
if (async) {
return false;
}
if (_id != kActorMcCoy) {
_vm->_mouse->disable();
}
if (interruptible) {
_vm->_isWalkingInterruptible = 1;
_vm->_interruptWalking = 0;
} else {
_vm->playerLosesControl();
}

if (a8) {
_inWalkLoop = true;
}
if (a8) {
_inWalkLoop = true;
}

bool v46 = false;
while (_walkInfo->isWalking() && _vm->_gameIsRunning) {
if (_walkInfo->isRunning()) {
*flagIsRunning = true;
}
_vm->gameTick();
if (_id == 0 && a3 /*&& dword_482994*/) {
stopWalking(false);
v46 = true;
}
}
if (a8) {
_inWalkLoop = false;
}
if (a3) {
// dword_482990 = 1;
} else {
_vm->playerGainsControl();
}
if (!v46 && destinationOffset == 0 /* && !PlayerActorIdle*/) {
setAtXYZ(destination, _facing, true, false, false);
bool wasInterrupted = false;
while (_walkInfo->isWalking() && _vm->_gameIsRunning) {
if (_walkInfo->isRunning()) {
*flagIsRunning = true;
}
if (_id) {
_vm->_mouse->enable();
_vm->gameTick();
if (_id == kActorMcCoy && interruptible && _vm->_interruptWalking) {
stopWalking(false);
wasInterrupted = true;
}
return v46;
}
if (a8) {
_inWalkLoop = false;
}
if (interruptible) {
_vm->_isWalkingInterruptible = false;
} else {
_vm->playerGainsControl();
}
if (!wasInterrupted && destinationOffset == 0 && !_vm->_playerActorIdle) {
setAtXYZ(destination, _facing, true, false, false);
}
if (_id != kActorMcCoy) {
_vm->_mouse->enable();
}
return wasInterrupted;
}

bool Actor::walkTo(bool run, const Vector3 &destination, bool a3) {
Expand All @@ -472,21 +450,21 @@ bool Actor::walkTo(bool run, const Vector3 &destination, bool a3) {
return _walkInfo->setup(_id, run, _position, destination, a3, &arrived);
}

bool Actor::loopWalkToActor(int otherActorId, int destinationOffset, int a3, bool run, bool a5, bool *flagIsRunning) {
return loopWalk(_vm->_actors[otherActorId]->_position, destinationOffset, a3, run, _position, 24.0f, 24.0f, a5, flagIsRunning, false);
bool Actor::loopWalkToActor(int otherActorId, int destinationOffset, int interruptible, bool run, bool a5, bool *flagIsRunning) {
return loopWalk(_vm->_actors[otherActorId]->_position, destinationOffset, interruptible, run, _position, 24.0f, 24.0f, a5, flagIsRunning, false);
}

bool Actor::loopWalkToItem(int itemId, int destinationOffset, int a3, bool run, bool a5, bool *flagIsRunning) {
bool Actor::loopWalkToItem(int itemId, int destinationOffset, int interruptible, bool run, bool a5, bool *flagIsRunning) {
float x, y, z;
int width, height;
_vm->_items->getXYZ(itemId, &x, &y, &z);
_vm->_items->getWidthHeight(itemId, &width, &height);
Vector3 itemPosition(x, y, z);

return loopWalk(itemPosition, destinationOffset, a3, run, _position, width, 24.0f, a5, flagIsRunning, false);
return loopWalk(itemPosition, destinationOffset, interruptible, run, _position, width, 24.0f, a5, flagIsRunning, false);
}

bool Actor::loopWalkToSceneObject(const char *objectName, int destinationOffset, bool a3, bool run, bool a5, bool *flagIsRunning) {
bool Actor::loopWalkToSceneObject(const char *objectName, int destinationOffset, bool interruptible, bool run, bool a5, bool *flagIsRunning) {
int sceneObject = _vm->_scene->_set->findObject(objectName);
if (sceneObject < 0) {
return true;
Expand Down Expand Up @@ -528,17 +506,17 @@ bool Actor::loopWalkToSceneObject(const char *objectName, int destinationOffset,
float y = _vm->_scene->_set->getAltitudeAtXZ(closestX, closestZ, &inWalkbox);
Vector3 destination(closestX, y, closestZ);

return loopWalk(destination, destinationOffset, a3, run, _position, 0.0f, 24.0f, a5, flagIsRunning, false);
return loopWalk(destination, destinationOffset, interruptible, run, _position, 0.0f, 24.0f, a5, flagIsRunning, false);
}

bool Actor::loopWalkToWaypoint(int waypointId, int destinationOffset, int a3, bool run, bool a5, bool *flagIsRunning) {
bool Actor::loopWalkToWaypoint(int waypointId, int destinationOffset, int interruptible, bool run, bool a5, bool *flagIsRunning) {
Vector3 waypointPosition;
_vm->_waypoints->getXYZ(waypointId, &waypointPosition.x, &waypointPosition.y, &waypointPosition.z);
return loopWalk(waypointPosition, destinationOffset, a3, run, _position, 0.0f, 24.0f, a5, flagIsRunning, false);
return loopWalk(waypointPosition, destinationOffset, interruptible, run, _position, 0.0f, 24.0f, a5, flagIsRunning, false);
}

bool Actor::loopWalkToXYZ(const Vector3 &destination, int destinationOffset, bool a3, bool run, bool a5, bool *flagIsRunning) {
return loopWalk(destination, destinationOffset, a3, run, _position, 0.0f, 24.0f, a5, flagIsRunning, false);
bool Actor::loopWalkToXYZ(const Vector3 &destination, int destinationOffset, bool interruptible, bool run, bool a5, bool *flagIsRunning) {
return loopWalk(destination, destinationOffset, interruptible, run, _position, 0.0f, 24.0f, a5, flagIsRunning, false);
}

bool Actor::asyncWalkToWaypoint(int waypointId, int destinationOffset, bool run, bool a5) {
Expand Down Expand Up @@ -581,7 +559,7 @@ bool Actor::tick(bool forceDraw, Common::Rect *screenRect) {
Vector3 positionChange = _vm->_sliceAnimations->getPositionChange(_animationId);
float angleChange = _vm->_sliceAnimations->getFacingChange(_animationId);

if (_id == 47) {
if (_id == kActorHysteriaPatron1) {
positionChange.x = 0.0f;
positionChange.y = 0.0f;
positionChange.z = 0.0f;
Expand Down Expand Up @@ -797,7 +775,7 @@ bool Actor::isRunning() const {
}

void Actor::stopWalking(bool value) {
if (value && _id == 0) {
if (value && _id == kActorMcCoy) {
_vm->_playerActorIdle = true;
}

Expand Down Expand Up @@ -949,7 +927,7 @@ void Actor::retire(bool retired, int width, int height, int retiredByActorId) {
_isRetired = retired;
_retiredWidth = MAX(width, 0);
_retiredHeight = MAX(height, 0);
if (_id == 0 && _isRetired) {
if (_id == kActorMcCoy && _isRetired) {
_vm->playerLosesControl();
_vm->_playerDead = true;
}
Expand All @@ -975,7 +953,7 @@ void Actor::combatModeOn(int a2, int a3, int otherActorId, int a5, int animation
_animationModeCombatWalk = animationModeCombatWalk;
_animationModeCombatRun = animationModeCombatRun;
_inCombat = true;
if (_id > 0)
if (_id != kActorMcCoy)
_combatInfo->combatOn(_id, a2, a3, otherActorId, a5, a9, a10, a11, ammoDamage, a13, a14);
stopWalking(false);
changeAnimationMode(_animationModeCombatIdle, false);
Expand Down
14 changes: 7 additions & 7 deletions engines/bladerunner/actor.h
Expand Up @@ -143,11 +143,11 @@ class Actor {
void movementTrackUnpause();
void movementTrackWaypointReached();

bool loopWalkToActor(int otherActorId, int destinationOffset, int a3, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToItem(int itemId, int destinationOffset, int a3, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToSceneObject(const char *objectName, int destinationOffset, bool a3, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToWaypoint(int waypointId, int destinationOffset, int a3, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToXYZ(const Vector3 &destination, int destinationOffset, bool a3, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToActor(int otherActorId, int destinationOffset, int interruptible, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToItem(int itemId, int destinationOffset, int interruptible, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToSceneObject(const char *objectName, int destinationOffset, bool interruptible, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToWaypoint(int waypointId, int destinationOffset, int interruptible, bool run, bool a5, bool *flagIsRunning);
bool loopWalkToXYZ(const Vector3 &destination, int destinationOffset, bool interruptible, bool run, bool a5, bool *flagIsRunning);
bool asyncWalkToWaypoint(int waypointId, int destinationOffset, bool run, bool a5);
void asyncWalkToXYZ(const Vector3 &destination, int destinationOffset, bool run, int a6);

Expand Down Expand Up @@ -223,8 +223,8 @@ class Actor {
void setFacing(int facing, bool halfOrSet = true);
void setBoundingBox(const Vector3 &position, bool retired);
float distanceFromView(View *view) const;
bool loopWalk(const Vector3 &destination, int destinationOffset, bool a3, bool run, const Vector3 &start, float a6, float a7, bool a8, bool *isRunning, bool async);

bool loopWalk(const Vector3 &destination, int destinationOffset, bool interruptible, bool run, const Vector3 &start, float a6, float a7, bool a8, bool *isRunning, bool async);
bool walkTo(bool run, const Vector3 &destination, bool a3);

bool walkFindU1(const Vector3 &startPosition, const Vector3 &targetPosition, float a3, Vector3 *newDestination);
Expand Down
5 changes: 4 additions & 1 deletion engines/bladerunner/bladerunner.cpp
Expand Up @@ -629,7 +629,10 @@ bool BladeRunnerEngine::init2() {
}

Common::Point BladeRunnerEngine::getMousePos() const {
return _eventMan->getMousePos();
Common::Point p = _eventMan->getMousePos();
p.x = CLIP(p.x, int16(0), int16(639));
p.y = CLIP(p.y, int16(0), int16(479));
return p;
}

void BladeRunnerEngine::gameLoop() {
Expand Down
2 changes: 2 additions & 0 deletions engines/bladerunner/bladerunner.h
Expand Up @@ -171,6 +171,8 @@ class BladeRunnerEngine : public Engine {

Common::RandomSource _rnd;

bool _isWalkingInterruptible;
bool _interruptWalking;
bool _playerActorIdle;
bool _playerDead;
bool _speechSkipped;
Expand Down

0 comments on commit 270b691

Please sign in to comment.