[Scummvm-git-logs] scummvm master -> 384a1753f6ed1e0ef47a2e0cf3973bc2e5beecb6

mduggan mgithub at guarana.org
Mon May 18 00:31:10 UTC 2020


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

Summary:
384a1753f6 ULITIMA8: Improve basic avatar keyboard movement.


Commit: 384a1753f6ed1e0ef47a2e0cf3973bc2e5beecb6
    https://github.com/scummvm/scummvm/commit/384a1753f6ed1e0ef47a2e0cf3973bc2e5beecb6
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2020-05-18T09:31:06+09:00

Commit Message:
ULITIMA8: Improve basic avatar keyboard movement.

Changed paths:
    engines/ultima/ultima8/meta_engine.cpp
    engines/ultima/ultima8/misc/debugger.cpp
    engines/ultima/ultima8/misc/debugger.h
    engines/ultima/ultima8/world/actors/avatar_mover_process.cpp
    engines/ultima/ultima8/world/actors/avatar_mover_process.h


diff --git a/engines/ultima/ultima8/meta_engine.cpp b/engines/ultima/ultima8/meta_engine.cpp
index 86b57ade63..d57572ac54 100644
--- a/engines/ultima/ultima8/meta_engine.cpp
+++ b/engines/ultima/ultima8/meta_engine.cpp
@@ -56,10 +56,10 @@ static const KeybindingRecord KEYS[] = {
 		"GameMapGump::toggleHighlightItems", "TAB", nullptr },
 	{ ACTION_TOGGLE_TOUCHING, "TOUCHING", "Show Touching Items", "GUIApp::toggleShowTouchingItems", nullptr, "h", nullptr },
 	{ ACTION_JUMP, "JUMP", "Jump (fake both-button-click)", "AvatarMoverProcess::setFakeBothButtonClick", nullptr, "SPACE", nullptr },
-	{ ACTION_TURN_LEFT, "TURN_LEFT", "Turn Left", "AvatarMoverProcess::turnLeft", nullptr, "LEFT", nullptr },
-	{ ACTION_TURN_RIGHT, "TURN_RIGHT", "Turn Right", "AvatarMoverProcess::turnRight", nullptr, "RIGHT", nullptr },
-	{ ACTION_MOVE_FORWARD, "MOVE_FORWARD", "Move Forward", "AvatarMoverProcess::moveForward", nullptr, "UP", nullptr },
-	{ ACTION_MOVE_BACK, "MOVE_BACK", "Move Back", "AvatarMoverProcess::moveBack", nullptr, "DOWN", nullptr },
+	{ ACTION_TURN_LEFT, "TURN_LEFT", "Turn Left", "AvatarMoverProcess::startTurnLeft", "AvatarMoverProcess::stopTurnLeft", "LEFT", nullptr },
+	{ ACTION_TURN_RIGHT, "TURN_RIGHT", "Turn Right", "AvatarMoverProcess::startTurnRight", "AvatarMoverProcess::stopTurnRight", "RIGHT", nullptr },
+	{ ACTION_MOVE_FORWARD, "MOVE_FORWARD", "Move Forward", "AvatarMoverProcess::startMoveForward", "AvatarMoverProcess::stopMoveForward", "UP", nullptr },
+	{ ACTION_MOVE_BACK, "MOVE_BACK", "Move Back", "AvatarMoverProcess::startMoveBack", "AvatarMoverProcess::stopMoveBack", "DOWN", nullptr },
 
 	{ ACTION_NONE, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }
 };
diff --git a/engines/ultima/ultima8/misc/debugger.cpp b/engines/ultima/ultima8/misc/debugger.cpp
index ed889dd03e..7267e808e3 100644
--- a/engines/ultima/ultima8/misc/debugger.cpp
+++ b/engines/ultima/ultima8/misc/debugger.cpp
@@ -83,10 +83,14 @@ Debugger::Debugger() : Shared::Debugger() {
 	registerCmd("Ultima8Engine::closeItemGumps", WRAP_METHOD(Debugger, cmdCloseItemGumps));
 
 	registerCmd("AvatarMoverProcess::setFakeBothButtonClick", WRAP_METHOD(Debugger, cmdBothButtonClick));
-	registerCmd("AvatarMoverProcess::turnLeft", WRAP_METHOD(Debugger, cmdTurnLeft));
-	registerCmd("AvatarMoverProcess::turnRight", WRAP_METHOD(Debugger, cmdTurnRight));
-	registerCmd("AvatarMoverProcess::moveForward", WRAP_METHOD(Debugger, cmdMoveForward));
-	registerCmd("AvatarMoverProcess::moveBack", WRAP_METHOD(Debugger, cmdMoveBack));
+	registerCmd("AvatarMoverProcess::startTurnLeft", WRAP_METHOD(Debugger, cmdStartTurnLeft));
+	registerCmd("AvatarMoverProcess::startTurnRight", WRAP_METHOD(Debugger, cmdStartTurnRight));
+	registerCmd("AvatarMoverProcess::startMoveForward", WRAP_METHOD(Debugger, cmdStartMoveForward));
+	registerCmd("AvatarMoverProcess::startMoveBack", WRAP_METHOD(Debugger, cmdStartMoveBack));
+	registerCmd("AvatarMoverProcess::stopTurnLeft", WRAP_METHOD(Debugger, cmdStopTurnLeft));
+	registerCmd("AvatarMoverProcess::stopTurnRight", WRAP_METHOD(Debugger, cmdStopTurnRight));
+	registerCmd("AvatarMoverProcess::stopMoveForward", WRAP_METHOD(Debugger, cmdStopMoveForward));
+	registerCmd("AvatarMoverProcess::stopMoveBack", WRAP_METHOD(Debugger, cmdStopMoveBack));
 
 	registerCmd("AudioProcess::listSFX", WRAP_METHOD(Debugger, cmdListSFX));
 	registerCmd("AudioProcess::playSFX", WRAP_METHOD(Debugger, cmdPlaySFX));
@@ -1111,7 +1115,7 @@ bool Debugger::cmdBothButtonClick(int argc, const char **argv) {
 	return false;
 }
 
-bool Debugger::cmdTurnLeft(int argc, const char **argv) {
+bool Debugger::cmdStartTurnLeft(int argc, const char **argv) {
 	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
 		debugPrintf("Can't turn left: avatarInStasis\n");
 		return false;
@@ -1119,12 +1123,12 @@ bool Debugger::cmdTurnLeft(int argc, const char **argv) {
 	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
 
 	if (proc) {
-		proc->tryTurnLeft();
+		proc->tryTurnLeft(true);
 	}
 	return false;
 }
 
-bool Debugger::cmdTurnRight(int argc, const char **argv) {
+bool Debugger::cmdStartTurnRight(int argc, const char **argv) {
 	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
 		debugPrintf("Can't turn right: avatarInStasis\n");
 		return false;
@@ -1132,12 +1136,12 @@ bool Debugger::cmdTurnRight(int argc, const char **argv) {
 	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
 
 	if (proc) {
-		proc->tryTurnRight();
+		proc->tryTurnRight(true);
 	}
 	return false;
 }
 
-bool Debugger::cmdMoveForward(int argc, const char **argv) {
+bool Debugger::cmdStartMoveForward(int argc, const char **argv) {
 	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
 		debugPrintf("Can't move forward: avatarInStasis\n");
 		return false;
@@ -1145,12 +1149,12 @@ bool Debugger::cmdMoveForward(int argc, const char **argv) {
 	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
 
 	if (proc) {
-		proc->tryMoveForward();
+		proc->tryMoveForward(true);
 	}
 	return false;
 }
 
-bool Debugger::cmdMoveBack(int argc, const char **argv) {
+bool Debugger::cmdStartMoveBack(int argc, const char **argv) {
 	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
 		debugPrintf("Can't move back: avatarInStasis\n");
 		return false;
@@ -1158,7 +1162,59 @@ bool Debugger::cmdMoveBack(int argc, const char **argv) {
 	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
 
 	if (proc) {
-		proc->tryMoveBack();
+		proc->tryMoveBack(true);
+	}
+	return false;
+}
+
+bool Debugger::cmdStopTurnLeft(int argc, const char **argv) {
+	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
+		debugPrintf("Can't turn left: avatarInStasis\n");
+		return false;
+	}
+	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
+
+	if (proc) {
+		proc->tryTurnLeft(false);
+	}
+	return false;
+}
+
+bool Debugger::cmdStopTurnRight(int argc, const char **argv) {
+	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
+		debugPrintf("Can't turn right: avatarInStasis\n");
+		return false;
+	}
+	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
+
+	if (proc) {
+		proc->tryTurnRight(false);
+	}
+	return false;
+}
+
+bool Debugger::cmdStopMoveForward(int argc, const char **argv) {
+	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
+		debugPrintf("Can't move forward: avatarInStasis\n");
+		return false;
+	}
+	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
+
+	if (proc) {
+		proc->tryMoveForward(false);
+	}
+	return false;
+}
+
+bool Debugger::cmdStopMoveBack(int argc, const char **argv) {
+	if (Ultima8Engine::get_instance()->isAvatarInStasis()) {
+		debugPrintf("Can't move back: avatarInStasis\n");
+		return false;
+	}
+	AvatarMoverProcess *proc = Ultima8Engine::get_instance()->getAvatarMoverProcess();
+
+	if (proc) {
+		proc->tryMoveBack(false);
 	}
 	return false;
 }
diff --git a/engines/ultima/ultima8/misc/debugger.h b/engines/ultima/ultima8/misc/debugger.h
index 7fe9726130..965758bd07 100644
--- a/engines/ultima/ultima8/misc/debugger.h
+++ b/engines/ultima/ultima8/misc/debugger.h
@@ -154,10 +154,14 @@ private:
 
 	// Avatar mover
 	bool cmdBothButtonClick(int argc, const char **argv);
-	bool cmdTurnLeft(int argc, const char **argv);
-	bool cmdTurnRight(int argc, const char **argv);
-	bool cmdMoveForward(int argc, const char **argv);
-	bool cmdMoveBack(int argc, const char **argv);
+	bool cmdStartTurnLeft(int argc, const char **argv);
+	bool cmdStartTurnRight(int argc, const char **argv);
+	bool cmdStartMoveForward(int argc, const char **argv);
+	bool cmdStartMoveBack(int argc, const char **argv);
+	bool cmdStopTurnLeft(int argc, const char **argv);
+	bool cmdStopTurnRight(int argc, const char **argv);
+	bool cmdStopMoveForward(int argc, const char **argv);
+	bool cmdStopMoveBack(int argc, const char **argv);
 
 	// Audio Process
 	bool cmdListSFX(int argc, const char **argv);
diff --git a/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp b/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp
index 32806f60ab..a8ceb36e48 100644
--- a/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp
+++ b/engines/ultima/ultima8/world/actors/avatar_mover_process.cpp
@@ -43,7 +43,9 @@ DEFINE_RUNTIME_CLASSTYPE_CODE(AvatarMoverProcess)
 
 AvatarMoverProcess::AvatarMoverProcess() : Process(),
 		_lastFrame(0), _lastAttack(0), _idleTime(0),
-		_lastHeadShakeAnim(Animation::lookLeft), _fakeBothButtonClick(false) {
+		_lastHeadShakeAnim(Animation::lookLeft), _fakeBothButtonClick(false),
+		_tryTurnLeft(false), _tryTurnRight(false),
+		_tryMoveForward(false), _tryMoveBack(false) {
 	_type = 1; // CONSTANT! (type 1 = persistent)
 }
 
@@ -288,6 +290,33 @@ void AvatarMoverProcess::handleCombatMode() {
 		if (checkTurn(mousedir, false))
 			return;
 
+	bool moving = (lastanim == Animation::advance || lastanim == Animation::retreat);
+	bool tryMove = _tryMoveForward || _tryMoveBack;
+
+	//  if we are trying to move, allow change direction only after move occurs to avoid spinning
+	if (moving || !tryMove) {
+		if (_tryTurnLeft) {
+			direction = (direction + 7) % 8;
+		}
+
+		if (_tryTurnRight) {
+			direction = (direction + 1) % 8;
+		}
+	}
+
+	if (_tryMoveForward) {
+		waitFor(avatar->doAnim(Animation::advance, direction));
+		return;
+	}
+
+	if (_tryMoveBack) {
+		waitFor(avatar->doAnim(Animation::retreat, direction));
+		return;
+	}
+
+	if (checkTurn(direction, false))
+		return;
+
 	// not doing anything in particular? stand
 	// TODO: make sure falling works properly.
 	if (lastanim != Animation::combatStand) {
@@ -521,6 +550,36 @@ void AvatarMoverProcess::handleNormalMode() {
 		if (checkTurn(mousedir, false))
 			return;
 
+	bool moving = (lastanim == Animation::run || lastanim == Animation::walk);
+	bool tryMove = _tryMoveForward || _tryMoveBack;
+
+	//  if we are trying to move, allow change direction only after move occurs to avoid spinning
+	if (moving || !tryMove) {
+		if (_tryTurnLeft) {
+			direction = (direction + 7) % 8;
+		}
+
+		if (_tryTurnRight) {
+			direction = (direction + 1) % 8;
+		}
+	}
+
+	if (_tryMoveForward) {
+		step(Animation::walk, direction);
+		return;
+	}
+
+	if (_tryMoveBack) {
+		step(Animation::walk, (direction + 4) % 8);
+		// flip to move forward once turned
+		_tryMoveBack = false;
+		_tryMoveForward = true;
+		return;
+	}
+
+	if (checkTurn(direction, moving))
+		return;
+
 	// doing another animation?
 	if (Kernel::get_instance()->getNumProcesses(1, ActorAnimProcess::ACTOR_ANIM_PROC_TYPE))
 		return;
@@ -547,8 +606,19 @@ void AvatarMoverProcess::handleNormalMode() {
 				nextanim = Animation::lookLeft;
 			waitFor(avatar->doAnim(nextanim, direction));
 			_idleTime = 0;
+			return;
 		}
 	}
+
+	// if we were running, slow to a walk before stopping
+	if (lastanim == Animation::run) {
+		waitFor(avatar->doAnim(Animation::walk, direction));
+	}
+
+	// not doing anything in particular? stand
+	if (lastanim != Animation::stand) {
+		waitFor(avatar->doAnim(Animation::stand, direction));
+	}
 }
 
 void AvatarMoverProcess::step(Animation::Sequence action, int direction,
@@ -675,40 +745,26 @@ void AvatarMoverProcess::jump(Animation::Sequence action, int direction) {
 	}
 }
 
-void AvatarMoverProcess::tryTurnLeft() {
-	const MainActor *avatar = getMainActor();
-	int curdir = avatar->getDir();
-	Animation::Sequence action = avatar->getLastAnim();
-	bool moving = (action == Animation::run || action == Animation::walk);
-	checkTurn((curdir - 1 + 8) % 8, moving);
+void AvatarMoverProcess::tryTurnLeft(bool b) {
+	_tryTurnLeft = b;
 }
 
-void AvatarMoverProcess::tryTurnRight() {
-	const MainActor *avatar = getMainActor();
-	int curdir = avatar->getDir();
-	Animation::Sequence action = avatar->getLastAnim();
-	bool moving = (action == Animation::run || action == Animation::walk);
-	checkTurn((curdir + 1) % 8, moving);
+void AvatarMoverProcess::tryTurnRight(bool b) {
+	_tryTurnRight = b;
 }
 
-void AvatarMoverProcess::tryMoveForward() {
-	const MainActor *avatar = getMainActor();
-	int curdir = avatar->getDir();
-	Animation::Sequence action = avatar->getLastAnim();
-	bool moving = (action == Animation::run || action == Animation::walk);
-	if (moving)
-		return;
-	step(Animation::step, curdir, false);
+void AvatarMoverProcess::tryMoveForward(bool b) {
+	_tryMoveForward = b;
 }
 
-void AvatarMoverProcess::tryMoveBack() {
-	const MainActor *avatar = getMainActor();
-	int curdir = avatar->getDir();
-	Animation::Sequence action = avatar->getLastAnim();
-	bool moving = (action == Animation::run || action == Animation::walk);
-	if (moving)
-		return;
-	step(Animation::step, (curdir + 4) % 8, false);
+void AvatarMoverProcess::tryMoveBack(bool b) {
+	if (b) {
+		_tryMoveBack = true;
+	}
+	else {
+		_tryMoveBack = false;
+		_tryMoveForward = false;
+	}
 }
 
 void AvatarMoverProcess::turnToDirection(int direction) {
diff --git a/engines/ultima/ultima8/world/actors/avatar_mover_process.h b/engines/ultima/ultima8/world/actors/avatar_mover_process.h
index d4e330bcc1..a3430d3be7 100644
--- a/engines/ultima/ultima8/world/actors/avatar_mover_process.h
+++ b/engines/ultima/ultima8/world/actors/avatar_mover_process.h
@@ -53,10 +53,10 @@ public:
 		_fakeBothButtonClick = true;
 	}
 
-	void tryTurnLeft();
-	void tryTurnRight();
-	void tryMoveForward();
-	void tryMoveBack();
+	void tryTurnLeft(bool b);
+	void tryTurnRight(bool b);
+	void tryMoveForward(bool b);
+	void tryMoveBack(bool b);
 
 private:
 	void saveData(Common::WriteStream *ws) override;
@@ -82,8 +82,13 @@ private:
 
 	//! A fake "both button" event has been requested
 	bool _fakeBothButtonClick;
-
+	
 	MButton _mouseButton[2];
+
+	bool _tryTurnLeft;
+	bool _tryTurnRight;
+	bool _tryMoveForward;
+	bool _tryMoveBack;
 };
 
 } // End of namespace Ultima8




More information about the Scummvm-git-logs mailing list