1 /* $NetBSD: global.c,v 1.11 2008/02/03 21:24:58 dholland Exp $ */
4 * global.c Larn is copyrighted 1986 by Noah Morgan.
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 * losemspells(x) subroutine to lose maximum spells
15 * raisemspells(x) subroutine to gain maximum spells
16 * makemonst(lev) function to return monster number for a randomly
18 * positionplayer() function to be sure player is not in a wall
19 * recalc() function to recalculate the armor class of the player
20 * quit() subroutine to ask if the player really wants to quit
22 #include <sys/cdefs.h>
24 __RCSID("$NetBSD: global.c,v 1.11 2008/02/03 21:24:58 dholland Exp $");
31 extern int score
[], dropflag
;
32 extern char *what
[], *who
[];
34 extern char sciv
[SCORESIZE
+ 1][26][2];
35 extern char *password
;
40 subroutine to raise the player one level
41 uses the skill[] array to find level boundarys
42 uses c[EXPERIENCE] c[LEVEL]
47 if (c
[LEVEL
] < MAXPLEVEL
)
48 raiseexperience((long) (skill
[c
[LEVEL
]] - c
[EXPERIENCE
]));
54 subroutine to lower the players character level by one
60 loseexperience((long) (c
[EXPERIENCE
] - skill
[c
[LEVEL
] - 1] + 1));
66 subroutine to increase experience points
75 while (c
[EXPERIENCE
] >= skill
[c
[LEVEL
]] && (c
[LEVEL
] < MAXPLEVEL
)) {
76 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1;
78 raisemhp((int) (rnd(3) + rnd((tmp
> 0) ? tmp
: 1)));
79 raisemspells((int) rund(3));
80 if (c
[LEVEL
] < 7 - c
[HARDGAME
])
81 raisemhp((int) (c
[CONSTITUTION
] >> 2));
86 lprintf("\nWelcome to level %ld", (long) c
[LEVEL
]); /* if we changed levels */
94 subroutine to lose experience points
103 if (c
[EXPERIENCE
] < 0)
105 while (c
[EXPERIENCE
] < skill
[c
[LEVEL
] - 1]) {
107 c
[LEVEL
] = 1; /* down one level */
108 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1; /* lose hpoints */
109 losemhp((int) rnd((tmp
> 0) ? tmp
: 1)); /* lose hpoints */
110 if (c
[LEVEL
] < 7 - c
[HARDGAME
])
111 losemhp((int) (c
[CONSTITUTION
] >> 2));
112 losemspells((int) rund(3)); /* lose spells */
117 lprintf("\nYou went down to level %ld!", (long) c
[LEVEL
]);
126 subroutine to remove hit points from the player
127 warning -- will kill player if hp goes to zero
133 if ((c
[HP
] -= x
) <= 0) {
157 subroutine to gain maximum hit points
163 if ((c
[HP
] += x
) > c
[HPMAX
])
178 subroutine to gain maximum spells
191 subroutine to lose maximum spells
197 if ((c
[SPELLMAX
] -= x
) < 0)
199 if ((c
[SPELLS
] -= x
) < 0)
207 function to return monster number for a randomly selected monster
208 for the given cave level
221 while (tmp
== WATERLORD
)
222 tmp
= rnd((x
= monstlevel
[lev
- 1]) ? x
: 1);
224 while (tmp
== WATERLORD
)
225 tmp
= rnd((x
= monstlevel
[lev
- 1] - monstlevel
[lev
- 4]) ? x
: 1) + monstlevel
[lev
- 4];
227 while (monster
[tmp
].genocided
&& tmp
< MAXMONST
)
228 tmp
++; /* genocided? */
235 function to be sure player is not in a wall
242 while ((item
[playerx
][playery
] || mitem
[playerx
][playery
]) && (try))
243 if (++playerx
>= MAXX
- 1) {
245 if (++playery
>= MAXY
- 1) {
251 lprcat("Failure in positionplayer\n");
255 recalc() function to recalculate the armor class of the player
261 c
[AC
] = c
[MOREDEFENSES
];
263 switch (iven
[c
[WEAR
]]) {
265 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
268 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
271 c
[AC
] += 3 + ivenarg
[c
[WEAR
]];
274 c
[AC
] += 5 + ivenarg
[c
[WEAR
]];
277 c
[AC
] += 6 + ivenarg
[c
[WEAR
]];
280 c
[AC
] += 7 + ivenarg
[c
[WEAR
]];
283 c
[AC
] += 9 + ivenarg
[c
[WEAR
]];
286 c
[AC
] += 10 + ivenarg
[c
[WEAR
]];
289 c
[AC
] += 12 + ivenarg
[c
[WEAR
]];
294 if (iven
[c
[SHIELD
]] == OSHIELD
)
295 c
[AC
] += 2 + ivenarg
[c
[SHIELD
]];
299 i
= ivenarg
[c
[WIELD
]];
300 switch (iven
[c
[WIELD
]]) {
331 case OSWORDofSLASHING
:
341 c
[WCLASS
] += c
[MOREDAM
];
343 /* now for regeneration abilities based on rings */
347 for (k
= 25; k
> 0; k
--)
352 for (i
= 0; i
<= j
; i
++) {
355 c
[AC
] += ivenarg
[i
] + 1;
358 c
[WCLASS
] += ivenarg
[i
] + 1;
361 c
[WCLASS
] += ((ivenarg
[i
] << 1)) + 2;
365 c
[REGEN
] += ivenarg
[i
] + 1;
368 c
[REGEN
] += 5 * (ivenarg
[i
] + 1);
371 c
[ENERGY
] += ivenarg
[i
] + 1;
381 subroutine to ask if the player really wants to quit
388 strcpy(lastmonst
, "");
389 lprcat("\n\nDo you really want to quit?");
396 if ((i
== 'n') || (i
== '\33')) {
409 lprcat(" please? Do you want to quit? ");
414 function to ask --more-- then the user must enter a space
419 lprcat("\n --- press ");
421 lprcat(" to continue --- ");
422 while (ttgetch() != ' ');
426 function to put something in the players inventory
427 returns 0 if success, 1 if a failure
430 take(int theitem
, int arg
)
434 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
436 for (i
= 0; i
< limit
; i
++)
448 c
[DEXTERITY
] += ivenarg
[i
] + 1;
452 c
[STREXTRA
] += ivenarg
[i
] + 1;
456 c
[INTELLIGENCE
] += ivenarg
[i
] + 1;
462 c
[INTELLIGENCE
] -= 10;
478 case OSWORDofSLASHING
:
483 lprcat("\nYou pick up:");
490 lprcat("\nYou can't carry anything else");
495 subroutine to drop an object
496 returns 1 if something there already else 0
503 if ((k
< 0) || (k
> 25))
508 lprintf("\nYou don't have item %c! ", k
+ 'a');
511 if (item
[playerx
][playery
]) {
513 lprcat("\nThere's something here already");
516 if (playery
== MAXY
- 1 && playerx
== 33)
517 return (1); /* not in entrance */
518 item
[playerx
][playery
] = theitem
;
519 iarg
[playerx
][playery
] = ivenarg
[k
];
521 lprcat("\n You drop:");
522 show3(k
); /* show what item you dropped */
523 know
[playerx
][playery
] = 0;
531 adjustcvalues(theitem
, ivenarg
[k
]);
532 dropflag
= 1; /* say dropped an item so wont ask to pick it
538 function to enchant armor player is currently wearing
548 lprcat("\nYou feel a sense of loss");
551 tmp
= iven
[c
[SHIELD
]];
553 if (tmp
!= OPOTION
) {
554 ivenarg
[c
[SHIELD
]]++;
561 if (tmp
!= OPOTION
) {
568 function to enchant a weapon presently being wielded
577 lprcat("\nYou feel a sense of loss");
580 tmp
= iven
[c
[WIELD
]];
582 if (tmp
!= OPOTION
) {
584 if (tmp
== OCLEVERRING
)
586 else if (tmp
== OSTRRING
)
588 else if (tmp
== ODEXRING
)
595 routine to tell if player can carry one more thing
596 returns 1 if pockets are full, else 0
602 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
604 for (i
= 0; i
< limit
; i
++)
611 function to return 1 if a monster is next to the player else returns 0
617 for (tmp
= playerx
- 1; tmp
< playerx
+ 2; tmp
++)
618 for (tmp2
= playery
- 1; tmp2
< playery
+ 2; tmp2
++)
619 if (mitem
[tmp
][tmp2
])
620 return (1); /* if monster nearby */
625 function to steal an item from the players pockets
626 returns 1 if steals something else returns 0
638 if (c
[SHIELD
] != i
) {
641 adjustcvalues(iven
[i
], ivenarg
[i
]);
651 function to return 1 is player carrys nothing else return 0
657 for (i
= 0; i
< 26; i
++)
667 function to create a gem on a square near the player
691 createitem(i
, rnd(j
) + j
/ 10);
695 function to change character levels as needed when dropping an object
696 that affects these characteristics
699 adjustcvalues(int theitem
, int arg
)
705 c
[DEXTERITY
] -= arg
+ 1;
709 c
[STREXTRA
] -= arg
+ 1;
713 c
[INTELLIGENCE
] -= arg
+ 1;
719 c
[INTELLIGENCE
] += 10;
722 case OSWORDofSLASHING
:
753 function to ask user for a password (no echo)
754 returns 1 if entered correctly, 0 if not
756 static char gpwbuf
[33];
762 scbr(); /* system("stty -echo cbreak"); */
764 lprcat("\nEnter Password: ");
766 i
= strlen(password
);
767 for (j
= 0; j
< i
; j
++)
770 sncbr(); /* system("stty echo -cbreak"); */
771 if (strcmp(gpwbuf
, password
) != 0) {
780 subroutine to get a yes or no response from the user
788 while (i
!= 'y' && i
!= 'n' && i
!= '\33')
794 function to calculate the pack weight of the player
795 returns the number of pounds the player is carrying
803 while ((iven
[j
] == 0) && (j
> 0))
805 for (i
= 0; i
<= j
; i
++)
822 case OSWORDofSLASHING
:
850 k
+= 30 + ivenarg
[i
];
859 /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
864 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)) + 1);
871 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)));
873 #endif /* MACRORND */