1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/debug.h"
24
25 #include "toon/state.h"
26 #include "toon/toon.h"
27
28 namespace Toon {
29
save(Common::WriteStream * stream)30 void Location::save(Common::WriteStream *stream) {
31 stream->write(_cutaway, 64);
32 stream->write(_music, 64);
33 stream->write(_name, 64);
34 stream->writeSint16BE(_numRifBoxes);
35 stream->writeSint16BE(_numSceneAnimations);
36 stream->writeSByte(_visited);
37
38 for (int32 i = 0; i < _numRifBoxes * 2; i++) {
39 stream->writeSint16BE(_rifBoxesFlags[i]);
40 }
41 }
load(Common::ReadStream * stream)42 void Location::load(Common::ReadStream *stream) {
43 stream->read(_cutaway, 64);
44 stream->read(_music, 64);
45 stream->read(_name, 64);
46 _numRifBoxes = stream->readSint16BE();
47 _numSceneAnimations = stream->readSint16BE();
48 _visited = stream->readSByte();
49
50 for (int32 i = 0; i < _numRifBoxes * 2; i++) {
51 _rifBoxesFlags[i] = stream->readSint16BE();
52 }
53 }
54
State(void)55 State::State(void) {
56 for (int32 i = 0; i < 256; i++) {
57 _locations[i]._visited = false;
58 _locations[i]._numSceneAnimations = 0;
59 _locations[i]._numRifBoxes = 0;
60 }
61
62 memset(_gameFlag, 0, sizeof(_gameFlag));
63 memset(_gameGlobalData, -1, sizeof(_gameGlobalData));
64
65 for (int32 i = 0; i < 2; i++) {
66 _timerEnabled[i] = false;
67 _timerTimeout[i] = 0;
68 _timerDelay[i] = -1;
69 }
70
71 _lastVisitedScene = -1;
72 _currentScene = -1;
73
74 _currentScrollLock = false;
75 _currentScrollValue = 0;
76
77 _gameTimer = 0;
78 _currentChapter = 1;
79
80 _showConversationIcons = false;
81
82 _inMenu = false;
83 _inCloseUp = false;
84 _inConversation = false;
85
86 _mouseState = -1;
87 _mouseHidden = false;
88
89 _firstConverstationLine = false;
90
91 _sackVisible = false; // to change
92 _inCutaway = false;
93
94 _inInventory = false;
95 _numInventoryItems = 0; //To chhange
96 _numConfiscatedInventoryItems = 0;
97
98 _nextSpecialEnterX = -1;
99 _nextSpecialEnterY = -1;
100
101 #if 0
102 for (int i = 0; i < 30; i++) {
103 _inventory[i] = 90 + i;
104 if (_inventory[i] == 41)
105 _inventory[i] = 42;
106 }
107
108 _inventory[0] = 53;
109 _inventory[1] = 22;
110 _inventory[2] = 93;
111 _inventory[3] = 49;
112 _inventory[4] = 47;
113 _inventory[5] = 14;
114 _numInventoryItems = 6; //To change
115 #endif
116
117 memset(_conversationState, 0, sizeof(Conversation) * 60);
118
119 _conversationData = nullptr;
120 _currentConversationId = -1;
121 _exitConversation = true;
122 }
123
~State(void)124 State::~State(void) {
125 }
126
getGameFlag(int32 flagId)127 int32 State::getGameFlag(int32 flagId) {
128 return (_gameFlag[flagId >> 3] & (1 << (flagId & 7))) != 0;
129 }
130
hasItemInInventory(int32 item)131 bool State::hasItemInInventory(int32 item) {
132 debugC(1, kDebugState, "hasItemInInventory(%d)", item);
133
134 for (int32 i = 0; i < _numInventoryItems; i++) {
135 if (_inventory[i] == item)
136 return true;
137 }
138 return false;
139 }
140
save(Common::WriteStream * stream)141 void State::save(Common::WriteStream *stream) {
142
143 for (int32 i = 0; i < 256; i++) {
144 _locations[i].save(stream);
145 }
146
147 for (int32 i = 0; i < 256; i++) {
148 stream->writeSint16BE(_gameGlobalData[i]);
149 }
150
151 for (int32 i = 0; i < 256; i++) {
152 stream->writeSint16BE(_gameFlag[i]);
153 }
154
155 stream->writeSint16BE(_lastVisitedScene);
156 stream->writeSint16BE(_currentScene);
157 stream->writeSint16BE(_currentScrollValue);
158 stream->writeSByte(_currentScrollLock);
159
160 for (int32 i = 0; i < 35; i++) {
161 stream->writeSint16BE(_inventory[i]);
162 }
163
164 for (int32 i = 0; i < 35; i++) {
165 stream->writeSint16BE(_confiscatedInventory[i]);
166 }
167
168 stream->writeSint32BE(_numInventoryItems);
169 stream->writeSint32BE(_numConfiscatedInventoryItems);
170
171 stream->writeSByte(_inCloseUp);
172 stream->writeSByte(_inCutaway);
173 stream->writeSByte(_inConversation);
174 stream->writeSByte(_inInventory);
175 stream->writeSByte(_showConversationIcons);
176
177 stream->writeSint16BE(_mouseState);
178
179 stream->writeSint16BE(_currentConversationId);
180 stream->writeSByte(_firstConverstationLine);
181 stream->writeSByte(_exitConversation);
182 stream->writeSByte(_mouseHidden);
183 stream->writeSByte(_sackVisible);
184 stream->writeSint32BE(_gameTimer);
185 stream->writeSByte(_currentChapter);
186
187 stream->writeByte(_timerEnabled[0]);
188 stream->writeByte(_timerEnabled[1]);
189
190 stream->writeSint32BE(_timerTimeout[0]);
191 stream->writeSint32BE(_timerTimeout[1]);
192
193 stream->writeSint32BE(_timerDelay[0]);
194 stream->writeSint32BE(_timerDelay[1]);
195 }
196
load(Common::ReadStream * stream)197 void State::load(Common::ReadStream *stream) {
198 for (int32 i = 0; i < 256; i++) {
199 _locations[i].load(stream);
200 }
201
202 for (int32 i = 0; i < 256; i++) {
203 _gameGlobalData[i] = stream->readSint16BE();
204 }
205
206 for (int32 i = 0; i < 256; i++) {
207 _gameFlag[i] = stream->readSint16BE();
208 }
209
210 _lastVisitedScene = stream->readSint16BE();
211 _currentScene = stream->readSint16BE();
212 _currentScrollValue = stream->readSint16BE();
213 _currentScrollLock = stream->readSByte();
214
215 for (int32 i = 0; i < 35; i++) {
216 _inventory[i] = stream->readSint16BE();
217 }
218
219 for (int32 i = 0; i < 35; i++) {
220 _confiscatedInventory[i] = stream->readSint16BE();
221 }
222
223 _numInventoryItems = stream->readSint32BE();
224 _numConfiscatedInventoryItems = stream->readSint32BE();
225
226 _inCloseUp = stream->readSByte();
227 _inCutaway = stream->readSByte();
228 _inConversation = stream->readSByte();
229 _inInventory = stream->readSByte();
230 _showConversationIcons = stream->readSByte();
231
232 _mouseState = stream->readSint16BE();
233
234 _currentConversationId = stream->readSint16BE();
235 _firstConverstationLine = stream->readSByte();
236 _exitConversation = stream->readSByte();
237 _mouseHidden = stream->readSByte();
238 _sackVisible = stream->readSByte();
239 _gameTimer = stream->readSint32BE();
240 _currentChapter = stream->readSByte();
241
242 _timerEnabled[0] = stream->readByte();
243 _timerEnabled[1] = stream->readByte();
244
245 _timerTimeout[0] = stream->readSint32BE();
246 _timerTimeout[1] = stream->readSint32BE();
247
248 _timerDelay[0] = stream->readSint32BE();
249 _timerDelay[1] = stream->readSint32BE();
250 }
251
loadConversations(Common::ReadStream * stream)252 void State::loadConversations(Common::ReadStream *stream) {
253 for (int32 i = 0; i < 60; i++) {
254 _conversationState[i].load(stream, _conversationData);
255 }
256 }
257
saveConversations(Common::WriteStream * stream)258 void State::saveConversations(Common::WriteStream *stream) {
259 for (int32 i = 0; i < 60; i++) {
260 _conversationState[i].save(stream, _conversationData);
261 }
262 }
263
264 } // End of namespace Toon
265