1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "dreamweb/sound.h"
#include "dreamweb/dreamweb.h"
namespace DreamWeb {
void DreamWebEngine::showRain() {
Common::List<Rain>::iterator i;
// Do nothing if there's no rain at all
if (_rainList.empty())
return;
const uint8 *frameData = _mainSprites.getFrameData(58);
for (i = _rainList.begin(); i != _rainList.end(); ++i) {
Rain &rain = *i;
uint16 y = rain.y + _mapAdY + _mapYStart;
uint16 x = rain.x + _mapAdX + _mapXStart;
uint16 size = rain.size;
uint16 offset = (rain.w3 - rain.b5) & 511;
rain.w3 = offset;
const uint8 *src = frameData + offset;
uint8 *dst = workspace() + y * kScreenwidth + x;
for (uint16 j = 0; j < size; ++j) {
uint8 v = src[j];
if (v != 0)
*dst = v;
dst += kScreenwidth-1; // advance diagonally
}
}
if (_sound->isChannel1Playing())
return;
if (_realLocation == 2 && _vars._beenMugged != 1)
return;
if (_realLocation == 55)
return;
if (randomNumber() >= 1) // play thunder with 1 in 256 chance
return;
uint8 soundIndex;
if (_sound->getChannel0Playing() != 6)
soundIndex = 4;
else
soundIndex = 7;
_sound->playChannel1(soundIndex);
}
uint8 DreamWebEngine::getBlockOfPixel(uint8 x, uint8 y) {
uint8 flag, flagEx, type, flagX, flagY;
checkOne(x + _mapXStart, y + _mapYStart, &flag, &flagEx, &type, &flagX, &flagY);
if (flag & 1)
return 0;
else
return type;
}
void DreamWebEngine::splitIntoLines(uint8 x, uint8 y) {
do {
Rain rain;
// Look for line start
while (!getBlockOfPixel(x, y)) {
--x;
++y;
if (x == 0 || y >= _mapYSize)
return;
}
rain.x = x;
rain.y = y;
uint8 length = 1;
// Look for line end
while (getBlockOfPixel(x, y)) {
--x;
++y;
if (x == 0 || y >= _mapYSize)
break;
++length;
}
rain.size = length;
rain.w3 = _rnd.getRandomNumber(65535);
rain.b5 = _rnd.getRandomNumberRng(4, 7);
_rainList.push_back(rain);
} while (x > 0 && y < _mapYSize);
}
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 DreamWebEngine::initRain() {
const RainLocation *r = rainLocationList;
_rainList.clear();
uint8 rainSpacing = 0;
// look up location in rainLocationList to determine rainSpacing
for (r = rainLocationList; r->location != 0xff; ++r) {
if (r->location == _realLocation &&
r->x == _mapX && r->y == _mapY) {
rainSpacing = r->rainSpacing;
break;
}
}
if (rainSpacing == 0) {
// location not found in rainLocationList: no rain
return;
}
// start lines of rain from top of screen
uint8 x = 4;
do {
uint8 delta = _rnd.getRandomNumberRng(3, rainSpacing - 1);
x += delta;
if (x >= _mapXSize)
break;
splitIntoLines(x, 0);
} while (true);
// start lines of rain from side of screen
uint8 y = 0;
do {
uint8 delta = _rnd.getRandomNumberRng(3, rainSpacing - 1);
y += delta;
if (y >= _mapYSize)
break;
splitIntoLines(_mapXSize - 1, y);
} while (true);
}
} // End of namespace DreamWeb
|