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
|
/* 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/>.
*
*/
#ifndef ASYLUM_PUZZLES_PIPES_H
#define ASYLUM_PUZZLES_PIPES_H
#include "common/list.h"
#include "common/hashmap.h"
#include "common/array.h"
#include "common/random.h"
#include "common/str.h"
#include "asylum/puzzles/puzzle.h"
namespace Asylum {
class AsylumEngine;
class Connector;
static const uint32 connectorsCount = 21, peepholesCount = 37;
enum BinNum {
kBinNum0000,
kBinNum0001,
kBinNum0010,
kBinNum0011,
kBinNum0100,
kBinNum0101,
kBinNum0110,
kBinNum0111,
kBinNum1000,
kBinNum1001,
kBinNum1010,
kBinNum1011,
kBinNum1100,
kBinNum1101,
kBinNum1110,
kBinNum1111
};
enum ConnectorType {
kConnectorTypeI = kBinNum0101,
kConnectorTypeL = kBinNum0110,
kConnectorTypeT = kBinNum0111
};
enum Direction {
kDirectionNowhere = kBinNum0000,
kDirectionNh = kBinNum0001,
kDirectionEt = kBinNum0010,
kDirectionSh = kBinNum0100,
kDirectionWt = kBinNum1000
};
class Peephole {
public:
Peephole() : _id(0) {}
~Peephole() {}
static bool marks[peepholesCount];
uint32 _flowValues[4];
uint32 getId() { return _id; }
void setId(uint32 id) { _id = id; }
uint32 getLevel() { return (_flowValues[0] > 0) + (_flowValues[1] > 0) + (_flowValues[2] > 0) + (_flowValues[3] > 0); }
uint32 getLevel1() { return _flowValues[0] + _flowValues[1] + _flowValues[2] + _flowValues[3]; }
bool isConnected() { return isConnected(0) || isConnected(1) || isConnected(2) || isConnected(3); }
void connect(Connector *connector) { _connectors.push_back(connector); }
void disconnect(Connector *connector) { _connectors.remove(connector); }
void startUpWater(bool flag = false);
private:
uint32 _id;
Common::List<Connector *> _connectors;
bool isConnected(uint32 val) { return _flowValues[val]; }
};
class Connector {
public:
Connector();
~Connector() {}
uint32 getId() { return _id; }
void setId(uint32 id) { _id = id; }
void setPos(uint32 *pos) { _position = pos; }
BinNum getState() { return _state; }
ConnectorType getType() { return _type; }
void init(Peephole *n, Peephole *e, Peephole *s, Peephole *w, uint32 pos, ConnectorType type, Connector *nextConnector = NULL, Direction nextConnectorPosition = kDirectionNowhere);
void initGroup();
void turn(bool updpos = true);
private:
uint32 _id;
BinNum _state;
ConnectorType _type;
uint32 *_position;
Peephole *_nodes[4];
Common::List<Peephole *> _connectedNodes;
Connector *_nextConnector;
Direction _nextConnectorPosition;
bool _isConnected;
void connect(Connector *connector);
void disconnect(Connector *connector);
bool isReadyForConnection() { return _state & _nextConnectorPosition; }
friend void Peephole::startUpWater(bool);
};
class Spider {
public:
Spider(AsylumEngine *engine, const Common::Rect &rect);
~Spider() {}
bool isAlive() const { return _isAlive; }
bool isActive() const { return _delta != Common::Point(0, 0); }
bool isVisible(Common::Rect rect) const { return rect.contains(_location); }
Direction getDirection() const { return _direction; }
Common::Rect getPolygon(Common::Rect frame) const { return Common::Rect(_location.x - frame.left, _location.y - frame.top, _location.x + frame.right, _location.y + frame.bottom); }
Common::Point move();
void smash() { _isAlive = false; }
private:
static const uint32 minStepsNumber = 20, maxStepsNumber = 200;
AsylumEngine *_vm;
bool _isAlive;
Common::Point _location;
Common::Point _delta;
Common::Rect _boundingBox;
Direction _direction;
uint32 _stepsNumber;
uint32 _steps;
void randomize(Direction excluded = kDirectionNowhere);
};
class PuzzlePipes : public Puzzle {
public:
PuzzlePipes(AsylumEngine *engine);
~PuzzlePipes();
// Serializable
virtual void saveLoadWithSerializer(Common::Serializer &s);
private:
int32 _previousMusicVolume;
int32 _rectIndex;
uint32 _frameIndex, _frameIndexLever;
bool _levelFlags[5];
float _levelValues[4], _previousLevels[4];
bool _isLeverReady;
Common::HashMap<uint32, uint32> _connectorResources;
Connector _connectors[connectorsCount];
uint32 _positions[connectorsCount];
Peephole _peepholes[peepholesCount];
Peephole *_sinks[4], *_sources[4];
Common::Array<Spider *> _spiders;
uint32 *_frameIndexSpider;
//////////////////////////////////////////////////////////////////////////
// Event Handling
//////////////////////////////////////////////////////////////////////////
bool init(const AsylumEvent &evt);
void updateScreen();
bool mouseLeftDown(const AsylumEvent &evt);
bool exitPuzzle();
//////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////
void initResources();
void setup();
void updateCursor();
int32 findRect();
uint32 checkFlags();
void startUpWater();
void checkConnections();
};
} // End of namespace Asylum
#endif // ASYLUM_PUZZLES_PIPES_H
|