diff options
author | Willem Jan Palenstijn | 2011-12-18 15:32:25 +0100 |
---|---|---|
committer | Willem Jan Palenstijn | 2011-12-18 16:01:06 +0100 |
commit | 8449493eff5ff26e8550dec6c50470521fc31947 (patch) | |
tree | 7d9eff8220801e82a5dbd5ab782704672027d121 /engines/dreamweb/object.cpp | |
parent | ebbc8ae3d2f7b868d4392b3df82ec1f332599dd7 (diff) | |
download | scummvm-rg350-8449493eff5ff26e8550dec6c50470521fc31947.tar.gz scummvm-rg350-8449493eff5ff26e8550dec6c50470521fc31947.tar.bz2 scummvm-rg350-8449493eff5ff26e8550dec6c50470521fc31947.zip |
DREAMWEB: Convert removeObFromInv, deleteExObject, deleteExFrame, deleteExText
Diffstat (limited to 'engines/dreamweb/object.cpp')
-rw-r--r-- | engines/dreamweb/object.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/engines/dreamweb/object.cpp b/engines/dreamweb/object.cpp index 53ecc0c362..384e001b5e 100644 --- a/engines/dreamweb/object.cpp +++ b/engines/dreamweb/object.cpp @@ -477,4 +477,90 @@ void DreamGenContext::setPickup() { workToScreenM(); } +void DreamGenContext::deleteExFrame() { + deleteExFrame(al); +} + +void DreamBase::deleteExFrame(uint8 frameNum) { + Frame *frame = (Frame *)getSegment(data.word(kExtras)).ptr(kExframedata + sizeof(Frame)*frameNum, sizeof(Frame)); + + uint16 frameSize = frame->width * frame->height; + // Note: the original asm didn't subtract frameSize from remainder + uint16 remainder = kExframeslen - frame->ptr() - frameSize; + uint16 startOff = kExframes + frame->ptr(); + uint16 endOff = startOff + frameSize; + + // Shift frame data after this one down + memmove(getSegment(data.word(kExtras)).ptr(startOff, remainder), getSegment(data.word(kExtras)).ptr(endOff, remainder), remainder); + + // Combined frame data is now frameSize smaller + data.word(kExframepos) -= frameSize; + + // Adjust all frame pointers pointing into the shifted data + for (unsigned int i = 0; i < 3*kNumexobjects; ++i) { + frame = (Frame *)getSegment(data.word(kExtras)).ptr(kExframedata + sizeof(Frame)*i, sizeof(Frame)); + if (frame->ptr() >= startOff) + frame->setPtr(frame->ptr() - frameSize); + } +} + +void DreamGenContext::deleteExText() { + deleteExText(al); +} + +void DreamBase::deleteExText(uint8 textNum) { + uint16 offset = getSegment(data.word(kExtras)).word(kExtextdat + 2*textNum); + + uint16 startOff = kExtext + offset; + uint16 textSize = strlen((char *)getSegment(data.word(kExtras)).ptr(startOff, 0)) + 1; + uint16 endOff = startOff + textSize; + uint16 remainder = kExtextlen - offset - textSize; + + // Shift text data after this one down + memmove(getSegment(data.word(kExtras)).ptr(startOff, remainder), getSegment(data.word(kExtras)).ptr(endOff, remainder), remainder); + + // Combined text data is now frameSize smaller + data.word(kExtextpos) -= textSize; + + // Adjust all text pointers pointing into the shifted data + for (unsigned int i = 0; i < kNumexobjects; ++i) { + uint16 t = getSegment(data.word(kExtras)).word(kExtextdat + 2*i); + if (t >= offset + textSize) + getSegment(data.word(kExtras)).word(kExtextdat + 2*i) = t - textSize; + } +} + +// This takes es:di and cl as input, but es:di always points to getExAd(cl) +void DreamGenContext::deleteExObject() { + deleteExObject(cl); +} + +void DreamBase::deleteExObject(uint8 index) { + DynObject *obj = getExAd(index); + + memset(obj, 0xFF, sizeof(DynObject)); + + deleteExFrame(3*index); + deleteExFrame(3*index + 1); + + deleteExText(index); + + for (uint8 i = 0; i < kNumexobjects; ++i) { + DynObject *t = getExAd(index); + // Is this object contained in the one we've just deleted? + if (t->mapad[0] == 4 && t->mapad[1] == index) + deleteExObject(i); + } +} + +void DreamBase::removeObFromInv() { + if (data.byte(kCommand) == 100) + return; // object doesn't exit + + assert(data.byte(kObjecttype) == kExObjectType); + + deleteExObject(data.byte(kCommand)); +} + + } // End of namespace DreamGen |