aboutsummaryrefslogtreecommitdiff
path: root/engines/igor/parts/part_23.cpp
blob: b1451442ac3006f0945fddd638a55d5520d65a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#include "igor/igor.h"

namespace Igor {

static const uint8 PART_23_ANIM_DATA_1[4] = { 0, 4, 1, 11 };

void IgorEngine::PART_23_EXEC_ACTION(int action) {
	switch (action) {
	case 101:
		_currentPart = 280;
		break;
	case 102:
		ADD_DIALOGUE_TEXT(201, 2);
		SET_DIALOGUE_TEXT(1, 1);
		startIgorDialogue();
		break;
	case 105:
		PART_23_ACTION_105();
		break;
	case 106:
		ADD_DIALOGUE_TEXT(205, 1);
		SET_DIALOGUE_TEXT(1, 1);
		startIgorDialogue();
		break;
	case 107:
		PART_23_ACTION_107();
		break;
	case 108:
		PART_23_ACTION_108();
		break;
	case 109:
		_currentPart = 300;
		break;
	case 110:
		ADD_DIALOGUE_TEXT(203, 1);
		ADD_DIALOGUE_TEXT(204, 1);
		SET_DIALOGUE_TEXT(1, 2);
		startIgorDialogue();
		break;
	case 111:
		ADD_DIALOGUE_TEXT(208, 2);
		SET_DIALOGUE_TEXT(1, 1);
		startIgorDialogue();
		break;
	case 112:
		ADD_DIALOGUE_TEXT(210, 1);
		ADD_DIALOGUE_TEXT(211, 1);
		SET_DIALOGUE_TEXT(1, 2);
		startIgorDialogue();
		break;
	case 113:
		ADD_DIALOGUE_TEXT(212, 1);
		SET_DIALOGUE_TEXT(1, 1);
		startIgorDialogue();
		break;
	default:
		error("PART_23_EXEC_ACTION unhandled action %d", action);
		break;
	}
}

void IgorEngine::PART_23_ACTION_105() {
	if (_objectsState[66] != 0) {
		_roomObjectAreasTable[_screenLayer2[38633]].area = 1;
		--_walkDataLastIndex;
		buildWalkPathSimple(233, 132, 233, 120);
		_walkDataCurrentIndex = 1;
		_gameState.igorMoving = true;
		waitForIgorMove();
		_currentPart = 190;
	}
}

void IgorEngine::PART_23_ACTION_107() {
	if (_objectsState[66] == 1) {
		EXEC_MAIN_ACTION(11);
	} else {
		const int offset = 23901;
		for (int i = 2; i <= 3; ++i) {
			for (int j = 0; j <= 53; ++j) {
				memcpy(_screenVGA + j * 320 + offset, _animFramesBuffer + i * 1620 + j * 30 + 0x895, 30);
			}
		}
		playSound(13, 1);
		waitForTimer(100);
		_objectsState[66] = 1;
		PART_23_HELPER_1(1);
	}
}

void IgorEngine::PART_23_ACTION_108() {
	if (_objectsState[66] == 0) {
		EXEC_MAIN_ACTION(14);
	} else {
		const int offset = 23901;
		for (int i = 2; i <= 3; ++i) {
			for (int j = 0; j <= 53; ++j) {
				memcpy(_screenVGA + j * 320 + offset, _animFramesBuffer + PART_23_ANIM_DATA_1[i] * 1620 + j * 30 + 0x895, 30);
			}
		}
		playSound(14, 1);
		waitForTimer(100);
		_objectsState[66] = 0;
		PART_23_HELPER_1(1);
	}
}

void IgorEngine::PART_23_UPDATE_ROOM_BACKGROUND() {
	if (compareGameTick(29) || compareGameTick(61)) {
		int rnd = getRandomNumber(11);
		if (rnd <= 4) {
			_gameState.unk10 = 1;
		} else if (rnd <= 9) {
			_gameState.unk10 = 2;
		} else if (rnd == 10) {
			if (_gameState.unk10 < 3) {
				_gameState.unk10 = getRandomNumber(2) + 3;
			} else {
				_gameState.unk10 = getRandomNumber(2) + 1;
			}
		}
		PART_23_HELPER_7(_gameState.unk10);
	}
}

void IgorEngine::PART_23_HELPER_1(int num) {
	if (num == 1 || num == 255) {
		if (_objectsState[66] == 0) {
			PART_23_HELPER_2(1);
			_roomActionsTable[4] = 6;
		} else {
			PART_23_HELPER_2(2);
			_roomActionsTable[4] = 7;
		}
	}
	PART_23_HELPER_3();
}

void IgorEngine::PART_23_HELPER_2(int frame) {
	const int offset = 23907;
	for (int i = 0; i <= 53; ++i) {
		memcpy(_screenLayer1 + i * 320 + offset, _animFramesBuffer + (frame - 1) * 1296 + i * 24, 24);
	}
}

void IgorEngine::PART_23_HELPER_3() {
	const int offset = 25763;
	for (int i = 0; i <= 48; ++i) {
		memcpy(_screenLayer1 + i * 320 + offset, _animFramesBuffer + i * 25 + 0xA20, 25);
	}
}

void IgorEngine::PART_23_HELPER_4() {
	_walkData[0].setPos(233, 120, 3, 0);
	_walkData[0].setDefaultScale();
	_walkDataLastIndex = 0;
 	_roomObjectAreasTable[_screenLayer2[38633]].area = 1;
	buildWalkPathSimple(233, 120, 233, 137);
	_roomObjectAreasTable[_screenLayer2[38633]].area = 0;
	_walkData[_walkDataLastIndex].frameNum = 0;
	_walkDataCurrentIndex = 1;
	_gameState.igorMoving = true;
	waitForIgorMove();
	if (_objectsState[59] == 0) {
		for (int i = 0; i <= 53; ++i) {
			for (int j = 0; j <= 23; ++j) {
				uint8 color = _screenVGA[(i + 74) * 320 + j + 227];
				if (color >= 0xC0 && color <= 0xCF) {
					_screenTempLayer[i * 100 + j] = color;
				} else {
					_screenTempLayer[i * 100 + j] = _animFramesBuffer[i * 24 + j];
				}
			}
		}
		for (int i = 0; i <= 53; ++i) {
			memcpy(_screenVGA + i * 320 + 23907, _screenTempLayer + i * 100, 24);
		}
		playSound(14, 1);
		_objectsState[66] = 0;
		PART_23_HELPER_1(1);
		ADD_DIALOGUE_TEXT(206, 2);
		SET_DIALOGUE_TEXT(1, 1);
		startIgorDialogue();
	}
}

void IgorEngine::PART_23_HELPER_5() {
	_walkData[0].setPos(0, 134, 2, 0);
	_walkData[0].setDefaultScale();
	_walkData[0].clipSkipX = 15;
	_walkData[0].clipWidth = 15;
	_walkDataLastIndex = 0;
	_walkDataCurrentIndex = 1;
	buildWalkPathSimple(0, 134, 100, 140);
	_walkData[_walkDataLastIndex].frameNum = 0;
	_gameState.igorMoving = true;
	waitForIgorMove();
}

void IgorEngine::PART_23_HELPER_6() {
	_walkData[0].setPos(319, 134, 4, 0);
	_walkData[0].setDefaultScale();
	_walkData[0].clipWidth = 15;
	_walkDataLastIndex = 0;
	_walkDataCurrentIndex = 1;
	buildWalkPathSimple(319, 134, 289, 134);
	_walkData[_walkDataLastIndex].frameNum = 0;
	_gameState.igorMoving = true;
	waitForIgorMove();
}

void IgorEngine::PART_23_HELPER_7(int frame) {
	_roomCursorOn = false;
	for (int i = 0; i <= 18; ++i) {
		for (int j = 0; j <= 14; ++j) {
			int offset = (i + 80) * 320 + j + 162;
			uint8 color = _screenVGA[offset];
			if ((color >= 192 && color <= 207) || color == 240 || color == 241) {
				_screenTempLayer[i * 100 + j] = color;
			} else {
				_screenTempLayer[i * 100 + j] = _animFramesBuffer[frame * 285 + i * 15 + j + 0x271C];
			}
		}
	}
	int offset = 25762;
	for (int i = 0; i <= 18; ++i) {
		memcpy(_screenVGA + i * 320 + offset, _screenTempLayer + i * 100, 15);
		memcpy(_screenLayer1 + i * 320 + offset, _animFramesBuffer + frame * 285 + i * 15 + 0x271C, 15);
	}
	if (_dialogueCursorOn) {
		_roomCursorOn = true;
	}
}

void IgorEngine::PART_23() {
	_gameState.enableLight = 2;
	loadRoomData(PAL_CollegeCorridorLucas, IMG_CollegeCorridorLucas, BOX_CollegeCorridorLucas, MSK_CollegeCorridorLucas, TXT_CollegeCorridorLucas);
	static const int anm[] = { FRM_CollegeCorridorLucas1, FRM_CollegeCorridorLucas2, FRM_CollegeCorridorLucas3, FRM_CollegeCorridorLucas4, 0 };
	loadAnimData(anm);
	loadActionData(DAT_CollegeCorridorLucas);
	_roomDataOffsets = PART_23_ROOM_DATA_OFFSETS;
	setRoomWalkBounds(15, 0, 319, 143);
	SET_EXEC_ACTION_FUNC(1, &IgorEngine::PART_23_EXEC_ACTION);
	_updateRoomBackground = &IgorEngine::PART_23_UPDATE_ROOM_BACKGROUND;
	PART_23_HELPER_1(255);
	memcpy(_screenVGA, _screenLayer1, 46080);
	_currentAction.verb = kVerbWalk;
	fadeInPalette(768);
	if (_currentPart == 230) {
		PART_23_HELPER_5();
	} else if (_currentPart == 231) {
		PART_23_HELPER_6();
	} else if (_currentPart == 232) {
		PART_23_HELPER_4();
	}
	enterPartLoop();
	while (_currentPart >= 230 && _currentPart <= 232) {
		runPartLoop();
	}
	leavePartLoop();
	fadeOutPalette(624);
}

} // namespace Igor