~case/dbns

ref: 0f9985edf4d2b9e98aaac388d30fd4ab8c4722cf dbns/src/act_move.c -rw-r--r-- 67.5 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
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
/****************************************************************************
* [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                                      |             *
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
* Chastain, Michael Quan, and Mitchell Tse.                                *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
* ------------------------------------------------------------------------ *
*			   Player movement module			    *
****************************************************************************/


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



const sh_int movement_loss[SECT_MAX] =
{
	1, 2, 2, 3, 4, 6, 4, 1, 6, 10, 6, 5, 7, 4
};

char   *const dir_name[] =
{
	"north", "east", "south", "west", "up", "down",
	"northeast", "northwest", "southeast", "southwest", "somewhere"
};

const int trap_door[] =
{
	TRAP_N, TRAP_E, TRAP_S, TRAP_W, TRAP_U, TRAP_D,
	TRAP_NE, TRAP_NW, TRAP_SE, TRAP_SW
};


const sh_int rev_dir[] =
{
	2, 3, 0, 1, 5, 4, 9, 8, 7, 6, 10
};


ROOM_INDEX_DATA *vroom_hash[64];


/*
 * Local functions.
 */
OBJ_DATA *has_key args((CHAR_DATA * ch, int key));


char   *const sect_names[SECT_MAX][2] =
{
	{"In a room", "inside"
	}
	,{"In a city", "cities"},
	{"In a field", "fields"}, {"In a forest", "forests"},
	{"hill", "hills"}, {"On a mountain", "mountains"},
	{"In the water", "waters"}, {"In rough water", "waters"},
	{"Underwater", "underwaters"}, {"In the air", "air"},
	{"In a desert", "deserts"}, {"Somewhere", "unknown"},
	{"ocean floor", "ocean floor"}, {"underground", "underground"}
};


const int sent_total[SECT_MAX] =
{
	3, 5, 4, 4, 1, 1, 1, 1, 1, 2, 2, 25, 1, 1
};

char   *const room_sents[SECT_MAX][25] =
{
	{
		"rough hewn walls of granite with the occasional spider crawling around",
		"signs of a recent battle from the bloodstains on the floor",
		"a damp musty odour not unlike rotting vegetation"
	},

	{
		"the occasional stray digging through some garbage",
		"merchants trying to lure customers to their tents",
		"some street people putting on an interesting display of talent",
		"an argument between a customer and a merchant about the price of an item",
		"several shady figures talking down a dark alleyway"
	},

	{
		"sparce patches of brush and shrubs",
		"a small cluster of trees far off in the distance",
		"grassy fields as far as the eye can see",
		"a wide variety of weeds and wildflowers"
	},

	{
		"tall, dark evergreens prevent you from seeing very far",
		"many huge oak trees that look several hundred years old",
		"a solitary lonely weeping willow",
		"a patch of bright white birch trees slender and tall"
	},

	{
		"rolling hills lightly speckled with violet wildflowers"
	},

	{
		"the rocky mountain pass offers many hiding places"
	},

	{
		"the water is smooth as glass"
	},

	{
		"rough waves splash about angrily"
	},

	{
		"a small school of fish"
	},

	{
		"the land far below",
		"a misty haze of clouds"
	},

	{
		"sand as far as the eye can see",
		"an oasis far in the distance"
	},

	{
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual", "nothing unusual", "nothing unusual",
		"nothing unusual",
	},

	{
		"rocks and coral which litter the ocean floor."
	},

	{
		"a lengthy tunnel of rock."
	}

};

char       *
grab_word(char *argument, char *arg_first)
{
	char cEnd;
	sh_int count;

	count = 0;

	while (isspace(*argument))
		argument++;

	cEnd = ' ';
	if (*argument == '\'' || *argument == '"')
		cEnd = *argument++;

	while (*argument != '\0' || ++count >= 255) {
		if (*argument == cEnd) {
			argument++;
			break;
		}
		*arg_first++ = *argument++;
	}
	*arg_first = '\0';

	while (isspace(*argument))
		argument++;

	return (argument);
}

bool
has_exits(ROOM_INDEX_DATA * room)
{
	EXIT_DATA *e;
	int count = 0;

	for (e = room->first_exit; e; e = e->next)
		count++;

	if (count > 0)
		return (true);
	else
		return (false);

}

char     *
wordwrap(char *txt, sh_int wrap)
{
	static char buf[MAX_STRING_LENGTH];
	char *bufp;

	buf[0] = '\0';
	bufp = buf;
	if (txt != NULL) {
		char line[MAX_STRING_LENGTH];
		char temp[MAX_STRING_LENGTH];
		char *ptr, *p;
		int ln, x;

		++bufp;
		line[0] = '\0';
		ptr = txt;
		while (*ptr) {
			ptr = grab_word(ptr, temp);
			ln = strlen(line);
			x = strlen(temp);
			if ((ln + x + 1) < wrap) {
				if (ln > 0 && line[ln - 1] == '.')
					strcat(line, "  ");
				else
					strcat(line, " ");
				strcat(line, temp);
				p = strchr(line, '\n');
				if (!p)
					p = strchr(line, '\r');
				if (p) {
					strcat(buf, line);
					line[0] = '\0';
				}
			} else {
				strcat(line, "\r\n");
				strcat(buf, line);
				strcpy(line, temp);
			}
		}
		if (line[0] != '\0')
			strcat(buf, line);
	}
	return (bufp);
}

void
decorate_room(ROOM_INDEX_DATA * room)
{
	char buf[MAX_STRING_LENGTH];
	char buf2[MAX_STRING_LENGTH];
	int nRand;
	int iRand, len;
	int previous[8];
	int sector = room->sector_type;
	char *pre = "You notice ", *post = ".";

	if (room->name)
		STRFREE(room->name);
	if (room->description)
		STRFREE(room->description);

	room->name = STRALLOC("In a virtual room");
	room->description = STRALLOC("You're on a pathway.\n\r");

	return;				/* Return (with above till I can figure)
					 * out what is wrong with it.
					 * --Shaddai */
	room->name = STRALLOC(sect_names[sector][0]);
	buf[0] = '\0';
	nRand = number_range(1, UMIN(8, sent_total[sector]));

	for (iRand = 0; iRand < nRand; iRand++)
		previous[iRand] = -1;

	for (iRand = 0; iRand < nRand; iRand++) {
		while (previous[iRand] == -1) {
			int x, z;

			x = number_range(0, sent_total[sector] - 1);

			for (z = 0; z < iRand; z++)
				if (previous[z] == x)
					break;

			if (z < iRand)
				continue;

			previous[iRand] = x;

			len = strlen(buf);
			if (len == 0) {
			  switch (number_range(1, (2 * (iRand == nRand - 1)) ? 1 : 2)) {
				case 1:
					pre = "You notice ";
					post = ".";
					break;
				case 2:
					pre = "You see ";
					post = ".";
					break;
				case 3:
					pre = "You see ";
					post = ", and ";
					break;
				case 4:
					pre = "You notice ";
					post = ", and ";
					break;
				}
				sprintf(buf2, "%s%s%s", pre, room_sents[sector][x], post);
			} else if (iRand != nRand - 1) {
				if (buf[len - 1] == '.')
					switch (number_range(0, 3)) {
					case 0:
						pre = "you notice ";
						post = ".";
						break;
					case 1:
						pre = "you see ";
						post = ", and ";
						break;
					case 2:
						pre = "you see ";
						post = ".";
						break;
					case 3:
						pre = "over yonder ";
						post = ", and ";
						break;
					}
				else
					switch (number_range(0, 3)) {
					case 0:
						pre = "";
						post = ".";
						break;
					case 1:
						pre = "";
						post = " not too far away.";
						break;
					case 2:
						pre = "";
						post = ", and ";
						break;
					case 3:
						pre = "";
						post = " nearby.";
						break;
					}
				sprintf(buf2, "%s%s%s", pre, room_sents[sector][x], post);
			} else
				sprintf(buf2, "%s.", room_sents[sector][x]);
			if (len > 5 && buf[len - 1] == '.') {
				strcat(buf, "  ");
				buf2[0] = UPPER(buf2[0]);
			} else if (len == 0)
				buf2[0] = UPPER(buf2[0]);
			strcat(buf, buf2);
		}
	}
	/*
	 * Below is the line that causes the uninitialized memory read
	 * --Shaddai
	 */
	sprintf(buf2, "%s\n\r", wordwrap(buf, 78));
	room->description = STRALLOC(buf2);
}

/*
 * Remove any unused virtual rooms				-Thoric
 */
void 
clear_vrooms()
{
	int hash;
	ROOM_INDEX_DATA *room, *room_next, *prev;

	for (hash = 0; hash < 64; hash++) {
		while (vroom_hash[hash]
		    && !vroom_hash[hash]->first_person
		    && !vroom_hash[hash]->first_content) {
			room = vroom_hash[hash];
			vroom_hash[hash] = room->next;
			clean_room(room);
			DISPOSE(room);
			--top_vroom;
		}
		prev = NULL;
		for (room = vroom_hash[hash]; room; room = room_next) {
			room_next = room->next;
			if (!room->first_person && !room->first_content) {
				if (prev)
					prev->next = room_next;
				clean_room(room);
				DISPOSE(room);
				--top_vroom;
			}
			if (room)
				prev = room;
		}
	}
}

char   *
rev_exit(sh_int vdir)
{
	switch (vdir) {
	default:
		return ("somewhere");
	case 0:
		return ("the south");
	case 1:
		return ("the west");
	case 2:
		return ("the north");
	case 3:
		return ("the east");
	case 4:
		return ("below");
	case 5:
		return ("above");
	case 6:
		return ("the southwest");
	case 7:
		return ("the southeast");
	case 8:
		return ("the northwest");
	case 9:
		return ("the northeast");
	}

	return ("<BUG: NOTIFY GOKU>");
}

/*
 * Function to get the equivelant exit of DIR 0-MAXDIR out of linked list.
 * Made to allow old-style diku-merc exit functions to work.	-Thoric
 */
EXIT_DATA *
get_exit(ROOM_INDEX_DATA * room, sh_int dir)
{
	EXIT_DATA *xit;

	if (!room) {
		bug("Get_exit: NULL room", 0);
		return (NULL);
	}
	for (xit = room->first_exit; xit; xit = xit->next)
		if (xit->vdir == dir)
			return (xit);
	return (NULL);
}

/*
 * Function to get an exit, leading the the specified room
 */
EXIT_DATA *
get_exit_to(ROOM_INDEX_DATA * room, sh_int dir, int vnum)
{
	EXIT_DATA *xit;

	if (!room) {
		bug("Get_exit: NULL room", 0);
		return (NULL);
	}
	for (xit = room->first_exit; xit; xit = xit->next)
		if (xit->vdir == dir && xit->vnum == vnum)
			return (xit);
	return (NULL);
}

/*
 * Function to get the nth exit of a room			-Thoric
 */
EXIT_DATA *
get_exit_num(ROOM_INDEX_DATA * room, sh_int count)
{
	EXIT_DATA *xit;
	int cnt;

	if (!room) {
		bug("Get_exit: NULL room", 0);
		return (NULL);
	}
	for (cnt = 0, xit = room->first_exit; xit; xit = xit->next)
		if (++cnt == count)
			return (xit);
	return (NULL);
}


/*
 * Modify movement due to encumbrance				-Thoric
 */
sh_int 
encumbrance(CHAR_DATA * ch, sh_int move)
{
	int cur, max;

	max = can_carry_w(ch);
	cur = ch->carry_weight;
	if (cur >= max)
		return (move * 4);
	else if (cur >= max * 0.95)
		return (move * 3.5);
	else if (cur >= max * 0.90)
		return (move * 3);
	else if (cur >= max * 0.85)
		return (move * 2.5);
	else if (cur >= max * 0.80)
		return (move * 2);
	else if (cur >= max * 0.75)
		return (move * 1.5);
	else
		return (move);
}


/*
 * Check to see if a character can fall down, checks for looping   -Thoric
 */
bool 
will_fall(CHAR_DATA * ch, int fall)
{
	if (xIS_SET(ch->in_room->room_flags, ROOM_NOFLOOR)
	    && CAN_GO(ch, DIR_DOWN)
	    && (!IS_AFFECTED(ch, AFF_FLYING)
	    || (ch->mount && !IS_AFFECTED(ch->mount, AFF_FLYING)))) {
		if (fall > 80) {
			bug("Falling (in a loop?) more than 80 rooms: vnum %d", ch->in_room->vnum);
			char_from_room(ch);
			char_to_room(ch, get_room_index(ROOM_VNUM_TEMPLE));
			fall = 0;
			return (true);
		}
		set_char_color(AT_FALLING, ch);
		send_to_char("You're falling down...\n\r", ch);
		move_char(ch, get_exit(ch->in_room, DIR_DOWN), ++fall);
		return (true);
	}
	return (false);
}


/*
 * create a 'virtual' room					-Thoric
 */
ROOM_INDEX_DATA *
generate_exit(ROOM_INDEX_DATA * in_room, EXIT_DATA ** pexit)
{
	EXIT_DATA *xit, *bxit;
	EXIT_DATA *orig_exit = (EXIT_DATA *) * pexit;
	ROOM_INDEX_DATA *room, *backroom;
	int brvnum;
	int serial;
	int roomnum;
	int distance = -1;
	int vdir = orig_exit->vdir;
	sh_int hash;
	bool found = false;

	if (in_room->vnum > MAX_VNUMS) {/* room is virtual */
		serial = in_room->vnum;
		roomnum = in_room->tele_vnum;
		if ((serial & MAX_VNUMS) == orig_exit->vnum) {
			brvnum = serial >> 16;
			--roomnum;
			distance = roomnum;
		} else {
			brvnum = serial & MAX_VNUMS;
			++roomnum;
			distance = orig_exit->distance - 1;
		}
		backroom = get_room_index(brvnum);
	} else {
		int r1 = in_room->vnum;
		int r2 = orig_exit->vnum;

		brvnum = r1;
		backroom = in_room;
		serial = (UMAX(r1, r2) << 16) | UMIN(r1, r2);
		distance = orig_exit->distance - 1;
		roomnum = r1 < r2 ? 1 : distance;
	}
	hash = serial % 64;

	for (room = vroom_hash[hash]; room; room = room->next)
		if (room->vnum == serial && room->tele_vnum == roomnum) {
			found = true;
			break;
		}
	if (!found) {
		CREATE(room, ROOM_INDEX_DATA, 1);
		room->area = in_room->area;
		room->vnum = serial;
		room->tele_vnum = roomnum;
		room->sector_type = in_room->sector_type;
		room->room_flags = in_room->room_flags;
		decorate_room(room);
		room->next = vroom_hash[hash];
		vroom_hash[hash] = room;
		++top_vroom;
	}
	if (!found || (xit = get_exit(room, vdir)) == NULL) {
		xit = make_exit(room, orig_exit->to_room, vdir);
		xit->keyword = STRALLOC("");
		xit->description = STRALLOC("");
		xit->key = -1;
		xit->distance = distance;
	}
	if (!found) {
		bxit = make_exit(room, backroom, rev_dir[vdir]);
		bxit->keyword = STRALLOC("");
		bxit->description = STRALLOC("");
		bxit->key = -1;
		if ((serial & MAX_VNUMS) != orig_exit->vnum)
			bxit->distance = roomnum;
		else {
			EXIT_DATA *tmp = get_exit(backroom, vdir);
			int fulldist = tmp->distance;

			bxit->distance = fulldist - distance;
		}
	}
	*pexit = xit;
	return (room);
}

ch_ret 
move_char(CHAR_DATA * ch, EXIT_DATA * pexit, int fall)
{
	ROOM_INDEX_DATA *in_room;
	ROOM_INDEX_DATA *to_room;
	ROOM_INDEX_DATA *from_room;
	OBJ_DATA *boat;
	char buf[MAX_STRING_LENGTH];
	char *txt;
	char *dtxt;
	ch_ret retcode;
	sh_int door, distance;
	bool drunk = false;
	bool nuisance = false;
	bool brief = false;

	if (!IS_NPC(ch)) {
		if (IS_DRUNK(ch, 2) && (ch->position != POS_SHOVE)
		    && (ch->position != POS_DRAG))
			drunk = true;

		/*
		 * Nuisance flag, makes them walk in random directions 50%
		 * of the time -Shaddai
		 */

		if (ch->pcdata->nuisance && ch->pcdata->nuisance->flags > 8 &&
		    (ch->position != POS_SHOVE) && (ch->position != POS_DRAG) &&
		    number_percent() > (ch->pcdata->nuisance->flags * ch->pcdata->nuisance->power))
			nuisance = true;
	}
	if ((nuisance || drunk) && !fall) {
		door = number_door();
		pexit = get_exit(ch->in_room, door);
	}
#ifdef DEBUG
	if (pexit) {
		sprintf(buf, "move_char: %s to door %d", ch->name, pexit->vdir);
		log_string(buf);
	}
#endif

	retcode = rNONE;
	txt = NULL;

	if (IS_NPC(ch) && xIS_SET(ch->act, ACT_MOUNTED))
		return (retcode);

	in_room = ch->in_room;
	from_room = in_room;
	if (pexit)
		to_room = pexit->to_room;
		if (!pexit || !to_room) {
			if (drunk && ch->position != POS_MOUNTED
			    && ch->in_room->sector_type != SECT_WATER_SWIM
			    && ch->in_room->sector_type != SECT_WATER_NOSWIM
			    && ch->in_room->sector_type != SECT_UNDERWATER
			    && ch->in_room->sector_type != SECT_OCEANFLOOR
			    && ch->in_room->sector_type != SECT_SPACE) {
				switch (number_bits(4)) {
				default:
					act(AT_ACTION, "You drunkenly stumble into some obstacle.", ch, NULL, NULL, TO_CHAR);
					act(AT_ACTION, "$n drunkenly stumbles into a nearby obstacle.", ch, NULL, NULL, TO_ROOM);
					break;
				case 3:
					act(AT_ACTION, "In your drunken stupor you trip over your own feet and tumble to the ground.", ch, NULL, NULL, TO_CHAR);
					act(AT_ACTION, "$n stumbles drunkenly, trips and tumbles to the ground.", ch, NULL, NULL, TO_ROOM);
					ch->position = POS_RESTING;
					break;
				case 4:
					act(AT_SOCIAL, "You utter a string of slurred obscenities.", ch, NULL, NULL, TO_CHAR);
					act(AT_ACTION, "Something blurry and immovable has intercepted you as you stagger along.", ch, NULL, NULL, TO_CHAR);
					act(AT_HURT, "Oh geez... THAT really hurt.  Everything slowly goes dark and numb...", ch, NULL, NULL, TO_CHAR);
					act(AT_ACTION, "$n drunkenly staggers into something.", ch, NULL, NULL, TO_ROOM);
					act(AT_SOCIAL, "$n utters a string of slurred obscenities: @*&^%@*&!", ch, NULL, NULL, TO_ROOM);
					act(AT_ACTION, "$n topples to the ground with a thud.", ch, NULL, NULL, TO_ROOM);
					ch->position = POS_INCAP;
					break;
				}
			} else if (nuisance)
				act(AT_ACTION, "You stare around trying to remember where you where going.", ch, NULL, NULL, TO_CHAR);
			else if (drunk)
				act(AT_ACTION, "You stare around trying to make sense of things through your drunken stupor.", ch, NULL, NULL, TO_CHAR);
			else
				send_to_char("Alas, you cannot go that way.\n\r", ch);
			return (rNONE);
		}
	door = pexit->vdir;
	distance = pexit->distance;

	/*
	 * Exit is only a "window", there is no way to travel in that direction
	 * unless it's a door with a window in it		-Thoric
	 */
	if (IS_SET(pexit->exit_info, EX_WINDOW)
	    && !IS_SET(pexit->exit_info, EX_ISDOOR)) {
		send_to_char("Alas, you cannot go that way.\n\r", ch);
		return (rNONE);
	}
	if (IS_SET(pexit->exit_info, EX_PORTAL)
	    && IS_NPC(ch)) {
		act(AT_PLAIN, "Mobs can't use portals.", ch, NULL, NULL, TO_CHAR);
		return (rNONE);
	}
	if (IS_SET(pexit->exit_info, EX_NOMOB)
	    && IS_NPC(ch) && !is_split(ch)) {
		act(AT_PLAIN, "Mobs can't enter there.", ch, NULL, NULL, TO_CHAR);
		return (rNONE);
	}
	if (IS_SET(pexit->exit_info, EX_CLOSED)
	    && (!IS_AFFECTED(ch, AFF_PASS_DOOR)
	    || IS_SET(pexit->exit_info, EX_NOPASSDOOR))) {
		if (!IS_SET(pexit->exit_info, EX_SECRET)
		    && !IS_SET(pexit->exit_info, EX_DIG)) {
			if (drunk) {
				act(AT_PLAIN, "$n runs into the $d in $s drunken state.", ch,
				    NULL, pexit->keyword, TO_ROOM);
				act(AT_PLAIN, "You run into the $d in your drunken state.", ch,
				    NULL, pexit->keyword, TO_CHAR);
			} else
				act(AT_PLAIN, "The $d is closed.", ch, NULL, pexit->keyword, TO_CHAR);
		} else {
			if (drunk)
				send_to_char("You stagger around in your drunken state.\n\r", ch);
			else
				send_to_char("Alas, you cannot go that way.\n\r", ch);
		}

		return (rNONE);
	}
	/*
	 * Crazy virtual room idea, created upon demand.		-Thoric
	 */
	if (distance > 1)
		if ((to_room = generate_exit(in_room, &pexit)) == NULL)
			send_to_char("Alas, you cannot go that way.\n\r", ch);

	if (!fall
	    && IS_AFFECTED(ch, AFF_CHARM)
	    && ch->master
	    && in_room == ch->master->in_room) {
		send_to_char("What?  And leave your beloved master?\n\r", ch);
		return (rNONE);
	}
	if (room_is_private(to_room)) {
		send_to_char("That room is private right now.\n\r", ch);
		return (rNONE);
	}
	if (room_is_dnd(ch, to_room)) {
		send_to_char("That room is \"do not disturb\" right now.\n\r", ch);
		return (rNONE);
	}
	if (room_HBTC_check(ch, to_room)) {
		char sbuf[MAX_STRING_LENGTH];

		sprintf(sbuf, "You can't enter there until: %24.24s.\n\r",
		    ctime(&ch->pcdata->nextHBTCDate));
		send_to_char(sbuf, ch);
		return (rNONE);
	}
	if (room_HBTC_not_partner(ch, to_room)) {
		send_to_char("The person in there is not designated as your partner "
		    "for the Time Chamber.\n\r", ch);
		return (rNONE);
	}
	if (!IS_IMMORTAL(ch)
	    && !IS_NPC(ch)
	    && ch->in_room->area != to_room->area) {
		if (ch->level < to_room->area->low_hard_range) {
			set_char_color(AT_TELL, ch);
			switch (to_room->area->low_hard_range - ch->level) {
			case 1:
				send_to_char("A voice in your mind says, 'You are nearly ready to go that way...'", ch);
				break;
			case 2:
				send_to_char("A voice in your mind says, 'Soon you shall be ready to travel down this path... soon.'", ch);
				break;
			case 3:
				send_to_char("A voice in your mind says, 'You are not ready to go down that path... yet.'.\n\r", ch);
				break;
			default:
				send_to_char("A voice in your mind says, 'You are not ready to go down that path.'.\n\r", ch);
			}
			return (rNONE);
		} else if (ch->level > to_room->area->hi_hard_range) {
			set_char_color(AT_TELL, ch);
			send_to_char("A voice in your mind says, 'There is nothing more for you down that path.'", ch);
			return (rNONE);
		}
	}
	if (!fall && !IS_NPC(ch)) {
		/*
		 * Prevent deadlies from entering a nopkill-flagged area
		 * from a non-flagged area, but allow them to move around if
		 * already inside a nopkill area. - Blodkai
		 * 
		 * 
		 * if (  IS_SET( to_room->area->flags, AFLAG_NOPKILL ) &&
		 * !IS_SET( ch->in_room->area->flags, AFLAG_NOPKILL ) && (
		 * IS_PKILL (ch) && !IS_IMMORTAL (ch) ) ) { set_char_color(
		 * AT_MAGIC, ch ); send_to_char( "\n\rA godly force forbids
		 * deadly characters from entering that area...\n\r", ch);
		 * return (rNONE; })
		 */
		if (in_room->sector_type == SECT_AIR
		    || in_room->sector_type == SECT_SPACE
		    || to_room->sector_type == SECT_AIR
		    || to_room->sector_type == SECT_SPACE
		    || IS_SET(pexit->exit_info, EX_FLY)) {
			if (ch->mount && !IS_AFFECTED(ch->mount, AFF_FLYING)) {
				send_to_char("Your mount can't fly.\n\r", ch);
				return (rNONE);
			}
			if (!ch->mount && !IS_AFFECTED(ch, AFF_FLYING)) {
				send_to_char("You'd need to fly to go there.\n\r", ch);
				return (rNONE);
			}
		}
		if (in_room->sector_type == SECT_WATER_NOSWIM
		    || to_room->sector_type == SECT_WATER_NOSWIM) {
			if ((ch->mount && !IS_FLOATING(ch->mount)) || !IS_FLOATING(ch)) {
				/*
				 * Look for a boat.
				 * We can use the boat obj for a more detailed description.
				 */
				if ((boat = get_objtype(ch, ITEM_BOAT)) != NULL) {
					if (drunk)
						txt = "paddles unevenly";
					else
						txt = "paddles";
				} else {
					if (ch->mount)
						send_to_char("Your mount would drown!\n\r", ch);
					else
						send_to_char("You'd need a boat to go there.\n\r", ch);
					return (rNONE);
				}
			}
		}
		if (IS_SET(pexit->exit_info, EX_CLIMB)) {
			bool found;

			found = false;
			if (ch->mount && IS_AFFECTED(ch->mount, AFF_FLYING))
				found = true;
			else if (IS_AFFECTED(ch, AFF_FLYING))
				found = true;

			if (!found && !ch->mount) {
				if ((!IS_NPC(ch) && number_percent() > LEARNED(ch, gsn_climb))
				    || drunk || ch->mental_state < -90) {
					send_to_char("You start to climb... but lose your grip and fall!\n\r", ch);
					learn_from_failure(ch, gsn_climb);
					if (pexit->vdir == DIR_DOWN) {
						retcode = move_char(ch, pexit, 1);
						return (retcode);
					}
					set_char_color(AT_HURT, ch);
					send_to_char("OUCH! You hit the ground!\n\r", ch);
					WAIT_STATE(ch, 20);
					retcode = damage(ch, ch, (pexit->vdir == DIR_UP ? 10 : 5),
					    TYPE_UNDEFINED);
					return (retcode);
				}
				found = true;
				learn_from_success(ch, gsn_climb);
				WAIT_STATE(ch, skill_table[gsn_climb]->beats);
				txt = "climbs";
			}
			if (!found) {
				send_to_char("You can't climb.\n\r", ch);
				return (rNONE);
			}
		}
		if (ch->mount) {
			switch (ch->mount->position) {
			case POS_DEAD:
				send_to_char("Your mount is dead!\n\r", ch);
				return (rNONE);
				break;

			case POS_MORTAL:
			case POS_INCAP:
				send_to_char("Your mount is hurt far too badly to move.\n\r", ch);
				return (rNONE);
				break;

			case POS_STUNNED:
				send_to_char("Your mount is too stunned to do that.\n\r", ch);
				return (rNONE);
				break;

			case POS_SLEEPING:
				send_to_char("Your mount is sleeping.\n\r", ch);
				return (rNONE);
				break;

			case POS_RESTING:
				send_to_char("Your mount is resting.\n\r", ch);
				return (rNONE);
				break;

			case POS_SITTING:
				send_to_char("Your mount is sitting down.\n\r", ch);
				return (rNONE);
				break;

			default:
				break;
			}
		}
	}
	/* Check if player can fit in the room */
	if (to_room->tunnel > 0) {
		CHAR_DATA *ctmp;
		int count = ch->mount ? 1 : 0;

		for (ctmp = to_room->first_person; ctmp; ctmp = ctmp->next_in_room)
			if (++count >= to_room->tunnel) {
				if (ch->mount && count == to_room->tunnel)
					send_to_char("There is no room for both you and your mount there.\n\r", ch);
				else
					send_to_char("There is no room for you there.\n\r", ch);
				return (rNONE);
			}
	}
	/* check for traps on exit - later */
	if (!IS_AFFECTED(ch, AFF_SNEAK)
	    && (IS_NPC(ch) || !xIS_SET(ch->act, PLR_WIZINVIS))) {
		if (fall)
			txt = "falls";
		else if (!txt) {
			if (ch->mount) {
				if (IS_AFFECTED(ch->mount, AFF_FLOATING))
					txt = "floats";
				else if (IS_AFFECTED(ch->mount, AFF_FLYING))
					txt = "flies";
				else
					txt = "rides";
			} else {
				if (IS_AFFECTED(ch, AFF_FLOATING)) {
					if (drunk)
						txt = "floats unsteadily";
					else
						txt = "floats";
				} else if (IS_AFFECTED(ch, AFF_FLYING)) {
					if (drunk)
						txt = "flies shakily";
					else
						txt = "flies";
				} else if (ch->position == POS_SHOVE)
					txt = "is shoved";
				else if (ch->position == POS_DRAG)
					txt = "is dragged";
				else {
					if (drunk)
						txt = "stumbles drunkenly";
					else
						txt = "leaves";
				}
			}
		}
		if (ch->mount) {
			sprintf(buf, "$n %s %s upon $N.", txt, dir_name[door]);

			act(AT_ACTION, buf, ch, NULL, ch->mount, TO_NOTVICT);
		} else {
			sprintf(buf, "$n %s $T.", txt);

			act(AT_ACTION, buf, ch, NULL, dir_name[door], TO_ROOM);
		}
	}
	rprog_leave_trigger(ch);
	if (char_died(ch))
		return (global_retcode);

	char_from_room(ch);
	if (ch->mount) {
		rprog_leave_trigger(ch->mount);
		if (char_died(ch))
			return (global_retcode);
		if (ch->mount) {
			char_from_room(ch->mount);
			char_to_room(ch->mount, to_room);
		}
	}
	char_to_room(ch, to_room);
	if (!IS_AFFECTED(ch, AFF_SNEAK)
	    && (IS_NPC(ch) || !xIS_SET(ch->act, PLR_WIZINVIS))) {
		if (fall)
			txt = "falls";
		else if (ch->mount) {
			if (IS_AFFECTED(ch->mount, AFF_FLOATING))
				txt = "floats in";
			else if (IS_AFFECTED(ch->mount, AFF_FLYING))
				txt = "flies in";
			else
				txt = "rides in";
		} else {
			if (IS_AFFECTED(ch, AFF_FLOATING)) {
				if (drunk)
					txt = "floats in unsteadily";
				else
					txt = "floats in";
			} else if (IS_AFFECTED(ch, AFF_FLYING)) {
				if (drunk)
					txt = "flies in shakily";
				else
					txt = "flies in";
			} else if (ch->position == POS_SHOVE)
				txt = "is shoved in";
			else if (ch->position == POS_DRAG)
				txt = "is dragged in";
			else {
				if (drunk)
					txt = "stumbles drunkenly in";
				else
					txt = "arrives";
			}
		}
		dtxt = rev_exit(door);
		if (ch->mount) {
			sprintf(buf, "$n %s from %s upon $N.", txt, dtxt);

			act(AT_ACTION, buf, ch, NULL, ch->mount, TO_ROOM);
		} else {
			sprintf(buf, "$n %s from %s.", txt, dtxt);

			act(AT_ACTION, buf, ch, NULL, NULL, TO_ROOM);
		}
	}
	if (!IS_IMMORTAL(ch)
	    && !IS_NPC(ch)
	    && ch->in_room->area != to_room->area) {
		if (ch->level < to_room->area->low_soft_range) {
			set_char_color(AT_MAGIC, ch);
			send_to_char("You feel uncomfortable being in this strange land...\n\r", ch);
		} else if (ch->level > to_room->area->hi_soft_range) {
			set_char_color(AT_MAGIC, ch);
			send_to_char("You feel there is not much to gain visiting this place...\n\r", ch);
		}
	}
	/* Make sure everyone sees the room description of death traps. */
	if (xIS_SET(ch->in_room->room_flags, ROOM_DEATH) && !IS_IMMORTAL(ch)) {
		if (xIS_SET(ch->act, PLR_BRIEF))
			brief = true;
		xREMOVE_BIT(ch->act, PLR_BRIEF);
	}
	do_look(ch, "auto");
	if (brief)
		xSET_BIT(ch->act, PLR_BRIEF);

	/*
	 * Put good-old EQ-munching death traps back in!		-Thoric
	 */
	if (xIS_SET(ch->in_room->room_flags, ROOM_DEATH) && !IS_IMMORTAL(ch)) {
		act(AT_DEAD, "$n falls prey to a terrible death!", ch, NULL, NULL, TO_ROOM);
		set_char_color(AT_DEAD, ch);
		send_to_char("Oopsie... you're dead!\n\r", ch);
		sprintf(buf, "%s hit a DEATH TRAP in room %d!",
		    ch->name, ch->in_room->vnum);
		log_string(buf);
		to_channel(buf, CHANNEL_MONITOR, "Monitor", LEVEL_IMMORTAL);
		extract_char(ch, false, false);
		return (rCHAR_DIED);
	}
	/*
	 * BIG ugly looping problem here when the character is mptransed
	 * back to the starting room.  To avoid this, check how many chars
	 * are in the room at the start and stop processing followers after
	 * doing the right number of them.  -- Narn
	 */
	if (!fall) {
		CHAR_DATA *fch;
		CHAR_DATA *nextinroom;
		int chars = 0, count = 0;

		for (fch = from_room->first_person; fch; fch = fch->next_in_room)
			chars++;

		for (fch = from_room->first_person; fch && (count < chars); fch = nextinroom) {
			nextinroom = fch->next_in_room;
			count++;
			if (fch != ch	/* loop room bug fix here by Thoric */
			    && fch->master == ch
			    && fch->position == POS_STANDING) {
				act(AT_ACTION, "You follow $N.", fch, NULL, ch, TO_CHAR);
				move_char(fch, pexit, 0);
			}
		}
	}
	if (ch->in_room->first_content)
		retcode = check_room_for_traps(ch, TRAP_ENTER_ROOM);
	if (retcode != rNONE)
		return (retcode);

	if (char_died(ch))
		return (retcode);

	mprog_entry_trigger(ch);
	if (char_died(ch))
		return (retcode);

	rprog_enter_trigger(ch);
	if (char_died(ch))
		return (retcode);

	mprog_greet_trigger(ch);
	if (char_died(ch))
		return (retcode);

	oprog_greet_trigger(ch);
	if (char_died(ch))
		return (retcode);

	if (!will_fall(ch, fall)
	    && fall > 0) {
		if (!IS_AFFECTED(ch, AFF_FLOATING)
		    || (ch->mount && !IS_AFFECTED(ch->mount, AFF_FLOATING))) {
			set_char_color(AT_HURT, ch);
			send_to_char("OUCH! You hit the ground!\n\r", ch);
			WAIT_STATE(ch, 20);
			retcode = damage(ch, ch, 20 * fall, TYPE_UNDEFINED);
		} else {
			set_char_color(AT_MAGIC, ch);
			send_to_char("You lightly float down to the ground.\n\r", ch);
		}
	}
	return (retcode);
}


/* ARGSUSED */
void 
do_north(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_NORTH), 0);
	return;
}

/* ARGSUSED */
void 
do_east(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_EAST), 0);
	return;
}


/* ARGSUSED */
void 
do_south(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_SOUTH), 0);
	return;
}


/* ARGSUSED */
void 
do_west(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_WEST), 0);
	return;
}


/* ARGSUSED */
void 
do_up(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_UP), 0);
	return;
}


/* ARGSUSED */
void 
do_down(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_DOWN), 0);
	return;
}

/* ARGSUSED */
void 
do_northeast(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_NORTHEAST), 0);
	return;
}

/* ARGSUSED */
void 
do_northwest(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_NORTHWEST), 0);
	return;
}

/* ARGSUSED */
void 
do_southeast(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_SOUTHEAST), 0);
	return;
}

/* ARGSUSED */
void 
do_southwest(CHAR_DATA * ch, char *argument)
{
	move_char(ch, get_exit(ch->in_room, DIR_SOUTHWEST), 0);
	return;
}



EXIT_DATA *
find_door(CHAR_DATA * ch, char *arg, bool quiet)
{
	EXIT_DATA *pexit;
	int door;

	if (arg == NULL || !str_cmp(arg, ""))
		return (NULL);

	pexit = NULL;
	if (!str_cmp(arg, "n") || !str_cmp(arg, "north"))
		door = 0;
	else if (!str_cmp(arg, "e") || !str_cmp(arg, "east"))
		door = 1;
	else if (!str_cmp(arg, "s") || !str_cmp(arg, "south"))
		door = 2;
	else if (!str_cmp(arg, "w") || !str_cmp(arg, "west"))
		door = 3;
	else if (!str_cmp(arg, "u") || !str_cmp(arg, "up"))
		door = 4;
	else if (!str_cmp(arg, "d") || !str_cmp(arg, "down"))
		door = 5;
	else if (!str_cmp(arg, "ne") || !str_cmp(arg, "northeast"))
		door = 6;
	else if (!str_cmp(arg, "nw") || !str_cmp(arg, "northwest"))
		door = 7;
	else if (!str_cmp(arg, "se") || !str_cmp(arg, "southeast"))
		door = 8;
	else if (!str_cmp(arg, "sw") || !str_cmp(arg, "southwest"))
		door = 9;
	else {
		for (pexit = ch->in_room->first_exit; pexit; pexit = pexit->next) {
			if ((quiet || IS_SET(pexit->exit_info, EX_ISDOOR))
			    && pexit->keyword
			    && nifty_is_name(arg, pexit->keyword))
				return (pexit);
		}
		if (!quiet)
			act(AT_PLAIN, "You see no $T here.", ch, NULL, arg, TO_CHAR);
		return (NULL);
	}

	if ((pexit = get_exit(ch->in_room, door)) == NULL) {
		if (!quiet)
			act(AT_PLAIN, "You see no $T here.", ch, NULL, arg, TO_CHAR);
		return (NULL);
	}
	if (quiet)
		return (pexit);

	if (IS_SET(pexit->exit_info, EX_SECRET)) {
		act(AT_PLAIN, "You see no $T here.", ch, NULL, arg, TO_CHAR);
		return (NULL);
	}
	if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
		send_to_char("You can't do that.\n\r", ch);
		return (NULL);
	}
	return (pexit);
}


void 
set_bexit_flag(EXIT_DATA * pexit, int flag)
{
	EXIT_DATA *pexit_rev;

	SET_BIT(pexit->exit_info, flag);
	if ((pexit_rev = pexit->rexit) != NULL
	    && pexit_rev != pexit)
		SET_BIT(pexit_rev->exit_info, flag);
}

void 
remove_bexit_flag(EXIT_DATA * pexit, int flag)
{
	EXIT_DATA *pexit_rev;

	REMOVE_BIT(pexit->exit_info, flag);
	if ((pexit_rev = pexit->rexit) != NULL
	    && pexit_rev != pexit)
		REMOVE_BIT(pexit_rev->exit_info, flag);
}

void 
toggle_bexit_flag(EXIT_DATA * pexit, int flag)
{
	EXIT_DATA *pexit_rev;

	TOGGLE_BIT(pexit->exit_info, flag);
	if ((pexit_rev = pexit->rexit) != NULL
	    && pexit_rev != pexit)
		TOGGLE_BIT(pexit_rev->exit_info, flag);
}

void 
do_open(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	OBJ_DATA *obj;
	EXIT_DATA *pexit;
	int door;

	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Open what?\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, true)) != NULL) {
		/* 'open door' */
		EXIT_DATA *pexit_rev;

		if (IS_SET(pexit->exit_info, EX_SECRET)
		    && pexit->keyword && !nifty_is_name(arg, pexit->keyword)) {
			ch_printf(ch, "You see no %s here.\n\r", arg);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
			send_to_char("You can't do that.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("It's already open.\n\r", ch);
			return;
		}
		if (IS_SET(pexit->exit_info, EX_LOCKED)
		    && IS_SET(pexit->exit_info, EX_BOLTED)) {
			send_to_char("The bolts locked.\n\r", ch);
			return;
		}
		if (IS_SET(pexit->exit_info, EX_BOLTED)) {
			send_to_char("It's bolted.\n\r", ch);
			return;
		}
		if (IS_SET(pexit->exit_info, EX_LOCKED)) {
			send_to_char("It's locked.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_SECRET)
		    || (pexit->keyword && nifty_is_name(arg, pexit->keyword))) {
			act(AT_ACTION, "$n opens the $d.", ch, NULL, pexit->keyword, TO_ROOM);
			act(AT_ACTION, "You open the $d.", ch, NULL, pexit->keyword, TO_CHAR);
			if ((pexit_rev = pexit->rexit) != NULL
			    && pexit_rev->to_room == ch->in_room) {
				CHAR_DATA *rch;

				for (rch = pexit->to_room->first_person; rch; rch = rch->next_in_room)
					act(AT_ACTION, "The $d opens.", rch, NULL, pexit_rev->keyword, TO_CHAR);
			}
			remove_bexit_flag(pexit, EX_CLOSED);
			if ((door = pexit->vdir) >= 0 && door < 10)
				check_room_for_traps(ch, trap_door[door]);
			return;
		}
	}
	if ((obj = get_obj_here(ch, arg)) != NULL) {
		/* 'open object' */
		if (obj->item_type != ITEM_CONTAINER) {
			ch_printf(ch, "%s is not a container.\n\r", capitalize(obj->short_descr));
			return;
		}
		if (!IS_SET(obj->value[1], CONT_CLOSED)) {
			ch_printf(ch, "%s is already open.\n\r", capitalize(obj->short_descr));
			return;
		}
		if (!IS_SET(obj->value[1], CONT_CLOSEABLE)) {
			ch_printf(ch, "%s cannot be opened or closed.\n\r", capitalize(obj->short_descr));
			return;
		}
		if (IS_SET(obj->value[1], CONT_LOCKED)) {
			ch_printf(ch, "%s is locked.\n\r", capitalize(obj->short_descr));
			return;
		}
		REMOVE_BIT(obj->value[1], CONT_CLOSED);
		act(AT_ACTION, "You open $p.", ch, obj, NULL, TO_CHAR);
		act(AT_ACTION, "$n opens $p.", ch, obj, NULL, TO_ROOM);
		check_for_trap(ch, obj, TRAP_OPEN);
		return;
	}
	ch_printf(ch, "You see no %s here.\n\r", arg);
	return;
}



void 
do_close(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	OBJ_DATA *obj;
	EXIT_DATA *pexit;
	int door;

	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Close what?\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, true)) != NULL) {
		/* 'close door' */
		EXIT_DATA *pexit_rev;

		if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
			send_to_char("You can't do that.\n\r", ch);
			return;
		}
		if (IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("It's already closed.\n\r", ch);
			return;
		}
		act(AT_ACTION, "$n closes the $d.", ch, NULL, pexit->keyword, TO_ROOM);
		act(AT_ACTION, "You close the $d.", ch, NULL, pexit->keyword, TO_CHAR);

		/* close the other side */
		if ((pexit_rev = pexit->rexit) != NULL
		    && pexit_rev->to_room == ch->in_room) {
			CHAR_DATA *rch;

			SET_BIT(pexit_rev->exit_info, EX_CLOSED);
			for (rch = pexit->to_room->first_person; rch; rch = rch->next_in_room)
				act(AT_ACTION, "The $d closes.", rch, NULL, pexit_rev->keyword, TO_CHAR);
		}
		set_bexit_flag(pexit, EX_CLOSED);
		if ((door = pexit->vdir) >= 0 && door < 10)
			check_room_for_traps(ch, trap_door[door]);
		return;
	}
	if ((obj = get_obj_here(ch, arg)) != NULL) {
		/* 'close object' */
		if (obj->item_type != ITEM_CONTAINER) {
			ch_printf(ch, "%s is not a container.\n\r", capitalize(obj->short_descr));
			return;
		}
		if (IS_SET(obj->value[1], CONT_CLOSED)) {
			ch_printf(ch, "%s is already closed.\n\r", capitalize(obj->short_descr));
			return;
		}
		if (!IS_SET(obj->value[1], CONT_CLOSEABLE)) {
			ch_printf(ch, "%s cannot be opened or closed.\n\r", capitalize(obj->short_descr));
			return;
		}
		SET_BIT(obj->value[1], CONT_CLOSED);
		act(AT_ACTION, "You close $p.", ch, obj, NULL, TO_CHAR);
		act(AT_ACTION, "$n closes $p.", ch, obj, NULL, TO_ROOM);
		check_for_trap(ch, obj, TRAP_CLOSE);
		return;
	}
	ch_printf(ch, "You see no %s here.\n\r", arg);
	return;
}


/*
 * Keyring support added by Thoric
 * Idea suggested by Onyx <MtRicmer@worldnet.att.net> of Eldarion
 *
 * New: returns pointer to key/NULL instead of true/false
 *
 * If you want a feature like having immortals always have a key... you'll
 * need to code in a generic key, and make sure extract_obj doesn't extract it
 */
OBJ_DATA *
has_key(CHAR_DATA * ch, int key)
{
	OBJ_DATA *obj, *obj2;

	for (obj = ch->first_carrying; obj; obj = obj->next_content) {
		if (obj->pIndexData->vnum == key || (obj->item_type == ITEM_KEY && obj->value[0] == key))
			return (obj);
		else if (obj->item_type == ITEM_KEYRING)
			for (obj2 = obj->first_content; obj2; obj2 = obj2->next_content)
				if (obj2->pIndexData->vnum == key || obj2->value[0] == key)
					return (obj2);
	}

	return (NULL);
}


void 
do_lock(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	OBJ_DATA *obj, *key;
	EXIT_DATA *pexit;
	int count;

	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Lock what?\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, true)) != NULL) {
		/* 'lock door' */

		if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
			send_to_char("You can't do that.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("It's not closed.\n\r", ch);
			return;
		}
		if (pexit->key < 0) {
			send_to_char("It can't be locked.\n\r", ch);
			return;
		}
		if ((key = has_key(ch, pexit->key)) == NULL) {
			send_to_char("You lack the key.\n\r", ch);
			return;
		}
		if (IS_SET(pexit->exit_info, EX_LOCKED)) {
			send_to_char("It's already locked.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_SECRET)
		    || (pexit->keyword && nifty_is_name(arg, pexit->keyword))) {
			send_to_char("*Click*\n\r", ch);
			count = key->count;
			key->count = 1;
			act(AT_ACTION, "$n locks the $d with $p.", ch, key, pexit->keyword, TO_ROOM);
			key->count = count;
			set_bexit_flag(pexit, EX_LOCKED);
			return;
		}
	}
	if ((obj = get_obj_here(ch, arg)) != NULL) {
		/* 'lock object' */
		if (obj->item_type != ITEM_CONTAINER) {
			send_to_char("That's not a container.\n\r", ch);
			return;
		}
		if (!IS_SET(obj->value[1], CONT_CLOSED)) {
			send_to_char("It's not closed.\n\r", ch);
			return;
		}
		if (obj->value[2] < 0) {
			send_to_char("It can't be locked.\n\r", ch);
			return;
		}
		if ((key = has_key(ch, obj->value[2])) == NULL) {
			send_to_char("You lack the key.\n\r", ch);
			return;
		}
		if (IS_SET(obj->value[1], CONT_LOCKED)) {
			send_to_char("It's already locked.\n\r", ch);
			return;
		}
		SET_BIT(obj->value[1], CONT_LOCKED);
		send_to_char("*Click*\n\r", ch);
		count = key->count;
		key->count = 1;
		act(AT_ACTION, "$n locks $p with $P.", ch, obj, key, TO_ROOM);
		key->count = count;
		return;
	}
	ch_printf(ch, "You see no %s here.\n\r", arg);
	return;
}



void 
do_unlock(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	OBJ_DATA *obj, *key;
	EXIT_DATA *pexit;
	int count;

	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Unlock what?\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, true)) != NULL) {
		/* 'unlock door' */

		if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
			send_to_char("You can't do that.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("It's not closed.\n\r", ch);
			return;
		}
		if (pexit->key < 0) {
			send_to_char("It can't be unlocked.\n\r", ch);
			return;
		}
		if ((key = has_key(ch, pexit->key)) == NULL) {
			send_to_char("You lack the key.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_LOCKED)) {
			send_to_char("It's already unlocked.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_SECRET)
		    || (pexit->keyword && nifty_is_name(arg, pexit->keyword))) {
			send_to_char("*Click*\n\r", ch);
			count = key->count;
			key->count = 1;
			act(AT_ACTION, "$n unlocks the $d with $p.", ch, key, pexit->keyword, TO_ROOM);
			key->count = count;
			if (IS_SET(pexit->exit_info, EX_EATKEY)) {
				separate_obj(key);
				extract_obj(key);
			}
			remove_bexit_flag(pexit, EX_LOCKED);
			return;
		}
	}
	if ((obj = get_obj_here(ch, arg)) != NULL) {
		/* 'unlock object' */
		if (obj->item_type != ITEM_CONTAINER) {
			send_to_char("That's not a container.\n\r", ch);
			return;
		}
		if (!IS_SET(obj->value[1], CONT_CLOSED)) {
			send_to_char("It's not closed.\n\r", ch);
			return;
		}
		if (obj->value[2] < 0) {
			send_to_char("It can't be unlocked.\n\r", ch);
			return;
		}
		if ((key = has_key(ch, obj->value[2])) == NULL) {
			send_to_char("You lack the key.\n\r", ch);
			return;
		}
		if (!IS_SET(obj->value[1], CONT_LOCKED)) {
			send_to_char("It's already unlocked.\n\r", ch);
			return;
		}
		REMOVE_BIT(obj->value[1], CONT_LOCKED);
		send_to_char("*Click*\n\r", ch);
		count = key->count;
		key->count = 1;
		act(AT_ACTION, "$n unlocks $p with $P.", ch, obj, key, TO_ROOM);
		key->count = count;
		if (IS_SET(obj->value[1], CONT_EATKEY)) {
			separate_obj(key);
			extract_obj(key);
		}
		return;
	}
	ch_printf(ch, "You see no %s here.\n\r", arg);
	return;
}

void 
do_bashdoor(CHAR_DATA * ch, char *argument)
{
	CHAR_DATA *gch;
	EXIT_DATA *pexit;
	char arg[MAX_INPUT_LENGTH];

	if (!IS_NPC(ch)
	    && ch->level < skill_table[gsn_bashdoor]->skill_level[ch->class]) {
		send_to_char("You're not enough of a warrior to bash doors!\n\r", ch);
		return;
	}
	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Bash what?\n\r", ch);
		return;
	}
	if (ch->fighting) {
		send_to_char("You can't break off your fight.\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, false)) != NULL) {
		ROOM_INDEX_DATA *to_room;
		EXIT_DATA *pexit_rev;
		int chance;
		char *keyword;

		if (!IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("Calm down.  It is already open.\n\r", ch);
			return;
		}
		WAIT_STATE(ch, skill_table[gsn_bashdoor]->beats);

		if (IS_SET(pexit->exit_info, EX_SECRET))
			keyword = "wall";
		else
			keyword = pexit->keyword;
		if (!IS_NPC(ch))
			chance = LEARNED(ch, gsn_bashdoor) / 2;
		else
			chance = 90;
		if (IS_SET(pexit->exit_info, EX_LOCKED))
			chance /= 3;

		if (!IS_SET(pexit->exit_info, EX_BASHPROOF)
		    // &&ch->move >= 15
		    && number_percent() < (chance + 4 * (get_curr_str(ch) - 19))) {
			REMOVE_BIT(pexit->exit_info, EX_CLOSED);
			if (IS_SET(pexit->exit_info, EX_LOCKED))
				REMOVE_BIT(pexit->exit_info, EX_LOCKED);
			SET_BIT(pexit->exit_info, EX_BASHED);

			act(AT_SKILL, "Crash!  You bashed open the $d!", ch, NULL, keyword, TO_CHAR);
			act(AT_SKILL, "$n bashes open the $d!", ch, NULL, keyword, TO_ROOM);
			learn_from_success(ch, gsn_bashdoor);

			if ((to_room = pexit->to_room) != NULL
			    && (pexit_rev = pexit->rexit) != NULL
			    && pexit_rev->to_room == ch->in_room) {
				CHAR_DATA *rch;

				REMOVE_BIT(pexit_rev->exit_info, EX_CLOSED);
				if (IS_SET(pexit_rev->exit_info, EX_LOCKED))
					REMOVE_BIT(pexit_rev->exit_info, EX_LOCKED);
				SET_BIT(pexit_rev->exit_info, EX_BASHED);

				for (rch = to_room->first_person; rch; rch = rch->next_in_room) {
					act(AT_SKILL, "The $d crashes open!",
					    rch, NULL, pexit_rev->keyword, TO_CHAR);
				}
			}
			damage(ch, ch, (ch->max_hit / 20), gsn_bashdoor);

		} else {
			act(AT_SKILL, "WHAAAAM!!!  You bash against the $d, but it doesn't budge.",
			    ch, NULL, keyword, TO_CHAR);
			act(AT_SKILL, "WHAAAAM!!!  $n bashes against the $d, but it holds strong.",
			    ch, NULL, keyword, TO_ROOM);
			damage(ch, ch, (ch->max_hit / 20) + 10, gsn_bashdoor);
			learn_from_failure(ch, gsn_bashdoor);
		}
	} else {
		act(AT_SKILL, "WHAAAAM!!!  You bash against the wall, but it doesn't budge.",
		    ch, NULL, NULL, TO_CHAR);
		act(AT_SKILL, "WHAAAAM!!!  $n bashes against the wall, but it holds strong.",
		    ch, NULL, NULL, TO_ROOM);
		damage(ch, ch, (ch->max_hit / 20) + 10, gsn_bashdoor);
		learn_from_failure(ch, gsn_bashdoor);
	}
	if (!char_died(ch))
		for (gch = ch->in_room->first_person; gch; gch = gch->next_in_room) {
			if (IS_AWAKE(gch)
			    && !gch->fighting
			    && (IS_NPC(gch) && !IS_AFFECTED(gch, AFF_CHARM))
			    && (ch->level - gch->level <= 4)
			    && number_bits(2) == 0)
				multi_hit(gch, ch, TYPE_UNDEFINED);
		}

	return;
}


/* ARGSUSED */
void 
do_stand(CHAR_DATA * ch, char *argument)
{
	switch (ch->position) {
	case POS_SLEEPING:
		if (IS_AFFECTED(ch, AFF_SLEEP)) {
			send_to_char("You can't seem to wake up!\n\r", ch);
			return;
		}
		send_to_char("You wake and climb quickly to your feet.\n\r", ch);
		act(AT_ACTION, "$n arises from $s slumber.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_STANDING;
		break;

	case POS_RESTING:
		send_to_char("You gather yourself and stand up.\n\r", ch);
		act(AT_ACTION, "$n rises from $s rest.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_STANDING;
		break;

	case POS_SITTING:
		send_to_char("You move quickly to your feet.\n\r", ch);
		act(AT_ACTION, "$n rises up.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_STANDING;
		break;

	case POS_STANDING:
		send_to_char("You are already standing.\n\r", ch);
		break;

	case POS_FIGHTING:
	case POS_EVASIVE:
	case POS_DEFENSIVE:
	case POS_AGGRESSIVE:
	case POS_BERSERK:
		send_to_char("You are already fighting!\n\r", ch);
		break;
	}

	return;
}


/* ARGSUSED */
void 
do_sit(CHAR_DATA * ch, char *argument)
{
	switch (ch->position) {
	case POS_SLEEPING:
		if (IS_AFFECTED(ch, AFF_SLEEP)) {
			send_to_char("You can't seem to wake up!\n\r", ch);
			return;
		}
		send_to_char("You wake and sit up.\n\r", ch);
		act(AT_ACTION, "$n wakes and sits up.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_SITTING;
		break;

	case POS_RESTING:
		send_to_char("You stop resting and sit up.\n\r", ch);
		act(AT_ACTION, "$n stops resting and sits up.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_SITTING;
		break;

	case POS_STANDING:
		send_to_char("You sit down.\n\r", ch);
		act(AT_ACTION, "$n sits down.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_SITTING;
		break;
	case POS_SITTING:
		send_to_char("You are already sitting.\n\r", ch);
		return;

	case POS_FIGHTING:
	case POS_EVASIVE:
	case POS_DEFENSIVE:
	case POS_AGGRESSIVE:
	case POS_BERSERK:
		send_to_char("You are busy fighting!\n\r", ch);
		return;
	case POS_MOUNTED:
		send_to_char("You are already sitting - on your mount.\n\r", ch);
		return;
	}

	return;
}


/* ARGSUSED */
void 
do_rest(CHAR_DATA * ch, char *argument)
{
	if (xIS_SET((ch)->affected_by, AFF_PUSHUPS)
		|| xIS_SET((ch)->affected_by, AFF_SHADOWBOXING)
		|| xIS_SET((ch)->affected_by, AFF_ENDURING)
		|| xIS_SET((ch)->affected_by, AFF_MEDITATION)
		|| xIS_SET((ch)->affected_by, AFF_POWERCHANNEL)
		|| xIS_SET((ch)->affected_by, AFF_POWERUPTRAIN)
		|| xIS_SET((ch)->affected_by, AFF_OVERCHANNEL)) {
			send_to_char("You're a little too busy to do that.\n\r", ch);
			return;
		}
	switch (ch->position) {
	case POS_SLEEPING:
		if (IS_AFFECTED(ch, AFF_SLEEP)) {
			send_to_char("You can't seem to wake up!\n\r", ch);
			return;
		}
		send_to_char("You rouse from your slumber.\n\r", ch);
		act(AT_ACTION, "$n rouses from $s slumber.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_RESTING;
		ch->focus = 0;
		break;

	case POS_RESTING:
		send_to_char("You are already resting.\n\r", ch);
		ch->focus = 0;
		return;

	case POS_STANDING:
		send_to_char("You sprawl out haphazardly.\n\r", ch);
		act(AT_ACTION, "$n sprawls out haphazardly.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_RESTING;
		ch->focus = 0;
		break;

	case POS_SITTING:
		send_to_char("You lie back and sprawl out to rest.\n\r", ch);
		act(AT_ACTION, "$n lies back and sprawls out to rest.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_RESTING;
		ch->focus = 0;
		break;

	case POS_FIGHTING:
	case POS_EVASIVE:
	case POS_DEFENSIVE:
	case POS_AGGRESSIVE:
	case POS_BERSERK:
		send_to_char("You are busy fighting!\n\r", ch);
		return;
	case POS_MOUNTED:
		send_to_char("You'd better dismount first.\n\r", ch);
		return;
	}

	rprog_rest_trigger(ch);
	return;
}


/* ARGSUSED */
void 
do_sleep(CHAR_DATA * ch, char *argument)
{

	switch (ch->position) {
	case POS_SLEEPING:
		send_to_char("You are already sleeping.\n\r", ch);
		ch->focus = 0;
		return;

	case POS_RESTING:
		if (ch->mental_state > 30 && (number_percent() + 10) < ch->mental_state) {
			send_to_char("You just can't seem to calm yourself down enough to sleep.\n\r", ch);
			act(AT_ACTION, "$n closes $s eyes for a few moments, but just can't seem to go to sleep.", ch, NULL, NULL, TO_ROOM);
			return;
		}
		send_to_char("You close your eyes and drift into slumber.\n\r", ch);
		act(AT_ACTION, "$n closes $s eyes and drifts into a deep slumber.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_SLEEPING;
		ch->focus = 0;
		break;

	case POS_SITTING:
		if (ch->mental_state > 30 && (number_percent() + 5) < ch->mental_state) {
			send_to_char("You just can't seem to calm yourself down enough to sleep.\n\r", ch);
			act(AT_ACTION, "$n closes $s eyes for a few moments, but just can't seem to go to sleep.", ch, NULL, NULL, TO_ROOM);
			return;
		}
		send_to_char("You slump over and fall dead asleep.\n\r", ch);
		act(AT_ACTION, "$n nods off and slowly slumps over, dead asleep.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_SLEEPING;
		ch->focus = 0;
		break;

	case POS_STANDING:
		if (ch->mental_state > 30 && number_percent() < ch->mental_state) {
			send_to_char("You just can't seem to calm yourself down enough to sleep.\n\r", ch);
			act(AT_ACTION, "$n closes $s eyes for a few moments, but just can't seem to go to sleep.", ch, NULL, NULL, TO_ROOM);
			return;
		}
		send_to_char("You collapse into a deep sleep.\n\r", ch);
		act(AT_ACTION, "$n collapses into a deep sleep.", ch, NULL, NULL, TO_ROOM);
		ch->position = POS_SLEEPING;
		ch->focus = 0;
		break;

	case POS_FIGHTING:
	case POS_EVASIVE:
	case POS_DEFENSIVE:
	case POS_AGGRESSIVE:
	case POS_BERSERK:
		send_to_char("You are busy fighting!\n\r", ch);
		return;
	case POS_MOUNTED:
		send_to_char("You really should dismount first.\n\r", ch);
		return;
	}

	rprog_sleep_trigger(ch);
	return;
}


void 
do_wake(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	CHAR_DATA *victim;

	do_stand(ch, argument);
	return;

	if (!IS_AWAKE(ch)) {
		send_to_char("You are asleep yourself!\n\r", ch);
		return;
	}
	if ((victim = get_char_room(ch, arg)) == NULL) {
		send_to_char("They aren't here.\n\r", ch);
		return;
	}
	if (IS_AWAKE(victim)) {
		act(AT_PLAIN, "$N is already awake.", ch, NULL, victim, TO_CHAR);
		return;
	}
	if (IS_AFFECTED(victim, AFF_SLEEP) || victim->position < POS_SLEEPING) {
		act(AT_PLAIN, "You can't seem to wake $M!", ch, NULL, victim, TO_CHAR);
		return;
	}
	act(AT_ACTION, "You wake $M.", ch, NULL, victim, TO_CHAR);
	victim->position = POS_STANDING;
	act(AT_ACTION, "$n wakes you.", ch, NULL, victim, TO_VICT);
	return;
}


/*
 * teleport a character to another room
 */
void 
teleportch(CHAR_DATA * ch, ROOM_INDEX_DATA * room, bool show)
{
	char buf[MAX_STRING_LENGTH];

	if (room_is_private(room))
		return;
	act(AT_ACTION, "$n disappears suddenly!", ch, NULL, NULL, TO_ROOM);
	char_from_room(ch);
	char_to_room(ch, room);
	act(AT_ACTION, "$n arrives suddenly!", ch, NULL, NULL, TO_ROOM);
	if (show)
		do_look(ch, "auto");
	if (xIS_SET(ch->in_room->room_flags, ROOM_DEATH) && !IS_IMMORTAL(ch)) {
		act(AT_DEAD, "$n falls prey to a terrible death!", ch, NULL, NULL, TO_ROOM);
		set_char_color(AT_DEAD, ch);
		send_to_char("Oopsie... you're dead!\n\r", ch);
		sprintf(buf, "%s hit a DEATH TRAP in room %d!",
		    ch->name, ch->in_room->vnum);
		log_string(buf);
		to_channel(buf, CHANNEL_MONITOR, "Monitor", LEVEL_IMMORTAL);
		extract_char(ch, false, false);
	}
}

void 
teleport(CHAR_DATA * ch, int room, int flags)
{
	CHAR_DATA *nch, *nch_next;
	ROOM_INDEX_DATA *start = ch->in_room, *dest;
	bool show;

	dest = get_room_index(room);
	if (!dest) {
		bug("teleport: bad room vnum %d", room);
		return;
	}
	if (IS_SET(flags, TELE_SHOWDESC))
		show = true;
	else
		show = false;
	if (!IS_SET(flags, TELE_TRANSALL)) {
		teleportch(ch, dest, show);
		return;
	}
	/* teleport everybody in the room */
	for (nch = start->first_person; nch; nch = nch_next) {
		nch_next = nch->next_in_room;
		teleportch(nch, dest, show);
	}

	/* teleport the objects on the ground too */
	if (IS_SET(flags, TELE_TRANSALLPLUS)) {
		OBJ_DATA *obj, *obj_next;

		for (obj = start->first_content; obj; obj = obj_next) {
			obj_next = obj->next_content;
			obj_from_room(obj);
			obj_to_room(obj, dest);
		}
	}
}

/*
 * "Climb" in a certain direction.				-Thoric
 */
void 
do_climb(CHAR_DATA * ch, char *argument)
{
	EXIT_DATA *pexit;
	bool found;

	found = false;
	if (argument[0] == '\0') {
		for (pexit = ch->in_room->first_exit; pexit; pexit = pexit->next)
			if (IS_SET(pexit->exit_info, EX_xCLIMB)) {
				move_char(ch, pexit, 0);
				return;
			}
		send_to_char("You cannot climb here.\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, argument, true)) != NULL
	    && IS_SET(pexit->exit_info, EX_xCLIMB)) {
		move_char(ch, pexit, 0);
		return;
	}
	send_to_char("You cannot climb there.\n\r", ch);
	return;
}

/*
 * "enter" something (moves through an exit)			-Thoric
 */
void 
do_enter(CHAR_DATA * ch, char *argument)
{
	EXIT_DATA *pexit;
	bool found;

	found = false;
	if (argument[0] == '\0') {
		for (pexit = ch->in_room->first_exit; pexit; pexit = pexit->next)
			if (IS_SET(pexit->exit_info, EX_xENTER)) {
				move_char(ch, pexit, 0);
				return;
			}
		if (ch->in_room->sector_type != SECT_INSIDE && IS_OUTSIDE(ch))
			for (pexit = ch->in_room->first_exit; pexit; pexit = pexit->next)
				if (pexit->to_room && (pexit->to_room->sector_type == SECT_INSIDE
				    || xIS_SET(pexit->to_room->room_flags, ROOM_INDOORS))) {
					move_char(ch, pexit, 0);
					return;
				}
		send_to_char("You cannot find an entrance here.\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, argument, true)) != NULL
	    && IS_SET(pexit->exit_info, EX_xENTER)) {
		move_char(ch, pexit, 0);
		return;
	}
	send_to_char("You cannot enter that.\n\r", ch);
	return;
}

/*
 * Leave through an exit.					-Thoric
 */
void 
do_leave(CHAR_DATA * ch, char *argument)
{
	EXIT_DATA *pexit;
	bool found;

	found = false;
	if (argument[0] == '\0') {
		for (pexit = ch->in_room->first_exit; pexit; pexit = pexit->next)
			if (IS_SET(pexit->exit_info, EX_xLEAVE)) {
				move_char(ch, pexit, 0);
				return;
			}
		if (ch->in_room->sector_type == SECT_INSIDE || !IS_OUTSIDE(ch))
			for (pexit = ch->in_room->first_exit; pexit; pexit = pexit->next)
				if (pexit->to_room && pexit->to_room->sector_type != SECT_INSIDE
				    && !xIS_SET(pexit->to_room->room_flags, ROOM_INDOORS)) {
					move_char(ch, pexit, 0);
					return;
				}
		send_to_char("You cannot find an exit here.\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, argument, true)) != NULL
	    && IS_SET(pexit->exit_info, EX_xLEAVE)) {
		move_char(ch, pexit, 0);
		return;
	}
	send_to_char("You cannot leave that way.\n\r", ch);
	return;
}

/*
 * Check to see if an exit in the room is pulling (or pushing) players around.
 * Some types may cause damage.					-Thoric
 *
 * People kept requesting currents (like SillyMUD has), so I went all out
 * and added the ability for an exit to have a "pull" or a "push" force
 * and to handle different types much beyond a simple water current.
 *
 * This check is called by violence_update().  I'm not sure if this is the
 * best way to do it, or if it should be handled by a special queue.
 *
 * Future additions to this code may include equipment being blown away in
 * the wind (mostly headwear), and people being hit by flying objects
 *
 * TODO:
 *	handle more pulltypes
 *	give "entrance" messages for players and objects
 *	proper handling of player resistance to push/pulling
 */
ch_ret 
pullcheck(CHAR_DATA * ch, int pulse)
{
	ROOM_INDEX_DATA *room;
	EXIT_DATA *xtmp, *xit = NULL;
	OBJ_DATA *obj, *obj_next;
	bool move = false, moveobj = true, showroom = true;
	int pullfact, pull;
	int resistance;
	char *tochar = NULL, *toroom = NULL, *objmsg = NULL;
	char *destrm = NULL, *destob = NULL, *dtxt = "somewhere";

	if ((room = ch->in_room) == NULL) {
		bug("pullcheck: %s not in a room?!?", ch->name);
		return (rNONE);
	}
	/* Find the exit with the strongest force (if any) */
	for (xtmp = room->first_exit; xtmp; xtmp = xtmp->next)
		if (xtmp->pull && xtmp->to_room && (!xit || abs(xtmp->pull) > abs(xit->pull)))
			xit = xtmp;

	if (!xit)
		return (rNONE);

	pull = xit->pull;

	/* strength also determines frequency */
	pullfact = URANGE(1, 20 - (abs(pull) / 5), 20);

	/* strongest pull not ready yet... check for one that is */
	if ((pulse % pullfact) != 0) {
		for (xit = room->first_exit; xit; xit = xit->next)
			if (xit->pull && xit->to_room) {
				pull = xit->pull;
				pullfact = URANGE(1, 20 - (abs(pull) / 5), 20);
				if ((pulse % pullfact) != 0)
					break;
			}
		if (!xit)
			return (rNONE);
	}
	/* negative pull = push... get the reverse exit if any */
	if (pull < 0)
		if ((xit = get_exit(room, rev_dir[xit->vdir])) == NULL)
			return (rNONE);

	dtxt = rev_exit(xit->vdir);

	/*
	 * First determine if the player should be moved or not
	 * Check various flags, spells, the players position and strength vs.
	 * the pull, etc... any kind of checks you like.
	 */
	switch (xit->pulltype) {
	case PULL_CURRENT:
	case PULL_WHIRLPOOL:
		switch (room->sector_type) {
			/* allow whirlpool to be in any sector type */
		default:
			if (xit->pulltype == PULL_CURRENT)
				break;
		case SECT_WATER_SWIM:
		case SECT_WATER_NOSWIM:
			if ((ch->mount && !IS_FLOATING(ch->mount))
			    || (!ch->mount && !IS_FLOATING(ch)))
				move = true;
			break;

		case SECT_UNDERWATER:
		case SECT_OCEANFLOOR:
			move = true;
			break;
		}
		break;
	case PULL_GEYSER:
	case PULL_WAVE:
		move = true;
		break;

	case PULL_WIND:
	case PULL_STORM:
		/* if not flying... check weight, position & strength */
		move = true;
		break;

	case PULL_COLDWIND:
		/* if not flying... check weight, position & strength */
		/* also check for damage due to bitter cold */
		move = true;
		break;

	case PULL_HOTAIR:
		/* if not flying... check weight, position & strength */
		/* also check for damage due to heat */
		move = true;
		break;

		/* light breeze -- very limited moving power */
	case PULL_BREEZE:
		move = false;
		break;

		/*
		 * exits with these pulltypes should also be blocked from movement
		 * ie: a secret locked pickproof door with the name "_sinkhole_", etc
		 */
	case PULL_EARTHQUAKE:
	case PULL_SINKHOLE:
	case PULL_QUICKSAND:
	case PULL_LANDSLIDE:
	case PULL_SLIP:
	case PULL_LAVA:
		if ((ch->mount && !IS_FLOATING(ch->mount))
		    || (!ch->mount && !IS_FLOATING(ch)))
			move = true;
		break;

		/* as if player moved in that direction him/herself */
	case PULL_UNDEFINED:
		return (move_char(ch, xit, 0));

		/* all other cases ALWAYS move */
	default:
		move = true;
		break;
	}

	/* assign some nice text messages */
	switch (xit->pulltype) {
	case PULL_MYSTERIOUS:
		/* no messages to anyone */
		showroom = false;
		break;
	case PULL_WHIRLPOOL:
	case PULL_VACUUM:
		tochar = "You are sucked $T!";
		toroom = "$n is sucked $T!";
		destrm = "$n is sucked in from $T!";
		objmsg = "$p is sucked $T.";
		destob = "$p is sucked in from $T!";
		break;
	case PULL_CURRENT:
	case PULL_LAVA:
		tochar = "You drift $T.";
		toroom = "$n drifts $T.";
		destrm = "$n drifts in from $T.";
		objmsg = "$p drifts $T.";
		destob = "$p drifts in from $T.";
		break;
	case PULL_BREEZE:
		tochar = "You drift $T.";
		toroom = "$n drifts $T.";
		destrm = "$n drifts in from $T.";
		objmsg = "$p drifts $T in the breeze.";
		destob = "$p drifts in from $T.";
		break;
	case PULL_GEYSER:
	case PULL_WAVE:
		tochar = "You are pushed $T!";
		toroom = "$n is pushed $T!";
		destrm = "$n is pushed in from $T!";
		destob = "$p floats in from $T.";
		break;
	case PULL_EARTHQUAKE:
		tochar = "The earth opens up and you fall $T!";
		toroom = "The earth opens up and $n falls $T!";
		destrm = "$n falls from $T!";
		objmsg = "$p falls $T.";
		destob = "$p falls from $T.";
		break;
	case PULL_SINKHOLE:
		tochar = "The ground suddenly gives way and you fall $T!";
		toroom = "The ground suddenly gives way beneath $n!";
		destrm = "$n falls from $T!";
		objmsg = "$p falls $T.";
		destob = "$p falls from $T.";
		break;
	case PULL_QUICKSAND:
		tochar = "You begin to sink $T into the quicksand!";
		toroom = "$n begins to sink $T into the quicksand!";
		destrm = "$n sinks in from $T.";
		objmsg = "$p begins to sink $T into the quicksand.";
		destob = "$p sinks in from $T.";
		break;
	case PULL_LANDSLIDE:
		tochar = "The ground starts to slide $T, taking you with it!";
		toroom = "The ground starts to slide $T, taking $n with it!";
		destrm = "$n slides in from $T.";
		objmsg = "$p slides $T.";
		destob = "$p slides in from $T.";
		break;
	case PULL_SLIP:
		tochar = "You lose your footing!";
		toroom = "$n loses $s footing!";
		destrm = "$n slides in from $T.";
		objmsg = "$p slides $T.";
		destob = "$p slides in from $T.";
		break;
	case PULL_VORTEX:
		tochar = "You are sucked into a swirling vortex of colors!";
		toroom = "$n is sucked into a swirling vortex of colors!";
		toroom = "$n appears from a swirling vortex of colors!";
		objmsg = "$p is sucked into a swirling vortex of colors!";
		objmsg = "$p appears from a swirling vortex of colors!";
		break;
	case PULL_HOTAIR:
		tochar = "A blast of hot air blows you $T!";
		toroom = "$n is blown $T by a blast of hot air!";
		destrm = "$n is blown in from $T by a blast of hot air!";
		objmsg = "$p is blown $T.";
		destob = "$p is blown in from $T.";
		break;
	case PULL_COLDWIND:
		tochar = "A bitter cold wind forces you $T!";
		toroom = "$n is forced $T by a bitter cold wind!";
		destrm = "$n is forced in from $T by a bitter cold wind!";
		objmsg = "$p is blown $T.";
		destob = "$p is blown in from $T.";
		break;
	case PULL_WIND:
		tochar = "A strong wind pushes you $T!";
		toroom = "$n is blown $T by a strong wind!";
		destrm = "$n is blown in from $T by a strong wind!";
		objmsg = "$p is blown $T.";
		destob = "$p is blown in from $T.";
		break;
	case PULL_STORM:
		tochar = "The raging storm drives you $T!";
		toroom = "$n is driven $T by the raging storm!";
		destrm = "$n is driven in from $T by a raging storm!";
		objmsg = "$p is blown $T.";
		destob = "$p is blown in from $T.";
		break;
	default:
		if (pull > 0) {
			tochar = "You are pulled $T!";
			toroom = "$n is pulled $T.";
			destrm = "$n is pulled in from $T.";
			objmsg = "$p is pulled $T.";
			objmsg = "$p is pulled in from $T.";
		} else {
			tochar = "You are pushed $T!";
			toroom = "$n is pushed $T.";
			destrm = "$n is pushed in from $T.";
			objmsg = "$p is pushed $T.";
			objmsg = "$p is pushed in from $T.";
		}
		break;
	}


	/* Do the moving */
	if (move) {
		/* display an appropriate exit message */
		if (tochar) {
			act(AT_PLAIN, tochar, ch, NULL, dir_name[xit->vdir], TO_CHAR);
			send_to_char("\n\r", ch);
		}
		if (toroom)
			act(AT_PLAIN, toroom, ch, NULL, dir_name[xit->vdir], TO_ROOM);

		/* display an appropriate entrance message */
		if (destrm && xit->to_room->first_person) {
			act(AT_PLAIN, destrm, xit->to_room->first_person, NULL, dtxt, TO_CHAR);
			act(AT_PLAIN, destrm, xit->to_room->first_person, NULL, dtxt, TO_ROOM);
		}
		/* move the char */
		if (xit->pulltype == PULL_SLIP)
			return (move_char(ch, xit, 1));
		char_from_room(ch);
		char_to_room(ch, xit->to_room);

		if (showroom)
			do_look(ch, "auto");

		/* move the mount too */
		if (ch->mount) {
			char_from_room(ch->mount);
			char_to_room(ch->mount, xit->to_room);
			if (showroom)
				do_look(ch->mount, "auto");
		}
	}
	/* move objects in the room */
	if (moveobj) {
		for (obj = room->first_content; obj; obj = obj_next) {
			obj_next = obj->next_content;

			if (IS_OBJ_STAT(obj, ITEM_BURIED) || !CAN_WEAR(obj, ITEM_TAKE))
				continue;

			resistance = get_obj_weight(obj);
			if (IS_OBJ_STAT(obj, ITEM_METAL))
				resistance = (resistance * 6) / 5;
			switch (obj->item_type) {
			case ITEM_SCROLL:
			case ITEM_NOTE:
			case ITEM_TRASH:
				resistance >>= 2;
				break;
			case ITEM_SCRAPS:
			case ITEM_CONTAINER:
				resistance >>= 1;
				break;
			case ITEM_PEN:
			case ITEM_WAND:
				resistance = (resistance * 5) / 6;
				break;

			case ITEM_CORPSE_PC:
			case ITEM_CORPSE_NPC:
			case ITEM_FOUNTAIN:
				resistance <<= 2;
				break;
			}

			/*
			 * is the pull greater than the resistance of the
			 * object?
			 */
			if ((abs(pull) * 10) > resistance) {
				if (objmsg && room->first_person) {
					act(AT_PLAIN, objmsg, room->first_person, obj, dir_name[xit->vdir], TO_CHAR);
					act(AT_PLAIN, objmsg, room->first_person, obj, dir_name[xit->vdir], TO_ROOM);
				}
				if (destob && xit->to_room->first_person) {
					act(AT_PLAIN, destob, xit->to_room->first_person, obj, dtxt, TO_CHAR);
					act(AT_PLAIN, destob, xit->to_room->first_person, obj, dtxt, TO_ROOM);
				}
				obj_from_room(obj);
				obj_to_room(obj, xit->to_room);
			}
		}
	}
	return (rNONE);
}

/*
 * This function bolts a door. Written by Blackmane
 */

void 
do_bolt(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	EXIT_DATA *pexit;

	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Bolt what?\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, true)) != NULL) {

		if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
			send_to_char("You can't do that.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("It's not closed.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_ISBOLT)) {
			send_to_char("You don't see a bolt.\n\r", ch);
			return;
		}
		if (IS_SET(pexit->exit_info, EX_BOLTED)) {
			send_to_char("It's already bolted.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_SECRET)
		    || (pexit->keyword && nifty_is_name(arg, pexit->keyword))) {
			send_to_char("*Clunk*\n\r", ch);
			act(AT_ACTION, "$n bolts the $d.", ch, NULL, pexit->keyword, TO_ROOM);
			set_bexit_flag(pexit, EX_BOLTED);
			return;
		}
	}
	ch_printf(ch, "You see no %s here.\n\r", arg);
	return;
}



/*
 * This function unbolts a door.  Written by Blackmane
 */

void 
do_unbolt(CHAR_DATA * ch, char *argument)
{
	char arg[MAX_INPUT_LENGTH];
	EXIT_DATA *pexit;

	one_argument(argument, arg);

	if (arg[0] == '\0') {
		send_to_char("Unbolt what?\n\r", ch);
		return;
	}
	if ((pexit = find_door(ch, arg, true)) != NULL) {

		if (!IS_SET(pexit->exit_info, EX_ISDOOR)) {
			send_to_char("You can't do that.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_CLOSED)) {
			send_to_char("It's not closed.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_ISBOLT)) {
			send_to_char("You don't see a bolt.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_BOLTED)) {
			send_to_char("It's already unbolted.\n\r", ch);
			return;
		}
		if (!IS_SET(pexit->exit_info, EX_SECRET)
		    || (pexit->keyword && nifty_is_name(arg, pexit->keyword))) {
			send_to_char("*Clunk*\n\r", ch);
			act(AT_ACTION, "$n unbolts the $d.", ch, NULL, pexit->keyword, TO_ROOM);
			remove_bexit_flag(pexit, EX_BOLTED);
			return;
		}
	}
	ch_printf(ch, "You see no %s here.\n\r", arg);
	return;
}