1 /* global.c Larn is copyrighted 1986 by Noah Morgan.
2 * $FreeBSD: src/games/larn/global.c,v 1.5 1999/11/16 02:57:21 billf Exp $
3 * $DragonFly: src/games/larn/global.c,v 1.5 2006/08/26 17:05:05 pavalos Exp $
5 * raiselevel() subroutine to raise the player one level
6 * loselevel() subroutine to lower the player by one level
7 * raiseexperience(x) subroutine to increase experience points
8 * loseexperience(x) subroutine to lose experience points
9 * losehp(x) subroutine to remove hit points from the player
10 * losemhp(x) subroutine to remove max # hit points from the player
11 * raisehp(x) subroutine to gain hit points
12 * raisemhp(x) subroutine to gain maximum hit points
13 * losemspells(x) subroutine to lose maximum spells
14 * raisemspells(x) subroutine to gain maximum spells
15 * makemonst(lev) function to return monster number for a randomly
17 * positionplayer() function to be sure player is not in a wall
18 * recalc() function to recalculate the armor class of the player
19 * quit() subroutine to ask if the player really wants to quit
24 extern int score[], dropflag;
25 extern char *what[], *who[];
26 extern char password[], winner[];
27 extern char sciv[SCORESIZE + 1][26][2];
32 subroutine to raise the player one level
33 uses the skill[] array to find level boundarys
34 uses c[EXPERIENCE] c[LEVEL]
39 if (c[LEVEL] < MAXPLEVEL)
40 raiseexperience((long)(skill[c[LEVEL]] - c[EXPERIENCE]));
46 subroutine to lower the players character level by one
52 loseexperience((long)(c[EXPERIENCE] - skill[c[LEVEL] - 1] + 1));
58 subroutine to increase experience points
61 raiseexperience(long x)
66 while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) {
67 tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1;
69 raisemhp((int)(rnd(3) + rnd((tmp > 0) ? tmp : 1)));
70 raisemspells((int)rund(3));
71 if (c[LEVEL] < 7 - c[HARDGAME])
72 raisemhp((int)(c[CONSTITUTION] >> 2));
77 lprintf("\nWelcome to level %d", (long)c[LEVEL]); /* if we changed levels */
85 subroutine to lose experience points
88 loseexperience(long x)
93 if (c[EXPERIENCE] < 0)
95 while (c[EXPERIENCE] < skill[c[LEVEL] - 1]) {
96 if (--c[LEVEL] <= 1) /* down one level */
98 tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1; /* lose hpoints */
99 losemhp((int)rnd((tmp > 0) ? tmp : 1)); /* lose hpoints */
100 if (c[LEVEL] < 7 - c[HARDGAME])
101 losemhp((int)(c[CONSTITUTION] >> 2));
102 losemspells((int)rund(3)); /* lose spells */
107 lprintf("\nYou went down to level %d!", (long)c[LEVEL]);
116 subroutine to remove hit points from the player
117 warning -- will kill player if hp goes to zero
122 if ((c[HP] -= x) <= 0) {
145 subroutine to gain maximum hit points
150 if ((c[HP] += x) > c[HPMAX])
164 subroutine to gain maximum spells
176 subroutine to lose maximum spells
181 if ((c[SPELLMAX] -= x) < 0)
183 if ((c[SPELLS] -= x) < 0)
191 function to return monster number for a randomly selected monster
192 for the given cave level
204 while (tmp == WATERLORD)
205 tmp = rnd((x = monstlevel[lev - 1]) ? x : 1);
207 while (tmp == WATERLORD)
208 tmp = rnd((x = monstlevel[lev - 1] - monstlevel[lev - 4])
209 ? x : 1) + monstlevel[lev - 4];
211 while (monster[tmp].genocided && tmp < MAXMONST) /* genocided? */
219 function to be sure player is not in a wall
226 while ((item[playerx][playery] || mitem[playerx][playery]) && (try))
227 if (++playerx >= MAXX - 1) {
229 if (++playery >= MAXY - 1) {
235 lprcat("Failure in positionplayer\n");
239 recalc() function to recalculate the armor class of the player
245 c[AC] = c[MOREDEFENSES];
247 switch (iven[c[WEAR]]) {
249 c[AC] += 2 + ivenarg[c[WEAR]];
252 c[AC] += 2 + ivenarg[c[WEAR]];
255 c[AC] += 3 + ivenarg[c[WEAR]];
258 c[AC] += 5 + ivenarg[c[WEAR]];
261 c[AC] += 6 + ivenarg[c[WEAR]];
264 c[AC] += 7 + ivenarg[c[WEAR]];
267 c[AC] += 9 + ivenarg[c[WEAR]];
270 c[AC] += 10 + ivenarg[c[WEAR]];
273 c[AC] += 12 + ivenarg[c[WEAR]];
278 if (iven[c[SHIELD]] == OSHIELD)
279 c[AC] += 2 + ivenarg[c[SHIELD]];
283 i = ivenarg[c[WIELD]];
284 switch (iven[c[WIELD]]) {
315 case OSWORDofSLASHING:
325 c[WCLASS] += c[MOREDAM];
327 /* now for regeneration abilities based on rings */
331 for (k = 25; k > 0; k--)
336 for (i = 0; i <= j; i++) {
339 c[AC] += ivenarg[i] + 1;
342 c[WCLASS] += ivenarg[i] + 1;
345 c[WCLASS] += ((ivenarg[i] << 1)) + 2;
349 c[REGEN] += ivenarg[i] + 1;
352 c[REGEN] += 5 * (ivenarg[i] + 1);
355 c[ENERGY] += ivenarg[i] + 1;
365 subroutine to ask if the player really wants to quit
372 strcpy(lastmonst, "");
373 lprcat("\n\nDo you really want to quit?");
380 if ((i == 'n') || (i == '\33')) {
393 lprcat(" please? Do you want to quit? ");
398 function to ask --more-- then the user must enter a space
403 lprcat("\n --- press ");
405 lprcat(" to continue --- ");
406 while (getchr() != ' ')
411 function to put something in the players inventory
412 returns 0 if success, 1 if a failure
415 take(int itm, int arg)
418 if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
420 for (i = 0; i < limit; i++)
432 c[DEXTERITY] += ivenarg[i] + 1;
436 c[STREXTRA] += ivenarg[i] + 1;
440 c[INTELLIGENCE] += ivenarg[i] + 1;
446 c[INTELLIGENCE] -= 10;
462 case OSWORDofSLASHING:
467 lprcat("\nYou pick up:");
474 lprcat("\nYou can't carry anything else");
479 subroutine to drop an object
480 returns 1 if something there already else 0
486 if ((k < 0) || (k > 25))
491 lprintf("\nYou don't have item %c! ", k + 'a');
494 if (item[playerx][playery]) {
496 lprcat("\nThere's something here already");
499 if (playery == MAXY - 1 && playerx == 33) /* not in entrance */
501 item[playerx][playery] = itm;
502 iarg[playerx][playery] = ivenarg[k];
504 lprcat("\n You drop:");
505 show3(k); /* show what item you dropped*/
506 know[playerx][playery] = 0;
514 adjustcvalues(itm, ivenarg[k]);
515 /* say dropped an item so wont ask to pick it up right away */
521 function to enchant armor player is currently wearing
531 lprcat("\nYou feel a sense of loss");
534 tmp = iven[c[SHIELD]];
536 if (tmp != OPOTION) {
537 ivenarg[c[SHIELD]]++;
544 if (tmp != OPOTION) {
551 function to enchant a weapon presently being wielded
560 lprcat("\nYou feel a sense of loss");
563 tmp = iven[c[WIELD]];
565 if (tmp != OPOTION) {
567 if (tmp == OCLEVERRING)
569 else if (tmp == OSTRRING)
571 else if (tmp == ODEXRING)
578 routine to tell if player can carry one more thing
579 returns 1 if pockets are full, else 0
585 if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
587 for (i = 0; i < limit; i++)
594 function to return 1 if a monster is next to the player else returns 0
600 for (tmp = playerx - 1; tmp < playerx + 2; tmp++)
601 for (tmp2 = playery - 1; tmp2 < playery + 2; tmp2++)
602 if (mitem[tmp][tmp2]) /* if monster nearby */
608 function to steal an item from the players pockets
609 returns 1 if steals something else returns 0
621 if (c[SHIELD] != i) {
624 adjustcvalues(iven[i], ivenarg[i]);
634 function to return 1 is player carrys nothing else return 0
640 for (i = 0; i < 26; i++)
650 function to create a gem on a square near the player
674 createitem(i, rnd(j) + j / 10);
678 function to change character levels as needed when dropping an object
679 that affects these characteristics
682 adjustcvalues(int itm, int arg)
688 c[DEXTERITY] -= arg + 1;
692 c[STREXTRA] -= arg + 1;
696 c[INTELLIGENCE] -= arg + 1;
702 c[INTELLIGENCE] += 10;
705 case OSWORDofSLASHING:
736 function to ask user for a password (no echo)
737 returns 1 if entered correctly, 0 if not
739 static char gpwbuf[33];
748 lprcat("\nEnter Password: ");
750 i = strlen(password);
751 for (j = 0; j < i; j++)
755 if (strcmp(gpwbuf, password) != 0) {
764 subroutine to get a yes or no response from the user
772 while (i != 'y' && i != 'n' && i != '\33')
778 function to calculate the pack weight of the player
779 returns the number of pounds the player is carrying
787 while ((iven[j] == 0) && (j > 0))
789 for (i = 0; i <= j; i++)
806 case OSWORDofSLASHING:
834 k += 30 + ivenarg[i];
843 /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
847 return ((random() % x) + 1);
853 return (random() % x);
855 #endif /* MACRORND */