]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/global.c
1 /* $NetBSD: global.c,v 1.6 1997/10/18 20:03:20 christos 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 * 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
21 * positionplayer() function to be sure player is not in a wall
22 * quit() subroutine to ask if the player really wants to quit
24 #include <sys/cdefs.h>
26 __RCSID("$NetBSD: global.c,v 1.6 1997/10/18 20:03:20 christos Exp $");
33 extern int score
[], srcount
, dropflag
;
34 extern int random
; /* the random number seed */
35 extern short playerx
, playery
, lastnum
, level
;
37 extern char monstnamelist
[], logname
[];
38 extern char lastmonst
[], *what
[], *who
[];
40 extern u_char monstlevel
[];
41 extern char sciv
[SCORESIZE
+ 1][26][2], *potionname
[], *scrollname
[];
48 subroutine to raise the player one level
49 uses the skill[] array to find level boundarys
50 uses c[EXPERIENCE] c[LEVEL]
55 if (c
[LEVEL
] < MAXPLEVEL
)
56 raiseexperience((long) (skill
[c
[LEVEL
]] - c
[EXPERIENCE
]));
65 subroutine to lower the players character level by one
71 loseexperience((long) (c
[EXPERIENCE
] - skill
[c
[LEVEL
] - 1] + 1));
80 subroutine to increase experience points
89 while (c
[EXPERIENCE
] >= skill
[c
[LEVEL
]] && (c
[LEVEL
] < MAXPLEVEL
)) {
90 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1;
92 raisemhp((int) (rnd(3) + rnd((tmp
> 0) ? tmp
: 1)));
93 raisemspells((int) rund(3));
94 if (c
[LEVEL
] < 7 - c
[HARDGAME
])
95 raisemhp((int) (c
[CONSTITUTION
] >> 2));
100 lprintf("\nWelcome to level %d", (long) c
[LEVEL
]); /* if we changed levels */
111 subroutine to lose experience points
120 if (c
[EXPERIENCE
] < 0)
122 while (c
[EXPERIENCE
] < skill
[c
[LEVEL
] - 1]) {
124 c
[LEVEL
] = 1; /* down one level */
125 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1; /* lose hpoints */
126 losemhp((int) rnd((tmp
> 0) ? tmp
: 1)); /* lose hpoints */
127 if (c
[LEVEL
] < 7 - c
[HARDGAME
])
128 losemhp((int) (c
[CONSTITUTION
] >> 2));
129 losemspells((int) rund(3)); /* lose spells */
134 lprintf("\nYou went down to level %d!", (long) c
[LEVEL
]);
146 subroutine to remove hit points from the player
147 warning -- will kill player if hp goes to zero
153 if ((c
[HP
] -= x
) <= 0) {
180 subroutine to gain maximum hit points
186 if ((c
[HP
] += x
) > c
[HPMAX
])
205 subroutine to gain maximum spells
211 if ((c
[SPELLS
] += x
) > c
[SPELLMAX
])
212 c
[SPELLS
] = c
[SPELLMAX
];
230 subroutine to lose maximum spells
236 if ((c
[SPELLS
] -= x
) < 0)
244 if ((c
[SPELLMAX
] -= x
) < 0)
246 if ((c
[SPELLS
] -= x
) < 0)
254 function to return monster number for a randomly selected monster
255 for the given cave level
268 while (tmp
== WATERLORD
)
269 tmp
= rnd((x
= monstlevel
[lev
- 1]) ? x
: 1);
271 while (tmp
== WATERLORD
)
272 tmp
= rnd((x
= monstlevel
[lev
- 1] - monstlevel
[lev
- 4]) ? x
: 1) + monstlevel
[lev
- 4];
274 while (monster
[tmp
].genocided
&& tmp
< MAXMONST
)
275 tmp
++; /* genocided? */
282 function to be sure player is not in a wall
289 while ((item
[playerx
][playery
] || mitem
[playerx
][playery
]) && (try))
290 if (++playerx
>= MAXX
- 1) {
292 if (++playery
>= MAXY
- 1) {
298 lprcat("Failure in positionplayer\n");
302 recalc() function to recalculate the armor class of the player
308 c
[AC
] = c
[MOREDEFENSES
];
310 switch (iven
[c
[WEAR
]]) {
312 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
315 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
318 c
[AC
] += 3 + ivenarg
[c
[WEAR
]];
321 c
[AC
] += 5 + ivenarg
[c
[WEAR
]];
324 c
[AC
] += 6 + ivenarg
[c
[WEAR
]];
327 c
[AC
] += 7 + ivenarg
[c
[WEAR
]];
330 c
[AC
] += 9 + ivenarg
[c
[WEAR
]];
333 c
[AC
] += 10 + ivenarg
[c
[WEAR
]];
336 c
[AC
] += 12 + ivenarg
[c
[WEAR
]];
341 if (iven
[c
[SHIELD
]] == OSHIELD
)
342 c
[AC
] += 2 + ivenarg
[c
[SHIELD
]];
346 i
= ivenarg
[c
[WIELD
]];
347 switch (iven
[c
[WIELD
]]) {
378 case OSWORDofSLASHING
:
388 c
[WCLASS
] += c
[MOREDAM
];
390 /* now for regeneration abilities based on rings */
394 for (k
= 25; k
> 0; k
--)
399 for (i
= 0; i
<= j
; i
++) {
402 c
[AC
] += ivenarg
[i
] + 1;
405 c
[WCLASS
] += ivenarg
[i
] + 1;
408 c
[WCLASS
] += ((ivenarg
[i
] << 1)) + 2;
412 c
[REGEN
] += ivenarg
[i
] + 1;
415 c
[REGEN
] += 5 * (ivenarg
[i
] + 1);
418 c
[ENERGY
] += ivenarg
[i
] + 1;
428 subroutine to ask if the player really wants to quit
435 strcpy(lastmonst
, "");
436 lprcat("\n\nDo you really want to quit?");
443 if ((i
== 'n') || (i
== '\33')) {
456 lprcat(" please? Do you want to quit? ");
461 function to ask --more-- then the user must enter a space
466 lprcat("\n --- press ");
468 lprcat(" to continue --- ");
469 while (getchar() != ' ');
473 function to put something in the players inventory
474 returns 0 if success, 1 if a failure
482 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
484 for (i
= 0; i
< limit
; i
++)
496 c
[DEXTERITY
] += ivenarg
[i
] + 1;
500 c
[STREXTRA
] += ivenarg
[i
] + 1;
504 c
[INTELLIGENCE
] += ivenarg
[i
] + 1;
510 c
[INTELLIGENCE
] -= 10;
526 case OSWORDofSLASHING
:
531 lprcat("\nYou pick up:");
538 lprcat("\nYou can't carry anything else");
543 subroutine to drop an object
544 returns 1 if something there already else 0
551 if ((k
< 0) || (k
> 25))
556 lprintf("\nYou don't have item %c! ", k
+ 'a');
559 if (item
[playerx
][playery
]) {
561 lprcat("\nThere's something here already");
564 if (playery
== MAXY
- 1 && playerx
== 33)
565 return (1); /* not in entrance */
566 item
[playerx
][playery
] = itm
;
567 iarg
[playerx
][playery
] = ivenarg
[k
];
569 lprcat("\n You drop:");
570 show3(k
); /* show what item you dropped */
571 know
[playerx
][playery
] = 0;
579 adjustcvalues(itm
, ivenarg
[k
]);
580 dropflag
= 1; /* say dropped an item so wont ask to pick it
586 function to enchant armor player is currently wearing
596 lprcat("\nYou feel a sense of loss");
599 tmp
= iven
[c
[SHIELD
]];
601 if (tmp
!= OPOTION
) {
602 ivenarg
[c
[SHIELD
]]++;
609 if (tmp
!= OPOTION
) {
616 function to enchant a weapon presently being wielded
625 lprcat("\nYou feel a sense of loss");
628 tmp
= iven
[c
[WIELD
]];
630 if (tmp
!= OPOTION
) {
632 if (tmp
== OCLEVERRING
)
634 else if (tmp
== OSTRRING
)
636 else if (tmp
== ODEXRING
)
643 routine to tell if player can carry one more thing
644 returns 1 if pockets are full, else 0
650 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
652 for (i
= 0; i
< limit
; i
++)
659 function to return 1 if a monster is next to the player else returns 0
665 for (tmp
= playerx
- 1; tmp
< playerx
+ 2; tmp
++)
666 for (tmp2
= playery
- 1; tmp2
< playery
+ 2; tmp2
++)
667 if (mitem
[tmp
][tmp2
])
668 return (1); /* if monster nearby */
673 function to steal an item from the players pockets
674 returns 1 if steals something else returns 0
686 if (c
[SHIELD
] != i
) {
689 adjustcvalues(iven
[i
], ivenarg
[i
]);
699 function to return 1 is player carrys nothing else return 0
705 for (i
= 0; i
< 26; i
++)
715 function to create a gem on a square near the player
739 createitem(i
, rnd(j
) + j
/ 10);
743 function to change character levels as needed when dropping an object
744 that affects these characteristics
747 adjustcvalues(itm
, arg
)
754 c
[DEXTERITY
] -= arg
+ 1;
758 c
[STREXTRA
] -= arg
+ 1;
762 c
[INTELLIGENCE
] -= arg
+ 1;
768 c
[INTELLIGENCE
] += 10;
771 case OSWORDofSLASHING
:
802 function to read a string from token input "string"
803 returns a pointer to the string
811 while ((getchar() != '"') && (--i
> 0));
814 if ((j
= getchar()) != '"')
822 /* if end due to too long, then find closing quote */
823 while ((getchar() != '"') && (--i
> 0));
827 function to ask user for a password (no echo)
828 returns 1 if entered correctly, 0 if not
830 static char gpwbuf
[33];
836 extern char *password
;
837 scbr(); /* system("stty -echo cbreak"); */
839 lprcat("\nEnter Password: ");
841 i
= strlen(password
);
842 for (j
= 0; j
< i
; j
++)
845 sncbr(); /* system("stty echo -cbreak"); */
846 if (strcmp(gpwbuf
, password
) != 0) {
855 subroutine to get a yes or no response from the user
863 while (i
!= 'y' && i
!= 'n' && i
!= '\33')
869 function to calculate the pack weight of the player
870 returns the number of pounds the player is carrying
878 while ((iven
[j
] == 0) && (j
> 0))
880 for (i
= 0; i
<= j
; i
++)
897 case OSWORDofSLASHING
:
925 k
+= 30 + ivenarg
[i
];
934 /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
939 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)) + 1);
946 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)));
948 #endif /* MACRORND */