/
hebrac2015.c
1854 lines (1760 loc) · 61.2 KB
/
hebrac2015.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
// Copyright (c) 2015, Thjafa <thjalfa@libero.it>
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <stddef.h>
#define INVNUM 10
#define DEBUG 0
#ifdef __APPLE__ && __MACH__ /*MacOSX*/
#define OS 0
#endif /*__APPLE__ && __MACH__*/
#ifdef _WIN32 /*Windows 32-bit or 64-bit*/
#define OS 1
#endif /*_WIN32*/
#ifdef __gnu_linux__ /*GNU/Linux*/
#define OS 2
#endif /*__gnu_linux__*/
//test ifdef
void treasure(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag, int rec, int stat, int combat);
void magic(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* floor, int* start, int* antimag, int* checkcurse, int combat, int* control, int* contator, int* modenemy, int* datt, int* modatt, int* nomag, char* s);
int magicconsume(int* aces, int* inv, int cost, char* name);
void stonestatue(int* aces, int* inv, int* map, int times, int combat, int free);
void godvision(int* aces, int* inv, int* vision, int* nomag, int free);
int getint(int *i) {
int nope=0;
int end;
char buffer[100];
do {
if (nope==1)
fputs("Invalid input, try again.\n", stdout);
nope=1;
if (NULL==fgets(buffer,sizeof(buffer),stdin))
return -1;
errno=0;
} while ((1!=sscanf(buffer,"%d %n",i,&end))||buffer[end]||errno);
return 0;
}
void shiftarray(int* a) {
int i;
for (i=0; i<INVNUM-1; i++) *(a+i)=*(a+i+1);
*(a+INVNUM-1)=-1;
}
void hebrac(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag, int rec, int stat, int combat) {
struct timespec a;
a.tv_sec = 0;
a.tv_nsec = 1000;
nanosleep( &a, NULL );
struct timeval t1;
gettimeofday(&t1, NULL);
srand(t1.tv_usec * t1.tv_sec);
int r,i=0;
do {
printf("Hebrac itself is in front of you!\n'Do you want to play? It's a coin flip: you can get some nice treasure or you can get hurt...'\n[0]: Don't play\n[1]: Heads\n[2]: Tails\n");
getint(&r);
if ((r!=0)&&(r!=1)&&(r!=2)) {
if (i==0) {
printf("'I don't have all the day...'\n");
i=1;
} else if (i>0) {
printf("'Don't be rude the next time!'\nHebrac disappears!\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
}
} while ((r!=0)&&(r!=1)&&(r!=2));
printf("'As you wish...'\n");
if (r==0) {
printf("Hebrac disappears!\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
i=rand()%2;
if (*future>=0) {
printf("Do you think that your divination skills can surpass my power?\n");
shiftarray(future);
}
if (i==0) {
if (r==1) {
printf("Tails! You lose 5 HP!\nHebrac disappears!\n");
}
else {
printf("Heads! You lose 5 HP!\nHebrac disappears!\n");
}
*(loot+*pos)=-1;
*(vision+*pos)=2;
*hpnow=*hpnow-5;
return;
} else {
if (r==1) {
printf("Heads! You can take the treasure!\nHebrac disappears!\n");
}
else {
printf("Tails! You can take the treasure!\nHebrac disappears!\n");
}
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,rec,stat,combat);
}
}
void genie(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag, int r, int combat) {
if (r==12) {
printf("You rub the lantern! From the smoke, a djinn of Life appears!\nYour maximum HP are increased by 2!\n");
*hpmax=*hpmax+2;
return;
}
if (r==25) {
printf("You rub the lantern! From the smoke, a djinn of Luck appears!\nYou find some treasure!\n");
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,1,0,combat);
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,1,0,combat);
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,1,0,combat);
return;
}
if (r==38) {
printf("You rub the lantern! From the smoke, a djinn of Destiny appears!\nNow you know this floor perfectly!\n");
godvision(aces,inv,vision,NULL,1);
return;
}
printf("You rub the lantern! From the smoke, a djinn of Death appears!\nYou can choose to kill 3 enemies!\n");
stonestatue(aces,inv,map,3,combat,1);
}
int checkpositiveinv(int* a) {
int i;
for (i=0; i<INVNUM; i++) {
if (*(a+i)>0) return 1;
}
return 0;
}
int checkpositiveace(int* a) {
int i;
for (i=0; i<4; i++) {
if (*(a+i)>0) return 1;
}
return 0;
}
int checkfullinv(int* a) {
int i;
for (i=0; i<INVNUM; i++) {
if (*(a+i)==0) return i;
}
return -1;
}
int value(int card) {
switch (card) {
case 22: return 40;
case 21: return 39;
case 20: return 38;
case 9: return 37;
case 8: return 36;
case 19: return 35;
case 35: return 34;
case 34: return 33;
case 48: return 32;
case 47: return 31;
case 7: return 30;
case 33: return 29;
case 18: return 28;
case 6: return 27;
case 46: return 26;
case 32: return 25;
case 45: return 24;
case 17: return 23;
case 31: return 22;
case 5: return 21;
case 44: return 20;
case 4: return 19;
case 30: return 18;
case 43: return 17;
case 15: return 16;
case 3: return 15;
case 29: return 14;
case 16: return 13;
case 14: return 12;
case 2: return 11;
case 1: return 10;
case 28: return 9;
case 27: return 8;
case 42: return 7;
case 41: return 6;
case 40: return 5;
default: return -1;
}
}
int leastvalueinv(int* inv) {
int min=-1;
int pos;
for (pos=0; pos<INVNUM; pos++) {
if (min<0) {
if (*(inv+pos)>0) min=pos;
}
else if ((value(*inv+min)>value(*inv+pos))&&(value(*inv+pos)>0)) min=pos;
}
return min;
}
void nameitem(char* s, int i) {
memset(s,0,sizeof(s));
if (i==0) {
sprintf(s,"Ruby of Gaza");
return;
}
if (i==26) {
sprintf(s,"Scepter of Leynos");
return;
}
if (i==39) {
sprintf(s,"Bracelet of Armok");
return;
}
if (i%13==10) {
sprintf(s,"prisoner");
return;
}
if (i%13==11) {
sprintf(s,"white priestess");
return;
}
if (i==12) {
sprintf(s,"djinn of Life");
return;
}
if (i==25) {
sprintf(s,"djinn of Luck");
return;
}
if (i==38) {
sprintf(s,"djinn of Destiny");
return;
}
if (i==51) {
sprintf(s,"djinn of Death");
return;
}
if (i<12) {
sprintf(s,"%d life potions",i%13+1);
return;
}
if (i<25) {
sprintf(s,"%d gems",i%13+1);
return;
}
if (i<38) {
sprintf(s,"%d magic potions",i%13+1);
return;
}
if (i<51) sprintf(s,"%d strength potions",i%13+1);
}
void removeleast(int* hpmax, int* hpnow, int* aces, int* inv) {
if (!checkpositiveinv(inv)) {
if (!checkpositiveace(aces)) {
printf("'Your bag is empty!'\nThe black priestess disappears!\n");
return;
}
if (*(aces+3)==1) {
*(aces+3)=0;
printf("'I'm sorry, but I have to take your Bracelet of Armok.'\nThe black priestess disappears!\n");
return;
}
if (*(aces+2)==1) {
*(aces+2)=0;
printf("'I'm sorry, but I have to take your Scepter of Leynos.'\nThe black priestess disappears!\n");
return;
}
if (*(aces)==1) {
*(aces)=0;
printf("'I'm sorry, but I have to take your Ruby of Gaza.'\nThe black priestess disappears!\n");
*hpmax=*hpmax-5;
*hpnow=min(*hpmax,*hpnow);
return;
}
if (*(aces+1)==1) {
*(aces+1)=0;
printf("'I'm sorry, but I have to take your Bag of Meres.'\nThe black priestess disappears!\n");
return;
}
}
int p=leastvalueinv(inv);
char s[20];
nameitem(s,*(inv+p));
printf("'I'm sorry, but I have to take your %s.'\nThe black priestess disappears!\n",s);
*(inv+p)=0;
}
int mostvalueinv(int* inv) {
int max=-1;
int pos;
for (pos=0; pos<INVNUM; pos++) {
if (max<0) {
if ((*(inv+pos)>0)&&(*(inv+pos)%13!=10)) max=pos;
}
else if ((*(inv+pos)%13!=10)&&(value(*inv+max)<value(*inv+pos))) max=pos;
}
return max;
}
void removemost(int* hpmax, int* hpnow, int* aces, int* inv) {
if (checkpositiveace(aces)) {
if (*(aces+1)==1) {
*(aces+1)=0;
printf("'Nice, I will take your Bag of Meres.'\nThe black priestess disappears!\n");
return;
}
if (*(aces)==1) {
*(aces)=0;
printf("'Nice, I will take your Ruby of Gaza.'\nThe black priestess disappears!\n");
*hpmax=*hpmax-5;
*hpnow=min(*hpmax,*hpnow);
return;
}
if (*(aces+2)==1) {
*(aces+2)=0;
printf("'Nice, I will take your Scepter of Leynos.'\nThe black priestess disappears!\n");
return;
}
if (*(aces+3)==1) {
*(aces+3)=0;
printf("'Nice, I will take your Bracelet of Armok.'\nThe black priestess disappears!\n");
return;
}
}
if (!checkpositiveinv(inv)) {
printf("'Damn, your bag is empty!'\nThe black priestess disappears!\n");
return;
}
int p=mostvalueinv(inv);
if (p=0) {
printf("'I can't take anything from you!'\nThe black priestess disappears!\n");
return;
}
char s[20];
nameitem(s,*(inv+p));
printf("'Not bad, I will take your %s.'\nThe black priestess disappears!\n",s);
*(inv+p)=0;
}
void blackqueen(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag, int good) {
printf("It is a black priestess, a kleptomaniac demon!\n");
if (*antimag==1) {
printf("Because the antimagic field, the black magic of the priestess is uneffective!\n");
return;
}
if (good==1) {
printf("'Because you freed me, I will take your cheapest item with my black magic...'\n");
removeleast(hpmax,hpnow,aces,inv);
return;
}
printf("'Ah, I will take something expensive from you!'\n");
removemost(hpmax,hpnow,aces,inv);
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,0,1,0);
}
void redqueen(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag, int rec, int stat, int combat) {
int i;
printf("You meet a white priestess, a gentle pixie!\n'Greetings! I want to help you, but you don't have to be greedy. Do you want a gift or you want to be healed?'\n");
if (*antimag==1) {
printf("'Wait! I perceive an antimagic field, so I can't heal you... here a gift, I hope it will be useful...'\n");
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,rec,stat,combat);
return;
} else {
printf("[0]: Gift\n[1]: Heal\n");
}
do {
getint(&i);
if (i==0) {
printf("'As you wish, here your gift!'\nThe white priestess disappears!\n");
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,rec,stat,combat);
return;
}
if (i==1) {
printf("'As you wish, I will heal you!'\nThe white priestess disappears!\n");
*hpnow=*hpmax;
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
printf("'I'm sorry, but I can't understand you... Do you want a gift or you want to be healed?'\n[0]: Gift\n[1]: Heal\n'");
i=-1;
} while (i==-1);
}
void addslave(int* slave) {
printf("A prisoner stands before you.\n'Thanks! Thanks so much! Because you freed me, I will help in a battle!'\n");
int i;
for (i=0; i<INVNUM; i++) {
if (*(slave+i)==0) *(slave+i)=1;
return;
}
printf("'...but it seems that your group is too much large and there isn't a place for me.'");
}
void addaces(int* hpmax, int* aces, int a) {
printf("Is this one of the four artifacts?!\n");
if (a<9) a=0;
else if (a<22) a=1;
else if (a<35) a=2;
else a=3;
if (*(aces+a)) {
printf("It is only a pathetic imitation...\n");
return;
}
*(aces+a)=1;
if (a==0) {
printf("You found the Ruby of Gaza!\n");
*hpmax=*hpmax+5;
}
else if (a==1) {
printf("You found the Bag of Meres!\n");
}
else if (a==2) {
printf("You found the Scepter of Leynos!\n");
}
else {
printf("You found the Bracelet of Armok!\n");
}
}
void dropinv(int* inv, int r) {
int i;
char s[20];
char t[20];
nameitem(s,r);
printf("Your bag is full! Do you want to drop something to keep %s?\n[0]: No\n[1]: Yes\n",s);
getint(&i);
if (i==0) {
printf("You don't keep the %s.\n",s);
} else {
i=0;
do {
printf("What do you want to drop?\n");
getint(&i);
if ((i<0)||(i>=INVNUM)) {
printf("You don't have that slot! Insert a number between 0 and %d!\n",INVNUM-1);
i=0;
} else {
int k;
nameitem(t,*(inv+i));
printf("Do you want to drop the %s?\n[0]: No\n[1]: Yes\n",t);
getint(&k);
if (k==1) {
printf("You dropped the %s to keep the %s.\n",s,t);
*(inv+i)=r;
i=-1;
return;
} else if (k!=0) {
printf("You don't have all the day to decide...\n");
}
}
} while (i!=-1);
}
printf("What do you want to drop?\n");
}
void treasure(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag, int rec, int stat, int combat) {
struct timespec a;
a.tv_sec = 0;
a.tv_nsec = 1000;
nanosleep( &a, NULL );
struct timeval t1;
gettimeofday(&t1, NULL);
srand(t1.tv_usec * t1.tv_sec);
int r,n;
if (stat==0) {
if (*future>=0) {
r=*future;
shiftarray(future);
}
else r=rand()%54;
}
else r=*(loot+*pos);
if (r==-1) {
printf("This room is empty...\n");
return;
}
if (stat==1) {
printf("Do you want to take the treasure in this room?\n[0]: No\n[1]: Yes\n");
getint(&n);
if (n==0) return;
}
if (r>=52) hebrac(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,rec,0,combat);
else if (r%13==12) {
if (rec==0) genie(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,r,combat);
else {
printf("An empty lantern...");
}
}
else if (r%13==11) {
if (r>=25) blackqueen(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,1);
else redqueen(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,rec,0,combat);
}
else if (r%13==10) addslave(slave);
else if (r%13==0) addaces(hpmax,aces,r);
else {
int n=checkfullinv(inv);
char s[20];
if (n>=0) {
*(inv+n)=r;
nameitem(s,r);
printf("You received %s!\n",s);
} else {
dropinv(inv,r);
}
}
if (stat==1) {
*(loot+*pos)=-1;
*(vision+*pos)=2;
}
}
int valueitem(int n) {
if (n>51) return 2;
if (n%13==0) return 12;
if (n%13==10) return 8;
if (n%13==11) return 9;
if (n%13==12) return 10;
if ((n>25)&&(n<39)) return 2*(n%13+1);
return n%13+1;
}
int gemcount(int* inv) {
int value=0;
int i;
for (i=0; i<INVNUM; i++) {
if ((*(inv+i)>12)&&(*(inv+i)<22)) value+=(*(inv+i)%13)+1;
}
return value;
}
int valueinv(int* inv, int* slave) {
int i;
int value=0;
for (i=0; i<INVNUM; i++) {
if (*(inv+i)) value+=valueitem(*(inv+i));
value+=8*(*(slave+i));
}
return value;
}
int numslav(int* slave) {
int i;
int n=0;
for (i=0; i<INVNUM; i++) {
n+=*(slave+i);
}
return n;
}
void removeslave(int* slave, int n) {
int i;
for (i=INVNUM-1; i>=0; i--) {
if (*(slave+i)) {
*(slave+i)=0;
n--;
}
if (n==0) return;
}
}
void goodsoffer(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag) {
int value=0;
int k;
int offitem[INVNUM];
for (k=0; k<INVNUM; k++) {
offitem[k]=0;
}
int offslav;
char s[20];
int p=-1;
do {
printf("'What do you want to offer? An item or a slave?'\n[0]: Item\n[1]: Slave\n");
getint(&k);
if (k==0) {
printf("'What item do you want to offer?'\n");
getint(&k);
if ((k<0)||(k>=INVNUM)||(*(inv+k)==0)) {
printf("'Are you kidding me? Do you want to abort the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==1) {
printf("You aborted the trade.\n");
return;
}
} else {
value+=valueitem(*(inv+k));
p++;
offitem[p]=*(inv+k);
}
} else if (k==1) {
if (offslav>=numslav(slave)) {
printf("'You don't have enough slaves to offer!\n'");
} else {
offslav++;
value+=8;
}
} else {
printf("'Are you kidding me? Do you want to abort the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==1) {
printf("You aborted the trade.\n");
return;
}
}
if (value<valueitem(*(loot+*pos))) printf("'My item is valued %d gems and you offer is worth %d gems.'\n",valueitem(*(loot+*pos)),value);
else {
printf("'I'm satisfied with your offer of %d slaves and",offslav);
for (k=0; k<=p; k++) {
nameitem(s,offitem[k]);
printf(" %s",s);
if (k<p) {
printf(",");
}
else {
printf(".");
}
}
if (p<0) {
printf("nothing else.'\n");
}
else {
printf(".'\n");
}
k=-1;
do {
printf("'Do you accept the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==0) {
printf("'Do you want to abort the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==1) {
printf("You aborted the trade.\n");
return;
}
printf("'Do you want to propose another offer?'\n[0]: No\n[1]: Yes\n");
if (k==0) {
printf("You aborted the trade.\n");
return;
}
for (k=0; k<INVNUM; k++) {
offitem[k]=0;
}
offslav=0;
p=-1;
} else if (k==1) {
removeslave(slave,offslav);
for (k=0; k<=p; k++) {
*(inv+offitem[k])=0;
}
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,0,1,0);
}
} while (k<0);
}
} while (value<valueitem(*(loot+*pos)));
}
void gemoffer(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* antimag) {
int value=0;
int k;
int offgem[INVNUM];
for (k=0; k<INVNUM; k++) {
offgem[k]=0;
}
char s[20];
int p=-1;
do {
printf("'What gem do you want to offer?'\n");
getint(&k);
if ((k<0)||(k>=INVNUM)||(*(inv+k)==0)) {
printf("'Are you kidding me? Do you want to abort the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==1) return;
} else if ((*(inv+k)>22)||(*(inv+k)<14)) {
printf("'That's not a gem! Do you want to abort the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==1) {
printf("You aborted the trade.\n");
return;
}
} else {
value+=*(inv+k)%13;
p++;
offgem[p]=*(inv+k);
}
if (value<valueitem(*(loot+*pos))) printf("'My item is valued %d gems and you offer is worth %d gems.'\n",valueitem(*(loot+*pos)),value);
else {
printf("'I'm satisfied with your offer of %d gems:",value);
for (k=0; k<=p; k++) {
nameitem(s,offgem[k]);
if (k==p) {
printf(" %s gems.'\n",s);
} else {
printf(" %s gems,",s);
}
}
k=-1;
do {
printf("'Do you accept the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==0) {
printf("'Do you want to abort the trade?'\n[0]: No\n[1]: Yes\n");
getint(&k);
if (k==1) {
printf("You aborted the trade.\n");
return;
}
printf("'Do you want to propose another offer?'\n[0]: No\n[1]: Yes\n");
if (k==0) {
printf("You aborted the trade.\n");
return;
}
for (k=0; k<INVNUM; k++) {
offgem[k]=0;
}
p=-1;
} else if (k==1) {
for (k=0; k<=p; k++) {
*(inv+offgem[k])=0;
}
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,0,1,0);
}
} while (k<0);
}
} while (value<valueitem(*(loot+*pos)));
}
int illusion(int* aces, int* inv) {
char s[20];
memset(s,0,sizeof(s));
sprintf(s,"Illusion");
int v=magicconsume(aces,inv,4,s);
if (v<0) return 0;
return 1;
}
void stealingspirit(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* floor, int* start, int* antimag, int* checkcurse, char* st, int* control);
void exchange(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* floor, int* start, int* antimag, int type) {
char s[20];
int i;
nameitem(s,*(loot+*pos));
if (*(aces+1)==1) {
printf("You put out enough gems from your bag of Meres and buy the %s.\n",s);
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,0,1,0);
return;
}
if ((type==1)&&(magiccount(aces,inv)>3)) {
printf("Do you want to use an Illusion spell?\n[0]: No\n[1]: Yes\n");
getint(&i);
if (i==1) i=illusion(aces,inv);
if (i==1) {
printf("You give nothing to the adventurer, but you receive the treasure!\n");
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,0,1,0);
}
}
if (magiccount(aces,inv)>5) {
printf("Do you want to use a StealingSpirit spell?\n[0]: No\n[1]: Yes\n");
getint(&i);
if (i==1) {
stealingspirit(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,floor,start,antimag,NULL,NULL,NULL);
if (type==0) {
printf("The merchant disappears!\n");
}
}
}
if (valueitem(*(loot+*pos))>valueinv(inv,slave)) {
printf("'You don't have enough goods to trade!'\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
if ((type==1)&&(valueitem(*(loot+*pos))>gemcount(inv))) {
printf("'You don't have enough gems to trade!'\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
if (type==0) {
goodsoffer(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag);
return;
}
gemoffer(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag);
}
void trade(int* hpmax, int* hpnow, int* aces, int* inv, int* future, int* slave, int* map, int* loot, int* vision, int* end, int* pos, int* floor, int* start, int* antimag, int type) {
int i;
if ((type==1)&&(*(loot+*pos)>13)&&(*(loot+*pos)<23)) {
printf("'I'm sorry, but I have already sold my goods.'\n");
if (magiccount(aces,inv)>5) {
printf("Do you want to use a StealingSpirit spell?\n[0]: No\n[1]: Yes\n");
getint(&i);
if (i==1) {
stealingspirit(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,floor,start,antimag,NULL,NULL,NULL);
if (type==0) {
printf("The merchant disappears!\n");
}
}
}
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
if ((type==0)&&(*(loot+*pos)%13==0)) {
printf("'I'm sorry, but I don't want to trade my artifact.'\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
if ((*(loot+*pos)%13==11)&&(*(loot+*pos)>25)) {
printf("'I don't think you are interest in a black priestess...'\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
char s[20];
nameitem(s,*(loot+*pos));
do {
printf("'Are you interested in my %s?'\n",s);
if (*(loot+*pos)%13==0) {
if (((*(loot+*pos)==0)&&(*aces==1))||((*(loot+*pos)==13)&&(*(aces+1)==1))||((*(loot+*pos)==26)&&(*(aces+2)==1))||((*(loot+*pos)==39)&&(*(aces+3)==1))) {
printf("You see it's only a pathetic imitation...\n");
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
}
printf("[0]: No\n[1]: Yes\n");
getint(&i);
if (i==0) {
*(loot+*pos)=-1;
*(vision+*pos)=2;
return;
}
if (i==1) {
exchange(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,floor,start,antimag,type);
*(vision+*pos)=2;
*(loot+*pos)=-1;
return;
}
else {
i=-1;
printf("'What?'\n");
}
} while (i=-1);
}
int hit(int* future) {
struct timespec a;
a.tv_sec = 0;
a.tv_nsec = 1000;
nanosleep( &a, NULL );
struct timeval t1;
gettimeofday(&t1, NULL);
srand(t1.tv_usec * t1.tv_sec);
int k;
if (*future>=0) {
k=*future;
shiftarray(future);
} else k=rand()%13;
if (k>8) return 10;
return k+1;
}
int max(int a, int b) {
if (a>b) return a;
return b;
}
void nameenemy(char* s, int enemy) {
memset(s,0,sizeof(s));
if (enemy%13==10) sprintf(s,"adventurer");
else if (enemy<13) sprintf(s,"amazon");
else if (enemy<26) sprintf(s,"demon");
else if (enemy<39) sprintf(s,"magician");
else sprintf(s,"warrior");
}
int min(int a, int b) {
if (a<b) return a;
return b;
}
void useitemcombat(int* hpmax, int* hpnow, int* inv, int* slave, int* bonusnext, int* bonuscomb) {
int k=-1;
char s[20];
printf("Do you want to use an item or seek help from a prisoner?\n[0]: Item\n[1]: Prisoner\n");
getint(&k);
if (k==0) {
printf("What item do you want to use?\n");
getint(&k);
if ((k<0)||(k>=INVNUM)||(*(inv+k)==0)) {
printf("Maybe you are a little too much excited for this fight!\n");
return;
} else if (*(inv+k)<14) {
if (*hpmax==*hpnow) {
printf("Not really useful now...\n");
return;
}
nameitem(s,*(inv+k));
printf("You use %s!\n",s);
*hpnow=min(*hpmax,*hpnow+(*(inv+k)%13)+1);
*(inv+k)=0;
} else if (*(inv+k)<27) {
printf("Gems are nice, but not really useful in a fight!\n");
return;
} else if (*(inv+k)<40) {
printf("If you want to do magic, maybe you have to cast a spell...\n");
return;
} else {
nameitem(s,*(inv+k));
printf("You use %s!\n",s);
*bonusnext=*bonusnext+(*(inv+k)%13)+1;
*(inv+k)=0;
}
} else if (k==1) {
if (!checkpositiveinv(slave)) {
printf("There aren't other adventures with you!\n");
return;
} else {
*bonuscomb=*bonuscomb+3;
removeslave(slave,1);
printf("A prisoner join your fight for his freedom!\n");
}
} else {
printf("Maybe you are a little too much excited for this fight!\n");
}
}
int combat(int* hpmax, int* hpnow, int* aces, int* inv, int* slave, int* future, int* map, int* loot, int* vision, int* end, int* pos, int* floor, int* start, int* antimag, int* checkcurse, int* nomag, int enemy) {
char s[10];
nameenemy(s,enemy);
int hpenemy=enemy%13+1;
if (enemy==0) hpenemy=10;
if (*checkcurse) {
int a=hpenemy%2;
hpenemy=hpenemy/2+a;
}
printf("An enemy %s appears! It has %d HP!\n",s,hpenemy);
int e=0;
int k;
int control=1;
int bonusnext=0;
int bonuscomb=0;
int bonusaces=0;
int modenemy=1;
if ((*antimag==1)&&(enemy>26)&&(enemy<36)) modenemy=0;
int contator=0;
int datt=0;
int modatt=1;
if (*nomag==2) *nomag=1;
if (*(aces+3)) bonusaces=3;
do {
printf("What do you want to do?\n[0]: Attack\n[1]: Magic\n[2]: Items\n");
getint(&k);
if (k==0) {
k=hit(future)*modatt+bonusnext+bonuscomb+bonusaces;
hpenemy-=k;
hpenemy=max(hpenemy,0);
printf("You strike the %s for %d damage! It has %d HP!\n",s,k,hpenemy);
if (datt==1) {
k=hit(future)+bonusnext+bonuscomb+bonusaces;
hpenemy-=k;
hpenemy=max(hpenemy,0);
datt=0;
printf("You perform a second attack and strike the %s for %d damage! It has %d HP!\n",s,k,hpenemy);
}
if (hpenemy==0) {
e=1;
treasure(hpmax,hpnow,aces,inv,slave,future,map,loot,vision,end,pos,antimag,0,1,0);
}