]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/global.c
1 /* $NetBSD: global.c,v 1.14 2012/06/19 05:30:43 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.14 2012/06/19 05:30:43 dholland Exp $");
31 extern int score
[], dropflag
;
32 extern char *what
[], *who
[];
34 extern char sciv
[SCORESIZE
+ 1][26][2];
35 extern const 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
69 raiseexperience(long x
)
74 while (c
[EXPERIENCE
] >= skill
[c
[LEVEL
]] && (c
[LEVEL
] < MAXPLEVEL
)) {
75 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1;
77 raisemhp((int) (rnd(3) + rnd((tmp
> 0) ? tmp
: 1)));
78 raisemspells((int) rund(3));
79 if (c
[LEVEL
] < 7 - c
[HARDGAME
])
80 raisemhp((int) (c
[CONSTITUTION
] >> 2));
85 lprintf("\nWelcome to level %ld", (long) c
[LEVEL
]); /* if we changed levels */
93 subroutine to lose experience points
96 loseexperience(long x
)
101 if (c
[EXPERIENCE
] < 0)
103 while (c
[EXPERIENCE
] < skill
[c
[LEVEL
] - 1]) {
105 c
[LEVEL
] = 1; /* down one level */
106 tmp
= (c
[CONSTITUTION
] - c
[HARDGAME
]) >> 1; /* lose hpoints */
107 losemhp((int) rnd((tmp
> 0) ? tmp
: 1)); /* lose hpoints */
108 if (c
[LEVEL
] < 7 - c
[HARDGAME
])
109 losemhp((int) (c
[CONSTITUTION
] >> 2));
110 losemspells((int) rund(3)); /* lose spells */
115 lprintf("\nYou went down to level %ld!", (long) c
[LEVEL
]);
124 subroutine to remove hit points from the player
125 warning -- will kill player if hp goes to zero
130 if ((c
[HP
] -= x
) <= 0) {
153 subroutine to gain maximum hit points
158 if ((c
[HP
] += x
) > c
[HPMAX
])
172 subroutine to gain maximum spells
184 subroutine to lose maximum spells
189 if ((c
[SPELLMAX
] -= x
) < 0)
191 if ((c
[SPELLS
] -= x
) < 0)
199 function to return monster number for a randomly selected monster
200 for the given cave level
212 while (tmp
== WATERLORD
)
213 tmp
= rnd((x
= monstlevel
[lev
- 1]) ? x
: 1);
215 while (tmp
== WATERLORD
)
216 tmp
= rnd((x
= monstlevel
[lev
- 1] - monstlevel
[lev
- 4]) ? x
: 1) + monstlevel
[lev
- 4];
218 while (monster
[tmp
].genocided
&& tmp
< MAXMONST
)
219 tmp
++; /* genocided? */
226 function to be sure player is not in a wall
233 while ((item
[playerx
][playery
] || mitem
[playerx
][playery
]) && (try))
234 if (++playerx
>= MAXX
- 1) {
236 if (++playery
>= MAXY
- 1) {
242 lprcat("Failure in positionplayer\n");
246 recalc() function to recalculate the armor class of the player
252 c
[AC
] = c
[MOREDEFENSES
];
254 switch (iven
[c
[WEAR
]]) {
256 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
259 c
[AC
] += 2 + ivenarg
[c
[WEAR
]];
262 c
[AC
] += 3 + ivenarg
[c
[WEAR
]];
265 c
[AC
] += 5 + ivenarg
[c
[WEAR
]];
268 c
[AC
] += 6 + ivenarg
[c
[WEAR
]];
271 c
[AC
] += 7 + ivenarg
[c
[WEAR
]];
274 c
[AC
] += 9 + ivenarg
[c
[WEAR
]];
277 c
[AC
] += 10 + ivenarg
[c
[WEAR
]];
280 c
[AC
] += 12 + ivenarg
[c
[WEAR
]];
285 if (iven
[c
[SHIELD
]] == OSHIELD
)
286 c
[AC
] += 2 + ivenarg
[c
[SHIELD
]];
290 i
= ivenarg
[c
[WIELD
]];
291 switch (iven
[c
[WIELD
]]) {
322 case OSWORDofSLASHING
:
332 c
[WCLASS
] += c
[MOREDAM
];
334 /* now for regeneration abilities based on rings */
338 for (k
= 25; k
> 0; k
--)
343 for (i
= 0; i
<= j
; i
++) {
346 c
[AC
] += ivenarg
[i
] + 1;
349 c
[WCLASS
] += ivenarg
[i
] + 1;
352 c
[WCLASS
] += ((ivenarg
[i
] << 1)) + 2;
356 c
[REGEN
] += ivenarg
[i
] + 1;
359 c
[REGEN
] += 5 * (ivenarg
[i
] + 1);
362 c
[ENERGY
] += ivenarg
[i
] + 1;
372 subroutine to ask if the player really wants to quit
379 strcpy(lastmonst
, "");
380 lprcat("\n\nDo you really want to quit?");
387 if ((i
== 'n') || (i
== '\33')) {
400 lprcat(" please? Do you want to quit? ");
405 function to ask --more-- then the user must enter a space
410 lprcat("\n --- press ");
412 lprcat(" to continue --- ");
413 while (ttgetch() != ' ');
417 function to put something in the players inventory
418 returns 0 if success, 1 if a failure
421 take(int theitem
, int arg
)
425 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
427 for (i
= 0; i
< limit
; i
++)
439 c
[DEXTERITY
] += ivenarg
[i
] + 1;
443 c
[STREXTRA
] += ivenarg
[i
] + 1;
447 c
[INTELLIGENCE
] += ivenarg
[i
] + 1;
453 c
[INTELLIGENCE
] -= 10;
469 case OSWORDofSLASHING
:
474 lprcat("\nYou pick up:");
481 lprcat("\nYou can't carry anything else");
486 subroutine to drop an object
487 returns 1 if something there already else 0
493 if ((k
< 0) || (k
> 25))
498 lprintf("\nYou don't have item %c! ", k
+ 'a');
501 if (item
[playerx
][playery
]) {
503 lprcat("\nThere's something here already");
506 if (playery
== MAXY
- 1 && playerx
== 33)
507 return (1); /* not in entrance */
508 item
[playerx
][playery
] = theitem
;
509 iarg
[playerx
][playery
] = ivenarg
[k
];
511 lprcat("\n You drop:");
512 show3(k
); /* show what item you dropped */
513 know
[playerx
][playery
] = 0;
521 adjustcvalues(theitem
, ivenarg
[k
]);
522 dropflag
= 1; /* say dropped an item so wont ask to pick it
528 function to enchant armor player is currently wearing
538 lprcat("\nYou feel a sense of loss");
541 tmp
= iven
[c
[SHIELD
]];
543 if (tmp
!= OPOTION
) {
544 ivenarg
[c
[SHIELD
]]++;
551 if (tmp
!= OPOTION
) {
558 function to enchant a weapon presently being wielded
567 lprcat("\nYou feel a sense of loss");
570 tmp
= iven
[c
[WIELD
]];
572 if (tmp
!= OPOTION
) {
574 if (tmp
== OCLEVERRING
)
576 else if (tmp
== OSTRRING
)
578 else if (tmp
== ODEXRING
)
585 routine to tell if player can carry one more thing
586 returns 1 if pockets are full, else 0
592 if ((limit
= 15 + (c
[LEVEL
] >> 1)) > 26)
594 for (i
= 0; i
< limit
; i
++)
601 function to return 1 if a monster is next to the player else returns 0
607 for (tmp
= playerx
- 1; tmp
< playerx
+ 2; tmp
++)
608 for (tmp2
= playery
- 1; tmp2
< playery
+ 2; tmp2
++)
609 if (mitem
[tmp
][tmp2
])
610 return (1); /* if monster nearby */
615 function to steal an item from the players pockets
616 returns 1 if steals something else returns 0
628 if (c
[SHIELD
] != i
) {
631 adjustcvalues(iven
[i
], ivenarg
[i
]);
641 function to return 1 is player carrys nothing else return 0
647 for (i
= 0; i
< 26; i
++)
657 function to create a gem on a square near the player
681 createitem(i
, rnd(j
) + j
/ 10);
685 function to change character levels as needed when dropping an object
686 that affects these characteristics
689 adjustcvalues(int theitem
, int arg
)
695 c
[DEXTERITY
] -= arg
+ 1;
699 c
[STREXTRA
] -= arg
+ 1;
703 c
[INTELLIGENCE
] -= arg
+ 1;
709 c
[INTELLIGENCE
] += 10;
712 case OSWORDofSLASHING
:
743 function to ask user for a password (no echo)
744 returns 1 if entered correctly, 0 if not
746 static char gpwbuf
[33];
752 scbr(); /* system("stty -echo cbreak"); */
754 lprcat("\nEnter Password: ");
756 i
= strlen(password
);
757 for (j
= 0; j
< i
; j
++)
760 sncbr(); /* system("stty echo -cbreak"); */
761 if (strcmp(gpwbuf
, password
) != 0) {
770 subroutine to get a yes or no response from the user
778 while (i
!= 'y' && i
!= 'n' && i
!= '\33')
784 function to calculate the pack weight of the player
785 returns the number of pounds the player is carrying
793 while ((iven
[j
] == 0) && (j
> 0))
795 for (i
= 0; i
<= j
; i
++)
812 case OSWORDofSLASHING
:
840 k
+= 30 + ivenarg
[i
];
849 /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
853 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)) + 1);
859 return ((((randx
= randx
* 1103515245 + 12345) >> 7) % (x
)));
861 #endif /* MACRORND */