]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/misc.c
1 /* $NetBSD: misc.c,v 1.15 2008/01/28 06:20:15 dholland Exp $ */
4 * misc.c Phantasia miscellaneous support routines
15 const struct charstats
*statptr
; /* for pointing into Stattable */
16 double new; /* new level */
17 double inc
; /* increment between new and old levels */
21 if (Player
.p_type
== C_EXPER
)
22 /* roll a type to use for increment */
23 statptr
= &Stattable
[(int) ROLL(C_MAGIC
, C_HALFLING
- C_MAGIC
+ 1)];
27 new = explevel(Player
.p_experience
);
28 inc
= new - Player
.p_level
;
31 /* add increments to statistics */
32 Player
.p_strength
+= statptr
->c_strength
.increase
* inc
;
33 Player
.p_mana
+= statptr
->c_mana
.increase
* inc
;
34 Player
.p_brains
+= statptr
->c_brains
.increase
* inc
;
35 Player
.p_magiclvl
+= statptr
->c_magiclvl
.increase
* inc
;
36 Player
.p_maxenergy
+= statptr
->c_energy
.increase
* inc
;
38 /* rest to maximum upon reaching new level */
39 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
41 if (Player
.p_crowns
> 0 && Player
.p_level
>= 1000.0)
42 /* no longer able to be king -- turn crowns into cash */
44 Player
.p_gold
+= ((double) Player
.p_crowns
) * 5000.0;
47 if (Player
.p_level
>= 3000.0 && Player
.p_specialtype
< SC_COUNCIL
)
48 /* make a member of the council */
50 mvaddstr(6, 0, "You have made it to the Council of the Wise.\n");
51 addstr("Good Luck on your search for the Holy Grail.\n");
53 Player
.p_specialtype
= SC_COUNCIL
;
55 /* no rings for council and above */
56 Player
.p_ring
.ring_type
= R_NONE
;
57 Player
.p_ring
.ring_duration
= 0;
59 Player
.p_lives
= 3; /* three extra lives */
61 if (Player
.p_level
> 9999.0 && Player
.p_specialtype
!= SC_VALAR
)
66 descrlocation(playerp
, shortflag
)
67 struct player
*playerp
;
70 double circle
; /* corresponding circle for coordinates */
71 int quadrant
; /* quandrant of grid */
72 const char *label
; /* pointer to place name */
73 static const char *const nametable
[4][4] = /* names of places */
75 {"Anorien", "Ithilien", "Rohan", "Lorien"},
76 {"Gondor", "Mordor", "Dunland", "Rovanion"},
77 {"South Gondor", "Khand", "Eriador", "The Iron Hills"},
78 {"Far Harad", "Near Harad", "The Northern Waste", "Rhun"}
81 if (playerp
->p_specialtype
== SC_VALAR
)
82 return (" is in Valhala");
84 if ((circle
= CIRCLE(playerp
->p_x
, playerp
->p_y
)) >= 1000.0) {
85 if (MAX(fabs(playerp
->p_x
), fabs(playerp
->p_y
)) > D_BEYOND
)
86 label
= "The Point of No Return";
88 label
= "The Ashen Mountains";
94 label
= "Kennaquahair";
97 label
= "The Dead Marshes";
100 label
= "The Outer Waste";
103 label
= "The Moors Adventurous";
105 if (playerp
->p_x
== 0.0 && playerp
->p_y
== 0.0)
106 label
= "The Lord's Chamber";
131 quadrant
= ((playerp
->p_x
> 0.0) ? 1 : 0);
132 quadrant
+= ((playerp
->p_y
>= 0.0) ? 2 : 0);
133 label
= nametable
[((int) circle
) - 1][quadrant
];
138 sprintf(Databuf
, "%.29s", label
);
140 sprintf(Databuf
, " is in %s (%.0f,%.0f)", label
, playerp
->p_x
, playerp
->p_y
);
148 double numitems
; /* number of items to purchase */
149 double cost
; /* cost of purchase */
150 double blessingcost
; /* cost of blessing */
152 int size
; /* size of the trading post */
153 int loop
; /* loop counter */
154 int cheat
= 0; /* number of times player has tried to cheat */
155 bool dishonest
= FALSE
; /* set when merchant is dishonest */
157 Player
.p_status
= S_TRADING
;
158 writerecord(&Player
, Fileloc
);
161 addstr("You are at a trading post. All purchases must be made with gold.");
163 size
= sqrt(fabs(Player
.p_x
/ 100)) + 1;
166 /* set up cost of blessing */
167 blessingcost
= 1000.0 * (Player
.p_level
+ 5.0);
171 for (loop
= 0; loop
< size
; ++loop
)
177 cost
= Menu
[loop
].cost
;
178 printw("(%d) %-12s: %6.0f\n", loop
+ 1, Menu
[loop
].item
, cost
);
181 mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? ");
184 adjuststats(); /* truncate any bad values */
186 /* print some important statistics */
187 mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n",
188 Player
.p_gold
, Player
.p_gems
, Player
.p_level
, Player
.p_charms
);
189 printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n",
190 Player
.p_shield
, Player
.p_sword
, Player
.p_quksilver
,
191 (Player
.p_blessing
? " True" : "False"));
192 printw("Brains: %9.0f Mana: %9.0f", Player
.p_brains
, Player
.p_mana
);
195 ch
= getanswer("LPS", FALSE
);
199 case 'L': /* leave */
201 altercoordinates(0.0, 0.0, A_NEAR
);
204 case 'P': /* make purchase */
205 mvaddstr(15, 0, "What what would you like to buy ? ");
206 ch
= getanswer(" 1234567", FALSE
);
211 addstr("Sorry, this merchant doesn't have that.");
215 printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ",
216 Menu
[0].cost
, floor(Player
.p_gold
/ Menu
[0].cost
));
217 cost
= (numitems
= floor(infloat())) * Menu
[0].cost
;
219 if (cost
> Player
.p_gold
|| numitems
< 0)
223 Player
.p_gold
-= cost
;
224 if (drandom() < 0.02)
227 Player
.p_mana
+= numitems
;
232 printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ",
233 Menu
[1].cost
, floor(Player
.p_gold
/ Menu
[1].cost
));
234 cost
= (numitems
= floor(infloat())) * Menu
[1].cost
;
239 if (cost
> Player
.p_gold
|| numitems
< 0)
242 if (numitems
< Player
.p_shield
)
246 Player
.p_gold
-= cost
;
247 if (drandom() < 0.02)
250 Player
.p_shield
= numitems
;
255 printw("A book costs %.0f gp. How many do you want (%.0f max) ? ",
256 Menu
[2].cost
, floor(Player
.p_gold
/ Menu
[2].cost
));
257 cost
= (numitems
= floor(infloat())) * Menu
[2].cost
;
259 if (cost
> Player
.p_gold
|| numitems
< 0)
263 Player
.p_gold
-= cost
;
264 if (drandom() < 0.02)
267 if (drandom() * numitems
> Player
.p_level
/ 10.0
269 printw("\nYou blew your mind!\n");
270 Player
.p_brains
/= 5;
272 Player
.p_brains
+= floor(numitems
) * ROLL(20, 8);
278 printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ",
279 Menu
[3].cost
, floor(Player
.p_gold
/ Menu
[3].cost
));
280 cost
= (numitems
= floor(infloat())) * Menu
[3].cost
;
285 if (cost
> Player
.p_gold
|| numitems
< 0)
288 if (numitems
< Player
.p_sword
)
292 Player
.p_gold
-= cost
;
293 if (drandom() < 0.02)
296 Player
.p_sword
= numitems
;
301 printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ",
302 Menu
[4].cost
, floor(Player
.p_gold
/ Menu
[4].cost
));
303 cost
= (numitems
= floor(infloat())) * Menu
[4].cost
;
305 if (cost
> Player
.p_gold
|| numitems
< 0)
309 Player
.p_gold
-= cost
;
310 if (drandom() < 0.02)
313 Player
.p_charms
+= numitems
;
318 printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ",
319 Menu
[5].cost
, floor(Player
.p_gold
/ Menu
[5].cost
));
320 cost
= (numitems
= floor(infloat())) * Menu
[5].cost
;
325 if (cost
> Player
.p_gold
|| numitems
< 0)
328 if (numitems
< Player
.p_quksilver
)
332 Player
.p_gold
-= cost
;
333 if (drandom() < 0.02)
336 Player
.p_quksilver
= numitems
;
341 if (Player
.p_blessing
) {
342 addstr("You already have a blessing.");
345 printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost
);
346 ch
= getanswer("NY", FALSE
);
349 if (Player
.p_gold
< blessingcost
)
353 Player
.p_gold
-= blessingcost
;
354 if (drandom() < 0.02)
357 Player
.p_blessing
= TRUE
;
364 case 'S': /* sell gems */
365 mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ",
366 (double) N_GEMVALUE
, Player
.p_gems
);
367 numitems
= floor(infloat());
369 if (numitems
> Player
.p_gems
|| numitems
< 0)
373 Player
.p_gems
-= numitems
;
374 Player
.p_gold
+= numitems
* N_GEMVALUE
;
379 mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n");
382 mvaddstr(17, 0, "You had your chance. This merchant happens to be\n");
383 printw("a %.0f level magic user, and you made %s mad!\n",
384 ROLL(Circle
* 20.0, 40.0), (drandom() < 0.5) ? "him" : "her");
385 altercoordinates(0.0, 0.0, A_FAR
);
386 Player
.p_energy
/= 2.0;
392 mvaddstr(17, 0, "The merchant stole your money!");
394 altercoordinates(Player
.p_x
- Player
.p_x
/ 10.0,
395 Player
.p_y
- Player
.p_y
/ 10.0, A_SPECIFIC
);
405 mvprintw(0, 0, "%s%s\n", Player
.p_name
, descrlocation(&Player
, FALSE
));
406 mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n",
407 Player
.p_level
, Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
,
408 Player
.p_mana
, Users
);
409 mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n",
410 Player
.p_speed
, Player
.p_quickness
+ Player
.p_quksilver
, Player
.p_might
,
411 Player
.p_strength
+ Player
.p_sword
, Player
.p_gold
, descrstatus(&Player
));
417 static const char *const flags
[] = /* to print value of some bools */
423 mvprintw(8, 0, "Type: %s\n", descrtype(&Player
, FALSE
));
425 mvprintw(10, 0, "Experience: %9.0f", Player
.p_experience
);
426 mvprintw(11, 0, "Brains : %9.0f", Player
.p_brains
);
427 mvprintw(12, 0, "Magic Lvl : %9.0f", Player
.p_magiclvl
);
428 mvprintw(13, 0, "Sin : %9.5f", Player
.p_sin
);
429 mvprintw(14, 0, "Poison : %9.5f", Player
.p_poison
);
430 mvprintw(15, 0, "Gems : %9.0f", Player
.p_gems
);
431 mvprintw(16, 0, "Age : %9ld", Player
.p_age
);
432 mvprintw(10, 40, "Holy Water: %9d", Player
.p_holywater
);
433 mvprintw(11, 40, "Amulets : %9d", Player
.p_amulets
);
434 mvprintw(12, 40, "Charms : %9d", Player
.p_charms
);
435 mvprintw(13, 40, "Crowns : %9d", Player
.p_crowns
);
436 mvprintw(14, 40, "Shield : %9.0f", Player
.p_shield
);
437 mvprintw(15, 40, "Sword : %9.0f", Player
.p_sword
);
438 mvprintw(16, 40, "Quickslver: %9.0f", Player
.p_quksilver
);
440 mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s",
441 flags
[(int)Player
.p_blessing
],
442 flags
[Player
.p_ring
.ring_type
!= R_NONE
],
443 flags
[(int)Player
.p_virgin
],
444 flags
[(int)Player
.p_palantir
]);
448 descrtype(playerp
, shortflag
)
449 struct player
*playerp
;
452 int type
; /* for caluculating result subscript */
453 static const char *const results
[] =/* description table */
455 " Magic User", " MU",
460 " Experimento", " EX",
463 " Council of Wise", " CW",
469 type
= playerp
->p_type
;
471 switch (playerp
->p_specialtype
) {
473 type
= playerp
->p_type
;
493 type
*= 2; /* calculate offset */
500 /* use short descriptions */
503 if (playerp
->p_crowns
> 0) {
504 strcpy(Databuf
, results
[type
]);
508 return (results
[type
]);
512 findname(name
, playerp
)
514 struct player
*playerp
;
516 long loc
= 0; /* location in the file */
518 fseek(Playersfp
, 0L, SEEK_SET
);
519 while (fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
520 if (strcmp(playerp
->p_name
, name
) == 0) {
521 if (playerp
->p_status
!= S_NOTUSED
|| Wizard
)
525 loc
+= SZ_PLAYERSTRUCT
;
534 long loc
= 0L; /* location in file */
536 fseek(Playersfp
, 0L, SEEK_SET
);
537 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
538 if (Other
.p_status
== S_NOTUSED
)
539 /* found an empty record */
542 loc
+= SZ_PLAYERSTRUCT
;
545 /* make a new record */
547 Player
.p_status
= S_OFF
;
548 writerecord(&Other
, loc
);
554 freerecord(playerp
, loc
)
555 struct player
*playerp
;
558 playerp
->p_name
[0] = CH_MARKDELETE
;
559 playerp
->p_status
= S_NOTUSED
;
560 writerecord(playerp
, loc
);
567 if (Player
.p_level
< 1.0)
568 /* delete character */
569 freerecord(&Player
, Fileloc
);
571 Player
.p_status
= S_OFF
;
572 writerecord(&Player
, Fileloc
);
583 FILE *fp
; /* for updating various files */
585 static const char *const deathmesg
[] =
586 /* add more messages here, if desired */
588 "You have been wounded beyond repair. ",
589 "You have been disemboweled. ",
590 "You've been mashed, mauled, and spit upon. (You're dead.)\n",
592 "You're a complete failure -- you've died!!\n",
593 "You have been dealt a fatal blow! "
598 if (strcmp(how
, "Stupidity") != 0) {
599 if (Player
.p_level
> 9999.0)
601 addstr("Characters must be retired upon reaching level 10000. Sorry.");
603 if (Player
.p_lives
> 0)
606 addstr("You should be more cautious. You've been killed.\n");
607 printw("You only have %d more chance(s).\n", --Player
.p_lives
);
609 Player
.p_energy
= Player
.p_maxenergy
;
612 if (Player
.p_specialtype
== SC_VALAR
) {
613 addstr("You had your chances, but Valar aren't totally\n");
614 addstr("immortal. You are now left to wither and die . . .\n");
616 Player
.p_brains
= Player
.p_level
/ 25.0;
617 Player
.p_energy
= Player
.p_maxenergy
/= 5.0;
618 Player
.p_quksilver
= Player
.p_sword
= 0.0;
619 Player
.p_specialtype
= SC_COUNCIL
;
622 if (Player
.p_ring
.ring_inuse
&&
623 (Player
.p_ring
.ring_type
== R_DLREG
|| Player
.p_ring
.ring_type
== R_NAZREG
))
624 /* good ring in use - saved
627 mvaddstr(4, 0, "Your ring saved you from death!\n");
629 Player
.p_ring
.ring_type
= R_NONE
;
630 Player
.p_energy
= Player
.p_maxenergy
/ 12.0 + 1.0;
631 if (Player
.p_crowns
> 0)
635 if (Player
.p_ring
.ring_type
== R_BAD
636 || Player
.p_ring
.ring_type
== R_SPOILED
)
639 * idiot after player */
642 "Your ring has taken control of you and turned you into a monster!\n");
643 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, SEEK_SET
);
644 fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
645 strcpy(Curmonster
.m_name
, Player
.p_name
);
646 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, SEEK_SET
);
647 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
651 enterscore(); /* update score board */
653 /* put info in last dead file */
654 fp
= fopen(_PATH_LASTDEAD
, "w");
655 fprintf(fp
, "%s (%s, run by %s, level %.0f, killed by %s)",
656 Player
.p_name
, descrtype(&Player
, TRUE
),
657 Player
.p_login
, Player
.p_level
, how
);
660 /* let other players know */
661 fp
= fopen(_PATH_MESS
, "w");
662 fprintf(fp
, "%s was killed by %s.", Player
.p_name
, how
);
665 freerecord(&Player
, Fileloc
);
669 addstr(deathmesg
[(int) ROLL(0.0, (double) sizeof(deathmesg
) / sizeof(char *))]);
670 addstr("Care to give it another try ? ");
671 ch
= getanswer("NY", FALSE
);
675 execl(_PATH_GAMEPROG
, "phantasia", "-s",
676 (Wizard
? "-S" : (char *) NULL
), (char *) NULL
);
685 writerecord(playerp
, place
)
686 struct player
*playerp
;
689 fseek(Playersfp
, place
, SEEK_SET
);
690 fwrite((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
698 if (experience
< 1.1e7
)
699 return (floor(pow((experience
/ 1000.0), 0.4875)));
701 return (floor(pow((experience
/ 1250.0), 0.4865)));
708 int length
; /* length of string */
710 length
= strlen(string
);
711 while (string
[--length
] == ' ')
712 string
[length
] = '\0';
716 altercoordinates(xnew
, ynew
, operation
)
722 case A_FORCED
: /* move with no checks */
725 case A_NEAR
: /* pick random coordinates near */
726 xnew
= Player
.p_x
+ ROLL(1.0, 5.0);
727 ynew
= Player
.p_y
- ROLL(1.0, 5.0);
728 /* fall through for check */
730 case A_SPECIFIC
: /* just move player */
731 if (Beyond
&& fabs(xnew
) < D_BEYOND
&& fabs(ynew
) < D_BEYOND
)
733 * cannot move back from point of no return
734 * pick the largest coordinate to remain unchanged
737 if (fabs(xnew
) > fabs(ynew
))
738 xnew
= SGN(Player
.p_x
) * MAX(fabs(Player
.p_x
), D_BEYOND
);
740 ynew
= SGN(Player
.p_y
) * MAX(fabs(Player
.p_y
), D_BEYOND
);
744 case A_FAR
: /* pick random coordinates far */
745 xnew
= Player
.p_x
+ SGN(Player
.p_x
) * ROLL(50 * Circle
, 250 * Circle
);
746 ynew
= Player
.p_y
+ SGN(Player
.p_y
) * ROLL(50 * Circle
, 250 * Circle
);
750 /* now set location flags and adjust coordinates */
751 Circle
= CIRCLE(Player
.p_x
= floor(xnew
), Player
.p_y
= floor(ynew
));
753 /* set up flags based upon location */
754 Throne
= Marsh
= Beyond
= FALSE
;
756 if (Player
.p_x
== 0.0 && Player
.p_y
== 0.0)
759 if (Circle
< 35 && Circle
>= 20)
762 if (MAX(fabs(Player
.p_x
), fabs(Player
.p_y
)) >= D_BEYOND
)
769 readrecord(playerp
, loc
)
770 struct player
*playerp
;
773 fseek(Playersfp
, loc
, SEEK_SET
);
774 fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
780 double dtemp
; /* for temporary calculations */
782 if (explevel(Player
.p_experience
) > Player
.p_level
)
783 /* move one or more levels */
786 if (Player
.p_level
> 5.0)
789 if (Player
.p_specialtype
== SC_VALAR
)
791 Circle
= Player
.p_level
/ 5.0;
793 /* calculate effective quickness */
794 dtemp
= ((Player
.p_gold
+ Player
.p_gems
/ 2.0) - 1000.0) / Statptr
->c_goldtote
796 dtemp
= MAX(0.0, dtemp
);/* gold slows player down */
797 Player
.p_speed
= Player
.p_quickness
+ Player
.p_quksilver
- dtemp
;
799 /* calculate effective strength */
800 if (Player
.p_poison
> 0.0)
801 /* poison makes player weaker */
803 dtemp
= 1.0 - Player
.p_poison
* Statptr
->c_weakness
/ 800.0;
804 dtemp
= MAX(0.1, dtemp
);
807 Player
.p_might
= dtemp
* Player
.p_strength
+ Player
.p_sword
;
809 /* insure that important things are within limits */
810 Player
.p_quksilver
= MIN(99.0, Player
.p_quksilver
);
811 Player
.p_mana
= MIN(Player
.p_mana
,
812 Player
.p_level
* Statptr
->c_maxmana
+ 1000.0);
813 Player
.p_brains
= MIN(Player
.p_brains
,
814 Player
.p_level
* Statptr
->c_maxbrains
+ 200.0);
815 Player
.p_charms
= MIN(Player
.p_charms
, Player
.p_level
+ 10.0);
818 * some implementations have problems with floating point compare
819 * we work around it with this stuff
821 Player
.p_gold
= floor(Player
.p_gold
) + 0.1;
822 Player
.p_gems
= floor(Player
.p_gems
) + 0.1;
823 Player
.p_mana
= floor(Player
.p_mana
) + 0.1;
825 if (Player
.p_ring
.ring_type
!= R_NONE
)
829 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
831 if (Player
.p_ring
.ring_duration
<= 0)
832 /* clean up expired rings */
833 switch (Player
.p_ring
.ring_type
) {
834 case R_BAD
: /* ring drives player crazy */
835 Player
.p_ring
.ring_type
= R_SPOILED
;
836 Player
.p_ring
.ring_duration
= (short) ROLL(10.0, 25.0);
839 case R_NAZREG
: /* ring disappears */
840 Player
.p_ring
.ring_type
= R_NONE
;
843 case R_SPOILED
: /* ring kills player */
844 death("A cursed ring");
847 case R_DLREG
: /* this ring doesn't expire */
848 Player
.p_ring
.ring_duration
= 0;
852 if (Player
.p_age
/ N_AGE
> Player
.p_degenerated
)
853 /* age player slightly */
855 ++Player
.p_degenerated
;
856 if (Player
.p_quickness
> 23.0)
857 Player
.p_quickness
*= 0.99;
858 Player
.p_strength
*= 0.97;
859 Player
.p_brains
*= 0.95;
860 Player
.p_magiclvl
*= 0.97;
861 Player
.p_maxenergy
*= 0.95;
862 Player
.p_quksilver
*= 0.95;
863 Player
.p_sword
*= 0.93;
864 Player
.p_shield
*= 0.93;
870 struct player
*playerp
;
872 playerp
->p_experience
=
874 playerp
->p_strength
=
878 playerp
->p_maxenergy
=
880 playerp
->p_quickness
=
881 playerp
->p_quksilver
=
883 playerp
->p_magiclvl
=
889 playerp
->p_1scratch
=
890 playerp
->p_2scratch
= 0.0;
892 playerp
->p_gold
= ROLL(50.0, 75.0) + 0.1; /* give some gold */
894 playerp
->p_x
= ROLL(-125.0, 251.0);
895 playerp
->p_y
= ROLL(-125.0, 251.0); /* give random x, y */
898 playerp
->p_ring
.ring_type
= R_NONE
;
899 playerp
->p_ring
.ring_duration
= 0;
900 playerp
->p_ring
.ring_inuse
= FALSE
;
904 playerp
->p_degenerated
= 1; /* don't degenerate initially */
906 playerp
->p_type
= C_FIGHTER
; /* default */
907 playerp
->p_specialtype
= SC_NONE
;
912 playerp
->p_holywater
=
913 playerp
->p_lastused
= 0;
914 playerp
->p_status
= S_NOTUSED
;
915 playerp
->p_tampered
= T_OFF
;
916 playerp
->p_istat
= I_OFF
;
918 playerp
->p_palantir
=
919 playerp
->p_blessing
=
921 playerp
->p_blindness
= FALSE
;
924 playerp
->p_password
[0] =
925 playerp
->p_login
[0] = '\0';
933 fseek(Messagefp
, 0L, SEEK_SET
);
934 if (fgets(Databuf
, SZ_DATABUF
, Messagefp
) != NULL
)
940 const char *whichfile
;
942 int (*funcp
)(const char *,...);
950 (*funcp
) ("An unrecoverable error has occurred reading %s. (%s)\n", whichfile
, strerror(errno
));
951 (*funcp
) ("Please run 'setup' to determine the problem.\n");
957 distance(x_1
, x_2
, y_1
, y_2
)
958 double x_1
, x_2
, y_1
, y_2
;
960 double deltax
, deltay
;
964 return (sqrt(deltax
* deltax
+ deltay
* deltay
));
972 if (!(whichsig
== SIGINT
|| whichsig
== SIGQUIT
))
973 printw("Error: caught signal # %d.\n", whichsig
);
980 struct player
*playerp
;
982 switch (playerp
->p_status
) {
984 if (playerp
->p_energy
< 0.2 * (playerp
->p_maxenergy
+ playerp
->p_shield
))
985 return ("Low Energy");
987 if (playerp
->p_blindness
)
996 return ("In Battle");
999 return ("Encounter");
1018 if (sizeof(int) != 2)
1019 /* use only low bits */
1020 return ((double) (random() & 0x7fff) / 32768.0);
1022 return ((double) random() / 32768.0);
1026 collecttaxes(gold
, gems
)
1030 FILE *fp
; /* to update Goldfile */
1031 double dtemp
; /* for temporary calculations */
1032 double taxes
; /* tax liability */
1035 Player
.p_gold
+= gold
;
1036 Player
.p_gems
+= gems
;
1038 /* calculate tax liability */
1039 taxes
= N_TAXAMOUNT
/ 100.0 * (N_GEMVALUE
* gems
+ gold
);
1041 if (Player
.p_gold
< taxes
)
1042 /* not enough gold to pay taxes, must convert some gems to
1045 dtemp
= floor(taxes
/ N_GEMVALUE
+ 1.0); /* number of gems to
1048 if (Player
.p_gems
>= dtemp
)
1049 /* player has enough to convert */
1051 Player
.p_gems
-= dtemp
;
1052 Player
.p_gold
+= dtemp
* N_GEMVALUE
;
1054 /* take everything; this should never happen */
1056 Player
.p_gold
+= Player
.p_gems
* N_GEMVALUE
;
1057 Player
.p_gems
= 0.0;
1058 taxes
= Player
.p_gold
;
1061 Player
.p_gold
-= taxes
;
1063 if ((fp
= fopen(_PATH_GOLD
, "r+")) != NULL
)
1067 fread((char *) &dtemp
, sizeof(double), 1, fp
);
1068 dtemp
+= floor(taxes
);
1069 fseek(fp
, 0L, SEEK_SET
);
1070 fwrite((char *) &dtemp
, sizeof(double), 1, fp
);