-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCSBUI.cpp
More file actions
2366 lines (2198 loc) · 56.3 KB
/
CSBUI.cpp
File metadata and controls
2366 lines (2198 loc) · 56.3 KB
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
#include "stdafx.h"
#include "resource.h"
#ifdef _MSVC_INTEL //001
#pragma warning(disable:4201) //Allow nameless struct
#include <mmsystem.h>
#pragma warning(default:4201)
#endif //001
//#define WIN32_SOUNDMIXER
#include <stdio.h>
//typedef DWORD *DWORD_PTR; // Needed by dsound.h
#if defined(_MSC_VER) //002
#include <dsound.h>
#include <io.h>
#include <FCNTL.h>
#include <SYS\STAT.h>
#else
// ROQUEN: Not reasonable
#include <unistd.h>
#include <string.h>
#endif //002
#include "UI.h"
//#include "Objects.h"
#include "Dispatch.h"
#include "CSB.h"
#include "Data.h"
extern i32 updateScreenAreaEnterCount;
extern i32 updateScreenAreaLeaveCount;
extern i32 dsaFilterEnterCount;
extern i32 dsaFilterLeaveCount;
void DSAInstrumentation_Dump();
void ReadTranslationFile();
void RecordFile_Record(const char *line);
struct SNDHEAD
{
i8 byte0[4]; //"RIFF"
i32 Size; // 6076 // #bytes after this integer
i8 byte8[8]; //"WAVEfmt "
i32 int16; // 18
i16 wFormatTag; // 1
i16 nChannels; // 1
i32 nSamplesPerSecond; // 11025
i32 nAvgBytesPerSec; // 11025 // important
i16 nBlockAlign; // 1 // 2 for 16-bit
i16 wBitsPerSample; // 8
//i16 cbSize; // 40
//i8 byte38[4]; // "fact"
//i32 int42; // 4
//i32 numBytes46; //
i8 byte50[4]; // "data"
i32 numSamples54; //
i8 sample58[1];
};
void Statistics();
void EnqueMouseClick(i32, i32, i32);
void TAG001afe(i32, i32, i32);
//i32 AddSD(char *, i32, float, float, float);
void ItemsRemaining(i32 mode);
std::string parentFolder(char *folderName, char *endName);
bool PlayfileIsOpen();
bool GetVideoRectangle(i32, RECT *);
ui32 dumpWindow = 0;
bool annotationPlaced = false;
extern RECT g_rcClient;
#if defined(_MSC_VER) //003
WINDOWPLACEMENT annotationPlacement;
extern HINSTANCE hInst;
extern HWND hWnd;
#endif //003
extern i32 WindowHeight;
extern i32 WindowWidth;
extern i32 WindowX;
extern i32 WindowY;
extern bool fullscreenRequested;
extern bool virtualFullscreen;
//extern HINSTANCE hInst;
extern i32 VBLperTimer;
extern i32 VBLMultiplier;
extern i32 screenSize;
extern i32 keyboardMode;
extern i32 trace;
void PlayfileOpen(bool);
void RecordfileOpen(bool);
void RecordfilePreOpen();
extern bool BeginRecordOK;
extern bool TimerTraceActive;
extern bool AttackTraceActive;
extern bool RepeatGame;
extern i32 NoSpeedLimit;
bool OpenTraceFile();
void CloseTraceFile();
bool OpenGraphicTraceFile();
void CloseGraphicTraceFile();
extern bool g_cursorIsShowing;
extern bool RecordCommandOption;
extern bool NoRecordCommandOption;
extern HWND hWnd;
#define maxMessageStack 20
CSB_UI_MESSAGE msgStack[maxMessageStack];
i32 msgStackLen = 0;
i32 messageMask = 1; //Right now just 0 or 1
i32 latestScanp1 = 0;
i32 latestScanp2 = 0;
XLATETYPE latestScanType = TYPEIGNORED;
i32 latestScanXlate = 0;
XLATETYPE latestCharType = TYPEIGNORED;
i32 latestCharp1 = 0;
i32 latestCharXlate = 0;
char playFileName[80] = "Playfile.log";
char *PlayfileName = playFileName;
char dungeonname[80] = "dungeon.dat";
char *dungeonName = dungeonname;
bool PlaybackCommandOption = false;
bool RecordCommandOption = false;
bool NoRecordCommandOption = false;
bool RecordDesignOption = false;
bool DMRulesDesignOption = false;
bool RecordMenuOption = false;
bool NoRecordMenuOption = false;
bool extendedPortraits = false;
i32 keyQueueStart=0; // Next key to process
i32 keyQueueEnd=0; // Next Empty entry
i32 keyQueueLen=3;
i32 keyQueue[3];
#ifdef _MSVC_INTEL //004
DSAListDialog::DSAListDialog()
{
//m_initialText = NULL;
//m_finalText = NULL;
}
DSAListDialog::~DSAListDialog()
{
}
LRESULT CALLBACK DSAListCallback(
HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM /*lParam*/)
{
// i32 len;
switch (message)
{
case WM_DESTROY:
case WM_SETFONT:
case WM_NCDESTROY:
case WM_ACTIVATE:
case WM_NOTIFYFORMAT:
case 0x127:
case 0x128:
case 0x129:
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
case WM_NCACTIVATE:
case WM_USER:
case WM_SHOWWINDOW:
case WM_NCPAINT:
case WM_GETTEXT:
case WM_CTLCOLORDLG:
case WM_CTLCOLORBTN:
case WM_ERASEBKGND:
case WM_PAINT:
case WM_NOTIFY:
case WM_SETCURSOR:
case WM_NCHITTEST:
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
case WM_MOUSEACTIVATE:
case WM_SETFOCUS:
case WM_KILLFOCUS:
return false;
case WM_INITDIALOG:
{
HWND hList;
int i, idx;
hList = GetDlgItem(hDlg, IDC_DSAList);
//if (initialEditText == NULL)
//initialEditText = "No Game Information available";
//SetDlgItemText(hDlg, IDC_GameInformationEdit, initialEditText);
idx = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)"NONE");
SendMessage(hList, LB_SETITEMDATA, idx, -1);
idx = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)"ALL");
SendMessage(hList, LB_SETITEMDATA, idx, 256);
if (DSAIndex.IsLoaded())
{
bool all = true;
for (i=0; i<256; i++)
{
DSA *pDSA;
if ((pDSA=DSAIndex.GetDSA(i)) != NULL)
{
char line[200];
sprintf(line,"%03d - %s", i, pDSA->Description());
idx = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)line);
SendMessage(hList, LB_SETITEMDATA, (WPARAM)idx, (LPARAM)i);
if (DSAIndex.IsTracing(i))
{
SendMessage(hList,LB_SETSEL, (WPARAM)true, (LPARAM)idx);
}
else
{
all = false;
};
};
};
if (all)
{
SendMessage(hList, LB_SETSEL, (WPARAM)true, LPARAM(1));
};
}
else
{
int override;
override = DSAIndex.TraceOverride();
if (override == 256)
{
SendMessage(hList, LB_SELITEMRANGE, (WPARAM)1, MAKELPARAM(1,1));
}
else
{
DSAIndex.TraceOverride(-1);
SendMessage(hList, LB_SELITEMRANGE, (WPARAM)1, MAKELPARAM(0,0));
};
};
SetFocus(hList);
};
DSAIndex.SaveTracing();
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
{
//HWND hEdit = GetDlgItem(hDlg, IDC_DSAList);
//len = GetWindowTextLength(hEdit);
//if (finalEditText == NULL)
//{
// finalEditText = (char *)UI_malloc(len+1, MALLOC011);
//};
//GetWindowText(hEdit, finalEditText, len+1);
EndDialog(hDlg, LOWORD(wParam));
return 0; // Processed
};
case IDC_DSAList:
{
i32 focus;
HWND hList;
hList = GetDlgItem(hDlg, IDC_DSAList);
switch(HIWORD(wParam))
{
case LBN_SETFOCUS:
case LBN_KILLFOCUS:
return 1; //Not Processed.
case LBN_SELCHANGE:
focus = SendMessage(hList, LB_GETCARETINDEX, (WPARAM)0, (LPARAM)0);
if (DSAIndex.IsLoaded())
{
i32 traceNums[258];
i32 numSel;
i32 i;
numSel = SendMessage(hList, LB_GETSELITEMS, (WPARAM)258, (LPARAM)traceNums);
if (focus == 0)
{
DSAIndex.NoTracing();
SendMessage(hList, LB_SETSEL, (WPARAM)false, (LPARAM)-1);
SendMessage(hList, LB_SETSEL, (WPARAM)true, (LPARAM)0);
break;
}
if (focus == 1)
{
DSAIndex.AllTracing();
SendMessage(hList, LB_SETSEL, (WPARAM)true, (LPARAM)-1);
SendMessage(hList, LB_SETSEL, (WPARAM)false, (LPARAM)0);
SendMessage(hList, LB_SETSEL, (WPARAM)true, (LPARAM)1);
break;
}
SendMessage(hList, LB_SETSEL, (WPARAM)false, (LPARAM)0);
SendMessage(hList, LB_SETSEL, (WPARAM)false, (LPARAM)1);
DSAIndex.NoTracing();
for (i=0; i<numSel; i++)
{
i32 dsaNum;
dsaNum = SendMessage(hList, LB_GETITEMDATA, (WPARAM)traceNums[i], (LPARAM)0);
DSAIndex.SetTracing(dsaNum);
};
}
else
{
if (focus == 0)
{
DSAIndex.TraceOverride(-1);
DSAIndex.NoTracing();
SendMessage(hList, LB_SETSEL, (WPARAM)false, (LPARAM)1);
SendMessage(hList, LB_SETSEL, (WPARAM)true, (LPARAM)0);
break;
}
if (focus == 1)
{
DSAIndex.TraceOverride(256);
DSAIndex.AllTracing();
SendMessage(hList, LB_SETSEL, (WPARAM)false, (LPARAM)0);
SendMessage(hList, LB_SETSEL, (WPARAM)true, (LPARAM)1);
break;
}
};
return 0;
default:
return 1;
};
};
break;
default:
return 1; // Not Processed.
}
return 1; // WM_COMMAND not processed.
}
return FALSE;
}
i32 DSAListDialog::DoModal()
{
i32 result;
bool saveCursorShowing;
//initialEditText = m_initialText;
saveCursorShowing = g_cursorIsShowing;
if (!g_cursorIsShowing) ShowCursor(true);
i32 mask = UI_DisableAllMessages();
result = DialogBox(hInst, (LPCTSTR)IDD_TraceDSAList, hWnd, (DLGPROC)DSAListCallback);
// if (result < 0)
// {
// DWORD errorWord = GetLastError();
// };
if (!saveCursorShowing) ShowCursor(false);
UI_EnableMessages(mask);
return result;
}
#endif //004
EditDialog::EditDialog()
{
m_initialText = NULL;
m_finalText = NULL;
}
EditDialog::~EditDialog()
{
}
static char *initialEditText;
char *finalEditText= NULL;
// Mesage handler for EditDialog
#ifdef _MSVC_INTEL //005
LRESULT CALLBACK EditTextCallback(
HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM /*lParam*/)
{
i32 len;
switch (message)
{
case WM_INITDIALOG:
{
if (initialEditText == NULL)
initialEditText = "No Game Information available";
SetDlgItemTextA(hDlg, IDC_GameInformationEdit, initialEditText);
if (annotationPlaced)
{
SetWindowPlacement(hDlg, &annotationPlacement);
};
//BOOL SetWindowPos(
// HWND hWnd, // handle to window
// HWND hWndInsertAfter, // placement-order handle
// int X, // horizontal position
// int Y, // vertical position
// int cx, // width
// int cy, // height
// UINT uFlags // window-positioning flags
//);
};
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
HWND hEdit = GetDlgItem(hDlg, IDC_GameInformationEdit);
len = GetWindowTextLength(hEdit);
if (finalEditText == NULL)
{
finalEditText = (char *)UI_malloc(len+1, MALLOC011);
};
GetWindowTextA(hEdit, finalEditText, len+1);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
return FALSE;
case WM_SETFONT:
case WM_ACTIVATE:
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
case WM_NCACTIVATE:
case WM_USER:
case 0x0127:
case 0x0128:
case WM_SHOWWINDOW:
case WM_NCPAINT:
case WM_GETTEXT:
case WM_ERASEBKGND:
case WM_CTLCOLORDLG:
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
case WM_PAINT:
case WM_SETCURSOR:
case WM_NCHITTEST:
case WM_MOUSEFIRST:
case WM_MOUSEACTIVATE:
case WM_NCMOUSEMOVE:
case WM_SETFOCUS:
case WM_KILLFOCUS:
case WM_NCDESTROY:
case WM_NCLBUTTONDOWN:
case WM_SYSCOMMAND:
case WM_CAPTURECHANGED:
case WM_GETMINMAXINFO:
case WM_ENTERSIZEMOVE:
case WM_MOVING:
case WM_MOVE:
case WM_EXITSIZEMOVE:
case WM_TIMECHANGE:
case WM_ACTIVATEAPP:
case WM_ENTERMENULOOP:
return FALSE;
case WM_DESTROY:
{
if (GetWindowPlacement(
hDlg, // handle to window
&annotationPlacement)) // address of structure for position data
{
annotationPlaced = true;
};
};
return FALSE;
default:
return FALSE;
};
}
i32 EditDialog::DoModal()
{
i32 result;
bool saveCursorShowing;
initialEditText = m_initialText;
saveCursorShowing = g_cursorIsShowing;
if (!g_cursorIsShowing) ShowCursor(true);
i32 mask = UI_DisableAllMessages();
result = DialogBox(hInst, (LPCTSTR)IDD_GameInformation, hWnd, (DLGPROC)EditTextCallback);
if (!saveCursorShowing) ShowCursor(false);
UI_EnableMessages(mask);
m_finalText = finalEditText;
//if (finalEditText != NULL) UI_free(finalEditText);
finalEditText = NULL;
initialEditText = NULL;
return result;
}
#endif //005
struct KEYXLATE
{
struct Key
{
i32 m_scan, m_mode;
XLATETYPE m_type;
bool operator==(const Key &key) const { return m_scan==key.m_scan && m_mode==key.m_mode && m_type==key.m_type; }
};
void addkey(i32 scan, i32 key, i32 mode, XLATETYPE type);
i32 translate(i32 scan, i32 mode, XLATETYPE type);
private:
struct Map
{
Key m_key;
i32 m_result;
};
std::vector<Map> m_map;
};
void KEYXLATE::addkey(i32 scan, i32 key, i32 mode, XLATETYPE type)
{
m_map.emplace_back(Map{Key{scan, mode, type}, key});
}
i32 KEYXLATE::translate(i32 scan, i32 mode, XLATETYPE type)
{
Key key{scan, mode, type};
for(auto &entry : m_map)
if(entry.m_key==key)
return entry.m_result;
return 0;
}
KEYXLATE keyxlate;
char *getfield(const char *buf, i32& col)
{
static char result[200];
char term;
i32 len = 0;
term = ' ';
while (buf[col] != '\n')
{
if ((buf[col]!=' ') && (buf[col]!='\t')) break;
col++;
};
if (buf[col] == '"')
{
term = '"';
col++;
};
while (buf[col] != '\n')
{
if ( (buf[col]==term)
|| ((term==' ') && (buf[col]=='\t'))) break;
result[len++] = buf[col];
if (len>198) len--;
col++;
};
result[len]=0;
return result;
}
i32 gethex(char *buf, i32& col)
{
i32 result;
char *field;
field = getfield(buf,col);
sscanf(field,"%x", &result);
return result;
}
// ROQUEN: massive temp hack
#ifndef _MSC_VER //006
#ifdef TARGET_OS_MAC //007
#define strupr( a ) _strupr( a )
static void _strupr(char *str) {
if( str ) {
while(*str) {
*str = toupper( *str );
str++;
}
}
}
#else
#define _strupr(X) SDL_strupr(X)
#define strupr(X) SDL_strupr(X)
#endif //007
#endif //006
/*
i32 AddSmartDiscard(const char *buf)
{
char fld[10][200];
i32 i, j, col=0;
i32 minimum;
float level,y_intercept,slope;
char *pfld;
for (i=0; i<10; i++)
{
pfld=getfield(buf,col);
if (*pfld == 0) break;
_strupr(pfld);
strcpy(fld[i],pfld);
};
j=1;
while (i>5)
{
if ((fld[j][0]>='A') && (fld[j][0]<='Z'))
{
strcat(fld[0]," ");
strcat(fld[0],fld[j]);
j++;
i--;
}
else break;
};
if (i<5) return 1; //error
if (sscanf(fld[j],"%d",&minimum)!=1) return 1;
if (sscanf(fld[j+1],"%f",&level)!=1) return 1;
if (sscanf(fld[j+2],"%f",&y_intercept)!=1) return 1;
if (sscanf(fld[j+3],"%f",&slope)!=1) return 1;
return AddSD(fld[0],minimum,level,y_intercept,slope);
//return 0;
}
*/
/*
//************************************************************************
// Smart Discard definitions
//
//Smart Discard only operates on databases which have been enlarged
// to size 1023. Each item in a database is given a discard priority
// which is compared to other items in the same database. The item with
// the highest priority is discarded first.
//
// The program operates as follows: every clock tick initiates the
// "Smart Discard" process. The databases are considered one at a time.
// Each clock tick causes the items in a single room to be evaluated and
// added to the list. When all rooms have been evaluated and there are
// fewer than 900 items in the database then the next database is considered.
// If more than 900 items exist then on each tick of the clock the item
// with the highest discard priority has its priority recomputed. If it
// is still at least as great as the next higher item then it is deleted.
// On the other hand, if its priority has declined (perhaps due to party
// movement, because we just discarded an item of this type, etc) then it
// is put back in the list in its proper place and we wait for the next
// clock tick.
//
// The priority calculation includes a random number between 0.0 and 1.0
// so that items with the same basic priority will be randomly selected.
//
// Format:
//
// name minimum level y-intercept slope
//
// name item name - blanks are allowed (or "default") (case-insensitive)
// minimum integer - If this many or fewer of the item exist then
// none will be considered for discard.
// level float - additional priority for not being on a level
// adjacent to the party.
// y-intercept float - discard priority for minimum
// slope float - additional discard priority for each item over minimum
//
// The item's deletion priority is y-intercept + slope*(num-minimum) + level
//
// Let us provide an example:
//
// example --> Discard Worm Round 20 10.0 0 1
//
// Worm Rounds are not considered for deletion unless there are more than
// 20 of them in the dungeon. Assume there are 30 of them in the dungeon.
// The discard priority for each of the 30 Worm Rounds is equal to:
// 0 + 1*(30-20).
// Each Worm Round which is on a level not immediately adjacent to the party
// will have 10.0 added to its priority.
//
//
const char *SmartDiscards[] = {
"default 30 50 20.0 1.0",
"Wooden Shield 10 50 20.0 1.0", // We hardly need more than 10 of these
"Rock 10 50 20.0 1.0",
"Sword 10 50 20.0 1.0",
"Dagger 10 50 20.0 1.0",
"Falchion 10 50 20.0 1.0",
"Club 10 50 20.0 1.0",
"Stone Club 10 50 20.0 1.0",
"Armet 10 50 20.0 1.0",
"Torso Plate 10 50 20.0 1.0",
"Leg Plate 10 50 20.0 1.0",
"Foot Plate 10 50 20.0 1.0",
//; Miscellaneous items
"Boulder 20 50 70.0 1.0", // Be sure Boulders go before food
"Dragon Steak 150 0 20.0 0.0", // Default goes before Dragon Steak.
NULL
};
*/
// ROQUEN: humm...
#if !defined(_LINUX) //008
#define CONFIG_NAME "config.txt"
#else
#define CONFIG_NAME "config.linux"
#endif //008
#if defined TARGET_OS_MAC //009
#define strupr( a ) _strupr( a )
static void _strupr(char *str) {
if( str ) {
while(*str) {
*str = toupper( *str );
str++;
}
}
}
#endif //009
void ReadConfigFile()
{
char buf[501];
i16 f;
i32 lineNumber = 0;
i32 col, numerror=0;
char *field;
i32 scancode, key, mode;
/*
for (i32 i=0; SmartDiscards[i] != NULL; i++)
{
//_strupr(SmartDiscards[i]);
if (AddSmartDiscard(SmartDiscards[i]) == 0) continue;
};
*/
f=OPEN(CONFIG_NAME, "r");
if (f < 0) return;
while (GETS(buf,500,f) != NULL)
{
lineNumber++;
col=0;
if (buf[0] == ';') continue;
field=getfield(buf,col);
_strupr(field);
if (strcmp(field, ";")==0) continue;
if (strcmp(field, "") ==0) continue;
if (strcmp(field, "KEY")==0)
{
mode =gethex(buf,col);
scancode=gethex(buf,col);
key =gethex(buf,col);
keyxlate.addkey(scancode, key, mode, TYPEKEY);
continue;
};
if (strcmp(field,"SCAN")==0)
{
mode =gethex(buf,col);
scancode=gethex(buf,col);
key =gethex(buf,col);
keyxlate.addkey(scancode, key, mode, TYPESCAN);
continue;
};
if (strcmp(field,"MSCAN")==0)
{
i32 x, y;
XLATETYPE type;
char *button;
mode =gethex(buf,col);
scancode=gethex(buf,col);
x =gethex(buf,col);
y =gethex(buf,col);
button =getfield(buf,col);
_strupr(button);
if (strcmp(button,"L")==0) type=TYPEMSCANL; else type=TYPEMSCANR;
keyxlate.addkey(scancode, (x<<16)+y, mode, type);
continue;
};
if (strcmp(field,"DIRECTORY")==0)
{
field = getfield(buf,col);
if (g_folderName != NULL) UI_free(g_folderName);
g_folderName = (char *) UI_malloc(strlen(field) + 1, MALLOC012);
if (g_folderName!=NULL)
{
strcpy(g_folderName, field);
g_folderParentName = parentFolder(g_folderName, g_folderName+strlen(g_folderName+1));
};
continue;
};
#if defined(_LINUX) //010
extern ui32 TImER;
if (strcmp(field,"TIMER")==0)
{
field = getfield(buf,col);
if (TImER) continue; //cmd line has higher priority than config.linux
//sscanf(TIMER,"%d", field);
TImER=strtol( field,NULL, 10);
continue;
};
#endif //010
if (strcmp(field,"PLACE") == 0)
{
i32 k, size, srcx, srcy, width, height, x, y;
field = getfield(buf,col);
if ( (field[0] < 'A')||(field[0] > 'E') ) continue;
k = field[0] - 'A';
size = gethex(buf,col);
if ( (size < 0)||(size > 6) ) continue;
srcx = gethex(buf,col);
if ( (srcx<0) || (srcx>319) ) continue;
srcy = gethex(buf,col);
if ( (srcy<0) || (srcy>199) ) continue;
width = gethex(buf,col);
if ( (width<1) || (srcx+width>320) )continue;
height = gethex(buf,col);
if ( (height<1) || (srcy+height>200) )continue;
x = gethex(buf,col);
if ( (x < 0)||(x > 4096) ) continue;
y = gethex(buf,col);
if ( (y < 0)||(y >4096) ) continue;
videoSegSize[k] = size;
videoSegSrcX[k] = srcx;
videoSegSrcY[k] = srcy;
videoSegWidth[k] = width;
videoSegHeight[k] = height;
videoSegX[k] = x;
videoSegY[k] = y;
continue;
};
if (numerror==0)
{
char msg[200];
if (strlen(buf)>0)
if (buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = 0;
buf[100] = 0; //Just in case it is very long;
sprintf(msg,"Line number = %d\n%s",lineNumber,buf);
UI_MessageBox(msg,"Bad Config Line",MESSAGE_OK);
numerror++;
};
};
CLOSE(f);
}
i32 UI_DisableAllMessages()
{
i32 oldmask = messageMask;
messageMask = 0;
return oldmask;
}
i32 UI_EnableMessages(i32 mask)
{
messageMask |= mask;
return messageMask;
}
i32 CSBUI(CSB_UI_MESSAGE *msg)
{
static bool crash = false;
i32 CallCheckVBL= 0;
if (messageMask == 0) return UI_STATUS_NORMAL;
// {
// FILE *f;
// f = fopen("debug","a");
// fprintf(f,"CSBUI enter type = %d", msg->type);
// fclose(f);
// };
try
{
switch (msg->type)
{
case UIM_INITIALIZE:
ReadConfigFile();
//Set the GameMode //0=quit
//1=dungeon
//2=utility
//3=hint
ReadTranslationFile();
DispatchCSB(st_AskWhatToDo);
break;
case UIM_SETOPTION:
switch (msg->p1)
{
case OPT_DMRULES:
DM_rules = !DM_rules;
RecordFile_Record(DM_rules ? "#DMRules\n" : "#NoDMRules\n");
break;
case OPT_NORMAL:
UI_ClearScreen();
screenSize = 1;
break;
case OPT_DOUBLE:
UI_ClearScreen();
if (msg->p2 == 1) screenSize = 1;
else screenSize = 2;
break;
case OPT_TRIPLE:
UI_ClearScreen();
if (msg->p2 == 1) screenSize = 1;
else screenSize = 3;
break;
case OPT_QUADRUPLE:
UI_ClearScreen();
if (msg->p2 == 1) screenSize = 1;
else screenSize = 4;
break;
case OPT_QUINTUPLE:
UI_ClearScreen();
if (msg->p2 == 1) screenSize = 1;
else screenSize = 5;
break;
case OPT_SEXTUPLE:
UI_ClearScreen();
if (msg->p2 == 1) screenSize = 1;
else screenSize = 6;
break;
case OPT_RECORD:
if (msg->p2 == 1)
{
RecordMenuOption = true;
NoRecordMenuOption = false;
}
else
{
RecordfileOpen(false); //This will override any other
//Record options.
RecordMenuOption = false;
NoRecordMenuOption = true;
};
break;
case OPT_PLAYBACK:
if (msg->p2 == 1) PlayfileOpen(true);
else PlayfileOpen(false);
if (PlayfileIsOpen())
{
extraTicks = false;
};
break;
case OPT_QUICKPLAY:
if (msg->p2 == 1) NoSpeedLimit = 2000000000;
else
{
NoSpeedLimit = 0;
VBLMultiplier = 1;
};
break;
case OPT_CLOCK:
gameSpeed = (SPEEDS)msg->p2;
break;
case OPT_VOLUME:
gameVolume = (VOLUMES)msg->p2;
break;
case OPT_DIRECTX:
usingDirectX = !usingDirectX;
break;
case OPT_PLAYERCLOCK:
playerClock = !playerClock;
break;
case OPT_EXTRATICKS:
extraTicks = !extraTicks;
break;
case OPT_ITEMSREMAINING:
ItemsRemaining(0);
break;
case OPT_NONCSBITEMSREMAINING:
ItemsRemaining(1);
break;
case OPT_TIMERTRACE:
if (TimerTraceActive)
{
TimerTraceActive = false;
if (!AttackTraceActive && !AITraceActive)
{
CloseTraceFile();
};
}
else