]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/global.c
Add gcc printf format checking, and fix the abundant problems this revealed.
[bsdgames-darwin.git] / larn / global.c
1 /* $NetBSD: global.c,v 1.8 2008/01/28 03:39:31 dholland Exp $ */
2
3 /*
4 * global.c Larn is copyrighted 1986 by Noah Morgan.
5 *
6 * raiselevel() subroutine to raise the player one level
7 * loselevel() subroutine to lower the player by one level
8 * raiseexperience(x) subroutine to increase experience points
9 * loseexperience(x) subroutine to lose experience points
10 * losehp(x) subroutine to remove hit points from the player
11 * losemhp(x) subroutine to remove max # hit points from the player
12 * raisehp(x) subroutine to gain hit points
13 * raisemhp(x) subroutine to gain maximum hit points
14 * losespells(x) subroutine to lose spells
15 * losemspells(x) subroutine to lose maximum spells
16 * raisespells(x) subroutine to gain spells
17 * raisemspells(x) subroutine to gain maximum spells
18 * recalc() function to recalculate the armor class of the player
19 * makemonst(lev) function to return monster number for a randomly
20 * selected monster
21 * positionplayer() function to be sure player is not in a wall
22 * quit() subroutine to ask if the player really wants to quit
23 */
24 #include <sys/cdefs.h>
25 #ifndef lint
26 __RCSID("$NetBSD: global.c,v 1.8 2008/01/28 03:39:31 dholland Exp $");
27 #endif /* not lint */
28
29 #include <string.h>
30 #include <unistd.h>
31 #include "header.h"
32 #include "extern.h"
33 extern int score[], dropflag;
34 extern int random; /* the random number seed */
35 extern char *what[], *who[];
36 extern char winner[];
37 extern char sciv[SCORESIZE + 1][26][2];
38 extern char *password;
39
40 /*
41 ***********
42 RAISE LEVEL
43 ***********
44 raiselevel()
45
46 subroutine to raise the player one level
47 uses the skill[] array to find level boundarys
48 uses c[EXPERIENCE] c[LEVEL]
49 */
50 void
51 raiselevel()
52 {
53 if (c[LEVEL] < MAXPLEVEL)
54 raiseexperience((long) (skill[c[LEVEL]] - c[EXPERIENCE]));
55 }
56
57 /*
58 ***********
59 LOOSE LEVEL
60 ***********
61 loselevel()
62
63 subroutine to lower the players character level by one
64 */
65 void
66 loselevel()
67 {
68 if (c[LEVEL] > 1)
69 loseexperience((long) (c[EXPERIENCE] - skill[c[LEVEL] - 1] + 1));
70 }
71
72 /*
73 ****************
74 RAISE EXPERIENCE
75 ****************
76 raiseexperience(x)
77
78 subroutine to increase experience points
79 */
80 void
81 raiseexperience(x)
82 long x;
83 {
84 int i, tmp;
85 i = c[LEVEL];
86 c[EXPERIENCE] += x;
87 while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) {
88 tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1;
89 c[LEVEL]++;
90 raisemhp((int) (rnd(3) + rnd((tmp > 0) ? tmp : 1)));
91 raisemspells((int) rund(3));
92 if (c[LEVEL] < 7 - c[HARDGAME])
93 raisemhp((int) (c[CONSTITUTION] >> 2));
94 }
95 if (c[LEVEL] != i) {
96 cursors();
97 beep();
98 lprintf("\nWelcome to level %ld", (long) c[LEVEL]); /* if we changed levels */
99 }
100 bottomline();
101 }
102
103 /*
104 ****************
105 LOOSE EXPERIENCE
106 ****************
107 loseexperience(x)
108
109 subroutine to lose experience points
110 */
111 void
112 loseexperience(x)
113 long x;
114 {
115 int i, tmp;
116 i = c[LEVEL];
117 c[EXPERIENCE] -= x;
118 if (c[EXPERIENCE] < 0)
119 c[EXPERIENCE] = 0;
120 while (c[EXPERIENCE] < skill[c[LEVEL] - 1]) {
121 if (--c[LEVEL] <= 1)
122 c[LEVEL] = 1; /* down one level */
123 tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1; /* lose hpoints */
124 losemhp((int) rnd((tmp > 0) ? tmp : 1)); /* lose hpoints */
125 if (c[LEVEL] < 7 - c[HARDGAME])
126 losemhp((int) (c[CONSTITUTION] >> 2));
127 losemspells((int) rund(3)); /* lose spells */
128 }
129 if (i != c[LEVEL]) {
130 cursors();
131 beep();
132 lprintf("\nYou went down to level %ld!", (long) c[LEVEL]);
133 }
134 bottomline();
135 }
136
137 /*
138 ********
139 LOOSE HP
140 ********
141 losehp(x)
142 losemhp(x)
143
144 subroutine to remove hit points from the player
145 warning -- will kill player if hp goes to zero
146 */
147 void
148 losehp(x)
149 int x;
150 {
151 if ((c[HP] -= x) <= 0) {
152 beep();
153 lprcat("\n");
154 nap(3000);
155 died(lastnum);
156 }
157 }
158
159 void
160 losemhp(x)
161 int x;
162 {
163 c[HP] -= x;
164 if (c[HP] < 1)
165 c[HP] = 1;
166 c[HPMAX] -= x;
167 if (c[HPMAX] < 1)
168 c[HPMAX] = 1;
169 }
170
171 /*
172 ********
173 RAISE HP
174 ********
175 raisehp(x)
176 raisemhp(x)
177
178 subroutine to gain maximum hit points
179 */
180 void
181 raisehp(x)
182 int x;
183 {
184 if ((c[HP] += x) > c[HPMAX])
185 c[HP] = c[HPMAX];
186 }
187
188 void
189 raisemhp(x)
190 int x;
191 {
192 c[HPMAX] += x;
193 c[HP] += x;
194 }
195
196 /*
197 ************
198 RAISE SPELLS
199 ************
200 raisespells(x)
201 raisemspells(x)
202
203 subroutine to gain maximum spells
204 */
205 void
206 raisespells(x)
207 int x;
208 {
209 if ((c[SPELLS] += x) > c[SPELLMAX])
210 c[SPELLS] = c[SPELLMAX];
211 }
212
213 void
214 raisemspells(x)
215 int x;
216 {
217 c[SPELLMAX] += x;
218 c[SPELLS] += x;
219 }
220
221 /*
222 ************
223 LOOSE SPELLS
224 ************
225 losespells(x)
226 losemspells(x)
227
228 subroutine to lose maximum spells
229 */
230 void
231 losespells(x)
232 int x;
233 {
234 if ((c[SPELLS] -= x) < 0)
235 c[SPELLS] = 0;
236 }
237
238 void
239 losemspells(x)
240 int x;
241 {
242 if ((c[SPELLMAX] -= x) < 0)
243 c[SPELLMAX] = 0;
244 if ((c[SPELLS] -= x) < 0)
245 c[SPELLS] = 0;
246 }
247
248 /*
249 makemonst(lev)
250 int lev;
251
252 function to return monster number for a randomly selected monster
253 for the given cave level
254 */
255 int
256 makemonst(lev)
257 int lev;
258 {
259 int tmp, x;
260 if (lev < 1)
261 lev = 1;
262 if (lev > 12)
263 lev = 12;
264 tmp = WATERLORD;
265 if (lev < 5)
266 while (tmp == WATERLORD)
267 tmp = rnd((x = monstlevel[lev - 1]) ? x : 1);
268 else
269 while (tmp == WATERLORD)
270 tmp = rnd((x = monstlevel[lev - 1] - monstlevel[lev - 4]) ? x : 1) + monstlevel[lev - 4];
271
272 while (monster[tmp].genocided && tmp < MAXMONST)
273 tmp++; /* genocided? */
274 return (tmp);
275 }
276
277 /*
278 positionplayer()
279
280 function to be sure player is not in a wall
281 */
282 void
283 positionplayer()
284 {
285 int try;
286 try = 2;
287 while ((item[playerx][playery] || mitem[playerx][playery]) && (try))
288 if (++playerx >= MAXX - 1) {
289 playerx = 1;
290 if (++playery >= MAXY - 1) {
291 playery = 1;
292 --try;
293 }
294 }
295 if (try == 0)
296 lprcat("Failure in positionplayer\n");
297 }
298
299 /*
300 recalc() function to recalculate the armor class of the player
301 */
302 void
303 recalc()
304 {
305 int i, j, k;
306 c[AC] = c[MOREDEFENSES];
307 if (c[WEAR] >= 0)
308 switch (iven[c[WEAR]]) {
309 case OSHIELD:
310 c[AC] += 2 + ivenarg[c[WEAR]];
311 break;
312 case OLEATHER:
313 c[AC] += 2 + ivenarg[c[WEAR]];
314 break;
315 case OSTUDLEATHER:
316 c[AC] += 3 + ivenarg[c[WEAR]];
317 break;
318 case ORING:
319 c[AC] += 5 + ivenarg[c[WEAR]];
320 break;
321 case OCHAIN:
322 c[AC] += 6 + ivenarg[c[WEAR]];
323 break;
324 case OSPLINT:
325 c[AC] += 7 + ivenarg[c[WEAR]];
326 break;
327 case OPLATE:
328 c[AC] += 9 + ivenarg[c[WEAR]];
329 break;
330 case OPLATEARMOR:
331 c[AC] += 10 + ivenarg[c[WEAR]];
332 break;
333 case OSSPLATE:
334 c[AC] += 12 + ivenarg[c[WEAR]];
335 break;
336 }
337
338 if (c[SHIELD] >= 0)
339 if (iven[c[SHIELD]] == OSHIELD)
340 c[AC] += 2 + ivenarg[c[SHIELD]];
341 if (c[WIELD] < 0)
342 c[WCLASS] = 0;
343 else {
344 i = ivenarg[c[WIELD]];
345 switch (iven[c[WIELD]]) {
346 case ODAGGER:
347 c[WCLASS] = 3 + i;
348 break;
349 case OBELT:
350 c[WCLASS] = 7 + i;
351 break;
352 case OSHIELD:
353 c[WCLASS] = 8 + i;
354 break;
355 case OSPEAR:
356 c[WCLASS] = 10 + i;
357 break;
358 case OFLAIL:
359 c[WCLASS] = 14 + i;
360 break;
361 case OBATTLEAXE:
362 c[WCLASS] = 17 + i;
363 break;
364 case OLANCE:
365 c[WCLASS] = 19 + i;
366 break;
367 case OLONGSWORD:
368 c[WCLASS] = 22 + i;
369 break;
370 case O2SWORD:
371 c[WCLASS] = 26 + i;
372 break;
373 case OSWORD:
374 c[WCLASS] = 32 + i;
375 break;
376 case OSWORDofSLASHING:
377 c[WCLASS] = 30 + i;
378 break;
379 case OHAMMER:
380 c[WCLASS] = 35 + i;
381 break;
382 default:
383 c[WCLASS] = 0;
384 }
385 }
386 c[WCLASS] += c[MOREDAM];
387
388 /* now for regeneration abilities based on rings */
389 c[REGEN] = 1;
390 c[ENERGY] = 0;
391 j = 0;
392 for (k = 25; k > 0; k--)
393 if (iven[k]) {
394 j = k;
395 k = 0;
396 }
397 for (i = 0; i <= j; i++) {
398 switch (iven[i]) {
399 case OPROTRING:
400 c[AC] += ivenarg[i] + 1;
401 break;
402 case ODAMRING:
403 c[WCLASS] += ivenarg[i] + 1;
404 break;
405 case OBELT:
406 c[WCLASS] += ((ivenarg[i] << 1)) + 2;
407 break;
408
409 case OREGENRING:
410 c[REGEN] += ivenarg[i] + 1;
411 break;
412 case ORINGOFEXTRA:
413 c[REGEN] += 5 * (ivenarg[i] + 1);
414 break;
415 case OENERGYRING:
416 c[ENERGY] += ivenarg[i] + 1;
417 break;
418 }
419 }
420 }
421
422
423 /*
424 quit()
425
426 subroutine to ask if the player really wants to quit
427 */
428 void
429 quit()
430 {
431 int i;
432 cursors();
433 strcpy(lastmonst, "");
434 lprcat("\n\nDo you really want to quit?");
435 while (1) {
436 i = lgetchar();
437 if (i == 'y') {
438 died(300);
439 return;
440 }
441 if ((i == 'n') || (i == '\33')) {
442 lprcat(" no");
443 lflush();
444 return;
445 }
446 lprcat("\n");
447 setbold();
448 lprcat("Yes");
449 resetbold();
450 lprcat(" or ");
451 setbold();
452 lprcat("No");
453 resetbold();
454 lprcat(" please? Do you want to quit? ");
455 }
456 }
457
458 /*
459 function to ask --more-- then the user must enter a space
460 */
461 void
462 more()
463 {
464 lprcat("\n --- press ");
465 standout("space");
466 lprcat(" to continue --- ");
467 while (lgetchar() != ' ');
468 }
469
470 /*
471 function to put something in the players inventory
472 returns 0 if success, 1 if a failure
473 */
474 int
475 take(itm, arg)
476 int itm, arg;
477 {
478 int i, limit;
479 /* cursors(); */
480 if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
481 limit = 26;
482 for (i = 0; i < limit; i++)
483 if (iven[i] == 0) {
484 iven[i] = itm;
485 ivenarg[i] = arg;
486 limit = 0;
487 switch (itm) {
488 case OPROTRING:
489 case ODAMRING:
490 case OBELT:
491 limit = 1;
492 break;
493 case ODEXRING:
494 c[DEXTERITY] += ivenarg[i] + 1;
495 limit = 1;
496 break;
497 case OSTRRING:
498 c[STREXTRA] += ivenarg[i] + 1;
499 limit = 1;
500 break;
501 case OCLEVERRING:
502 c[INTELLIGENCE] += ivenarg[i] + 1;
503 limit = 1;
504 break;
505 case OHAMMER:
506 c[DEXTERITY] += 10;
507 c[STREXTRA] += 10;
508 c[INTELLIGENCE] -= 10;
509 limit = 1;
510 break;
511
512 case OORBOFDRAGON:
513 c[SLAYING]++;
514 break;
515 case OSPIRITSCARAB:
516 c[NEGATESPIRIT]++;
517 break;
518 case OCUBEofUNDEAD:
519 c[CUBEofUNDEAD]++;
520 break;
521 case ONOTHEFT:
522 c[NOTHEFT]++;
523 break;
524 case OSWORDofSLASHING:
525 c[DEXTERITY] += 5;
526 limit = 1;
527 break;
528 };
529 lprcat("\nYou pick up:");
530 srcount = 0;
531 show3(i);
532 if (limit)
533 bottomline();
534 return (0);
535 }
536 lprcat("\nYou can't carry anything else");
537 return (1);
538 }
539
540 /*
541 subroutine to drop an object
542 returns 1 if something there already else 0
543 */
544 int
545 drop_object(k)
546 int k;
547 {
548 int itm;
549 if ((k < 0) || (k > 25))
550 return (0);
551 itm = iven[k];
552 cursors();
553 if (itm == 0) {
554 lprintf("\nYou don't have item %c! ", k + 'a');
555 return (1);
556 }
557 if (item[playerx][playery]) {
558 beep();
559 lprcat("\nThere's something here already");
560 return (1);
561 }
562 if (playery == MAXY - 1 && playerx == 33)
563 return (1); /* not in entrance */
564 item[playerx][playery] = itm;
565 iarg[playerx][playery] = ivenarg[k];
566 srcount = 0;
567 lprcat("\n You drop:");
568 show3(k); /* show what item you dropped */
569 know[playerx][playery] = 0;
570 iven[k] = 0;
571 if (c[WIELD] == k)
572 c[WIELD] = -1;
573 if (c[WEAR] == k)
574 c[WEAR] = -1;
575 if (c[SHIELD] == k)
576 c[SHIELD] = -1;
577 adjustcvalues(itm, ivenarg[k]);
578 dropflag = 1; /* say dropped an item so wont ask to pick it
579 * up right away */
580 return (0);
581 }
582
583 /*
584 function to enchant armor player is currently wearing
585 */
586 void
587 enchantarmor()
588 {
589 int tmp;
590 if (c[WEAR] < 0) {
591 if (c[SHIELD] < 0) {
592 cursors();
593 beep();
594 lprcat("\nYou feel a sense of loss");
595 return;
596 } else {
597 tmp = iven[c[SHIELD]];
598 if (tmp != OSCROLL)
599 if (tmp != OPOTION) {
600 ivenarg[c[SHIELD]]++;
601 bottomline();
602 }
603 }
604 }
605 tmp = iven[c[WEAR]];
606 if (tmp != OSCROLL)
607 if (tmp != OPOTION) {
608 ivenarg[c[WEAR]]++;
609 bottomline();
610 }
611 }
612
613 /*
614 function to enchant a weapon presently being wielded
615 */
616 void
617 enchweapon()
618 {
619 int tmp;
620 if (c[WIELD] < 0) {
621 cursors();
622 beep();
623 lprcat("\nYou feel a sense of loss");
624 return;
625 }
626 tmp = iven[c[WIELD]];
627 if (tmp != OSCROLL)
628 if (tmp != OPOTION) {
629 ivenarg[c[WIELD]]++;
630 if (tmp == OCLEVERRING)
631 c[INTELLIGENCE]++;
632 else if (tmp == OSTRRING)
633 c[STREXTRA]++;
634 else if (tmp == ODEXRING)
635 c[DEXTERITY]++;
636 bottomline();
637 }
638 }
639
640 /*
641 routine to tell if player can carry one more thing
642 returns 1 if pockets are full, else 0
643 */
644 int
645 pocketfull()
646 {
647 int i, limit;
648 if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
649 limit = 26;
650 for (i = 0; i < limit; i++)
651 if (iven[i] == 0)
652 return (0);
653 return (1);
654 }
655
656 /*
657 function to return 1 if a monster is next to the player else returns 0
658 */
659 int
660 nearbymonst()
661 {
662 int tmp, tmp2;
663 for (tmp = playerx - 1; tmp < playerx + 2; tmp++)
664 for (tmp2 = playery - 1; tmp2 < playery + 2; tmp2++)
665 if (mitem[tmp][tmp2])
666 return (1); /* if monster nearby */
667 return (0);
668 }
669
670 /*
671 function to steal an item from the players pockets
672 returns 1 if steals something else returns 0
673 */
674 int
675 stealsomething()
676 {
677 int i, j;
678 j = 100;
679 while (1) {
680 i = rund(26);
681 if (iven[i])
682 if (c[WEAR] != i)
683 if (c[WIELD] != i)
684 if (c[SHIELD] != i) {
685 srcount = 0;
686 show3(i);
687 adjustcvalues(iven[i], ivenarg[i]);
688 iven[i] = 0;
689 return (1);
690 }
691 if (--j <= 0)
692 return (0);
693 }
694 }
695
696 /*
697 function to return 1 is player carrys nothing else return 0
698 */
699 int
700 emptyhanded()
701 {
702 int i;
703 for (i = 0; i < 26; i++)
704 if (iven[i])
705 if (i != c[WIELD])
706 if (i != c[WEAR])
707 if (i != c[SHIELD])
708 return (0);
709 return (1);
710 }
711
712 /*
713 function to create a gem on a square near the player
714 */
715 void
716 creategem()
717 {
718 int i, j;
719 switch (rnd(4)) {
720 case 1:
721 i = ODIAMOND;
722 j = 50;
723 break;
724 case 2:
725 i = ORUBY;
726 j = 40;
727 break;
728 case 3:
729 i = OEMERALD;
730 j = 30;
731 break;
732 default:
733 i = OSAPPHIRE;
734 j = 20;
735 break;
736 };
737 createitem(i, rnd(j) + j / 10);
738 }
739
740 /*
741 function to change character levels as needed when dropping an object
742 that affects these characteristics
743 */
744 void
745 adjustcvalues(itm, arg)
746 int itm, arg;
747 {
748 int flag;
749 flag = 0;
750 switch (itm) {
751 case ODEXRING:
752 c[DEXTERITY] -= arg + 1;
753 flag = 1;
754 break;
755 case OSTRRING:
756 c[STREXTRA] -= arg + 1;
757 flag = 1;
758 break;
759 case OCLEVERRING:
760 c[INTELLIGENCE] -= arg + 1;
761 flag = 1;
762 break;
763 case OHAMMER:
764 c[DEXTERITY] -= 10;
765 c[STREXTRA] -= 10;
766 c[INTELLIGENCE] += 10;
767 flag = 1;
768 break;
769 case OSWORDofSLASHING:
770 c[DEXTERITY] -= 5;
771 flag = 1;
772 break;
773 case OORBOFDRAGON:
774 --c[SLAYING];
775 return;
776 case OSPIRITSCARAB:
777 --c[NEGATESPIRIT];
778 return;
779 case OCUBEofUNDEAD:
780 --c[CUBEofUNDEAD];
781 return;
782 case ONOTHEFT:
783 --c[NOTHEFT];
784 return;
785 case OLANCE:
786 c[LANCEDEATH] = 0;
787 return;
788 case OPOTION:
789 case OSCROLL:
790 return;
791
792 default:
793 flag = 1;
794 };
795 if (flag)
796 bottomline();
797 }
798
799 /*
800 function to read a string from token input "string"
801 returns a pointer to the string
802 */
803 void
804 gettokstr(str)
805 char *str;
806 {
807 int i, j;
808 i = 50;
809 while ((lgetchar() != '"') && (--i > 0));
810 i = 36;
811 while (--i > 0) {
812 if ((j = lgetchar()) != '"')
813 *str++ = j;
814 else
815 i = 0;
816 }
817 *str = 0;
818 i = 50;
819 if (j != '"')
820 /* if end due to too long, then find closing quote */
821 while ((lgetchar() != '"') && (--i > 0));
822 }
823
824 /*
825 function to ask user for a password (no echo)
826 returns 1 if entered correctly, 0 if not
827 */
828 static char gpwbuf[33];
829 int
830 getpassword()
831 {
832 int i, j;
833 char *gpwp;
834 scbr(); /* system("stty -echo cbreak"); */
835 gpwp = gpwbuf;
836 lprcat("\nEnter Password: ");
837 lflush();
838 i = strlen(password);
839 for (j = 0; j < i; j++)
840 read(0, gpwp++, 1);
841 gpwbuf[i] = 0;
842 sncbr(); /* system("stty echo -cbreak"); */
843 if (strcmp(gpwbuf, password) != 0) {
844 lprcat("\nSorry\n");
845 lflush();
846 return (0);
847 } else
848 return (1);
849 }
850
851 /*
852 subroutine to get a yes or no response from the user
853 returns y or n
854 */
855 int
856 getyn()
857 {
858 int i;
859 i = 0;
860 while (i != 'y' && i != 'n' && i != '\33')
861 i = lgetchar();
862 return (i);
863 }
864
865 /*
866 function to calculate the pack weight of the player
867 returns the number of pounds the player is carrying
868 */
869 int
870 packweight()
871 {
872 int i, j, k;
873 k = c[GOLD] / 1000;
874 j = 25;
875 while ((iven[j] == 0) && (j > 0))
876 --j;
877 for (i = 0; i <= j; i++)
878 switch (iven[i]) {
879 case 0:
880 break;
881 case OSSPLATE:
882 case OPLATEARMOR:
883 k += 40;
884 break;
885 case OPLATE:
886 k += 35;
887 break;
888 case OHAMMER:
889 k += 30;
890 break;
891 case OSPLINT:
892 k += 26;
893 break;
894 case OSWORDofSLASHING:
895 case OCHAIN:
896 case OBATTLEAXE:
897 case O2SWORD:
898 k += 23;
899 break;
900 case OLONGSWORD:
901 case OSWORD:
902 case ORING:
903 case OFLAIL:
904 k += 20;
905 break;
906 case OLANCE:
907 case OSTUDLEATHER:
908 k += 15;
909 break;
910 case OLEATHER:
911 case OSPEAR:
912 k += 8;
913 break;
914 case OORBOFDRAGON:
915 case OBELT:
916 k += 4;
917 break;
918 case OSHIELD:
919 k += 7;
920 break;
921 case OCHEST:
922 k += 30 + ivenarg[i];
923 break;
924 default:
925 k++;
926 };
927 return (k);
928 }
929
930 #ifndef MACRORND
931 /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
932 int
933 rnd(x)
934 int x;
935 {
936 return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)) + 1);
937 }
938
939 int
940 rund(x)
941 int x;
942 {
943 return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)));
944 }
945 #endif /* MACRORND */