Skip to content

Commit

Permalink
PRINCE: Inventory LMB update, VariaTxt::getString fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jun 22, 2014
1 parent 25f51bf commit daf91dc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 26 deletions.
54 changes: 37 additions & 17 deletions engines/prince/prince.cpp
Expand Up @@ -883,15 +883,6 @@ void PrinceEngine::showTexts(Graphics::Surface *screen) {
}

int leftBorderText = 6;
/*
if (text._x + wideLine / 2 > _picWindowX + kNormalWidth - leftBorderText) {
text._x = _picWindowX + kNormalWidth - leftBorderText - wideLine / 2;
}
if (text._x - wideLine / 2 < _picWindowX + leftBorderText) {
text._x = _picWindowX + leftBorderText + wideLine / 2;
}
*/
if (text._x + wideLine / 2 > kNormalWidth - leftBorderText) {
text._x = kNormalWidth - leftBorderText - wideLine / 2;
}
Expand All @@ -902,7 +893,7 @@ void PrinceEngine::showTexts(Graphics::Surface *screen) {

for (uint8 i = 0; i < lines.size(); i++) {
int x = text._x - getTextWidth(lines[i].c_str()) / 2;
int y = text._y - (lines.size() - i) * (_font->getFontHeight());
int y = text._y - (lines.size() - i) * (_font->getFontHeight()); // to fix
if (x < 0) {
x = 0;
}
Expand Down Expand Up @@ -1673,7 +1664,10 @@ void PrinceEngine::leftMouseButton() {
//_script->_scriptInfo.stdUse;
} else {
debug("selectedMob: %d", _selectedMob);
_script->scanMobEvents(_mobList[_selectedMob]._mask, _room->_itemUse);
int mobEvent = _script->scanMobEventsWithItem(_mobList[_selectedMob - 1]._mask, _room->_itemUse, _selectedItem);
if (mobEvent == -1) {

}
}
}

Expand Down Expand Up @@ -1723,15 +1717,28 @@ void PrinceEngine::inventoryLeftMouseButton() {
//do_option
} else {
//use_item_on_item
int invObjUU = _script->scanMobEventsWithItem(_invMobList[_selectedMob - 1]._mask, _script->_scriptInfo.invObjUU, _selectedItem);
if (invObjUU == -1) {
int textNr = 11;
if (_selectedItem == 31 || _invMobList[_selectedMob - 1]._mask == 31) {
textNr = 20;
}
printAt(0, 216, _variaTxt->getString(textNr), kNormalWidth / 2, 100);
//loadVoice(0, 28, Common::String::format("%05d-00.WAV", text));
//playSample(28, 0);
} else {
//store_new_pc
// storeNewPC();

}
}
} else {
return;
}
}
//do_option
if (_optionEnabled == 0) {
int invObjExamEvent = _script->scanMobEvents(_selectedMob, _script->_scriptInfo.invObjExam);
int invObjExamEvent = _script->scanMobEvents(_invMobList[_selectedMob - 1]._mask, _script->_scriptInfo.invObjExam);
if (invObjExamEvent == -1) {
// do_standard
printAt(0, 216, _invMobList[_selectedMob - 1]._examText.c_str(), kNormalWidth / 2, _invExamY);
Expand All @@ -1751,12 +1758,12 @@ void PrinceEngine::inventoryLeftMouseButton() {
}
} else if (_optionEnabled == 1) {
// not_examine
int invObjUse = _script->scanMobEvents(_selectedMob, _script->_scriptInfo.invObjUse);
int invObjUse = _script->scanMobEvents(_invMobList[_selectedMob - 1]._mask, _script->_scriptInfo.invObjUse);
if (invObjUse == -1) {
// do_standard_use
_selectedMode = 0;
_selectedItem = _selectedMob;
makeInvCursor(_selectedMob);
_selectedItem = _invMobList[_selectedMob - 1]._mask;
makeInvCursor(_invMobList[_selectedMob - 1]._mask);
_currentPointerNumber = 2;
changeCursor(2);
//exit_normally
Expand All @@ -1772,14 +1779,27 @@ void PrinceEngine::inventoryLeftMouseButton() {
// not_use_inv
// do_standard_give
_selectedMode = 1;
_selectedItem = _selectedMob;
makeInvCursor(_selectedMob);
_selectedItem = _invMobList[_selectedMob - 1]._mask;
makeInvCursor(_invMobList[_selectedMob - 1]._mask);
_currentPointerNumber = 2;
changeCursor(2);
//exit_normally
} else {
// use_item_on_item
int invObjUU = _script->scanMobEventsWithItem(_invMobList[_selectedMob - 1]._mask, _script->_scriptInfo.invObjUU, _selectedItem);
if (invObjUU == -1) {
int textNr = 11;
if (_selectedItem == 31 || _invMobList[_selectedMob - 1]._mask == 31) {
textNr = 20;
}
printAt(0, 216, _variaTxt->getString(textNr), kNormalWidth / 2, 100);
//loadVoice(0, 28, Common::String::format("%05d-00.WAV", text));
//playSample(28, 0);
} else {
//store_new_pc
// storeNewPC();

}
}
//exit_normally
_selectedMob = 0;
Expand Down
29 changes: 26 additions & 3 deletions engines/prince/script.cpp
Expand Up @@ -212,17 +212,40 @@ int Script::scanMobEvents(int mobMask, int dataEventOffset) {
int32 code;
do {
mob = (int)READ_UINT16(&_data[dataEventOffset + i * 6]);
debug("mob: %d", mob);
code = (int)READ_UINT32(&_data[dataEventOffset + i * 6 + 2]);
debug("code: %d", code);
if (mob == mobMask) {
code = (int)READ_UINT32(&_data[dataEventOffset + i * 6 + 2]);
debug("mob: %d", mob);
debug("code: %d", code);
return code;
}
i++;
} while (mob != -1);
return -1;
}

int Script::scanMobEventsWithItem(int mobMask, int dataEventOffset, int itemNr) {
debug("mobMask: %d", mobMask);
int i = 0;
int16 mob;
int16 item;
int32 code;
do {
mob = (int)READ_UINT16(&_data[dataEventOffset + i * 8]);
if (mob == mobMask) {
item = (int)READ_UINT16(&_data[dataEventOffset + i * 8 + 2]);
if (item == itemNr) {
code = (int)READ_UINT32(&_data[dataEventOffset + i * 8 + 4]);
debug("mob: %d", mob);
debug("item: %d", item);
debug("code: %d", code);
return code;
}
}
i++;
} while (mob != -1);
return -1;
}

void Script::installSingleBackAnim(Common::Array<BackgroundAnim> &_backanimList, int offset) {

BackgroundAnim newBackgroundAnim;
Expand Down
1 change: 1 addition & 0 deletions engines/prince/script.h
Expand Up @@ -140,6 +140,7 @@ class Script {
bool loadAllMasks(Common::Array<Mask> &maskList, int offset);

int scanMobEvents(int mobMask, int dataEventOffset);
int scanMobEventsWithItem(int mobMask, int dataEventOffset, int item);

const char *getString(uint32 offset) {
return (const char *)(&_data[offset]);
Expand Down
8 changes: 2 additions & 6 deletions engines/prince/variatxt.cpp
Expand Up @@ -42,15 +42,11 @@ bool VariaTxt::loadFromStream(Common::SeekableReadStream &stream) {
return true;
}

const char * VariaTxt::getString(uint32 stringId) {
uint32 stringOffset = READ_LE_UINT32(_data + stringId);

const char *VariaTxt::getString(uint32 stringId) {
uint32 stringOffset = READ_LE_UINT32(_data + stringId * 4);
if (stringOffset > _dataSize) {
assert(false);
}

debug("VariaTxt::getString %04X %04X", stringId, stringOffset);

return (const char *)_data + stringOffset;
}

Expand Down

0 comments on commit daf91dc

Please sign in to comment.