1 /* fight, buy or death routines */
  2 
  3 #include <stdio.h>
  4 #include <string.h>
  5 
  6 struct room
  7 {
  8           char *contents;
  9           char *id;
 10 };
 11 
 12 extern struct room dungeon[34];
 13 extern int ah, ee, ff, gg, hh, lf, tc, vf, uu, vv, ww, dd, ss, bl, isfrog, level[512];
 14 extern int c[3][4], p[16], r[3], t[8], attack, alive, x_axis, y_axis, z_axis;
 15 extern int bf, tt, rf, of, wc, master_game, escape;
 16 extern char *strength, *intelligence, *dexterity, *bright, *dim, *pad, *qpad;
 17 extern char *dots, *bell, *frog[42], *gold[14], *sss[10], *species[4], *treasure[16];
 18 extern char *clrs, *bad_response, *cause[8], *effect[8];
 19 int q1, q3, jj;
 20 char ms[30];
 21 
 22 go_fight()
 23 {
 24 int i, j, q, q2;
 25 
 26 int fighting = 1;
 27 
 28 q1 = 1 + attack / 2;
 29 q2 = attack + 4 + z_axis / 2 + 2 * master_game;
 30 q3 = 1;
 31 strcpy (ms,dungeon[attack + 11].contents);
 32 jj = 2;
 33 if (ms[2] == ' ') jj = 3;
 34 
 35 if ((c[0][3] > t[0])|| (bl)|| (ww < roll(9)+ roll(9))) monster_attack();
 36 
 37 while (fighting == 1) /* while still fighting*/
 38 {
 39 printf ("\n%sYou're facing %s",pad,dungeon[attack + 11].contents);
 40 border ("!",1 + q2 / 2);
 41 printf ("\n%sYou may (A)ttack or (R)etreat.\n",pad);
 42 if (q3 == 1) printf ("%sYou can also attempt a (B)ribe.\n",pad);
 43 if (vv > 14) printf ("%sYou can also (C)ast a spell.\n",pad);
 44 printf ("\n%sYour %s%s%s is %s%d%s",pad,bright,strength,dim,bright,uu,dim);
 45 printf (" and your %s%s%s is %s%d%s.\n",bright,dexterity,dim,bright,ww,dim);
 46 printf ("\nCommand #%d? ",tt);
 47 tt = tt + 1;
 48 i = fancy_input(4044);
 49 
 50 switch (i)
 51 {
 52           case 41:
 53           if (ff == 0) printf ("\n%s** POUNDING ON %s WON'T HURT IT!\n",pad,dungeon[attack +11].contents);
 54           else
 55           {
 56                     if (bf) printf ("\n%s ** YOU CAN'T BEAT IT TO DEATH WITH A BOOK!\n",pad);
 57 
 58                     else
 59                     {
 60                               if (ww < roll(20)+ bl * 3) printf ("\n%sYou missed, too bad!\n",pad);
 61                               else
 62                               {
 63                                         printf ("\n%s%s********** YOU HIT THE EVIL ",pad,bright);
 64                                         for (j = jj; j <= strlen(ms)- 1; ++j)
 65                                         {
 66                                                   printf ("%c",ms[j]);
 67                                                   }
 68                                         printf ("!%s%s\n",dim,bell);
 69                                         q2 = q2 - ff;
 70                                         if (((attack == 9)|| (attack == 12))&& (roll(8)== 1))
 71                                         {
 72                                                   printf ("\n%s%s********** OH NO!",bright,pad);
 73                                                   printf (" YOUR %s BROKE!%s%s\n",cause[ff],dim,bell);
 74                                                   ff = 0;
 75                                                   }
 76                                         if (q2 <= 0)
 77                                         {
 78                                                   monster_death();
 79                                                   fighting = 0;
 80                                                   }
 81                                         }
 82                               }
 83                     }
 84           if (fighting == 1) monster_attack();
 85           break;
 86 
 87           case 43:
 88           if (vv < 15)
 89           {
 90                     printf ("\n%s** YOU CAN'T CAST A SPELL NOW!\n",pad);
 91                     }
 92           else
 93           {
 94                     printf ("\nWhich spell -\n");
 95                     printf ("%s(W)eb, (F)ireball or (D)eathspell? ",pad);
 96                     j = fancy_input(4047);
 97                     if (j == 47)
 98                     {
 99                               uu = uu - 1;
100                               wc = roll(8) + 1;
101                               if (uu < 1) alive = 0;
102                               }
103                     if (j == 46)
104                     {
105                               q = roll(7) + roll(7);
106                               uu = uu - 1;
107                               vv = vv - 1;
108                               if ((uu < 1)|| (vv < 1)) alive = 0;
109                               else
110                               {
111                                         printf ("\n%sIt does %d POINTS worth of damage.\n",pad,q);
112                                         q2 = q2 - q;
113                                         if (q2 <= 0)
114                                         {
115                                                   monster_death();
116                                                   fighting = 0;
117                                                   }
118                                         }
119                               }
120                     if (j == 45)
121                     {
122                               printf ("Death . . . ");
123                               if (vv < roll(4)+ 15)
124                               {
125                                         printf ("YOURS!\n");
126                                         vv = 0;
127                                         alive = 0;
128                                         }
129                               else
130                               {
131                                         printf ("HIS!\n");
132                                         q2 = 0;
133                                         monster_death();
134                                         fighting = 0;
135                                         }
136                               }
137                     if ((alive == 1)&& (fighting == 1)) monster_attack();
138                     }
139           break;
140 
141           case 44:
142           monster_attack();
143           if (alive == 1)
144           {
145                     printf ("\n%s%s       YOU HAVE ESCAPED!%s\n",bright,qpad,dim);
146                     do
147                     {
148                               printf ("\nDo you want to go -\n%s(N)orth, (E)ast, (S)outh or (W)est? ",pad);
149                               j = fancy_input(1620);
150                               if ((j < 17)|| (j > 20)) printf ("\n%s** DON'T PRESS YOUR LUCK, %s!\n",pad,species[dd - 1]);
151                               }
152                     while ((j < 17)|| (j > 20));
153 
154                     if (j == 17) y_axis = y_axis - 1;
155                     if (j == 19) y_axis = y_axis + 1;
156                     y_axis = below_nine(y_axis);
157                     if (j == 18) x_axis = x_axis + 1;
158                     if (j == 20) x_axis = x_axis - 1;
159                     x_axis = below_nine(x_axis);
160                     escape = 1;
161                     }
162           fighting = 0;
163           break;
164 
165           default:
166           if ((i == 40)|| (q3 > 1)) printf ("\n%s\n",bad_response);
167           else
168           {
169                     if (tc == 0)
170                     {
171                               printf ("\n%sALL I WANT IS YOUR LIFE!\n",pad);
172                               monster_attack();
173                               }
174                     else
175                     {
176                               j = 0;
177                               do
178                               {
179                                         do
180                                         {
181                                                   q = roll(8);
182                                                   }
183                                         while (t[q - 1] == 0);
184                                         printf ("\nI want %s. Will you give it to me? ",dungeon[q + 24].contents);
185                                         j = fancy_input(102);
186                                         if ((j != 1)&& (j != 2)) printf ("\n%s\n",bad_response);
187                                         }
188                               while ((j != 1)&& (j != 2));
189                               if (j == 2)
190                               {
191                                         t[q - 1] = 0;
192                                         tc = tc - 1;
193                                         printf ("\n%sOK, just don't tell anyone else.\n",pad);
194                                         vf = vf - (level[func_d()- 1] == 25);
195                                         fighting = 0;
196                                         }
197                               else monster_attack();
198                               }
199                     }
200           break;
201           }
202 if (alive == 0) fighting = 0;
203 }
204 return 0;
205 }
206 
207 monster_attack()
208 {
209           int j;
210           q3 = 2;
211           if (wc > 0)
212           {
213                     wc = wc - 1;
214                     if (wc == 0) printf ("\n%sTHE WEB JUST BROKE!\n",pad);
215                     }
216           printf ("\n%sThe ",qpad);
217           for (j = jj; j <= strlen(ms)- 1; ++j)
218           {
219                     printf ("%c",ms[j]);
220                     }
221           if (wc > 0)
222           {
223                     printf (" is stuck and can't attack now!\n");
224                     return 0;
225                     }
226           printf (" attacks!\n");
227           if (ww >= roll(7)+ roll(7)+ roll(7)+ bl * 3)
228           {
229                     printf ("\n%sWhat luck, he missed you!\n",qpad);
230                     return 0;
231                     }
232           printf ("\n%s%s********** OUCH! HE HIT YOU!%s%s\n",bright,qpad,dim,bell);
233           check_damage(q1);
234           if ((uu < 1)|| (ww < 1)) alive = 0;
235           return 0;
236           }
237 
238 monster_death()
239 {
240           int n, q;
241 
242           printf ("\n%s%s ",pad,dungeon[attack + 11].contents);
243           printf ("lies dead at your feet!%s\n",bell);
244           if (hh <= tt - 60)
245           {
246                     printf ("\n%sYou spend an hour eating ",pad);
247                     printf ("%s%s.\n",dungeon[attack + 11].contents,effect[roll(8)- 1]);
248                     hh = tt;
249                     }
250           if (((x_axis == r[0])&& (y_axis == r[1])&& (z_axis == r[2]))&& (rf != 1))
251           {
252                     printf ("\n");
253                     border ("*",52);
254                     printf ("%s  GREAT ZOT! YOU'VE FOUND THE RUNESTAFF!%s\n",pad,bell);
255                     border ("*",52);
256                     rf = 1;
257                     printf ("\n");
258                     }
259           else
260           {
261                     if (attack == 13)
262                     {
263                               printf ("\n%sYOU GET ALL HIS WARES:\n",pad);
264                               printf ("%sPlate Armor\n",qpad);
265                               ee = 3;
266                               ah = 21;
267                               printf ("%sA Sword\n",qpad);
268                               ff = 3;
269                               printf ("%sA Strength Potion\n",qpad);
270                               uu = below_nineteen(uu + roll(6));
271                               printf ("%sAn Intelligence Potion\n",qpad);
272                               vv = below_nineteen(vv + roll(6));
273                               printf ("%sA Dexterity Potion\n",qpad);
274                               ww = below_nineteen(ww + roll(6));
275                               printf ("%sA Lamp\n",qpad);
276                               lf = 1;
277                               }
278                     }
279           q = roll(attack * 100 + z_axis * 50);
280           if ((attack == 9)|| (attack == 12)) q = q + 100 * (z_axis / 2);
281           find_money(q);
282           printf ("%sYou get his hoard of %d %s!%s\n",pad,q,gold[roll(14)- 1],bell);
283           gg = gg + q;
284           if (master_game > 1)
285           {
286                     n = roll(10);
287                     isfrog = (n + 4) / 5;
288                     printf ("\n%s%s%sOn the floor is a%s FROG!%s\n",bell,pad,bright,frog[n - 1],dim);
289                     printf ("    ");
290                     border ("-",52);
291                     }
292           if ((attack == 9)&& (master_game + of == 1))
293           {
294                     printf ("\n");
295                     border ("-",52);
296                     printf ("%s%sThis castle has electric power!%s\n",bright,pad,dim);
297                     border ("-",52);
298                     }
299           if ((attack == 12)&& (master_game + of == 1))
300           {
301                     printf ("\n");
302                     border ("-",52);
303                     printf ("%s%sWhere would YOU put the light switch?%s\n",bright,pad,dim);
304                     border ("-",52);
305                     }
306           level[func_d() - 1] = 1;
307           return 0;
308           }
309 
310 go_buy()
311 {
312           int a, i, q, done_buying = 0;
313 
314           if (master_game + of == 0) printf ("\n%s%sOld ZOT thought narcissism was a BRIGHT idea.%s\n",pad,bright,dim);
315           if (tc > 0)
316           {
317                     printf ("\nDo you want purchase offers on your treasures? ");
318                     i = fancy_input(102);
319                     if (i == 2)
320                     {
321                               printf ("\n%s   Gold%s%s Highest  Last   Current Sell?\n",bright,qpad,pad);
322                               printf ("  Balance  Treasures    Offer   Offer   Offer   Y/N\n");
323                               printf ("  -------  ----------  ------- ------- ------ -----\n");
324                               printf ("%s",dim);
325                               for (q = 1;  q <= 8; ++q)
326                               {
327                                         a = roll(q * 1500);
328                                         if (t[q - 1] > 0)
329                                         {
330                                                   if (gg < 1000) printf ("    %5d",gg);
331                                                   else printf ("   %2d,%03d",gg / 1000,gg % 1000);
332                                                   printf ("  %s  ",treasure[q + 7]);
333                                                   if (p[q + 7] < 1000) printf (" %5d",p[q + 7]);
334                                                   else printf ("%2d,%03d",p[q + 7] / 1000,p[q + 7] % 1000);
335                                                   if (p[q - 1] < 1000) printf ("   %5d",p[q - 1]);
336                                                   else printf ("  %2d,%03d",p[q - 1] / 1000,p[q - 1] % 1000);
337                                                   if (a < 1000) printf ("  %5d  ",a);
338                                                   else printf (" %2d,%03d  ",a / 1000,a % 1000);
339                                                   i = fancy_input(102);
340                                                   if (i == 2)
341                                                   {
342                                                             tc = tc - 1;
343                                                             t[q - 1] = 0;
344                                                             gg = gg + a;
345                                                             }
346                                                   p[q - 1] = a;
347                                                   if (a > p[q + 7]) p[q + 7] = a;
348                                                   }
349                                         if (gg > 20000) break;
350                                         }
351                               }
352                     }
353           if (gg < 1000)
354           {
355                     printf ("\n%sYOU'RE TOO POOR TO BUY ANYTHING, %s.\n",pad,species[dd - 1]);
356                     return 0;
357                     }
358           if (gg >= 1250) /* buy armor or weapon */
359           {
360                     if (((gg < 1500)&& (ee == 0))|| (((gg > 1499)&& (gg < 2000))&& (ee < 2))|| ((gg >= 2000)&& (ee < 3)))
361                     {
362                               do
363                               {
364                                         printf ("\n%sOK, %s, you have %d gold pieces\n%sand %s armor.\n",pad,species[dd - 1],gg,qpad,cause[ee + 4]);
365                                         printf ("\nThese are the types of ARMOR you can buy:\n");
366                                         printf ("%s(N)one ",bright);
367                                         if (ee < 1) printf ("(L)eather-1250 ");
368                                         if ((gg > 1499)&& (ee < 2)) printf ("(C)hainmail-1500 ");
369                                         if (gg > 1999) printf ("(P)late-2000");
370                                         printf ("%s\n",dim);
371                                         do
372                                         {
373                                                   printf ("\nCommand #%d? ",tt);
374                                                   ++tt;
375                                                   i = fancy_input(913);
376                                                   if ((i == 9)&& (ee < 1))
377                                                   {
378                                                             gg = gg - 1250;
379                                                             ee = 1;
380                                                             ah = 7;
381                                                             done_buying = 1;
382                                                             }
383                                                   if ((i == 10)&& (gg < 1500)) printf ("\n%s** YOU HAVEN'T GOT THAT MUCH CASH ON HAND!\n\n",pad);
384                                                   if (((i == 10)&& (ee < 2))&& (gg > 1499))
385                                                   {
386                                                             gg = gg - 1500;
387                                                             ee = 2;
388                                                             ah = 14;
389                                                             done_buying = 1;
390                                                             }
391                                                   if ((i == 11)&& (gg < 2000)) printf ("\n%s** YOU CAN'T AFFORD PLATE ARMOR!\n\n",pad);
392                                                   if ((i == 11)&& (gg > 1999))
393                                                   {
394                                                             gg = gg - 2000;
395                                                             ee = 3;
396                                                             ah = 21;
397                                                             done_buying = 1;
398                                                             }
399                                                   if (i == 13) done_buying = 1;
400                                                   if ((i < 9)|| (i > 13)) printf ("\n%s\n",bad_response);
401                                                   }
402                                         while ((i < 9)|| (i > 13));
403                                         }
404                               while (done_buying == 0);
405                               }
406                     done_buying = 0;
407                     if (((gg < 1500)&& (ff == 0))|| (((gg > 1499)&& (gg < 2000))&& (ff < 2))|| ((gg >= 2000)&& (ff < 3)))
408                     {
409                               do
410                               {
411                                         printf ("\n%sYou have %d gold pieces left.\n%swith %s in hand.\n",pad,gg,qpad,cause[ff]);
412                                         printf ("\nThese are the types of WEAPON you can buy:\n");
413                                         printf ("%s(N)one ",bright);
414                                         if (ff < 1) printf ("(D)agger-1250 ");
415                                         if ((gg > 1499)&& (ff < 2)) printf ("(M)ace-1500 ");
416                                         if (gg > 1999) printf ("(S)word-2000");
417                                         printf ("%s\n",dim);
418                                         do
419                                         {
420                                                   printf ("\nCommand #%d? ",tt);
421                                                   ++tt;
422                                                   i = fancy_input(1215);
423                                                   if ((i == 14)&& (ff < 1))
424                                                   {
425                                                             gg = gg - 1250;
426                                                             ff = 1;
427                                                             done_buying = 1;
428                                                             }
429                                                   if ((i == 15)&& (gg < 1500)) printf ("\n%s** SORRY, I'M AFRAID I DON'T GIVE CREDIT!\n\n",pad);
430                                                   if (((i == 15)&& (ff < 2))&& (gg > 1499))
431                                                   {
432                                                             gg = gg - 1500;
433                                                             ff = 2;
434                                                             done_buying = 1;
435                                                             }
436                                                   if ((i == 12)&& (gg < 2000)) printf ("\n%s** YOUR DUNGEON EXPRESS CARD -\n%s%sYOU LEFT HOME WITHOUT IT!\n",pad,qpad,pad);
437                                                   if ((i == 12)&& (gg > 1999))
438                                                   {
439                                                             gg = gg - 2000;
440                                                             ff = 3;
441                                                             done_buying = 1;
442                                                             }
443                                                   if (i == 13) done_buying = 1;
444                                                   if ((i < 12)|| (i > 15)) printf ("\n%s\n",bad_response);
445                                                   }
446                                         while ((i < 12)|| (i > 15));
447                                         }
448                               while (done_buying == 0);
449                               }
450                     done_buying = 0;
451                     }
452           if ((gg > 999)&& (uu + vv + ww < 54)) printf ("\nDo you want to buy some -\n");
453           if ((gg > 999)&& (uu < 18))
454           {
455                     do
456                     {
457                               i = buy_points(strength,uu);
458                               if (i == 2)
459                               {
460                                         gg = gg - 1000;
461                                         uu = below_nineteen(uu + roll(6));
462                                         }
463                               }
464                     while ((uu < 18)&& (gg > 999)&& (i == 2));
465                     }
466           if ((gg > 999)&& (vv < 18))
467           {
468                     do
469                     {
470                               i = buy_points(intelligence,vv);
471                               if (i == 2)
472                               {
473                                         gg = gg - 1000;
474                                         vv = below_nineteen(vv + roll(6));
475                                         }
476                               }
477                     while ((vv < 18)&& (gg > 999)&& (i == 2));
478                     }
479           if ((gg > 999)&& (ww < 18))
480           {
481                     do
482                     {
483                               i = buy_points(dexterity,ww);
484                               if (i == 2)
485                               {
486                                         gg = gg - 1000;
487                                         ww = below_nineteen(ww + roll(6));
488                                         }
489                               }
490                     while ((ww < 18)&& (gg > 999)&& (i == 2));
491                     }
492           if ((gg > 999)&& (lf == 0))
493           {
494                     printf ("\nDo you want a lamp for 1,000 gold pieces? ");
495                     i = fancy_input(102);
496                     if (i == 2)
497                     {
498                               printf ("\n%sIt's guaranteed to outlive you!\n",pad);
499                               gg = gg - 1000;
500                               lf = 1;
501                               }
502                     }
503           return 0;
504           }
505 
506 buy_points(z,n)
507 # 507
508 char *z;
509 # 507
510 int n;
511 {
512           int i;
513 
514           printf ("%s ( now %d )\t",z,n);
515           printf ("for 1,000 (of %2d,%03d)? ",gg / 1000,gg % 1000);
516           i = fancy_input(102);
517           return i;
518           }
519 
520 go_die()
521 {
522           int i;
523 
524           border ("*",52);
525           printf ("%s\n%sA noble effort, oh formerly living %s!%s\n",clrs,pad,species[dd - 1],bell);
526           printf ("\n%sYou died due to lack of",pad);
527           if (uu < 1)
528           {
529                     printf (" %s",strength);
530                     uu = 8;
531                     }
532           if (vv < 1)
533           {
534                     printf (" %s",intelligence);
535                     vv = 8;
536                     }
537           if (ww < 1)
538           {
539                     printf (" %s",dexterity);
540                     ww = 8;
541                     }
542           printf (".\n");
543           printf ("\nDo you want me to attempt to REINCARNATE you? ");
544           i = fancy_input(304);
545           if (i == 4)
546           {
547                     end_game();
548                     return 0;
549                     }
550           printf ("\n");
551           border ("-",52);
552           printf ("%s%s  OK, don't blame me if it doesn't work!\n",bright,pad);
553           if (roll(3)> 1)
554           {
555                     printf ("\n%s%s    Well I'll be%s%sIT WORKED!%s\n",dim,qpad,dots,bright,dim);
556                     ss = roll(2) + 1;
557                     dd = roll(4);
558                     x_axis = roll(8);
559                     y_axis = roll(8);
560                     z_axis = roll(8);
561                     bl = 1;
562                     printf ("\n  Sorry, but you came back as a %sBLIND %s%s!%s\n",bright,sss[ss],species[dd - 1],dim);
563                     border ("-",52);
564                     alive = 1;
565                     check_events();
566                     }
567           else
568           {
569                     printf ("\n%s   Oh well, at least I tried!\n",qpad);
570                     border ("-",52);
571                     end_game();
572                     }
573           return 0;
574           }
575