aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_remote.cpp
blob: 9b43b8dab935591224969821899a7421f1e4454a (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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/* 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.
 *
 */

#include "titanic/pet_control/pet_remote.h"
#include "titanic/pet_control/pet_remote_glyphs.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/messages/pet_messages.h"
#include "titanic/game_manager.h"
#include "titanic/titanic.h"

namespace Titanic {

static const byte REMOTE_DATA[] = {
	0x00, 0x02, 
		GLYPH_SUMMON_ELEVATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x01, 0x02,
		GLYPH_SUMMON_PELLERATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x02, 0x03,
		GLYPH_TELEVISION_CONTROL, GLYPH_OPERATE_LIGHTS, GLYPH_SUCCUBUS_DELIVERY,
	0x03, 0x02,
		GLYPH_SUMMON_ELEVATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x04, 0x02,
		GLYPH_TELEVISION_CONTROL, GLYPH_SUCCUBUS_DELIVERY,
	0x05, 0x02,
		GLYPH_SUMMON_PELLERATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x06, 0x02,
		GLYPH_SUMMON_PELLERATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x07, 0x03,
		GLYPH_TELEVISION_CONTROL, GLYPH_SUMMON_PELLERATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x08, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x09, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x0A, 0x02, GLYPH_SUMMON_ELEVATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x0B, 0x01,
		GLYPH_NAVIGATION_CONTROLLER,
	0x0C, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x0D, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x0E, 0x00,
	0x0F, 0x01,
		GLYPH_TELEVISION_CONTROL,
	0x10, 0x03,
		GLYPH_GOTO_BOTTOM_OF_WELL, GLYPH_GOTO_STATEROOM, GLYPH_GOTO_TOP_OF_WELL,
	0x11, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x12, 0x00,
	0x13, 0x02,
		GLYPH_SUMMON_PELLERATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x14, 0x00,
	0x15, 0x02,
		GLYPH_SUCCUBUS_DELIVERY, GLYPH_TELEVISION_CONTROL,
	0x16, 0x00,
	0x17, 0x02,
		GLYPH_SUMMON_PELLERATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x18, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x19, 0x00,
	0x1A, 0x00,
	0x1B, 0x00,
	0x1C, 0x00,
	0x1D, 0x02,
		GLYPH_SUMMON_ELEVATOR, GLYPH_SUCCUBUS_DELIVERY,
	0x1E, 0x0C,
		GLYPH_DEPLOY_FLORAL, GLYPH_DEPLOY_FULLY_RELAXATION, GLYPH_DEPLOY_COMFORT,
		GLYPH_DEPLOY_MINOR_STORAGE, GLYPH_ENTERTAINMENT_DEVICE, 
		GLYPH_DEPLOY_MAJOR_RELAXATION, GLYPH_INFLATE_RELAXATION,
		GLYPH_DEPLOY_MAINTENANCE, GLYPH_DEPLOY_WORK_SURFACE,
		GLYPH_DEPLOY_MINOR_RELAXATION, GLYPH_DEPLOY_SINK,
		GLYPH_DEPLOY_MAJOR_STORAGE,
	0x1F, 0x01,
		GLYPH_SUCCUBUS_DELIVERY,
	0x20, 0x02,
		GLYPH_SUMMON_ELEVATOR, GLYPH_SUMMON_PELLERATOR,
	0x21, 0x00
};

CPetRemote::CPetRemote() : CPetSection() {
}

bool CPetRemote::setup(CPetControl *petControl) {
	if (petControl && setupControl(petControl))
		return reset();
	return false;
}

bool CPetRemote::reset() {
	if (_petControl) {
		_onOff.reset("PetSwitchOn", _petControl, MODE_SELECTED);
		_onOff.reset("PetSwitchOff", _petControl, MODE_UNSELECTED);

		_up.reset("PetUp", _petControl, MODE_UNSELECTED);
		_down.reset("PetDown", _petControl, MODE_UNSELECTED);

		_left.reset("PetLeftUp", _petControl, MODE_SELECTED);
		_left.reset("PetLeft", _petControl, MODE_UNSELECTED);
		_right.reset("PetRightUp", _petControl, MODE_SELECTED);
		_right.reset("PetRight", _petControl, MODE_UNSELECTED);
		_top.reset("PetTopUp", _petControl, MODE_SELECTED);
		_top.reset("PetTop", _petControl, MODE_UNSELECTED);
		_bottom.reset("PetBottomUp", _petControl, MODE_SELECTED);
		_bottom.reset("PetBottom", _petControl, MODE_UNSELECTED);
		_action.reset("PetActionUp", _petControl, MODE_SELECTED);
		_action.reset("PetAction", _petControl, MODE_UNSELECTED);

		_send.reset("PetActSend0", _petControl, MODE_UNSELECTED);
		_send.reset("PetActSend1", _petControl, MODE_SELECTED);
		_receive.reset("PetActReceive0", _petControl, MODE_UNSELECTED);
		_receive.reset("PetActReceive1", _petControl, MODE_SELECTED);
		_call.reset("PetActCall0", _petControl, MODE_UNSELECTED);
		_call.reset("PetActCall1", _petControl, MODE_SELECTED);

		_items.reset();
		uint col = getColor(0);
		_text.setColor(col);
		_text.setLineColor(0, col);
	}

	return true;
}

void CPetRemote::draw(CScreenManager *screenManager) {
	_petControl->drawSquares(screenManager, 6);
	_items.draw(screenManager);
	_text.draw(screenManager);
}

bool CPetRemote::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
	return _items.MouseButtonDownMsg(msg->_mousePos);
}

bool CPetRemote::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
	return _items.MouseButtonUpMsg(msg->_mousePos);
}

bool CPetRemote::MouseDoubleClickMsg(CMouseDoubleClickMsg *msg) {
	return _items.MouseButtonDownMsg(msg->_mousePos);
}

bool CPetRemote::VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) {
	return _items.VirtualKeyCharMsg(msg);
}

bool CPetRemote::isValid(CPetControl *petControl) {
	return setupControl(petControl);
}

void CPetRemote::postLoad() {
	reset();
	CRoomItem *room = getRoom();
	if (room)
		enterRoom(room);
}

void CPetRemote::enter(PetArea oldArea) {
	if (_items.highlighted14())
		_text.setText(CString());
}

void CPetRemote::enterRoom(CRoomItem *room) {
	clearGlyphs();

	if (room) {
		CString roomName = room->getName();
		int roomIndex = roomIndexOf(roomName);
		if (roomIndex != -1) {
			Common::Array<uint> indexes;
			if (getRemoteData(roomIndex, indexes)) {
				loadGlyphs(indexes);
				_items.scrollToStart();
			}
		}
	}
}

CPetText *CPetRemote::getText() {
	return &_text;
}

CPetGfxElement *CPetRemote::getElement(uint id) {
	switch (id) {
	case 0:
		return &_onOff;
	case 1:
		return &_up;
	case 2:
		return &_down;
	case 3:
		return &_left;
	case 4:
		return &_right;
	case 5:
		return &_top;
	case 6:
		return &_bottom;
	case 7:
		return &_action;
	case 16:
		return &_send;
	case 17:
		return &_receive;
	case 18:
		return &_call;
	default:
		return nullptr;
	}
}

void CPetRemote::highlight(int id) {
	int highlightIndex = getHighlightIndex((RemoteGlyph)id);
	if (highlightIndex != -1)
		_items.highlight(highlightIndex);
}

bool CPetRemote::setupControl(CPetControl *petControl) {
	_petControl = petControl;
	if (!petControl)
		return false;

	_onOff.setBounds(Rect(0, 0, 15, 43));
	_onOff.translate(519, 381);
	_up.setBounds(Rect(0, 0, 21, 24));
	_up.translate(551, 381);
	_down.setBounds(Rect(0, 0, 21, 24));
	_down.translate(551, 402);
	_left.setBounds(Rect(0, 0, 22, 21));
	_left.translate(518, 393);
	_right.setBounds(Rect(0, 0, 21, 21));
	_right.translate(560, 393);
	_top.setBounds(Rect(0, 0, 21, 22));
	_top.translate(539, 371);
	_bottom.setBounds(Rect(0, 0, 21, 22));
	_bottom.translate(539, 414);
	_action.setBounds(Rect(0, 0, 21, 21));
	_action.translate(539, 393);
	_send.setBounds(Rect(0, 0, 62, 38));
	_send.translate(503, 373);
	_receive.setBounds(Rect(0, 0, 62, 38));
	_receive.translate(503, 420);
	_call.setBounds(Rect(0, 0, 62, 38));
	_call.translate(503, 383);

	Rect rect(0, 0, 580, 15);
	rect.moveTo(32, 445);
	_text.setBounds(rect);
	_text.setHasBorder(false);

	_items.setup(6, this);
	_items.setFlags(19);
	return true;
}

CRoomItem *CPetRemote::getRoom() const {
	if (_petControl) {
		CGameManager *gameManager = _petControl->getGameManager();
		if (gameManager)
			return gameManager->getRoom();
	}

	return nullptr;
}

int CPetRemote::getHighlightIndex(RemoteGlyph val) {
	CRoomItem *room = getRoom();
	if (!room)
		return -1;

	int roomIndex = roomIndexOf(room->getName());
	if (roomIndex == -1)
		return -1;

	Common::Array<uint> remoteData;
	getRemoteData(roomIndex, remoteData);

	// Loop through the data for the room
	for (uint idx = 0; idx < remoteData.size(); ++idx) {
		if ((RemoteGlyph)remoteData[idx + 1] == val)
			return idx;
	}

	return -1;
}

int CPetRemote::roomIndexOf(const CString &name) {
	for (int idx = 0; idx < TOTAL_ROOMS; ++idx) {
		if (g_vm->_roomNames[idx] == name)
			return idx;
	}

	return -1;
}

bool CPetRemote::getRemoteData(int roomIndex, Common::Array<uint> &indexes) {
	const byte *p = &REMOTE_DATA[0];
	for (int idx = 0; idx < TOTAL_ROOMS; ++idx) {
		if (*p == roomIndex) {
			for (int ctr = 0; ctr < *p; ++ctr)
				indexes.push_back(p[ctr + 1]);
			return true;
		}

		p += *(p + 1) + 2;
	}

	return false;
}

bool CPetRemote::loadGlyphs(const Common::Array<uint> &indexes) {
	for (uint idx = 0; idx < indexes.size(); ++idx) {
		if (!loadGlyph(indexes[idx]))
			return false;
	}

	return true;
}

bool CPetRemote::loadGlyph(int glyphIndex) {
	CPetRemoteGlyph *glyph = nullptr;

	switch (glyphIndex) {
	case GLYPH_SUMMON_ELEVATOR:
		glyph = new CSummonElevatorGlyph();
		break;

	case GLYPH_SUMMON_PELLERATOR:
		glyph = new CSummonPelleratorGlyph();
		break;

	case GLYPH_TELEVISION_CONTROL:
		glyph = new CTelevisionControlGlyph();
		break;

	case GLYPH_ENTERTAINMENT_DEVICE:
		glyph = new CEntertainmentDeviceGlyph();
		break;

	case GLYPH_OPERATE_LIGHTS:
		glyph = new COperateLightsGlyph();
		break;

	case GLYPH_DEPLOY_FLORAL:
		glyph = new CDeployFloralGlyph();
		break;

	case GLYPH_DEPLOY_FULLY_RELAXATION:
		glyph = new CDeployFullyRelaxationGlyph();
		break;

	case GLYPH_DEPLOY_COMFORT:
		glyph = new CDeployComfortGlyph();
		break;

	case GLYPH_DEPLOY_MINOR_STORAGE:
		glyph = new CDeployMinorStorageGlyph();
		break;

	case GLYPH_DEPLOY_MAJOR_RELAXATION:
		glyph = new CDeployMajorRelaxationGlyph();
		break;

	case GLYPH_INFLATE_RELAXATION:
		glyph = new CInflateRelaxationGlyph();
		break;

	case GLYPH_DEPLOY_MAINTENANCE:
		glyph = new CDeployMaintenanceGlyph();
		break;

	case GLYPH_DEPLOY_WORK_SURFACE:
		glyph = new CDeployWorkSurfaceGlyph();
		break;

	case GLYPH_DEPLOY_MINOR_RELAXATION:
		glyph = new CDeployMinorRelaxationGlyph();
		break;

	case GLYPH_DEPLOY_SINK:
		glyph = new CDeploySinkGlyph();
		break;

	case GLYPH_DEPLOY_MAJOR_STORAGE:
		glyph = new CDeployMajorStorageGlyph();
		break;

	case GLYPH_SUCCUBUS_DELIVERY:
		glyph = new CSuccubusDeliveryGlyph();
		break;

	case GLYPH_NAVIGATION_CONTROLLER:
		glyph = new CNavigationControllerGlyph();
		break;

	case GLYPH_GOTO_BOTTOM_OF_WELL:
		glyph = new CGotoBottomOfWellGlyph();
		break;

	case GLYPH_GOTO_TOP_OF_WELL:
		glyph = new CGotoTopOfWellGlyph();
		break;

	case GLYPH_GOTO_STATEROOM:
		glyph = new CGotoStateroomGlyph();
		break;

	case GLYPH_GOTO_BAR:
		glyph = new CGotoBarGlyph();

	case GLYPH_GOTO_PROMENADE:
		glyph = new CGotoPromenadeDeckGlyph();
		break;

	case GLYPH_GOTO_ARBORETUM:
		glyph = new CGotoArboretumGlyph();
		break;

	case GLYPH_GOTO_MUSIC_ROOM:
		glyph = new CGotoMusicRoomGlyph();
		break;

	case GLYPH_GOTO_RESTAURANT:
		glyph = new CGotoRestaurantGlyph();
		break;

	default:
		break;
	}

	if (glyph) {
		if (glyph->setup(_petControl, &_items)) {
			_items.push_back(glyph);
			return true;
		}
	}

	return false;
}

void CPetRemote::generateMessage(RemoteMessage msgNum, const CString &name, int num) {
	switch (msgNum) {
	case RMSG_LEFT: {
		CPETLeftMsg msg(name, num);
		msg.execute(_petControl->_remoteTarget);
		break;
	}

	case RMSG_RIGHT: {
		CPETRightMsg msg(name, num);
		msg.execute(_petControl->_remoteTarget);
		break;
	}

	case RMSG_UP: {
		CPETUpMsg msg(name, num);
		msg.execute(_petControl->_remoteTarget);
		break;
	}

	case RMSG_DOWN: {
		CPETDownMsg msg(name, num);
		msg.execute(_petControl->_remoteTarget);
		break;
	}

	case RMSG_ACTIVATE: {
		CPETActivateMsg msg(name, num);
		msg.execute(_petControl->_remoteTarget);
		break;
	}

	default:
		break;
	}
}

} // End of namespace Titanic