File: roomkeypaddialog.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (1539 lines) | stat: -rw-r--r-- 43,186 bytes parent folder | download | duplicates (2)
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
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.

--- HISTORICAL COMMENTS FOLLOW ---

 * $Logfile: /DescentIII/Main/editor/roomkeypaddialog.cpp $
 * $Revision: 1.1.1.1 $
 * $Date: 2003-08-26 03:57:38 $
 * $Author: kevinb $
 *
 *	Room keypad
 *
 * $Log: not supported by cvs2svn $
 *
 * 68    10/21/99 1:45p Jeff
 * fixed dialog update bug
 *
 * 67    10/21/99 1:33p Jeff
 * added checkbox to prevent certain rooms from lighting
 *
 * 66    4/29/99 5:44p Chris
 * Added the check for bad center points
 *
 * 65    4/29/99 1:59a Chris
 * Added the portal blockage support
 *
 * 64    4/28/99 1:39p Chris
 * Added the ability to block portals
 *
 * 63    4/24/99 4:32p Jason
 * fixed secret room checkbox
 *
 * 62    4/16/99 1:44p Jason
 * fixed selection of special rooms as goal rooms
 *
 * 61    4/15/99 12:18p Jason
 * made mirrors more robust and able to have multiple mirrored faces in
 * the same room (as long as they are all on the same plane)
 *
 * 60    4/14/99 7:21p Jason
 * added secret room checkbox
 *
 * 59    4/03/99 7:55p Matt
 * Use new keypad update system instead of timer to update.
 *
 * 58    3/31/99 5:15p Matt
 * Added checkboxes on the room tab to control rendering of faces based on
 * shell flag.
 *
 * 57    3/31/99 11:34a Matt
 * Got rid of unused forcefield checkbox on room tab
 *
 * 56    3/30/99 6:25p Matt
 * Use new error system for combine faces function.
 *
 * 55    2/03/99 5:48p Matt
 * Added room damage system
 *
 * 54    1/21/99 11:15p Jeff
 * pulled out some structs and defines from header files and moved them
 * into seperate header files so that multiplayer dlls don't require major
 * game headers, just those new headers.  Side effect is a shorter build
 * time.  Also cleaned up some header file #includes that weren't needed.
 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
 * manage.h and multi.h
 *
 * 53    1/15/99 10:50a Matt
 * Added rename room to Room menu & added shortcut key
 *
 * 52    1/08/99 6:32p Samir
 *
 * 51    1/08/99 5:37p Samir
 * reverb values per room.
 *
 * 50    12/30/98 6:50p Matt
 * Don't add rooms with no name (which may be placed doors) to the room
 * palette list
 *
 * 49    12/22/98 2:03p Matt
 * Added room names, and made rooms not compress so that room numbers are
 * suitable for persistant uses.
 *
 * 48    11/11/98 2:15p Jason
 *
 * 47    11/11/98 2:15p Jason
 * save current room directory
 *
 * 46    10/06/98 6:08p Jason
 * added RF_TRIANGULATE so that special rooms (with non-planar UVS) can be
 * drawn correctly
 *
 * 45    10/04/98 2:35p Matt
 * Added debug options to limit rendering
 *
 * 44    9/28/98 6:09p Jason
 * Corrected appending ORF to rooms
 *
 * 43    9/18/98 8:13p Jason
 * automatically append .orf extension when saving rooms
 *
 * 42    9/07/98 8:04p Matt
 * After combining faces, set curface to marked face.  (Old curface gets
 * deleting when joined.)
 *
 * 41    9/01/98 12:04p Matt
 * Ripped out multi-face portal code
 *
 * 40    8/28/98 6:21p Matt
 * Added a function to flip a face.
 *
 * 39    8/27/98 7:16p Jason
 * changes to dialog
 *
 * 38    8/20/98 12:17p Matt
 * When building ambient sound pattern list, ignore patterns that have
 * been marked as deleted.
 *
 * 37    8/20/98 12:07p Matt
 * Rebuild the ambient sound pattern list whenever we update, since the
 * list can change while the program is running.
 *
 * 36    8/17/98 6:40p Matt
 * Added ambient sound system
 *
 * 35    8/10/98 7:31p Jeff
 * fixed bug with special flag 6
 *
 * 34    7/20/98 4:46p Jason
 * added BOA vis table stuff
 *
 * 33    7/16/98 12:06p Jason
 * added special flags to room structure
 *
 * 32    4/21/98 2:31p Matt
 * When showing what vertex selected, show vert number in addition to
 * index
 *
 * 31    4/10/98 4:12p Jason
 * fixed room loading bug
 *
 * 30    4/10/98 11:52a Jason
 * fixed face splintering bug
 *
 * 29    3/30/98 5:49p Jason
 * fixed selection of faces
 *
 * 28    3/16/98 6:41p Jason
 * added goal room stuff
 *
 * 27    3/06/98 3:23p Jason
 * added lighting from satellites to indoor rooms
 *
 * 26    2/10/98 7:46p Matt
 * Added roompad check boxes for fuelcen and goals
 *
 * 25    2/10/98 1:12p Jason
 * added forcefields and saturating walls
 *
 * 24    1/21/98 12:33p Matt
 * Revamped viewer system
 *
 * 23    1/20/98 4:05p Matt
 * Move BuildListOfPortalVerts() from roomkeypaddialog.cpp to erooms.cpp
 *
 * 22    12/23/97 1:33p Samir
 * Added pserror.h
 *
 * 21    12/02/97 5:31p Samir
 * New file dialog interface implemented.
 *
 * 20    11/05/97 9:31p Jason
 * made render_external_rooms button work
 *
 * 19    10/01/97 7:49p Matt
 * Added "External Room" checkbox on room keypad
 *
 * 18    9/15/97 12:26p Matt
 * When a face is deleted (via combining faces) update markedface if it's
 * changed
 *
 * 17    9/10/97 5:13p Matt
 * Made small portal change to room keypad
 *
 * 16    9/06/97 10:53p Matt
 * Added portal stuff to room keypad
 *
 * 15    9/06/97 3:14p Matt
 * Added button to go to next portal
 * Added seperate face & vert count displays for current room & cur
 * palette room
 * Use new PrintToDsgItem() function
 *
 * 14    9/02/97 12:08p Samir
 * Fixed scrolling.
 *
 * 13    8/29/97 3:57p Samir
 * This should add scrolling support.
 *
 * 12    8/21/97 5:59p Matt
 * Added next vertex & combine faces functions
 *
 * 11    8/04/97 12:48p Matt
 * Use SetMarkedRoom()
 *
 * 10    8/01/97 4:56p Jason
 * added face moving
 *
 * 9     8/01/97 12:50p Jason
 * added code to support scaling of rooms/faces/edges
 *
 * 8     7/31/97 3:31p Jason
 * added functions to rotate portal rooms
 *
 * 7     7/29/97 12:45p Matt
 * Force window redraws when loading or switching rooms
 *
 * 6     7/28/97 5:32p Matt
 * When loading a room, update the keypad dialog, and force the editor
 * into room view
 *
 * 6     6/30/97 1:30p Jason
 * added netherspace stuff
 *
 * 5     6/27/97 4:34p Jason
 * fixed silly bug
 *
 * 4     6/27/97 4:15p Jason
 * added more room functions
 *
 * 3     6/27/97 3:10p Jason
 * added groovy stuff for rooms
 *
 * 2     6/27/97 12:20p Samir
 * Added RCS comment header.
 *
 * $NoKeywords: $
 */

#include "stdafx.h"
#include "editor.h"
#include "RoomKeypadDialog.h"
#include "ddio.h"
#include "erooms.h"
#include "mainfrm.h"
#include "rotateroom.h"
#include "boa.h"
#include "HRoom.h"
#include "pserror.h"
#include "HView.h"
#include "ambient.h"
#include "render.h"
#include "EditLineDialog.h"
#include "hlsoundlib.h"
#include "mem.h"
#include "damage_external.h"
#include "boa.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// list shold match hlsoundlib.h constants.
const char *EnvAudio_PresetNames[N_ENVAUDIO_PRESETS] = {
    "<none>",       "Padded Cell", "Room",    "Bathroom",  "Living Room", "Stone Room", "Auditorium",
    "Concert Hall", "Cave",        "Arena",   "Hangar",    "Carpet Hall", "Hall",       "Stone Corridor",
    "Alley",        "Forest",      "City",    "Mountains", "Quarry",      "Plain",      "Parkinglot",
    "Sewer",        "Underwater",  "Drugged", "Dizzy",     "Psychotic"};

/////////////////////////////////////////////////////////////////////////////
// CRoomKeypadDialog dialog

int CRoomKeypadDialog::m_Instances = 0; // number of instances of this keypad.

CRoomKeypadDialog::CRoomKeypadDialog(CWnd *pParent /*=NULL*/) : CKeypadDialog(CRoomKeypadDialog::IDD, pParent) {
  //{{AFX_DATA_INIT(CRoomKeypadDialog)
  // NOTE: the ClassWizard will add member initialization here
  //}}AFX_DATA_INIT
}

void CRoomKeypadDialog::DoDataExchange(CDataExchange *pDX) {
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CRoomKeypadDialog)
  // NOTE: the ClassWizard will add DDX and DDV calls here
  //}}AFX_DATA_MAP
}

void CRoomKeypadDialog::RunKeypadFunction(int code) {}

//	These functions save information about this dialog's current UI state to the database
void CRoomKeypadDialog::LoadSettings() {}

void CRoomKeypadDialog::SaveSettings() {}

BEGIN_MESSAGE_MAP(CRoomKeypadDialog, CDialog)
//{{AFX_MSG_MAP(CRoomKeypadDialog)
ON_BN_CLICKED(IDC_LOAD_ROOM, OnLoadRoom)
ON_BN_CLICKED(IDC_SAVE_ROOM_LOCALLY, OnSaveRoomLocally)
ON_CBN_SELENDOK(IDC_ROOM_PULLDOWN, OnSelendokRoomPulldown)
ON_WM_PAINT()
ON_WM_HELPINFO()
ON_BN_CLICKED(IDC_MARK_ROOM, OnMarkRoom)
ON_BN_CLICKED(IDC_ROOMPAD_ROTATE_LEFT, OnRoompadRotateLeft)
ON_BN_CLICKED(IDC_ROOMPAD_ROTATE_RIGHT, OnRoompadRotateRight)
ON_BN_CLICKED(IDC_ROOMPAD_PITCH_FORWARD, OnRoompadPitchForward)
ON_BN_CLICKED(IDC_ROOMPAD_PITCH_BACKWARD, OnRoompadPitchBackward)
ON_BN_CLICKED(IDC_ROOMPAD_BANK_RIGHT, OnRoompadBankRight)
ON_BN_CLICKED(IDC_ROOMPAD_BANK_LEFT, OnRoompadBankLeft)
ON_BN_CLICKED(IDC_ROOMPAD_NEXT_EDGE, OnRoompadNextEdge)
ON_BN_CLICKED(IDC_ROOMPAD_EXPAND_ROOM, OnRoompadExpandRoom)
ON_BN_CLICKED(IDC_ROOMPAD_CONTRACT_ROOM, OnRoompadContractRoom)
ON_BN_CLICKED(IDC_ROOMPAD_EXPAND_FACE, OnRoompadExpandFace)
ON_BN_CLICKED(IDC_ROOMPAD_CONTRACT_FACE, OnRoompadContractFace)
ON_BN_CLICKED(IDC_ROOMPAD_EXPAND_EDGE, OnRoompadExpandEdge)
ON_BN_CLICKED(IDC_ROOMPAD_CONTRACT_EDGE, OnRoompadContractEdge)
ON_BN_CLICKED(IDC_ROOMPAD_MOVE_FORWARD, OnRoompadMoveForward)
ON_BN_CLICKED(IDC_ROOMPAD_MOVE_BACKWARD, OnRoompadMoveBackward)
ON_BN_CLICKED(IDC_ROOMPAD_MOVE_RIGHT, OnRoompadMoveRight)
ON_BN_CLICKED(IDC_ROOMPAD_MOVE_LEFT, OnRoompadMoveLeft)
ON_BN_CLICKED(IDC_ROOMPAD_MOVE_UP, OnRoompadMoveUp)
ON_BN_CLICKED(IDC_ROOMPAD_MOVE_DOWN, OnRoompadMoveDown)
ON_BN_CLICKED(IDC_ROOMPAD_NEXT_VERTEX, OnRoompadNextVertex)
ON_BN_CLICKED(IDC_ROOMPAD_COMBINE_FACES, OnRoompadCombineFaces)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_ROOMPAD_NEXT_PORTAL, OnRoompadNextPortal)
ON_BN_CLICKED(IDC_RENDER_PORTAL_FACES, OnRenderPortalFaces)
ON_BN_CLICKED(IDC_ENABLE_PORTAL_FLYTHROUGH, OnEnablePortalFlythrough)
ON_BN_CLICKED(IDC_EXTERNAL_ROOM, OnExternalRoom)
ON_BN_CLICKED(IDC_RENDER_EXTERNAL_ROOMS, OnRenderExternalRooms)
ON_BN_CLICKED(IDC_NEXT_FACE, OnNextFace)
ON_BN_CLICKED(IDC_ROOMPAD_GOAL1, OnRoompadGoal1)
ON_BN_CLICKED(IDC_ROOMPAD_GOAL2, OnRoompadGoal2)
ON_BN_CLICKED(IDC_ROOMPAD_REFUELING_CENTER, OnRoompadRefuelingCenter)
ON_BN_CLICKED(IDC_TOUCHES_OUTSIDE, OnTouchesOutside)
ON_BN_CLICKED(IDC_ROOMPAD_GOAL3, OnRoompadGoal3)
ON_BN_CLICKED(IDC_ROOMPAD_GOAL4, OnRoompadGoal4)
ON_BN_CLICKED(IDC_GOALFACE_CHECK, OnGoalfaceCheck)
ON_BN_CLICKED(IDC_SPECIAL_1, OnSpecial1)
ON_BN_CLICKED(IDC_SPECIAL_2, OnSpecial2)
ON_BN_CLICKED(IDC_SPECIAL_3, OnSpecial3)
ON_BN_CLICKED(IDC_SPECIAL_4, OnSpecial4)
ON_BN_CLICKED(IDC_SPECIAL_5, OnSpecial5)
ON_BN_CLICKED(IDC_SPECIAL_6, OnSpecial6)
ON_BN_CLICKED(IDC_BOA_VIS_BUTTON, OnBoaVisButton)
ON_CBN_SELENDOK(IDC_ROOM_AMBIENT, OnSelendokRoomAmbient)
ON_BN_CLICKED(IDC_MIRROR_BUTTON, OnMirrorButton)
ON_BN_CLICKED(IDC_NO_MIRROR_BUTTON, OnNoMirrorButton)
ON_BN_CLICKED(IDC_ROOMPAD_FLIP_FACE, OnRoompadFlipFace)
ON_BN_CLICKED(IDC_ROOMPAD_NO_DRAW_TERRAIN, OnRoompadNoDrawTerrain)
ON_BN_CLICKED(IDC_ROOMPAD_ONE_ROOM_ONLY, OnRoompadOneRoomOnly)
ON_BN_CLICKED(IDC_TRIANGULATE, OnTriangulate)
ON_BN_CLICKED(IDC_EDIT_NAME, OnEditName)
ON_CBN_SELCHANGE(IDC_ROOM_ENVAUDIO, OnSelchangeRoomEnvaudio)
ON_EN_KILLFOCUS(IDC_ROOMPAD_DAMAGE, OnKillfocusRoompadDamage)
ON_CBN_SELCHANGE(IDC_ROOMPAD_DAMAGETYPE, OnSelchangeRoompadDamageType)
ON_BN_CLICKED(IDC_RENDER_SHELL, OnRenderShell)
ON_BN_CLICKED(IDC_RENDER_NON_SHELL, OnRenderNonShell)
ON_BN_CLICKED(IDC_SECRET_CHECK, OnSecretCheck)
ON_BN_CLICKED(IDC_PORTAL_BLOCKED_CHECK, OnPortalBlockedCheck)
ON_BN_CLICKED(IDC_PORTAL_BLOCKED_CAN_GO_AWAY_CHECK, OnPortalBlockedCanGoAwayCheck)
ON_BN_CLICKED(IDC_BAD_CENTERPOINTS, OnBadCenterpoints)
ON_BN_CLICKED(IDC_ROOM_SKIP_LIGHTING, OnRoomSkipLighting)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRoomKeypadDialog message handlers

void CRoomKeypadDialog::OnLoadRoom() {
  char filename[255];
  int c = 1, finding_name = 1;

  CString filter = "Descent III room files (*.orf)|*.orf||";

  if (!OpenFileDialog(this, (LPCSTR)filter, filename, Current_room_dir, sizeof(Current_room_dir)))
    return;

  char name[255];
  char path[255];
  char extension[255];
  char roomname[255];
  int find_new = 0;

  // Find a unique name for this room
  ddio_SplitPath(filename, path, name, extension);
  int done = 0;
  int count = 1;

  strcpy(Current_room_dir, path);

  sprintf(roomname, "%s.ORF", name);

  int val = FindRoomName(roomname);

  if (val != -1) {
    int answer =
        MessageBox("Do you wish to overwrite the room in memory that already has this name?", roomname, MB_YESNO);
    if (answer == IDYES)
      FreeRoom(&Rooms[val]);
    else
      find_new = 1;
  }

  //	Okay, we selected a file. Lets do what needs to be done here.
  int n = AllocLoadRoom(filename);

  if (n < 0) {
    OutrageMessageBox("Couldn't load that room for some reason.");
    return;
  }

  while (!done && find_new) {
    val = FindRoomName(roomname);
    if (val == -1) {
      done = 1;
      continue;
    }
    count++;
    sprintf(roomname, "%s%d.ORF", name, count);
  }

  ASSERT(Rooms[n].name == NULL);
  Rooms[n].name = (char *)mem_malloc(strlen(roomname) + 1);
  strcpy(Rooms[n].name, roomname);

  D3EditState.current_room = n;

  // Update keypad
  UpdateDialog();

  // Force into room view
  ResetRoomViewer();
  SetViewMode(VM_ROOM);

  // Force window updates
  State_changed = 1;
}

void CRoomKeypadDialog::OnSaveRoomLocally() {
  char filename[255];

  if (Curroomp == NULL || Curroomp->used == 0) {
    OutrageMessageBox("No valid room selected for saving!");
    return;
  }

  CString filter = "Descent III room files (*.orf)|*.orf||";

  if (!SaveFileDialog(this, (LPCSTR)filter, filename, Current_weapon_dir, sizeof(Current_weapon_dir)))
    return;

  int len = strlen(filename);
  if (filename[len - 4] != '.' || filename[len - 3] != 'o' || filename[len - 2] != 'r' || filename[len - 1] != 'f')
    strcat(filename, ".orf");

  // Save it out to disk (locally)
  SaveRoom(Curroomp - Rooms, filename);
  OutrageMessageBox("Room saved.");
}

void CRoomKeypadDialog::OnSelendokRoomPulldown() {
  int i, cur;
  char name[200];

  cur = SendDlgItemMessage(IDC_ROOM_PULLDOWN, CB_GETCURSEL, 0, 0);
  SendDlgItemMessage(IDC_ROOM_PULLDOWN, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name);

  i = FindRoomName(name);

  if (i == -1) {
    mprintf(0, "Possible corrupted room list, but probably nothing.");
    UpdateDialog();
  }

  D3EditState.current_room = i;
  UpdateDialog();

  ResetRoomViewer();

  // Force window updates
  State_changed = 1;
}

#define NULL_NAME "<none>"

void CRoomKeypadDialog::UpdateDialog() {
  int i;

  // Show the number of verts, faces, & portals in the current room
  PrintToDlgItem(this, IDC_ROOM_NAME, "Name:\t%s", Curroomp->name ? Curroomp->name : "<none>");
  PrintToDlgItem(this, IDC_VERTEX_COUNT, "Vertices:\t%d", Curroomp->num_verts);
  PrintToDlgItem(this, IDC_FACE_COUNT, "Faces:\t%d", Curroomp->num_faces);
  PrintToDlgItem(this, IDC_PORTAL_COUNT, "Portals:\t%d", Curroomp->num_portals);

  // Show flags
  ((CButton *)GetDlgItem(IDC_EXTERNAL_ROOM))->SetCheck(Curroomp->flags & RF_EXTERNAL);
  ((CButton *)GetDlgItem(IDC_ROOM_SKIP_LIGHTING))->SetCheck((Curroomp->flags & RF_NO_LIGHT) ? 1 : 0);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_REFUELING_CENTER))->SetCheck(Curroomp->flags & RF_FUELCEN);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_GOAL1))->SetCheck(Curroomp->flags & RF_GOAL1);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_GOAL2))->SetCheck(Curroomp->flags & RF_GOAL2);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_GOAL3))->SetCheck(Curroomp->flags & RF_GOAL3);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_GOAL4))->SetCheck(Curroomp->flags & RF_GOAL4);
  ((CButton *)GetDlgItem(IDC_SPECIAL_1))->SetCheck(Curroomp->flags & RF_SPECIAL1);
  ((CButton *)GetDlgItem(IDC_SPECIAL_2))->SetCheck(Curroomp->flags & RF_SPECIAL2);
  ((CButton *)GetDlgItem(IDC_SPECIAL_3))->SetCheck(Curroomp->flags & RF_SPECIAL3);
  ((CButton *)GetDlgItem(IDC_SPECIAL_4))->SetCheck(Curroomp->flags & RF_SPECIAL4);
  ((CButton *)GetDlgItem(IDC_SPECIAL_5))->SetCheck(Curroomp->flags & RF_SPECIAL5);
  ((CButton *)GetDlgItem(IDC_SPECIAL_6))->SetCheck(Curroomp->flags & RF_SPECIAL6);
  ((CButton *)GetDlgItem(IDC_TRIANGULATE))->SetCheck(Curroomp->flags & RF_TRIANGULATE);
  ((CButton *)GetDlgItem(IDC_TOUCHES_OUTSIDE))->SetCheck(Curroomp->flags & RF_TOUCHES_TERRAIN);

  if (Curroomp->flags & RF_SECRET)
    ((CButton *)GetDlgItem(IDC_SECRET_CHECK))->SetCheck(1);
  else
    ((CButton *)GetDlgItem(IDC_SECRET_CHECK))->SetCheck(0);

  // Show flags
  ((CButton *)GetDlgItem(IDC_EXTERNAL_ROOM))->SetCheck(Curroomp->flags & RF_EXTERNAL);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_NO_DRAW_TERRAIN))->SetCheck(Render_inside_only);
  ((CButton *)GetDlgItem(IDC_ROOMPAD_ONE_ROOM_ONLY))->SetCheck(Render_one_room_only);
  ((CButton *)GetDlgItem(IDC_ROOM_SKIP_LIGHTING))->SetCheck((Curroomp->flags & RF_NO_LIGHT) ? 1 : 0);

  // set forcefield check
  //@@((CButton *) GetDlgItem(IDC_FORCEFIELD_CHECK))->SetCheck(Curroomp->faces[Curface].flags & FF_FORCEFIELD);
  ((CButton *)GetDlgItem(IDC_GOALFACE_CHECK))->SetCheck(Curroomp->faces[Curface].flags & FF_GOALFACE);
  PrintToDlgItem(this, IDC_CURRENT_FACE, "Current face: %d", Curface);

  // Enable/disable the next portal button
  ((CButton *)GetDlgItem(IDC_ROOMPAD_NEXT_PORTAL))
      ->EnableWindow(((Curportal == -1) && (Curroomp->num_portals > 0)) || (Curroomp->num_portals > 1));

  // Enable/disable the portal items
  ((CButton *)GetDlgItem(IDC_CURRENT_PORTAL))->EnableWindow(Curportal != -1);
  ((CButton *)GetDlgItem(IDC_RENDER_PORTAL_FACES))->EnableWindow(Curportal != -1);
  ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CHECK))->EnableWindow(Curportal != -1);
  ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CAN_GO_AWAY_CHECK))->EnableWindow(Curportal != -1);

  // Set shell render checkboxes
  ((CButton *)GetDlgItem(IDC_RENDER_SHELL))->SetCheck(!(Shell_render_flag & SRF_NO_SHELL));
  ((CButton *)GetDlgItem(IDC_RENDER_NON_SHELL))->SetCheck(!(Shell_render_flag & SRF_NO_NON_SHELL));

  // Update the portal number & checkboxes
  if (Curportal != -1) {
    portal *pp = &Curroomp->portals[Curportal];

    ASSERT(Curportal < Curroomp->num_portals);

    PrintToDlgItem(this, IDC_CURRENT_PORTAL, "Portal:\t%d", Curportal);
    ((CButton *)GetDlgItem(IDC_RENDER_PORTAL_FACES))->SetCheck(pp->flags & PF_RENDER_FACES);
    ((CButton *)GetDlgItem(IDC_ENABLE_PORTAL_FLYTHROUGH))->SetCheck(pp->flags & PF_RENDERED_FLYTHROUGH);
    ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CHECK))->SetCheck(pp->flags & PF_BLOCK);
    ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CAN_GO_AWAY_CHECK))->SetCheck(pp->flags & PF_BLOCK_REMOVABLE);

    // if render faces is on, enable the rendered flythrough checkbox
    ((CButton *)GetDlgItem(IDC_ENABLE_PORTAL_FLYTHROUGH))->EnableWindow(pp->flags & PF_RENDER_FACES);
    ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CAN_GO_AWAY_CHECK))->EnableWindow(pp->flags & PF_BLOCK);
  } else {
    ((CButton *)GetDlgItem(IDC_ENABLE_PORTAL_FLYTHROUGH))->EnableWindow(0);
    ((CButton *)GetDlgItem(IDC_RENDER_PORTAL_FACES))->SetCheck(0);
    ((CButton *)GetDlgItem(IDC_ENABLE_PORTAL_FLYTHROUGH))->SetCheck(0);
    ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CHECK))->SetCheck(0);
    ((CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CAN_GO_AWAY_CHECK))->SetCheck(0);
  }

  // Build the ambient sound list
  SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_RESETCONTENT, 0, 0);
  SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME);
  for (i = 0; i < Num_ambient_sound_patterns; i++)
    if (Ambient_sound_patterns[i].name[0])
      SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)AmbientSoundPatternName(i));
  SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME);

  // Set the current ambient sound pattern
  SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_SELECTSTRING, 0,
                     (LPARAM)(LPCTSTR)((Curroomp->ambient_sound == -1)
                                           ? NULL_NAME
                                           : AmbientSoundPatternName(Curroomp->ambient_sound)));

  // Build environmental presets list
  ((CComboBox *)GetDlgItem(IDC_ROOM_ENVAUDIO))
      ->SelectString(-1, EnvAudio_PresetNames[(Curroomp->env_reverb < N_ENVAUDIO_PRESETS) ? Curroomp->env_reverb : 0]);

  // Update Mirror Stuff
  char str[255];
  if (Curroomp->mirror_face == -1)
    strcpy(str, "None");
  else
    sprintf(str, "%d", Curroomp->mirror_face);

  PrintToDlgItem(this, IDC_MIRROR_FACE_TEXT, "Current mirror face:\t%s", str);

  // Update the damage
  CEdit *box = (CEdit *)GetDlgItem(IDC_ROOMPAD_DAMAGE);
  sprintf(str, "%.2f", Curroomp->damage);
  box->SetWindowText(str);

  // Update the damage type
  CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ROOMPAD_DAMAGETYPE);
  int n = cbox->GetCount();
  for (i = 0; i < n; i++) {
    if (cbox->GetItemData(i) == Curroomp->damage_type) {
      cbox->SetCurSel(i);
      break;
    }
  }
  ASSERT(i < n);

  // Get current room in palette
  n = D3EditState.current_room;
  if ((n == -1) || !Rooms[n].used)                 // no current room?
    n = D3EditState.current_room = GetNextRoom(n); //..try to get one

  // Update palette room stuff
  if (n != -1) {

    // Show the number of verts & faces in the current palette room
    PrintToDlgItem(this, IDC_PALETTE_VERTEX_COUNT, "Vertices:\t%d", Rooms[n].num_verts);
    PrintToDlgItem(this, IDC_PALETTE_FACE_COUNT, "Faces:\t%d", Rooms[n].num_faces);

    // Update the list of palette rooms
    SendDlgItemMessage(IDC_ROOM_PULLDOWN, CB_RESETCONTENT, 0, 0);

    for (int i = FIRST_PALETTE_ROOM; i < FIRST_PALETTE_ROOM + MAX_PALETTE_ROOMS; i++) {
      if (Rooms[i].used && Rooms[i].name) // if a placed door, won't have a name
        SendDlgItemMessage(IDC_ROOM_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Rooms[i].name);
    }
    SendDlgItemMessage(IDC_ROOM_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Rooms[n].name);
  }
}

void CRoomKeypadDialog::OnPaint() {
  CPaintDC dc(this); // device context for painting

  UpdateDialog();

  // Do not call CDialog::OnPaint() for painting messages
}

BOOL CRoomKeypadDialog::OnHelpInfo(HELPINFO *pHelpInfo) {
  // TODO: Add your message handler code here and/or call default
  WinHelp(HID_ROOMTAB, HELP_CONTEXT);
  return TRUE;
  // return CDialog::OnHelpInfo(pHelpInfo);
}

void CRoomKeypadDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
  CKeypadDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CRoomKeypadDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
  CKeypadDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CRoomKeypadDialog::OnSize(UINT nType, int cx, int cy) { CKeypadDialog::OnSize(nType, cx, cy); }

/////////////////////////////////////////////////////////////////////////////
// helper functions

// Goes through all the vertices in the room and scales them by scale_factor
void SizeRoomVertices(room *rp, float scale_factor) {
  vector room_center;
  vector vec;
  int portal_list[MAX_VERTS_PER_ROOM];
  int i, t, ok_to_scale;
  int num_portal_verts;

  ASSERT(rp->used > 0);

  num_portal_verts = BuildListOfPortalVerts(rp, portal_list);

  ComputeRoomCenter(&room_center, rp);

  for (i = 0; i < rp->num_verts; i++) {
    for (ok_to_scale = 1, t = 0; t < num_portal_verts; t++) {
      if (portal_list[t] == i) {
        ok_to_scale = 0;
        break;
      }
    }

    if (ok_to_scale) {
      vec = rp->verts[i] - room_center;
      vec *= scale_factor;
      rp->verts[i] = vec + room_center;
    }
  }
}

// Goes through all the vertices in a face and scales them by scale_factor
void SizeFaceVertices(room *rp, int facenum, float scale_factor) {
  vector face_center;
  vector vec;
  int portal_list[MAX_VERTS_PER_ROOM];
  int face_list[MAX_FACES_PER_ROOM];
  int i, t, ok_to_scale, k;
  int num_portal_verts;
  int facecount = 0;
  face *fp = &rp->faces[facenum];

  ASSERT(rp->used > 0);

  num_portal_verts = BuildListOfPortalVerts(rp, portal_list);

  ComputeCenterPointOnFace(&face_center, rp, facenum);

  for (i = 0; i < fp->num_verts; i++) {
    int vertnum = fp->face_verts[i];

    for (ok_to_scale = 1, t = 0; t < num_portal_verts; t++) {
      if (portal_list[t] == vertnum) {
        ok_to_scale = 0;
        break;
      }
    }

    if (ok_to_scale) {
      vec = rp->verts[vertnum] - face_center;
      vec *= scale_factor;
      rp->verts[vertnum] = vec + face_center;
    }
  }

  // Build a list of faces that share vertices with this face
  for (i = 0; i < rp->num_faces; i++) {
    for (t = 0; t < rp->faces[i].num_verts; t++) {
      for (k = 0; k < fp->num_verts; k++) {
        if (fp->face_verts[k] == rp->faces[i].face_verts[t]) {
          face_list[facecount] = i;
          facecount++;
        }
      }
    }
  }

  // Now fixup any concave/nonplanar faces
  FixConcaveFaces(rp, face_list, facecount);
}

void SizeFaceEdge(room *rp, int facenum, int edge, float scale_factor) {
  vector line_center;
  vector vec;
  int portal_list[MAX_VERTS_PER_ROOM];
  int face_list[MAX_FACES_PER_ROOM];
  int i, t, ok_to_scale;
  int num_portal_verts;
  int facecount = 0;
  face *fp = &rp->faces[facenum];
  int nextedge, vert, nextvert;

  nextedge = (edge + 1) % fp->num_verts;
  vert = fp->face_verts[edge];
  nextvert = fp->face_verts[nextedge];

  ASSERT(rp->used > 0);

  num_portal_verts = BuildListOfPortalVerts(rp, portal_list);

  line_center = ((rp->verts[nextvert] - rp->verts[vert]) / 2) + rp->verts[vert];

  for (ok_to_scale = 1, t = 0; t < num_portal_verts; t++)
    if (portal_list[t] == vert)
      ok_to_scale = 0;

  if (ok_to_scale) {
    vec = rp->verts[vert] - line_center;
    vec *= scale_factor;
    rp->verts[vert] = vec + line_center;
  }

  for (ok_to_scale = 1, t = 0; t < num_portal_verts; t++)
    if (portal_list[t] == nextvert)
      ok_to_scale = 0;

  if (ok_to_scale) {
    vec = rp->verts[nextvert] - line_center;
    vec *= scale_factor;
    rp->verts[nextvert] = vec + line_center;
  }

  // Build a list of faces that share vertices with this edge
  for (i = 0; i < rp->num_faces; i++) {
    for (t = 0; t < rp->faces[i].num_verts; t++) {
      if (rp->faces[i].face_verts[t] == vert || rp->faces[i].face_verts[t] == nextvert) {
        face_list[facecount] = i;
        facecount++;
      }
    }
  }

  // Now fixup any concave/nonplanar faces
  FixConcaveFaces(rp, face_list, facecount);
}

// moves a face of a room by a delta amount
void MoveRoomFace(room *rp, int facenum, float dx, float dy, float dz) {
  matrix facematrix;
  vector norm = -rp->faces[facenum].normal;

  int face_list[MAX_FACES_PER_ROOM];
  int portal_list[MAX_VERTS_PER_ROOM];
  int i, t, ok_to_scale, k, touches_portal = 0;
  int num_portal_verts;
  int facecount = 0;
  face *fp = &rp->faces[facenum];

  ASSERT(rp->used > 0);
  ASSERT(facenum >= 0 && facenum < rp->num_faces);

  num_portal_verts = BuildListOfPortalVerts(rp, portal_list);

  vm_VectorToMatrix(&facematrix, &norm, NULL, NULL);

  for (i = 0; i < fp->num_verts; i++) {
    for (ok_to_scale = 1, t = 0; t < num_portal_verts; t++) {
      if (portal_list[t] == fp->face_verts[i]) {
        ok_to_scale = 0;
        touches_portal = 1;
      }
    }

    if (ok_to_scale) {
      rp->verts[fp->face_verts[i]] += (facematrix.rvec * dx);
      rp->verts[fp->face_verts[i]] += (facematrix.uvec * dy);
      rp->verts[fp->face_verts[i]] += (facematrix.fvec * dz);
    }
  }

  // Build a list of faces that share vertices with this edge
  for (i = 0; i < rp->num_faces; i++) {
    if (i == facenum && touches_portal == 0)
      continue;

    for (t = 0; t < rp->faces[i].num_verts; t++) {
      for (k = 0; k < fp->num_verts; k++) {
        if (fp->face_verts[k] == rp->faces[i].face_verts[t]) {
          face_list[facecount] = i;
          facecount++;
        }
      }
    }
  }

  // Now fixup any concave/nonplanar faces
  FixConcaveFaces(rp, face_list, facecount);
}

void CRoomKeypadDialog::OnMarkRoom() { SetMarkedRoom(); }

void CRoomKeypadDialog::OnRoompadRotateLeft() { RotateRooms(0, (angle)-512, 0); }

void CRoomKeypadDialog::OnRoompadRotateRight() { RotateRooms(0, (angle)512, 0); }

void CRoomKeypadDialog::OnRoompadPitchForward() { RotateRooms((angle)512, 0, 0); }

void CRoomKeypadDialog::OnRoompadPitchBackward() { RotateRooms((angle)-512, 0, 0); }

void CRoomKeypadDialog::OnRoompadBankRight() { RotateRooms(0, 0, (angle)512); }

void CRoomKeypadDialog::OnRoompadBankLeft() { RotateRooms(0, 0, (angle)-512); }

void CRoomKeypadDialog::OnRoompadNextEdge() {
  Curedge++;
  if (Curedge >= Curroomp->faces[Curface].num_verts)
    Curedge = 0;

  EditorStatus("Edge %d selected.", Curedge);

  State_changed = 1;
}

void CRoomKeypadDialog::OnRoompadNextVertex() {
  if (++Curvert >= Curroomp->faces[Curface].num_verts)
    Curvert = 0;

  EditorStatus("Vertex %d (%d) selected.", Curvert, Curroomp->faces[Curface].face_verts[Curvert]);

  State_changed = 1;
}

void CRoomKeypadDialog::OnRoompadExpandRoom() {
  if (Curroomp == NULL)
    return;

  SizeRoomVertices(Curroomp, 1.05f);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadContractRoom() {
  if (Curroomp == NULL)
    return;

  SizeRoomVertices(Curroomp, .95f);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadExpandFace() {
  if (Curroomp == NULL || Curface < 0 || Curface >= Curroomp->num_faces)
    return;

  SizeFaceVertices(Curroomp, Curface, 1.05f);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadContractFace() {
  if (Curroomp == NULL || Curface < 0 || Curface >= Curroomp->num_faces)
    return;

  SizeFaceVertices(Curroomp, Curface, .95f);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadExpandEdge() {

  if (Curroomp == NULL || Curface < 0 || Curface >= Curroomp->num_faces)
    return;

  SizeFaceEdge(Curroomp, Curface, Curedge, 1.05f);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadContractEdge() {
  if (Curroomp == NULL || Curface < 0 || Curface >= Curroomp->num_faces)
    return;

  SizeFaceEdge(Curroomp, Curface, Curedge, .95f);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadMoveForward() {
  MoveRoomFace(Curroomp, Curface, 0, 0, 1);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadMoveBackward() {
  MoveRoomFace(Curroomp, Curface, 0, 0, -1);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadMoveRight() {
  MoveRoomFace(Curroomp, Curface, 1, 0, 0);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadMoveLeft() {
  MoveRoomFace(Curroomp, Curface, -1, 0, 0);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadMoveUp() {
  MoveRoomFace(Curroomp, Curface, 0, 1, 0);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadMoveDown() {
  MoveRoomFace(Curroomp, Curface, 0, -1, 0);
  World_changed = 1;
}

void CRoomKeypadDialog::OnRoompadCombineFaces() {
  if (Markedroomp == NULL) {
    OutrageMessageBox("You must have a marked face for this operation.");
    return;
  }

  if (Markedroomp != Curroomp) {
    OutrageMessageBox("The marked face and current face must be in the same room for this operation.");
    return;
  }

  if (Markedface == Curface) {
    OutrageMessageBox("The marked face and current face cannot be the same for this operation.");
    return;
  }

  // Combine the faces
  if (!CombineFaces(Curroomp, Markedface, Curface)) {
    OutrageMessageBox("Cannot combine faces: %s", GetErrorMessage());
    return;
  }

  // Fix marked face, if the number has changed
  if (Curface < Markedface)
    Markedface--;

  // Reset curface, which should no longer exist
  Curface = Markedface;
  Curedge = Curvert = 0;
}

void CRoomKeypadDialog::OnRoompadNextPortal() {
  if (Curroomp->num_portals) {
    Curportal = (Curportal + 1) % Curroomp->num_portals;
    portal *pp = &Curroomp->portals[Curportal];
    Curface = pp->portal_face;
    EditorStatus("Portal %d selected.  Face %d selected.", Curportal, Curface);
    State_changed = 1;
    UpdateDialog();
  }
}

BOOL CRoomKeypadDialog::OnInitDialog() {
  CDialog::OnInitDialog();

  int i;

  // set up reverb dropdown listbox
  CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ROOM_ENVAUDIO);
  cbox->ResetContent();
  for (i = 0; i < N_ENVAUDIO_PRESETS; i++) {
    cbox->AddString(EnvAudio_PresetNames[i]);
  }

  // Set up damage type dialog
  CComboBox *box = (CComboBox *)GetDlgItem(IDC_ROOMPAD_DAMAGETYPE);
  i = box->AddString("None");
  box->SetItemData(i, PD_NONE);
  i = box->AddString("Energy Weapon");
  box->SetItemData(i, PD_ENERGY_WEAPON);
  i = box->AddString("Matter Weapon");
  box->SetItemData(i, PD_MATTER_WEAPON);
  i = box->AddString("Melee Attach");
  box->SetItemData(i, PD_MELEE_ATTACK);
  i = box->AddString("Concussive Force");
  box->SetItemData(i, PD_CONCUSSIVE_FORCE);
  i = box->AddString("Wall Hit");
  box->SetItemData(i, PD_WALL_HIT);

  return TRUE; // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

void CRoomKeypadDialog::UpdateKeypad(int mask) {
  if (mask & (KUF_CURROOM_CHANGED + KUF_CURFACE_CHANGED))
    UpdateDialog();
}

void CRoomKeypadDialog::OnRenderPortalFaces() {
  CButton *btn;
  portal *pp = &Curroomp->portals[Curportal];

  btn = (CButton *)GetDlgItem(IDC_RENDER_PORTAL_FACES);

  if (btn->GetCheck())
    pp->flags |= PF_RENDER_FACES;
  else
    pp->flags &= ~PF_RENDER_FACES;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnEnablePortalFlythrough() {
  CButton *btn;
  portal *pp = &Curroomp->portals[Curportal];

  btn = (CButton *)GetDlgItem(IDC_ENABLE_PORTAL_FLYTHROUGH);

  if (btn->GetCheck())
    pp->flags |= PF_RENDERED_FLYTHROUGH;
  else
    pp->flags &= ~PF_RENDERED_FLYTHROUGH;

  World_changed = 1;
}

void CRoomKeypadDialog::OnExternalRoom() {
  CButton *btn;
  portal *pp = &Curroomp->portals[Curportal];

  btn = (CButton *)GetDlgItem(IDC_EXTERNAL_ROOM);

  if (btn->GetCheck())
    Curroomp->flags |= RF_EXTERNAL;
  else
    Curroomp->flags &= ~RF_EXTERNAL;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadRefuelingCenter() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_ROOMPAD_REFUELING_CENTER);

  if (btn->GetCheck())
    Curroomp->flags |= RF_FUELCEN;
  else
    Curroomp->flags &= ~RF_FUELCEN;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadGoal1() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_ROOMPAD_GOAL1);

  if (btn->GetCheck())
    Curroomp->flags |= RF_GOAL1;
  else
    Curroomp->flags &= ~RF_GOAL1;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadGoal2() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_ROOMPAD_GOAL2);

  if (btn->GetCheck())
    Curroomp->flags |= RF_GOAL2;
  else
    Curroomp->flags &= ~RF_GOAL2;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRenderExternalRooms() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_RENDER_EXTERNAL_ROOMS);

  if (btn->GetCheck())
    Render_all_external_rooms = 1;
  else
    Render_all_external_rooms = 0;

  State_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnNextFace() {
  if (++Curface >= Curroomp->num_faces)
    Curface = 0;

  EditorStatus("Face %d selected.", Curface);
  UpdateDialog();

  State_changed = 1;
}

void CRoomKeypadDialog::OnTouchesOutside() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_TOUCHES_OUTSIDE);

  if (btn->GetCheck())
    Curroomp->flags |= RF_TOUCHES_TERRAIN;
  else
    Curroomp->flags &= ~RF_TOUCHES_TERRAIN;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadGoal3() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_ROOMPAD_GOAL3);

  if (btn->GetCheck())
    Curroomp->flags |= RF_GOAL3;
  else
    Curroomp->flags &= ~RF_GOAL3;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadGoal4() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_ROOMPAD_GOAL4);

  if (btn->GetCheck())
    Curroomp->flags |= RF_GOAL4;
  else
    Curroomp->flags &= ~RF_GOAL4;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnGoalfaceCheck() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_GOALFACE_CHECK);

  if (btn->GetCheck()) {
    if (!(Curroomp->flags & GOALROOM | RF_SPECIAL1 | RF_SPECIAL2 | RF_SPECIAL3 | RF_SPECIAL4 | RF_SPECIAL5 |
          RF_SPECIAL6)) {
      OutrageMessageBox("This room needs to marked as a goal first.");
    } else
      Curroomp->faces[Curface].flags |= FF_GOALFACE;
  } else
    Curroomp->faces[Curface].flags &= ~FF_GOALFACE;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSpecial1() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SPECIAL_1);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SPECIAL1;
  else
    Curroomp->flags &= ~RF_SPECIAL1;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSpecial2() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SPECIAL_2);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SPECIAL2;
  else
    Curroomp->flags &= ~RF_SPECIAL2;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSpecial3() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SPECIAL_3);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SPECIAL3;
  else
    Curroomp->flags &= ~RF_SPECIAL3;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSpecial4() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SPECIAL_4);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SPECIAL4;
  else
    Curroomp->flags &= ~RF_SPECIAL4;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSpecial5() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SPECIAL_5);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SPECIAL5;
  else
    Curroomp->flags &= ~RF_SPECIAL5;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSpecial6() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SPECIAL_6);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SPECIAL6;
  else
    Curroomp->flags &= ~RF_SPECIAL6;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnBoaVisButton() {
  int answer = MessageBox("Do you wish compute the BOA vis table?", "Question", MB_YESNO);

  if (answer == IDNO)
    return;

  MakeBOAVisTable();
}

void CRoomKeypadDialog::OnSelendokRoomAmbient() {
  int cur;
  char name[200];

  cur = SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_GETCURSEL, 0, 0);
  SendDlgItemMessage(IDC_ROOM_AMBIENT, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name);

  Curroomp->ambient_sound = FindAmbientSoundPattern(name);

  World_changed = 1;
}

void CRoomKeypadDialog::OnMirrorButton() {
  if (Curroomp == NULL)
    return;
  Curroomp->mirror_face = Curface;
  ConsolidateMineMirrors();
  UpdateDialog();
}

void CRoomKeypadDialog::OnNoMirrorButton() {
  if (Curroomp == NULL)
    return;
  Curroomp->mirror_face = -1;
  ConsolidateMineMirrors();
  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadFlipFace() {
  if (Curroomp->faces[Curface].portal_num != -1) {
    OutrageMessageBox("You cannot flip a portal face.");
    return;
  }

  if (OutrageMessageBox(MBOX_YESNO, "Are you sure you want to flip the current face?") != IDYES)
    return;

  // Flip the face
  FlipFace(Curroomp, Curface);
}

void CRoomKeypadDialog::OnRoompadNoDrawTerrain() {
  CButton *btn = (CButton *)GetDlgItem(IDC_ROOMPAD_NO_DRAW_TERRAIN);

  Render_inside_only = (btn->GetCheck() != 0);

  State_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRoompadOneRoomOnly() {
  CButton *btn = (CButton *)GetDlgItem(IDC_ROOMPAD_ONE_ROOM_ONLY);

  Render_one_room_only = (btn->GetCheck() != 0);

  State_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnTriangulate() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_TRIANGULATE);

  if (btn->GetCheck())
    Curroomp->flags |= RF_TRIANGULATE;
  else
    Curroomp->flags &= ~RF_TRIANGULATE;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnEditName() {
  extern void RenameRoom();

  RenameRoom();

  UpdateDialog();
}

///////////////////////////////////////////////////////////////////////

void CRoomKeypadDialog::OnSelchangeRoomEnvaudio() {
  CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_ROOM_ENVAUDIO);
  CString selection;
  int i;

  cbox->GetLBText(cbox->GetCurSel(), selection);

  for (i = 0; i < N_ENVAUDIO_PRESETS; i++) {
    if (selection == EnvAudio_PresetNames[i]) {
      Curroomp->env_reverb = i;
      break;
    }
  }
}

void CRoomKeypadDialog::OnKillfocusRoompadDamage() {
  char buf[128];

  CEdit *box = (CEdit *)GetDlgItem(IDC_ROOMPAD_DAMAGE);

  box->GetWindowText(buf, sizeof(buf));

  Curroomp->damage = atof(buf);

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSelchangeRoompadDamageType() {
  CComboBox *box = (CComboBox *)GetDlgItem(IDC_ROOMPAD_DAMAGETYPE);

  Curroomp->damage_type = (int8_t)box->GetItemData(box->GetCurSel());
}

void CRoomKeypadDialog::OnRenderShell() {
  Shell_render_flag ^= SRF_NO_SHELL;

  State_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnRenderNonShell() {
  Shell_render_flag ^= SRF_NO_NON_SHELL;

  State_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnSecretCheck() {
  CButton *btn;

  btn = (CButton *)GetDlgItem(IDC_SECRET_CHECK);

  if (btn->GetCheck())
    Curroomp->flags |= RF_SECRET;
  else
    Curroomp->flags &= ~RF_SECRET;

  World_changed = 1;

  UpdateDialog();
}

void CRoomKeypadDialog::OnPortalBlockedCheck() {
  CButton *btn;
  portal *pp = &Curroomp->portals[Curportal];

  btn = (CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CHECK);

  portal *np = &Rooms[Curroomp->portals[Curportal].croom].portals[Curroomp->portals[Curportal].cportal];

  if (btn->GetCheck()) {
    pp->flags |= PF_BLOCK;
    np->flags |= PF_BLOCK;
  } else {
    pp->flags &= ~PF_BLOCK;
    np->flags &= ~PF_BLOCK;
  }

  World_changed = 1;
}

void CRoomKeypadDialog::OnPortalBlockedCanGoAwayCheck() {
  CButton *btn;
  portal *pp = &Curroomp->portals[Curportal];

  btn = (CButton *)GetDlgItem(IDC_PORTAL_BLOCKED_CAN_GO_AWAY_CHECK);

  if (btn->GetCheck())
    pp->flags |= PF_BLOCK_REMOVABLE;
  else
    pp->flags &= ~PF_BLOCK_REMOVABLE;

  World_changed = 1;
}

void CRoomKeypadDialog::OnBadCenterpoints() {
  char message[10000];
  message[0] = '\0';

  mprintf(0, "Computing bad centers\n");
  BOA_ComputePathPoints(message, 10000);
  mprintf(0, "Done computing bad centers... List in clipboard.\n");
  DumpTextToClipboard(message);
}

void CRoomKeypadDialog::OnRoomSkipLighting() {
  CButton *btn = (CButton *)GetDlgItem(IDC_ROOM_SKIP_LIGHTING);

  if (btn->GetCheck()) {
    Curroomp->flags |= RF_NO_LIGHT;
  } else {
    Curroomp->flags &= ~RF_NO_LIGHT;
  }

  World_changed = 1;
  UpdateDialog();
}