forked from Interrupt/systemshock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.c
More file actions
1555 lines (1237 loc) · 41.6 KB
/
setup.c
File metadata and controls
1555 lines (1237 loc) · 41.6 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
/*
Copyright (C) 2015-2018 Night Dive Studios, LLC.
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/>.
*/
/*
* $Source: r:/prj/cit/src/RCS/setup.c $
* $Revision: 1.141 $
* $Author: dc $
* $Date: 1994/11/23 00:05:51 $
*/
#include <string.h>
#include <SDL.h>
// TODO: extract this into a compatibility header
#ifdef _MSC_VER
#ifndef F_OK
#define F_OK 0
#endif
#else
#include <unistd.h>
#endif
#ifdef SVGA_SUPPORT
#include "fullscrn.h"
#endif
#include "archiveformat.h"
#include "setup.h"
#include "colors.h"
#include "cybmem.h"
#include "diffq.h"
#include "gamewrap.h"
#include "gr2ss.h"
#include "hud.h"
#include "init.h"
#include "miscqvar.h"
#include "player.h"
#include "version.h"
#include "wrapper.h"
#include "verify.h"
#include "sdl_events.h"
#include "cybstrng.h"
#include "gamestrn.h"
#include "mainloop.h"
#include "tools.h"
#include "input.h"
#include "game_screen.h"
#include "hkeyfunc.h"
#include "loops.h"
#include "keydefs.h"
#include "status.h"
#include "cutsloop.h"
#include "musicai.h"
#include "palfx.h"
#include "gamescr.h"
#include "faketime.h"
#include "2d.h"
#include "splash.h"
#include "splshpal.h"
#include "tickcount.h"
#include "MacTune.h"
#include "Shock.h"
#include "Xmi.h"
#ifdef PLAYTEST
#include <mprintf.h>
#endif
#define KEYBOARD_FOCUS_COLOR (RED_BASE + 3)
#define NORMAL_ENTRY_COLOR (RED_BASE + 7)
#define CURRENT_DIFF_COLOR (RED_BASE + 3)
#define SELECTED_COLOR (RED_BASE)
#define UNAVAILABLE_COLOR (RED_BASE + 11)
uiSlab setup_slab;
LGRegion setup_root_region;
uchar play_intro_anim;
uchar save_game_exists = FALSE;
SetupMode setup_mode;
SetupMode last_setup_mode;
int intro_num;
int splash_num;
int diff_sum = 0;
bool do_fades = false;
ubyte valid_save;
uchar setup_bio_started = FALSE;
uchar start_first_time = TRUE;
bool waiting_for_key = false;
static uchar direct_into_cutscene = FALSE;
extern char which_lang;
extern uchar clear_player_data;
extern char current_cutscene;
extern char curr_vol_lev;
extern char curr_sfx_vol;
extern uchar fullscrn_vitals;
extern uchar fullscrn_icons;
extern uchar map_notes_on;
extern uchar audiolog_setting;
extern uchar mouseLefty;
#ifdef AUDIOLOGS
extern char curr_alog_vol;
#endif
errtype draw_difficulty_char(int char_num);
errtype draw_difficulty_description(int which_cat, int color);
errtype journey_newgame_func(void);
errtype journey_continue_func(uchar draw_stuff);
errtype draw_username(int color, char *string);
//*****************************************************************************
// DIFFICULTY
#define DIFF_DONE_X1 119
#define DIFF_DONE_Y1 179
#define DIFF_DONE_X2 203
#define DIFF_DONE_Y2 198
#define DIFF_NAME_X 57
#define DIFF_NAME_Y 49
#define DIFF_NAME_X2 253
#define DIFF_NAME_Y2 65
#define DIFF_NAME_TEXT_X 124
#define DIFF_X_BASE 28
#define DIFF_W_BASE 156
#define DIFF_W_ELEM 32
#define DIFF_H_ELEM 20
#define DIFF_OPT_TOP 99
#define DIFF_OPT_DELTA 53
#define DIFF_OPT_HEIGHT 24
#define DIFF_STRING_OFFSET_Y 10
#define DIFF_STRING_OFFSET_X 13
#define DIFF_TITLE1_X1 12
#define DIFF_TITLE1_Y1 70
#define DIFF_TITLE1_X2 155
#define DIFF_TITLE1_Y2 93
#define DIFF_TITLE1_OPT_TOP 94
#define DIFF_TITLE1_OPT_BOTTOM 118
#define DIFF_TITLE1_LEFT1 25
#define DIFF_TITLE1_RIGHT1 45
#define DIFF_TITLE2_X1 169
#define DIFF_TITLE2_Y1 70
#define DIFF_TITLE2_X2 311
#define DIFF_TITLE2_Y2 93
#define DIFF_TITLE3_X1 12
#define DIFF_TITLE3_Y1 123
#define DIFF_TITLE3_X2 155
#define DIFF_TITLE3_Y2 146
#define DIFF_TITLE4_X1 169
#define DIFF_TITLE4_Y1 123
#define DIFF_TITLE4_X2 311
#define DIFF_TITLE4_Y2 146
#define DIFF_SIZE_X DIFF_TITLE1_RIGHT1 - DIFF_TITLE1_LEFT1
#define DIFF_SIZE_Y DIFF_TITLE1_OPT_BOTTOM - DIFF_TITLE1_OPT_TOP
// why +2?
#define build_diff_x(char_num) \
((DIFF_X_BASE + (DIFF_W_ELEM * (char_num & 3)) + (((char_num >> 2) & 1) * DIFF_W_BASE)) + 2)
#define build_diff_y(char_num) ((DIFF_OPT_TOP + ((char_num >> 3) * DIFF_OPT_DELTA)) + 2)
#define NUM_DIFF_CATEGORIES 4
#define CATEGORY_STRING_BASE REF_STR_diffCategories
#define DIFF_STRING_BASE REF_STR_diffStrings
#define DIFF_NAME REF_STR_diffName
#define DIFF_START REF_STR_diffStart
#define FLASH_TIME (CIT_CYCLE / 8)
#define COMPUTE_DIFF_STRING_X(wcat) (DIFF_X_BASE + (DIFF_W_BASE * (wcat & 1)) - DIFF_STRING_OFFSET_X)
#define COMPUTE_DIFF_STRING_Y(wcat) (DIFF_OPT_TOP + ((wcat >> 1) * DIFF_OPT_DELTA) - DIFF_STRING_OFFSET_Y)
#define REF_IMG_bmDifficultyScreen 0x26d0000
char curr_diff = 0;
uchar start_selected = FALSE;
short diff_titles_x[] = {DIFF_TITLE1_X1, DIFF_TITLE2_X1, DIFF_TITLE3_X1, DIFF_TITLE4_X1};
short diff_titles_y[] = {DIFF_TITLE1_Y1, DIFF_TITLE2_Y1, DIFF_TITLE3_Y1, DIFF_TITLE4_Y1};
char *valid_char_string = "0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
LGRect name_rect = {{DIFF_NAME_TEXT_X, DIFF_NAME_Y}, {DIFF_NAME_X2, DIFF_NAME_Y2}};
errtype compute_new_diff(void) {
int i, new_sum = 0;
for (i = 0; i < 4; i++)
new_sum += player_struct.difficulty[i];
diff_sum = new_sum;
return OK;
}
errtype difficulty_draw(uchar full) {
int i;
uiHideMouse(NULL);
if (full) {
draw_raw_res_bm_temp(REF_IMG_bmDifficultyScreen, 0, 0);
status_bio_draw();
}
setup_mode = SETUP_DIFFICULTY;
for (i = 0; i < NUM_DIFF_CATEGORIES; i++) {
if (i == curr_diff && !start_selected)
gr_set_fcolor(KEYBOARD_FOCUS_COLOR);
else
gr_set_fcolor(NORMAL_ENTRY_COLOR);
res_draw_string(RES_citadelFont, CATEGORY_STRING_BASE + i, diff_titles_x[i] + 12, diff_titles_y[i] + 2);
}
if (start_selected)
gr_set_fcolor(KEYBOARD_FOCUS_COLOR);
else
gr_set_fcolor(NORMAL_ENTRY_COLOR);
res_draw_string(RES_citadelFont, DIFF_START, DIFF_DONE_X1 + 13, DIFF_DONE_Y1 + 2);
if (full) {
for (i = 0; i < 16; i++)
draw_difficulty_char(i);
for (i = 0; i < 4; i++)
draw_difficulty_description(i, NORMAL_ENTRY_COLOR);
gr_set_fcolor(KEYBOARD_FOCUS_COLOR);
res_draw_string(RES_citadelFont, DIFF_NAME, DIFF_NAME_X, DIFF_NAME_Y);
draw_username(NORMAL_ENTRY_COLOR, player_struct.name);
}
uiShowMouse(NULL);
return OK;
}
errtype draw_username(int color, char *string) {
gr_set_fcolor(color);
uiHideMouse(&name_rect);
res_draw_text(RES_citadelFont, string, DIFF_NAME_TEXT_X, DIFF_NAME_Y);
uiShowMouse(&name_rect);
return OK;
}
void flash_username(void) {
long flash_done;
uiHideMouse(&name_rect);
gr_set_fcolor(SELECTED_COLOR - 4);
res_draw_string(RES_citadelFont, DIFF_NAME, DIFF_NAME_X, DIFF_NAME_Y);
flash_done = *tmd_ticks + FLASH_TIME;
while (TickCount() < flash_done) {
SDLDraw();
}
gr_set_fcolor(KEYBOARD_FOCUS_COLOR);
res_draw_string(RES_citadelFont, DIFF_NAME, DIFF_NAME_X, DIFF_NAME_Y);
uiShowMouse(&name_rect);
}
errtype draw_difficulty_line(int which_line) {
int i;
for (i = 0; i < 4; i++)
draw_difficulty_char((which_line * 4) + i);
draw_difficulty_description(which_line, NORMAL_ENTRY_COLOR);
return OK;
}
errtype draw_difficulty_description(int which_cat, int color) {
if (color != -1)
gr_set_fcolor(color);
res_draw_string(RES_smallTechFont, DIFF_STRING_BASE + (which_cat * 4) + player_struct.difficulty[which_cat],
COMPUTE_DIFF_STRING_X(which_cat), COMPUTE_DIFF_STRING_Y(which_cat));
return OK;
}
// char_num 1-16
errtype draw_difficulty_char(int char_num) {
char buff[] = "X";
uiHideMouse(NULL);
if (player_struct.difficulty[char_num / 4] == char_num % 4)
gr_set_fcolor(CURRENT_DIFF_COLOR);
else
gr_set_fcolor(NORMAL_ENTRY_COLOR);
buff[0] = (char_num & 3) + '0';
res_draw_text(RES_citadelFont, buff, build_diff_x(char_num), build_diff_y(char_num));
uiShowMouse(NULL);
return OK;
}
//*****************************************************************************
//*****************************************************************************
// JOURNEY
#define JOURNEY_OPT1_TOP 66
#define JOURNEY_OPT1_BOT 88
#define JOURNEY_OPT2_TOP 97
#define JOURNEY_OPT2_BOT 119
#define JOURNEY_OPT3_TOP 129
#define JOURNEY_OPT3_BOT 160
#define JOURNEY_OPT4_TOP 160
#define JOURNEY_OPT4_BOT 182
#define SETUP_STRING_BASE REF_STR_journeyOpts
#define NUM_SETUP_LINES 4
#define JOURNEY_OPT_LEFT 79
#define JOURNEY_OPT_RIGHT 247
#define REF_IMG_bmJourneyOnwards 0x26c0000
#ifdef DEMO
char curr_setup_line = 1;
#else
char curr_setup_line = 0;
#endif
int journey_y[8] = {JOURNEY_OPT1_TOP, JOURNEY_OPT1_BOT, JOURNEY_OPT2_TOP, JOURNEY_OPT2_BOT,
JOURNEY_OPT3_TOP, JOURNEY_OPT3_BOT, JOURNEY_OPT4_TOP, JOURNEY_OPT4_BOT};
short setup_tops[] = {JOURNEY_OPT1_TOP, JOURNEY_OPT2_TOP, JOURNEY_OPT3_TOP, JOURNEY_OPT4_TOP};
errtype journey_draw(char part) {
char i;
uiHideMouse(NULL);
if (setup_bio_started) {
status_bio_end();
setup_bio_started = FALSE;
}
// extract into buffer - AFTER we've stopped biorhythms (which used that buffer.....)
if (part == 0)
draw_raw_res_bm_temp(REF_IMG_bmJourneyOnwards, 0, 0);
for (i = 0; i < NUM_SETUP_LINES; i++) {
if ((part == 0) || (part - 1 == i)) {
int col;
if (i == curr_setup_line)
col = KEYBOARD_FOCUS_COLOR;
else
col = NORMAL_ENTRY_COLOR;
#ifdef DEMO
if ((i == NUM_SETUP_LINES - 1) || (i == 0))
#else
if (i == NUM_SETUP_LINES - 1) // why is NUM_SETUP_LINES-1 necessarily continue?
#endif
{
#ifndef DEMO
if (!save_game_exists)
#endif
col = UNAVAILABLE_COLOR;
}
gr_set_fcolor(col);
res_draw_string(RES_citadelFont, SETUP_STRING_BASE + i, JOURNEY_OPT_LEFT + 15, setup_tops[i] + 4);
}
}
uiShowMouse(NULL);
setup_mode = SETUP_JOURNEY;
return OK;
}
errtype journey_intro_func(uchar draw_stuff) {
#ifdef DEMO
uiShowMouse(NULL); // need to leave it hidden
return OK;
#else
if (draw_stuff)
res_draw_string(RES_citadelFont, SETUP_STRING_BASE, JOURNEY_OPT_LEFT + 15, JOURNEY_OPT1_TOP + 2);
uiShowMouse(NULL); // need to leave it hidden
MacTuneKillCurrentTheme();
return play_cutscene(START_CUTSCENE, FALSE);
#endif
}
errtype journey_newgame_func(void) {
clear_player_data = TRUE;
DEBUG("Load object data");
object_data_load();
player_struct.level = 0xFF;
DEBUG("Create initial game");
create_initial_game_func(0, 0, 0);
INFO("Started new game!");
change_mode_func(0, 0, GAME_LOOP);
return OK;
}
errtype journey_difficulty_func(uchar draw_stuff) {
if (draw_stuff)
res_draw_string(RES_citadelFont, SETUP_STRING_BASE + 1, JOURNEY_OPT_LEFT + 15, JOURNEY_OPT2_TOP + 2);
uiShowMouse(NULL);
difficulty_draw(TRUE);
compute_new_diff();
status_bio_set(DIFF_BIO);
status_bio_start();
setup_bio_started = TRUE;
return OK;
}
//*****************************************************************************
//*****************************************************************************
// CREDITS
#define CredResFnt (RES_coloraliasedFont)
#define CredColor (GREEN_BASE + 4)
#define CredResource (RES_credits)
int credits_inp = 0;
void *credits_txtscrn;
int CreditsTune;
// set this when game is won, then stats will be shown once before credits
int WonGame_ShowStats = 0;
// ticks: 0 wait forever
int WaitForKey(ulong ticks) {
ulong end_ticks = (ulong)TickCount();
ulong key_ticks = end_ticks + (!ticks ? 500 : (ticks * 1 / 8));
end_ticks = ticks ? end_ticks + ticks : 0;
int ch;
// wait for specified elapsed ticks or keypress
for (;;) {
// loop win or elevator music
int i = 0;
if (music_on && !IsPlaying(i)) {
int track;
if (WonGame_ShowStats)
track = 0;
else
track = 1 + CreditsTune;
if (track >= 0 && track < NumTracks) {
// int volume = (int)curr_vol_lev * 127 / 100; //convert from 0-100 to 0-127
StartTrack(i, track);
if (!WonGame_ShowStats)
CreditsTune = (CreditsTune + 1) % 8;
}
}
pump_events();
SDLDraw();
kbs_event ev = kb_next();
ch = ev.ascii;
ticks = (ulong)TickCount();
if ((ch == 27 || ch == ' ' || ch == '\r') && ticks >= key_ticks)
break;
if (end_ticks && ticks >= end_ticks)
break;
}
return ch;
}
void PrintWinStats(void) {
char buf[256], buf_temp[256];
int x, y = 15;
short w, h;
grs_font *fon = gr_get_font();
gr_set_font(ResLock(RES_coloraliasedFont));
gr_clear(0);
sprintf(buf, "CONGRATULATIONS!");
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12 * 2;
sprintf(buf, "YOU HAVE COMPLETED SYSTEM SHOCK!");
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12;
sprintf(buf, "HIT ESC TO VIEW CREDITS.");
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12 * 2;
sprintf(buf, "STATISTICS");
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12;
// underline
short x1 = SCONV_X((320 - w) / 2);
short x2 = SCONV_X((320 - w) / 2 + w - 1);
for (; x1 <= x2; x1++) {
short y1 = SCONV_Y(y);
short y2 = SCONV_Y(y + 1);
y2 = y1 + (y2 - y1) / 3;
for (; y1 <= y2; y1++)
gr_set_pixel(GREEN_BASE + 4, x1, y1);
}
y += 4;
sprintf(buf, "TIME: %u", player_struct.game_time);
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12;
sprintf(buf, "KILLS: %d", player_struct.num_victories);
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12;
sprintf(buf, "REGENERATIONS: %d", player_struct.num_deaths);
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12;
uint8_t stupid = 0;
for (uint8_t i = 0; i < 4; i++)
stupid += (player_struct.difficulty[i] * player_struct.difficulty[i]);
sprintf(buf, "DIFFICULTY INDEX: %d", stupid);
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
y += 12;
int score;
// death is 10 anti-kills, but you always keep at least a third of your kills.
score = player_struct.num_victories - lg_min(player_struct.num_deaths * 10, player_struct.num_victories * 2 / 3);
score = score * 10000;
score = score - lg_min(score * 2 / 3, ((player_struct.game_time / (CIT_CYCLE * 36)) * 100));
score = score * (stupid + 1) / 37; // 9 * 4 + 1 is best difficulty factor
if (stupid == 36) {
score += 2222222; // secret kevin bonus
}
sprintf(buf, "SCORE: %d", score);
gr_string_size(buf, &w, &h);
ss_string(buf, (320 - w) / 2, y);
ResUnlock(RES_coloraliasedFont);
gr_set_font(fon);
WaitForKey(0);
}
void PrintCredits(void) {
// Credits display reverse-engineered from text resources
int end = 0, line = 0, x, y = 15, columns = 1, cur_col = 0;
int underline = 0, last_underline = 0;
char buf[256];
gr_clear(0);
while (!end) {
get_string((RES_credits << 16) | line, buf, sizeof(buf));
line++;
int len = strlen(buf);
if (*buf == '^') {
for (int i = 1; i < len; i++) {
switch (buf[i]) {
case 'E':
WaitForKey(0);
end = 1;
break;
case 'p':
WaitForKey(200);
break;
case 'G':
if (WaitForKey(2000) == 27)
end = 1;
gr_clear(0);
y = 15;
break;
case 'N':
break; // dunno
case '1':
columns = 1;
cur_col = 0;
break;
case '2':
columns = 2;
cur_col = 0;
break;
case 'H':
underline = 3;
break;
case 'T':
underline = 2;
break;
case 'h':
underline = 1;
break;
case 'c':
underline = 0;
break;
case 'S':
y += 10;
break;
case 'L':
y = 15 * (buf[++i] - '0');
break;
}
}
continue;
}
grs_font *fon = gr_get_font();
gr_set_font(ResLock(RES_coloraliasedFont));
short w, h;
gr_string_size(buf, &w, &h);
x = (columns == 1) ? (320 - w) / 2 : (cur_col == 0) ? 320 / 2 - 8 - w : 320 / 2 + 8;
ss_string(buf, x, y);
ResUnlock(RES_coloraliasedFont);
gr_set_font(fon);
if (underline) {
short x1, x2, y1, y2;
x1 = SCONV_X(x);
x2 = SCONV_X(x + w - 1);
for (; x1 <= x2; x1++) {
y1 = SCONV_Y(y + h + 1);
y2 = SCONV_Y(y + h + 2);
if (underline == 2)
y2 = y1 + (y2 - y1) / 2;
else
y2 = y1 + (y2 - y1) / 3;
for (; y1 <= y2; y1++)
gr_set_pixel(GREEN_BASE + 4, x1, y1);
}
if (underline == 3) {
x1 = SCONV_X(x + 1);
x2 = SCONV_X(x + w - 1 - 1);
for (; x1 <= x2; x1++) {
y1 = SCONV_Y(y + h + 1);
y2 = SCONV_Y(y + h + 2);
y1 = y1 + (y2 - y1) / 3;
for (; y1 <= y2; y1++)
gr_set_pixel(GREEN_BASE + 4, x1, y1);
}
}
}
if (columns == 1) {
y += underline ? 14 : 11;
underline = 0;
} else {
if (!cur_col)
last_underline = underline;
else {
y += (underline || last_underline) ? 14 : 11;
underline = 0;
}
cur_col ^= 1;
}
}
}
errtype journey_credits_func(uchar draw_stuff) {
setup_mode = SETUP_CREDITS;
if (draw_stuff) {
if (music_on) {
if (WonGame_ShowStats) {
MacTuneLoadTheme("endloop", 0);
} else {
CreditsTune = 0;
load_score_guts(7); // elevator
}
}
if (WonGame_ShowStats)
PrintWinStats();
PrintCredits();
WonGame_ShowStats = 0;
journey_credits_done();
} else {
if (credits_inp != 0) {
journey_credits_done();
}
}
return OK;
}
void journey_credits_done(void) {
kb_flush();
mouse_flush();
credits_inp = 0;
uiShowMouse(NULL);
journey_draw(0);
if (music_on)
MacTuneLoadTheme("titloop", 0);
}
//*****************************************************************************
//*****************************************************************************
// CONTINUE
#define SG_SLOT_HT 17
#define SG_SLOT_WD 169
#define SG_SLOT_OFFSET_X 21
#define SG_SLOT_OFFSET_Y 6
#define SG_SLOT_X 79
#define SG_SLOT_Y 62
#define REF_IMG_bmContinueScreen 0x26e0000
char curr_sg = 0;
errtype draw_sg_slot(int slot_num) {
char temp[64];
short sz, x, y;
uiHideMouse(NULL);
if (curr_sg == slot_num)
gr_set_fcolor(KEYBOARD_FOCUS_COLOR);
else
gr_set_fcolor(NORMAL_ENTRY_COLOR);
// if slot_num == -1 highlight the curr_sg slot with the SELECTED_COLOR color
if (slot_num == -1) {
gr_set_fcolor(SELECTED_COLOR);
slot_num = curr_sg;
}
if (valid_save & (1 << slot_num)) {
sz = strlen(comments[slot_num]);
strcpy(temp, comments[slot_num]);
} else {
get_string(REF_STR_UnusedSave, temp, 64);
}
gr_set_font(ResLock(RES_smallTechFont));
gr_string_size(temp, &x, &y);
while ((x > SG_SLOT_WD - SG_SLOT_OFFSET_X) && (sz > 0)) {
sz--;
strcpy(temp, "");
strncpy(temp, comments[slot_num], sz);
temp[sz] = '\0';
gr_string_size(temp, &x, &y);
}
ResUnlock(RES_smallTechFont); // was RES_CitadelFont
res_draw_text(RES_smallTechFont, temp, SG_SLOT_X + SG_SLOT_OFFSET_X,
SG_SLOT_Y + SG_SLOT_OFFSET_Y + (slot_num * SG_SLOT_HT));
uiShowMouse(NULL);
return OK;
}
errtype draw_savegame_names(void) {
int i;
for (i = 0; i < NUM_SAVE_SLOTS; i++)
draw_sg_slot(i);
return OK;
}
errtype load_that_thar_game(int which_slot) {
DEBUG("load_that_thar_game %i", which_slot);
errtype retval;
if (valid_save & (1 << which_slot)) {
draw_sg_slot(-1); // highlight the current save game slot with SELECTED_COLOR
clear_player_data = TRUE; // initializes the player struct in object_data_load
object_data_load();
player_create_initial();
player_struct.level = 0xFF; // make sure we load textures
Poke_SaveName(which_slot);
change_mode_func(0, 0, GAME_LOOP);
retval = load_game(save_game_name);
if (retval != OK) {
strcpy(comments[which_slot], "<< INVALID GAME >>");
uiHideMouse(NULL);
journey_continue_func(TRUE);
return retval;
}
gr2ss_override = OVERRIDE_ALL; // CC: This fixed popups cursors drawing tiny after loading
}
return OK;
}
errtype journey_continue_func(uchar draw_stuff) {
#ifndef DEMO
if (save_game_exists) {
// draw_raw_res_bm_extract(REF_IMG_bmContinueScreen, 0, 0);
// do what the above line does, but hack bitmap height
Ref rid = REF_IMG_bmContinueScreen;
int i = REFINDEX(rid);
RefTable *rt = ResReadRefTable(REFID(rid));
if (RefIndexValid(rt, i)) {
FrameDesc *f = RefLock(rid);
grs_bitmap bm = f->bm;
bm.h = 200; // SUPER HACK: resource reports 320
ss_bitmap(&bm, 0, 0);
RefUnlock(rid);
}
ResFreeRefTable(rt);
setup_mode = SETUP_CONTINUE;
draw_savegame_names();
}
#endif
uiShowMouse(NULL);
return OK;
}
//*****************************************************************************
//*****************************************************************************
// SETUP
#define DO_FADES
#define SECRET_MISSION_DIFFICULTY_QB 0xB0
#define ALT(x) ((x) | KB_FLAG_ALT)
#define CFG_NAME_VAR "name"
char diff_qvars[4] = {COMBAT_DIFF_QVAR, MISSION_DIFF_QVAR, PUZZLE_DIFF_QVAR, CYBER_DIFF_QVAR};
typedef errtype (*journey_func)(uchar draw_stuff);
journey_func journey_funcs[4] = {journey_intro_func, journey_difficulty_func, journey_credits_func,
journey_continue_func};
// if there are two different input events - only lets one call a journey_func
uchar journey_lock = FALSE;
void go_and_start_the_game_already(void) {
INFO("New Journey");
char i;
#ifdef GAMEONLY
if (strlen(player_struct.name) == 0) {
flash_username();
return;
}
#endif
uiHideMouse(NULL);
gr_set_fcolor(SELECTED_COLOR);
res_draw_string(RES_citadelFont, DIFF_START, DIFF_DONE_X1 + 13, DIFF_DONE_Y1 + 2);
uiShowMouse(NULL);
journey_newgame_func();
#ifdef SVGA_SUPPORT
QUESTVAR_SET(SCREENMODE_QVAR, convert_use_mode);
#endif
QUESTVAR_SET(MUSIC_VOLUME_QVAR, (curr_vol_lev * curr_vol_lev) / 100);
QUESTVAR_SET(SFX_VOLUME_QVAR, (curr_sfx_vol * curr_sfx_vol) / 100);
#ifdef AUDIOLOGS
QUESTVAR_SET(ALOG_VOLUME_QVAR, (curr_alog_vol * curr_alog_vol) / 100);
QUESTVAR_SET(ALOG_OPT_QVAR, audiolog_setting);
#endif
QUESTVAR_SET(FULLSCRN_ICON_QVAR, fullscrn_icons);
QUESTVAR_SET(FULLSCRN_VITAL_QVAR, fullscrn_vitals);
QUESTVAR_SET(AMAP_NOTES_QVAR, map_notes_on);
QUESTVAR_SET(HUDCOLOR_QVAR, hud_color_bank);
QUESTVAR_SET(SCREENMODE_QVAR, 3);
QUESTVAR_SET(DCLICK_QVAR, FIX_UNIT / 3);
for (i = 0; i < 4; i++)
QUESTVAR_SET(diff_qvars[i], player_struct.difficulty[i]);
if (QUESTVAR_GET(MISSION_DIFF_QVAR) == 3)
hud_set(HUD_GAMETIME);
strncpy(player_struct.version, SYSTEM_SHOCK_VERSION, 6);
if (setup_bio_started) {
status_bio_end();
setup_bio_started = FALSE;
}
gr2ss_override = OVERRIDE_ALL; // CC: This fixed popups cursors drawing tiny
}
uchar intro_mouse_handler(uiEvent *ev, LGRegion *r, intptr_t user_data) {
int which_one = -1;
int i = 0;
int old_diff;
uchar diff_changed;
#ifndef NO_DUMMIES
intptr_t dummy = user_data;
LGRegion *dummy2 = r;
#endif
if (ev->mouse_data.action & MOUSE_LDOWN) {
// If in the splash screen, advance
if (waiting_for_key) {
waiting_for_key = false;
return OK;
}
switch (setup_mode) {
case SETUP_JOURNEY:
if (!journey_lock) {
if ((ev->pos.x > JOURNEY_OPT_LEFT) && (ev->pos.x < JOURNEY_OPT_RIGHT)) {
while ((which_one == -1) && (i <= 6)) {
if ((ev->pos.y > journey_y[i]) && (ev->pos.y < journey_y[i + 1]))
which_one = i >> 1;
else
i += 2;
}
TRACE("%s: which_one = %d", __FUNCTION__, which_one);
if (which_one != -1) {
uiHideMouse(NULL);
gr_set_fcolor(SELECTED_COLOR);
journey_lock = TRUE;
journey_funcs[which_one](TRUE);
journey_lock = FALSE;
}