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 "tucker/tucker.h"
24 #include "tucker/graphics.h"
25 #include "common/system.h"
26 #include "graphics/palette.h"
27 
28 namespace Tucker {
29 
30 static const int _data3UpdateLocation1_xTable[] = { 287, 120,  61 };
31 static const int _data3UpdateLocation1_yTable[] = { 152,   8,  95 };
32 
execData3PreUpdate_locationNum1()33 void TuckerEngine::execData3PreUpdate_locationNum1() {
34 	if (_flagsTable[1] == 1) {
35 		_flagsTable[1] = 2;
36 		_locationSoundsTable[3]._type = 2;
37 		startSound(_locationSoundsTable[3]._offset, 3, _locationSoundsTable[3]._volume);
38 	}
39 	_mapSequenceFlagsLocationTable[0] = (_flagsTable[1] > 0) ? 1 : 0;
40 	if (_updateLocationCounter == 0) {
41 		execData3PreUpdate_locationNum1Helper1();
42 		execData3PreUpdate_locationNum1Helper2();
43 	} else {
44 		--_updateLocationCounter;
45 		if (_updateLocationCounter == 0) {
46 			++_updateLocationPos;
47 			if (_updateLocationPos > 1) {
48 				_updateLocationPos = 0;
49 			}
50 			for (int i = 0; i < 5; ++i) {
51 				_updateLocationXPosTable[i] = _data3UpdateLocation1_xTable[_updateLocationPos];
52 				_updateLocationYPosTable[i] = _data3UpdateLocation1_yTable[_updateLocationPos];
53 				_updateLocationFlagsTable[i] = 0;
54 			}
55 		}
56 	}
57 }
58 
execData3PreUpdate_locationNum1Helper1()59 void TuckerEngine::execData3PreUpdate_locationNum1Helper1() {
60 	int code = 0;
61 	if (_updateLocationXPosTable[0] > 0 && _updateLocationYPosTable[0] > 0) {
62 		for (int i = 4; i > 0; --i) {
63 			_updateLocationXPosTable[i] = _updateLocationXPosTable[i - 1];
64 			_updateLocationYPosTable[i] = _updateLocationYPosTable[i - 1];
65 			_updateLocationFlagsTable[i] = _updateLocationFlagsTable[i - 1];
66 		}
67 	}
68 	if (_updateLocationFlagsTable[0] == 1 && _updateLocationCounter == 0) {
69 		setVolumeSound(12, _locationSoundsTable[12]._volume);
70 	} else {
71 		setVolumeSound(12, 0);
72 	}
73 	static const int dxTable[] = {  0, -1, -1, -1, 0, 1, 1,  1 };
74 	static const int dyTable[] = { -1, -1,  0,  1, 1, 1, 0, -1 };
75 	for (int i = 0; code == 0 && i < 8; ++i) {
76 		code = execData3PreUpdate_locationNum1Helper3(dxTable[i], dyTable[i]);
77 	}
78 	_updateLocationFlagsTable[0] = code;
79 }
80 
execData3PreUpdate_locationNum1Helper2()81 void TuckerEngine::execData3PreUpdate_locationNum1Helper2() {
82 	static const int dxTable[] = { -95, 84, 110 };
83 	static const int dyTable[] = { -50, 46,   0 };
84 	int xPos = 0;
85 	int yPos = 0;
86 	for (int i = 0; i < 6; i += 2) {
87 		if (_updateLocationFlagsTable[i] == 1) {
88 			xPos = _updateLocationXPosTable[i] + dxTable[_updateLocationPos];
89 			yPos = _updateLocationYPosTable[i] + dyTable[_updateLocationPos];
90 		}
91 		if (xPos > 319 || yPos > 199 || xPos < 0 || yPos < 0) {
92 			xPos = 0;
93 			yPos = 0;
94 		}
95 		_locationBackgroundGfxBuf[yPos * 640 + xPos] = 100;
96 		addDirtyRect(xPos, yPos, 1, 1);
97 	}
98 }
99 
execData3PreUpdate_locationNum1Helper3(int dx,int dy)100 int TuckerEngine::execData3PreUpdate_locationNum1Helper3(int dx, int dy) {
101 	static const int counterTable[3] = { 30, 50, 70 };
102 	const int xPos = _updateLocationXPosTable[0] + dx;
103 	const int yPos = _updateLocationYPosTable[0] + dy;
104 	static const int num[] = { 2, 3, 4, 1 };
105 	for (int i = 0; i < 4; ++i) {
106 		if (xPos == _updateLocationXPosTable[num[i]] && yPos == _updateLocationYPosTable[num[i]]) {
107 			return 0;
108 		}
109 	}
110 	const int code = (int8)_loadLocBufPtr[yPos * 320 + xPos];
111 	if (code > 0) {
112 		_updateLocationXPosTable[0] = xPos;
113 		_updateLocationYPosTable[0] = yPos;
114 		if (xPos == _data3UpdateLocation1_xTable[_updateLocationPos] && yPos == _data3UpdateLocation1_yTable[_updateLocationPos]) {
115 			_updateLocationCounter = counterTable[_updateLocationPos];
116 		}
117 	}
118 	return code;
119 }
120 
execData3PostUpdate_locationNum1()121 void TuckerEngine::execData3PostUpdate_locationNum1() {
122 	if (_flagsTable[63] == 0) {
123 		if (getRandomNumber() < 400) {
124 			_flagsTable[63] = 1;
125 			startSound(_locationSoundsTable[2]._offset, 2, _locationSoundsTable[2]._volume);
126 		}
127 	}
128 	_locationHeightTable[1] = (_yPosCurrent > 104) ? 60 : 0;
129 }
130 
updateSprite_locationNum2()131 void TuckerEngine::updateSprite_locationNum2() {
132 	if (_flagsTable[9] == 2) {
133 		_spritesTable[0]._state = -1;
134 		return;
135 	}
136 	if (_flagsTable[9] == 1) {
137 		if (_flagsTable[10] == 1) {
138 			_spritesTable[0]._state = -1;
139 		} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
140 			_spritesTable[0]._state = 4;
141 			_spritesTable[0]._needUpdate = true;
142 		} else {
143 			_spritesTable[0]._needUpdate = false;
144 			_spritesTable[0]._state = 5;
145 			_flagsTable[10] = 1;
146 			_spritesTable[0]._gfxBackgroundOffset = 0;
147 		}
148 		return;
149 	}
150 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
151 		_spritesTable[0]._state = 3;
152 		_spritesTable[0]._needUpdate = true;
153 		return;
154 	}
155 	if (_csDataHandled) {
156 		_spritesTable[0]._needUpdate = false;
157 		if (_flagsTable[199] == 0) {
158 			_flagsTable[199] = 1;
159 			setCharacterAnimation(0, 0);
160 		} else if (getRandomNumber() > 20000) {
161 			_spritesTable[0]._state = 6;
162 		} else {
163 			_spritesTable[0]._state = 3;
164 			_spritesTable[0]._updateDelay = 5;
165 		}
166 	} else {
167 		if (_flagsTable[199] == 0) {
168 			_flagsTable[199] = 1;
169 			setCharacterAnimation(1, 0);
170 		} else if (getRandomNumber() < 20000) {
171 			_spritesTable[0]._state = 1;
172 			_spritesTable[0]._updateDelay = 5;
173 		} else {
174 			_spritesTable[0]._state = 1;
175 		}
176 	}
177 }
178 
execData3PreUpdate_locationNum2()179 void TuckerEngine::execData3PreUpdate_locationNum2() {
180 	static const int xPosTable[] = { 110, 117, 127, 146, 160, 183, 195, 210 };
181 	static const int yPosTable[] = {  50,  60,  60,  60,  50,  55,  50,  50 };
182 	static const int yMaxTable[] = { 100,  97,  94,  91,  89,  86,  83,  80 };
183 	if (_execData3Counter == 0) {
184 		_execData3Counter = 1;
185 		for (int i = 0; i < 3; ++i) {
186 			_updateLocationYPosTable2[i] = 0;
187 		}
188 		if (_flagsTable[10] == 0) {
189 			copyLocBitmap("path02b.pcx", 0, true);
190 		}
191 		for (int i = 0; i < 3; ++i) {
192 			if (_updateLocationYPosTable2[i] > 0) {
193 				for (int j = 0; j < 2; ++j) {
194 					const int offset = (_updateLocationYPosTable2[i] + j) * 640 + _updateLocationXPosTable2[i];
195 					_locationBackgroundGfxBuf[offset] = 142 + j * 2;
196 				}
197 				addDirtyRect(_updateLocationXPosTable2[i], _updateLocationYPosTable2[i], 1, 2);
198 				_updateLocationYPosTable2[i] += 2;
199 				if (_updateLocationYPosTable2[i] > _updateLocationYMaxTable[i]) {
200 					_updateLocationYPosTable2[i] = 0;
201 					const int num = (getRandomNumber() < 16000) ? 2 : 3;
202 					startSound(_locationSoundsTable[num]._offset, num, _locationSoundsTable[num]._volume);
203 				}
204 			} else if (getRandomNumber() > 32000) {
205 				const int num = getRandomNumber() / 8192;
206 				_updateLocationXPosTable2[i] = xPosTable[num];
207 				_updateLocationYPosTable2[i] = yPosTable[num];
208 				_updateLocationYMaxTable[i] = yMaxTable[num];
209 			}
210 		}
211 	}
212 	execData3PreUpdate_locationNum2Helper();
213 }
214 
execData3PreUpdate_locationNum2Helper()215 void TuckerEngine::execData3PreUpdate_locationNum2Helper() {
216 	if (_fadePaletteCounter != 16) {
217 		return;
218 	}
219 	int start, end;
220 	if (_location == kLocationBackAlley) {
221 		start = 116;
222 		end = 125;
223 	} else {
224 		start = 215;
225 		end = 223;
226 	}
227 	++_updateLocationFadePaletteCounter;
228 	if (_updateLocationFadePaletteCounter > 10 || _updateLocationFadePaletteCounter < 0) {
229 		_updateLocationFadePaletteCounter = 0;
230 	}
231 	int step;
232 	if (_updateLocationFadePaletteCounter < 6) {
233 		step = _updateLocationFadePaletteCounter;
234 	} else {
235 		step = 10 - _updateLocationFadePaletteCounter;
236 	}
237 	for (int i = start; i < end; ++i) {
238 		fadePaletteColor(i, step);
239 	}
240 }
241 
updateSprite_locationNum3_0(int i)242 void TuckerEngine::updateSprite_locationNum3_0(int i) {
243 	int num;
244 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
245 		num = 5;
246 		_spritesTable[i]._needUpdate = true;
247 	} else if (_spritesTable[i]._prevState == 5 && _spritesTable[i]._animationFrame == 1) {
248 		_spritesTable[i]._needUpdate = false;
249 		int r = getRandomNumber();
250 		if (r < 12000) {
251 			num = 3;
252 		} else if (r < 24000) {
253 			num = 1;
254 		} else {
255 			num = 2;
256 		}
257 	} else {
258 		num = 5;
259 		_spritesTable[i]._animationFrame = 1;
260 		_spritesTable[i]._updateDelay = 10;
261 	}
262 	_spritesTable[i]._state = num;
263 	_spritesTable[i]._prevAnimationFrame = true;
264 }
265 
updateSprite_locationNum3_1(int i)266 void TuckerEngine::updateSprite_locationNum3_1(int i) {
267 	int num;
268 	if (_flagsTable[207] == 1) {
269 		num = -1;
270 	} else if (_flagsTable[203] == 1) {
271 		_spritesTable[i]._needUpdate = true;
272 		num = 20;
273 		_flagsTable[203] = 2;
274 	} else if (_flagsTable[203] == 2) {
275 		num = 12;
276 	} else if (_flagsTable[203] == 3) {
277 		_spritesTable[i]._needUpdate = false;
278 		num = 19;
279 		_flagsTable[203] = 0;
280 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
281 		_spritesTable[i]._needUpdate = true;
282 		if (_flagsTable[21] == 0) {
283 			num = 7;
284 		} else {
285 			num = 8;
286 		}
287 	} else {
288 		_spritesTable[i]._needUpdate = false;
289 		if (_csDataHandled) {
290 			num = 6;
291 			if (getRandomNumber() < 32000) {
292 				_spritesTable[i]._updateDelay = 5;
293 			}
294 		} else if (_spritesTable[i]._state == 6 && _spritesTable[i]._animationFrame == 1) {
295 			if (getRandomNumber() < 20000) {
296 				num = 11;
297 				_spritesTable[i]._defaultUpdateDelay = 5;
298 			} else {
299 				num = 10;
300 			}
301 		} else {
302 			num = 6;
303 			_spritesTable[i]._animationFrame = 1;
304 			_spritesTable[i]._updateDelay = 10;
305 		}
306 	}
307 	_spritesTable[i]._state = num;
308 	_spritesTable[i]._gfxBackgroundOffset = 320;
309 }
310 
updateSprite_locationNum3_2(int i)311 void TuckerEngine::updateSprite_locationNum3_2(int i) {
312 	int num;
313 	if (_flagsTable[205] == 1) {
314 		_flagsTable[205] = 0;
315 		num = 18;
316 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
317 		_spritesTable[i]._needUpdate = true;
318 		num = 17;
319 	} else if (_flagsTable[45] == 1) {
320 		_flagsTable[45] = 2;
321 		num = 16;
322 	} else if (_flagsTable[45] == 2) {
323 		num = 17;
324 		_spritesTable[i]._updateDelay = 5;
325 		_spritesTable[i]._needUpdate = false;
326 	} else if (_flagsTable[45] == 3) {
327 		_flagsTable[45] = 0;
328 		num = 16;
329 		_updateSpriteFlag2 = true;
330 	} else {
331 		_spritesTable[i]._needUpdate = false;
332 		++_spritesTable[i]._counter;
333 		if (_spritesTable[i]._counter <= 5) {
334 			num = 14;
335 		} else {
336 			if (_spritesTable[i]._counter > 8) {
337 				_spritesTable[i]._counter = 0;
338 			}
339 			num = 15;
340 		}
341 	}
342 	_spritesTable[i]._state = num;
343 }
344 
execData3PreUpdate_locationNum3()345 void TuckerEngine::execData3PreUpdate_locationNum3() {
346 	execData3PreUpdate_locationNum2Helper();
347 	if (_flagsTable[7] == 0) {
348 		_flagsTable[7] = 1;
349 	}
350 	if (_flagsTable[20] == 1 && _inventoryItemsState[7] == 1) {
351 		_flagsTable[20] = 2;
352 	}
353 	if (_inventoryItemsState[19] == 1 && _flagsTable[54] == 1) {
354 		_flagsTable[43] = 1;
355 	} else {
356 		_flagsTable[43] = 0;
357 	}
358 }
359 
updateSprite_locationNum4(int i)360 void TuckerEngine::updateSprite_locationNum4(int i) {
361 	int state = -1;
362 	if (_flagsTable[9] == 2) {
363 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
364 			state = 1;
365 			_spritesTable[i]._needUpdate = true;
366 		} else {
367 			state = 2;
368 			_spritesTable[i]._needUpdate = false;
369 		}
370 	}
371 	_spritesTable[i]._state = state;
372 }
373 
execData3PreUpdate_locationNum4()374 void TuckerEngine::execData3PreUpdate_locationNum4() {
375 	if (_flagsTable[6] == 0) {
376 		setVolumeSound(0, 0);
377 	} else {
378 		setVolumeSound(0, _locationSoundsTable[0]._volume);
379 	}
380 }
381 
updateSprite_locationNum5_0()382 void TuckerEngine::updateSprite_locationNum5_0() {
383 	++_spritesTable[0]._counter;
384 	if (_spritesTable[0]._counter > 100) {
385 		_spritesTable[0]._counter = 0;
386 		_spritesTable[0]._state = 1;
387 		_locationSoundsTable[1]._type = 2;
388 		startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
389 	} else if (_spritesTable[0]._counter == 50) {
390 		_locationSoundsTable[1]._type = 2;
391 		_spritesTable[0]._state = 2;
392 		startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
393 	} else {
394 		_spritesTable[0]._state = -1;
395 		if (isSoundPlaying(1)) {
396 			stopSound(1);
397 		}
398 	}
399 }
400 
updateSprite_locationNum5_1(int i)401 void TuckerEngine::updateSprite_locationNum5_1(int i) {
402 	_spritesTable[i]._state = 3;
403 }
404 
updateSprite_locationNum6_0(int i)405 void TuckerEngine::updateSprite_locationNum6_0(int i) {
406 	int state;
407 	if (_flagsTable[184] == 1) {
408 		state = -1;
409 	} else if (_flagsTable[26] > 0 && _flagsTable[26] < 4 && _flagsTable[27] > 0) {
410 		state = 14;
411 	} else if (_flagsTable[26] == 4 || _flagsTable[26] == 5) {
412 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
413 			_spritesTable[0]._needUpdate = true;
414 			state = 3;
415 			_spritesTable[0]._counter = 0;
416 		} else if (_xPosCurrent < 370 && _flagsTable[26] == 4) {
417 			state = 2;
418 		} else if (_spritesTable[0]._counter == 0) {
419 			setCharacterAnimation(0, 0);
420 			_updateSpriteFlag1 = true;
421 			++_spritesTable[0]._counter;
422 			return;
423 		} else {
424 			state = 1;
425 			_spritesTable[0]._updateDelay = 2;
426 			++_spritesTable[0]._counter;
427 			if (_spritesTable[0]._counter > 100) {
428 				_spritesTable[0]._counter = 0;
429 			}
430 		}
431 	} else {
432 		state = -1;
433 	}
434 	_spritesTable[i]._state = state;
435 	_spritesTable[i]._gfxBackgroundOffset = 320;
436 }
437 
updateSprite_locationNum6_1(int i)438 void TuckerEngine::updateSprite_locationNum6_1(int i) {
439 	int state;
440 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
441 		if (_flagsTable[209] == 1) {
442 			state = 9;
443 			_spritesTable[i]._needUpdate = true;
444 		} else {
445 			_spritesTable[i]._needUpdate = true;
446 			state = 10;
447 		}
448 	} else {
449 		if (getRandomNumber() < 30000 || (_csDataHandled && _xPosCurrent == 248)) {
450 			_spritesTable[i]._needUpdate = false;
451 			state = 7;
452 			_spritesTable[i]._updateDelay = 5;
453 		} else {
454 			_spritesTable[i]._needUpdate = false;
455 			state = 7;
456 			_miscSoundFxNum[0] = 3;
457 			_miscSoundFxDelayCounter[0] = 70;
458 			_miscSoundFxNum[1] = 4;
459 			_miscSoundFxDelayCounter[1] = 25;
460 		}
461 	}
462 	_spritesTable[i]._state = state;
463 }
464 
updateSprite_locationNum6_2(int i)465 void TuckerEngine::updateSprite_locationNum6_2(int i) {
466 	int state;
467 	if (_flagsTable[26] < 5 || _flagsTable[207] > 0) {
468 		state = -1;
469 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
470 		_spritesTable[i]._needUpdate = true;
471 		state = 12;
472 	} else {
473 		state = 12;
474 		_spritesTable[i]._updateDelay = 2;
475 	}
476 	_spritesTable[i]._state = state;
477 }
478 
execData3PreUpdate_locationNum6()479 void TuckerEngine::execData3PreUpdate_locationNum6() {
480 	if (_flagsTable[26] > 3) {
481 		execData3PreUpdate_locationNum6Helper1();
482 	}
483 	if (_flagsTable[26] == 2) {
484 		_currentSpriteAnimationLength = 2;
485 		_currentSpriteAnimationFrame = 112;
486 		if (_spritesTable[0]._xSource < 45) {
487 			_currentSpriteAnimationFrame2 = 144;
488 		} else if (_spritesTable[0]._xSource > 80) {
489 			_currentSpriteAnimationFrame2 = 147;
490 		} else if (_spritesTable[0]._xSource < 60) {
491 			_currentSpriteAnimationFrame2 = 145;
492 		} else {
493 			_currentSpriteAnimationFrame2 = 146;
494 		}
495 	}
496 }
497 
execData3PreUpdate_locationNum6Helper1()498 void TuckerEngine::execData3PreUpdate_locationNum6Helper1() {
499 	if (_mainLoopCounter1 < 2) {
500 		if (_flagsTable[26] == 1) {
501 			if (_flagsTable[27] < 15) {
502 				if (_flagsTable[27] == 0) {
503 					startSound(_locationSoundsTable[2]._offset, 2, _locationSoundsTable[2]._volume);
504 					startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
505 				}
506 				++_flagsTable[27];
507 				setVolumeSound(0, _locationSoundsTable[0]._volume - _flagsTable[27] * 5);
508 				setVolumeMusic(0, _locationMusicsTable[0]._volume - _flagsTable[27] * 5);
509 			}
510 		} else if (_flagsTable[26] == 3) {
511 			if (_flagsTable[27] > 0) {
512 				if (_flagsTable[27] == 15) {
513 					startSound(_locationSoundsTable[2]._offset, 2, _locationSoundsTable[2]._volume);
514 				}
515 				--_flagsTable[27];
516 				setVolumeSound(0, _locationSoundsTable[0]._volume - _flagsTable[27] * 5);
517 				setVolumeMusic(0, _locationMusicsTable[0]._volume - _flagsTable[27] * 5);
518 				int volume = _flagsTable[27];
519 				if (volume < _locationSoundsTable[1]._volume) {
520 					volume = _locationSoundsTable[1]._volume;
521 				}
522 				setVolumeSound(1, volume);
523 			}
524 		}
525 	}
526 	int x1, x2;
527 	if (_flagsTable[27] == 0) {
528 		x1 = 8;
529 		x2 = 0;
530 	} else if (_flagsTable[27] == 15) {
531 		x1 = 1;
532 		x2 = 0;
533 	} else if (_flagsTable[27] < 8) {
534 		x1 = 8 - _flagsTable[27];
535 		x2 = _flagsTable[27];
536 	} else {
537 		x1 = 1;
538 		x2 = 15 - _flagsTable[27];
539 	}
540 	for (int i = 0; i < x1; ++i) {
541 		execData3PreUpdate_locationNum6Helper2(20 * 640 + 325 + i * 8, _data3GfxBuf + _dataTable[238]._sourceOffset);
542 		execData3PreUpdate_locationNum6Helper2(20 * 640 + 445 - i * 8, _data3GfxBuf + _dataTable[238]._sourceOffset);
543 	}
544 	for (int i = 0; i < x2; ++i) {
545 		execData3PreUpdate_locationNum6Helper3(20 * 640 + 325 + x1 * 8 + i * 4, _data3GfxBuf + _dataTable[238]._sourceOffset);
546 		execData3PreUpdate_locationNum6Helper3(20 * 640 + 449 - x1 * 8 - i * 4, _data3GfxBuf + _dataTable[238]._sourceOffset);
547 	}
548 	addDirtyRect(0, 20, 640, 51);
549 }
550 
execData3PreUpdate_locationNum6Helper2(int dstOffset,const uint8 * src)551 void TuckerEngine::execData3PreUpdate_locationNum6Helper2(int dstOffset, const uint8 *src) {
552 	for (int j = 0; j < 46; ++j) {
553 		memcpy(_locationBackgroundGfxBuf + dstOffset + j * 640, src + j * 8, 8);
554 	}
555 	for (int j = 46; j < 51; ++j) {
556 		for (int i = 0; i < 8; ++i) {
557 			const int offset = dstOffset + j * 640 + i;
558 			uint8 color = _locationBackgroundGfxBuf[offset];
559 			if (color < 224) {
560 				_locationBackgroundGfxBuf[offset] = src[j * 8 + i];
561 			}
562 		}
563 	}
564 }
565 
execData3PreUpdate_locationNum6Helper3(int dstOffset,const uint8 * src)566 void TuckerEngine::execData3PreUpdate_locationNum6Helper3(int dstOffset, const uint8 *src) {
567 	for (int j = 0; j < 51; ++j) {
568 		for (int i = 0; i < 4; ++i) {
569 			const int offset = dstOffset + j * 640 + i;
570 			uint8 color = _locationBackgroundGfxBuf[offset];
571 			if (color < 224) {
572 				_locationBackgroundGfxBuf[offset] = src[j * 8 + i * 2];
573 			}
574 		}
575 	}
576 }
577 
execData3PostUpdate_locationNum6()578 void TuckerEngine::execData3PostUpdate_locationNum6() {
579 	if (_flagsTable[26] < 4) {
580 		execData3PreUpdate_locationNum6Helper1();
581 	}
582 }
583 
updateSprite_locationNum7_0(int i)584 void TuckerEngine::updateSprite_locationNum7_0(int i) {
585 	int state;
586 	++_spritesTable[i]._counter;
587 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
588 		_spritesTable[i]._needUpdate = true;
589 		state = 4;
590 	} else {
591 		_spritesTable[i]._needUpdate = false;
592 		if (_spritesTable[i]._counter > 0) {
593 			state = 2;
594 			_spritesTable[i]._counter = 0;
595 		} else {
596 			state = 1;
597 		}
598 	}
599 	_spritesTable[i]._state = state;
600 }
601 
updateSprite_locationNum7_1(int i)602 void TuckerEngine::updateSprite_locationNum7_1(int i) {
603 	int state;
604 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
605 		_spritesTable[i]._needUpdate = true;
606 		state = 5;
607 	} else {
608 		_spritesTable[i]._needUpdate = false;
609 		state = 5;
610 		_spritesTable[i]._updateDelay = 5;
611 	}
612 	_spritesTable[i]._state = state;
613 }
614 
updateSprite_locationNum8_0(int i)615 void TuckerEngine::updateSprite_locationNum8_0(int i) {
616 	_spritesTable[i]._state = (_flagsTable[28] < 20) ? -1 : 7;
617 }
618 
updateSprite_locationNum8_1(int i)619 void TuckerEngine::updateSprite_locationNum8_1(int i) {
620 	int state;
621 	if (_flagsTable[207] == 1) {
622 		state = -1;
623 	} else if (_flagsTable[28] == 18) {
624 		state = 6;
625 		_spritesTable[i]._needUpdate = false;
626 	} else if (_flagsTable[29] == 0) {
627 		state = 1;
628 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 1) {
629 		_spritesTable[i]._needUpdate = true;
630 		state = 5;
631 	} else {
632 		_spritesTable[i]._needUpdate = false;
633 		state = 3;
634 	}
635 	if (_flagsTable[28] == 19) {
636 		_flagsTable[28] = 20;
637 	}
638 	_spritesTable[i]._state = state;
639 }
640 
execData3PostUpdate_locationNum8()641 void TuckerEngine::execData3PostUpdate_locationNum8() {
642 	if (_execData3Counter == 0) {
643 		_updateLocationYPosTable2[0] = 0;
644 	}
645 	if (_updateLocationYPosTable2[0] == 0) {
646 		++_execData3Counter;
647 		if (_execData3Counter > 30) {
648 			_updateLocationYPosTable2[0] = 16;
649 			_updateLocationXPosTable2[0] = 264;
650 		}
651 	}
652 	if (_updateLocationYPosTable2[0] > 0) {
653 		const int offset = _updateLocationYPosTable2[0] * 640 + _updateLocationXPosTable2[0];
654 		static const int colorsTable[] = { 143, 143, 144, 144, 144, 145, 147, 143, 147 };
655 		_locationBackgroundGfxBuf[offset] = 142;
656 		for (int j = 1; j <= 3; ++j) {
657 			for (int i = -1; i <= 1; ++i) {
658 				_locationBackgroundGfxBuf[offset + 640 * j + i] = colorsTable[(j - 1) * 3  + i + 1];
659 			}
660 		}
661 		addDirtyRect(_updateLocationXPosTable2[0] - 1, _updateLocationYPosTable2[0], 3, 4);
662 		_updateLocationYPosTable2[0] += 2;
663 		if (_updateLocationYPosTable2[0] > 120) {
664 			_updateLocationYPosTable2[0] = 0;
665 			startSound(_locationSoundsTable[2]._offset, 2, _locationSoundsTable[2]._volume);
666 		}
667 	}
668 	if (_flagsTable[28] > 1 && _flagsTable[28] < 5) {
669 		_locationHeightTable[8] = 60;
670 	} else {
671 		_locationHeightTable[8] = 0;
672 	}
673 }
674 
updateSprite_locationNum9_0(int i)675 void TuckerEngine::updateSprite_locationNum9_0(int i) {
676 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
677 		_spritesTable[i]._needUpdate = true;
678 		_spritesTable[i]._state = 3;
679 	} else if (_updateLocationCounter2 > 0 || getRandomNumber() > 30000) {
680 		_spritesTable[i]._state = 1;
681 		if (_updateLocationCounter2 == 0) {
682 			_updateLocationCounter2 = 6;
683 		}
684 	} else if (getRandomNumber() > 30000) {
685 		_spritesTable[i]._state = 2;
686 		_spritesTable[i]._defaultUpdateDelay = 5;
687 	} else {
688 		_spritesTable[i]._state = 1;
689 		_spritesTable[i]._animationFrame = 1;
690 		_spritesTable[i]._updateDelay = 10;
691 	}
692 }
693 
updateSprite_locationNum9_1(int i)694 void TuckerEngine::updateSprite_locationNum9_1(int i) {
695 	++_spritesTable[i]._counter;
696 	if (_spritesTable[i]._counter > 10) {
697 		_spritesTable[i]._counter = 0;
698 		_spritesTable[i]._state = 5;
699 		_spritesTable[i]._defaultUpdateDelay = 5;
700 	} else {
701 		_spritesTable[i]._state = 4;
702 	}
703 }
704 
updateSprite_locationNum9_2(int i)705 void TuckerEngine::updateSprite_locationNum9_2(int i) {
706 	_spritesTable[i]._state = 6;
707 	_spritesTable[i]._gfxBackgroundOffset = 320;
708 }
709 
execData3PreUpdate_locationNum9()710 void TuckerEngine::execData3PreUpdate_locationNum9() {
711 	if (_flagsTable[7] < 2) {
712 		_flagsTable[7] = 2;
713 	}
714 
715 	// If the door to the dentist is open play the dentist room music based on
716 	// Bud's proximity to the door (the closer the louder the music is played)
717 	_locationMusicsTable[0]._volume = _flagsTable[8] == 0 ? 0 : _xPosCurrent / 40;
718 	setVolumeMusic(0, _locationMusicsTable[0]._volume);
719 
720 	if (!isSoundPlaying(1) && getRandomNumber() > 32000) {
721 		int i = getRandomNumber() / 5500 + 3;
722 		assert(i >= 0 && i < kLocationSoundsTableSize);
723 		startSound(_locationSoundsTable[i]._offset, i, _locationSoundsTable[i]._volume);
724 	}
725 	if (_flagsTable[8] == 2 && _locationMaskType == 0) {
726 		_flagsTable[8] = 0;
727 		startSound(_locationSoundsTable[7]._offset, 7, _locationSoundsTable[7]._volume);
728 	}
729 }
730 
execData3PostUpdate_locationNum9()731 void TuckerEngine::execData3PostUpdate_locationNum9() {
732 	if (_spritesTable[1]._state == 4) {
733 		if (_spritesTable[1]._flipX) {
734 			--_updateLocationXPosTable2[0];
735 			if (_updateLocationXPosTable2[0] < -50) {
736 				_spritesTable[1]._flipX = false;
737 				_updateLocationXPosTable2[0] = -50;
738 			}
739 		} else {
740 			++_updateLocationXPosTable2[0];
741 			if (_updateLocationXPosTable2[0] > 500) {
742 				_spritesTable[1]._flipX = true;
743 				_updateLocationXPosTable2[0] = 500;
744 			}
745 		}
746 	}
747 	_spritesTable[1]._gfxBackgroundOffset = _updateLocationXPosTable2[0] + 8320;
748 	for (int i = 1; i < 3; ++i) {
749 		_spritesTable[i]._colorType = 1;
750 		_spritesTable[i]._yMaxBackground = 60;
751 		drawSprite(i);
752 		_spritesTable[i]._colorType = 0;
753 	}
754 }
755 
updateSprite_locationNum10()756 void TuckerEngine::updateSprite_locationNum10() {
757 	int state = 0;
758 	const int r = getRandomNumber();
759 	if (_flagsTable[99] == 1) {
760 		state = -1;
761 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
762 		_spritesTable[0]._needUpdate = true;
763 		if (r < 26000) {
764 			state = 1;
765 		} else if (r < 29000) {
766 			state = 2;
767 		} else {
768 			state = 3;
769 		}
770 	} else if (_csDataHandled) {
771 		state = 2;
772 		_spritesTable[0]._updateDelay = 4;
773 	} else {
774 		_spritesTable[0]._needUpdate = false;
775 		if (r > 26000) {
776 			state = 5;
777 			_spritesTable[0]._prevAnimationFrame = true;
778 		} else if (r > 24000) {
779 			state = 6;
780 			_miscSoundFxDelayCounter[0] = 120;
781 			_miscSoundFxNum[0] = 0;
782 		} else {
783 			setCharacterAnimation(0, 0);
784 		}
785 	}
786 	_spritesTable[0]._state = state;
787 }
788 
execData3PreUpdate_locationNum10()789 void TuckerEngine::execData3PreUpdate_locationNum10() {
790 	if (_execData3Counter == 0) {
791 		_execData3Counter = 1;
792 		++_flagsTable[68];
793 		if (_flagsTable[68] > 2) {
794 			_flagsTable[68] = 0;
795 		}
796 	}
797 	if (_flagsTable[47] == 1 && _inventoryItemsState[26] == 1) {
798 		_flagsTable[47] = 2;
799 	}
800 	if (_spritesTable[0]._state == 6 && _spritesTable[0]._animationFrame == 18 && !isSoundPlaying(0)) {
801 		startSound(_locationSoundsTable[0]._offset, 0, _locationSoundsTable[0]._volume);
802 	}
803 	if (_flagsTable[230] == 1 && getRandomNumber() > 32000) {
804 		_flagsTable[230] = 0;
805 	}
806 }
807 
updateSprite_locationNum11_0(int i)808 void TuckerEngine::updateSprite_locationNum11_0(int i) {
809 	const int r = getRandomNumber();
810 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
811 		_spritesTable[i]._needUpdate = true;
812 		_spritesTable[i]._state = 2;
813 	} else {
814 		_spritesTable[i]._needUpdate = false;
815 		if (r > 28000) {
816 			_spritesTable[i]._state = 3;
817 		} else if (r > 20000) {
818 			_spritesTable[i]._state = 4;
819 		} else {
820 			_spritesTable[i]._state = 3;
821 			_spritesTable[i]._animationFrame = 1;
822 			_spritesTable[i]._updateDelay = 5;
823 		}
824 	}
825 }
826 
updateSprite_locationNum11_1(int i)827 void TuckerEngine::updateSprite_locationNum11_1(int i) {
828 	if (getRandomNumber() > 20000) {
829 		_spritesTable[i]._state = 5;
830 	} else {
831 		_spritesTable[i]._animationFrame = 14;
832 		_updateSpriteFlag1 = true;
833 		_spritesTable[i]._state = 5;
834 	}
835 }
836 
updateSprite_locationNum11_2(int i)837 void TuckerEngine::updateSprite_locationNum11_2(int i) {
838 	if (getRandomNumber() > 20000) {
839 		_spritesTable[i]._state = 6;
840 	} else {
841 		_spritesTable[i]._animationFrame = 17;
842 		_spritesTable[i]._state = 6;
843 		_updateSpriteFlag1 = true;
844 	}
845 }
846 
updateSprite_locationNum11_3(int i)847 void TuckerEngine::updateSprite_locationNum11_3(int i) {
848 	_spritesTable[i]._state = 7;
849 }
850 
updateSprite_locationNum11_4(int i)851 void TuckerEngine::updateSprite_locationNum11_4(int i) {
852 	if (getRandomNumber() > 30000 && _flagsTable[55] < 2) {
853 		_spritesTable[i]._state = 1;
854 		startSound(_locationSoundsTable[6]._offset, 6, _locationSoundsTable[6]._volume);
855 	} else {
856 		_spritesTable[i]._state = -1;
857 	}
858 }
859 
updateSprite_locationNum12_0(int i)860 void TuckerEngine::updateSprite_locationNum12_0(int i) {
861 	++_updateLocationCounter2;
862 	if (_updateLocationCounter2 > 11) {
863 		_updateLocationCounter2 = 0;
864 	}
865 	int state;
866 	if (_flagsTable[207] > 0) {
867 		state = -1;
868 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
869 		_spritesTable[i]._needUpdate = true;
870 		state = 5;
871 	} else {
872 		_spritesTable[i]._needUpdate = false;
873 		if (_updateLocationCounter2 < 4) {
874 			state = 1;
875 		} else if (_updateLocationCounter2 < 8) {
876 			state = 2;
877 		} else {
878 			state = 4;
879 		}
880 	}
881 	_spritesTable[i]._state = state;
882 }
883 
updateSprite_locationNum12_1(int i)884 void TuckerEngine::updateSprite_locationNum12_1(int i) {
885 	int state;
886 	const int r = getRandomNumber();
887 	if (r > 22000) {
888 		state = 6;
889 	} else if (r > 10000) {
890 		state = 7;
891 	} else {
892 		state = 8;
893 	}
894 	_spritesTable[i]._state = state;
895 }
896 
execData3PreUpdate_locationNum12()897 void TuckerEngine::execData3PreUpdate_locationNum12() {
898 	if (_inventoryItemsState[12] == 1 && _flagsTable[38] == 0) {
899 		_flagsTable[38] = 1;
900 	}
901 	if (_flagsTable[41] == 0) {
902 		if (_locationMusicsTable[0]._volume != 100) {
903 			_locationMusicsTable[0]._volume = 100;
904 			setVolumeMusic(0, 100);
905 		}
906 	} else {
907 		if (_locationMusicsTable[0]._volume != 20) {
908 			_locationMusicsTable[0]._volume = 20;
909 			setVolumeMusic(0, 20);
910 		}
911 	}
912 }
913 
updateSprite_locationNum13(int i)914 void TuckerEngine::updateSprite_locationNum13(int i) {
915 	int state = 0;
916 	if (_csDataHandled) {
917 		if (_flagsTable[202] == 0) {
918 			_flagsTable[202] = 1;
919 			state = 3;
920 			_spritesTable[i]._stateIndex = -1;
921 		} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
922 			state = 4;
923 			_spritesTable[i]._needUpdate = true;
924 		} else {
925 			_spritesTable[i]._needUpdate = false;
926 			state = 5;
927 		}
928 	} else if (_flagsTable[202] == 1) {
929 		_spritesTable[i]._needUpdate = false;
930 		_flagsTable[202] = 0;
931 		state = 6;
932 	} else {
933 		setCharacterAnimation(0, 0);
934 		return;
935 	}
936 	_spritesTable[i]._state = state;
937 }
938 
execData3PreUpdate_locationNum13()939 void TuckerEngine::execData3PreUpdate_locationNum13() {
940 	if (_flagsTable[69] == 0) {
941 		if (getRandomNumber() > 31000) {
942 			_flagsTable[69] = 1;
943 			startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
944 		} else if (isSoundPlaying(1)) {
945 			stopSound(1);
946 		}
947 	}
948 	_flagsTable[8] = 2;
949 	if (_spritesTable[0]._state == 1) {
950 		if (_spritesTable[0]._animationFrame > 10 && _spritesTable[0]._animationFrame < 20) {
951 			if (!isSoundPlaying(0)) {
952 				startSound(_locationSoundsTable[0]._offset, 0, _locationSoundsTable[0]._volume);
953 			}
954 		}
955 	}
956 	if (isSoundPlaying(0)) {
957 		if (_spritesTable[0]._animationFrame > 10 && _spritesTable[0]._animationFrame < 20) {
958 			stopSound(0);
959 		}
960 	}
961 }
962 
updateSprite_locationNum14(int i)963 void TuckerEngine::updateSprite_locationNum14(int i) {
964 	int state = 2;
965 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
966 		_spritesTable[i]._needUpdate = true;
967 		state = (getRandomNumber() < 12000) ? 1 : 3;
968 	} else if (getRandomNumber() < 26000) {
969 		_spritesTable[i]._updateDelay = 5;
970 	}
971 	_spritesTable[i]._state = state;
972 }
973 
execData3PreUpdate_locationNum14()974 void TuckerEngine::execData3PreUpdate_locationNum14() {
975 	if (_yPosCurrent >= 127) {
976 		execData3Update_locationNum14();
977 	}
978 }
979 
execData3Update_locationNum14()980 void TuckerEngine::execData3Update_locationNum14() {
981 	if (!isSoundPlaying(0)) {
982 		int num = -1;
983 		const int i = getRandomNumber();
984 		if (i > 32000) {
985 			num = 0;
986 		} else if (i > 31800) {
987 			num = 3;
988 		} else if (i > 31600) {
989 			num = 4;
990 		} else if (i > 31400) {
991 			num = 7;
992 		}
993 		if (num != -1) {
994 			startSound(_locationSoundsTable[num]._offset, num, _locationSoundsTable[num]._volume);
995 		}
996 	}
997 	_locationHeightTable[14] = (_xPosCurrent < 100) ? 0 : 60;
998 	if (_updateLocationFadePaletteCounter == 0) {
999 		for (int i = 0; i < 10; ++i) {
1000 			_updateLocation14ObjNum[i] = 0;
1001 		}
1002 	}
1003 	++_updateLocationFadePaletteCounter;
1004 	if (_updateLocationFadePaletteCounter > 4) {
1005 		_updateLocationFadePaletteCounter = 1;
1006 	}
1007 	for (int i = 0; i < 10; ++i) {
1008 		execData3PreUpdate_locationNum14Helper1(i);
1009 		if (_updateLocationFadePaletteCounter == 1 && _updateLocation14ObjNum[i] > 0) {
1010 			execData3PreUpdate_locationNum14Helper2(i);
1011 		}
1012 		const int num = _updateLocation14ObjNum[i];
1013 		if (num > 0) {
1014 			const int w = _dataTable[num]._xSize;
1015 			const int h = _dataTable[num]._ySize;
1016 			const int x = _updateLocationXPosTable2[i] - w / 2;
1017 			const int y = _updateLocationYPosTable2[i] / 16 - h / 2;
1018 			Graphics::decodeRLE_248(_locationBackgroundGfxBuf + y * 640 + x, _data3GfxBuf + _dataTable[num]._sourceOffset, w, h, 0, 0, false);
1019 			addDirtyRect(x, y, w, h);
1020 		}
1021 	}
1022 }
1023 
execData3PreUpdate_locationNum14Helper1(int i)1024 void TuckerEngine::execData3PreUpdate_locationNum14Helper1(int i) {
1025 	const int y = 117 * 16;
1026 	if (_updateLocation14ObjNum[i] == 0) {
1027 		if (getRandomNumber() <= 30000) {
1028 			return;
1029 		}
1030 		_updateLocationXPosTable2[i] = 155;
1031 		_updateLocationYPosTable2[i] = y;
1032 		_updateLocation14Step[i] = -55 - getRandomNumber() / 512;
1033 		_updateLocation14ObjNum[i] = 231;
1034 		_updateLocation14Delay[i] = 16 + getRandomNumber() / 2048;
1035 	}
1036 	_updateLocation14Step[i] += 4;
1037 	_updateLocationYPosTable2[i] += _updateLocation14Step[i];
1038 	if (_updateLocationYPosTable2[i] > y) {
1039 		_updateLocationYPosTable2[i] = y;
1040 		_updateLocation14Step[i] = (-(getRandomNumber() + 32000) * _updateLocation14Step[i]) / 65536;
1041 	}
1042 	--_updateLocationXPosTable2[i];
1043 	if (_updateLocationXPosTable2[i] == 0) {
1044 		_updateLocation14ObjNum[i] = 0;
1045 	}
1046 }
1047 
execData3PreUpdate_locationNum14Helper2(int i)1048 void TuckerEngine::execData3PreUpdate_locationNum14Helper2(int i) {
1049 	--_updateLocation14Delay[i];
1050 	if (_updateLocation14Delay[i] == 0) {
1051 		_updateLocation14ObjNum[i] = 236;
1052 	} else {
1053 		++_updateLocation14ObjNum[i];
1054 		if (_updateLocation14ObjNum[i] > 237) {
1055 			_updateLocation14ObjNum[i] = 0;
1056 		} else if (_updateLocation14ObjNum[i] == 235) {
1057 			_updateLocation14ObjNum[i] = 231;
1058 		}
1059 	}
1060 }
1061 
execData3PostUpdate_locationNum14()1062 void TuckerEngine::execData3PostUpdate_locationNum14() {
1063 	if (_yPosCurrent < 127) {
1064 		execData3Update_locationNum14();
1065 	}
1066 }
1067 
updateSprite_locationNum15_0(int i)1068 void TuckerEngine::updateSprite_locationNum15_0(int i) {
1069 	_spritesTable[i]._state = -1;
1070 }
1071 
updateSprite_locationNum15_1(int i)1072 void TuckerEngine::updateSprite_locationNum15_1(int i) {
1073 	int state;
1074 	int r = getRandomNumber();
1075 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1076 		_spritesTable[i]._needUpdate = true;
1077 		state = 6;
1078 	} else {
1079 		_spritesTable[i]._needUpdate = false;
1080 		if (r < 26000) {
1081 			state = 5;
1082 		} else if (r < 29000) {
1083 			state = 2;
1084 			_spritesTable[i]._prevAnimationFrame = true;
1085 		} else {
1086 			state = 4;
1087 			_spritesTable[4]._counter = 1;
1088 		}
1089 	}
1090 	_spritesTable[i]._state = state;
1091 }
1092 
updateSprite_locationNum15_2(int i)1093 void TuckerEngine::updateSprite_locationNum15_2(int i) {
1094 	_spritesTable[i]._state = 3;
1095 	if (_spritesTable[4]._counter > 0) {
1096 		++_spritesTable[4]._counter;
1097 		if (_spritesTable[4]._counter > 6) {
1098 			_spritesTable[4]._counter = 0;
1099 		} else {
1100 			_spritesTable[i]._updateDelay = 2;
1101 		}
1102 	} else {
1103 		_spritesTable[i]._updateDelay = 2;
1104 	}
1105 }
1106 
execData3PreUpdate_locationNum15()1107 void TuckerEngine::execData3PreUpdate_locationNum15() {
1108 	++_updateLocationFadePaletteCounter;
1109 	if (_updateLocationFadePaletteCounter > 500) {
1110 		if (!isSoundPlaying(1) && getRandomNumber() > 31000) {
1111 			const int i = getRandomNumber() / 4714;
1112 			startSound(_locationSoundsTable[i]._offset, i, _locationSoundsTable[i]._volume);
1113 			_updateLocationFadePaletteCounter = 0;
1114 		}
1115 	}
1116 }
1117 
updateSprite_locationNum16_0(int i)1118 void TuckerEngine::updateSprite_locationNum16_0(int i) {
1119 	int state = 0;
1120 	int r = getRandomNumber();
1121 	if (_flagsTable[210] > 0) {
1122 		state = -1;
1123 	} else if (_flagsTable[82] == 1) {
1124 		state = 2;
1125 		_flagsTable[82] = 2;
1126 	} else if (_flagsTable[82] == 2) {
1127 		state = -1;
1128 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
1129 		if (!_spritesTable[0]._needUpdate) {
1130 			_spritesTable[0]._needUpdate = true;
1131 			state = 1;
1132 		} else {
1133 			state = 1;
1134 			_spritesTable[0]._animationFrame = 2;
1135 			_updateSpriteFlag1 = true;
1136 		}
1137 	} else if (_csDataHandled) {
1138 		_spritesTable[0]._needUpdate = false;
1139 		state = 4;
1140 		_spritesTable[0]._updateDelay = 5;
1141 	} else if (r < 30000) {
1142 		state = 4;
1143 		_spritesTable[0]._updateDelay = 5;
1144 	} else if (r < 31000) {
1145 		state = 4;
1146 		if (_xPosCurrent < 300) {
1147 			_miscSoundFxDelayCounter[0] = 2;
1148 			_miscSoundFxNum[0] = 9;
1149 		}
1150 	} else if (r < 32000) {
1151 		state = 5;
1152 	} else {
1153 		state = 6;
1154 	}
1155 	_spritesTable[i]._state = state;
1156 }
1157 
updateSprite_locationNum16_1(int i)1158 void TuckerEngine::updateSprite_locationNum16_1(int i) {
1159 	int state;
1160 	if (_flagsTable[61] == 0) {
1161 		state = -1;
1162 		if (isSoundPlaying(0)) {
1163 			stopSound(0);
1164 		} else if (isSoundPlaying(1)) {
1165 			stopSound(1);
1166 		}
1167 	} else if (_flagsTable[60] == 0) {
1168 		state = 10;
1169 		if (isSoundPlaying(1)) {
1170 			_locationSoundsTable[1]._type = 2;
1171 			startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
1172 		}
1173 	} else {
1174 		state = 9;
1175 		if (isSoundPlaying(0)) {
1176 			_locationSoundsTable[0]._type = 2;
1177 			startSound(_locationSoundsTable[0]._offset, 0, _locationSoundsTable[0]._volume);
1178 		}
1179 	}
1180 	_spritesTable[i]._state = state;
1181 	_spritesTable[i]._gfxBackgroundOffset = 320;
1182 }
1183 
updateSprite_locationNum16_2(int i)1184 void TuckerEngine::updateSprite_locationNum16_2(int i) {
1185 	int state = -1;
1186 	if (_flagsTable[78] == 0) {
1187 		if (_flagsTable[60] == 1 && _flagsTable[61] == 1) {
1188 			_flagsTable[78] = 1;
1189 			startSound(_locationSoundsTable[5]._offset, 5, _locationSoundsTable[5]._volume);
1190 			state = 7;
1191 		}
1192 	} else if (_flagsTable[78] == 1) {
1193 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1194 			_spritesTable[i]._needUpdate = true;
1195 			state = 8;
1196 		} else {
1197 			if (getRandomNumber() > 32000) {
1198 				state = 7;
1199 			} else if (getRandomNumber() > 10000) {
1200 				state = 13;
1201 				_spritesTable[i]._updateDelay = 5;
1202 			} else {
1203 				state = 13;
1204 			}
1205 			_spritesTable[i]._needUpdate = true;
1206 		}
1207 	}
1208 	_spritesTable[i]._state = state;
1209 	_spritesTable[i]._gfxBackgroundOffset = 320;
1210 }
1211 
execData3PreUpdate_locationNum16()1212 void TuckerEngine::execData3PreUpdate_locationNum16() {
1213 	_locationHeightTable[16] = (_xPosCurrent < 320) ? 60 : 0;
1214 }
1215 
updateSprite_locationNum17()1216 void TuckerEngine::updateSprite_locationNum17() {
1217 	int state;
1218 	if (_flagsTable[76] > 0) {
1219 		state = -1;
1220 		_disableCharactersPath = false;
1221 	} else if (_flagsTable[82] == 2) {
1222 		_flagsTable[82] = 3;
1223 		_disableCharactersPath = true;
1224 		_spritesTable[0]._gfxBackgroundOffset = 100;
1225 		state = 1;
1226 		_spritesTable[0]._backgroundOffset = -1;
1227 	} else if (_spritesTable[0]._gfxBackgroundOffset < -160) {
1228 		state = -1;
1229 	} else {
1230 		state = 1;
1231 		_spritesTable[0]._yMaxBackground = 0;
1232 		_spritesTable[0]._colorType = 1;
1233 	}
1234 	_spritesTable[0]._state = state;
1235 }
1236 
updateSprite_locationNum18()1237 void TuckerEngine::updateSprite_locationNum18() {
1238 	int state;
1239 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
1240 		_spritesTable[0]._needUpdate = true;
1241 		state = 2;
1242 	} else {
1243 		_spritesTable[0]._needUpdate = false;
1244 		state = 1;
1245 		const int r = getRandomNumber();
1246 		if (r > 31000) {
1247 			state = 3;
1248 		} else if (r > 30000) {
1249 			state = 4;
1250 		}
1251 	}
1252 	_spritesTable[0]._gfxBackgroundOffset = 0;
1253 	_spritesTable[0]._backgroundOffset = 0;
1254 	_spritesTable[0]._state = state;
1255 }
1256 
updateSprite_locationNum19_0(int i)1257 void TuckerEngine::updateSprite_locationNum19_0(int i) {
1258 	int state;
1259 	if (_flagsTable[206] == 1) {
1260 		state = 7;
1261 		_spritesTable[i]._needUpdate = false;
1262 		_flagsTable[206] = 0;
1263 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1264 		++_spritesTable[i]._counter;
1265 		_spritesTable[i]._needUpdate = true;
1266 		if (_spritesTable[i]._counter > 10) {
1267 			_spritesTable[i]._counter = 0;
1268 			state = 2;
1269 		} else {
1270 			state = 1;
1271 		}
1272 	} else {
1273 		_spritesTable[i]._needUpdate = false;
1274 		if (_spritesTable[i]._counter > 10) {
1275 			_spritesTable[i]._counter = 0;
1276 		}
1277 		if (_spritesTable[i]._counter == 2) {
1278 			state = 4;
1279 			_spritesTable[i]._prevAnimationFrame = true;
1280 		} else if (_spritesTable[i]._counter == 5) {
1281 			state = 5;
1282 			_spritesTable[i]._prevAnimationFrame = true;
1283 		} else {
1284 			state = 5;
1285 			_spritesTable[i]._updateDelay = 6;
1286 		}
1287 	}
1288 	_spritesTable[i]._state = state;
1289 	_spritesTable[i]._prevAnimationFrame = true;
1290 }
1291 
updateSprite_locationNum19_1(int i)1292 void TuckerEngine::updateSprite_locationNum19_1(int i) {
1293 	_spritesTable[i]._state = 9;
1294 	_spritesTable[i]._gfxBackgroundOffset = 320;
1295 }
1296 
updateSprite_locationNum19_2(int i)1297 void TuckerEngine::updateSprite_locationNum19_2(int i) {
1298 	_spritesTable[i]._gfxBackgroundOffset = 320;
1299 	_spritesTable[i]._state = -1;
1300 }
1301 
updateSprite_locationNum19_3(int i)1302 void TuckerEngine::updateSprite_locationNum19_3(int i) {
1303 	setCharacterAnimation(0, i);
1304 }
1305 
execData3PreUpdate_locationNum19()1306 void TuckerEngine::execData3PreUpdate_locationNum19() {
1307 	_locationHeightTable[19] = (_locationMaskType == 0) ? 0 : 60;
1308 }
1309 
updateSprite_locationNum21()1310 void TuckerEngine::updateSprite_locationNum21() {
1311 	int state;
1312 	if (_flagsTable[58] == 2) {
1313 		state = 5;
1314 		_flagsTable[58] = 3;
1315 		setVolumeSound(2, 0);
1316 	} else if (_flagsTable[58] == 3) {
1317 		state = 6;
1318 		_flagsTable[58] = 4;
1319 		_locationSoundsTable[0]._volume = 60;
1320 		_locationSoundsTable[5]._volume = 60;
1321 	} else if (_flagsTable[58] == 4) {
1322 		state = 7;
1323 		_locationSoundsTable[4]._volume = 60;
1324 	} else if (_flagsTable[59] == 4) {
1325 		_spritesTable[0]._needUpdate = true;
1326 		_flagsTable[59] = 2;
1327 		state = 2;
1328 		setVolumeSound(2, 0);
1329 	} else if (_flagsTable[59] == 3) {
1330 		_flagsTable[59] = 0;
1331 		state = 4;
1332 		setVolumeSound(2, _locationSoundsTable[2]._volume);
1333 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
1334 		_spritesTable[0]._needUpdate = true;
1335 		state = 3;
1336 	} else if (_flagsTable[59] == 2) {
1337 		_spritesTable[0]._needUpdate = false;
1338 		state = 3;
1339 		_spritesTable[0]._updateDelay = 5;
1340 	} else if (_flagsTable[15] == 1) {
1341 		state = 3;
1342 		_spritesTable[0]._updateDelay = 5;
1343 	} else {
1344 		_spritesTable[0]._needUpdate = false;
1345 		state = 1;
1346 	}
1347 	_spritesTable[0]._state = state;
1348 	_spritesTable[0]._gfxBackgroundOffset = 320;
1349 }
1350 
execData3PreUpdate_locationNum21()1351 void TuckerEngine::execData3PreUpdate_locationNum21() {
1352 	if (_xPosCurrent > 460 && _flagsTable[58] == 0 && _nextAction == 0) {
1353 		_currentActionVerb = kVerbWalk;
1354 		_pendingActionDelay = 0;
1355 		_flagsTable[59] = 1;
1356 		_nextAction = 2;
1357 		_csDataLoaded = false;
1358 	}
1359 	if (_flagsTable[58] > 0 && !isSoundPlaying(0)) {
1360 		const int r = getRandomNumber();
1361 		if (r > 10000) {
1362 			int num;
1363 			if (r > 25000) {
1364 				num = 0;
1365 			} else if (r > 17000) {
1366 				num = 4;
1367 			} else {
1368 				num = 5;
1369 			}
1370 			startSound(_locationSoundsTable[num]._offset, num, _locationSoundsTable[num]._volume);
1371 		}
1372 	}
1373 	if (_spritesTable[0]._state == 6) {
1374 		if (_spritesTable[0]._animationFrame < 18) {
1375 			_spritesTable[0]._gfxBackgroundOffset = 320 + _spritesTable[0]._animationFrame * 638;
1376 		} else {
1377 			_spritesTable[0]._gfxBackgroundOffset = 11840 - _spritesTable[0]._animationFrame * 2;
1378 		}
1379 	} else {
1380 		_spritesTable[0]._gfxBackgroundOffset = 320;
1381 	}
1382 	if (_inventoryItemsState[19] > 0) {
1383 		_flagsTable[43] = 1;
1384 	}
1385 }
1386 
execData3PostUpdate_locationNum21()1387 void TuckerEngine::execData3PostUpdate_locationNum21() {
1388 	if (_flagsTable[58] > 3) {
1389 		drawSprite(0);
1390 	}
1391 }
1392 
execData3PreUpdate_locationNum22()1393 void TuckerEngine::execData3PreUpdate_locationNum22() {
1394 	if (_flagsTable[53] > 1 && _flagsTable[53] != 4) {
1395 		if (_inventoryItemsState[5] > 0 && _inventoryItemsState[20] > 0 && _inventoryItemsState[16] > 0 && _inventoryItemsState[27] > 0) {
1396 			_flagsTable[53] = 3;
1397 		} else if (_inventoryItemsState[5] > 0 || _inventoryItemsState[20] > 0 || _inventoryItemsState[16] > 0 || _inventoryItemsState[27] > 0) {
1398 			_flagsTable[53] = 5;
1399 		}
1400 	}
1401 	if (_flagsTable[210] < 2 && !_csDataHandled && _flagsTable[54] == 1) {
1402 		_nextAction = 25;
1403 		_csDataLoaded = false;
1404 		_flagsTable[210] = 2;
1405 	}
1406 }
1407 
updateSprite_locationNum22()1408 void TuckerEngine::updateSprite_locationNum22() {
1409 	if (_flagsTable[207] == 1) {
1410 		_spritesTable[0]._state = -1;
1411 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
1412 		_spritesTable[0]._needUpdate = true;
1413 		_spritesTable[0]._state = 2;
1414 	} else {
1415 		_spritesTable[0]._needUpdate = false;
1416 		_spritesTable[0]._state = 1;
1417 	}
1418 }
1419 
updateSprite_locationNum23_0(int i)1420 void TuckerEngine::updateSprite_locationNum23_0(int i) {
1421 	int state;
1422 	if (_flagsTable[210] == 3) {
1423 		state = 12;
1424 	} else {
1425 		state = -1;
1426 	}
1427 	_spritesTable[i]._state = state;
1428 }
1429 
updateSprite_locationNum23_1(int i)1430 void TuckerEngine::updateSprite_locationNum23_1(int i) {
1431 	int state;
1432 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1433 		_spritesTable[i]._needUpdate = true;
1434 		state = 14;
1435 	} else if (getRandomNumber() < 30000) {
1436 		_spritesTable[i]._needUpdate = false;
1437 		state = 25;
1438 	} else {
1439 		_spritesTable[i]._needUpdate = false;
1440 		state = 13;
1441 	}
1442 	_spritesTable[i]._state = state;
1443 }
1444 
updateSprite_locationNum23_2(int i)1445 void TuckerEngine::updateSprite_locationNum23_2(int i) {
1446 	int state = 0;
1447 	if (_flagsTable[210] == 0) {
1448 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1449 			_spritesTable[i]._needUpdate = true;
1450 			state = 6;
1451 		} else {
1452 			_spritesTable[i]._needUpdate = false;
1453 			state = (getRandomNumber() < 25000) ? 4 : 5;
1454 		}
1455 	} else if (_flagsTable[210] == 1) {
1456 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1457 			_spritesTable[i]._needUpdate = true;
1458 			if (_flagsTable[211] == 10) {
1459 				state = 34;
1460 			} else if (_flagsTable[211] == 0) {
1461 				state = 30;
1462 				_flagsTable[211] = 1;
1463 			} else {
1464 				state = 31;
1465 			}
1466 		} else {
1467 			_spritesTable[i]._needUpdate = false;
1468 			if (_flagsTable[211] == 1) {
1469 				state = 32;
1470 				_flagsTable[211] = 0;
1471 			} else {
1472 				state = (getRandomNumber() < 25000) ? 10 : 11;
1473 			}
1474 		}
1475 	} else if (_flagsTable[210] == 2) {
1476 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1477 			_spritesTable[i]._needUpdate = true;
1478 			state = 33;
1479 		} else {
1480 			_spritesTable[i]._needUpdate = false;
1481 			if (_flagsTable[212] == 0) {
1482 				state = 3;
1483 				_flagsTable[212] = 1;
1484 			} else if (_flagsTable[212] == 2) {
1485 				state = 29;
1486 				_flagsTable[212] = 3;
1487 			} else {
1488 				state = (getRandomNumber() < 25000) ? 22 : 23;
1489 			}
1490 		}
1491 	} else {
1492 		state = 24;
1493 	}
1494 	_spritesTable[i]._state = state;
1495 }
1496 
updateSprite_locationNum23_3(int i)1497 void TuckerEngine::updateSprite_locationNum23_3(int i) {
1498 	int state;
1499 	if (_flagsTable[210] == 0 || _flagsTable[210] == 2) {
1500 		state = -1;
1501 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1502 		_spritesTable[i]._needUpdate = true;
1503 		state = 8;
1504 	} else {
1505 		_spritesTable[i]._needUpdate = false;
1506 		state = 9;
1507 	}
1508 	_spritesTable[i]._state = state;
1509 }
1510 
updateSprite_locationNum24_0(int i)1511 void TuckerEngine::updateSprite_locationNum24_0(int i) {
1512 	int state;
1513 	if (_flagsTable[103] == 4) {
1514 		_flagsTable[103] = 3;
1515 		state = 5;
1516 	} else if (_flagsTable[103] == 0) {
1517 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1518 			_spritesTable[i]._needUpdate = true;
1519 			state = 2;
1520 		} else {
1521 			_spritesTable[i]._needUpdate = true;
1522 			state = 1;
1523 			if (getRandomNumber() < 30000) {
1524 				_spritesTable[i]._updateDelay = 5;
1525 			}
1526 		}
1527 	} else if (_flagsTable[103] == 1 || _flagsTable[103] == 3) {
1528 		state = -1;
1529 	} else {
1530 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1531 			_spritesTable[i]._needUpdate = true;
1532 			state = 4;
1533 		} else {
1534 			if (getRandomNumber() < 30000) {
1535 				_spritesTable[i]._needUpdate = false;
1536 				state = 6;
1537 				_spritesTable[i]._updateDelay = 5;
1538 			} else {
1539 				_spritesTable[i]._needUpdate = false;
1540 				state = 6;
1541 			}
1542 		}
1543 	}
1544 	_spritesTable[i]._state = state;
1545 }
1546 
updateSprite_locationNum24_1(int i)1547 void TuckerEngine::updateSprite_locationNum24_1(int i) {
1548 	if (_flagsTable[103] > 1) {
1549 		_spritesTable[i]._state = 3;
1550 	} else {
1551 		_spritesTable[i]._state = -1;
1552 	}
1553 }
1554 
updateSprite_locationNum24_2(int i)1555 void TuckerEngine::updateSprite_locationNum24_2(int i) {
1556 	int state;
1557 	if (_flagsTable[214] > 1) {
1558 		state = -1;
1559 	} else if (_flagsTable[214] == 1) {
1560 		_spritesTable[i]._needUpdate = false;
1561 		_flagsTable[214] = 2;
1562 		state = 9;
1563 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1564 		_spritesTable[i]._needUpdate = true;
1565 		if (_flagsTable[213] == 1) {
1566 			state = 10;
1567 		} else if (_flagsTable[213] == 2) {
1568 			state = 14;
1569 		} else {
1570 			state = 8;
1571 		}
1572 	} else {
1573 		_spritesTable[i]._needUpdate = true;
1574 		state = 7;
1575 	}
1576 	_spritesTable[i]._state = state;
1577 }
1578 
updateSprite_locationNum24_3(int i)1579 void TuckerEngine::updateSprite_locationNum24_3(int i) {
1580 	int state;
1581 	if (_flagsTable[239] == 1) {
1582 		state = -1;
1583 	} else if (_flagsTable[214] == 2) {
1584 		_flagsTable[239] = 1;
1585 		state = 13;
1586 	} else if (getRandomNumber() > 32000) {
1587 		state = 12;
1588 	} else {
1589 		state = 11;
1590 	}
1591 	_spritesTable[i]._state = state;
1592 }
1593 
execData3PreUpdate_locationNum24()1594 void TuckerEngine::execData3PreUpdate_locationNum24() {
1595 	_characterPrevBackFrontFacing = false;
1596 	if (_flagsTable[112] == 0) {
1597 		_yPosCurrent = 132;
1598 		_xPosCurrent = 112;
1599 	} else if (_inventoryItemsState[2] == 1 && _inventoryItemsState[11] == 1 && _flagsTable[156] == 1 && _flagsTable[145] == 3) {
1600 		_flagsTable[156] = 2;
1601 		_nextAction = 61;
1602 		_csDataLoaded = false;
1603 	}
1604 	if (_flagsTable[103] > 0 && (_inventoryItemsState[2] > 0 || _inventoryItemsState[11] > 0 || _flagsTable[156] > 0 || _flagsTable[145] == 3) && _flagsTable[217] == 0) {
1605 		_flagsTable[217] = 1;
1606 	}
1607 	_locationHeightTable[24] = (_yPosCurrent < 125) ? 60 : 0;
1608 }
1609 
execData3PostUpdate_locationNum24()1610 void TuckerEngine::execData3PostUpdate_locationNum24() {
1611 	if (_yPosCurrent < 132) {
1612 		drawSprite(1);
1613 		drawSprite(0);
1614 	}
1615 }
1616 
execData3PreUpdate_locationNum25()1617 void TuckerEngine::execData3PreUpdate_locationNum25() {
1618 	_backgroundSprOffset = _xPosCurrent - 160;
1619 }
1620 
updateSprite_locationNum26_0(int i)1621 void TuckerEngine::updateSprite_locationNum26_0(int i) {
1622 	if (_flagsTable[125] > 0 && _flagsTable[125] < 300) {
1623 		_flagsTable[126] = 1;
1624 	}
1625 	_spritesTable[i]._gfxBackgroundOffset = _flagsTable[125];
1626 	_spritesTable[i]._state = 1;
1627 	_spritesTable[i]._colorType = 99;
1628 }
1629 
updateSprite_locationNum26_1(int i)1630 void TuckerEngine::updateSprite_locationNum26_1(int i) {
1631 	int state;
1632 	if (_flagsTable[125] == 0) {
1633 		state = -1;
1634 	} else if (_flagsTable[125] > 299) {
1635 		state = 2;
1636 		_spritesTable[i]._updateDelay = 5;
1637 	} else {
1638 		state = 2;
1639 	}
1640 	_spritesTable[i]._gfxBackgroundOffset = _flagsTable[125];
1641 	_spritesTable[i]._colorType = 1;
1642 	_spritesTable[i]._state = state;
1643 }
1644 
execData3PreUpdate_locationNum26()1645 void TuckerEngine::execData3PreUpdate_locationNum26() {
1646 	_characterPrevBackFrontFacing = true;
1647 	_spritesTable[1]._gfxBackgroundOffset = _flagsTable[125];
1648 	_spritesTable[0]._gfxBackgroundOffset = _flagsTable[125];
1649 	if (_flagsTable[125] > 0 && _flagsTable[125] < 300) {
1650 		if (!isSoundPlaying(5)) {
1651 			startSound(_locationSoundsTable[5]._offset, 5, _locationSoundsTable[5]._volume);
1652 			startSound(_locationSoundsTable[6]._offset, 6, _locationSoundsTable[6]._volume);
1653 		}
1654 		++_flagsTable[125];
1655 		_flagsTable[126] = 1;
1656 	} else {
1657 		if (isSoundPlaying(5)) {
1658 			stopSound(5);
1659 			stopSound(6);
1660 		}
1661 	}
1662 	if (!_panelLockedFlag) {
1663 		if (_xPosCurrent > 207 && _xPosCurrent < 256) {
1664 			_objectKeysLocationTable[26] = 0;
1665 			_objectKeysPosXTable[26] = 260;
1666 		} else {
1667 			_objectKeysLocationTable[26] = 1;
1668 		}
1669 	}
1670 }
1671 
updateSprite_locationNum27(int i)1672 void TuckerEngine::updateSprite_locationNum27(int i) {
1673 	int state;
1674 	if (_flagsTable[155] < 3 || _flagsTable[155] == 5) {
1675 		state = -1;
1676 	} else if (_flagsTable[155] == 3) {
1677 		state = 1;
1678 		_flagsTable[155] = 4;
1679 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1680 		_spritesTable[i]._needUpdate = true;
1681 		state = 2;
1682 	} else if (getRandomNumber() < 30000) {
1683 		_spritesTable[i]._needUpdate = false;
1684 		state = 3;
1685 		_spritesTable[i]._updateDelay = 5;
1686 	} else {
1687 		_spritesTable[i]._needUpdate = false;
1688 		state = 3;
1689 	}
1690 	_spritesTable[i]._state = state;
1691 }
1692 
execData3PreUpdate_locationNum27()1693 void TuckerEngine::execData3PreUpdate_locationNum27() {
1694 	_characterPrevBackFrontFacing = false;
1695 }
1696 
execData3PostUpdate_locationNum27()1697 void TuckerEngine::execData3PostUpdate_locationNum27() {
1698 	if (_flagsTable[155] == 4 && _yPosCurrent < 125) {
1699 		drawSprite(0);
1700 	}
1701 }
1702 
updateSprite_locationNum28_0(int i)1703 void TuckerEngine::updateSprite_locationNum28_0(int i) {
1704 	int state;
1705 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1706 		state = 4;
1707 		_spritesTable[i]._needUpdate = true;
1708 	} else {
1709 		_spritesTable[i]._needUpdate = false;
1710 		++_spritesTable[i]._counter;
1711 		if (_spritesTable[i]._counter > 30) {
1712 			_spritesTable[i]._counter = 0;
1713 		}
1714 		if (_flagsTable[86] == 1) {
1715 			if (_spritesTable[i]._counter == 16 || _spritesTable[i]._counter == 27) {
1716 				state = 3;
1717 			} else {
1718 				state = 3;
1719 				_spritesTable[i]._updateDelay = 5;
1720 			}
1721 		} else {
1722 			if (_spritesTable[i]._counter == 5 || _spritesTable[i]._counter == 11) {
1723 				state = 5;
1724 			} else if (_spritesTable[i]._counter == 16 || _spritesTable[i]._counter == 27) {
1725 				state = 6;
1726 			} else {
1727 				state = 6;
1728 				_spritesTable[i]._updateDelay = 5;
1729 			}
1730 		}
1731 	}
1732 	_spritesTable[i]._state = state;
1733 }
1734 
updateSprite_locationNum28_1(int i)1735 void TuckerEngine::updateSprite_locationNum28_1(int i) {
1736 	_spritesTable[i]._state = (_flagsTable[86] == 1) ? 1 : -1;
1737 }
1738 
updateSprite_locationNum28_2(int i)1739 void TuckerEngine::updateSprite_locationNum28_2(int i) {
1740 	int state;
1741 	if (_flagsTable[155] == 1) {
1742 		state = 8;
1743 		_flagsTable[155] = 2;
1744 	} else {
1745 		state = -1;
1746 	}
1747 	_spritesTable[i]._state = state;
1748 }
1749 
execData3PreUpdate_locationNum28()1750 void TuckerEngine::execData3PreUpdate_locationNum28() {
1751 	if (_flagsTable[86] == 0 && _xPosCurrent > 265 && _nextAction == 0) {
1752 		_panelLockedFlag = false;
1753 		_nextAction = 21;
1754 		_csDataLoaded = false;
1755 		_pendingActionDelay = 0;
1756 		_pendingActionIndex = 0;
1757 		_currentActionVerb = kVerbWalk;
1758 	}
1759 }
1760 
execData3PostUpdate_locationNum28()1761 void TuckerEngine::execData3PostUpdate_locationNum28() {
1762 	if (_yPosCurrent < 135) {
1763 		drawSprite(1);
1764 	}
1765 }
1766 
updateSprite_locationNum29_0(int i)1767 void TuckerEngine::updateSprite_locationNum29_0(int i) {
1768 	_spritesTable[i]._state = (getRandomNumber() < 32000) ? -1 : 2;
1769 }
1770 
updateSprite_locationNum29_1(int i)1771 void TuckerEngine::updateSprite_locationNum29_1(int i) {
1772 	int state = -1;
1773 	if (getRandomNumber() >= 32000) {
1774 		state = 1;
1775 		_spritesTable[i]._gfxBackgroundOffset = 320;
1776 	}
1777 	_spritesTable[i]._state = state;
1778 }
1779 
updateSprite_locationNum29_2(int i)1780 void TuckerEngine::updateSprite_locationNum29_2(int i) {
1781 	_spritesTable[i]._state = 3;
1782 	_spritesTable[i]._gfxBackgroundOffset = 320;
1783 }
1784 
execData3PreUpdate_locationNum29()1785 void TuckerEngine::execData3PreUpdate_locationNum29() {
1786 	static const uint8 r[] = { 0x0D, 0x0E, 0x0E, 0x0E, 0x0D, 0x0E, 0x0D, 0x0E, 0x0E, 0x0E, 0x0D };
1787 	static const uint8 g[] = { 0x0E, 0x14, 0x1B, 0x14, 0x0E, 0x0D, 0x0E, 0x14, 0x1B, 0x14, 0x0E };
1788 	static const uint8 b[] = { 0x2C, 0x34, 0x3B, 0x34, 0x2C, 0x24, 0x2C, 0x34, 0x3B, 0x34, 0x2C };
1789 	if (_fadePaletteCounter == 16) {
1790 		++_updateLocationFadePaletteCounter;
1791 		if (_updateLocationFadePaletteCounter > 10) {
1792 			_updateLocationFadePaletteCounter = 0;
1793 		}
1794 		const int d = _updateLocationFadePaletteCounter / 2;
1795 		uint8 scrollPal[5 * 3];
1796 		for (int i = 0; i < 5; ++i) {
1797 			// Bug Trac#6378. Shift the palette two bits to the left.
1798 			// The original was writing to 0x3C8-0x3c9 VGA registers which are
1799 			// 6-bit
1800 			scrollPal[i * 3 + 0] = r[i + d] << 2;
1801 			scrollPal[i * 3 + 1] = g[i + d] << 2;
1802 			scrollPal[i * 3 + 2] = b[i + d] << 2;
1803 		}
1804 		_system->getPaletteManager()->setPalette(scrollPal, 118, 5);
1805 
1806 		if (_flagsTable[143] == 1) {
1807 			_locationObjectsTable[2]._xPos = 999;
1808 			_locationObjectsTable[3]._xPos = 187;
1809 		} else {
1810 			_locationObjectsTable[2]._xPos = 187;
1811 			_locationObjectsTable[3]._xPos = 999;
1812 		}
1813 	}
1814 }
1815 
updateSprite_locationNum30_34(int i)1816 void TuckerEngine::updateSprite_locationNum30_34(int i) {
1817 	_spritesTable[i]._state = i + 1;
1818 }
1819 
execData3PreUpdate_locationNum30()1820 void TuckerEngine::execData3PreUpdate_locationNum30() {
1821 	if (!isSoundPlaying(1) && getRandomNumber() > 32500) {
1822 		startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
1823 	}
1824 }
1825 
execData3PreUpdate_locationNum31()1826 void TuckerEngine::execData3PreUpdate_locationNum31() {
1827 	if (getRandomNumber() > 32000 && _flagsTable[110] == 0) {
1828 		_flagsTable[110] = 1;
1829 	}
1830 	if (getRandomNumber() > 31000 && _flagsTable[111] == 0) {
1831 		_flagsTable[111] = 1;
1832 	}
1833 	if (_xPosCurrent < 112 && _flagsTable[104] == 0) {
1834 		_flagsTable[104] = 1;
1835 	}
1836 }
1837 
execData3PreUpdate_locationNum32()1838 void TuckerEngine::execData3PreUpdate_locationNum32() {
1839 	if (_spritesTable[0]._state == 12 && _spritesTable[0]._animationFrame < 22) {
1840 		_flagsTable[113] = 1;
1841 	} else {
1842 		_flagsTable[113] = 0;
1843 	}
1844 }
1845 
execData3PostUpdate_locationNum32()1846 void TuckerEngine::execData3PostUpdate_locationNum32() {
1847 	if (_yPosCurrent < 120) {
1848 		drawSprite(0);
1849 	}
1850 }
1851 
updateSprite_locationNum31_0(int i)1852 void TuckerEngine::updateSprite_locationNum31_0(int i) {
1853 	_spritesTable[i]._state = (getRandomNumber() < 32000) ? 3 : 1;
1854 }
1855 
updateSprite_locationNum31_1(int i)1856 void TuckerEngine::updateSprite_locationNum31_1(int i) {
1857 	_spritesTable[i]._state = (_flagsTable[86] == 1) ? 2 : -1;
1858 }
1859 
updateSprite_locationNum32_0(int i)1860 void TuckerEngine::updateSprite_locationNum32_0(int i) {
1861 	static const uint8 stateTable[] = { 12, 1, 11, 1, 11, 2, 1, 5, 5, 11, 1, 5, 5, 5 };
1862 	++_spritesTable[i]._counter;
1863 	if (_flagsTable[123] == 2) {
1864 		_flagsTable[123] = 0;
1865 	}
1866 	int state;
1867 	if (_flagsTable[222] == 1) {
1868 		state = 19;
1869 		_flagsTable[222] = 2;
1870 	} else if (_flagsTable[222] == 2) {
1871 		state = 19;
1872 		_spritesTable[i]._animationFrame = 23;
1873 		_updateSpriteFlag1 = true;
1874 	} else if (_flagsTable[123] == 1) {
1875 		state = 17;
1876 		_flagsTable[123] = 2;
1877 	} else if (_flagsTable[222] == 3) {
1878 		state = 18;
1879 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1880 		_spritesTable[i]._needUpdate = true;
1881 		state = 4;
1882 	} else if (_csDataHandled) {
1883 		state = 5;
1884 	} else {
1885 		_spritesTable[i]._needUpdate = false;
1886 		if (_spritesTable[i]._counter > 13) {
1887 			_spritesTable[i]._counter = 0;
1888 		}
1889 		state = stateTable[_spritesTable[i]._counter];
1890 	}
1891 	_spritesTable[i]._state = state;
1892 }
1893 
updateSprite_locationNum33_0(int i)1894 void TuckerEngine::updateSprite_locationNum33_0(int i) {
1895 	int state = 5;
1896 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
1897 		_spritesTable[i]._needUpdate = true;
1898 		state = 7;
1899 	} else if (_flagsTable[87] == 1) {
1900 		state = 8;
1901 	} else if (_flagsTable[222] == 5) {
1902 		state = 4;
1903 	} else {
1904 		_spritesTable[i]._needUpdate = false;
1905 		state = (getRandomNumber() < 30000) ? 5 : 6;
1906 	}
1907 	_spritesTable[i]._state = state;
1908 }
1909 
updateSprite_locationNum33_1(int i)1910 void TuckerEngine::updateSprite_locationNum33_1(int i) {
1911 	int state;
1912 	if (_flagsTable[87] == 1) {
1913 		state = 3;
1914 	} else if (_flagsTable[222] == 5) {
1915 		state = 2;
1916 	} else {
1917 		state = 1;
1918 	}
1919 	_spritesTable[i]._state = state;
1920 }
1921 
updateSprite_locationNum33_2(int i)1922 void TuckerEngine::updateSprite_locationNum33_2(int i) {
1923 	int state;
1924 	if (_flagsTable[87] == 1) {
1925 		state = 11;
1926 	} else if (_flagsTable[222] == 5) {
1927 		state = 10;
1928 	} else {
1929 		state = 9;
1930 	}
1931 	_spritesTable[i]._state = state;
1932 }
1933 
execData3PreUpdate_locationNum33()1934 void TuckerEngine::execData3PreUpdate_locationNum33() {
1935 	if (_xPosCurrent < 90) {
1936 		if (_flagsTable[105] == 0) {
1937 			_flagsTable[105] = 3;
1938 			startSound(_locationSoundsTable[5]._offset, 5, _locationSoundsTable[5]._volume);
1939 		}
1940 	} else {
1941 		if (_flagsTable[105] == 1) {
1942 			_flagsTable[105] = 2;
1943 			startSound(_locationSoundsTable[5]._offset, 5, _locationSoundsTable[5]._volume);
1944 		}
1945 	}
1946 	if (_xPosCurrent > 230) {
1947 		if (_flagsTable[106] == 0) {
1948 			_flagsTable[106] = 3;
1949 			startSound(_locationSoundsTable[5]._offset, 5, _locationSoundsTable[5]._volume);
1950 		}
1951 	} else {
1952 		if (_flagsTable[106] == 1) {
1953 			_flagsTable[106] = 2;
1954 			startSound(_locationSoundsTable[5]._offset, 5, _locationSoundsTable[5]._volume);
1955 		}
1956 	}
1957 }
1958 
execData3PreUpdate_locationNum34()1959 void TuckerEngine::execData3PreUpdate_locationNum34() {
1960 	if (_flagsTable[143] == 1) {
1961 		_locationObjectsTable[0]._xPos = 0;
1962 	}
1963 }
1964 
execData3PreUpdate_locationNum35()1965 void TuckerEngine::execData3PreUpdate_locationNum35() {
1966 	if (_flagsTable[250] > 0) {
1967 		_currentFxVolume = 0;
1968 	}
1969 }
1970 
updateSprite_locationNum36(int i)1971 void TuckerEngine::updateSprite_locationNum36(int i) {
1972 	_spritesTable[i]._state = (getRandomNumber() < 32000) ? 1 : 2;
1973 }
1974 
execData3PreUpdate_locationNum36()1975 void TuckerEngine::execData3PreUpdate_locationNum36() {
1976 	if (_execData3Counter == 0) {
1977 		_execData3Counter = 1;
1978 		_flagsTable[107] = 1;
1979 	} else if (_flagsTable[107] == 0 && _locationMaskType == 1 && _execData3Counter == 1) {
1980 		_execData3Counter = 2;
1981 		_flagsTable[107] = 1;
1982 	}
1983 }
1984 
updateSprite_locationNum37(int i)1985 void TuckerEngine::updateSprite_locationNum37(int i) {
1986 	int j = i + 1;
1987 	int offset = 200 - i * 45;
1988 	++_spritesTable[i]._counter;
1989 	if (_spritesTable[i]._counter > offset) {
1990 		_spritesTable[i]._state = j;
1991 		_spritesTable[i]._counter = 0;
1992 	} else {
1993 		_spritesTable[i]._state = -1;
1994 	}
1995 }
1996 
execData3PreUpdate_locationNum38()1997 void TuckerEngine::execData3PreUpdate_locationNum38() {
1998 	if (_flagsTable[117] == 0 && _flagsTable[116] == 1) {
1999 		_flagsTable[116] = 0;
2000 	}
2001 }
2002 
updateSprite_locationNum41(int i)2003 void TuckerEngine::updateSprite_locationNum41(int i) {
2004 	int state;
2005 	if (_flagsTable[223] > 1) {
2006 		state = -1;
2007 	} else if (_flagsTable[223] == 1) {
2008 		state = 1;
2009 		_flagsTable[158] = 2;
2010 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2011 		_spritesTable[i]._needUpdate = true;
2012 		state = 3;
2013 	} else if (getRandomNumber() < 30000) {
2014 		_spritesTable[i]._needUpdate = false;
2015 		state = 5;
2016 	} else {
2017 		_spritesTable[i]._needUpdate = false;
2018 		state = 4;
2019 	}
2020 	_spritesTable[i]._state = state;
2021 }
2022 
execData3PreUpdate_locationNum41()2023 void TuckerEngine::execData3PreUpdate_locationNum41() {
2024 	if (_backgroundSpriteCurrentAnimation == 4) {
2025 		if (_backgroundSpriteCurrentFrame == 8) {
2026 			_flagsTable[77] = 2;
2027 		} else if (_backgroundSpriteCurrentFrame == 7) {
2028 			_flagsTable[77] = 0;
2029 		}
2030 		if (!_changeBackgroundSprite) {
2031 			if (_backgroundSpriteCurrentFrame == 16 && !isSoundPlaying(4)) {
2032 				_locationSoundsTable[4]._type = 2;
2033 				startSound(_locationSoundsTable[4]._offset, 4, _locationSoundsTable[4]._volume);
2034 			} else {
2035 				if (_backgroundSpriteCurrentFrame == 28) {
2036 					stopSound(4);
2037 				}
2038 			}
2039 		} else {
2040 			if (_backgroundSpriteCurrentFrame == 28 && !isSoundPlaying(4)) {
2041 				_locationSoundsTable[4]._type = 2;
2042 				startSound(_locationSoundsTable[4]._offset, 4, _locationSoundsTable[4]._volume);
2043 			} else {
2044 				if (_backgroundSpriteCurrentFrame == 18) {
2045 					stopSound(4);
2046 				}
2047 			}
2048 		}
2049 	}
2050 	if (_panelLockedFlag && _yPosCurrent > 130 && _selectedObject._yPos > 135 && _nextAction == 0 && _flagsTable[223] == 0) {
2051 		_panelLockedFlag = false;
2052 		_csDataLoaded = false;
2053 		_nextLocation = kLocationNone;
2054 		_selectedObject._locationObjectLocation = kLocationNone;
2055 		_locationMaskType = 0;
2056 		_nextAction = _flagsTable[163] + 32;
2057 		++_flagsTable[163];
2058 		if (_flagsTable[163] > 2) {
2059 			_flagsTable[163] = 0;
2060 		}
2061 		if (_flagsTable[223] > 0 && _mapSequenceFlagsLocationTable[40] == 0) {
2062 			for (int i = 41; i < 53; ++i) {
2063 				_mapSequenceFlagsLocationTable[i - 1] = 1;
2064 			}
2065 		}
2066 		if (_flagsTable[77] == 0) {
2067 			_locationObjectsTable[3]._xPos = 230;
2068 		} else {
2069 			_locationObjectsTable[3]._xPos = 930;
2070 		}
2071 	}
2072 }
2073 
updateSprite_locationNum42(int i)2074 void TuckerEngine::updateSprite_locationNum42(int i) {
2075 	int state;
2076 	if (_flagsTable[223] == 0 || _flagsTable[223] > 3) {
2077 		state = -1;
2078 	} else if (_flagsTable[223] == 1) {
2079 		state = 1;
2080 		_flagsTable[223] = 2;
2081 	} else if (_flagsTable[223] == 2) {
2082 		state = 5;
2083 		_flagsTable[223] = 3;
2084 	} else if (_flagsTable[223] == 3) {
2085 		state = 5;
2086 		_spritesTable[i]._updateDelay = 5;
2087 		_spritesTable[i]._state = _spritesTable[i]._firstFrame - 1;
2088 		_updateSpriteFlag1 = true;
2089 	} else {
2090 		state = 2;
2091 	}
2092 	_spritesTable[i]._state = state;
2093 }
2094 
execData3PreUpdate_locationNum42()2095 void TuckerEngine::execData3PreUpdate_locationNum42() {
2096 	_flagsTable[167] = 1;
2097 }
2098 
updateSprite_locationNum43_2(int i)2099 void TuckerEngine::updateSprite_locationNum43_2(int i) {
2100 	int state;
2101 	if (_flagsTable[237] > 0) {
2102 		state = -1;
2103 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2104 		_spritesTable[i]._needUpdate = true;
2105 		state = 5;
2106 	} else if (_csDataHandled || _spritesTable[i]._counter == 2) {
2107 		_spritesTable[i]._needUpdate = false;
2108 		state = 6;
2109 	} else if (_spritesTable[i]._counter == 0) {
2110 		state = 3;
2111 	} else {
2112 		state = 4;
2113 		_spritesTable[i]._counter = 2;
2114 	}
2115 	_spritesTable[i]._state = state;
2116 }
2117 
updateSprite_locationNum43_3(int i)2118 void TuckerEngine::updateSprite_locationNum43_3(int i) {
2119 	int state;
2120 	if (_flagsTable[236] < 4) {
2121 		state = -1;
2122 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2123 		state = 7;
2124 		_spritesTable[i]._needUpdate = true;
2125 	} else {
2126 		state = 8;
2127 		_spritesTable[i]._needUpdate = false;
2128 	}
2129 	_spritesTable[i]._state = state;
2130 }
2131 
updateSprite_locationNum43_4(int i)2132 void TuckerEngine::updateSprite_locationNum43_4(int i) {
2133 	int state;
2134 	if (_flagsTable[236] < 4) {
2135 		state = -1;
2136 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2137 		state = 9;
2138 		_spritesTable[i]._needUpdate = true;
2139 	} else {
2140 		state = 10;
2141 		_spritesTable[i]._needUpdate = false;
2142 	}
2143 	_spritesTable[i]._state = state;
2144 }
2145 
updateSprite_locationNum43_5(int i)2146 void TuckerEngine::updateSprite_locationNum43_5(int i) {
2147 	_spritesTable[i]._state = (_flagsTable[236] < 4) ? -1 : 11;
2148 }
2149 
updateSprite_locationNum43_6(int i)2150 void TuckerEngine::updateSprite_locationNum43_6(int i) {
2151 	_spritesTable[i]._state = (_flagsTable[236] < 4) ? -1 : 12;
2152 }
2153 
execData3PreUpdate_locationNum43()2154 void TuckerEngine::execData3PreUpdate_locationNum43() {
2155 	if (_panelLockedFlag && _xPosCurrent > 67 && _selectedObject._xPos > 68 && _locationMaskType == 0) {
2156 		_panelLockedFlag = false;
2157 		_csDataLoaded = false;
2158 		_nextAction = 5;
2159 	}
2160 	if (_xPosCurrent > 55 && _spritesTable[2]._counter == 0) {
2161 		_spritesTable[2]._counter = 1;
2162 	}
2163 }
2164 
execData3PreUpdate_locationNum44()2165 void TuckerEngine::execData3PreUpdate_locationNum44() {
2166 	if (_backgroundSpriteCurrentAnimation == 1) {
2167 		if (!isSoundPlaying(3) && _backgroundSpriteCurrentFrame == 1) {
2168 			_locationSoundsTable[3]._type = 2;
2169 			startSound(_locationSoundsTable[3]._offset, 3, _locationSoundsTable[3]._volume);
2170 		}
2171 		if (_backgroundSpriteCurrentFrame == 21) {
2172 			_flagsTable[77] = 1;
2173 		} else if (_backgroundSpriteCurrentFrame == 20) {
2174 			_flagsTable[77] = 2;
2175 			stopSound(3);
2176 		}
2177 	} else if (_backgroundSpriteCurrentAnimation == 4) {
2178 		if (_backgroundSpriteCurrentFrame == 20 && !isSoundPlaying(3)) {
2179 			startSound(_locationSoundsTable[3]._offset, 3, _locationSoundsTable[3]._volume);
2180 		}
2181 	}
2182 }
2183 
updateSprite_locationNum48(int i)2184 void TuckerEngine::updateSprite_locationNum48(int i) {
2185 	int state;
2186 	if (_flagsTable[160] == 0 || _flagsTable[160] > 2 || _flagsTable[207] > 0) {
2187 		state = -1;
2188 	} else if (_flagsTable[160] == 2) {
2189 		_flagsTable[160] = 3;
2190 		state = 3;
2191 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2192 		_spritesTable[i]._needUpdate = true;
2193 		state = 2;
2194 	} else {
2195 		_spritesTable[i]._needUpdate = false;
2196 		state = 2;
2197 		_spritesTable[i]._updateDelay = 5;
2198 	}
2199 	_spritesTable[i]._state = state;
2200 }
2201 
updateSprite_locationNum49(int i)2202 void TuckerEngine::updateSprite_locationNum49(int i) {
2203 	if (_flagsTable[136] == 1 && _flagsTable[207] == 0) {
2204 		_flagsTable[136] = 2;
2205 	}
2206 	if (_flagsTable[185] == 0 && _yPosCurrent < 125) {
2207 		_flagsTable[185] = 1;
2208 	} else if (_flagsTable[185] == 2 && (_yPosCurrent > 130 || _flagsTable[236] == 4)) {
2209 		_flagsTable[185] = 3;
2210 	}
2211 	int state;
2212 	if (_flagsTable[185] == 0 || _flagsTable[160] < 3) {
2213 		state = -1;
2214 	} else if (_flagsTable[185] == 1) {
2215 		_flagsTable[185] = 2;
2216 		state = 1;
2217 	} else if (_flagsTable[185] == 3) {
2218 		_flagsTable[185] = 0;
2219 		state = 4;
2220 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2221 		_spritesTable[i]._needUpdate = true;
2222 		state = 2;
2223 	} else {
2224 		_spritesTable[i]._needUpdate = false;
2225 		if (getRandomNumber() < 30000 || _backgroundSpriteCurrentAnimation <= -1) {
2226 			state = 3;
2227 			_spritesTable[i]._updateDelay = 1;
2228 		} else if (getRandomNumber() < 16000) {
2229 			state = 5;
2230 		} else {
2231 			state = 6;
2232 		}
2233 	}
2234 	_spritesTable[i]._state = state;
2235 }
2236 
execData3PreUpdate_locationNum49()2237 void TuckerEngine::execData3PreUpdate_locationNum49() {
2238 	_flagsTable[132] = 0;
2239 	if (_execData3Counter == 0) {
2240 		_execData3Counter = 1;
2241 		if (_flagsTable[181] == 2) {
2242 			_flagsTable[181] = 3;
2243 		}
2244 	}
2245 	static const int items[] = { 15, 44, 25, 27, 19, 21, 24, 13, 20, 29, 35, 23, 3 };
2246 	for (int i = 0; i < 13; ++i) {
2247 		if (_inventoryItemsState[items[i]] == 1) {
2248 			_flagsTable[168 + i] = 1;
2249 		}
2250 	}
2251 	int counter = 0;
2252 	for (int i = 168; i < 181; ++i) {
2253 		if (_flagsTable[i] == 2) {
2254 			++counter;
2255 		}
2256 	}
2257 	if (_nextAction == 0) {
2258 		if (counter == 2 && _flagsTable[236] == 0) {
2259 			_nextAction = 56;
2260 			_csDataLoaded = false;
2261 		} else if (counter == 6 && _flagsTable[236] == 1) {
2262 			_nextAction = 59;
2263 			_csDataLoaded = false;
2264 		} else if (counter == 10 && _flagsTable[236] == 2) {
2265 			_nextAction = 62;
2266 			_csDataLoaded = false;
2267 		} else if (counter == 13 && _flagsTable[236] == 3) {
2268 			_nextAction =  65;
2269 			_csDataLoaded = false;
2270 		}
2271 	}
2272 }
2273 
updateSprite_locationNum50(int i)2274 void TuckerEngine::updateSprite_locationNum50(int i) {
2275 	int state;
2276 	if (_flagsTable[240] == 0) {
2277 		state = i + 1;
2278 		if (i == 5) {
2279 			_flagsTable[240] = 1;
2280 		}
2281 	} else {
2282 		_spritesTable[i]._animationFrame = _spritesTable[i]._firstFrame - 1;
2283 		_spritesTable[i]._updateDelay = 5;
2284 		_updateSpriteFlag1 = true;
2285 		state = i + 1;
2286 	}
2287 	_spritesTable[i]._state = state;
2288 }
2289 
updateSprite_locationNum51(int i)2290 void TuckerEngine::updateSprite_locationNum51(int i) {
2291 	if (i == 2) {
2292 		_spritesTable[i]._state = 1;
2293 	} else if (i == 0) {
2294 		static const int stateTable[] = { 3, 3, 4, 5, 3, 3, 5, 4, 3, 3, 4, 5, 4, 4 };
2295 		++_spritesTable[i]._counter;
2296 		if (_spritesTable[i]._counter > 13) {
2297 			_spritesTable[i]._counter = 0;
2298 		}
2299 		_spritesTable[i]._state = stateTable[_spritesTable[i]._counter];
2300 	} else {
2301 		i = 1;
2302 		_spritesTable[i]._state = 6;
2303 	}
2304 
2305 	_spritesTable[i]._colorType = 1;
2306 	_spritesTable[i]._yMaxBackground = 0;
2307 }
2308 
2309 
execData3PreUpdate_locationNum52()2310 void TuckerEngine::execData3PreUpdate_locationNum52() {
2311 	if (_selectedObject._xPos > 108 && _panelLockedFlag && _nextAction == 0 && _locationMaskType == 0) {
2312 		_nextAction = 1;
2313 		_csDataLoaded = false;
2314 	}
2315 }
2316 
updateSprite_locationNum53_0(int i)2317 void TuckerEngine::updateSprite_locationNum53_0(int i) {
2318 	if (_flagsTable[197] == 2) {
2319 		_flagsTable[197] = 3;
2320 	}
2321 	int state;
2322 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2323 		_spritesTable[i]._needUpdate = true;
2324 		state = 1;
2325 	} else if (_flagsTable[197] == 1) {
2326 		state = 3;
2327 		_spritesTable[i]._needUpdate = false;
2328 		_flagsTable[197] = 2;
2329 	} else if (_flagsTable[192] == 1) {
2330 		_spritesTable[i]._needUpdate = false;
2331 		state = 5;
2332 	} else {
2333 		_spritesTable[i]._needUpdate = false;
2334 		state = 5;
2335 		_spritesTable[i]._updateDelay = 5;
2336 	}
2337 	_spritesTable[i]._state = state;
2338 }
2339 
updateSprite_locationNum53_1(int i)2340 void TuckerEngine::updateSprite_locationNum53_1(int i) {
2341 	int state;
2342 	if (_flagsTable[197] == 3) {
2343 		state = 6;
2344 	} else if (_flagsTable[197] == 4) {
2345 		state = 7;
2346 	} else {
2347 		state = -1;
2348 	}
2349 	_spritesTable[i]._state = state;
2350 }
2351 
execData3PreUpdate_locationNum53()2352 void TuckerEngine::execData3PreUpdate_locationNum53() {
2353 	if (_flagsTable[192] == 0 && _xPosCurrent < 200 && _nextAction == 0) {
2354 		_panelLockedFlag = false;
2355 		_nextAction = 14;
2356 		_csDataLoaded = false;
2357 		_pendingActionDelay = 0;
2358 		_pendingActionIndex = 0;
2359 		_currentActionVerb = kVerbWalk;
2360 	}
2361 }
2362 
updateSprite_locationNum54(int i)2363 void TuckerEngine::updateSprite_locationNum54(int i) {
2364 	if (_flagsTable[141] == 2) {
2365 		_spritesTable[i]._needUpdate = false;
2366 		setCharacterAnimation(0, i);
2367 		_flagsTable[141] = 1;
2368 		_spritesTable[i]._counter = 0;
2369 	} else if (_flagsTable[141] == 1 && _spritesTable[i]._counter < 40) {
2370 		setCharacterAnimation(1, i);
2371 		++_spritesTable[i]._counter;
2372 	} else if (_flagsTable[141] == 1) {
2373 		setCharacterAnimation(2, i);
2374 		_flagsTable[141] = 3;
2375 	} else {
2376 		int state = 3;
2377 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2378 			_spritesTable[i]._needUpdate = true;
2379 			state = (getRandomNumber() < 12000) ? 2 : 4;
2380 		} else if (_flagsTable[141] == 3) {
2381 			_flagsTable[141] = 0;
2382 			_flagsTable[224] = 1;
2383 			_spritesTable[i]._counter = 0;
2384 			if (!_panelLockedFlag && _xPosCurrent > 130 && _inventoryItemsState[17] == 0) {
2385 				_nextAction = 18;
2386 				_csDataLoaded = false;
2387 			}
2388 		} else if (getRandomNumber() < 26000) {
2389 			_spritesTable[i]._needUpdate = false;
2390 			_spritesTable[i]._updateDelay = 5;
2391 		} else {
2392 			_spritesTable[i]._needUpdate = false;
2393 		}
2394 		if (_inventoryItemsState[17] == 1) {
2395 			_flagsTable[224] = 2;
2396 		}
2397 		_spritesTable[i]._state = state;
2398 	}
2399 }
2400 
updateSprite_locationNum55(int i)2401 void TuckerEngine::updateSprite_locationNum55(int i) {
2402 	if (_flagsTable[193] > 0 && _flagsTable[193] < 14) {
2403 		setCharacterAnimation(_flagsTable[193] - 1, i);
2404 		_updateSpriteFlag1 = true;
2405 		if (_flagsTable[193] == 1 || _flagsTable[193] == 3 || _flagsTable[193] == 5 || _flagsTable[193] == 7 || _flagsTable[193] == 11 || _flagsTable[193] == 13) {
2406 			++_flagsTable[193];
2407 		}
2408 	} else {
2409 		_spritesTable[i]._state = -1;
2410 		if (_flagsTable[193] == 14) {
2411 			_flagsTable[193] = 15;
2412 		}
2413 	}
2414 }
2415 
updateSprite_locationNum56(int i)2416 void TuckerEngine::updateSprite_locationNum56(int i) {
2417 	int state;
2418 	++_spritesTable[i]._counter;
2419 	if (_flagsTable[153] == 1) {
2420 		state = -1;
2421 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2422 		_spritesTable[i]._needUpdate = true;
2423 		state = 2;
2424 	} else {
2425 		_spritesTable[i]._needUpdate = false;
2426 		state = 1;
2427 	}
2428 	_spritesTable[i]._state = state;
2429 }
2430 
updateSprite_locationNum57_0(int i)2431 void TuckerEngine::updateSprite_locationNum57_0(int i) {
2432 	int state;
2433 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2434 		_spritesTable[i]._needUpdate = true;
2435 		state = 5;
2436 	} else {
2437 		_spritesTable[i]._needUpdate = false;
2438 		if (getRandomNumber() < 30000) {
2439 			state = 1;
2440 		} else if (getRandomNumber() < 16000) {
2441 			state = 4;
2442 		} else {
2443 			state = 2;
2444 		}
2445 	}
2446 	_spritesTable[i]._state = state;
2447 }
2448 
updateSprite_locationNum57_1(int i)2449 void TuckerEngine::updateSprite_locationNum57_1(int i) {
2450 	int state = 6;
2451 	if (getRandomNumber() < 30000) {
2452 		_spritesTable[i]._updateDelay = 5;
2453 	}
2454 	_spritesTable[i]._state = state;
2455 }
2456 
execData3PreUpdate_locationNum57()2457 void TuckerEngine::execData3PreUpdate_locationNum57() {
2458 	if (_flagsTable[137] == 2 && _xPosCurrent < 42 && _yPosCurrent == 135) {
2459 		_flagsTable[137] = 0;
2460 		_backgroundSpriteCurrentAnimation = 2;
2461 		_backgroundSpriteCurrentFrame = 0;
2462 		_backgroundSprOffset = 0;
2463 	}
2464 }
2465 
updateSprite_locationNum58(int i)2466 void TuckerEngine::updateSprite_locationNum58(int i) {
2467 	int state;
2468 	if (_flagsTable[190] == 0) {
2469 		state = 1;
2470 	} else if (_flagsTable[190] == 1) {
2471 		state = 2;
2472 		_flagsTable[190] = 2;
2473 	} else {
2474 		state = 3;
2475 		if (_flagsTable[190] == 2) {
2476 			_flagsTable[190] = 3;
2477 		}
2478 	}
2479 	_spritesTable[i]._state = state;
2480 	_spritesTable[i]._gfxBackgroundOffset = 320;
2481 }
2482 
execData3PreUpdate_locationNum58()2483 void TuckerEngine::execData3PreUpdate_locationNum58() {
2484 	// workaround original game glitch #2872348: do not change position on location change
2485 	if (_nextLocation == kLocationNone && _flagsTable[190] < 3 && _xPosCurrent > 310) {
2486 		_xPosCurrent = 310;
2487 		_panelLockedFlag = false;
2488 	}
2489 	if (_flagsTable[190] > 0 && _locationSoundsTable[0]._volume > 0) {
2490 		_locationSoundsTable[0]._volume = 0;
2491 		_locationSoundsTable[4]._volume = 0;
2492 		_locationSoundsTable[5]._volume = 0;
2493 		if (isSoundPlaying(0)) {
2494 			stopSound(0);
2495 		}
2496 	}
2497 }
2498 
updateSprite_locationNum59(int i)2499 void TuckerEngine::updateSprite_locationNum59(int i) {
2500 	int state;
2501 	if (_flagsTable[207] == 1) {
2502 		state = -1;
2503 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2504 		state = 3;
2505 		_spritesTable[i]._needUpdate = true;
2506 	} else if (_csDataHandled) {
2507 		_spritesTable[i]._needUpdate = false;
2508 		if (_flagsTable[199] == 0) {
2509 			_flagsTable[199] = 1;
2510 			setCharacterAnimation(0, 0);
2511 			return;
2512 		}
2513 		_spritesTable[i]._needUpdate = false;
2514 		state = 3;
2515 		_spritesTable[i]._updateDelay = 5;
2516 	} else if (_flagsTable[199] == 1) {
2517 		_flagsTable[199] = 0;
2518 		_spritesTable[i]._needUpdate = false;
2519 		setCharacterAnimation(1, 0);
2520 		return;
2521 	} else {
2522 		_spritesTable[i]._needUpdate = false;
2523 		state = 1;
2524 	}
2525 	_spritesTable[i]._state = state;
2526 }
2527 
updateSprite_locationNum60_0(int i)2528 void TuckerEngine::updateSprite_locationNum60_0(int i) {
2529 	int state;
2530 	if (_flagsTable[186] > 0) {
2531 		state = -1;
2532 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2533 		_spritesTable[i]._needUpdate = true;
2534 		state = 9;
2535 	} else {
2536 		_spritesTable[i]._needUpdate = false;
2537 		state = (getRandomNumber() > 32000) ? 8 : 7;
2538 	}
2539 	_spritesTable[i]._state = state;
2540 	_spritesTable[i]._gfxBackgroundOffset = 320;
2541 }
2542 
updateSprite_locationNum60_1(int i)2543 void TuckerEngine::updateSprite_locationNum60_1(int i) {
2544 	int state;
2545 	if (_flagsTable[186] == 1) {
2546 		_flagsTable[186] = 2;
2547 		_spritesTable[i]._needUpdate = false;
2548 		state = 2;
2549 	} else if (_flagsTable[186] == 2) {
2550 		state = 6;
2551 		_flagsTable[187] = 1;
2552 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2553 		_spritesTable[i]._needUpdate = true;
2554 		state = 1;
2555 	} else {
2556 		_spritesTable[i]._needUpdate = false;
2557 		state = (getRandomNumber() > 32000) ? 5 : 4;
2558 	}
2559 	_spritesTable[i]._state = state;
2560 	_spritesTable[i]._gfxBackgroundOffset = 320;
2561 }
2562 
execData3PostUpdate_locationNum60()2563 void TuckerEngine::execData3PostUpdate_locationNum60() {
2564 	drawSprite(0);
2565 }
2566 
updateSprite_locationNum61_0(int i)2567 void TuckerEngine::updateSprite_locationNum61_0(int i) {
2568 	int state;
2569 	const int r = getRandomNumber();
2570 	if (_flagsTable[88] == 1) {
2571 		state = 3;
2572 		_flagsTable[88] = 2;
2573 	} else if (_flagsTable[88] == 2) {
2574 		state = -1;
2575 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == 0) {
2576 		if (!_spritesTable[i]._needUpdate) {
2577 			_spritesTable[i]._needUpdate = true;
2578 			state = 2;
2579 		} else {
2580 			state = 2;
2581 			_spritesTable[0]._animationFrame = 2;
2582 			_updateSpriteFlag1 = true;
2583 		}
2584 	} else {
2585 		_spritesTable[i]._needUpdate = false;
2586 		if (r < 30000) {
2587 			state = 7;
2588 			_spritesTable[i]._updateDelay = 5;
2589 		} else if (r < 31000) {
2590 			state = 7;
2591 		} else if (r < 32000) {
2592 			state = 5;
2593 		} else {
2594 			state = 6;
2595 		}
2596 	}
2597 	_spritesTable[i]._state = state;
2598 }
2599 
updateSprite_locationNum61_1(int i)2600 void TuckerEngine::updateSprite_locationNum61_1(int i) {
2601 	int state;
2602 	if (_flagsTable[151] == 1) {
2603 		state = -1;
2604 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2605 		_spritesTable[i]._needUpdate = true;
2606 		state = 14;
2607 	} else if (_csDataHandled || getRandomNumber() < 29000) {
2608 		_spritesTable[i]._needUpdate = false;
2609 		state = 12;
2610 		_spritesTable[i]._updateDelay = 5;
2611 	} else if (getRandomNumber() < 20000) {
2612 		state = 12;
2613 	} else {
2614 		state = 13;
2615 	}
2616 	_spritesTable[i]._state = state;
2617 	_spritesTable[i]._gfxBackgroundOffset = 320;
2618 }
2619 
updateSprite_locationNum61_2(int i)2620 void TuckerEngine::updateSprite_locationNum61_2(int i) {
2621 	int state;
2622 	const int r = getRandomNumber();
2623 	_flagsTable[150] = 1;
2624 	if (_flagsTable[198] == 2) {
2625 		_flagsTable[150] = 2;
2626 		state = 16;
2627 	} else if (_flagsTable[198] == 1) {
2628 		if (_flagsTable[150] == 2) {
2629 			state = 10;
2630 		} else {
2631 			state = 18;
2632 		}
2633 		_flagsTable[198] = 2;
2634 		_flagsTable[150] = 0;
2635 	} else if (r < 32000) {
2636 		state = 15;
2637 	} else if (r < 32100) {
2638 		state = 1;
2639 		if (_xPosCurrent < 340 || _xPosCurrent > 380) {
2640 			_flagsTable[150] = 0;
2641 			if (_flagsTable[136] == 0) {
2642 				state = 17;
2643 			}
2644 		} else {
2645 			state = 15;
2646 		}
2647 	} else if (r < 32200) {
2648 		state = 4;
2649 	} else if (r < 32300) {
2650 		state = 8;
2651 	} else {
2652 		state = 9;
2653 	}
2654 	_flagsTable[248] = _flagsTable[150];
2655 	if (_flagsTable[136] != 2) {
2656 		_flagsTable[150] = 0;
2657 	}
2658 	_spritesTable[i]._state = state;
2659 	_spritesTable[i]._gfxBackgroundOffset = 320;
2660 }
2661 
execData3PreUpdate_locationNum61()2662 void TuckerEngine::execData3PreUpdate_locationNum61() {
2663 	if (_inventoryItemsState[36] == 1) {
2664 		_flagsTable[93] = (_inventoryItemsState[6] == 1) ? 3 : 1;
2665 	} else {
2666 		_flagsTable[93] = (_inventoryItemsState[6] == 1) ? 2 : 0;
2667 	}
2668 	_flagsTable[154] = _inventoryItemsState[16];
2669 	if (_inventoryItemsState[16] == 2 && _inventoryItemsState[36] == 2) {
2670 		if (!_csDataHandled && _flagsTable[88] == 0) {
2671 			_flagsTable[88] = 1;
2672 		}
2673 	}
2674 }
2675 
updateSprite_locationNum63_0(int i)2676 void TuckerEngine::updateSprite_locationNum63_0(int i) {
2677 	int state;
2678 	if (_flagsTable[136] > 0 && _flagsTable[132] == 2) {
2679 		state = 12;
2680 	} else if (_flagsTable[132] != 2 || _flagsTable[133] != 1 || _flagsTable[136] > 0) {
2681 		state = -1;
2682 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2683 		_spritesTable[i]._needUpdate = true;
2684 		state = 6;
2685 	} else {
2686 		_spritesTable[i]._needUpdate = false;
2687 		state = -1;
2688 	}
2689 	_spritesTable[i]._state = state;
2690 }
2691 
updateSprite_locationNum63_1(int i)2692 void TuckerEngine::updateSprite_locationNum63_1(int i) {
2693 	int state = -1;
2694 	if (_flagsTable[132] == 2 && _flagsTable[133] == 1 && _flagsTable[136] <= 0) {
2695 		if (getRandomNumber() > 30000) {
2696 			state = 5;
2697 		} else if (getRandomNumber() > 30000) {
2698 			state = 8;
2699 		}
2700 	}
2701 	_spritesTable[i]._state = state;
2702 }
2703 
updateSprite_locationNum63_2(int i)2704 void TuckerEngine::updateSprite_locationNum63_2(int i) {
2705 	++_spritesTable[i]._counter;
2706 	int state = -1;
2707 	if (_flagsTable[132] == 2 && _flagsTable[133] == 1 && _flagsTable[136] <= 0) {
2708 		if (_flagsTable[226] == 0) {
2709 			state = 9;
2710 			_spritesTable[i]._updateDelay = 5;
2711 		} else if (_flagsTable[226] == 1) {
2712 			state = 9;
2713 			_flagsTable[226] = 2;
2714 		} else if (_flagsTable[226] == 2) {
2715 			state = 3;
2716 		} else {
2717 			_flagsTable[226] = 0;
2718 			state = 10;
2719 		}
2720 	}
2721 	_spritesTable[i]._state = state;
2722 }
2723 
updateSprite_locationNum63_3(int i)2724 void TuckerEngine::updateSprite_locationNum63_3(int i) {
2725 	++_spritesTable[i]._counter;
2726 	int state = -1;
2727 	if (_flagsTable[132] == 2 && _flagsTable[133] == 1 && _flagsTable[136] <= 0) {
2728 		if (_spritesTable[i]._counter > 80) {
2729 			state = 7;
2730 			_spritesTable[i]._counter = 0;
2731 		} else if (getRandomNumber() > 32000) {
2732 			state = 2;
2733 		} else if (getRandomNumber() > 32000) {
2734 			state = 4;
2735 		} else if (getRandomNumber() > 28000) {
2736 			state = 8;
2737 		}
2738 	}
2739 	_spritesTable[i]._state = state;
2740 }
2741 
updateSprite_locationNum63_4(int i)2742 void TuckerEngine::updateSprite_locationNum63_4(int i) {
2743 	int state = -1;
2744 	if (_flagsTable[132] == 2 && _flagsTable[133] == 1 && _flagsTable[136] == 0) {
2745 		state = 1;
2746 	}
2747 	_spritesTable[i]._state = state;
2748 }
2749 
execData3PreUpdate_locationNum63()2750 void TuckerEngine::execData3PreUpdate_locationNum63() {
2751 	_currentGfxBackgroundCounter = 20 - _flagsTable[132] * 10;
2752 	if (_flagsTable[132] != _execData3Counter) {
2753 		_mainLoopCounter1 = 0;
2754 		_execData3Counter = _flagsTable[132];
2755 	}
2756 	if (_flagsTable[133] == 0) {
2757 		_currentGfxBackgroundCounter = 30;
2758 	}
2759 	if (_flagsTable[136] > 0 && _flagsTable[132] == 2) {
2760 		_currentGfxBackgroundCounter = 20;
2761 	}
2762 	if (_flagsTable[133] == 0) {
2763 		for (int i = 0; i < 3; ++i) {
2764 			if (isSoundPlaying(i)) {
2765 				stopSound(i);
2766 			}
2767 		}
2768 	} else {
2769 		if (_flagsTable[132] == 0 || (_flagsTable[132] == 2 && _flagsTable[136] > 0)) {
2770 			if (!isSoundPlaying(1)) {
2771 				_locationSoundsTable[1]._type = 2;
2772 				startSound(_locationSoundsTable[1]._offset, 1, _locationSoundsTable[1]._volume);
2773 			}
2774 		} else {
2775 			if (isSoundPlaying(1)) {
2776 				stopSound(1);
2777 			}
2778 		}
2779 		if (_flagsTable[132] == 1) {
2780 			if (!isSoundPlaying(0)) {
2781 				_locationSoundsTable[0]._type = 2;
2782 				startSound(_locationSoundsTable[0]._offset, 0, _locationSoundsTable[0]._volume);
2783 			}
2784 		} else {
2785 			if (isSoundPlaying(0)) {
2786 				stopSound(0);
2787 			}
2788 		}
2789 		if (_flagsTable[132] == 2 && _flagsTable[136] == 0) {
2790 			if (!isSoundPlaying(2)) {
2791 				startSound(_locationSoundsTable[2]._offset, 2, _locationSoundsTable[2]._volume);
2792 			}
2793 		} else {
2794 			if (isSoundPlaying(2)) {
2795 				stopSound(2);
2796 			}
2797 		}
2798 	}
2799 }
2800 
execData3PreUpdate_locationNum64()2801 void TuckerEngine::execData3PreUpdate_locationNum64() {
2802 	if (_currentGfxBackgroundCounter < 30) {
2803 		_locationHeightTable[64] = 48 - (_currentGfxBackgroundCounter / 10);
2804 	} else {
2805 		_locationHeightTable[64] = 47;
2806 	}
2807 }
2808 
updateSprite_locationNum65(int i)2809 void TuckerEngine::updateSprite_locationNum65(int i) {
2810 	int state;
2811 	if (_flagsTable[188] == 1) {
2812 		_flagsTable[188] = 2;
2813 		state = 1;
2814 		_spritesTable[i]._gfxBackgroundOffset = 100;
2815 	} else if (_flagsTable[188] > 0 && _flagsTable[189] > 0) {
2816 		state = -1;
2817 		if (_xPosCurrent < 150 || _yPosCurrent > 240) {
2818 			_flagsTable[189] = 0;
2819 		}
2820 	} else {
2821 		if (_xPosCurrent >= 150 && _yPosCurrent < 240) { // FIXME: bug
2822 			if (getRandomNumber() > 32000) {
2823 				state = 2;
2824 				_flagsTable[189] = 1;
2825 			} else {
2826 				state = -1;
2827 			}
2828 		} else {
2829 			state = -1;
2830 			_flagsTable[189] = 0;
2831 		}
2832 	}
2833 	_spritesTable[i]._state = state;
2834 }
2835 
execData3PreUpdate_locationNum65()2836 void TuckerEngine::execData3PreUpdate_locationNum65() {
2837 	_flagsTable[137] = 0;
2838 }
2839 
updateSprite_locationNum66_0(int i)2840 void TuckerEngine::updateSprite_locationNum66_0(int i) {
2841 	int state;
2842 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2843 		_spritesTable[i]._needUpdate = true;
2844 		state = 2;
2845 	} else {
2846 		_spritesTable[i]._needUpdate = false;
2847 		state = 2;
2848 		_spritesTable[i]._updateDelay = 5;
2849 	}
2850 	_spritesTable[i]._state = state;
2851 	_spritesTable[i]._gfxBackgroundOffset = 320;
2852 }
2853 
updateSprite_locationNum66_1(int i)2854 void TuckerEngine::updateSprite_locationNum66_1(int i) {
2855 	int state;
2856 	if (_flagsTable[191] == 0 && _xPosCurrent > 568) {
2857 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2858 			_spritesTable[i]._needUpdate = true;
2859 			state = 8;
2860 		} else {
2861 			state = 10;
2862 			_spritesTable[i]._needUpdate = false;
2863 		}
2864 	} else {
2865 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2866 			_spritesTable[i]._needUpdate = true;
2867 			state = 9;
2868 		} else if (getRandomNumber() > 30000) {
2869 			state = 6;
2870 			_spritesTable[i]._needUpdate = false;
2871 		} else {
2872 			_spritesTable[i]._needUpdate = false;
2873 			state = 7;
2874 			_spritesTable[i]._updateDelay = 5;
2875 		}
2876 	}
2877 	_spritesTable[i]._state = state;
2878 	_spritesTable[i]._gfxBackgroundOffset = 320;
2879 }
2880 
updateSprite_locationNum66_2(int i)2881 void TuckerEngine::updateSprite_locationNum66_2(int i) {
2882 	_spritesTable[i]._disabled = true;
2883 	_spritesTable[i]._state = 3;
2884 }
2885 
updateSprite_locationNum66_3(int i)2886 void TuckerEngine::updateSprite_locationNum66_3(int i) {
2887 	_spritesTable[i]._state = 4;
2888 }
2889 
updateSprite_locationNum66_4(int i)2890 void TuckerEngine::updateSprite_locationNum66_4(int i) {
2891 	_spritesTable[i]._state = 5;
2892 	_spritesTable[i]._gfxBackgroundOffset = 320;
2893 }
2894 
execData3PreUpdate_locationNum66()2895 void TuckerEngine::execData3PreUpdate_locationNum66() {
2896 	// WORKAROUND
2897 	// If you don't have the appointment card yet and use the map to go to
2898 	// Seedy Street Bud ends up being teleported back to the mall.
2899 	// Because of the destination coordinates which warp Bud past x==583 the
2900 	// below 'if' triggers and automatically makes Violet refuse Bud entrance
2901 	// to the dentist. On top of that the graphics end up all garbled which
2902 	// indicates that even worse things happen under the hood.
2903 	// To work around this we only trigger Violet if Bud actually _walked_ past
2904 	// the trigger coordinates (as opposed to using the map).
2905 	// Fixes Trac#10452.
2906 	if (_nextLocation != kLocationNone)
2907 		return;
2908 
2909 	_flagsTable[137] = 0;
2910 	if (_xPosCurrent > 583 && _flagsTable[191] == 0 && _nextAction == 0 && _locationMaskType == 0) {
2911 		_panelLockedFlag = false;
2912 		_csDataLoaded = false;
2913 		_nextLocation = kLocationNone;
2914 		_selectedObject._locationObjectLocation = kLocationNone;
2915 		if (_flagsTable[131] == 0) {
2916 			_nextAction = 13;
2917 		} else if (_flagsTable[130] == 0) {
2918 			_nextAction = 14;
2919 		} else {
2920 			_nextAction = 35;
2921 		}
2922 	}
2923 }
2924 
execData3PostUpdate_locationNum66()2925 void TuckerEngine::execData3PostUpdate_locationNum66() {
2926 	if (_spritesTable[2]._flipX) {
2927 		--_updateLocationXPosTable2[0];
2928 		if (_updateLocationXPosTable2[0] < -50) {
2929 			_spritesTable[2]._flipX = false;
2930 			_updateLocationXPosTable2[0] = -50;
2931 		}
2932 	} else {
2933 		++_updateLocationXPosTable2[0];
2934 		if (_updateLocationXPosTable2[0] > 500) {
2935 			_spritesTable[2]._flipX = true;
2936 			_updateLocationXPosTable2[0] = 500;
2937 		}
2938 	}
2939 	_spritesTable[2]._gfxBackgroundOffset = _updateLocationXPosTable2[0] + 8320;
2940 	const int spr = 2;
2941 	_spritesTable[spr]._colorType = 1;
2942 	_spritesTable[spr]._yMaxBackground = 0;
2943 	drawSprite(spr);
2944 	_spritesTable[spr]._colorType = 0;
2945 }
2946 
updateSprite_locationNum69_1(int i)2947 void TuckerEngine::updateSprite_locationNum69_1(int i) {
2948 	int state;
2949 	if (_flagsTable[236] == 1) {
2950 		state = 4;
2951 	} else if (_flagsTable[236] == 2) {
2952 		state = 3;
2953 	} else if (_flagsTable[236] == 3) {
2954 		state = 2;
2955 	} else if (_flagsTable[236] == 4) {
2956 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2957 			state = 9;
2958 			_spritesTable[i]._needUpdate = true;
2959 		} else {
2960 			state = 14;
2961 			_spritesTable[i]._needUpdate = false;
2962 		}
2963 	} else if (_flagsTable[236] == 5) {
2964 		state = 7;
2965 		_flagsTable[236] = 6;
2966 	} else {
2967 		state = -1;
2968 	}
2969 	_spritesTable[i]._state = state;
2970 }
2971 
updateSprite_locationNum69_2(int i)2972 void TuckerEngine::updateSprite_locationNum69_2(int i) {
2973 	if (_flagsTable[237] == 2) {
2974 		_flagsTable[237] = 3;
2975 	}
2976 	int state;
2977 	if (_flagsTable[236] < 4 || _flagsTable[237] == 0) {
2978 		state = -1;
2979 	} else if (_flagsTable[237] == 1) {
2980 		state = 5;
2981 		_flagsTable[237] = 2;
2982 	} else if (_flagsTable[237] == 4 || _flagsTable[237] == 2 || _flagsTable[237] == 3 || _flagsTable[237] == 7) {
2983 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
2984 			state = 10;
2985 			_spritesTable[i]._needUpdate = true;
2986 		} else {
2987 			state = 12;
2988 			_spritesTable[i]._needUpdate = false;
2989 		}
2990 	} else if (_flagsTable[237] == 5) {
2991 		state = 16;
2992 		_flagsTable[237] = 6;
2993 	} else if (_flagsTable[237] == 6) {
2994 		state = 15;
2995 		_flagsTable[237] = 7;
2996 	} else if (_flagsTable[237] == 8) {
2997 		state = 6;
2998 		_flagsTable[237] = 9;
2999 	} else {
3000 		state = -1;
3001 	}
3002 	_spritesTable[i]._state = state;
3003 }
3004 
updateSprite_locationNum69_3(int i)3005 void TuckerEngine::updateSprite_locationNum69_3(int i) {
3006 	int state;
3007 	if (_flagsTable[236] > 4) {
3008 		state = -1;
3009 	} else if (_flagsTable[237] == 3) {
3010 		state = 8;
3011 		_flagsTable[237] = 4;
3012 	} else if (_flagsTable[237] > 2 && _flagsTable[237] < 9) {
3013 		_flagsTable[238] = 1;
3014 		if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
3015 			state = 11;
3016 			_spritesTable[i]._needUpdate = true;
3017 		} else {
3018 			state = 13;
3019 			_spritesTable[i]._needUpdate = false;
3020 		}
3021 	} else {
3022 		state = -1;
3023 	}
3024 	_spritesTable[i]._state = state;
3025 }
3026 
execData3PreUpdate_locationNum70()3027 void TuckerEngine::execData3PreUpdate_locationNum70() {
3028 	const uint8 color = 103;
3029 	if (_execData3Counter == 0) {
3030 		startSound(_locationSoundsTable[6]._offset, 6, _locationSoundsTable[6]._volume);
3031 		_execData3Counter = 1;
3032 		_flagsTable[143] = 0;
3033 		_updateLocation70StringLen = 0;
3034 		_forceRedrawPanelItems = true;
3035 		_panelType = kPanelTypeEmpty;
3036 		setCursorState(kCursorStateDisabledHidden);
3037 	}
3038 	_forceRedrawPanelItems = true;
3039 	_panelType = kPanelTypeEmpty;
3040 	setCursorState(kCursorStateDisabledHidden);
3041 	int pos = getPositionForLine(22, _infoBarBuf);
3042 	const int yPos = (_flagsTable[143] == 0) ? 90 : 72;
3043 	drawStringAlt(88, yPos, color, &_infoBarBuf[pos]);
3044 	Graphics::drawStringChar(_locationBackgroundGfxBuf, 88, yPos + 9, 640, 62, color, _charsetGfxBuf);
3045 	if (_flagsTable[143] != 0) {
3046 		pos = getPositionForLine(_flagsTable[143] * 2 + 23, _infoBarBuf);
3047 		drawStringAlt(88, yPos + 18, color, &_infoBarBuf[pos]);
3048 		pos = getPositionForLine(_flagsTable[143] * 2 + 24, _infoBarBuf);
3049 		drawStringAlt(88, yPos + 27, color, &_infoBarBuf[pos]);
3050 	}
3051 	execData3PreUpdate_locationNum70Helper();
3052 	drawStringAlt(88 + 8, yPos + 9, color, _updateLocation70String, _updateLocation70StringLen);
3053 }
3054 
execData3PreUpdate_locationNum70Helper()3055 void TuckerEngine::execData3PreUpdate_locationNum70Helper() {
3056 	if (_lastKeyPressed != 0 && _flagsTable[143] <= 0) {
3057 		if (_lastKeyPressed == Common::KEYCODE_BACKSPACE || _lastKeyPressed == Common::KEYCODE_DELETE) {
3058 			if (_updateLocation70StringLen > 0) {
3059 				--_updateLocation70StringLen;
3060 				startSound(_locationSoundsTable[0]._offset, 0, _locationSoundsTable[0]._volume);
3061 			}
3062 		} else if (_lastKeyPressed == Common::KEYCODE_RETURN) {
3063 			_flagsTable[143] = 1;
3064 			_nextAction = 1;
3065 			_csDataLoaded = false;
3066 			const int pos = getPositionForLine(23, _infoBarBuf);
3067 			if (memcmp(&_infoBarBuf[pos + 3], _updateLocation70String, 16) != 0) {
3068 				_flagsTable[143] = 2;
3069 			}
3070 			const int num = (_flagsTable[143] == 1) ? 4 : 5;
3071 			startSound(_locationSoundsTable[num]._offset, num, _locationSoundsTable[num]._volume);
3072 		} else if (_updateLocation70StringLen < 19) {
3073 			uint8 chr = 0;
3074 			switch (_lastKeyPressed) {
3075 			case Common::KEYCODE_SPACE:
3076 				chr = 32;
3077 				break;
3078 			case Common::KEYCODE_BACKQUOTE:
3079 				chr = 35;
3080 				break;
3081 			case Common::KEYCODE_LEFTPAREN:
3082 				chr = 40;
3083 				break;
3084 			case Common::KEYCODE_RIGHTPAREN:
3085 				chr = 41;
3086 				break;
3087 			case Common::KEYCODE_LESS:
3088 				chr = 44;
3089 				break;
3090 			case Common::KEYCODE_GREATER:
3091 				chr = 46;
3092 				break;
3093 			case Common::KEYCODE_COLON:
3094 				chr = 56;
3095 				break;
3096 			case Common::KEYCODE_QUESTION:
3097 				chr = 92;
3098 				break;
3099 			case Common::KEYCODE_QUOTE:
3100 				chr = 96;
3101 				break;
3102 			default:
3103 				if (_lastKeyPressed >= Common::KEYCODE_a && _lastKeyPressed <= Common::KEYCODE_z) {
3104 					chr = 'A' + (_lastKeyPressed - Common::KEYCODE_a);
3105 				}
3106 				break;
3107 			}
3108 			startSound(_locationSoundsTable[0]._offset, 0, _locationSoundsTable[0]._volume);
3109 			if (chr > 0) {
3110 				_updateLocation70String[_updateLocation70StringLen] = chr;
3111 				++_updateLocation70StringLen;
3112 			}
3113 		}
3114 		_lastKeyPressed = 0;
3115 	}
3116 }
3117 
updateSprite_locationNum71(int i)3118 void TuckerEngine::updateSprite_locationNum71(int i) {
3119 	int state;
3120 	if (_flagsTable[155] != 6 || _flagsTable[207] == 1) {
3121 		state = -1;
3122 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
3123 		_spritesTable[i]._needUpdate = true;
3124 		state = 1;
3125 	} else if (getRandomNumber() < 30000) {
3126 		_spritesTable[i]._needUpdate = false;
3127 		state = 2;
3128 		_spritesTable[i]._updateDelay = 5;
3129 	} else {
3130 		_spritesTable[i]._needUpdate = false;
3131 		state = 2;
3132 	}
3133 	_spritesTable[i]._state = state;
3134 }
3135 
updateSprite_locationNum72(int i)3136 void TuckerEngine::updateSprite_locationNum72(int i) {
3137 	int state;
3138 	if (_flagsTable[155] == 7 || _flagsTable[207] == 1) {
3139 		state = -1;
3140 	} else if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
3141 		_spritesTable[i]._needUpdate = true;
3142 		state = 2;
3143 	} else {
3144 		_spritesTable[i]._needUpdate = false;
3145 		state = 1;
3146 	}
3147 	_spritesTable[i]._state = state;
3148 }
3149 
updateSprite_locationNum74(int i)3150 void TuckerEngine::updateSprite_locationNum74(int i) {
3151 	static const uint8 stateTable[] = { 1, 3, 5, 5, 10, 16, 16 };
3152 	int num = _flagsTable[236] - 74;
3153 	if (stateTable[num] + i == 21) {
3154 		if (!_updateLocationFlag) {
3155 			_updateLocationFlag = true;
3156 		} else {
3157 			_spritesTable[i]._animationFrame = _spritesTable[i]._firstFrame - 1;
3158 			_spritesTable[i]._updateDelay = 5;
3159 			_updateSpriteFlag1 = true;
3160 		}
3161 	}
3162 	_spritesTable[i]._state = stateTable[num] + i;
3163 }
3164 
updateSprite_locationNum79(int i)3165 void TuckerEngine::updateSprite_locationNum79(int i) {
3166 	int state;
3167 	if (_flagsTable[227] == 0) {
3168 		state = 1;
3169 		_flagsTable[227] = 1;
3170 	} else if (_flagsTable[227] == 1 && _charSpeechSoundCounter > 0) {
3171 		state = 2;
3172 		_spritesTable[i]._needUpdate = true;
3173 	} else if (_flagsTable[227] == 2) {
3174 		state = 3;
3175 		_flagsTable[227] = 3;
3176 		_spritesTable[i]._needUpdate = true;
3177 	} else {
3178 		_spritesTable[i]._animationFrame = _spritesTable[i]._firstFrame - 1;
3179 		_spritesTable[i]._updateDelay = 5;
3180 		_updateSpriteFlag1 = true;
3181 		state = 3;
3182 	}
3183 	_spritesTable[i]._state = state;
3184 }
3185 
updateSprite_locationNum81_0(int i)3186 void TuckerEngine::updateSprite_locationNum81_0(int i) {
3187 	int state;
3188 	if (_charSpeechSoundCounter > 0 && _actionCharacterNum == i) {
3189 		_spritesTable[i]._needUpdate = true;
3190 		state = 3;
3191 		_flagsTable[288] = 1;
3192 	} else if (_flagsTable[288] < 2) {
3193 		_spritesTable[i]._needUpdate = false;
3194 		state = 2;
3195 		if (_flagsTable[288] == 1) {
3196 			_flagsTable[288] = 2;
3197 		}
3198 	} else {
3199 		_spritesTable[i]._animationFrame = _spritesTable[i]._firstFrame - 1;
3200 		_spritesTable[i]._updateDelay = 5;
3201 		_updateSpriteFlag1 = true;
3202 		state = 2;
3203 	}
3204 	_spritesTable[i]._state = state;
3205 }
3206 
updateSprite_locationNum81_1(int i)3207 void TuckerEngine::updateSprite_locationNum81_1(int i) {
3208 	_spritesTable[i]._state = 1;
3209 }
3210 
updateSprite_locationNum82(int i)3211 void TuckerEngine::updateSprite_locationNum82(int i) {
3212 	int state;
3213 	if (_charSpeechSoundCounter > 0) {
3214 		state = 1;
3215 		_flagsTable[229] = 1;
3216 		_spritesTable[i]._needUpdate = true;
3217 	} else if (_flagsTable[229] == 0) {
3218 		state = 1;
3219 	} else if (_flagsTable[229] == 1) {
3220 		state = 2;
3221 		_flagsTable[229] = 2;
3222 		_spritesTable[i]._needUpdate = false;
3223 	} else {
3224 		_spritesTable[i]._animationFrame = _spritesTable[i]._firstFrame - 1;
3225 		_spritesTable[i]._updateDelay = 5;
3226 		_updateSpriteFlag1 = true;
3227 		state = 2;
3228 	}
3229 	_spritesTable[i]._state = state;
3230 }
3231 
3232 } // namespace Tucker
3233