aboutsummaryrefslogtreecommitdiff
path: root/engines/lab/map.cpp
blob: 2e3dffc94367229680982b9aa1e74e41221c00c2 (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
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
/* 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.
 *
 */

/*
 * This code is based on Labyrinth of Time code with assistance of
 *
 * Copyright (c) 1993 Terra Nova Development
 * Copyright (c) 2004 The Wyrmkeep Entertainment Co.
 *
 */

#include "lab/lab.h"
#include "lab/stddefines.h"
#include "lab/labfun.h"
#include "lab/diff.h"
#include "lab/vga.h"
#include "lab/text.h"
#include "lab/mouse.h"
#include "lab/parsefun.h"
#include "lab/parsetypes.h"
#include "lab/interface.h"
#include "lab/text.h"

namespace Lab {

static TextFont *BigMsgFont;
static TextFont bmf;


extern uint16 Direction;
extern bool IsHiRes;
extern uint32 VGAScreenWidth, VGAScreenHeight;

extern CloseDataPtr CPtr;
extern uint16 RoomNum;

/*****************************************************************************/
/* Converts an Amiga palette (up to 16 colors) to a VGA palette, then sets   */
/* the VGA palette.                                                          */
/*****************************************************************************/
void setAmigaPal(uint16 *pal, uint16 numcolors) {
	byte vgapal[16 * 3];
	uint16 vgacount = 0;

	if (numcolors > 16)
		numcolors = 16;

	for (uint16 counter = 0; counter < numcolors; counter++) {
		vgapal[vgacount++] = (byte)(((pal[counter] & 0xf00) >> 8) << 2);
		vgapal[vgacount++] = (byte)(((pal[counter] & 0x0f0) >> 4) << 2);
		vgapal[vgacount++] = (byte)(((pal[counter] & 0x00f)) << 2);
	}

	writeColorRegsSmooth(vgapal, 0, 16);
}


/*****************************************************************************/
/* Gets a font from disk and puts it into temporary memory.                  */
/*****************************************************************************/
bool getFont(const char *filename, TextFont *textfont) {
	byte **file = NULL;
	char header[5];
	uint32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;

	file = g_music->newOpen(filename, filesize);
	g_music->updateMusic();

	if ((file != NULL) && (filesize > headersize)) {
		byte *fontbuffer = (byte *)stealBufMem(filesize - (sizeof(TextFont) + 4));
		if (!fontbuffer)
			return false;

		header[4] = 0;
		readBlock(&header, 4L, file);

		if (strcmp(header, "VGAF") == 0) {
			textfont->DataLength = filesize - headersize;
			readBlock(&(textfont->Height), 2L, file);
			swapUShortPtr(&(textfont->Height), 1);

			readBlock(textfont->Widths, 256L, file);
			readBlock(textfont->Offsets, 256L * 2L, file);
			swapUShortPtr(textfont->Offsets, 256);

			(*file) += 4;
			textfont->data = fontbuffer;
			readBlock(textfont->data, textfont->DataLength, file);
			return true;
		}
	}

	return false;
}


/*****************************************************************************/
/* Gets a chunk of text and puts it into the graphics memory.                */
/*****************************************************************************/
char *getText(const char *filename) {
	bool dodecrypt;
	byte **tfile;

	g_music->updateMusic();
	dodecrypt = (isBuffered(filename) == NULL);
	tfile = g_music->newOpen(filename);

	if (!tfile)
		return NULL;

	if (dodecrypt)
		decrypt(*tfile);

	return (char *)*tfile;
}



/*****************************************************************************/
/* Reads in an image from disk.                                              */
/*****************************************************************************/
void readImage(byte **buffer, Image **im) {
	uint32 size;

	(*im) = (Image *)(*buffer);

	(*im)->Width = READ_LE_UINT16(*buffer);
	(*im)->Height = READ_LE_UINT16(*buffer + 2);

	*buffer += 8; /* sizeof(struct Image); */

	size = (*im)->Width * (*im)->Height;

	if (1L & size)
		size++;

	(*im)->ImageData = (byte *)(*buffer);
	(*buffer) += size;
}


/*---------------------------------------------------------------------------*/
/*------------------------------ The Map stuff ------------------------------*/
/*---------------------------------------------------------------------------*/

extern RoomData *Rooms;

static Image *Map, *Room, *UpArrowRoom, *DownArrowRoom, *Bridge,
			 *HRoom, *VRoom, *Maze, *HugeMaze, *Path, *MapNorth,
			 *MapEast, *MapSouth, *MapWest, *XMark, *Back, *BackAlt,
			 *Down, *DownAlt, *Up, *UpAlt;

static uint16 MaxRooms;
static MapData *Maps;

extern char *LOWERFLOORS, *MIDDLEFLOORS, *UPPERFLOORS, *MEDMAZEFLOORS, *HEDGEMAZEFLOORS, *SURMAZEFLOORS, *CARNIVALFLOOR, *SURMAZEMSG;

extern TextFont *MsgFont;

uint16 *FadePalette;

static uint16 MapGadX[3] = {101, 55, 8}, MapGadY[3] = {105, 105, 105};

static Gadget downgadget = { 101, 105, 2, VKEY_DNARROW, 0L, NULL, NULL, NULL },
			  upgadget   = {  55, 105, 1, VKEY_UPARROW, 0L, NULL, NULL, &downgadget },
			  backgadget = {   8, 105, 0, 0, 0L, NULL, NULL, &upgadget };

static Gadget *MapGadgetList = &backgadget;

static uint16 AmigaMapPalette[] = {
	0x0BA8, 0x0C11, 0x0A74, 0x0076,
	0x0A96, 0x0DCB, 0x0CCA, 0x0222,
	0x0444, 0x0555, 0x0777, 0x0999,
	0x0AAA, 0x0ED0, 0x0EEE, 0x0694
};


#define LOWERFLOOR     1
#define MIDDLEFLOOR    2
#define UPPERFLOOR     3
#define MEDMAZEFLOOR   4
#define HEDGEMAZEFLOOR 5
#define SURMAZEFLOOR   6
#define CARNIVAL       7



static uint16 mapScaleX(uint16 x) {
	if (IsHiRes)
		return (x - 45);
	else
		return ((x - 45) >> 1);
}



static uint16 mapScaleY(uint16 y) {
	if (IsHiRes)
		return y;
	else
		return ((y - 35) >> 1) - (y >> 6);
}




/*****************************************************************************/
/* Loads in the map data.                                                    */
/*****************************************************************************/
static bool loadMapData() {
	byte **buffer, Temp[5];
	uint32 Size;
	Gadget *gptr;
	uint16 counter;

	BigMsgFont = &bmf;

	if (!getFont("P:Map.fon", BigMsgFont))
		BigMsgFont = MsgFont;

	resetBuffer();  /* Make images load into start of buffer */
	buffer = g_music->newOpen("P:MapImage", Size);

	if (!buffer)
		return false;

	stealBufMem(Size); /* Now freeze that buffer from further use */

	readImage(buffer, &Map);

	readImage(buffer, &Room);
	readImage(buffer, &UpArrowRoom);
	readImage(buffer, &DownArrowRoom);
	readImage(buffer, &HRoom);
	readImage(buffer, &VRoom);
	readImage(buffer, &Maze);
	readImage(buffer, &HugeMaze);

	readImage(buffer, &MapNorth);
	readImage(buffer, &MapEast);
	readImage(buffer, &MapSouth);
	readImage(buffer, &MapWest);

	readImage(buffer, &Path);
	readImage(buffer, &Bridge);

	readImage(buffer, &Back);
	readImage(buffer, &BackAlt);
	readImage(buffer, &Up);
	readImage(buffer, &UpAlt);
	readImage(buffer, &Down);
	readImage(buffer, &DownAlt);

	backgadget.Im    = Back;
	backgadget.ImAlt = BackAlt;
	upgadget.Im      = Up;
	upgadget.ImAlt   = UpAlt;
	downgadget.Im    = Down;
	downgadget.ImAlt = DownAlt;

	counter = 0;
	gptr = MapGadgetList;

	while (gptr) {
		gptr->x = VGAScaleX(MapGadX[counter]);
		gptr->y = VGAScaleY(MapGadY[counter]);
		gptr = gptr->NextGadget;
		counter++;
	}

	uint32 bufferSize;
	buffer = g_music->newOpen("Lab:Maps", bufferSize);
	stealBufMem(bufferSize);  /* Freeze the memory for the maps */
	readBlock(Temp, 4L, buffer);
	Temp[4] = 0;

	if (strcmp((char *)Temp, "MAP0") == 0) {
		readBlock(&MaxRooms, 2L, buffer);
		swapUShortPtr(&MaxRooms, 1);
		Maps = (MapData *)(*buffer);

		for (counter = 1; counter <= MaxRooms; counter++) {
			swapUShortPtr(&Maps[counter].x, 4);
			swapULong(&Maps[counter].MapFlags);
		}
	} else
		return false;

	return true;
}




static uint16 fadeNumIn(uint16 num, uint16 res, uint16 counter) {
	return (num - ((((int32)(15 - counter)) * ((int32)(num - res))) / 15));
}


static uint16 fadeNumOut(uint16 num, uint16 res, uint16 counter) {
	return (num - ((((int32) counter) * ((int32)(num - res))) / 15));
}



/*****************************************************************************/
/* Does the fading of the Palette on the screen.                             */
/*****************************************************************************/
void fade(bool fadein, uint16 res) {
	uint16 pennum, counter, newpal[16];

	for (counter = 0; counter < 16; counter++) {
		for (pennum = 0; pennum < 16; pennum++) {
			if (fadein)
				newpal[pennum] = (0x00F & fadeNumIn(0x00F & FadePalette[pennum], 0x00F & res, counter)) +
				                 (0x0F0 & fadeNumIn(0x0F0 & FadePalette[pennum], 0x0F0 & res, counter)) +
				                 (0xF00 & fadeNumIn(0xF00 & FadePalette[pennum], 0xF00 & res, counter));
			else
				newpal[pennum] = (0x00F & fadeNumOut(0x00F & FadePalette[pennum], 0x00F & res, counter)) +
				                 (0x0F0 & fadeNumOut(0x0F0 & FadePalette[pennum], 0x0F0 & res, counter)) +
				                 (0xF00 & fadeNumOut(0xF00 & FadePalette[pennum], 0xF00 & res, counter));
		}

		setAmigaPal(newpal, 16);
		waitTOF();
		g_music->updateMusic();
	}
}



/*****************************************************************************/
/* Figures out what a room's coordinates should be.                          */
/*****************************************************************************/
static void roomCords(uint16 CurRoom, uint16 *x1, uint16 *y1, uint16 *x2, uint16 *y2) {
	*x1 = mapScaleX(Maps[CurRoom].x);
	*y1 = mapScaleY(Maps[CurRoom].y);
	*x2 = *x1;
	*y2 = *y1;

	switch (Maps[CurRoom].SpecialID) {
	case NORMAL:
	case UPARROWROOM:
	case DOWNARROWROOM:
		(*x2) += Room->Width;
		(*y2) += Room->Height;
		break;

	case BRIDGEROOM:
		(*x2) += Bridge->Width;
		(*y2) += Bridge->Height;
		break;

	case VCORRIDOR:
		(*x2) += VRoom->Width;
		(*y2) += VRoom->Height;
		break;

	case HCORRIDOR:
		(*x2) += HRoom->Width;
		(*y2) += HRoom->Height;
		break;
	}
}





/*****************************************************************************/
/* Draws a room to the bitmap.                                               */
/*****************************************************************************/
static void drawRoom(uint16 CurRoom, bool drawx) {
	uint16 x, y, xx, xy, offset;
	uint32 flags;

	x = mapScaleX(Maps[CurRoom].x);
	y = mapScaleY(Maps[CurRoom].y);
	flags = Maps[CurRoom].MapFlags;

	switch (Maps[CurRoom].SpecialID) {
	case NORMAL:
	case UPARROWROOM:
	case DOWNARROWROOM:
		if (Maps[CurRoom].SpecialID == NORMAL)
			drawImage(Room, x, y);
		else if (Maps[CurRoom].SpecialID == DOWNARROWROOM)
			drawImage(DownArrowRoom, x, y);
		else
			drawImage(UpArrowRoom, x, y);

		offset = (Room->Width - Path->Width) / 2;

		if ((NORTHDOOR & flags) && (y >= Path->Height))
			drawImage(Path, x + offset, y - Path->Height);

		if (SOUTHDOOR & flags)
			drawImage(Path, x + offset, y + Room->Height);

		offset = (Room->Height - Path->Height) / 2;

		if (EASTDOOR & flags)
			drawImage(Path, x + Room->Width, y + offset);

		if (WESTDOOR & flags)
			drawImage(Path, x - Path->Width, y + offset);

		xx = x + (Room->Width - XMark->Width) / 2;
		xy = y + (Room->Height - XMark->Height) / 2;

		break;

	case BRIDGEROOM:
		drawImage(Bridge, x, y);

		xx = x + (Bridge->Width - XMark->Width) / 2;
		xy = y + (Bridge->Height - XMark->Height) / 2;

		break;

	case VCORRIDOR:
		drawImage(VRoom, x, y);

		offset = (VRoom->Width - Path->Width) / 2;

		if (NORTHDOOR & flags)
			drawImage(Path, x + offset, y - Path->Height);

		if (SOUTHDOOR & flags)
			drawImage(Path, x + offset, y + VRoom->Height);

		offset = (Room->Height - Path->Height) / 2;

		if (EASTDOOR & flags)
			drawImage(Path, x + VRoom->Width, y + offset);

		if (WESTDOOR & flags)
			drawImage(Path, x - Path->Width, y + offset);

		if (EASTBDOOR & flags)
			drawImage(Path, x + VRoom->Width, y - offset - Path->Height + VRoom->Height);

		if (WESTBDOOR & flags)
			drawImage(Path, x - Path->Width, y - offset - Path->Height + VRoom->Height);

		offset = (VRoom->Height - Path->Height) / 2;

		if (EASTMDOOR & flags)
			drawImage(Path, x + VRoom->Width, y - offset - Path->Height + VRoom->Height);

		if (WESTMDOOR & flags)
			drawImage(Path, x - Path->Width, y - offset - Path->Height + VRoom->Height);

		xx = x + (VRoom->Width - XMark->Width) / 2;
		xy = y + (VRoom->Height - XMark->Height) / 2;

		break;

	case HCORRIDOR:
		drawImage(HRoom, x, y);

		offset = (Room->Width - Path->Width) / 2;

		if (NORTHDOOR & flags)
			drawImage(Path, x + offset, y - Path->Height);

		if (SOUTHDOOR & flags)
			drawImage(Path, x + offset, y + Room->Height);

		if (NORTHRDOOR & flags)
			drawImage(Path, x - offset - Path->Width + HRoom->Width, y - Path->Height);

		if (SOUTHRDOOR & flags)
			drawImage(Path, x - offset - Path->Width + HRoom->Width, y + Room->Height);

		offset = (HRoom->Width - Path->Width) / 2;

		if (NORTHMDOOR & flags)
			drawImage(Path, x - offset - Path->Width + HRoom->Width, y - Path->Height);

		if (SOUTHMDOOR & flags)
			drawImage(Path, x - offset - Path->Width + HRoom->Width, y + Room->Height);

		offset = (Room->Height - Path->Height) / 2;

		if (EASTDOOR & flags)
			drawImage(Path, x + HRoom->Width, y + offset);

		if (WESTDOOR & flags)
			drawImage(Path, x - Path->Width, y + offset);

		xx = x + (HRoom->Width - XMark->Width) / 2;
		xy = y + (HRoom->Height - XMark->Height) / 2;

		break;

	default:
		return;
	}

	if (drawx)
		drawImage(XMark, xx, xy);
}



/*****************************************************************************/
/* Checks if a floor has been visitted.                                      */
/*****************************************************************************/
static bool onFloor(uint16 Floor) {
	uint16 drawroom;

	for (drawroom = 1; drawroom <= MaxRooms; drawroom++) {
		if ((Maps[drawroom].PageNumber == Floor)
		        && g_lab->_roomsFound->in(drawroom)
		        && Maps[drawroom].x) {
			return true;
		}
	}

	return false;
}




/*****************************************************************************/
/* Figures out which floor, if any, should be gone to if the up arrow is hit */
/*****************************************************************************/
static void getUpFloor(uint16 *Floor, bool *isfloor) {
	do {
		*isfloor = true;

		if (*Floor < UPPERFLOOR)
			(*Floor)++;
		else {
			*Floor   = CARNIVAL + 1;
			*isfloor = false;
			return;
		}
	} while ((!onFloor(*Floor)) && (*Floor <= CARNIVAL));
}




/*****************************************************************************/
/* Figures out which floor, if any, should be gone to if the down arrow is   */
/* hit.                                                                      */
/*****************************************************************************/
static void getDownFloor(uint16 *Floor, bool *isfloor) {
	do {
		*isfloor = true;

		if ((*Floor == LOWERFLOOR) || (*Floor == 0)) {
			*Floor   = 0;
			*isfloor = false;
			return;
		} else if (*Floor > UPPERFLOOR) {
			/* LAB: Labyrinth specific code */
			if (*Floor == HEDGEMAZEFLOOR)
				*Floor = UPPERFLOOR;
			else if ((*Floor == CARNIVAL) || (*Floor == MEDMAZEFLOOR))
				*Floor = MIDDLEFLOOR;
			else if (*Floor == SURMAZEFLOOR)
				*Floor = LOWERFLOOR;
			else {
				*Floor = 0;
				*isfloor = false;
				return;
			}
		} else
			(*Floor)--;

	} while ((!onFloor(*Floor)) && *Floor);
}





/*****************************************************************************/
/* Draws the map                                                             */
/*****************************************************************************/
static void drawMap(uint16 CurRoom, uint16 CurMsg, uint16 Floor, bool fadeout, bool fadein) {
	uint16 drawroom;
	char *sptr;

	uint16 tempfloor;
	bool noghoast;

	mouseHide();

	if (fadeout)
		fade(false, 0);

	setAPen(0);
	rectFill(0, 0, VGAScreenWidth - 1, VGAScreenHeight - 1);

	drawImage(Map, 0, 0);
	drawGadgetList(MapGadgetList);

	for (drawroom = 1; drawroom <= MaxRooms; drawroom++) {
		if ((Maps[drawroom].PageNumber == Floor)
		        && g_lab->_roomsFound->in(drawroom)
		        && Maps[drawroom].x) {
			drawRoom(drawroom, (bool)(drawroom == CurRoom));
			g_music->updateMusic();
		}
	}

	if ((Maps[CurRoom].PageNumber == Floor)   /* Makes sure the X is drawn in corridors */
	        && g_lab->_roomsFound->in(CurRoom) /* NOTE: this here on purpose just in case there's some weird condition, like the surreal maze where there are no rooms */
	        && Maps[CurRoom].x)
		drawRoom(CurRoom, true);

	tempfloor = Floor;
	getUpFloor(&tempfloor, &noghoast);

	if (noghoast)
		unGhoastGadget(&upgadget);
	else
		ghoastGadget(&upgadget, 12);

	tempfloor = Floor;
	getDownFloor(&tempfloor, &noghoast);

	if (noghoast)
		unGhoastGadget(&downgadget);
	else
		ghoastGadget(&downgadget, 12);

	/* LAB: Labyrinth specific code */
	if (Floor == LOWERFLOOR) {
		if (onFloor(SURMAZEFLOOR))
			drawImage(Maze, mapScaleX(538), mapScaleY(277));
	}

	else if (Floor == MIDDLEFLOOR) {
		if (onFloor(CARNIVAL))
			drawImage(Maze, mapScaleX(358), mapScaleY(72));

		if (onFloor(MEDMAZEFLOOR))
			drawImage(Maze, mapScaleX(557), mapScaleY(325));
	}

	else if (Floor == UPPERFLOOR) {
		if (onFloor(HEDGEMAZEFLOOR))
			drawImage(HugeMaze, mapScaleX(524), mapScaleY(97));
	}

	else if (Floor == SURMAZEFLOOR) {
		flowText(MsgFont, 0, 7, 0, true, true, true, true, mapScaleX(360), 0, mapScaleX(660), mapScaleY(450), SURMAZEMSG);
	}


	switch (Floor) {
	case LOWERFLOOR:
		sptr = LOWERFLOORS;
		break;
	case MIDDLEFLOOR:
		sptr = MIDDLEFLOORS;
		break;
	case UPPERFLOOR:
		sptr = UPPERFLOORS;
		break;
	case MEDMAZEFLOOR:
		sptr = MEDMAZEFLOORS;
		break;
	case HEDGEMAZEFLOOR:
		sptr = HEDGEMAZEFLOORS;
		break;
	case SURMAZEFLOOR:
		sptr = SURMAZEFLOORS;
		break;
	case CARNIVAL:
		sptr = CARNIVALFLOOR;
		break;
	default:
		sptr = NULL;
		break;
	}

	if (sptr)
		flowText(MsgFont, 0, 5, 3, true, true, true, true, VGAScaleX(14), VGAScaleY(75), VGAScaleX(134), VGAScaleY(97), sptr);

	if ((sptr = Rooms[CurMsg].RoomMsg))
		flowText(MsgFont, 0, 5, 3, true, true, true, true, VGAScaleX(14), VGAScaleY(148), VGAScaleX(134), VGAScaleY(186), sptr);

	if (fadein)
		fade(true, 0);

	mouseShow();
}



/*****************************************************************************/
/* Processes the map.                                                        */
/*****************************************************************************/
void processMap(uint16 CurRoom) {
	uint32 Class, place = 1;
	uint16 Code, Qualifier, MouseX, MouseY, GadgetID, CurFloor, OldFloor, OldMsg, CurMsg, drawroom, x1, y1, x2, y2;
	char *sptr;
	byte newcolor[3];
	bool drawmap;
	IntuiMessage *Msg;

	CurMsg   = CurRoom;
	CurFloor = Maps[CurRoom].PageNumber;

	while (1) {
		g_music->updateMusic();  /* Make sure we check the music at least after every message */
		Msg = getMsg();

		if (Msg == NULL) {
			g_music->updateMusic();

			if (place <= 14) {
				newcolor[0] = 14 << 2;
				newcolor[1] = place << 2;
				newcolor[2] = newcolor[1];
			} else {
				newcolor[0] = 14 << 2;
				newcolor[1] = (28 - place) << 2;
				newcolor[2] = newcolor[1];
			}

			waitTOF();
			writeColorReg(newcolor, 1);
			updateMouse();
			waitTOF();
			updateMouse();
			waitTOF();
			updateMouse();
			waitTOF();
			updateMouse();

			place++;

			if (place >= 28)
				place = 1;

		} else {
			Class     = Msg->Class;
			Code      = Msg->Code;
			GadgetID  = Msg->GadgetID;
			Qualifier = Msg->Qualifier;
			MouseX    = Msg->MouseX;
			MouseY    = Msg->MouseY;

			if (((Class == MOUSEBUTTONS) && (IEQUALIFIER_RBUTTON & Qualifier)) ||
			        ((Class == RAWKEY) && (Code == 27)))
				return;

			if (Class == GADGETUP) {
				if (GadgetID == 0) { /* Quit menu button */
					return;
				} else if (GadgetID == 1) { /* Up arrow */
					OldFloor = CurFloor;
					getUpFloor(&CurFloor, &drawmap);

					if (drawmap) {
						fade(false, 0);
						drawMap(CurRoom, CurMsg, CurFloor, false, false);
						fade(true, 0);
					} else
						CurFloor = OldFloor;
				} else if (GadgetID == 2) { /* Down arrow */
					OldFloor = CurFloor;
					getDownFloor(&CurFloor, &drawmap);

					if (drawmap) {
						fade(false, 0);
						drawMap(CurRoom, CurMsg, CurFloor, false, false);
						fade(true, 0);
					} else
						CurFloor = OldFloor;
				}
			}

			else if ((Class == MOUSEBUTTONS) && (IEQUALIFIER_LEFTBUTTON & Qualifier)) {
				if ((CurFloor == LOWERFLOOR) && (MouseX >= mapScaleX(538)) && (MouseY >= mapScaleY(277))
				        && (MouseX <= mapScaleX(633)) && (MouseY <= mapScaleY(352))
				        && onFloor(SURMAZEFLOOR)) {
					CurFloor = SURMAZEFLOOR;

					fade(false, 0);
					drawMap(CurRoom, CurMsg, CurFloor, false, false);
					fade(true, 0);
				}

				else if ((CurFloor == MIDDLEFLOOR) && (MouseX >= mapScaleX(358)) && (MouseY >= mapScaleY(71))
				         && (MouseX <= mapScaleX(452)) && (MouseY <= mapScaleY(147))
				         && onFloor(CARNIVAL)) {
					CurFloor = CARNIVAL;

					fade(false, 0);
					drawMap(CurRoom, CurMsg, CurFloor, false, false);
					fade(true, 0);
				}

				else if ((CurFloor == MIDDLEFLOOR) && (MouseX >= mapScaleX(557)) && (MouseY >= mapScaleY(325))
				         && (MouseX <= mapScaleX(653)) && (MouseY <= mapScaleY(401))
				         && onFloor(MEDMAZEFLOOR)) {
					CurFloor = MEDMAZEFLOOR;

					fade(false, 0);
					drawMap(CurRoom, CurMsg, CurFloor, false, false);
					fade(true, 0);
				}

				else if ((CurFloor == UPPERFLOOR) && (MouseX >= mapScaleX(524)) && (MouseY >=  mapScaleY(97))
				         && (MouseX <= mapScaleX(645)) && (MouseY <= mapScaleY(207))
				         && onFloor(HEDGEMAZEFLOOR)) {
					CurFloor = HEDGEMAZEFLOOR;

					fade(false, 0);
					drawMap(CurRoom, CurMsg, CurFloor, false, false);
					fade(true, 0);
				}

				else if (MouseX > mapScaleX(314)) {
					OldMsg = CurMsg;

					for (drawroom = 1; drawroom <= MaxRooms; drawroom++) {
						roomCords(drawroom, &x1, &y1, &x2, &y2);

						if ((Maps[drawroom].PageNumber == CurFloor)
						        && g_lab->_roomsFound->in(drawroom)
						        && (MouseX >= x1) && (MouseX <= x2)
						        && (MouseY >= y1) && (MouseY <= y2)) {
							CurMsg = drawroom;
						}
					}

					if (OldMsg != CurMsg) {
						if (Rooms[CurMsg].RoomMsg == NULL)
							readViews(CurMsg);

						if ((sptr = Rooms[CurMsg].RoomMsg)) {
							mouseHide();
							setAPen(3);
							rectFill(VGAScaleX(13), VGAScaleY(148), VGAScaleX(135), VGAScaleY(186));
							flowText(MsgFont, 0, 5, 3, true, true, true, true, VGAScaleX(14), VGAScaleY(148), VGAScaleX(134), VGAScaleY(186), sptr);

							if (Maps[OldMsg].PageNumber == CurFloor)
								drawRoom(OldMsg, (bool)(OldMsg == CurRoom));

							roomCords(CurMsg, &x1, &y1, &x2, &y2);
							x1 = (x1 + x2) / 2;
							y1 = (y1 + y2) / 2;

							if ((CurMsg != CurRoom) && (Maps[CurMsg].PageNumber == CurFloor)) {
								setAPen(1);
								rectFill(x1 - 1, y1, x1, y1);
							}

							mouseShow();
						}
					}
				}
			}

			WSDL_UpdateScreen();
		}
	}
}


/*****************************************************************************/
/* Does the map processing.                                                  */
/*****************************************************************************/
void doMap(uint16 CurRoom) {
	FadePalette = AmigaMapPalette;

	g_music->updateMusic();
	loadMapData();
	blackAllScreen();

	if (Direction == NORTH)
		XMark = MapNorth;
	else if (Direction == SOUTH)
		XMark = MapSouth;
	else if (Direction == EAST)
		XMark = MapEast;
	else if (Direction == WEST)
		XMark = MapWest;

	drawMap(CurRoom, CurRoom, Maps[CurRoom].PageNumber, false, true);
	mouseShow();
	attachGadgetList(MapGadgetList);
	WSDL_UpdateScreen();
	processMap(CurRoom);
	attachGadgetList(NULL);
	fade(false, 0);
	blackAllScreen();
	mouseHide();
	setAPen(0);
	rectFill(0, 0, VGAScreenWidth - 1, VGAScreenHeight - 1);
	freeAllStolenMem();
	blackAllScreen();
	mouseShow();
	WSDL_UpdateScreen();
}

} // End of namespace Lab