diff options
Diffstat (limited to 'engines/dreamweb/sprite.cpp')
-rw-r--r-- | engines/dreamweb/sprite.cpp | 155 |
1 files changed, 136 insertions, 19 deletions
diff --git a/engines/dreamweb/sprite.cpp b/engines/dreamweb/sprite.cpp index 3b67bfbd72..34b0729535 100644 --- a/engines/dreamweb/sprite.cpp +++ b/engines/dreamweb/sprite.cpp @@ -494,43 +494,30 @@ void DreamGenContext::facerightway() { data.byte(kLeavedirection) = dir; } -void DreamGenContext::findsource() { +Frame *DreamGenContext::findsource() { uint16 currentFrame = data.word(kCurrentframe); if (currentFrame < 160) { - ds = data.word(kReel1); data.word(kTakeoff) = 0; + return (Frame *)segRef(data.word(kReel1)).ptr(0, 0); } else if (currentFrame < 320) { - ds = data.word(kReel2); data.word(kTakeoff) = 160; + return (Frame *)segRef(data.word(kReel2)).ptr(0, 0); } else { - ds = data.word(kReel3); data.word(kTakeoff) = 320; + return (Frame *)segRef(data.word(kReel3)).ptr(0, 0); } } -Frame *DreamGenContext::findsourceCPP() { - push(ds); - findsource(); - Frame *result = (Frame *)ds.ptr(0, 0); - ds = pop(); - return result; -} - Reel *DreamGenContext::getreelstart() { Reel *reel = (Reel *)segRef(data.word(kReels)).ptr(kReellist + data.word(kReelpointer) * sizeof(Reel) * 8, sizeof(Reel)); return reel; } -void DreamGenContext::showreelframe() { - Reel *reel = (Reel *)es.ptr(si, sizeof(Reel)); - showreelframe(reel); -} - void DreamGenContext::showreelframe(Reel *reel) { uint16 x = reel->x + data.word(kMapadx); uint16 y = reel->y + data.word(kMapady); data.word(kCurrentframe) = reel->frame(); - Frame *source = findsourceCPP(); + Frame *source = findsource(); uint16 frame = data.word(kCurrentframe) - data.word(kTakeoff); showframe(source, x, y, frame, 8); } @@ -550,7 +537,7 @@ void DreamGenContext::showgamereel(ReelRoutine *routine) { const Frame *DreamGenContext::getreelframeax(uint16 frame) { data.word(kCurrentframe) = frame; - Frame *source = findsourceCPP(); + Frame *source = findsource(); uint16 offset = data.word(kCurrentframe) - data.word(kTakeoff); return source + offset; } @@ -602,6 +589,10 @@ void DreamGenContext::updatepeople() { data.word(kListpos) = kPeoplelist; memset(segRef(data.word(kBuffers)).ptr(kPeoplelist, 12 * sizeof(People)), 0xff, 12 * sizeof(People)); ++data.word(kMaintimer); + + // The callbacks are called with es:bx pointing to their reelRoutine entry. + // They use some of the fields in it to store state. + es = cs; bx = kReelroutines; const ReelRoutine *reelRoutine = (const ReelRoutine *)cs.ptr(bx, 0); @@ -903,5 +894,131 @@ void DreamGenContext::addtopeoplelist(ReelRoutine *routine) { data.word(kListpos) += sizeof(People); } +Rain *DreamGenContext::splitintolines(uint8 x, uint8 y, Rain *rain) { + do { + // Look for line start + while (!getblockofpixel(x, y)) { + --x; + ++y; + if (x == 0 || y >= data.byte(kMapysize)) + return rain; + } + + rain->x = x; + rain->y = y; + + uint8 length = 1; + + // Look for line end + while (getblockofpixel(x, y)) { + --x; + ++y; + if (x == 0 || y >= data.byte(kMapysize)) + break; + ++length; + } + + rain->size = length; + rain->w3_lo = engine->randomNumber(); + rain->w3_hi = engine->randomNumber(); + rain->b5 = (engine->randomNumber() & 3) + 4; + ++rain; + } while (x > 0 && y < data.byte(kMapysize)); + + return rain; +} + +struct RainLocation { + uint8 location; + uint8 x, y; + uint8 rainSpacing; +}; + +static const RainLocation rainLocationList[] = { + { 1,44,10,16 }, + { 4,11,30,14 }, + { 4,22,30,14 }, + { 3,33,10,14 }, + { 10,33,30,14 }, + { 10,22,30,24 }, + { 9,22,10,14 }, + { 2,33,0,14 }, + { 2,22,0,14 }, + { 6,11,30,14 }, + { 7,11,20,18 }, + { 7,0,20,18 }, + { 7,0,30,18 }, + { 55,44,0,14 }, + { 5,22,30,14 }, + + { 8,0,10,18 }, + { 8,11,10,18 }, + { 8,22,10,18 }, + { 8,33,10,18 }, + { 8,33,20,18 }, + { 8,33,30,18 }, + { 8,33,40,18 }, + { 8,22,40,18 }, + { 8,11,40,18 }, + + { 21,44,20,18 }, + { 255,0,0,0 } +}; + +void DreamGenContext::initrain() { + const RainLocation *r = rainLocationList; + Rain *rainList = (Rain *)segRef(data.word(kBuffers)).ptr(kRainlist, 0); + Rain *rain = rainList; + + uint8 rainSpacing = 0; + + // look up location in rainLocationList to determine rainSpacing + for (r = rainLocationList; r->location != 0xff; ++r) { + if (r->location == data.byte(kReallocation) && + r->x == data.byte(kMapx) && r->y == data.byte(kMapy)) { + rainSpacing = r->rainSpacing; + break; + } + } + + if (rainSpacing == 0) { + // location not found in rainLocationList: no rain + rain->x = 0xff; + return; + } + + // start lines of rain from top of screen + uint8 x = 4; + do { + uint8 delta; + do { + delta = (engine->randomNumber() & 31) + 3; + } while (delta >= rainSpacing); + + x += delta; + if (x >= data.byte(kMapxsize)) + break; + + rain = splitintolines(x, 0, rain); + } while (true); + + // start lines of rain from side of screen + uint8 y = 0; + do { + uint8 delta; + do { + delta = (engine->randomNumber() & 31) + 3; + } while (delta >= rainSpacing); + + y += delta; + if (y >= data.byte(kMapysize)) + break; + + rain = splitintolines(data.byte(kMapxsize) - 1, y, rain); + } while (true); + + rain->x = 0xff; +} + } /*namespace dreamgen */ |