DRAGONS: refactored inventory logic into inventory class
This commit is contained in:
parent
4bd381242a
commit
c20d288e22
5 changed files with 92 additions and 75 deletions
|
@ -362,7 +362,6 @@ void DragonsEngine::gameLoop()
|
||||||
if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
|
if ((_cursor->_iniUnderCursor & 0x8000) != 0) {
|
||||||
if (_cursor->_iniUnderCursor == 0x8002) {
|
if (_cursor->_iniUnderCursor == 0x8002) {
|
||||||
LAB_80027294:
|
LAB_80027294:
|
||||||
uVar7 = 0;
|
|
||||||
if (_cursor->iniItemInHand == 0) {
|
if (_cursor->iniItemInHand == 0) {
|
||||||
if ((bit_flags_8006fbd8 & 3) != 1) {
|
if ((bit_flags_8006fbd8 & 3) != 1) {
|
||||||
sequenceId = _dragonVAR->getVar(7);
|
sequenceId = _dragonVAR->getVar(7);
|
||||||
|
@ -372,19 +371,11 @@ void DragonsEngine::gameLoop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
actorId = 0;
|
if(_inventory->addItem(_cursor->iniItemInHand)) {
|
||||||
do {
|
|
||||||
if (unkArray_uint16[actorId] == 0) break;
|
|
||||||
uVar7 = uVar7 + 1;
|
|
||||||
actorId = (uint)uVar7;
|
|
||||||
} while (uVar7 < 0x29);
|
|
||||||
if (uVar7 < 0x29) {
|
|
||||||
_cursor->_sequenceID = 1;
|
_cursor->_sequenceID = 1;
|
||||||
waitForFrames(1);
|
waitForFrames(1);
|
||||||
uVar6 = _cursor->iniItemInHand;
|
|
||||||
_cursor->iniItemInHand = 0;
|
_cursor->iniItemInHand = 0;
|
||||||
_cursor->_iniUnderCursor = 0;
|
_cursor->_iniUnderCursor = 0;
|
||||||
unkArray_uint16[(uint)uVar7] = uVar6;
|
|
||||||
actorId = uVar3;
|
actorId = uVar3;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -478,7 +469,6 @@ void DragonsEngine::gameLoop()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (_cursor->_iniUnderCursor != 0) {
|
if (_cursor->_iniUnderCursor != 0) {
|
||||||
actorId_00 = 0;
|
|
||||||
if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
|
if ((_cursor->_sequenceID != 4) && (_cursor->_sequenceID != 2)) {
|
||||||
_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
|
_cursor->data_800728b0_cursor_seqID = _cursor->_sequenceID;
|
||||||
_cursor->data_80072890 = _cursor->_iniUnderCursor;
|
_cursor->data_80072890 = _cursor->_iniUnderCursor;
|
||||||
|
@ -490,27 +480,19 @@ void DragonsEngine::gameLoop()
|
||||||
walkFlickerToObject();
|
walkFlickerToObject();
|
||||||
goto LAB_8002790c;
|
goto LAB_8002790c;
|
||||||
}
|
}
|
||||||
if (_cursor->_iniUnderCursor != unkArray_uint16[0]) {
|
Actor *actor = _inventory->getInventoryItemActor(_cursor->_iniUnderCursor);
|
||||||
actorId = 1;
|
uint16 tmpId = _cursor->iniItemInHand;
|
||||||
do {
|
_inventory->replaceItem(_cursor->_iniUnderCursor, _cursor->iniItemInHand);
|
||||||
actorId_00 = actorId;
|
|
||||||
actorId = actorId_00 + 1;
|
|
||||||
} while (_cursor->_iniUnderCursor != unkArray_uint16[actorId_00 & 0xffff]);
|
|
||||||
}
|
|
||||||
puVar9 = unkArray_uint16 + (actorId_00 & 0xffff);
|
|
||||||
Actor *actor = _actorManager->getActor(actorId_00 + 0x17);
|
|
||||||
*puVar9 = _cursor->iniItemInHand;
|
|
||||||
_cursor->data_8007283c = actor->_sequenceID;
|
_cursor->data_8007283c = actor->_sequenceID;
|
||||||
actor->clearFlag(ACTOR_FLAG_40);
|
actor->clearFlag(ACTOR_FLAG_40);
|
||||||
_cursor->iniItemInHand = _cursor->_iniUnderCursor;
|
_cursor->iniItemInHand = _cursor->_iniUnderCursor;
|
||||||
_cursor->_sequenceID = 5;
|
_cursor->_sequenceID = 5;
|
||||||
actorId = uVar3;
|
actorId = uVar3;
|
||||||
if (*puVar9 != 0) {
|
if (tmpId != 0) {
|
||||||
actorId = actorId_00 + 0x17 & 0xffff;
|
|
||||||
actor->flags = 0;
|
actor->flags = 0;
|
||||||
actor->priorityLayer = 0;
|
actor->priorityLayer = 0;
|
||||||
actor->field_e = 0x100;
|
actor->field_e = 0x100;
|
||||||
actor->updateSequence(getINI((uint)*puVar9 - 1)->field_8 * 2 + 10);
|
actor->updateSequence(getINI(tmpId - 1)->field_8 * 2 + 10);
|
||||||
actor->setFlag(ACTOR_FLAG_40);
|
actor->setFlag(ACTOR_FLAG_40);
|
||||||
actor->setFlag(ACTOR_FLAG_80);
|
actor->setFlag(ACTOR_FLAG_80);
|
||||||
actor->setFlag(ACTOR_FLAG_100);
|
actor->setFlag(ACTOR_FLAG_100);
|
||||||
|
@ -520,38 +502,22 @@ void DragonsEngine::gameLoop()
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
uVar6 = 0;
|
|
||||||
if (_cursor->iniItemInHand == 0) goto LAB_80027b58;
|
if (_cursor->iniItemInHand == 0) goto LAB_80027b58;
|
||||||
//drop item back into inventory
|
//drop item back into inventory
|
||||||
actorId = 0;
|
Actor *invActor = _inventory->addItemIfPositionIsEmpty(_cursor->iniItemInHand, _cursor->_x, _cursor->_y);
|
||||||
do {
|
if (invActor != NULL) {
|
||||||
Actor *actor = _actorManager->getActor(actorId + 0x17);
|
invActor->flags = 0;
|
||||||
if (((((int)(short)actor->x_pos - 0x10 <= (int)_cursor->_x) &&
|
invActor->priorityLayer = 0;
|
||||||
((int)_cursor->_x < (int)(short)actor->x_pos + 0x10)) &&
|
invActor->field_e = 0x100;
|
||||||
((int)(short)actor->y_pos - 0xc <= (int)_cursor->_y)) &&
|
invActor->updateSequence(
|
||||||
(actorId = (uint)uVar6, (int)_cursor->_y < (int)(short)actor->y_pos + 0xc)) {
|
getINI(_cursor->iniItemInHand - 1)->field_8 * 2 + 10);
|
||||||
break;
|
|
||||||
}
|
|
||||||
uVar6 = uVar6 + 1;
|
|
||||||
actorId = (uint)uVar6;
|
|
||||||
} while (uVar6 < 0x29);
|
|
||||||
if (actorId != 0x29) {
|
|
||||||
actorId_00 = (uint)(ushort)(uVar6 + 0x17);
|
|
||||||
unkArray_uint16[actorId] = _cursor->iniItemInHand;
|
|
||||||
Actor *actor = _actorManager->getActor(actorId_00);
|
|
||||||
actor->flags = 0;
|
|
||||||
actor->priorityLayer = 0;
|
|
||||||
actor->field_e = 0x100;
|
|
||||||
_cursor->iniItemInHand = 0;
|
_cursor->iniItemInHand = 0;
|
||||||
actor->updateSequence(
|
invActor->setFlag(ACTOR_FLAG_40);
|
||||||
getINI((uint)unkArray_uint16[actorId] - 1)->field_8 * 2 + 10);
|
invActor->setFlag(ACTOR_FLAG_80);
|
||||||
uVar6 = _cursor->_sequenceID;
|
invActor->setFlag(ACTOR_FLAG_100);
|
||||||
actor->setFlag(ACTOR_FLAG_40);
|
invActor->setFlag(ACTOR_FLAG_200);
|
||||||
actor->setFlag(ACTOR_FLAG_80);
|
invActor->priorityLayer = 6;
|
||||||
actor->setFlag(ACTOR_FLAG_100);
|
if (_cursor->_sequenceID == 5) {
|
||||||
actor->setFlag(ACTOR_FLAG_200);
|
|
||||||
actor->priorityLayer = 6;
|
|
||||||
if (uVar6 == 5) {
|
|
||||||
_cursor->_sequenceID = 4;
|
_cursor->_sequenceID = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1219,7 +1185,6 @@ void DragonsEngine::reset() {
|
||||||
opCode1A_tbl[i].field8 = 0;
|
opCode1A_tbl[i].field8 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
|
|
||||||
setSceneUpdateFunction(NULL);
|
setSceneUpdateFunction(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,6 @@ public:
|
||||||
Talk *_talk;
|
Talk *_talk;
|
||||||
Sound *_sound;
|
Sound *_sound;
|
||||||
|
|
||||||
uint16 unkArray_uint16[42];
|
|
||||||
opCode1AStruct opCode1A_tbl[8];
|
opCode1AStruct opCode1A_tbl[8];
|
||||||
|
|
||||||
uint16 data_800633fc;
|
uint16 data_800633fc;
|
||||||
|
|
|
@ -160,11 +160,11 @@ void Inventory::openInventory() {
|
||||||
item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
|
item->x_pos = item->target_x_pos = invXPosTable[i] + 0x10;
|
||||||
item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
|
item->y_pos = item->target_y_pos = invYPosTable[i] + 0xc;
|
||||||
|
|
||||||
if (_vm->unkArray_uint16[i]) {
|
if (unkArray_uint16[i]) {
|
||||||
item->flags = 0; //clear all flags
|
item->flags = 0; //clear all flags
|
||||||
item->field_e = 0x100;
|
item->field_e = 0x100;
|
||||||
item->priorityLayer = 0;
|
item->priorityLayer = 0;
|
||||||
item->updateSequence(_vm->getINI(_vm->unkArray_uint16[i] - 1)->field_8 * 2 + 10);
|
item->updateSequence(_vm->getINI(unkArray_uint16[i] - 1)->field_8 * 2 + 10);
|
||||||
item->setFlag(ACTOR_FLAG_200);
|
item->setFlag(ACTOR_FLAG_200);
|
||||||
item->setFlag(ACTOR_FLAG_100);
|
item->setFlag(ACTOR_FLAG_100);
|
||||||
item->setFlag(ACTOR_FLAG_80);
|
item->setFlag(ACTOR_FLAG_80);
|
||||||
|
@ -247,11 +247,11 @@ void Inventory::draw() {
|
||||||
|
|
||||||
uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
|
uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
|
||||||
for (int i = 0; i < 0x29; i++) {
|
for (int i = 0; i < 0x29; i++) {
|
||||||
if (_vm->unkArray_uint16[i]) {
|
if (unkArray_uint16[i]) {
|
||||||
Actor *item = _vm->_actorManager->getActor(i + 0x17);
|
Actor *item = _vm->_actorManager->getActor(i + 0x17);
|
||||||
if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
|
if (item->x_pos - 0x10 <= x && x < item->x_pos + 0x10
|
||||||
&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
|
&& item->y_pos - 0xc <= y && y < item->y_pos + 0xc) {
|
||||||
return _vm->unkArray_uint16[i];
|
return unkArray_uint16[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,11 +259,12 @@ uint16 Inventory::getIniAtPosition(int16 x, int16 y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Inventory::loadInventoryItemsFromSave() {
|
void Inventory::loadInventoryItemsFromSave() {
|
||||||
|
memset(unkArray_uint16, 0, sizeof(unkArray_uint16));
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < 0x29; i++ ) {
|
for (int i=0; i < _vm->_dragonINIResource->totalRecords() && j < 0x29; i++ ) {
|
||||||
DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
|
DragonINI *ini = _vm->_dragonINIResource->getRecord(i);
|
||||||
if (ini->sceneId == 1) {
|
if (ini->sceneId == 1) {
|
||||||
_vm->unkArray_uint16[j++] = i + 1;
|
unkArray_uint16[j++] = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,4 +333,56 @@ void Inventory::setPositionFromSceneId(uint32 sceneId) {
|
||||||
_actor->y_pos = positionTable[_screenPositionIndex].y;
|
_actor->y_pos = positionTable[_screenPositionIndex].y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Inventory::addItem(uint16 initId) {
|
||||||
|
for (int i = 0; i < 0x29; i++) {
|
||||||
|
if (unkArray_uint16[i] == 0) {
|
||||||
|
unkArray_uint16[i] = initId;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Actor *Inventory::getInventoryItemActor(uint16 iniId) {
|
||||||
|
for (int i = 0; i < 0x29; i++) {
|
||||||
|
if (unkArray_uint16[i] == iniId) {
|
||||||
|
return _vm->_actorManager->getActor(i + 0x17);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
error("getInventoryItemActor(%d) not found", iniId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Inventory::replaceItem(uint16 existingIniId, uint16 newIniId) {
|
||||||
|
for (int i = 0; i < 0x29; i++) {
|
||||||
|
if (unkArray_uint16[i] == existingIniId) {
|
||||||
|
unkArray_uint16[i] = newIniId;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Actor *Inventory::addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y) {
|
||||||
|
for (int i = 0; i < 0x29; i++) {
|
||||||
|
Actor *actor = _vm->_actorManager->getActor(i + 0x17);
|
||||||
|
if ((((actor->x_pos - 0x10 <= x) &&
|
||||||
|
(x < actor->x_pos + 0x10)) &&
|
||||||
|
(actor->y_pos - 0xc <= y)) &&
|
||||||
|
(y < actor->y_pos + 0xc)) {
|
||||||
|
unkArray_uint16[i] = iniId;
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Inventory::clearItem(uint16 iniId) {
|
||||||
|
for (int i = 0; i < 0x29; i++) {
|
||||||
|
if(unkArray_uint16[i] == iniId) {
|
||||||
|
unkArray_uint16[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // End of namespace Dragons
|
} // End of namespace Dragons
|
|
@ -50,6 +50,7 @@ private:
|
||||||
uint16 inventionBookPrevFlickerINISceneId;
|
uint16 inventionBookPrevFlickerINISceneId;
|
||||||
Common::Point inventionBookPrevFlickerINIPosition;
|
Common::Point inventionBookPrevFlickerINIPosition;
|
||||||
|
|
||||||
|
uint16 unkArray_uint16[42];
|
||||||
public:
|
public:
|
||||||
Inventory(DragonsEngine *vm);
|
Inventory(DragonsEngine *vm);
|
||||||
|
|
||||||
|
@ -88,6 +89,14 @@ public:
|
||||||
|
|
||||||
void openInventionBook();
|
void openInventionBook();
|
||||||
void closeInventionBook();
|
void closeInventionBook();
|
||||||
|
|
||||||
|
bool addItem(uint16 iniId);
|
||||||
|
Actor *addItemIfPositionIsEmpty(uint16 iniId, uint16 x, uint16 y);
|
||||||
|
void replaceItem(uint16 existingIniId, uint16 newIniId);
|
||||||
|
bool clearItem(uint16 iniId);
|
||||||
|
|
||||||
|
Actor *getInventoryItemActor(uint16 iniId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setPositionFromSceneId(uint32 sceneId);
|
void setPositionFromSceneId(uint32 sceneId);
|
||||||
void animateBagIn();
|
void animateBagIn();
|
||||||
|
|
|
@ -1176,12 +1176,9 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
|
||||||
_vm->_cursor->iniItemInHand = 0;
|
_vm->_cursor->iniItemInHand = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (int i = 0; i < 0x29; i++) {
|
if (_vm->_inventory->clearItem(ini->id + 1)) {
|
||||||
if (_vm->unkArray_uint16[i] - 1 == ini->id) {
|
if (_vm->_inventory->getType() == 1) {
|
||||||
_vm->unkArray_uint16[i] = 0;
|
ini->actor->clearFlag(ACTOR_FLAG_40);
|
||||||
if (_vm->_inventory->getType() == 1) {
|
|
||||||
ini->actor->clearFlag(ACTOR_FLAG_40);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1189,19 +1186,13 @@ void ScriptOpcodes::opCode_Unk7(ScriptOpCall &scriptOpCall) {
|
||||||
|
|
||||||
if (sceneId == 1) {
|
if (sceneId == 1) {
|
||||||
if (_vm->_cursor->iniItemInHand != 0) {
|
if (_vm->_cursor->iniItemInHand != 0) {
|
||||||
uint16 freeSlot = 0;
|
_vm->_inventory->addItem(_vm->_cursor->iniItemInHand);
|
||||||
for( ;_vm->unkArray_uint16[freeSlot] != 0; freeSlot++) {
|
|
||||||
if (_vm->unkArray_uint16[freeSlot] == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_vm->unkArray_uint16[freeSlot] = _vm->_cursor->iniItemInHand;
|
|
||||||
if (_vm->_inventory->getType() == 1) {
|
if (_vm->_inventory->getType() == 1) {
|
||||||
Actor *actor = _vm->_actorManager->getActor(freeSlot + 0x17);
|
Actor *actor = _vm->_inventory->getInventoryItemActor(_vm->_cursor->iniItemInHand);
|
||||||
actor->flags = 0;
|
actor->flags = 0;
|
||||||
actor->priorityLayer = 0;
|
actor->priorityLayer = 0;
|
||||||
actor->field_e = 0x100;
|
actor->field_e = 0x100;
|
||||||
actor->updateSequence((_vm->getINI(_vm->unkArray_uint16[freeSlot] - 1)->field_8 * 2 + 10) & 0xfffe);
|
actor->updateSequence((_vm->getINI(_vm->_cursor->iniItemInHand - 1)->field_8 * 2 + 10) & 0xfffe);
|
||||||
actor->setFlag(ACTOR_FLAG_40);
|
actor->setFlag(ACTOR_FLAG_40);
|
||||||
actor->setFlag(ACTOR_FLAG_80);
|
actor->setFlag(ACTOR_FLAG_80);
|
||||||
actor->setFlag(ACTOR_FLAG_100);
|
actor->setFlag(ACTOR_FLAG_100);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue