From c2a94132c8adf8bec5914ca6fa2e312248e1c2bd Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 26 Dec 2011 18:42:28 +0100 Subject: DREAMWEB: Convert pickupConts --- engines/dreamweb/dreambase.h | 2 ++ engines/dreamweb/dreamgen.cpp | 69 ------------------------------------------- engines/dreamweb/dreamgen.h | 2 -- engines/dreamweb/object.cpp | 50 +++++++++++++++++++++++++------ engines/dreamweb/stubs.cpp | 7 +++-- engines/dreamweb/stubs.h | 7 ++--- 6 files changed, 50 insertions(+), 87 deletions(-) (limited to 'engines') diff --git a/engines/dreamweb/dreambase.h b/engines/dreamweb/dreambase.h index 4b9919de7a..b134159a2e 100644 --- a/engines/dreamweb/dreambase.h +++ b/engines/dreamweb/dreambase.h @@ -219,6 +219,8 @@ public: void findAllOpen(); void fillOpen(); ObjectRef findInvPos(); + void reExFromInv(); + void swapWithInv(); // from pathfind.cpp void turnPathOn(uint8 param); diff --git a/engines/dreamweb/dreamgen.cpp b/engines/dreamweb/dreamgen.cpp index 424c4ab71e..356ebc8d36 100644 --- a/engines/dreamweb/dreamgen.cpp +++ b/engines/dreamweb/dreamgen.cpp @@ -73,75 +73,6 @@ void DreamGenContext::transferMap() { _add(data.word(kExframepos), cx); } -void DreamGenContext::pickupConts() { - STACK_CHECK; - al = ds.byte(si+7); - _cmp(al, 255); - if (flags.z()) - return /* (notopenable) */; - al = data.byte(kItemframe); - ah = data.byte(kObjecttype); - dl = data.byte(kExpos); - es = data.word(kFreedat); - bx = 0; - cx = 0; -pickupcontloop: - push(cx); - push(es); - push(bx); - push(dx); - push(ax); - _cmp(es.byte(bx+2), ah); - if (!flags.z()) - goto notinsidethis; - _cmp(es.byte(bx+3), al); - if (!flags.z()) - goto notinsidethis; - data.byte(kItemtotran) = cl; - transferConToEx(); -notinsidethis: - ax = pop(); - dx = pop(); - bx = pop(); - es = pop(); - cx = pop(); - _add(bx, 16); - _inc(cx); - _cmp(cx, 80); - if (!flags.z()) - goto pickupcontloop; -} - -void DreamGenContext::transferConToEx() { - STACK_CHECK; - push(es); - push(bx); - push(dx); - push(es); - push(bx); - getExPos(); - si = pop(); - ds = pop(); - push(di); - cx = 8; - _movsw(cx, true); - di = pop(); - dx = pop(); - al = data.byte(kReallocation); - es.byte(di) = al; - es.byte(di+11) = al; - al = data.byte(kItemtotran); - es.byte(di+1) = al; - es.byte(di+3) = dl; - es.byte(di+2) = 4; - transferMap(); - transferInv(); - transferText(); - si = pop(); - ds = pop(); - ds.byte(si+2) = 255; -} - void DreamGenContext::read() { STACK_CHECK; cx = 40; diff --git a/engines/dreamweb/dreamgen.h b/engines/dreamweb/dreamgen.h index 41c252ed72..0c61a60a6e 100644 --- a/engines/dreamweb/dreamgen.h +++ b/engines/dreamweb/dreamgen.h @@ -425,13 +425,11 @@ public: #include "stubs.h" // Allow hand-reversed functions to have a signature different than void f() void dirFile(); - void pickupConts(); void transferMap(); void dreamweb(); void read(); void searchForString(); void parser(); - void transferConToEx(); }; } // End of namespace DreamGen diff --git a/engines/dreamweb/object.cpp b/engines/dreamweb/object.cpp index 5d0fbab7ee..9799ca4726 100644 --- a/engines/dreamweb/object.cpp +++ b/engines/dreamweb/object.cpp @@ -712,7 +712,7 @@ void DreamBase::dropObject() { object->currentLocation = data.byte(kReallocation); } -bool DreamGenContext::checkObjectSizeCPP() { +bool DreamGenContext::checkObjectSize() { byte containerSize = getOpenedSlotSize(); DynObject *object = getEitherAdCPP(); // If there is no size defined for the object in the editor, set its size @@ -774,7 +774,7 @@ void DreamGenContext::selectOpenOb() { delPointer(); } -void DreamGenContext::reExFromInv() { +void DreamBase::reExFromInv() { ObjectRef objectId = findInvPos(); data.byte(kCommandtype) = objectId._type; data.byte(kCommand) = objectId._index; @@ -782,7 +782,7 @@ void DreamGenContext::reExFromInv() { data.byte(kPointermode) = 0; } -void DreamGenContext::swapWithInv() { +void DreamBase::swapWithInv() { ObjectRef subject; subject._type = data.byte(kObjecttype); subject._index = data.byte(kItemframe); @@ -868,7 +868,7 @@ void DreamGenContext::useOpened() { return; } - if (!checkObjectSizeCPP()) + if (!checkObjectSize()) return; data.byte(kPickup) = 0; @@ -964,7 +964,7 @@ void DreamGenContext::swapWithOpen() { return; } - if (!checkObjectSizeCPP()) + if (!checkObjectSize()) return; byte prevType = data.byte(kObjecttype); @@ -1012,9 +1012,8 @@ ObjectRef DreamBase::findOpenPos() { byte DreamGenContext::transferToEx() { emergencyPurge(); - getExPos(); + DynObject *exObject = getExPos(); // Also sets es:di byte pos = data.byte(kExpos); - DynObject *exObject = getExAd(pos); DynObject *freeObject = getFreeAd(data.byte(kItemframe)); memcpy(exObject, freeObject, sizeof(DynObject)); exObject->currentLocation = data.byte(kReallocation); @@ -1029,8 +1028,6 @@ byte DreamGenContext::transferToEx() { transferText(); freeObject = getFreeAd(data.byte(kItemframe)); freeObject->mapad[0] = 254; - ds = data.word(kFreedat); - si = data.byte(kItemframe) * sizeof(DynObject); pickupConts(); return pos; } @@ -1078,4 +1075,39 @@ void DreamBase::findAllOpen() { } } +void DreamGenContext::pickupConts() { + assert(data.byte(kObjecttype) == kFreeObjectType); + const DynObject *obj = getFreeAd(data.byte(kItemframe)); + + if (obj->slotCount == 255) + return; // not openable + + uint8 expos = data.byte(kExpos); + + for (uint16 index = 0; index < 80; ++index) { + DynObject *freeObj = getFreeAd(index); + + if (freeObj->mapad[0] != data.byte(kObjecttype)) + continue; + if (freeObj->mapad[1] != data.byte(kItemframe)) + continue; + data.byte(kItemtotran) = index; + + DynObject *exObj = getExPos(); // Also sets es:di to exObj + + memcpy(exObj, freeObj, sizeof(DynObject)); + exObj->currentLocation = data.byte(kReallocation); + exObj->initialLocation = data.byte(kReallocation); + exObj->index = index; + exObj->mapad[0] = 4; // kExObjectType? + exObj->mapad[1] = expos; + + transferMap(); + transferInv(); + transferText(); + + freeObj->mapad[0] = 0xFF; + } +} + } // End of namespace DreamGen diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp index 87bca3d67c..9351a01bb5 100644 --- a/engines/dreamweb/stubs.cpp +++ b/engines/dreamweb/stubs.cpp @@ -1364,18 +1364,19 @@ void DreamBase::deleteTaken() { } } -void DreamGenContext::getExPos() { +DynObject *DreamGenContext::getExPos() { es = data.word(kExtras); - const DynObject *objects = (const DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, sizeof(DynObject)); + DynObject *objects = (DynObject *)getSegment(data.word(kExtras)).ptr(kExdata, sizeof(DynObject)); for (size_t i = 0; i < kNumexobjects; ++i) { if (objects[i].mapad[0] == 0xff) { data.byte(kExpos) = i; di = kExdata + i * sizeof(DynObject); - return; + return &objects[i]; } } data.byte(kExpos) = kNumexobjects; di = kExdata + kNumexobjects * sizeof(DynObject); + return 0; } void DreamBase::placeSetObject(uint8 index) { diff --git a/engines/dreamweb/stubs.h b/engines/dreamweb/stubs.h index 5577c772d5..8bdc0b11c0 100644 --- a/engines/dreamweb/stubs.h +++ b/engines/dreamweb/stubs.h @@ -66,7 +66,7 @@ void walkAndExamine(); void obName(uint8 command, uint8 commandType); - void getExPos(); + DynObject *getExPos(); bool checkIfSet(uint8 x, uint8 y); void obToInv(); void obToInv(uint8 index, uint8 flag, uint16 x, uint16 y) { @@ -118,7 +118,7 @@ void triggerMessage(uint16 index); void processTrigger(); bool execCommand(); - bool checkObjectSizeCPP(); + bool checkObjectSize(); void identifyOb(); void selectOb(); void setPickup(); @@ -127,13 +127,12 @@ void inToInv(); void outOfInv(); void selectOpenOb(); - void reExFromInv(); void useOpened(); void outOfOpen(); void swapWithOpen(); - void swapWithInv(); void searchForFiles(uint16 segment); byte transferToEx(); void dirCom(); + void pickupConts(); #endif -- cgit v1.2.3