-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdungeon.c
5862 lines (5190 loc) · 158 KB
/
dungeon.c
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
/* dungeon.c */
/* Here you should find the guts of the game */
#include "imoria.h"
#include "dungeon.h"
//////////////////////////////////////////////////////////////////////
/* I got rid of all the ones I think are not "real" globals... */
integer dir_val; // { For movement (running)}
// integer y,x,moves; // { For movement }
// integer i1,i2,tmp1; // { Temporaries }
integer old_chp,old_cmana; // { Detect change }
real regen_amount; // { Regenerate hp and mana}
char command; // { Last command }
// vtype out_val,out2; // { For messages }
// vtype tmp_str; // { Temporary }
boolean moria_flag; // { Next level when true }
boolean reset_flag; // { Do not move creatures }
boolean search_flag; // { Player is searching }
boolean teleport_flag; // { Handle telport traps }
boolean player_light; // { Player carrying light }
boolean save_msg_flag; // { Msg flag after INKEY }
ttype s1,s2,s3,s4; // { Summon item strings }
integer i_summ_count; // { Summon item count }
// char trash_char;
// FILE * f1;
// stat_set tstat;
// treas_ptr trash_ptr;
//////////////////////////////////////////////////////////////////////
void panel_bounds()
{
/*{ Calculates current boundries -RAK- }*/
panel_row_min = (trunc(panel_row*(SCREEN_HEIGHT/2)) + 1);
panel_row_max = panel_row_min + SCREEN_HEIGHT - 1;
panel_col_min = (trunc(panel_col*(SCREEN_WIDTH/2)) + 1);
panel_col_max = panel_col_min + SCREEN_WIDTH - 1;
panel_row_prt = panel_row_min - 2;
panel_col_prt = panel_col_min - 15;
}
//////////////////////////////////////////////////////////////////////
/* { Figure out what kind of coin is beign asked about }*/
boolean coin_stuff(char typ, /*{ Initial of coin metal }*/
integer *type_num)
{
boolean return_value;
return_value = true;
switch (typ) {
case 'm' : *type_num = MITHRIL; break;
case 'p' : *type_num = PLATINUM; break;
case 'g' : *type_num = GOLD; break;
case 's' : *type_num = SILVER; break;
case 'c' : *type_num = COPPER; break;
case 'i' : *type_num = IRON; break;
default: return_value = false; break;
}
return return_value;
}; /* end coin_stuff */
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void get_money_type__prompt_money(vtype astr, string out_val, boolean *commas)
{
if (*commas) {
strcat(out_val, ", ");
}
strcat(out_val, astr);
*commas = true;
}; /* end get_money_type__prompt_money */
//////////////////////////////////////////////////////////////////////
integer get_money_type(
string prompt,
boolean *back,
boolean no_check)
{
/* { Prompt for what type of money to use -DMF- }*/
boolean comma_flag = false;
boolean test_flag = false;
string out_val;
integer com_val;
strncpy(out_val, prompt, sizeof(string));
if ((py.misc.money[6] > 0) || (no_check))
get_money_type__prompt_money("<m>ithril",out_val,&comma_flag);
if ((py.misc.money[5] > 0) || (no_check))
get_money_type__prompt_money("<p>latinum",out_val,&comma_flag);
if ((py.misc.money[4] > 0) || (no_check))
get_money_type__prompt_money("<g>old",out_val,&comma_flag);
if ((py.misc.money[3] > 0) || (no_check))
get_money_type__prompt_money("<s>ilver",out_val,&comma_flag);
if ((py.misc.money[2] > 0) || (no_check))
get_money_type__prompt_money("<c>opper",out_val,&comma_flag);
if ((py.misc.money[1] > 0) || (no_check))
get_money_type__prompt_money("<i>ron",out_val,&comma_flag);
prt(out_val,1,1);
*back = true;
do {
command = inkey();
com_val = (integer)(command);
switch (com_val) {
case 0: case 3: case 25: case 26: case 27:
test_flag = true;
*back = false;
break;
case 109:
test_flag = ((py.misc.money[MITHRIL] > 0) || (no_check));
break;
case 112:
test_flag = ((py.misc.money[PLATINUM] > 0) || (no_check));
break;
case 103:
test_flag = ((py.misc.money[GOLD] > 0) || (no_check));
break;
case 115:
test_flag = ((py.misc.money[SILVER] > 0) || (no_check));
break;
case 99:
test_flag = ((py.misc.money[COPPER] > 0) || (no_check));
break;
case 105:
test_flag = ((py.misc.money[IRON] > 0) || (no_check));
break;
} /* end switch */
} while (!test_flag);
return com_val;
}; /* end get_money_type */
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void py_bonuses(treasure_type *tobj, integer factor)
{
/*
{ Player bonuses -RAK- }
{ When an item is worn or taken off, this re-adjusts the player }
{ bonuses. Factor=1 : wear; Factor=-1 : removed }
*/
unsigned long item_flags,item_flags2;
integer i1,old_dis_ac;
stat_set tstat;
PF.see_inv = false;
PF.teleport = false;
PF.free_act = false;
PF.slow_digest = false;
PF.aggravate = false;
for (tstat = STR; tstat <= CHR; tstat++) {
PF.sustain[(int)tstat] = false;
}
PF.fire_resist = false;
PF.hunger_item = false;
PF.acid_resist = false;
PF.cold_resist = false;
PF.regenerate = false;
PF.lght_resist = false;
PF.ffall = false;
if (uand(Strength_worn_bit,tobj->flags) != 0) {
change_stat(STR,tobj->p1,factor);
print_stat = uor(0x0001,print_stat);
}
if (uand(Magic_proof_worn_bit,tobj->flags2) != 0) {
py.misc.save += (25 * factor);
}
if (uand(Bad_repute_worn_bit,tobj->flags2) != 0) {
change_rep(-100*factor); /*{XXX hey! this is bad! new variable!-ste}*/
}
if (uand(Disarm_worn_bit,tobj->flags2) != 0) {
py.misc.disarm += (tobj->p1 * factor);
}
if (uand(Dexterity_worn_bit,tobj->flags) != 0) {
change_stat(DEX,tobj->p1,factor);
print_stat = uor(0x0002,print_stat);
}
if (uand(Constitution_worn_bit,tobj->flags) != 0) {
change_stat(CON,tobj->p1,factor);
print_stat = uor(0x0004,print_stat);
}
if (uand(Intelligence_worn_bit,tobj->flags) != 0) {
change_stat(INT,tobj->p1,factor);
print_stat = uor(0x0008,print_stat);
}
if (uand(Wisdom_worn_bit,tobj->flags) != 0) {
change_stat(WIS,tobj->p1,factor);
print_stat = uor(0x0010,print_stat);
}
if (uand(Charisma_worn_bit,tobj->flags) != 0) {
change_stat(CHR,tobj->p1,factor);
print_stat = uor(0x0020,print_stat);
}
if (uand(Searching_worn_bit,tobj->flags) != 0) {
py.misc.srh += (tobj->p1 * factor);
py.misc.fos -= (tobj->p1 * factor);
}
if (uand(Stealth_worn_bit,tobj->flags) != 0) {
py.misc.stl += (tobj->p1 * factor) + factor;
}
if (uand(Speed_worn_bit,tobj->flags) != 0) {
i1 = tobj->p1*factor;
change_speed(-i1);
}
if (uand(Blindness_worn_bit,tobj->flags) != 0) {
if (factor > 0) {
py.flags.blind += 1000;
}
}
if (uand(Timidness_worn_bit,tobj->flags) != 0) {
if (factor > 0) {
py.flags.afraid += 50;
}
}
if (uand(Infra_Vision_worn_bit,tobj->flags) != 0) {
py.flags.see_infra += (tobj->p1 * factor);
}
if (uand(Swimming_worn_bit,tobj->flags2) != 0) {
i1 = tobj->p1*factor; /* XXX what does this do? */
}
if (uand(Increase_carry_worn_bit,tobj->flags2) != 0) {
switch (tobj->p1) {
case 1 : i1 = 500; break;
case 2 : i1 = 1000; break;
case 3 : i1 = 1750; break;
case 4 : i1 = 2500; break;
case 5 : i1 = 3500; break;
case 6 : i1 = 4500; break;
case 7 : i1 = 6000; break;
default:
MSG("Increase carry worn value (p1) out of range");
i1 = 500;
break;
}
py.misc.xtr_wgt += i1 * factor;
}
//with py.misc do;
old_dis_ac = PM.dis_ac;
PM.ptohit = tohit_adj(); //{ Real To Hit }
PM.ptodam = todam_adj(); //{ Real To Dam }
PM.ptoac = toac_adj(); //{ Real To AC }
PM.pac = 0; //{ Real AC }
PM.dis_th = PM.ptohit; //{ Display To Hit }
PM.dis_td = PM.ptodam; //{ Display To Dam }
PM.dis_ac = 0; //{ Display To AC }
PM.dis_tac = PM.ptoac; //{ Display AC }
for (i1 = Equipment_min; i1 <= EQUIP_MAX-2; i1++) {
//with equipment[i1] do;
if (equipment[i1].tval > 0) {
if (uand(Cursed_worn_bit,equipment[i1].flags) == 0) {
PM.pac += equipment[i1].ac;
PM.dis_ac += equipment[i1].ac;
}
PM.ptohit += equipment[i1].tohit;
PM.ptodam += equipment[i1].todam;
PM.ptoac += equipment[i1].toac;
if (strstr(equipment[i1].name,"^") == NULL) {
PM.dis_th += equipment[i1].tohit;
PM.dis_td += equipment[i1].todam;
PM.dis_tac += equipment[i1].toac;
}
}
}
PM.dis_ac += PM.dis_tac;
/* { Add in temporary spell increases }*/
//with py.flags do;
if (PF.invuln > 0) {
PM.pac += 100;
PM.dis_ac += 100;
}
if (PF.blessed > 0) {
PM.pac += 5;
PM.dis_ac += 5;
}
if (PF.detect_inv > 0) {
PF.see_inv = true; /* does this mean that if you put on/take off stuff
you are going to lose magic detect_inv ? */
}
if (old_dis_ac != PM.dis_ac) {
print_stat = uor(0x0040,print_stat);
}
item_flags2 = 0;
item_flags = 0;
for (i1 = Equipment_min; i1 <= EQUIP_MAX-2; i1++) {
//with equipment[i1] do;
item_flags = uor(item_flags,equipment[i1].flags);
item_flags2 = uor(item_flags2,equipment[i1].flags2);
}
//with py.flags do;
PF.slow_digest = uand( Slow_Digestion_worn_bit, item_flags) != 0;
PF.aggravate = uand( Aggravation_worn_bit, item_flags) != 0;
PF.teleport = uand( Teleportation_worn_bit, item_flags) != 0;
PF.regenerate = uand( Regeneration_worn_bit, item_flags) != 0;
PF.hunger_item = uand( Hunger_worn_bit, item_flags2) != 0;
PF.fire_resist = uand( Resist_Fire_worn_bit, item_flags) != 0;
PF.acid_resist = uand( Resist_Acid_worn_bit, item_flags) != 0;
PF.cold_resist = uand( Resist_Cold_worn_bit, item_flags) != 0;
PF.free_act = uand( Free_Action_worn_bit, item_flags) != 0;
PF.see_inv |= uand( See_Invisible_worn_bit, item_flags) != 0;
PF.lght_resist = uand( Resist_Lightning_worn_bit, item_flags) != 0;
PF.ffall = uand( Feather_Fall_worn_bit, item_flags) != 0;
for (i1 = Equipment_min; i1 <= EQUIP_MAX-2; i1++) {
//with equipment[i1] do;
if (uand(Sustain_Stat_worn_bit,equipment[i1].flags) != 0) {
if ((equipment[i1].p1>0) && (equipment[i1].p1<7)) {
py.flags.sustain[equipment[i1].p1-1] = true;
}
}
}
}; /* end py_bonuses */
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void change_stat(stat_set tstat, integer amount, integer factor)
{
/*{ Changes stats up or down for magic items -RAK- }*/
PS.m[(int)tstat] += amount*factor;
update_stat(tstat);
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void change_speed(integer num)
{
/*
{ Changes speed of monsters relative to player -RAK- }
{ Note: When the player is sped up or slowed down, I simply }
{ change the speed of all the monsters. This greatly }
{ simplified the logic... }
*/
integer i1;
py.flags.speed += num;
for (i1 = muptr; i1 != 0; i1 = m_list[i1].nptr) {
m_list[i1].cspeed += num;
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void update_stat(stat_set tstat)
{
PS.c[(int)tstat] = squish_stat(PS.p[(int)tstat] + 10*PS.m[(int)tstat] -
PS.l[(int)tstat]);
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void change_rep(integer amt)
{
//with py.misc do;
if ((amt<0) || (PM.rep+amt<=0)) { /*{bad deed or make up for sins}*/
PM.rep += amt;
} else {/*{ good deed that puts char into positive reputation }*/
/*{ good characters progress slowly -- past 0 it costs 2, past 20 costs 3...}*/
if (PM.rep < 0) { /*{ go from bad to good }*/
amt += PM.rep;
PM.rep = 0;
} /*{increase goodness}*/
PM.rep = trunc(sqrt((20+PM.rep)*(20+PM.rep)+40*amt)-20);
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
boolean panel_contains(integer y, integer x)
{
/*{ Tests a given point to see if it is within the screen -RAK- }*/
/*{ boundries. }*/
boolean return_value = false;
if ((y >= panel_row_min) && (y <= panel_row_max)) {
if ((x >= panel_col_min) && (x <= panel_col_max)) {
return_value = true;
}
}
return return_value;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void ml__draw_block(integer y1, integer x1, integer y2, integer x2)
{
/*{ Given two sets of points, draw the block }*/
integer i1,i2,xpos,xmax=0;
integer topp,bott,left,righ;
integer new_topp,new_bott,new_left,new_righ;
vtype floor_str,save_str;
integer floor_str_len = 0;
char tmp_char;
boolean flag;
ENTER("ml__draw_block","m");
/*{ From uppermost to bottom most lines player was on... }*/
/*{ Points are guaranteed to be on the screen (I hope...) }*/
//fprintf(debug_file,": draw_block: y1: %d x1: %d y2: %d x2: %d\n",
// y1,x1,y2,x2);
//fflush(debug_file);
topp = maxmin(y1,y2,panel_row_min);
bott = minmax(y1,y2,panel_row_max);
left = maxmin(x1,x2,panel_col_min);
righ = minmax(x1,x2,panel_col_max);
//fprintf(debug_file,": draw_block: topp: %d bott: %d left: %d right: %d\n",
// topp,bott,left,righ);
//fflush(debug_file);
new_topp = y2 - 1; /*{ Margins for new things to appear}*/
new_bott = y2 + 1;
new_left = x2 - 1;
new_righ = x2 + 1;
for (i1 = topp; i1 <= bott; i1++) {
floor_str[0] = 0; /*{ Null out print string }*/
floor_str_len = 0;
save_str[0] = 0;
xpos = 0;
for (i2 = left; i2 <= righ; i2++) { /*{ Leftmost to rightmost do}*/
//with cave[i1,i2] do;
if ((cave[i1][i2].pl) || (cave[i1][i2].fm)) {
flag = (((i1==y1) && (i2==x1)) || ((i1==y2) && (i2==x2)));
//flag = true;
} else {
flag = true;
if (((i1 >= new_topp) && (i1 <= new_bott)) &&
((i2 >= new_left) && (i2 <= new_righ))) {
if (cave[i1][i2].tl) {
if (is_in(cave[i1][i2].fval,pwall_set)) {
cave[i1][i2].pl = true;
} else if (cave[i1][i2].tptr > 0) {
if (is_in(t_list[cave[i1][i2].tptr].tval,light_set)) {
if (!(cave[i1][i2].fm)) {
cave[i1][i2].fm = true;
}
}
}
}
}
}
if ((cave[i1][i2].pl) || (cave[i1][i2].tl) || (cave[i1][i2].fm)) {
tmp_char = loc_symbol(i1,i2);
} else {
tmp_char = ' ';
}
if (py.flags.image > 0) {
if (randint(12) == 1) {
tmp_char = (char)(randint(95) + 31);
}
}
if (flag) {
if (xpos == 0) {
xpos = i2;
}
xmax = i2;
}
if (xpos > 0) {
if (floor_str_len > 80) {
MSG(": ERROR draw_block floor_str_len too big\n");
}
floor_str[floor_str_len++] = tmp_char;
}
} /* end for i2 */
if (floor_str_len > 80) {
MSG(": ERROR draw_block floor_str_len too big\n");
}
floor_str[floor_str_len] = 0;
// fprintf(debug_file,": floor before if %d: |%s|\n",i1,floor_str);
// fflush(debug_file);
if (xpos > 0) {
i2 = i1; /*{ Var for PRINT cannot be loop index}*/
/*print(substr(floor_str,1,1+xmax-xpos),i2,xpos);*/
if ( ((1+xmax-xpos+1) > 80) || ((1+xmax-xpos+1) < 0) ) {
MSG(": ERROR draw_block xmax-xpos is bad\n");
}
floor_str[1+xmax-xpos+1] = 0;
print_str(floor_str,i2,xpos);
}
}
LEAVE("ml__draw_block","m");
};
//////////////////////////////////////////////////////////////////////
void ml__sub1_move_light(integer y1,integer x1,integer y2,integer x2)
{
/*{ Normal movement }*/
integer i1,i2;
ENTER("ml__sub1_move_light","m");
light_flag = true;
for (i1 = y1-1; i1 <= y1+1; i1++) { /*{ Turn off lamp light }*/
for (i2 = x1-1; i2 <= x1+1; i2++) {
cave[i1][i2].tl = false;
}
}
for (i1 = y2-1; i1 <= y2+1; i1++) {
for (i2 = x2-1; i2 <= x2+1; i2++) {
cave[i1][i2].tl = true;
}
}
ml__draw_block(y1,x1,y2,x2); /*{ Redraw area }*/
LEAVE("ml__sub1_move_light","m");
};
//////////////////////////////////////////////////////////////////////
void ml__sub2_move_light(integer y1,integer x1,integer y2,integer x2)
{
/*{ When FIND_FLAG, light only permanent features }*/
integer i1,i2,xpos;
vtype floor_str,save_str;
integer floor_str_len, save_str_len;
char tmp_char;
boolean flag;
ENTER("ml__sub2_move_light","m");
if (light_flag) {
for (i1 = y1-1; i1 <= y1+1; i1++) {
for (i2 = x1-1; i2 <= x1+1; i2++) {
cave[i1][i2].tl = false;
}
}
ml__draw_block(y1,x1,y1,x1);
light_flag = false;
}
for (i1 = y2-1; i1 <= y2+1; i1++) {
floor_str[0] = 0;
save_str[0] = 0;
floor_str_len = 0;
save_str_len = 0;
xpos = 0;
for (i2 = x2-1; i2 <= x2+1; i2++) {
//with cave[i1,i2] do;
flag = false;
if (!((cave[i1][i2].fm) || (cave[i1][i2].pl))) {
tmp_char = ' ';
if (player_light) {
if (is_in(cave[i1][i2].fval, pwall_set)) {
cave[i1][i2].pl = true; /*{ Turn on perm light }*/
tmp_char = loc_symbol(i1,i2);
flag = true;
} else {
if (cave[i1][i2].tptr > 0) {
if (is_in(t_list[cave[i1][i2].tptr].tval,light_set)) {
cave[i1][i2].fm = true; /*{ Turn on field marker }*/
tmp_char = loc_symbol(i1,i2);
flag = true;
}
}
}
}
} else {
tmp_char = loc_symbol(i1,i2);
}
if (flag) {
if (xpos == 0) {
xpos = i2;
}
if (save_str[0] != 0) {
//floor_str := floor_str + save_str;
floor_str[floor_str_len] = 0;
save_str[save_str_len] = 0;
strcat(floor_str, save_str);
floor_str_len += save_str_len;
save_str[0] = 0;
save_str_len = 0;
}
floor_str[floor_str_len++] = tmp_char;
} else if (xpos > 0) {
save_str[save_str_len++] = tmp_char;
}
} /* end for i2 */
if (xpos > 0) {
i2 = i1;
floor_str[floor_str_len] = 0;
print_str(floor_str,i2,xpos);
}
} /* end for i1 */
LEAVE("ml__sub2_move_light","m");
};
//////////////////////////////////////////////////////////////////////
void ml__sub3_move_light(integer y1,integer x1,integer y2,integer x2)
{
/*{ When blinded, move only the player symbol... }*/
integer i1,i2;
ENTER("ml__sub3_move_light","m");
if (light_flag) {
for (i1 = y1-1; i1 <= y1+1; i1++) {
for (i2 = x1-1; i2 <= x1+1; i2++) {
cave[i1][i2].tl = false;
}
}
light_flag = false;
}
print(' ',y1,x1);
print('@',y2,x2);
LEAVE("ml__sub3_move_light","m");
};
//////////////////////////////////////////////////////////////////////
void ml__sub4_move_light(integer y1,integer x1,integer y2,integer x2)
{
/*{ With no light, movement becomes involved... }*/
integer i1,i2;
ENTER("ml__sub4_move_light","m");
light_flag = true;
if (cave[y1][x1].tl) {
for (i1 = y1-1; i1 <= y1+1; i1++) {
for (i2 = x1-1; i2 <= x1+1; i2++) {
cave[i1][i2].tl = false;
if (test_light(i1,i2)) {
lite_spot(i1,i2);
} else {
unlite_spot(i1,i2);
}
}
}
} else if (test_light(y1,x1)) {
lite_spot(y1,x1);
} else {
unlite_spot(y1,x1);
}
print('@',y2,x2);
LEAVE("ml__sub4_move_light","m");
};
//////////////////////////////////////////////////////////////////////
void move_light(integer y1,integer x1,integer y2,integer x2)
{
/*{ Package for moving the character's light about the screen }*/
/*{ Three cases : Normal, Finding, and Blind -RAK- }*/
/* (so what is that sub4 thing?) */
if (py.flags.blind > 0) {
ml__sub3_move_light(y1,x1,y2,x2); /* blind */
} else if (find_flag) {
ml__sub2_move_light(y1,x1,y2,x2); /* searching */
} else if (!player_light) {
ml__sub4_move_light(y1,x1,y2,x2); /* no light */
} else {
ml__sub1_move_light(y1,x1,y2,x2); /* normal */
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void lite_spot(integer y,integer x)
{
if (panel_contains(y,x)) {
print(loc_symbol(y,x),y,x);
}
};
void unlite_spot(integer y,integer x)
{
if (panel_contains(y,x)) {
print(' ',y,x);
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void teleport(integer dis)
{
/*{ Teleport the player to a new location -RAK- }*/
integer y,x,i1,i2;
ENTER("teleport", "d");
do {
y = randint(cur_height);
x = randint(cur_width);
for (;distance(y,x,char_row,char_col) > dis;) {
y += trunc((char_row-y)/2);
x += trunc((char_col-x)/2);
}
} while (!((cave[y][x].fopen) && (cave[y][x].cptr < 2)));
move_rec(char_row,char_col,y,x);
for (i1 = char_row-1; i1 <= char_row+1; i1++) {
for (i2 = char_col-1; i2 <= char_col+1; i2++) {
//with cave[i1,i2] do;
cave[i1][i2].tl = false;
if (!(test_light(i1,i2))) {
unlite_spot(i1,i2);
}
}
}
if (test_light(char_row,char_col)) {
lite_spot(char_row,char_col);
}
char_row = y;
char_col = x;
move_char(5);
creatures(false);
teleport_flag = false;
LEAVE("teleport", "d")
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
boolean get_panel(integer y, integer x, boolean forceit)
{
/*{ Given an row (y) and col (x), this routine detects -RAK- }*/
/*{ when a move off the screen has occurred and figures new borders}*/
/* forceit forcses the panel bounds to be recalculated (show_location). */
integer prow,pcol;
boolean return_value;
prow = panel_row;
pcol = panel_col;
if (forceit || (y < panel_row_min + 2) || (y > panel_row_max - 2)) {
prow = trunc((y - 2)/(SCREEN_HEIGHT/2));
if (prow > max_panel_rows) {
prow = max_panel_rows;
} else if (prow < 0) {
prow = 0;
}
}
if (forceit || (x < panel_col_min + 3) || (x > panel_col_max - 3)) {
pcol = trunc((x - 3)/(SCREEN_WIDTH/2));
if (pcol > max_panel_cols) {
pcol = max_panel_cols;
} else if (pcol < 0) {
pcol = 0;
}
}
if ((prow != panel_row) || (pcol != panel_col) || !(cave_flag)) {
panel_row = prow;
panel_col = pcol;
panel_bounds();
cave_flag = true;
return_value = true;
} else {
return_value = false;
}
return return_value;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void move_rec(integer y1,integer x1,integer y2,integer x2)
{
/*{ Moves creature record from one space to another -RAK- }*/
/* (x1,y1) might equal (x2,y2) so use a temp var */
byteint i1;
i1 = cave[y1][x1].cptr;
cave[y1][x1].cptr = 0;
cave[y2][x2].cptr = i1;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
boolean find_range(obj_set item_val,boolean inner,
treas_ptr *first, integer *count)
{
boolean flag;
treas_ptr ptr;
ENTER("find_range", "");
*count = 0;
*first = nil;
flag = false;
change_all_ok_stats(false,false);
for (ptr = inventory_list; ptr != NULL; ptr = ptr->next) {
// fprintf(debug_file,"find: >%s<\n",ptr->data.name);
// fprintf(debug_file,"find: %d %d %d %d\n",
// (integer)ptr->data.tval, (integer)ptr->is_in,
// (integer)ptr->insides, (integer)ptr->ok);
if ((is_in(ptr->data.tval, item_val)) &&
(!(ptr->is_in) || inner) &&
((ptr->insides == 0) || (ptr->data.tval != bag_or_sack))) {
if (!flag) {
flag = true;
*first = ptr;
}
ptr->ok = true;
(*count)++;
}
}
#if DO_DEBUG
fprintf(debug_file,"find: count=%ld\n",*count);
#endif
RETURN("find_range", "",'b',"found",&flag);
return flag;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void carry(integer y, integer x)
{
/*{ Player is on an object. Many things can happen BASED -RAK- }*/
/*{ on the TVAL of the object. Traps are set off, money and most }*/
/*{ objects are picked up. Some objects, such as open doors, just}*/
/*{ sit there... }*/
treas_ptr item_ptr;
vtype out_val,out2;
char page_char;
char inv_char;
treas_ptr tmp_ptr;
integer count;
boolean money_flag;
money_flag = false;
find_flag = false;
//with cave[y][x]. do;
inven_temp->data = t_list[cave[y][x].tptr];
/*{ There's GOLD in them thar hills! }*/
/*{ OPPS! }*/
if (is_in(t_list[cave[y][x].tptr].tval, trap_set)) {
hit_trap(&y,&x);
} else if (t_list[cave[y][x].tptr].tval <= valuable_metal) {
/*{ Attempt to pick up an object. }*/
if (inven_check_num()) { /*{ Too many objects? }*/
if (inven_check_weight()) { /*{ Weight limit check }*/
/*{ Okay, pick it up }*/
pusht(cave[y][x].tptr);
cave[y][x].tptr = 0;
if (inven_temp->data.tval == valuable_metal) {
item_ptr = money_carry();
money_flag = true;
} else {
item_ptr = inven_carry();
}
prt_weight();
objdes(out_val,item_ptr,true);
if (money_flag) {
page_char = '$';
inv_char = '$';
} else {
count = 0;
tmp_ptr = inventory_list;
if (tmp_ptr->next == item_ptr->next) {
count = 0;
} else {
do {
count++;
tmp_ptr = tmp_ptr->next;
} while (tmp_ptr->next != item_ptr->next);
}
if ((count div 20) > 9) {
page_char = '*';
inv_char = '*';
} else {
page_char = ((count div 20)+49);
inv_char = (count - (count div 20)*20 + 97);
}
}
sprintf(out2, "You have %s. (%c%c)",out_val,page_char,inv_char);
msg_print(out2);
} else {
msg_print("You can't carry that much weight.");
}
} else {
msg_print("You can't carry that many items.");
}
}
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
integer react(integer x)
{
/* returns 0 to 10 -- SD 2.4; */
/* x is average reaction for a 0 SC ugly half-troll*/
integer ans;
ans = (py.stat.c[CHR]+PM.rep*2+randint(200)+randint(200)
+randint(200)) div 50 + x - 4;
if (ans < 0) {
ans = 0;
} else if (ans > 10) {
ans = 10;
}
return ans;
};
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void battle_game(integer plus, vtype kb_str)
{
integer score,i1,time;
vtype out_val;
if (get_yes_no("Do you accept their invitation?")) {
msg_print("Good for you!");
score = 0;
time = 10;
//with py.misc do;
for (i1 = 1; i1 <= 7; i1++) {
if (player_test_hit(PM.bth,PM.lev,plus,20*i1,false)) {
score++;
time = time * 2 + 10;
}
}
sprintf(out_val, "with some %s", kb_str);
spend_time(time,out_val,false);
switch (score) {
case 1 :
msg_print("They ridicule your clumsy performance...");
msg_print("'Come back when you are more experienced!!'");
change_rep(-2);
break;