aboutsummaryrefslogtreecommitdiff
path: root/kyra
diff options
context:
space:
mode:
authorJohannes Schickel2005-12-09 17:36:57 +0000
committerJohannes Schickel2005-12-09 17:36:57 +0000
commit69114bb80dc8b8f0c4326e2aed43050ed3d52124 (patch)
tree3613414c77971956f042e1e6296ef094a03975e0 /kyra
parent1fc81a08fa6eab8d29b8e0d443501727b1c6c224 (diff)
downloadscummvm-rg350-69114bb80dc8b8f0c4326e2aed43050ed3d52124.tar.gz
scummvm-rg350-69114bb80dc8b8f0c4326e2aed43050ed3d52124.tar.bz2
scummvm-rg350-69114bb80dc8b8f0c4326e2aed43050ed3d52124.zip
Finished item pick up code.
Changed writing of stack access in the script functions. Also fixed typo with cmdPoisonBrandonAndRemaps. svn-id: r19764
Diffstat (limited to 'kyra')
-rw-r--r--kyra/kyra.cpp45
-rw-r--r--kyra/screen.cpp3
-rw-r--r--kyra/script_v1.cpp22
3 files changed, 45 insertions, 25 deletions
diff --git a/kyra/kyra.cpp b/kyra/kyra.cpp
index 76d3aae899..d1efa94c2e 100644
--- a/kyra/kyra.cpp
+++ b/kyra/kyra.cpp
@@ -2536,24 +2536,24 @@ byte KyraEngine::findFreeItemInScene(int scene) {
byte KyraEngine::findItemAtPos(int x, int y) {
debug(9, "findItemAtPos(%d, %d)", x, y);
assert(_currentCharacter->sceneId < _roomTableSize);
- uint8 *itemsTable = _roomTable[_currentCharacter->sceneId].itemsTable;
- uint16 *xposOffset = _roomTable[_currentCharacter->sceneId].itemsXPos;
- uint8 *yposOffset = _roomTable[_currentCharacter->sceneId].itemsYPos;
+ const uint8 *itemsTable = _roomTable[_currentCharacter->sceneId].itemsTable;
+ const uint16 *xposOffset = _roomTable[_currentCharacter->sceneId].itemsXPos;
+ const uint8 *yposOffset = _roomTable[_currentCharacter->sceneId].itemsYPos;
int highestYPos = -1;
byte returnValue = 0xFF;
for (int i = 0; i < 12; ++i) {
if (*itemsTable != 0xFF) {
- int xpos = *xposOffset - 8;
+ int xpos = *xposOffset - 11;
int xpos2 = *xposOffset + 10;
if (x > xpos && x < xpos2) {
assert(*itemsTable < ARRAYSIZE(_itemTable));
int itemHeight = _itemTable[*itemsTable].height;
- int ypos = *yposOffset;
+ int ypos = *yposOffset + 3;
int ypos2 = ypos - itemHeight - 3;
- if (y < ypos2 && (ypos+3) > y) {
+ if (y > ypos2 && ypos > y) {
if (highestYPos <= ypos) {
returnValue = i;
highestYPos = ypos;
@@ -2561,9 +2561,9 @@ byte KyraEngine::findItemAtPos(int x, int y) {
}
}
}
- xposOffset += 2;
- yposOffset += 1;
- itemsTable += 1;
+ ++xposOffset;
+ ++yposOffset;
+ ++itemsTable;
}
return returnValue;
@@ -2906,7 +2906,7 @@ void KyraEngine::exchangeItemWithMouseItem(uint16 sceneId, int itemIndex) {
assert(sceneId < _roomTableSize);
Room *currentRoom = &_roomTable[sceneId];
- uint8 item = currentRoom->itemsTable[itemIndex];
+ int item = currentRoom->itemsTable[itemIndex];
currentRoom->itemsTable[itemIndex] = _itemInHand;
_itemInHand = item;
animAddGameItem(itemIndex, sceneId);
@@ -4540,13 +4540,32 @@ void KyraEngine::processInput(int xpos, int ypos) {
handleSceneChange(xpos, ypos, 1, 1);
return;
}
- }
-
-
+ }
}
int KyraEngine::processInputHelper(int xpos, int ypos) {
debug(9, "processInputHelper(%d, %d)", xpos, ypos);
+ uint8 item = findItemAtPos(xpos, ypos);
+ if (item != 0xFF) {
+ if (_itemInHand == -1) {
+ _screen->hideMouse();
+ animRemoveGameItem(item);
+ // XXX call kyraPlaySound(53)
+ assert(_currentCharacter->sceneId < _roomTableSize);
+ Room *currentRoom = &_roomTable[_currentCharacter->sceneId];
+ int item2 = currentRoom->itemsTable[item];
+ currentRoom->itemsTable[item] = 0xFF;
+ setMouseItem(item2);
+ // XXX updateSentenceCommand
+ _itemInHand = item2;
+ _screen->showMouse();
+ clickEventHandler2();
+ return 1;
+ } else {
+ exchangeItemWithMouseItem(_currentCharacter->sceneId, item);
+ return 1;
+ }
+ }
return 0;
}
diff --git a/kyra/screen.cpp b/kyra/screen.cpp
index 84d0928a7a..91ba5bda36 100644
--- a/kyra/screen.cpp
+++ b/kyra/screen.cpp
@@ -567,7 +567,8 @@ void Screen::setScreenDim(int dim) {
void Screen::drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int sd, int flags, ...) {
debug(9, "Screen::drawShape(%d, 0x%X, %d, %d, %d, 0x%.04X, ...)", pageNum, shapeData, x, y, sd, flags);
- assert(shapeData);
+ if (!shapeData)
+ return;
va_list args;
va_start(args, flags);
diff --git a/kyra/script_v1.cpp b/kyra/script_v1.cpp
index 3c5488bebe..4b20fd2cdd 100644
--- a/kyra/script_v1.cpp
+++ b/kyra/script_v1.cpp
@@ -74,7 +74,7 @@ void ScriptHelper::c1_pushBPAdd() {
void ScriptHelper::c1_popRetOrPos() {
switch (_parameter) {
case 0:
- _curScript->retValue = _curScript->stack[++_curScript->sp-1];
+ _curScript->retValue = _curScript->stack[_curScript->sp++];
break;
case 1:
@@ -82,8 +82,8 @@ void ScriptHelper::c1_popRetOrPos() {
_continue = false;
_curScript->ip = 0;
} else {
- _curScript->bp = _curScript->stack[++_curScript->sp-1];
- _curScript->ip = _curScript->dataPtr->data + (_curScript->stack[++_curScript->sp-1] << 1);
+ _curScript->bp = _curScript->stack[_curScript->sp++];
+ _curScript->ip = _curScript->dataPtr->data + (_curScript->stack[_curScript->sp++] << 1);
}
break;
@@ -95,15 +95,15 @@ void ScriptHelper::c1_popRetOrPos() {
}
void ScriptHelper::c1_popVar() {
- _curScript->variables[_parameter] = _curScript->stack[++_curScript->sp-1];
+ _curScript->variables[_parameter] = _curScript->stack[_curScript->sp++];
}
void ScriptHelper::c1_popBPNeg() {
- _curScript->stack[(-(int32)(_parameter + 2)) + _curScript->bp] = _curScript->stack[++_curScript->sp-1];
+ _curScript->stack[(-(int32)(_parameter + 2)) + _curScript->bp] = _curScript->stack[_curScript->sp++];
}
void ScriptHelper::c1_popBPAdd() {
- _curScript->stack[(_parameter - 1) + _curScript->bp] = _curScript->stack[++_curScript->sp-1];
+ _curScript->stack[(_parameter - 1) + _curScript->bp] = _curScript->stack[_curScript->sp++];
}
void ScriptHelper::c1_addSP() {
@@ -157,8 +157,8 @@ void ScriptHelper::c1_eval() {
int16 ret = 0;
bool error = false;
- int16 val1 = _curScript->stack[++_curScript->sp-1];
- int16 val2 = _curScript->stack[++_curScript->sp-1];
+ int16 val1 = _curScript->stack[_curScript->sp++];
+ int16 val2 = _curScript->stack[_curScript->sp++];
switch (_parameter) {
case 0:
@@ -284,8 +284,8 @@ void ScriptHelper::c1_setRetAndJmp() {
_continue = false;
_curScript->ip = 0;
} else {
- _curScript->retValue = _curScript->stack[++_curScript->sp-1];
- uint16 temp = _curScript->stack[++_curScript->sp-1];
+ _curScript->retValue = _curScript->stack[_curScript->sp++];
+ uint16 temp = _curScript->stack[_curScript->sp++];
_curScript->stack[60] = 0;
_curScript->ip = &_curScript->dataPtr->data[temp*2];
}
@@ -1277,7 +1277,7 @@ int KyraEngine::cmd_setSceneAnimCurrXY(ScriptState *script) {
}
int KyraEngine::cmd_poisonBrandonAndRemaps(ScriptState *script) {
- warning("STUB: cmdPoisonBrandonAndRemaps");
+ warning("STUB: cmd_poisonBrandonAndRemaps");
return 0;
}