~case/dbns

ref: 0f9985edf4d2b9e98aaac388d30fd4ab8c4722cf dbns/src/mapout.c -rw-r--r-- 37.8 KiB
0f9985edcase rm extern 10 months ago
                                                                                
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
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
/****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |   \\._.//   *
 * -----------------------------------------------------------|   (0...0)   *
 * SMAUG 1.4 (C) 1994, 1995, 1996, 1998  by Derek Snider      |    ).:.(    *
 * -----------------------------------------------------------|    {o o}    *
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |   / ' ' \   *
 * Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek,      |~'~.VxvxV.~'~*
 * Tricops and Fireblade                                      |             *
 * ------------------------------------------------------------------------ *
 * v. 0.9: 6/19/95:  Converts an ascii map to rooms.                        *
 * v. 1.0: 7/05/95:  Read/write maps to .are files.  Efficient storage.     *
 *	             Room qualities based on map code. Can add & remove rms *
 *	                from a map. (Somewhat) intelligent exit decisions.  *
 * v. 1.1: 7/11/95:  Various display options.  See comments over draw_map   *
 *	                                                                    *
 ****************************************************************************/

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"


/*
 * Useful Externals
 */
extern int      top_exit;
void note_attach( CHAR_DATA *ch );

/*
 * Local defines.  Undef'ed at end of file.
 */

#define MID	MAP_INDEX_DATA
#define MD	MAP_DATA
#define RID	ROOM_INDEX_DATA
#define CD	CHAR_DATA
#define EDD     EXTRA_DESCR_DATA
#define OD      OBJ_DATA
#define OID     OBJ_INDEX_DATA
#define XD      EXIT_DATA

/*
 * Local function prototypes
 */
MID * 		make_new_map_index (int vnum);
void 		map_to_rooms (CD * ch, MID * m_index);
void 		map_stats (CD * ch, int *rooms, int *rows, int *cols);
int     	num_rooms_avail (CD * ch);
int     	add_new_room_to_map (CD * ch, MID * map, int row, int col, int proto_room, char code);
int     	number_to_room_num(int array_index);
int     	char_to_number (char code);
int     	exit_lookup (int vnum1, int vnum2);
void 		draw_map (CD * ch, RID * rm, int flag, int mode);
char   		*you_are_here (int row, int col, char *map);
char            get_map_code( RID *room, int mode );

/*
 * Local Variables & Structs
 */
char    text_map[4150];
extern  MID * first_map;/* should be global */
struct map_stuff {
    int     vnum;
    int     proto_vnum;
    int     exits;
    int     index;
    char    code;
};


/*************************************************************/
/*                                                           */
/* First section for read/write of map to .are files and     */
/*  on-line map editing, such as it is.                      */
/*                                                           */
/*************************************************************/

/*
 * Be careful not to give
 * this an existing map_index
 */
MID * make_new_map_index (int vnum) {
    MID * map_index;
    int     i, j;

    CREATE (map_index, MID, 1);
    map_index -> vnum = vnum;
    for (i = 0; i < 49; i++) {
	for (j = 0; j < 78; j++) {
	    map_index -> map_of_vnums[i][j] = -1;
	}
    }
    map_index -> next = first_map;
    first_map = map_index;
    return map_index;
}

/* 
 * output goes in global text_map 
 *  flag = 0, do a 'you_are_here'
 *  flag = 1, don't
 *
 *
 *  Modes  :  what characters mean :  character set
 *  --------------------------------------------------------------------
 *        0: room code             : 92 ascii chars, detailed elsewhere
 *        1: # of mobs             : 0 thru 9, +
 *        2: # of pc's             : 0 thru 9, +
 *        3: # of objs             : 0 thru 9, +
 *        4: # of exits            : 0 thru 6
 *        5: sectortype            : hex, 0 thru MAX_SECT
 *        6: light                 : 0 or 1 
 *        7: indoors               : X or O
 *        8: death                 : X or O
 *        9: safe                  : X or O
 *       10: nosummon              : X or O
 *       11: # of descr lines      : 0 thru 9, +
 */

char * const map_opts [] = 
{
"code","mobs","pcs","objs","exits","sector","light","indoors","death","safe","nosummon", "descr", "descrlines"
};

char count_lines(char *txt)
{
int i;
char *c, buf[MAX_STRING_LENGTH];

if(!txt)
  return (char) '0';

i=1;
for(c=txt;*c!='\0';c++)
  if (*c == '\n') i++;

if( i  > 9 ) 
    return (char) '+';
sprintf(buf,"%d",i);
return(buf[0]);
}

char get_map_code( RID *room, int mode )
{
   char buf[MAX_STRING_LENGTH];
   CD *mob;
   OD *obj;
   int count/*, i*/; /* Unused */
   EXIT_DATA *pexit;

   if( !room)
     return (char) 'X';

   count = 0;
   switch(mode)
   {
      case 11: return count_lines(room->description);
      case 10: if(xIS_SET(room->room_flags,ROOM_NO_SUMMON)) return (char) 'X';
	       return (char) 'O';
       case 9: if(xIS_SET(room->room_flags,ROOM_SAFE)) return (char) 'X';
	       return (char) 'O';
       case 8: if(xIS_SET(room->room_flags,ROOM_DEATH)) return (char) 'X';
	       return (char) 'O';
       case 7: if(xIS_SET(room->room_flags,ROOM_INDOORS)) return (char) 'X';
	       return (char) 'O';
       case 6: sprintf(buf,"%d",room->light);
	       return(buf[0]);
       case 5: sprintf(buf,"%d",room->sector_type);
	       return(buf[0]);
       case 4: for ( pexit = room->first_exit; pexit; pexit = pexit->next)
		  count++;
	       sprintf(buf,"%d",count);
	       return(buf[0]);
       case 3: for(obj=room->first_content;obj;obj=obj->next_content)
                  count++;
	       if( count  > 9 ) 
		    return (char) '+';
	       sprintf(buf,"%d",count);
	       return(buf[0]);
       case 2: for(mob=room->first_person;mob;mob=mob->next_in_room) {
		  if(!IS_NPC(mob) )
                     count++;
	       }
	       if( count  > 9 ) 
		    return (char) '+';
	       sprintf(buf,"%d",count);
	       return(buf[0]);
       case 1: for(mob=room->first_person;mob;mob=mob->next_in_room) {
		  if(IS_NPC(mob) )
                     count++;
	       }
	       if( count  > 9 ) 
		    return (char) '+';
	       sprintf(buf,"%d",count);
	       return(buf[0]);
       default:
	       if(!room->map) return (char) 'X';
	       return ((char) room->map->entry);
   }
   return (char) '?';
}

void draw_map (CD * ch, RID * rm, int flag, int mode) {
    MID * map_index;
    RID * tmp_rm;
    int     i,
            x,
            y,
            nontriv;

    if (!rm -> map) {
	sprintf (text_map, "(no rm->map)\n\r");
	return;
    }
    if ((map_index = get_map_index (rm -> map -> vnum)) == NULL) {
	bug (" No map_index with vnum %d\n\r", rm -> map -> vnum);
	sprintf (text_map, "-ERROR-\n\r");
	return;
    }
    i = 0;
    nontriv = 0;
    for (y = 0; y < 49; y++) {
	for (x = 0; x < 78; x++) {
	    if (map_index -> map_of_vnums[y][x] < 1) {
		text_map[i] = ' ';
		i++;
		continue;
	    }
	    /* tmp_rm = map_index -> map_of_ptrs[y][x]; */
	    tmp_rm = get_room_index( map_index -> map_of_vnums[y][x] ) ;
	    if (tmp_rm == NULL) {
		text_map[i] = ' ';
		i++;
		continue;
	    }
	    if (!tmp_rm -> map) {
		text_map[i] = ' ';
		i++;
		continue;
	    }

	    /*
	     *  Following's kinda convoluted...  If ch has ansi,
	     *   bold the code of the room he's in.  If not, indicate
	     *   room he's in by '*'
	     */
	    if(flag==1)
	    {
	       if(map_index->map_of_vnums[y][x]==ch->in_room->vnum)
	       {
		  if ( xIS_SET(ch->act, PLR_ANSI) ){
	             text_map[i] = (char) '\x1B';    /* Bold */
		     i++;
	             text_map[i] = (char) '[';
		     i++;
	             text_map[i] = (char) '1';
		     i++;
	             text_map[i] = (char) 'm';
		     i++;
	             /*text_map[i] = (char) tmp_rm -> map -> entry;*/
	             text_map[i] = (char) get_map_code(tmp_rm, mode); 
		     i++;
	             text_map[i] = (char) '\x1B';   /* Normal */
		     i++;
	             text_map[i] = (char) '[';
		     i++;
	             text_map[i] = (char) '0';
		     i++;
	             text_map[i] = (char) 'm';
		     i++;
                     
		  } else {
	             text_map[i] = (char) '*';
		     i++;
                  }
	       } else  {
	           text_map[i] = (char) get_map_code(tmp_rm, mode); 
	           /*text_map[i] = (char) tmp_rm -> map -> entry; */
	           i++;
	       }
            } else {
	       text_map[i] = (char) get_map_code(tmp_rm, mode); 
	       /*text_map[i] = (char) tmp_rm -> map -> entry;*/
	       i++;
            }
	    nontriv = i;
	}
	text_map[i] = '\n';
	i++;
    }
    text_map[nontriv + 2] = '\n';
    text_map[nontriv + 3] = '\r';
    text_map[nontriv + 4] = '\0';
}

MID *
get_map_index (int vnum) {
    MID * map;

    for (map = first_map; map; map = map -> next) {
	if (map -> vnum == vnum)
	    return map;
    }
    return NULL;
}



void 
init_maps () {
    int     i;

/*
    for (map_index = first_map; map_index; map_index = map_index -> next) {

	for (i = 0; i < 49; i++) {
	    for (j = 0; j < 78; j++) {
		   map_index -> map_of_ptrs[i][j] = 
		    get_room_index (map_index -> map_of_vnums[i][j]);
                   
	    }
	}

    }
*/

    for (i = 0; i < 49 * 78; i++)
	text_map[i] = '\0';

    return;
}


/******************************************************************
 * These functions convert maps to rooms
 ******************************************************************/
void map_stats (CD * ch, int *rooms, int *rows, int *cols) {
    int     row,
            col,
            n;
    int     leftmost,
            rightmost;
    char   *l,
            c;

    if (!ch -> pnote) {
	bug ("map_stats: ch->pnote==NULL!", 0);
	return;
    }
    n = 0;
    row = col = 0;
    leftmost = rightmost = 0;

    l = ch -> pnote -> text;
    do {
	c = l[0];
	switch (c) {
	    case '\n': 
		break;
	    case '\r': 
		col = 0;
		row++;
		break;
	    case ' ': 
		col++;
		break;
	}
	if (char_to_number (c) > -1) {
	    if (col < leftmost)
		leftmost = col;
	    if (col > rightmost)
		rightmost = col;
	    col++;
	    n++;
	};
	l++;
    } while (c != '\0');

    *cols = rightmost - leftmost + 1;
    *rows = row;		/* [sic.] */
    *rooms = n;
}

int get_mode( char *type)
{
   int x;

   for( x = 0; x < 12; x++ )
     if( !str_cmp( type, map_opts[x] ) )
          return x;
   return -1;
}

void do_lookmap (CD * ch, char *argument) {
char arg1[MAX_STRING_LENGTH];
char buf[MAX_STRING_LENGTH];
int mode;
   

    if (ch -> in_room -> map) {
	if( ! argument ) { 
	   mode = 0;
        } else {
           argument = one_argument( argument, arg1);
           mode = get_mode( arg1 );
        }

        set_char_color( AT_PLAIN, ch );
        sprintf( buf , ".------[Map %5.5d]-----------------------------------------------------------.\n\r", ch -> in_room -> map -> vnum);
	send_to_char (buf , ch);
	draw_map (ch, ch -> in_room, 1, mode);
	send_to_char (text_map, ch);
	sprintf( buf,"`----------------------------------------------------------------------------'\n\r");
	send_to_char (buf , ch);
    }
    else {
	send_to_char ("You see no map here.\n\r", ch);
    }
    return;
}

void do_mapout (CD * ch, char *argument) {
    char    buf[MAX_STRING_LENGTH];
    char    arg[MAX_INPUT_LENGTH];
    char    arg1[MAX_INPUT_LENGTH];
    char    arg2[MAX_INPUT_LENGTH];
    char    arg3[MAX_INPUT_LENGTH];   /* growl */
    char    arg4[MAX_INPUT_LENGTH];   /* rediculous */
    OD      *map_obj;                 /* an obj made with map as an ed */
    OID     *map_obj_index;           /*    obj_index for previous     */
    EDD     *ed;                      /*    the ed for it to go in     */
    MID     *map_index;               /* the "vnum" of map_index to use*/
    MD      *map, *tmp;               /* for new per-room map info to goin*/
    RID     *this_rm, *tmp_r = NULL;  /* room ch is standing in */
    XD      *tmp_x;                   /* exit data */
    char    code;
    int     rooms,                    
            rows,                     /* ints for stats & looping */
            cols,
	    row,
	    col,
	    mapnum,
	    x,
	    y,
            avail_rooms;

    if (!ch) {
	bug ("do_mapout: null ch", 0);
	return;
    }
    if (IS_NPC (ch)) {
	send_to_char ("Not in mobs.\n\r", ch);
	return;
    }
    if (!ch -> desc) {
	bug ("do_mapout: no descriptor", 0);
	return;
    }
    switch (ch -> substate) {
	default: 
	    break;
	case SUB_WRITING_NOTE: 
	    if (ch -> dest_buf != ch -> pnote)
		bug ("do_mapout: sub_writing_map: ch->dest_buf != ch->pnote", 0);
	    STRFREE (ch -> pnote -> text);
	    ch -> pnote -> text = copy_buffer (ch);
	    stop_editing (ch);
	    return;
    }

    set_char_color (AT_NOTE, ch);
    argument = one_argument (argument, arg);
    smash_tilde (argument);

    if (!str_cmp (arg, "stat")) {
	if (!ch -> pnote) {
	    send_to_char ("You have no map in progress.\n\r", ch);
	    return;
	}
	map_stats (ch, &rooms, &rows, &cols);
	sprintf (buf,
		"Map represents %d rooms, and has %d rows and %d columns\n\r",
		rooms,
		rows,
		cols);
	send_to_char (buf, ch);
	avail_rooms = num_rooms_avail (ch);
	sprintf (buf, "You currently have %d unused rooms.\n\r", avail_rooms);
	send_to_char (buf, ch);

	act (AT_ACTION, "$n glances at an etherial map.", ch, NULL, NULL, TO_ROOM);
	return;
    }


    /*
     *  Adds an existing room to a map
     */
    if (!str_cmp (arg, "continue")) {
       if ( ch->prev_cmd == do_north )
       {
           send_to_char ("Your last command was north.\n\r", ch);
	   argument = one_argument (argument, arg1);

	   if ( arg1[0] == '\0' )
	   {
               code = '#';
	   } else {
               code = arg1[0];     
	   }

	   tmp = NULL;
	   tmp_x = get_exit(ch->in_room, DIR_SOUTH );
	   if ( tmp_x )
	     tmp_r = tmp_x->to_room;
	   if ( tmp_r )
	     tmp = tmp_r->map;
	   if( !tmp )
	   {
                send_to_char("No exit to south, or no map in south room. Aborting. \n\r",ch);
		return;
	   }

	   row = (tmp->y) - 1;
	   col = (tmp->x);

	   if( row < 0) {
                send_to_char("Can't map off the top of the buffer.\n\r",ch);
		return;
	   }
	   if( row >48) {
                send_to_char("Can't map off the bottom of the buffer.\n\r",ch);
		return;
	   }

	   mapnum = tmp->vnum;
	   if( (map_index=get_map_index( mapnum )) ==NULL  )
	   {
	      sprintf ( buf,"Trouble accessing map.(No such map?).\n\r");
              send_to_char (buf, ch);
	      return;
	   }
           sprintf( buf, "addroom %d %d %d %c",mapnum,row,col,code);
	   do_mapout(ch, buf);
	   return;
       }

       if ( ch->prev_cmd == do_east )
       {
           send_to_char ("Your last command started was east\n\r", ch);
	   argument = one_argument (argument, arg1);

	   if ( arg1[0] == '\0' )
	   {
               code = '#';
	   } else {
               code = arg1[0];     
	   }
	   tmp = NULL;
	   tmp_x = get_exit( ch->in_room, DIR_WEST );
	   if ( tmp_x )
	     tmp_r = tmp_x->to_room;
	   if ( tmp_r )
	     tmp = tmp_r->map;

	   if( !tmp )
	   {
                send_to_char("No exit to west, or no map in west room. Aborting. \n\r",ch);
		return;
	   }

	   row = (tmp->y);
	   col = (tmp->x)+1;

	   if( col < 0) {
                send_to_char("Can't map off the left of the buffer.\n\r",ch);
		return;
	   }
	   if( row >78) {
                send_to_char("Can't map off the right of the buffer.\n\r",ch);
		return;
	   }

	   mapnum = tmp->vnum;
	   if( (map_index=get_map_index( mapnum )) ==NULL  )
	   {
	      sprintf ( buf,"Trouble accessing map.(No such map?).\n\r");
              send_to_char (buf, ch);
	      return;
	   }
           sprintf( buf, "addroom %d %d %d %c",mapnum,row,col,code);
	   do_mapout(ch, buf);
	   return;
       }

       if ( ch->prev_cmd == do_south )
       {
           send_to_char ("Your last command was south\n\r", ch);
	   argument = one_argument (argument, arg1);

	   if ( arg1[0] == '\0' )
	   {
               code = '#';
	   } else {
               code = arg1[0];     
	   }
	   tmp = NULL;
	   tmp_x = get_exit( ch->in_room, DIR_NORTH );
	   if ( tmp_x )
	     tmp_r = tmp_x->to_room;
	   if ( tmp_r )
	     tmp = tmp_r->map;

	   if( !tmp )
	   {
                send_to_char("No exit to north, or no map in north room. Aborting. \n\r",ch);
		return;
	   }

	   row = (tmp->y)+1;
	   col = (tmp->x);

	   if( row < 0) {
                send_to_char("Can't map off the top of the buffer.\n\r",ch);
		return;
	   }
	   if( row >48) {
                send_to_char("Can't map off the bottom of the buffer.\n\r",ch);
		return;
	   }

	   mapnum = tmp->vnum;
	   if( (map_index=get_map_index( mapnum )) ==NULL  )
	   {
	      sprintf ( buf,"Trouble accessing map.(No such map?).\n\r");
              send_to_char (buf, ch);
	      return;
	   }
           sprintf( buf, "addroom %d %d %d %c",mapnum,row,col,code);
	   do_mapout(ch, buf);
	   return;
       }

       if ( ch->prev_cmd == do_west )
       {
           send_to_char ("Your last command was west\n\r", ch);
	   argument = one_argument (argument, arg1);

	   if ( arg1[0] == '\0' )
	   {
               code = '#';
	   } else {
               code = arg1[0];     
	   }

	   tmp = NULL;
	   tmp_x = get_exit( ch->in_room, DIR_EAST );
	   if ( tmp_x )
	     tmp_r = tmp_x->to_room;
	   if ( tmp_r )
	     tmp = tmp_r->map;

	   if( !tmp )
	   {
                send_to_char("No exit to east, or no map in east room. Aborting. \n\r",ch);
		return;
	   }

	   row = (tmp->y);
	   col = (tmp->x) - 1;

	   if( col < 0) {
                send_to_char("Can't map off the left of the buffer.\n\r",ch);
		return;
	   }
	   if( row >78) {
                send_to_char("Can't map off the right of the buffer.\n\r",ch);
		return;
	   }

	   mapnum = tmp->vnum;
	   if( (map_index=get_map_index( mapnum )) ==NULL  )
	   {
	      sprintf ( buf,"Trouble accessing map.(No such map?).\n\r");
              send_to_char (buf, ch);
	      return;
	   }
           sprintf( buf, "addroom %d %d %d %c",mapnum,row,col,code);
	   do_mapout(ch, buf);
	   return;
       }

       sprintf (buf, "Your previous command was something I cannot backtrack..\n\r");
       send_to_char (buf,ch);
       return;
    }

    /*
     *  Adds an existing room to a map
     */
    if (!str_cmp (arg, "addroom")) {

        argument = one_argument (argument, arg1);
        argument = one_argument (argument, arg2);
        argument = one_argument (argument, arg3);
        argument = one_argument (argument, arg4);

	mapnum  = atoi ( arg1);   /* i don't like this */
	y 	= atoi ( arg2);
	x 	= atoi ( arg3);

        if ( (arg1[0] == '\0') || (arg2[0] == '\0') || (arg3[0] == '\0') )
	{
          send_to_char("Syntax:                                   \n\r",ch);
          send_to_char("mapout addroom <mapnum> <row> <col> [code]\n\r",ch);
          send_to_char("                                          \n\r",ch);
          send_to_char("where: <mapnum> is the vnum of map to use\n\r",ch);
          send_to_char("       <row> is row of room (start 0)\n\r",ch);
          send_to_char("       <col> is col of room (start 0)\n\r",ch);
          send_to_char("   [code] is optional  room character code \n\r",ch);
            return;
	}

	if ( arg4[0] == '\0' )
	{
            code = '#';
	} else {
            code = arg4[0];     
	}


	if( (map_index=get_map_index( mapnum )) ==NULL  )
	{
#ifdef HURM
	   sprintf ( buf,"Trouble accessing map.(No such map?).\n\r");
           send_to_char (buf, ch);
	   return;
#endif
	    map_index = make_new_map_index ( mapnum);
	    if (map_index == NULL)
	    {
               send_to_char("Could neither find nor make a map index with that number.\n\r", ch);
	       return;
	    }
	}

        this_rm = ch->in_room;
	if(this_rm->map!=NULL)
	{
	   sprintf ( buf,"This room (vnum %d) is already in map %d.\n\r",
						  ch->in_room->vnum,
						  ch->in_room->map->vnum);
           send_to_char (buf, ch);
	   return;
	}

	if(  (x <0 ) || (x >78) )
	{
	   sprintf ( buf,"Bad map x coordinate. Room(vnum %d), x= %d \n\r",
						  ch->in_room->vnum,
						  x);
           send_to_char (buf, ch);
	   return;
	}
	if(  (y <0 ) || (y >48 ) )
	{
	   sprintf ( buf,"Bad map y coordinate. Room(vnum %d), y= %d \n\r",
						  ch->in_room->vnum,
						  y);
           send_to_char (buf, ch);
	   return;
	}
        if(map_index->map_of_vnums[y][x]!=-1)
	{
	   sprintf ( buf,"That (x,y) coordinate (%d, %d) is already taken by room %d.\n\r",
				  x,y, map_index->map_of_vnums[y][x]);
           send_to_char (buf, ch);
	   return;
	}

        /* all error checking done */
        CREATE( map, MAP_DATA, 1);
	map->vnum        = mapnum;
	map->x		 = x;
	map->y		 = y;
	map->entry	 = code;
	ch->in_room->map = map;

        map_index->map_of_vnums[y][x] = ch->in_room->vnum;

        send_to_char ("Added.\n\r", ch);
	return;


    }

    /*
     *  Removes a room from a map
     */
    if (!str_cmp (arg, "removeroom")) {
        this_rm = ch->in_room;
	if(!this_rm->map)
	{
	   sprintf ( buf,"This room (vnum %d) is in no map \n\r",
						  ch->in_room->vnum);
           send_to_char (buf, ch);
	   return;
	}
        
	if(   (map_index=get_map_index(this_rm->map->vnum )) ==NULL  )
	{
	   sprintf ( buf,"Trouble accessing map room(vnum %d), map vnum %d \n\r",
						  ch->in_room->vnum,
						  this_rm->map->vnum);
           send_to_char (buf, ch);
	   return;
	}
	if(  (this_rm->map->x <0 ) || (this_rm->map->x >78) )
	{
	   sprintf ( buf,"Bad map x coordinate. Room(vnum %d), x= %d \n\r",
						  ch->in_room->vnum,
						  this_rm->map->x);
           send_to_char (buf, ch);
	   return;
	}
	if(  (this_rm->map->y <0 ) || (this_rm->map->y >48 ) )
	{
	   sprintf ( buf,"Bad map y coordinate. Room(vnum %d), y= %d \n\r",
						  ch->in_room->vnum,
						  this_rm->map->y);
           send_to_char (buf, ch);
	   return;
	}
	/* now that all that's out of the way.... */
	   sprintf ( buf,"Removing room (vnum %d), from map %d \n\r",
						  ch->in_room->vnum,
						  this_rm->map->vnum);
           send_to_char (buf, ch);

	/* Thanks to Nick Gammon for pointing out x and y being
	   uninitialized.  -Thoric */
	x = this_rm->map->x;
	y = this_rm->map->y;

	map_index->map_of_vnums[y][x]= -1;
	this_rm->map->vnum        = 0;
	this_rm->map->x	 	  = -1;
	this_rm->map->y	 	  = -1;
	this_rm->map->entry 	  = ' ';  
	DISPOSE(this_rm->map);
	this_rm->map = NULL;   /* redundant? */
        send_to_char ("Removed.\n\r", ch);
	return;
    }

    if (!str_cmp (arg, "write")) {
	note_attach (ch);
	ch -> substate = SUB_WRITING_NOTE;
	ch -> dest_buf = ch -> pnote;
	start_editing (ch, ch -> pnote -> text);
	return;
    }
    if (!str_cmp (arg, "clear")) {
	if (ch -> pnote) {
	    STRFREE (ch -> pnote -> text);
	    STRFREE (ch -> pnote -> subject);
	    STRFREE (ch -> pnote -> to_list);
	    STRFREE (ch -> pnote -> date);
	    STRFREE (ch -> pnote -> sender);
	    DISPOSE (ch -> pnote);
	}
	ch -> pnote = NULL;

	send_to_char ("Map cleared.\n\r", ch);
	return;
    }
    if (!str_cmp (arg, "show")) {
	if (!ch -> pnote) {
	    send_to_char ("You have no map in progress.\n\r", ch);
	    return;
	}
	/* send_to_char(buf, ch); */
	send_to_char (ch -> pnote -> text, ch);
	do_mapout (ch, "stat");
	return;
    }
    if (!str_cmp (arg, "redo")) {
	if (!ch -> pnote) {
	    send_to_char ("You have no map in progress.\n\r", ch);
	    return;
	}
	send_to_char ("This option not yet supported.\n\r", ch);
	return;

    }
    if (!str_cmp (arg, "create")) {
	if (!ch -> pnote) {
	    send_to_char ("You have no map in progress.\n\r", ch);
	    return;
	}
	map_stats (ch, &rooms, &rows, &cols);
	avail_rooms = num_rooms_avail (ch);

	/* check for not enough rooms */
	if (rooms > avail_rooms) {
	    send_to_char ("You don't have enough unused rooms allocated!\n\r", ch);
	    return;
	}
	act (AT_ACTION, "$n warps the very dimensions of space!", ch, NULL, NULL, TO_ROOM);

	map_to_rooms (ch, NULL);/* this does the grunt work */

	map_obj_index = get_obj_index (5013);
	if(!map_obj_index)
	{
	    map_obj = create_object (map_obj_index , 0);
	    ed = SetOExtra (map_obj, "runes map scrawls");
	    STRFREE( ed->description );
	    ed -> description = QUICKLINK (ch -> pnote -> text);
	    obj_to_char (map_obj, ch);
	} else {
            send_to_char ("Couldn't give you a map object.  Need Great Eastern Desert\n\r", ch);
            return;
	}

	do_mapout (ch, "clear");
	send_to_char ("Ok.\n\r", ch);
	return;
    }
    send_to_char ("mapout write: create a map in edit buffer.\n\r", ch);
    send_to_char ("mapout stat: get information about a written, but not yet created map.\n\r", ch);
    send_to_char ("mapout clear: clear a written, but not yet created map.\n\r", ch);
    send_to_char ("mapout show: show a written, but not yet created map.\n\r", ch);
    send_to_char ("mapout create: turn a written map into rooms in your assigned room vnum range.\n\r", ch);
    return;
}



int     
add_new_room_to_map(CD *ch,MID *map,int row,int col,int proto_room,char code) {
    int     i;
    char    buf[MAX_STRING_LENGTH];
    RID * location, *rm;


    /* 
     * Get a room to copy from
     */
    rm = get_room_index (proto_room);
    if (!rm)
	rm = ch -> in_room;


    /* 
     * Get an unused room to copy to
     */
    for (i = ch -> pcdata -> r_range_lo; i <= ch -> pcdata -> r_range_hi; i++) {
	if (get_room_index (i) == NULL) {
	    location = make_room (i);
	    if (!location) {
		bug ("next_rooms_avail: make_room failed", 0);
		return - 1;
	    }
	    /* 
	     * Clones current room  (quietly)
	     */
	    location -> area = ch -> pcdata -> area;
	    location -> name = QUICKLINK (rm -> name);
	    location -> description = QUICKLINK (rm -> description);
	    CREATE (location -> map, MAP_DATA, 1);
	    location -> map -> vnum = map -> vnum;   /* not working? */
	    location -> map -> x = col;
	    location -> map -> y = row;
	    location -> map -> entry = code;

//	    location -> room_flags = ROOM_PROTOTYPE && rm -> room_flags;
	    location -> light = rm -> light;
	    location -> sector_type = rm -> sector_type;
	    return i;
	}
    }
    sprintf (buf, "No available room!\n\r");
    send_to_char (buf, ch);
    return - 1;
}

int     num_rooms_avail (CD * ch) {
    int     i,
            n;

    n = 0;
    for (i = ch -> pcdata -> r_range_lo; i <= ch -> pcdata -> r_range_hi; i++)
	if (!get_room_index (i))
	    n++;

    return n;
}

/*
 * This function takes the character string in ch->pnote and
 *  creates rooms laid out in the appropriate configuration.
 */
void map_to_rooms (CD * ch, MID * m_index) {
    struct map_stuff    map[49][78];    /* size of edit buffer */
    int     row,                       
            col,
            i,
            n,
            x,
            y,
            tvnum,
            proto_vnum,
            leftmost,
            rightmost;
    char   *l,
            c;
    RID * newrm;
    MID * map_index = NULL, *tmp;
    XD  * xit;   		/* these are for exits */
    int   exit_type;

    if (!ch -> pnote) {
	bug ("map_to_rooms: ch->pnote==NULL!", 0);
	return;
    }
    n = 0;
    row = col = 0;
    leftmost = rightmost = 0;

    /* 
     * Check to make sure map_index exists.  
     * If not, then make a new one.
     */
    if (!m_index) {		/* Make a new vnum */
	for (i=ch->pcdata->r_range_lo;i<=ch->pcdata->r_range_hi;i++) {
	    if ((tmp = get_map_index (i)) == NULL) {
		map_index = make_new_map_index (i);
		break;
	    }
	}
    }
    else {
	map_index = m_index;
    }

   /*
    *  
    */
    if(!map_index)
    {
	 send_to_char("Couldn't find or make a map_index for you!\n\r",ch);
	 bug("map_to_rooms: Couldn't find or make a map_index\n\r",0);
        /* do something. return failed or somesuch */
    }


    for (x = 0; x < 49; x++) {
	for (y = 0; y < 78; y++) {
	    map[x][y].vnum = 0;
	    map[x][y].proto_vnum = 0;
	    map[x][y].exits = 0;
	    map[x][y].index = 0;
	}
    }
    l = ch -> pnote -> text;
    do {
	c = l[0];
	switch (c) {
	    case '\n': 
		break;
	    case '\r': 
		col = 0;
		row++;
		break;
	    case ' ': 
		col++;
		break;
	}
	if ((map[row][col].index = char_to_number (c)) > -1) {
	    proto_vnum = number_to_room_num (map[row][col].index);
	    map[row][col].vnum = add_new_room_to_map (ch, map_index, row, col, proto_vnum, c);

            map_index->map_of_vnums[row][col] = map[row][col].vnum;
	    map[row][col].proto_vnum = proto_vnum;
	    map[row][col].code = c;
	    col++;
	    n++;

	}
	else {
            map_index->map_of_vnums[row][col] = 0;
	    map[row][col].vnum = 0;
	    map[row][col].exits = 0;
	}

	l++;
    } while (c != '\0');

    for (y = 0; y < row + 1; y++) {/* rows */
	for (x = 0; x < 78; x++) {/* cols (78, i think) */

	    if (map[y][x].vnum == 0)
		continue;

	    newrm = get_room_index (map[y][x].vnum);
	    CREATE (newrm -> map, MAP_DATA, 1);
	    newrm -> map -> vnum = map_index->vnum; 
	    newrm -> map -> x = x;
	    newrm -> map -> y = y;
	    newrm -> map -> entry = map[y][x].code;  

	    /* 
	     * Check north
	     */
	    if (y > 0) {
		if ((tvnum = map[y - 1][x].vnum) != 0) {
		    exit_type = exit_lookup (map[y][x].proto_vnum,
			    map[y - 1][x].proto_vnum);
		    if (exit_type > -1) {
			xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTH );
			xit->keyword  		= STRALLOC( "" );
			xit->description	= STRALLOC( "" );
			xit->key 		= -1;
			xit->exit_info 		= exit_type;
		    }
		}
	    }
	    /* east */
	    if (x < 79) {
		if ((tvnum = map[y][x + 1].vnum) != 0) {
		    exit_type = exit_lookup (map[y][x].proto_vnum,
			    map[y][x + 1].proto_vnum);
		    if (exit_type > -1) {
			xit = make_exit( newrm, get_room_index( tvnum ), DIR_EAST );
			xit->keyword  		= STRALLOC( "" );
			xit->description	= STRALLOC( "" );
			xit->key 		= -1;
			xit->exit_info 		= exit_type;
		    }
		}
	    }
	    /* south */
	    if (y < 48) {
		if ((tvnum = map[y + 1][x].vnum) != 0) {
		    exit_type = exit_lookup (map[y][x].proto_vnum,
			    map[y + 1][x].proto_vnum);
		    if (exit_type > -1) {
			xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTH );
			xit->keyword  		= STRALLOC( "" );
			xit->description	= STRALLOC( "" );
			xit->key 		= -1;
			xit->exit_info 		= exit_type;
		    }
		}
	    }
	    /* west */
	    if (x > 0) {
		if ((tvnum = map[y][x - 1].vnum) != 0) {
		    exit_type = exit_lookup (map[y][x].proto_vnum,
			    map[y][x - 1].proto_vnum);
		    if (exit_type > -1) {
			xit = make_exit( newrm, get_room_index( tvnum ), DIR_WEST );
			xit->keyword  		= STRALLOC( "" );
			xit->description	= STRALLOC( "" );
			xit->key 		= -1;
			xit->exit_info 		= exit_type;
		    }
		}
	    }
	}
    }
}

/******************************************************************
 * Constants & constant-like functions follow
 ******************************************************************/

char   *const standard_room_names[] =
{
    "Hut", "Tent", "Hovel", "Campsite",
    "Shack", "Cabin", "Homested", "Keep",
    "Fortress", "Castle", "GuardHse", "Temple",
    "Store", "Graveyard", "Monastry", "Stable", "Tavern",
    "Basemnt", "Bedroom", "BnquetRm", "Corridor", "Attic",
    "Vault", "SittingRm", "Study", "Passage", "Tower",
    "Crypt", "WorkRoom", "Lab", "Hallway", "Turret",
    "StorRm", "Kitchen", "Larder", "Stairway", "Rooftop",
    "Closet", "Office", "Treasury", "Landing", "Balcony",
    "Foyer", "DrawingRm", "Den", "Ladder", "Catwalk",
    "Entrnce", "Arboretum", "Library", "Vent", "Shaft",
    "Gate", "AudiencRm", "Consrvty", "DumbWatr", "Chimney",
    "Porch", "ClassRoom", "CloakRm", "Lawn", "Garden",
    "Lake", "Forest", "Swamp", "Well", "Street",
    "River", "Canyon", "Beach", "Mine", "Road",
    "Stream", "Clearing", "SnakePit", "Tunnel", "Path",
    "Rapids", "Desert", "SandStrm", "Rope", "Cliff",
    "CaveRiv", "Jungle", "Sandbar", "RopeBrdg", "Bridge",
    "CaveLak", "Cave", "None", "RopeLadr", "NatlBrdg"
};

int     const standard_room_vnums[] =
{
    9500, 9501, 9502, 9503,
    9504, 9505, 9506, 9507,
    9508, 9509, 9510, 9511,
    9512, 9513, 9514, 9515, 9516,
    9517, 9518, 9519, 9520, 9521,
    9522, 9523, 9524, 9525, 9526,
    9527, 9528, 9529, 9530, 9531,
    9532, 9533, 9534, 9535, 9536,
    9537, 9538, 9539, 9540, 9541,
    9542, 9543, 9544, 9545, 9546,
    9547, 9548, 9549, 9550, 9551,
    9552, 9553, 9554, 9555, 9556,
    9557, 9558, 9559, 9560, 9561,
    9562, 9563, 9564, 9565, 9566,
    9567, 9568, 9569, 9570, 9571,
    9572, 9573, 9574, 9575, 9576,
    9577, 9578, 9579, 9580, 9581,
    9582, 9583, 9584, 9585, 9586,
    9587, 9588, 9589, 9590, 9591
};


/*
 *  Picks an entry from standard_room_vnums[], checking
 *   that it's legal
 */
int     
number_to_room_num (int array_index) {
    if      ((array_index < 0) || (array_index > 91))
	        return 2;

    return standard_room_vnums[array_index];
}

/*
 * Attempts to intellignetly determineif two adjecent rooms should
 *  be linked with an exit, and if so, what kind.
 *
 * This fn _depends_ on standard_room_vnums[] to make decisions.
 */
int     exit_lookup (int vnum1, int vnum2) {
    int     sect1,
            sect2;
    ROOM_INDEX_DATA * rm1, *rm2;
    int     exit_flag;

    rm1 = get_room_index (vnum1);
    rm2 = get_room_index (vnum2);

    if ((!rm1) || (!rm2)) {
	bug ("bad room index in exit_lookup!\n\r", 0);
	return (0);
    }
    exit_flag = 0;

    sect1 = rm1 -> sector_type;
    sect2 = rm2 -> sector_type;


    if (rm1 == rm2)		/* adjacent rooms with same std_rm_vnum */
	return 0;		/* assume they're simply linked */

    if ((vnum1 == 9589) || (vnum2 == 9589))
	return 0;		/* if 'none,' no assumptions */



    if ((sect1 == SECT_INSIDE) && (sect2 != SECT_INSIDE)) {
	switch (vnum1) {
	    case 9500: 		/* hut  *//* these are almost always */
	    case 9501: 		/* tent *//* single-roomed buildings */
	    case 9502: 		/* hovel *//* so let them be open on */
	    case 9504: 		/* shack *//* all sides -- user fixes */
	    case 9505: 		/* cabin */
	    case 9506: 		/* homestd */
	    case 9510: 		/* guardhse */
	    case 9511: 		/* temple */
	    case 9512: 		/* store */
	    case 9515: 		/* stable */
	    case 9516: 		/* tavern */
		return 0;
	    case 9542: 		/* foyer *//* these are always closed drs 
				*/
	    case 9547: 		/* entrance */
		return 3;
	    default: 
		exit_flag = -1;
	}
    }
    if ((sect2 == SECT_INSIDE) && (sect1 != SECT_INSIDE)) {
	switch (vnum2) {
	    case 9500: 		/* hut  *//* these are almost always */
	    case 9501: 		/* tent *//* single-roomed buildings */
	    case 9502: 		/* hovel *//* so let them be open on */
	    case 9504: 		/* shack *//* all sides -- user fixes */
	    case 9505: 		/* cabin */
	    case 9506: 		/* homestd */
	    case 9510: 		/* guardhse */
	    case 9511: 		/* temple */
	    case 9512: 		/* store */
	    case 9515: 		/* stable */
	    case 9516: 		/* tavern */
		return 0;
	    case 9542: 		/* foyer *//* these are always closed drs 
				*/
	    case 9547: 		/* entrance */
		return 3;
	    default: 
		exit_flag = -1;
	}
    }
    /* 
     * Can look at these cases again
     * 
     */
    if ((sect1 == SECT_CITY) && (sect2 != SECT_CITY)) {
	switch (vnum1) {
	    case 9511: 		/* temple *//* these are always open */
	    case 9512: 		/* store */
	    case 9516: 		/* tavern */
		return 0;
	    case 9552: 		/* gate *//* these are always closed drs 
				*/
	    case 9547: 
		return 3;
	    default: 
		exit_flag = -1;
	}
    }
    if ((sect2 == SECT_CITY) && (sect1 != SECT_CITY)) {
	switch (vnum2) {
	    case 9511: 		/* temple *//* these are always open */
	    case 9512: 		/* store */
	    case 9516: 		/* tavern */
		return 0;
	    case 9552: 		/* gate *//* these are always closed drs 
				*/
	    case 9547: 
		return 3;
	    default: 
		exit_flag = -1;
	}
    }
    return exit_flag;
}

/*
 *  Given a character 'code' in a map, returns the location
 *   of the corresponding room vnum in the constant array
 *   standard_room_vnums.  If 'code' is illegal, it returns
 *   -1.  To lookup the corresponding room vnum, call
 *   number_to_room_num on value returned here.
 */
int     
char_to_number (char code) {

    switch  (code) {
	case    'a': 
	            return 0;
	case 'b': 
	    return 1;
	case 'c': 
	    return 2;
	case 'd': 
	    return 3;
	case 'e': 
	    return 4;
	case 'f': 
	    return 5;
	case 'g': 
	    return 6;
	case 'h': 
	    return 7;
	case 'i': 
	    return 8;
	case 'j': 
	    return 9;
	case 'k': 
	    return 10;
	case 'l': 
	    return 11;
	case 'm': 
	    return 12;
	case 'n': 
	    return 13;
	case 'o': 
	    return 14;
	case 'p': 
	    return 15;
	case 'q': 
	    return 16;
	case 'r': 
	    return 17;
	case 's': 
	    return 18;
	case 't': 
	    return 19;
	case 'u': 
	    return 20;
	case 'v': 
	    return 21;
	case 'w': 
	    return 22;
	case 'x': 
	    return 23;
	case 'y': 
	    return 24;
	case 'z': 
	    return 25;
	case 'A': 
	    return 26;
	case 'B': 
	    return 27;
	case 'C': 
	    return 28;
	case 'D': 
	    return 29;
	case 'E': 
	    return 30;
	case 'F': 
	    return 31;
	case 'G': 
	    return 32;
	case 'H': 
	    return 33;
	case 'I': 
	    return 34;
	case 'J': 
	    return 35;
	case 'K': 
	    return 36;
	case 'L': 
	    return 37;
	case 'M': 
	    return 38;
	case 'N': 
	    return 39;
	case 'O': 
	    return 40;
	case 'P': 
	    return 41;
	case 'Q': 
	    return 42;
	case 'R': 
	    return 43;
	case 'S': 
	    return 44;
	case 'T': 
	    return 45;
	case 'U': 
	    return 46;
	case 'V': 
	    return 47;
	case 'W': 
	    return 48;
	case 'X': 
	    return 49;
	case 'Y': 
	    return 50;
	case 'Z': 
	    return 51;
	case '0': 
	    return 52;
	case '1': 
	    return 53;
	case '2': 
	    return 54;
	case '3': 
	    return 55;
	case '4': 
	    return 56;
	case '5': 
	    return 57;
	case '6': 
	    return 58;
	case '7': 
	    return 59;
	case '8': 
	    return 60;
	case '9': 
	    return 61;
	case '!': 
	    return 62;
	case '@': 
	    return 63;
	case '#': 
	    return 64;
	case '$': 
	    return 65;
	case '%': 
	    return 66;
	case '^': 
	    return 67;
	case '&': 
	    return 68;
	case '*': 
	    return 69;
	case '(': 
	    return 70;
	case ')': 
	    return 71;

	case '-': 
	    return 72;
	case '_': 
	    return 73;
	case '+': 
	    return 74;
	case '=': 
	    return 75;
	case '|': 
	    return 76;

	    /* case '\\': return 77; */
	    /* case '~': return 78; */
	case '`': 
	    return 79;
	case '{': 
	    return 80;
	case '[': 
	    return 81;

	case '}': 
	    return 82;
	case ']': 
	    return 83;
	case ':': 
	    return 84;
	case '"': 
	    return 85;
	case '\'': 
	    return 86;

	case '<': 
	    return 87;
	case ',': 
	    return 88;
	case '>': 
	    return 89;
	case '.': 
	    return 90;
	case '?': 
	    return 91;
	default: 
	    return - 1;
    }
}

#undef MID	
#undef MD	
#undef RID	
#undef CD	
#undef EDD
#undef OD  
#undef OID  
#undef XD