SHERLOCK: Implemented pick up code

This commit is contained in:
Paul Gilbert 2015-04-12 11:06:25 -05:00
parent 461d5c64f2
commit 454b6a2bbe
5 changed files with 121 additions and 3 deletions

View file

@ -62,8 +62,6 @@ class Inventory : public Common::Array<InventoryItem> {
private:
SherlockEngine *_vm;
int putItemInInventory(Object &obj);
void copyToInventory(Object &obj);
public:
ImageFile *_invShapes[MAX_VISIBLE_INVENTORY];
@ -98,6 +96,7 @@ public:
void doInvJF();
int putNameInInventory(const Common::String &name);
int putItemInInventory(Object &obj);
int deleteItemFromInventory(const Common::String &name);
};

View file

@ -947,6 +947,97 @@ void Object::adjustObject() {
}
}
/**
* Handles trying to pick up an object. If allowed, plays an y necessary animation for picking
* up the item, and then adds it to the player's inventory
*/
int Object::pickUpObject(const char *const messages[]) {
Inventory &inv = *_vm->_inventory;
People &people = *_vm->_people;
Scene &scene = *_vm->_scene;
Screen &screen = *_vm->_screen;
Talk &talk = *_vm->_talk;
UserInterface &ui = *_vm->_ui;
int pickup = _pickup & 0x7f;
bool printed = false;
bool takeFlag = true;
int numObjects = 0;
int message;
if (pickup == 99) {
for (int idx = 0; idx < 4 && !talk._talkToAbort; ++idx) {
if (checkNameForCodes(_use[0]._names[idx], nullptr)) {
if (!talk._talkToAbort)
printed = true;
}
}
return 0;
}
if (!pickup || (pickup > 50 && pickup <= 80)) {
int message = _pickup;
if (message > 50)
message -= 50;
++ui._infoFlag;
ui.clearInfo();
screen.print(Common::Point(0, INFO_LINE + 1), INFO_LINE, messages[message]);
ui._menuCounter = 30;
} else {
// Pick it up
if ((_pickup & 0x80) == 0) {
// Play an animation
if (pickup > 80) {
takeFlag = false; // Don't pick it up
scene.startCAnim(pickup - 81, 1);
if (_pickupFlag)
_vm->setFlags(_pickupFlag);
} else {
scene.startCAnim(pickup - 1, 1);
if (!talk._talkToAbort) {
// Erase the shape
_type = _type == NO_SHAPE ? INVALID : REMOVE;
}
}
if (talk._talkToAbort)
return 0;
} else {
// Play generic pickup sequence
// Original moved cursor position here
people.goAllTheWay();
ui._menuCounter = 25;
ui._temp1 = 1;
}
for (int idx = 0; idx < 4 && !talk._talkToAbort; ++idx) {
if (checkNameForCodes(_use[0]._names[idx], nullptr)) {
if (!talk._talkToAbort)
printed = true;
}
}
if (talk._talkToAbort)
return 0;
// Add the item to the player's inventory
if (takeFlag)
numObjects = inv.putItemInInventory(*this);
if (!printed) {
ui._infoFlag++;
ui.clearInfo();
Common::String itemName = _description;
itemName.setChar(tolower(itemName[0]), 0);
screen.print(Common::Point(0, INFO_LINE + 1), INFO_FOREGROUND, "Picked up %s", itemName.c_str());
ui._menuCounter = 25;
}
}
return numObjects;
}
/**
* Returns the current bounds for the sprite
*/

View file

@ -214,6 +214,8 @@ public:
void adjustObject();
int pickUpObject(const char *const messages[]);
int frameWidth() const { return _imageFrame ? _imageFrame->_frame.w : 0; }
int frameHeight() const { return _imageFrame ? _imageFrame->_frame.h : 0; }
const Common::Rect getNewBounds() const;

View file

@ -92,6 +92,7 @@ UserInterface::UserInterface(SherlockEngine *vm) : _vm(vm) {
_lookHelp = 0;
_key = _oldKey = 0;
_temp = _oldTemp = 0;
_temp1 = 0;
_invLookFlag = 0;
_windowOpen = false;
_oldLook = false;
@ -711,6 +712,9 @@ void UserInterface::lookInv() {
}
}
/**
* Handles input when the file list window is being displayed
*/
void UserInterface::doEnvControl() {
// TODO
}
@ -1193,8 +1197,29 @@ void UserInterface::doMiscControl(int allowed) {
}
}
/**
* Handles input for picking up items
*/
void UserInterface::doPickControl() {
// TODO
Events &events = *_vm->_events;
Scene &scene = *_vm->_scene;
if (events._released) {
if ((_temp = _bgFound) != -1) {
events.clearEvents();
// Don't allow characters to be picked up
if (_bgFound < 1000) {
scene._bgShapes[_bgFound].pickUpObject(MPICK);
if (_menuMode != TALK_MODE) {
_key = _oldKey = -1;
_menuMode = STD_MODE;
restoreButton(PICKUP_MODE - 1);
}
}
}
}
}
void UserInterface::doTalkControl() {

View file

@ -125,6 +125,7 @@ public:
bool _windowOpen;
bool _endKeyActive;
int _invLookFlag;
int _temp1;
public:
UserInterface(SherlockEngine *vm);
~UserInterface();