]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/global.c
1 /* $NetBSD: global.c,v 1.8 2008/01/28 03:39:31 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 * 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.8 2008/01/28 03:39:31 dholland Exp $");
33 extern int score
[], dropflag
;
34 extern int random
; /* the random number seed */
35 extern char *what
[], *who
[];
37 extern char sciv
[SCORESIZE
+ 1][26][2];
38 extern char *password
;
46 subroutine to raise the player one level
47 uses the skill[] array to find level boundarys
48 uses c[EXPERIENCE] c[LEVEL]
53 if (c
[LEVEL
] < MAXPLEVEL
)
54 raiseexperience((long) (skill
[c
[LEVEL
]] - c
[EXPERIENCE
]));
63 subroutine to lower the players character level by one
69 loseexperience((long) (c
[EXPERIENCE
] - skill
[c
[LEVEL
] - 1] + 1));
78 subroutine to increase experience points
87 while (c
[EXPERIENCE
] >= skill
[c
[LEVEL
]] && (c
[LEVEL
] < MAXPLEVEL
)) {
88 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1;
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));
98 lprintf("\nWelcome to level %ld", (long) c
[LEVEL
]); /* if we changed levels */
109 subroutine to lose experience points
118 if (c
[EXPERIENCE
] < 0)
120 while (c
[EXPERIENCE
] < skill
[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 */
132 lprintf("\nYou went down to level %ld!", (long) c
[LEVEL
]);
144 subroutine to remove hit points from the player
145 warning -- will kill player if hp goes to zero
151 if ((c
[HP
] -= x
) <= 0) {
178 subroutine to gain maximum hit points
184 if ((c
[HP
] += x
) > c
[HPMAX
])
203 subroutine to gain maximum spells
209 if ((c
[SPELLS
] += x
) > c
[SPELLMAX
])
210 c
[SPELLS
] = c
[SPELLMAX
];
228 subroutine to lose maximum spells
234 if ((c
[SPELLS
] -= x
) < 0)
242 if ((c
[SPELLMAX
] -= x
) < 0)
244 if ((c
[SPELLS
] -= x
) < 0)
252 function to return monster number for a randomly selected monster
253 for the given cave level
266 while (tmp
== WATERLORD
)
267 tmp
= rnd((x
= monstlevel
[lev
- 1]) ? x
: 1);
269 while (tmp
== WATERLORD
)
270 tmp
= rnd((x
= monstlevel
[lev
- 1] - monstlevel
[lev
- 4]) ? x
: 1) + monstlevel
[lev
- 4];
272 while (monster
[tmp
].genocided
&& tmp
< MAXMONST
)
273 tmp
++; /* genocided? */
280 function to be sure player is not in a wall
287 while ((item
[playerx
][playery
] || mitem
[playerx
][playery
]) && (try))
288 if (++playerx
>= MAXX
- 1) {
290 if (++playery
>= MAXY
- 1) {
296 lprcat("Failure in positionplayer\n");
300 recalc() function to recalculate the armor class of the player
306 c
[AC
] = c
[MOREDEFENSES
];
308 switch (iven
[c
[WEAR
]]) {
310 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
313 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
316 c
[AC
] += 3 + ivenarg
[c
[WEAR
]];
319 c
[AC
] += 5 + ivenarg
[c
[WEAR
]];
322 c
[AC
] += 6 + ivenarg
[c
[WEAR
]];
325 c
[AC
] += 7 + ivenarg
[c
[WEAR
]];
328 c
[AC
] += 9 + ivenarg
[c
[WEAR
]];
331 c
[AC
] += 10 + ivenarg
[c
[WEAR
]];
334 c
[AC
] += 12 + ivenarg
[c
[WEAR
]];
339 if (iven
[c
[SHIELD
]] == OSHIELD
)
340 c
[AC
] += 2 + ivenarg
[c
[SHIELD
]];
344 i
= ivenarg
[c
[WIELD
]];
345 switch (iven
[c
[WIELD
]]) {
376 case OSWORDofSLASHING
:
386 c
[WCLASS
] += c
[MOREDAM
];
388 /* now for regeneration abilities based on rings */
392 for (k
= 25; k
> 0; k
--)
397 for (i
= 0; i
<= j
; i
++) {
400 c
[AC
] += ivenarg
[i
] + 1;
403 c
[WCLASS
] += ivenarg
[i
] + 1;
406 c
[WCLASS
] += ((ivenarg
[i
] << 1)) + 2;
410 c
[REGEN
] += ivenarg
[i
] + 1;
413 c
[REGEN
] += 5 * (ivenarg
[i
] + 1);
416 c
[ENERGY
] += ivenarg
[i
] + 1;
426 subroutine to ask if the player really wants to quit
433 strcpy(lastmonst
, "");
434 lprcat("\n\nDo you really want to quit?");
441 if ((i
== 'n') || (i
== '\33')) {
454 lprcat(" please? Do you want to quit? ");
459 function to ask --more-- then the user must enter a space
464 lprcat("\n --- press ");
466 lprcat(" to continue --- ");
467 while (lgetchar() != ' ');
471 function to put something in the players inventory
472 returns 0 if success, 1 if a failure
480 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
482 for (i
= 0; i
< limit
; i
++)
494 c
[DEXTERITY
] += ivenarg
[i
] + 1;
498 c
[STREXTRA
] += ivenarg
[i
] + 1;
502 c
[INTELLIGENCE
] += ivenarg
[i
] + 1;
508 c
[INTELLIGENCE
] -= 10;
524 case OSWORDofSLASHING
:
529 lprcat("\nYou pick up:");
536 lprcat("\nYou can't carry anything else");
541 subroutine to drop an object
542 returns 1 if something there already else 0
549 if ((k
< 0) || (k
> 25))
554 lprintf("\nYou don't have item %c! ", k
+ 'a');
557 if (item
[playerx
][playery
]) {
559 lprcat("\nThere's something here already");
562 if (playery
== MAXY
- 1 && playerx
== 33)
563 return (1); /* not in entrance */
564 item
[playerx
][playery
] = itm
;
565 iarg
[playerx
][playery
] = ivenarg
[k
];
567 lprcat("\n You drop:");
568 show3(k
); /* show what item you dropped */
569 know
[playerx
][playery
] = 0;
577 adjustcvalues(itm
, ivenarg
[k
]);
578 dropflag
= 1; /* say dropped an item so wont ask to pick it
584 function to enchant armor player is currently wearing
594 lprcat("\nYou feel a sense of loss");
597 tmp
= iven
[c
[SHIELD
]];
599 if (tmp
!= OPOTION
) {
600 ivenarg
[c
[SHIELD
]]++;
607 if (tmp
!= OPOTION
) {
614 function to enchant a weapon presently being wielded
623 lprcat("\nYou feel a sense of loss");
626 tmp
= iven
[c
[WIELD
]];
628 if (tmp
!= OPOTION
) {
630 if (tmp
== OCLEVERRING
)
632 else if (tmp
== OSTRRING
)
634 else if (tmp
== ODEXRING
)
641 routine to tell if player can carry one more thing
642 returns 1 if pockets are full, else 0
648 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
650 for (i
= 0; i
< limit
; i
++)
657 function to return 1 if a monster is next to the player else returns 0
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 */
671 function to steal an item from the players pockets
672 returns 1 if steals something else returns 0
684 if (c
[SHIELD
] != i
) {
687 adjustcvalues(iven
[i
], ivenarg
[i
]);
697 function to return 1 is player carrys nothing else return 0
703 for (i
= 0; i
< 26; i
++)
713 function to create a gem on a square near the player
737 createitem(i
, rnd(j
) + j
/ 10);
741 function to change character levels as needed when dropping an object
742 that affects these characteristics
745 adjustcvalues(itm
, arg
)
752 c
[DEXTERITY
] -= arg
+ 1;
756 c
[STREXTRA
] -= arg
+ 1;
760 c
[INTELLIGENCE
] -= arg
+ 1;
766 c
[INTELLIGENCE
] += 10;
769 case OSWORDofSLASHING
:
800 function to read a string from token input "string"
801 returns a pointer to the string
809 while ((lgetchar() != '"') && (--i
> 0));
812 if ((j
= lgetchar()) != '"')
820 /* if end due to too long, then find closing quote */
821 while ((lgetchar() != '"') && (--i
> 0));
825 function to ask user for a password (no echo)
826 returns 1 if entered correctly, 0 if not
828 static char gpwbuf
[33];
834 scbr(); /* system("stty -echo cbreak"); */
836 lprcat("\nEnter Password: ");
838 i
= strlen(password
);
839 for (j
= 0; j
< i
; j
++)
842 sncbr(); /* system("stty echo -cbreak"); */
843 if (strcmp(gpwbuf
, password
) != 0) {
852 subroutine to get a yes or no response from the user
860 while (i
!= 'y' && i
!= 'n' && i
!= '\33')
866 function to calculate the pack weight of the player
867 returns the number of pounds the player is carrying
875 while ((iven
[j
] == 0) && (j
> 0))
877 for (i
= 0; i
<= j
; i
++)
894 case OSWORDofSLASHING
:
922 k
+= 30 + ivenarg
[i
];
931 /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
936 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)) + 1);
943 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)));
945 #endif /* MACRORND */