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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
/* 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/room_flags.h"
#include "titanic/titanic.h"
namespace Titanic {
#define ELEVATOR_SHIFT 18
#define ELEVATOR_MASK 3
#define PASSENGER_CLASS_SHIFT 16
#define PASSENGER_CLASS_MASK 3
#define FLOOR_SHIFT 8
#define FLOOR_MASK 0xFF
#define ROOM_SHIFT 1
#define ROOM_MASK 0x7F
struct TransportFlagsEntry {
const char *const _roomName;
uint _roomFlags;
};
struct SuccUBusFlagsEntry {
const char *const _roomName;
uint _roomFlags;
uint _succubusNum;
};
#define TRANSPORT_ROOMS_SIZE 6
const TransportFlagsEntry TRANSPORT_ROOMS[TRANSPORT_ROOMS_SIZE] = {
{ "TopOfWell", 0xDF4D1 },
{ "Pellerator", 0xC95E9 },
{ "Dome", 0xAD171 },
{ "Lift", 0x96E45 },
{ "SGTLeisure", 0x5D3AD },
{ "ServiceElevator", 0x68797 }
};
#define SUCCUBUS_ROOMS_SIZE 17
const SuccUBusFlagsEntry SUCCUBUS_ROOMS[SUCCUBUS_ROOMS_SIZE] = {
{ "ParrotLobby", 0x1D0D9, 3 },
{ "SculptureChamber", 0x465FB, 2 },
{ "Bar", 0x0B3D97, 2 },
{ "EmbLobby", 0x0CC971, 3 },
{ "MoonEmbLobby", 0x0CC971, 3 },
{ "MusicRoom", 0x0F34DB, 2 },
{ "MusicRoomLobby", 0x0F34DB, 2 },
{ "Titania", 0x8A397, 3 },
{ "BottomOfWell", 0x59FAD, 3 },
{ "Arboretum", 0x4D6AF, 1 },
{ "PromenadeDeck", 0x79C45, 2 },
{ "1stClassRestaurant", 0x896B9, 1 },
{ "CreatorsChamber", 0x2F86D, 2 },
{ "CreatorsChamberOn", 0x2F86D, 2 },
{ "BilgeRoom", 0x3D94B, 3 },
{ "BilgeRoomWith", 0x3D94B, 3 },
{ "Bridge", 0x39FCB, 3 }
};
int CRoomFlags::getConditionally() const {
if (getRoomArea() != 5 || getRoomCategory() != 5)
return _data;
else
return 5;
}
bool CRoomFlags::isTransportRoom() const {
for (int idx = 0; idx < TRANSPORT_ROOMS_SIZE; ++idx) {
if (TRANSPORT_ROOMS[idx]._roomFlags == _data)
return true;
}
return false;
}
int CRoomFlags::getRoomCategory() const {
if (getRoomNum() == 0)
return false;
CRoomFlags tempFlags = _data;
tempFlags.setRoomBits(1);
return tempFlags.getRoomArea() != 5;
}
int CRoomFlags::getRoomArea() const {
if (isSuccUBusRoomFlags())
return 4;
if (!getBit0()) {
uint v3 = getFloorNum();
if (v3 <= 38) {
uint v4 = getRoomNum();
if (v4 <= 18) {
uint v6 = getElevatorNum();
if (v6 >= 1 && v6 <= 4) {
uint v7 = (int)getPassengerClassNum() - 1;
if (v7) {
uint v8 = v7 - 1;
if (v8) {
if (v8 == 1 && is28To38(v3) && (v6 & 1) && v4 >= 1)
return 3;
} else if (is20To27(v3)) {
if (v6 & 1) {
if (v4 >= 1 && v4 <= 3)
return 2;
} else if (v4 >= 1 && v4 <= 4) {
return 2;
}
}
} else if (is2To19(v3) && v4 >= 1 && v4 <= 3) {
return 1;
}
}
}
}
}
return 5;
}
CString CRoomFlags::getRoomDesc() const {
switch (getRoomArea()) {
case 1:
case 2:
case 3: {
CString result = getPassengerClassDesc();
result += ", ";
result += getFloorDesc();
result += ", ";
result += getElevatorDesc();
result += ", ";
result += getRoomDesc();
return result;
}
case 4:
if (isTransportRoom()) {
switch (_data) {
case 0x68797:
return "The Service Elevator";
case 0x5D3AD:
return "The Super Galactic Leisure Lounge";
case 0x96E45:
return "The Elevator";
case 0xAD171:
return "The Dome";
case 0xC95E9:
return "The Pellerator";
case 0xDF4D1:
return "The Top of the Well";
default:
break;
}
}
if (getRoomCategory() == 0) {
return "Nowhere you're likely to want to go.";
} else {
CString result = getPassengerClassDesc();
result += ", ";
result += getFloorDesc();
return result;
}
break;
case 5:
switch (_data) {
case 0x1D0D9:
return "The Parrot Lobby";
case 0x2F86D:
return "The Creators' Chamber";
case 0x39FCB:
return "The Bridge";
case 0x3D94B:
return "The Bilge Room";
case 0x465FB:
return "The Sculpture Chamber";
case 0x4D6AF:
return "The Arboretum";
case 0x59FAD:
return "The Bottom of the Well";
case 0x79C45:
return "The Promenade Deck";
case 0x896B9:
return "The 1st class restaurant";
case 0x8A397:
return "Titania's Room";
case 0xB3D97:
return "The Bar";
case 0xCC971:
return "The Embarkation Lobby";
case 0xF34DB:
return "The Music Room";
default:
break;
}
return "Unknown Room";
default:
break;
}
return "Unknown Room";
}
void CRoomFlags::setElevatorBits(uint val) {
_data &= ~(ELEVATOR_MASK << ELEVATOR_SHIFT);
_data |= (val & ELEVATOR_MASK) << ELEVATOR_SHIFT;
}
uint CRoomFlags::getElevatorBits() const {
return (_data >> ELEVATOR_SHIFT) & ELEVATOR_MASK;
}
void CRoomFlags::setPassengerClassBits(uint val) {
_data &= ~(PASSENGER_CLASS_MASK << PASSENGER_CLASS_SHIFT);
_data |= (val & PASSENGER_CLASS_MASK) << PASSENGER_CLASS_SHIFT;
}
uint CRoomFlags::getPassengerClassBits() const {
return (_data >> PASSENGER_CLASS_SHIFT) & PASSENGER_CLASS_MASK;
}
CString CRoomFlags::getPassengerClassDesc() const {
PassengerClass classNum = getPassengerClassNum();
switch (classNum) {
case FIRST_CLASS:
return "1st class";
case SECOND_CLASS:
return "2nd class";
case THIRD_CLASS:
return "SGT class";
default:
return "no class";
}
}
void CRoomFlags::setFloorBits(uint val) {
_data &= ~(FLOOR_MASK << FLOOR_SHIFT);
_data |= (val & FLOOR_MASK) << FLOOR_SHIFT;
}
uint CRoomFlags::getFloorBits() const {
return (_data >> FLOOR_SHIFT) & FLOOR_MASK;
}
uint CRoomFlags::decodeFloorBits(uint bits) const {
int base = 0;
int offset = bits & 0xF;
switch ((bits >> 4) & 0xF) {
case 1:
case 2:
case 3:
base = 40;
break;
case 4:
base = 10;
break;
case 5:
base = 20;
break;
case 6:
base = 30;
break;
default:
break;
}
return offset >= 10 ? 0 : base + offset;
}
void CRoomFlags::setFloorNum(uint floorNum) {
uint base = 0;
switch (floorNum / 10) {
case 0:
base = 0x90;
break;
case 1:
base = 0xD0;
case 2:
base = 0xE0;
case 3:
base = 0xF0;
break;
default:
break;
}
setFloorBits(base | (floorNum % 10));
}
uint CRoomFlags::getFloorNum() const {
return decodeFloorBits(getFloorBits());
}
void CRoomFlags::setRoomBits(uint roomBits) {
_data &= ~(ROOM_MASK << ROOM_SHIFT);
_data |= (roomBits & ROOM_MASK) << ROOM_SHIFT;
}
uint CRoomFlags::getRoomBits() const {
return (_data >> ROOM_SHIFT) & ROOM_MASK;
}
bool CRoomFlags::isSuccUBusRoomFlags() const {
for (int idx = 0; idx < SUCCUBUS_ROOMS_SIZE; ++idx) {
if (SUCCUBUS_ROOMS[idx]._roomFlags == _data)
return true;
}
return false;
}
bool CRoomFlags::getBit0() const {
return _data & 1;
}
uint CRoomFlags::getSpecialRoomFlags(const CString &roomName) {
for (int idx = 0; idx < SUCCUBUS_ROOMS_SIZE; ++idx) {
if (roomName == SUCCUBUS_ROOMS[idx]._roomName)
return SUCCUBUS_ROOMS[idx]._roomFlags;
}
for (int idx = 0; idx < TRANSPORT_ROOMS_SIZE; ++idx) {
if (roomName == TRANSPORT_ROOMS[idx]._roomName)
return TRANSPORT_ROOMS[idx]._roomFlags;
}
return 0;
}
uint CRoomFlags::getSuccUBusNum(const CString &roomName) const {
for (int idx = 0; idx < SUCCUBUS_ROOMS_SIZE; ++idx) {
if (roomName == SUCCUBUS_ROOMS[idx]._roomName)
return SUCCUBUS_ROOMS[idx]._succubusNum;
}
return 0;
}
CString CRoomFlags::getSuccUBusRoomName() const {
for (int idx = 0; idx < SUCCUBUS_ROOMS_SIZE; ++idx) {
if (SUCCUBUS_ROOMS[idx]._roomFlags == _data)
return SUCCUBUS_ROOMS[idx]._roomName;
}
return CString();
}
void CRoomFlags::changeLocation(int action) {
uint floorNum = getFloorNum();
uint roomNum = getRoomNum();
uint elevatorNum = getElevatorNum();
PassengerClass classNum = getPassengerClassNum();
uint v10, v11, v12, v13;
switch (classNum) {
case FIRST_CLASS:
v10 = 2;
v11 = 19;
v12 = 1;
v13 = 3;
break;
case SECOND_CLASS:
v10 = 20;
v11 = 27;
v12 = 1;
v13 = (elevatorNum & 1) ? 3 : 4;
break;
case THIRD_CLASS:
v10 = 28;
v11 = 38;
v12 = 1;
v13 = 18;
break;
default:
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 0;
break;
}
// Perform action to change room or floor
switch (action) {
case 1:
if (--roomNum < v12)
roomNum = v12;
break;
case 2:
if (++roomNum > v13)
roomNum = v13;
break;
case 3:
if (--floorNum < v10)
floorNum = v10;
break;
case 4:
if (++floorNum > v11)
floorNum = v11;
}
// Set new floor and room
setFloorNum(floorNum);
setRoomBits(roomNum);
}
bool CRoomFlags::compareClassElevator(uint flags1, uint flags2) {
CRoomFlags f1(flags1);
CRoomFlags f2(flags2);
if (f1.getFloorNum() != f2.getFloorNum())
return false;
uint elev1 = f1.getElevatorNum();
uint elev2 = f2.getElevatorNum();
PassengerClass class1 = f1.getPassengerClassNum();
PassengerClass class2 = f2.getPassengerClassNum();
if (class1 == FIRST_CLASS || class1 == SECOND_CLASS) {
if (elev1 == 2)
elev1 = 1;
else if (elev1 == 4)
elev1 = 3;
}
if (class2 == FIRST_CLASS || class2 == SECOND_CLASS) {
if (elev2 == 2)
elev2 = 1;
else if (elev2 == 4)
elev2 = 3;
}
return elev1 == elev2;
}
bool CRoomFlags::compareLocation(uint flags1, uint flags2) {
CRoomFlags f1(flags1);
CRoomFlags f2(flags2);
return f1.getElevatorNum() == f2.getElevatorBits() &&
f1.getFloorNum() == f2.getFloorNum() &&
f1.getRoomNum() == f2.getRoomNum();
}
bool CRoomFlags::isTitania(uint flags1, uint flags2) {
return flags2 == 0x8A397;
}
void CRoomFlags::setRandomLocation(int classNum, bool flag) {
uint minRoom, elevNum, maxRoom, maxFloor, minFloor;
do {
switch (classNum) {
case 1:
minFloor = 2;
maxFloor = 19;
minRoom = 1;
maxRoom = 3;
elevNum = g_vm->getRandomNumber(flag ? 2 : 3);
break;
case 2:
minFloor = 20;
maxFloor = 27;
elevNum = g_vm->getRandomNumber(flag ? 2 : 3);
minRoom = 1;
maxRoom = ((elevNum - 1) & 1) ? 3 : 4;
break;
case 3:
minRoom = 1;
minFloor = 28;
maxFloor = 38;
maxRoom = 18;
elevNum = g_vm->getRandomNumber(1);
if (elevNum == 1)
elevNum = 2;
break;
default:
return;
}
uint floorNum = minFloor + g_vm->getRandomNumber(maxFloor - minFloor);
uint roomNum = minRoom + g_vm->getRandomNumber(maxRoom - minRoom);
setElevatorBits(elevNum);
setRoomBits(roomNum);
setFloorNum(floorNum);
} while (_data == 0x59706);
}
int CRoomFlags::whatPassengerClass(int floorNum) {
if (is2To19(floorNum))
return 1;
return is20To27(floorNum) ? 2 : 3;
}
} // End of namespace Titanic
|