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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "asylum/puzzles/wheel.h"
#include "asylum/resources/special.h"
#include "asylum/resources/worldstats.h"
#include "asylum/system/cursor.h"
#include "asylum/system/graphics.h"
#include "asylum/system/screen.h"
#include "asylum/views/scene.h"
#include "asylum/asylum.h"
namespace Asylum {
const GameFlag puzzleWheelFlags[32] = {
kGameFlag253, kGameFlag257, kGameFlag259, kGameFlag254, kGameFlag258,
kGameFlag260, kGameFlag253, kGameFlag255, kGameFlag259, kGameFlag254,
kGameFlag256, kGameFlag260, kGameFlag253, kGameFlag255, kGameFlag257,
kGameFlag254, kGameFlag256, kGameFlag258, kGameFlag255, kGameFlag257,
kGameFlag259, kGameFlag256, kGameFlag258, kGameFlag260, kGameFlag253,
kGameFlag254, kGameFlag255, kGameFlag256, kGameFlag257, kGameFlag258,
kGameFlag259, kGameFlag260
};
const uint32 puzzleWheelContacts[24] = {
1, 5, 7, 2, 6,
8, 1, 3, 7, 2,
4, 8, 1, 3, 5,
2, 4, 6, 3, 5,
7, 4, 6, 8
};
const uint32 puzzleWheelSparks[8] = {
0, 6, 5, 4, 1, 3, 7, 2
};
const uint32 puzzleWheelClockResourceIndexes[16] = {
39, 40, 42, 44, 46,
48, 50, 52, 38, 41,
43, 45, 47, 49, 51,
53
};
const int16 puzzleWheelPoints[56][2] = {
{ 0, 0}, { 0, 0}, { 0, 0}, {250, 254}, {122, 24}, {208, 68}, {238, 160},
{218, 234}, {162, 228}, { 71, 222}, { 22, 165}, { 35, 70}, {278, 0}, {536, 146},
{122, 24}, {208, 68}, {238, 160}, {218, 234}, {162, 228}, { 71, 222}, { 22, 165},
{ 35, 70}, {342, 87}, {342, 87}, {342, 87}, {342, 87}, {342, 87}, {342, 87},
{342, 87}, {342, 87}, {358, 268}, {342, 87}, {342, 87}, {342, 87}, {342, 87},
{342, 87}, {342, 87}, {342, 87}, {342, 87}, {342, 87}, {342, 87}, {342, 87},
{342, 87}, {342, 87}, {342, 87}, {342, 87}, {342, 87}, {536, 146}, {406, 106},
{402, 217}, {369, 128}, {368, 197}, {452, 184}, {470, 144}, {442, 116}, {347, 166}
};
const int16 puzzleWheelRects[4][4] = {
{425, 268, 491, 407}, {358, 268, 424, 407}, {561, 251, 594, 324}, {280, 276, 310, 400}
};
PuzzleWheel::PuzzleWheel(AsylumEngine *engine) : Puzzle(engine) {
_currentRect = -1;
_resourceIndex = 0;
_resourceIndexClock = 0;
_resourceIndexLever = 13;
_frameIndexWheel = 0;
memset(&_frameIndexes, 0, sizeof(_frameIndexes));
memset(&_frameIndexesSparks, -1, sizeof(_frameIndexesSparks));
_showTurnedClock = false;
_turnWheelRight = false;
_moveLever = false;
_moveChain = false;
}
PuzzleWheel::~PuzzleWheel() {
}
void PuzzleWheel::saveLoadWithSerializer(Common::Serializer &s) {
s.syncAsSint32LE(_resourceIndex);
}
//////////////////////////////////////////////////////////////////////////
// Event Handling
//////////////////////////////////////////////////////////////////////////
bool PuzzleWheel::init(const AsylumEvent &) {
getSpecial()->reset(false);
getScreen()->setPalette(getWorld()->graphicResourceIds[1]);
getScreen()->setGammaLevel(getWorld()->graphicResourceIds[1]);
updateCursor();
getCursor()->show();
_currentRect = -2;
memset(&_frameIndexesSparks, -1, sizeof(_frameIndexesSparks));
for (uint32 i = 0; i < 8; i++) {
if (_vm->isGameFlagSet((GameFlag)(kGameFlag253 + i)))
_frameIndexes[i + 1] = GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[i + 14]) - 1;
else
_frameIndexes[i + 1] = GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[i + 4]) - 1;
}
return true;
}
void PuzzleWheel::updateScreen() {
getScreen()->clearGraphicsInQueue();
getScreen()->draw(getWorld()->graphicResourceIds[0]);
// Blinking red light
getScreen()->draw(getWorld()->graphicResourceIds[12], (uint32)_frameIndexes[11], &puzzleWheelPoints[12]);
_frameIndexes[11] = (_frameIndexes[11] + 1) % (int32)GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[12]);
// Clock
if (_showTurnedClock)
getScreen()->draw(getWorld()->graphicResourceIds[_resourceIndexClock], (uint32)_frameIndexes[9], Common::Point(342, 87));
else
getScreen()->draw(getWorld()->graphicResourceIds[_resourceIndex + 22], 0, Common::Point(342, 87));
// Chain
getScreen()->draw(getWorld()->graphicResourceIds[3], (uint32)_frameIndexes[0], &puzzleWheelPoints[3]);
// Update chain frame index
if (_moveChain) {
if (!_frameIndexes[0]) {
getCursor()->hide();
getSound()->playSound(getWorld()->graphicResourceIds[65]);
}
_frameIndexes[0] = (_frameIndexes[0] + 1) % (int32)GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[3]);
if (!_frameIndexes[0]) {
closeLocks();
_moveChain = false;
getCursor()->show();
}
}
// Locks
uint32 frameIndex = 1;
for (uint32 i = 0; i < 8; i++) {
ResourceId resourceIndex = 0;
uint32 pointIndex = 0;
if (_vm->isGameFlagSet((GameFlag)(kGameFlag253 + i))) {
resourceIndex = 14 + i;
pointIndex = 10 + (4 + i);
} else {
resourceIndex = 4 + i;
pointIndex = 4 + i;
}
getScreen()->draw(getWorld()->graphicResourceIds[resourceIndex], (uint32)_frameIndexes[frameIndex], &puzzleWheelPoints[pointIndex]);
if (_frameIndexes[frameIndex] != (int32)GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[resourceIndex]) - 1)
++_frameIndexes[frameIndex];
++frameIndex;
}
// Sparks
for (uint32 i = 0; i < 8; i++) {
if (_frameIndexesSparks[i] >= 0) {
getScreen()->draw(getWorld()->graphicResourceIds[57 + i], (uint32)_frameIndexesSparks[i], &puzzleWheelPoints[48 + i]);
if (_frameIndexesSparks[i] == (int32)GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[57 + i]) - 1)
_frameIndexesSparks[i] = -1;
else
++_frameIndexesSparks[i];
}
}
// Lever
if (_resourceIndexLever == 13)
getScreen()->draw(getWorld()->graphicResourceIds[_resourceIndexLever], (uint32)_frameIndexes[10], &puzzleWheelPoints[13]);
else if (_resourceIndexLever == 54)
getScreen()->draw(getWorld()->graphicResourceIds[_resourceIndexLever], (uint32)_frameIndexes[10], &puzzleWheelPoints[47]);
// Update lever frame index
if (_moveLever) {
if (!_frameIndexes[10] && _resourceIndexLever == 13) {
getCursor()->hide();
getSound()->playSound(getWorld()->graphicResourceIds[67]);
}
_frameIndexes[10] = (_frameIndexes[10] + 1) % (int32)GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[_resourceIndexLever]);
if (!_frameIndexes[10]) {
if (_resourceIndexLever == 54) {
_resourceIndexLever = 13;
toggleLocks();
_moveLever = false;
getCursor()->show();
} else {
_resourceIndexLever = 54;
}
}
}
// Wheel
getScreen()->draw(getWorld()->graphicResourceIds[30], _frameIndexWheel, &puzzleWheelPoints[30]);
// Update wheel frame index
if (_showTurnedClock) {
if (!_frameIndexes[9]) {
getCursor()->hide();
getSound()->playSound(getWorld()->graphicResourceIds[66]);
}
uint32 frameCountWheel = GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[30]);
if (_turnWheelRight)
_frameIndexWheel = (_frameIndexWheel + 1) % frameCountWheel;
else
_frameIndexWheel = (_frameIndexWheel + frameCountWheel - 1) % frameCountWheel;
_frameIndexes[9] = (_frameIndexes[9] + 1) % (int32)GraphicResource::getFrameCount(_vm, getWorld()->graphicResourceIds[_resourceIndexClock]);
if (!_frameIndexes[9]) {
_showTurnedClock = false;
getCursor()->show();
}
}
//////////////////////////////////////////////////////////////////////////
// Show elements on screen
getScene()->drawRain();
// Check for completion
checkFlags();
}
bool PuzzleWheel::mouseLeftDown(const AsylumEvent &) {
switch (findRect()) {
default:
break;
case 0: // Wheel right
_frameIndexes[9] = 0;
_turnWheelRight = true;
_showTurnedClock = true;
updateIndex();
break;
case 1: // Wheel left
_frameIndexes[9] = 0;
_turnWheelRight = false;
_showTurnedClock = true;
updateIndex();
break;
case 2: // Lever
_moveLever = true;
break;
case 3: // Chain
_moveChain = true;
break;
}
return true;
}
bool PuzzleWheel::exitPuzzle() {
getScreen()->clear();
_vm->switchEventHandler(getScene());
return true;
}
//////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////
void PuzzleWheel::updateCursor() {
int32 index = findRect();
if (_currentRect != index) {
_currentRect = index;
getCursor()->set(getWorld()->graphicResourceIds[2], -1, (index == -1) ? kCursorAnimationNone : kCursorAnimationMirror);
}
}
int32 PuzzleWheel::findRect() {
for (uint32 i = 0; i < ARRAYSIZE(puzzleWheelRects); i++) {
if (_vm->rectContains(&puzzleWheelRects[i], getCursor()->position()))
return i;
}
return -1;
}
void PuzzleWheel::updateIndex() {
if (_turnWheelRight) {
_resourceIndexClock = puzzleWheelClockResourceIndexes[_resourceIndex];
_resourceIndex = (_resourceIndex + 7) % ~7;
} else {
_resourceIndexClock = puzzleWheelClockResourceIndexes[_resourceIndex + 8];
_resourceIndex = (_resourceIndex + 1) % ~7;
}
}
void PuzzleWheel::checkFlags() {
for (uint32 i = 0; i < 8; i++)
if (!_vm->isGameFlagSet(puzzleWheelFlags[i]))
return;
_vm->setGameFlag(kGameFlag261);
getScreen()->clear();
_vm->switchEventHandler(getScene());
}
void PuzzleWheel::closeLocks() {
for (uint32 i = 0; i < 8; i++) {
if (!_vm->isGameFlagSet(puzzleWheelFlags[24 + i]))
continue;
getSound()->playSound(getWorld()->graphicResourceIds[69]);
_vm->clearGameFlag(puzzleWheelFlags[24 + i]);
_frameIndexes[i + 1] = 0;
}
}
void PuzzleWheel::toggleLocks() {
memset(&_frameIndexesSparks, -1, sizeof(_frameIndexesSparks));
for (int32 i = 0; i < 3; i++) {
_vm->toggleGameFlag(puzzleWheelFlags[i + 3 * _resourceIndex]);
// Update lock frame indexes
_frameIndexes[puzzleWheelContacts[i + 3 * _resourceIndex]] = 0;
// Update sparks frame indexes
_frameIndexesSparks[puzzleWheelSparks[puzzleWheelContacts[i + 3 * _resourceIndex] - 1]] = 0;
if (_vm->isGameFlagSet(puzzleWheelFlags[i]))
getSound()->playSound(getWorld()->graphicResourceIds[68]);
else
getSound()->playSound(getWorld()->graphicResourceIds[69]);
}
}
} // End of namespace Asylum
|