[Scummvm-cvs-logs] SF.net SVN: scummvm:[44965] scummvm/trunk/engines/draci
spalek at users.sourceforge.net
spalek at users.sourceforge.net
Mon Oct 12 05:08:29 CEST 2009
Revision: 44965
http://scummvm.svn.sourceforge.net/scummvm/?rev=44965&view=rev
Author: spalek
Date: 2009-10-12 03:08:28 +0000 (Mon, 12 Oct 2009)
Log Message:
-----------
Dragon looks into the requested direction.
Parsing _lookDir and _useDir, and passing it all the way around to walkHero().
Also, added playHeroAnimation() to reduce code duplication.
Modified Paths:
--------------
scummvm/trunk/engines/draci/game.cpp
scummvm/trunk/engines/draci/game.h
scummvm/trunk/engines/draci/script.cpp
Modified: scummvm/trunk/engines/draci/game.cpp
===================================================================
--- scummvm/trunk/engines/draci/game.cpp 2009-10-12 01:16:13 UTC (rev 44964)
+++ scummvm/trunk/engines/draci/game.cpp 2009-10-12 03:08:28 UTC (rev 44965)
@@ -282,17 +282,17 @@
_objUnderCursor = kObjectNotFound;
if (!obj->_imLook) {
- if (obj->_lookDir == -1) {
- walkHero(x, y);
+ if (obj->_lookDir == kDirectionLast) {
+ walkHero(x, y, obj->_lookDir);
} else {
- walkHero(obj->_lookX, obj->_lookY);
+ walkHero(obj->_lookX, obj->_lookY, obj->_lookDir);
}
}
_vm->_script->run(obj->_program, obj->_look);
_vm->_mouse->cursorOn();
} else {
- walkHero(x, y);
+ walkHero(x, y, kDirectionLast);
}
}
}
@@ -310,17 +310,17 @@
_objUnderCursor = kObjectNotFound;
if (!obj->_imUse) {
- if (obj->_useDir == -1) {
- walkHero(x, y);
+ if (obj->_useDir == kDirectionLast) {
+ walkHero(x, y, obj->_useDir);
} else {
- walkHero(obj->_useX, obj->_useY);
+ walkHero(obj->_useX, obj->_useY, obj->_useDir);
}
}
_vm->_script->run(obj->_program, obj->_use);
_vm->_mouse->cursorOn();
} else {
- walkHero(x, y);
+ walkHero(x, y, kDirectionLast);
}
} else {
if (_vm->_script->testExpression(_currentRoom._program, _currentRoom._canUse)) {
@@ -332,7 +332,7 @@
_vm->_script->run(_currentRoom._program, _currentRoom._use);
_vm->_mouse->cursorOn();
} else {
- walkHero(x, y);
+ walkHero(x, y, kDirectionLast);
}
}
}
@@ -940,7 +940,16 @@
return _dialogueOffsets[_currentDialogue];
}
-void Game::walkHero(int x, int y) {
+void Game::playHeroAnimation(int anim_index) {
+ const GameObject *dragon = getObject(kDragonObject);
+ const int animID = dragon->_anim[anim_index];
+ Animation *anim = _vm->_anims->getAnimation(animID);
+ stopObjectAnimations(dragon);
+ positionAnimAsHero(anim);
+ _vm->_anims->play(animID);
+}
+
+void Game::walkHero(int x, int y, SightDirection dir) {
// Needed for the map room with empty walking map. For some reason,
// findNearestWalkable() takes several seconds with 100% CPU to finish
// (correctly).
@@ -948,23 +957,28 @@
return;
Surface *surface = _vm->_screen->getSurface();
-
_hero = _currentRoom._walkingMap.findNearestWalkable(x, y, surface->getRect());
-
- GameObject *dragon = getObject(kDragonObject);
- stopObjectAnimations(dragon);
-
debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", _hero.x, _hero.y);
-
- // Fetch dragon's animation ID
// FIXME: Need to add proper walking (this only warps the dragon to position)
- int animID = dragon->_anim[kStopRight];
- Animation *anim = _vm->_anims->getAnimation(animID);
- positionAnimAsHero(anim);
-
- // Play the animation
- _vm->_anims->play(animID);
+ Movement movement = kStopRight;
+ switch (dir) {
+ case kDirectionLeft:
+ movement = kStopLeft;
+ break;
+ case kDirectionRight:
+ movement = kStopRight;
+ break;
+ default: {
+ const GameObject *dragon = getObject(kDragonObject);
+ const int anim_index = playingObjectAnimation(dragon);
+ if (anim_index >= 0) {
+ movement = static_cast<Movement> (anim_index);
+ }
+ break;
+ }
+ }
+ playHeroAnimation(movement);
}
void Game::loadItem(int itemID) {
@@ -1200,8 +1214,8 @@
obj->_lookY = objReader.readUint16LE();
obj->_useX = objReader.readUint16LE();
obj->_useY = objReader.readUint16LE();
- obj->_lookDir = objReader.readByte() - 1;
- obj->_useDir = objReader.readByte() - 1;
+ obj->_lookDir = static_cast<SightDirection> (objReader.readByte());
+ obj->_useDir = static_cast<SightDirection> (objReader.readByte());
obj->_absNum = objNum;
Modified: scummvm/trunk/engines/draci/game.h
===================================================================
--- scummvm/trunk/engines/draci/game.h 2009-10-12 01:16:13 UTC (rev 44964)
+++ scummvm/trunk/engines/draci/game.h 2009-10-12 03:08:28 UTC (rev 44965)
@@ -132,13 +132,21 @@
const byte *_data;
};
+/*
+ * Enumerates the directions the dragon can look into when arrived.
+ */
+enum SightDirection {
+ kDirectionLast, kDirectionMouse, kDirectionUnknown,
+ kDirectionRight, kDirectionLeft, kDirectionIntelligent
+};
+
struct GameObject {
uint _init, _look, _use, _canUse;
bool _imInit, _imLook, _imUse;
int _walkDir;
byte _z;
uint _lookX, _lookY, _useX, _useY;
- int _lookDir, _useDir;
+ SightDirection _lookDir, _useDir;
uint _absNum;
Common::Array<int> _anim;
GPL2Program _program;
@@ -255,10 +263,11 @@
return n;
}
- void walkHero(int x, int y);
+ void walkHero(int x, int y, SightDirection dir);
int getHeroX() const;
int getHeroY() const;
void positionAnimAsHero(Animation *anim);
+ void playHeroAnimation(int anim_index);
int loadAnimation(uint animNum, uint z);
void loadOverlays();
Modified: scummvm/trunk/engines/draci/script.cpp
===================================================================
--- scummvm/trunk/engines/draci/script.cpp 2009-10-12 01:16:13 UTC (rev 44964)
+++ scummvm/trunk/engines/draci/script.cpp 2009-10-12 03:08:28 UTC (rev 44965)
@@ -479,43 +479,25 @@
void Script::justTalk(Common::Queue<int> ¶ms) {
const GameObject *dragon = _vm->_game->getObject(kDragonObject);
const int last_anim = static_cast<Movement> (_vm->_game->playingObjectAnimation(dragon));
- if (last_anim >= 0) {
- _vm->_game->stopObjectAnimations(dragon);
- }
int new_anim;
if (last_anim == kSpeakRight || last_anim == kStopRight) {
new_anim = kSpeakRight;
} else {
new_anim = kSpeakLeft;
}
-
- const int animID = dragon->_anim[new_anim];
-
- Animation *anim = _vm->_anims->getAnimation(animID);
- _vm->_game->positionAnimAsHero(anim);
-
- _vm->_anims->play(animID);
+ _vm->_game->playHeroAnimation(new_anim);
}
void Script::justStay(Common::Queue<int> ¶ms) {
const GameObject *dragon = _vm->_game->getObject(kDragonObject);
const int last_anim = static_cast<Movement> (_vm->_game->playingObjectAnimation(dragon));
- if (last_anim >= 0) {
- _vm->_game->stopObjectAnimations(dragon);
- }
int new_anim;
if (last_anim == kSpeakRight || last_anim == kStopRight) {
new_anim = kStopRight;
} else {
new_anim = kStopLeft;
}
-
- const int animID = dragon->_anim[new_anim];
-
- Animation *anim = _vm->_anims->getAnimation(animID);
- _vm->_game->positionAnimAsHero(anim);
-
- _vm->_anims->play(animID);
+ _vm->_game->playHeroAnimation(new_anim);
}
void Script::c_If(Common::Queue<int> ¶ms) {
@@ -662,9 +644,9 @@
int x = params.pop();
int y = params.pop();
- params.pop(); // facing direction, not used yet
+ SightDirection dir = static_cast<SightDirection> (params.pop());
- _vm->_game->walkHero(x, y);
+ _vm->_game->walkHero(x, y, dir);
}
void Script::walkOnPlay(Common::Queue<int> ¶ms) {
@@ -674,12 +656,12 @@
int x = params.pop();
int y = params.pop();
- params.pop(); // facing direction, not used yet
+ SightDirection dir = static_cast<SightDirection> (params.pop());
// HACK: This should be an onDest action when hero walking is properly implemented
_vm->_game->setExitLoop(true);
- _vm->_game->walkHero(x, y);
+ _vm->_game->walkHero(x, y, dir);
_vm->_game->setLoopSubstatus(kSubstatusStrange);
_vm->_game->loop();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list