-
Notifications
You must be signed in to change notification settings - Fork 0
/
wfuncs.cpp
2057 lines (1856 loc) · 63.2 KB
/
wfuncs.cpp
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) 1985-2014 Daniel D Miller
// winwiz.exe - Win32 version of Wizard's Castle
// wfuncs.cpp - handle data update and rendering functions
//
// Written by: Dan Miller
//****************************************************************************
#include <windows.h>
#include <stdlib.h> // rand()
#include "resource.h"
#include "common.h"
#include "commonw.h"
#include "wizard.h"
#include "keywin32.h"
#include "cterminal.h"
#include "lode_png.h"
extern LodePng pngSprites ;
// extern LodePng pngVictory ;
// extern LodePng pngDeath ;
extern LodePng pngTiles ;
//@@@ why do I need this here??
//@@@ It *should* be defined in windef.h
#define min(a, b) (((a) < (b)) ? (a) : (b))
//lint -esym(714, clear_room)
//lint -esym(759, clear_room)
//lint -esym(765, clear_room)
//lint -esym(715, hdc, hwnd)
// winwiz.cpp
extern CTerminal *myTerminal ;
extern bool prog_init_done ;
//*************************************************************
#define X_OFFSET 16
#define X_GAP 10
#define Y_OFFSET 16
#define Y_GAP 10
//*************************************************************
static HWND hwndTreasures[10] ;
static HWND hwndMapArea = NULL ;
static HWND status_windows[8] ;
static bool level_known[DIMEN_COUNT] = { false, false, false, false, false, false, false, false };
// static bool location_forgotten = false ;
typedef enum map_image_e {
MI_UNDEFINED=0,
MI_MAP,
MI_COMBAT,
MI_VICTORY,
MI_DEATH
} map_image_t ;
static map_image_t map_image = MI_UNDEFINED ;
//***********************************************************************
static void react_to_room(HWND hwndUnused);
static void show_flares(void);
static void show_str(void);
static void mark_room_as_known(unsigned x, unsigned y, unsigned level);
static void draw_char_cursor(HDC hdc, unsigned on_or_off);
static bool is_location_forgotten(void)
{
return !level_known[player.level] ;
}
/************************************************************************/
void dump_level_knowledge(void)
{
syslog("0%c 1%c 2%c 3%c 4%c 5%c 6%c 7%c, level=%u\n",
(level_known[0]) ? 'T' : 'F',
(level_known[1]) ? 'T' : 'F',
(level_known[2]) ? 'T' : 'F',
(level_known[3]) ? 'T' : 'F',
(level_known[4]) ? 'T' : 'F',
(level_known[5]) ? 'T' : 'F',
(level_known[6]) ? 'T' : 'F',
(level_known[7]) ? 'T' : 'F',
player.level) ;
}
//*************************************************************
static unsigned get_room_contents(unsigned x, unsigned y, unsigned level)
{
return castle[x][y][level].contents ;
}
unsigned get_room_contents(void)
{
return castle[player.x][player.y][player.level].contents ;
}
//*************************************************************
char *get_room_contents_str(void)
{
return object_data[get_room_contents()].desc ;
}
//*************************************************************
static char *get_object_in_room(int x, int y, int level)
{
return object_data[get_room_contents(x, y, level)].desc ;
}
//*************************************************************
char *get_object_name(int index)
{
return object_data[index].desc ;
}
/************************************************************************/
// used only for Runestaff and OrbOfZot fields
/************************************************************************/
static void clear_treasure_area(HWND hwnd, COLORREF Color)
{
RECT rect ;
SetRect (&rect, 0, 0, SPRITE_WIDTH, SPRITE_HEIGHT) ;
HDC hdc = GetDC(hwnd) ;
HBRUSH hBrush = CreateSolidBrush (Color) ;
FillRect (hdc, &rect, hBrush) ;
DeleteObject (hBrush) ;
ReleaseDC(hwnd, hdc) ;
}
//***********************************************************************
// static void draw_sprite_treasure(HWND hwnd, unsigned scol, unsigned srow, unsigned xidest, unsigned yidest)
static void draw_sprite_treasure(unsigned scol, unsigned srow, unsigned idx)
{
HWND hwnd = hwndTreasures[idx] ;
HDC hdc = GetDC(hwnd) ;
pngSprites.render_bitmap(hdc, 0, 0, scol, srow) ;
ReleaseDC(hwnd, hdc) ;
}
//***********************************************************************
// static char *sprite_img_name = "tiles32.jpg";
static void draw_sprite(HDC hdc, unsigned scol, unsigned srow, unsigned xidest, unsigned yidest)
{
if (xidest >= 8 || yidest >= 8) {
syslog("draw_sprite: invalid pos: col=%u, row=%u\n", xidest, yidest) ;
return ;
}
unsigned xdest = X_OFFSET + (xidest * (SPRITE_WIDTH + X_GAP)) ; // draw_sprite()
unsigned ydest = Y_OFFSET + (yidest * (SPRITE_HEIGHT + Y_GAP)) ; // draw_sprite()
pngSprites.render_bitmap(hdc, xdest, ydest, scol, srow) ;
}
//***********************************************************************
static void draw_room_contents(HDC hdc, unsigned col, unsigned row)
{
unsigned content ;
if (castle[col][row][player.level].is_known)
content = get_room_contents(col, row, player.level) ;
else
content = UNSEEN_ROOM ;
draw_sprite(hdc,
object_data[content].sprite_col,
object_data[content].sprite_row,
col, row) ;
}
//***********************************************************************
static void draw_all_room_sprites(void)
{
HDC hdc = GetDC(hwndMapArea) ;
for (unsigned row=0; row<8; row++)
for (unsigned col=0; col<8; col++)
draw_room_contents(hdc, col, row) ;
ReleaseDC(hwndMapArea, hdc) ;
}
//***********************************************************************
static void draw_all_room_sprites(HDC hdc)
{
for (unsigned row=0; row<8; row++)
for (unsigned col=0; col<8; col++)
draw_room_contents(hdc, col, row) ;
}
/************************************************************************/
static void clear_map_area(HDC hdc, COLORREF Color)
{
RECT rect ;
// SetRect (&rect, 0, 0, HORZ_DIVIDER, VERT_DIVIDER-1) ;
GetClientRect(hwndMapArea, &rect) ;
// rect.left += 1 ;
// rect.top += 1 ;
rect.right -= 1 ;
// rect.bottom -= 1 ;
HBRUSH hBrush = CreateSolidBrush (Color) ;
FillRect (hdc, &rect, hBrush) ;
DeleteObject (hBrush) ;
}
//*************************************************************
void clear_room(HDC hdcUnused)
{
HDC hdc = GetDC(hwndMapArea) ;
castle[player.x][player.y][player.level].contents = EMPTY_ROOM ;
mark_room_as_known(player.x, player.y, player.level) ;
draw_room_contents(hdc, player.x, player.y) ; // calls draw_sprite()
show_player() ;
ReleaseDC(hwndMapArea, hdc) ;
}
//*************************************************************
static void update_position(void)
{
if (player.is_blind || is_location_forgotten())
wsprintf (tempstr, " X=?, Y=?");
else
wsprintf (tempstr, " X=%u, Y=%u", player.x, player.y);
status_message(1, tempstr);
if (player.is_blind || is_location_forgotten())
wsprintf (tempstr, " level=?");
else
wsprintf (tempstr, " level=%u", player.level);
status_message(2, tempstr);
}
//***********************************************************************
// this should *only* redraw the map
//***********************************************************************
void redraw_map(void)
{
if (!prog_init_done) {
return ;
}
// syslog("redraw_map\n") ;
HDC hdc = GetDC(hwndMapArea) ;
// syslog("call clear_map_area\n") ;
clear_map_area(hdc, WIN_BLACK) ;
draw_all_room_sprites(hdc); // using hwndMapArea
clear_room(NULL); // calls show_player()
ReleaseDC(hwndMapArea, hdc) ;
set_term_attr_default();
}
//*************************************************************
// called only by draw_main_screen()
//*************************************************************
static void redraw_game_screen(void)
{
HDC hdc = GetDC(hwndMapArea) ;
clear_map_area(hdc, WIN_BLACK) ;
draw_all_room_sprites(hdc); // using hwndMapArea
show_player() ;
update_position() ;
ReleaseDC(hwndMapArea, hdc) ;
set_term_attr_default();
}
//***********************************************************************
// called by *many* functions
//***********************************************************************
void draw_main_screen(HDC hdcUnused)
{
if (cxClient == 0 || cyClient == 0)
return ;
// syslog("draw_main_screen\n") ;
map_image = MI_MAP ;
// Old procedure:
// redraw_game_screen() did not call clear_room(),
// redraw_map() does...
redraw_game_screen() ;
// update_status() ;
// redraw_level(hdc) ;
// redraw_map();
update_status() ;
}
//****************************************************************************
void draw_current_screen(void)
{
HDC hdc ;
switch (map_image) {
case MI_COMBAT:
hdc = GetDC(hwndMapArea) ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_COMBAT) ;
ReleaseDC(hwndMapArea, hdc) ;
break;
case MI_VICTORY:
hdc = GetDC(hwndMapArea) ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_VICTORY) ;
ReleaseDC(hwndMapArea, hdc) ;
break;
case MI_DEATH:
hdc = GetDC(hwndMapArea) ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_DEATH) ;
ReleaseDC(hwndMapArea, hdc) ;
break;
case MI_UNDEFINED:
case MI_MAP:
default:
draw_main_screen(NULL) ;
break;
}
}
//****************************************************************************
static void restore_room(HDC hdc) // derived from hwndMapArea
{
draw_char_cursor(hdc, OFF) ;
draw_room_contents(hdc, player.x, player.y);
}
//*************************************************************
void show_player(void)
{
if (!player.is_blind) {
HDC hdc = GetDC(hwndMapArea) ;
draw_sprite(hdc, object_data[PLAYER].sprite_col,
object_data[PLAYER].sprite_row, player.x, player.y) ;
draw_char_cursor(hdc, ON) ;
ReleaseDC(hwndMapArea, hdc) ;
}
update_position() ;
}
//*************************************************************
bool starts_with_vowel(char *monster)
{
switch (*monster) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
return true;
default:
return false;
}
}
/************************************************************************/
// ;* Description: Draw line from (x0,y0) to (x1,y1) using color 'Color' *
/************************************************************************/
static void Box(HDC hdc, int x0, int y0, int x1, int y1, unsigned Color)
{
static HPEN hPen ;
hPen = CreatePen(PS_SOLID, 1, Color) ;
SelectObject(hdc, hPen) ;
MoveToEx(hdc, x0, y0, NULL) ;
LineTo (hdc, x1, y0) ;
LineTo (hdc, x1, y1) ;
LineTo (hdc, x0, y1) ;
LineTo (hdc, x0, y0) ;
SelectObject(hdc, GetStockObject(BLACK_PEN)) ; // deselect my pen
DeleteObject (hPen) ;
}
//***********************************************************************
static COLORREF cursor_frames[3] = {
WIN_GREEN, WIN_BMAGENTA, WIN_BGREEN
} ;
static uint cursor_idx = 0 ;
static void draw_char_cursor(HDC hdc, unsigned on_or_off)
{
// calculate actual bounds
unsigned x0 = X_OFFSET + (player.x * (SPRITE_WIDTH + X_GAP)) ; // cursor computation
unsigned y0 = Y_OFFSET + (player.y * (SPRITE_HEIGHT + Y_GAP)) ; // cursor computation
unsigned x1 = x0 + SPRITE_WIDTH ;
unsigned y1 = y0 + SPRITE_HEIGHT ;
unsigned Color = WIN_BLACK ;
if (on_or_off == ON)
Color = cursor_frames[cursor_idx % 3] ;
x0-- ;
y0-- ;
Box(hdc, x0, y0, x1, y1, Color) ;
if (on_or_off == ON)
Color = cursor_frames[(cursor_idx+1) % 3] ;
x0-- ;
y0-- ;
x1++ ;
y1++ ;
Box(hdc, x0, y0, x1, y1, Color) ;
if (on_or_off == ON)
Color = cursor_frames[(cursor_idx+2) % 3] ;
x0-- ;
y0-- ;
x1++ ;
y1++ ;
Box(hdc, x0, y0, x1, y1, Color) ;
}
//*************************************************************
void update_cursor(void)
{
HDC hdc ;
if (is_default_keymap() && !player.is_blind) {
if (++cursor_idx >= 3)
cursor_idx = 0 ;
switch (map_image) {
case MI_MAP:
hdc = GetDC(hwndMapArea) ;
draw_char_cursor(hdc, true) ;
ReleaseDC(hwndMapArea, hdc) ;
break;
case MI_UNDEFINED:
case MI_COMBAT:
case MI_VICTORY:
case MI_DEATH:
default:
draw_main_screen(NULL) ;
break;
}
}
}
//****************************************************************************
static void mark_room_as_known(unsigned x, unsigned y, unsigned level)
{
castle[x][y][level].is_known = 1 ;
}
static void hide_room(unsigned x, unsigned y, unsigned level)
{
castle[x][y][level].is_known = 0 ;
}
//*************************************************************
void render_combat_bitmap(void)
{
HDC hdc = GetDC(hwndMapArea) ;
map_image = MI_COMBAT ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_COMBAT) ;
ReleaseDC(hwndMapArea, hdc) ;
}
//************************************************************************************
// This function is one of the optional operations that may be invoked when
// a chest is opened. The original design attempted to add up the existing
// attribute values and randomly re-distribute them, but that is difficult to
// do in a truly balanced fashion.
//
// Instead, this modified routine (from 09/08/23) randomly generates new attributes
// from the theoretical maximum values.
// It may generate a total amount which is more or less than the original total,
// but it has advantage of being a truly random distribution.
//************************************************************************************
static void ScrambleAttr(void)
{
unsigned j=0, k=0, l=0 ;
#define USE_BASIC_SYSTEM
#ifdef USE_BASIC_SYSTEM
#define MAX_SINGLE_ATTR 18
j = 1 + random_int(MAX_SINGLE_ATTR);
k = 1 + random_int(MAX_SINGLE_ATTR);
l = 1 + random_int(MAX_SINGLE_ATTR);
#else
// This method favours STR over DEX, and DEX over INT.
unsigned attr_temp = player.str + player.dex + player.iq ;
j = (1 + random(min(attr_temp, 18))) ;
attr_temp -= j ;
if (attr_temp == 0) goto skipping ;
k = (1 + random(min(attr_temp, 18))) ;
attr_temp -= k ;
if (attr_temp == 0) goto skipping ;
l = (1 + random(min(attr_temp, 18))) ;
attr_temp -= l ;
skipping:
// printf("init str=%u, dex=%u, int=%u, j=%u, k=%u, l=%u, temp=%u\n",
// str, dex, iq, j, k, l, attr_temp) ;
// distribute remaining points evenly across all stats
while (attr_temp != 0) {
unsigned touched = 0 ;
if (j < 18) {
j++ ;
touched++ ;
if (--attr_temp == 0)
continue;
}
if (k < 18) {
k++ ;
touched++ ;
if (--attr_temp == 0)
continue;
}
if (l < 18) {
l++ ;
touched++ ;
if (--attr_temp == 0)
continue;
}
if (!touched) {
wsprintf(tempstr, "no touch: str=%u, dex=%u, int=%u\n", j, k, l) ;
status_message(tempstr);
break;
}
}
#endif
// attribute selection here should also be random...
player.str = j ;
player.dex = k ;
player.iq = l ;
adjust_hit_points() ;
update_status() ;
}
//*************************************************************
void win_game(HWND hwnd)
{
push_keymap(KEYMAP_WAIT_END) ;
HDC hdc = GetDC(hwndMapArea) ;
clear_map_area(hdc, WIN_BLACK) ;
map_image = MI_VICTORY ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_VICTORY) ;
ReleaseDC(hwndMapArea, hdc) ;
myTerminal->clear_message_area() ;
put_message("You find yourself standing beside a sweet, cool") ;
put_message("stream in the shade of a glowing, verdant forest...") ;
put_message(" ") ;
wsprintf(tempstr, "You emerge Victorious from %s !!!", names[player.castle_nbr]) ;
put_message(tempstr) ;
}
//*************************************************************
static void display_atmosphere(HDC hdcUnused)
{
if (player.has_orb_of_Zot) {
put_color_msg(TERM_DEATH, "In a burst of intense agony, you feel your very soul ripped from") ;
put_color_msg(TERM_DEATH, "your body, and sucked into the Orb of Zot, which drops to the ground") ;
put_color_msg(TERM_DEATH, "with a soft 'tink', and sinks softly below the surface.") ;
put_color_msg(TERM_DEATH, "Oddly, you find you are not alone within the Orb... in fact, your existance") ;
put_color_msg(TERM_DEATH, "promises to become quite interesting now - but that's another story.") ;
} else
if (player.has_runestaff) {
put_color_msg(TERM_DEATH, "With your last fading breath, you gasp a curse upon %s!!",
names[player.castle_nbr]) ;
put_color_msg(TERM_DEATH, "The power of your curse causes the Runestaff to shatter with") ;
put_color_msg(TERM_DEATH, "a catastrophic blast, collapsing the castle upon itself...") ;
put_color_msg(TERM_DEATH, "Surely the Wizard of Zot would be gratified.") ;
} else
{
put_color_msg(TERM_DEATH, "You died while exploring %s", names[player.castle_nbr]) ;
// char *sptr = get_object_in_room(player.x, player.y, player.level) ;
char *sptr = get_object_in_room(runestaff_room.x, runestaff_room.y, runestaff_room.level) ;
put_color_msg(TERM_DEATH, "%s %s declares itself Master of the Castle!!",
starts_with_vowel(sptr) ? "An" : "A", sptr) ;
}
}
//*************************************************************
void player_dies(HWND hwnd)
{
push_keymap(KEYMAP_WAIT_END) ;
HDC hdc = GetDC(hwndMain) ;
update_status() ;
// pngDeath.render_bitmap(hdc, 0, 0);
map_image = MI_DEATH ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_DEATH) ;
display_atmosphere(hdc) ;
ReleaseDC(hwndMapArea, hdc) ;
}
//*************************************************************
static char *zot_chest_end_msg[] = {
"The wizard continues speaking as you respond, but his voice",
"grows ever fainter, until it fades from hearing...",
" ",
"You grow colder and colder as your vision fades.......",
" ",
0 } ;
static void wrong_castle_death(HWND hwnd)
{
// hide_status_area() ;
// enable_player_info(false) ;
// HDC hdc = hdcMain ;
// draw_main_screen(NULL) ;
myTerminal->clear_message_area() ;
// redraw_game_screen(hdc) ; // wrong_castle_death()
// show_status_area() ;
// enable_player_info(true) ;
for (unsigned j=0; zot_chest_end_msg[j] != 0; j++)
// put_color_msg(TERM_DEATH, zot_chest_end_msg[j]) ;
put_color_msg(TERM_DEATH, zot_chest_end_msg[j]) ;
// pngDeath.render_bitmap(hdc, 0, 0);
HDC hdc = GetDC(hwndMapArea) ;
pngTiles.render_bitmap(hdc, 0, 0, TILE_DEATH) ;
ReleaseDC(hwndMapArea, hdc) ;
map_image = MI_DEATH ;
infoout("You died while exploring %s", names[player.castle_nbr]) ;
}
//*************************************************************
static char *first_zot_chest_msg[] = {
"The room fills with smoke that has an odd odor.",
"The smoke seems to bite into your skin.",
"Anxiety thrills through your body....",
" ",
"You are blinded for a moment, but then",
"the image of a man appears before you.",
"He is old and wizened, but seems strong despite his age.",
0 } ;
static char *second_zot_chest_msg[] = {
"This smoke is strong with the power of ZOT......",
"You are too weak to resist its effects, and you ",
"are now floating far, far away into the smoke...",
" ",
"I may be able to save you if you can tell me",
"WHICH CASTLE you are from .....",
"Please speak quickly before you are out of reach!!",
0 } ;
//*************************************************************
#define MAX_CASTLE_NAME 20
static char castle_name[MAX_CASTLE_NAME+1] ;
static unsigned cn_len ;
#ifdef USE_MESSAGE_WINDOW
static unsigned zot_name_row = 0 ;
#endif
// #define USE_MESSAGE_WINDOW 1
//*************************************************************
static int process_zot_keystroke (HWND hwnd, unsigned inchr)
{
// wsprintf(tempstr, "%X ", inchr) ;
// OutputDebugString(tempstr) ;
if (inchr & 0xFF00) {
wsprintf (tempstr, "PRESS=0x%04X", inchr);
status_message(tempstr);
}
// process normal keys
else if (inchr == kENTER) {
// return (cn_len == 0) ? -1 : (int) cn_len ;
return (int) cn_len ;
}
else if (inchr == kBSPACE) {
if (cn_len > 0) {
#ifdef USE_MESSAGE_WINDOW
// over-write existing name with black-on-black
dprints_centered_x(hwnd, zot_name_row, 0, 0, castle_name) ;
// modify name and redraw it
cn_len-- ;
castle_name[cn_len] = 0 ; // make sure string stays NULL-term
dprints_centered_x(hwnd, zot_name_row, WIN_BGREEN, 0, castle_name) ;
#else
// modify name and redraw it
cn_len-- ;
castle_name[cn_len] = 0 ; // make sure string stays NULL-term
term_replace(castle_name) ;
#endif
}
}
else {
if (cn_len < MAX_CASTLE_NAME) {
// wsprintf(tempstr, "%u ", inchr) ;
// OutputDebugString(tempstr) ;
// for some reason, single-quotes are coming in as 0xDE ...
if ((u8) inchr == 0xDE) {
inchr = 0x27 ;
}
castle_name[cn_len] = (char) inchr ;
cn_len++ ;
castle_name[cn_len] = 0 ; // make sure string stays NULL-term
#ifdef USE_MESSAGE_WINDOW
dprints_centered_x(hwnd, zot_name_row, WIN_BGREEN, 0, castle_name) ;
#else
term_replace(castle_name) ;
#endif
}
}
return 0; // indicates more data follows
}
//*********************************************************
int manage_zot_input(HWND hwnd, unsigned inchr)
{
int result = process_zot_keystroke (hwnd, inchr);
if (result < 0) {
// treat -1 as automatic fail
// OutputDebugString("automatic fail??") ;
wrong_castle_death(hwnd) ;
result = -1 ;
}
else if (result > 0) {
// compare entered data vs castle name
if (strnicmp(castle_name, names[player.castle_nbr],
strlen(names[player.castle_nbr])) == 0) {
result = 1 ;
infoout("Whew!!!") ;
// hide_status_area() ;
// clear_dialog_area(hdcMain, GetSysColor(COLOR_3DFACE));
// enable_player_info(false) ;
} else {
// clear_dialog_area(hdcMain, GetSysColor(COLOR_3DFACE));
wrong_castle_death(hwnd) ;
result = -1 ;
}
}
return result ;
}
//*********************************************************
static void draw_zot_window(HWND hwnd)
{
unsigned j ;
myTerminal->clear_message_area() ;
// clear_dialog_area(hdcMain, WIN_BLACK);
cn_len = 0 ;
castle_name[cn_len] = 0 ; // make sure string stays NULL-term
// void dprints_centered_x(HDC hdc, LONG y, unsigned attr, char *str)
#ifdef USE_MESSAGE_WINDOW
unsigned theight ;
static unsigned y = 0 ;
HDC hdc = hdcMain ; // ifdef USE_MESSAGE_WINDOW
myTerminal->set_terminal_font("Bodacious-Normal", 110, EZ_ATTR_NORMAL) ;
set_text_font("Bodacious-Normal", 110) ;
theight = textheight(hdc, 0) ;
y = 2 * theight ;
for (j=0; first_zot_chest_msg[j] != 0; j++) {
dprints_centered_x(hdc, y, WIN_BRED, first_zot_chest_msg[j]) ;
y += theight ;
}
y += theight ;
dprints_centered_x(hdc, y, WIN_BMAGENTA, " He speaks: ") ;
y += theight ;
y += theight ;
for (j=0; second_zot_chest_msg[j] != 0; j++) {
dprints_centered_x(hdc, y, WIN_BRED, second_zot_chest_msg[j]) ;
y += theight ;
}
y += theight ;
zot_name_row = y ;
#else
for (j=0; first_zot_chest_msg[j] != 0; j++) {
put_message(WIN_BRED, WIN_BLACK, first_zot_chest_msg[j]) ;
}
put_message(WIN_BMAGENTA, WIN_BLACK, " He speaks: ") ;
for (j=0; second_zot_chest_msg[j] != 0; j++) {
put_message(WIN_BRED, WIN_BLACK, second_zot_chest_msg[j]) ;
}
#endif
}
//*********************************************************
static void CheckCurses(HDC hdc) // derived from hwndMapArea
{
unsigned x, y, level, itemp ;
player.turns++ ;
/* CURSE OF LETHARGY */
// treasure[0] (Ruby Red) cures lethargy
// not currently used
if (player.curse_flags & CR_LETHARGY) {
if (player.treasures[TR_RUBY_RED]) {
player.curse_flags &= ~CR_LETHARGY ;
put_message("The Ruby Red cures the Curse of Lethargy...") ;
} else {
}
}
/* CURSE OF THE LEECH */
// treasure[2] (Pale Pearl) cures leech
if (player.curse_flags & CR_LEECH) {
if (player.treasures[TR_PALE_PEARL]) {
player.curse_flags &= ~CR_LEECH ;
put_message("The Pale Pearl cures the Curse of the Leech...") ;
} else {
itemp = random(5);
if (itemp >= player.gold) {
player.gold = 0 ;
} else {
player.gold -= itemp ;
}
show_gold() ;
}
}
/* CURSE OF FORGETFULNESS */
// treasure[4] (Green Gem) cures forgetfulness
if (player.curse_flags & CR_FORGET) {
if (player.treasures[TR_GREEN_GEM]) {
player.curse_flags &= ~CR_FORGET ;
put_message("The Green Gem cures the Curse of Forgetfulness...") ;
} else {
x = random(DIMEN_COUNT); y = random(DIMEN_COUNT); level = random(DIMEN_COUNT);
hide_room(x, y, level) ;
if (level == player.level) {
draw_room_contents(hdc, x, y) ;
}
}
}
// did we step on a new curse??
if (curse_rooms[CURSE_OF_LETHARGY].is_known == 0 &&
curse_rooms[CURSE_OF_LETHARGY].x == player.x &&
curse_rooms[CURSE_OF_LETHARGY].y == player.y &&
curse_rooms[CURSE_OF_LETHARGY].level == player.level) {
curse_rooms[CURSE_OF_LETHARGY].is_known = 1 ;
if (!(player.treasures[TR_RUBY_RED])) {
player.curse_flags |= CR_LETHARGY ;
put_message("*** You have been afflicted with the Curse of Lethargy !!") ;
}
}
if (curse_rooms[CURSE_OF_LEECH].is_known == 0 &&
curse_rooms[CURSE_OF_LEECH].x == player.x &&
curse_rooms[CURSE_OF_LEECH].y == player.y &&
curse_rooms[CURSE_OF_LEECH].level == player.level) {
curse_rooms[CURSE_OF_LEECH].is_known = 1 ;
if (!(player.treasures[TR_PALE_PEARL])) {
player.curse_flags |= CR_LEECH ;
put_message("*** You have been afflicted with the Curse of the Leech !!") ;
}
}
if (curse_rooms[CURSE_OF_FORGET].is_known == 0 &&
curse_rooms[CURSE_OF_FORGET].x == player.x &&
curse_rooms[CURSE_OF_FORGET].y == player.y &&
curse_rooms[CURSE_OF_FORGET].level == player.level) {
curse_rooms[CURSE_OF_FORGET].is_known = 1 ;
if (!(player.treasures[TR_GREEN_GEM])) {
player.curse_flags |= CR_FORGET ;
put_message("*** You have been afflicted with the Curse of Amnesia !!") ;
}
}
}
//*********************************************************
static char *comment_str[9] = {
"You stepped on a toad...",
"You hear a scream!!",
"You hear someone breathing!!",
"You hear a Limnphedon!",
"You hear thunder in the distance.",
"You feel bugs on your face !",
"You smell a fried monster",
"You see something glowing in the distance !",
"You hear faint rustling noises..."
} ;
static void Comments(void)
{
if (random(5) == 1) {
put_color_msg(TERM_ATMOSPHERE, comment_str[random(9)]) ;
}
}
//*************************************************************
static bool is_monster_index(uint idx)
{
if (idx >= MONSTER_BASE && idx <= MONSTER_END)
return true;
return false;
}
//*************************************************************
static void update_room(void)
{
if (player.is_blind)
return ;
HDC hdc = GetDC(hwndMapArea) ;
mark_room_as_known(player.x, player.y, player.level) ;
show_player() ;
if (player.has_lamp) {
if (player.x > 0) {
mark_room_as_known(player.x-1, player.y, player.level) ;
draw_room_contents(hdc, player.x-1, player.y) ;
}
if (player.x < 7) {
mark_room_as_known(player.x+1, player.y, player.level) ;
draw_room_contents(hdc, player.x+1, player.y) ;
}
if (player.y > 0) {
mark_room_as_known(player.x, player.y-1, player.level) ;
draw_room_contents(hdc, player.x, player.y-1) ;
}
if (player.y < 7) {
mark_room_as_known(player.x, player.y+1, player.level) ;
draw_room_contents(hdc, player.x, player.y+1) ;
}
}
// do not repeatedly display the "here you find normal room" message
uint idx = get_room_contents() ;
if (idx != EMPTY_ROOM) {
// if (idx >= MONSTER_BASE && idx <= MONSTER_END) {
if (is_monster_index(idx)) {
char *sptr = get_object_in_room(player.x, player.y, player.level) ;
wsprintf(tempstr, "Here you find %s %s.",
starts_with_vowel(sptr) ? "an" : "a", sptr) ;
// get_object_in_room(player.x, player.y, player.level)) ;
} else {
wsprintf(tempstr, "Here you find %s.",
get_object_in_room(player.x, player.y, player.level)) ;
}
put_message(tempstr) ;
}
ReleaseDC(hwndMapArea, hdc) ;
}
//****************************************************************************
int move_west(HWND hwnd)
{
if (player.x == 0)
return 1 ;
HDC hdc = GetDC(hwndMapArea) ;
restore_room(hdc) ;
player.x-- ;
update_room() ;
react_to_room(NULL) ;
ReleaseDC(hwndMapArea, hdc) ;
Comments() ;
return 0;
}
//****************************************************************************
int move_east(HWND hwnd)
{
if (player.x == 7)
return 1 ;
HDC hdc = GetDC(hwndMapArea) ;
restore_room(hdc) ;
player.x++ ;
update_room() ;
react_to_room(NULL) ;
ReleaseDC(hwndMapArea, hdc) ;
Comments() ;
return 0;
}
//****************************************************************************
int move_north(HWND hwnd)
{
if (player.y == 0)
return 1 ;
HDC hdc = GetDC(hwndMapArea) ;
restore_room(hdc) ;
player.y-- ;
update_room() ;
react_to_room(NULL) ;
ReleaseDC(hwndMapArea, hdc) ;
Comments() ;
return 0;
}
//****************************************************************************
int move_south(HWND hwnd)
{
if (player.y == 7)
return 1 ;
HDC hdc = GetDC(hwndMapArea) ;
restore_room(hdc) ;
player.y++ ;
update_room() ;
react_to_room(NULL) ;
ReleaseDC(hwndMapArea, hdc) ;
Comments() ;
return 0;
}
//****************************************************************************
int move_down(HWND hwnd)
{
int room_chr = get_room_contents();
if (room_chr != STAIRS_DOWN) {
put_message("It's hard to climb the walls...FIND SOME STAIRS!!");
return 1 ;
}
bool prev_level_known = level_known[player.level] ;
if (player.level < 7) {