]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/misc.c
1 /* $NetBSD: misc.c,v 1.7 2000/04/27 00:30:53 jdc Exp $ */
4 * misc.c Phantasia miscellaneous support routines
13 const struct charstats
*statptr
; /* for pointing into Stattable */
14 double new; /* new level */
15 double inc
; /* increment between new and old levels */
19 if (Player
.p_type
== C_EXPER
)
20 /* roll a type to use for increment */
21 statptr
= &Stattable
[(int) ROLL(C_MAGIC
, C_HALFLING
- C_MAGIC
+ 1)];
25 new = explevel(Player
.p_experience
);
26 inc
= new - Player
.p_level
;
29 /* add increments to statistics */
30 Player
.p_strength
+= statptr
->c_strength
.increase
* inc
;
31 Player
.p_mana
+= statptr
->c_mana
.increase
* inc
;
32 Player
.p_brains
+= statptr
->c_brains
.increase
* inc
;
33 Player
.p_magiclvl
+= statptr
->c_magiclvl
.increase
* inc
;
34 Player
.p_maxenergy
+= statptr
->c_energy
.increase
* inc
;
36 /* rest to maximum upon reaching new level */
37 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
39 if (Player
.p_crowns
> 0 && Player
.p_level
>= 1000.0)
40 /* no longer able to be king -- turn crowns into cash */
42 Player
.p_gold
+= ((double) Player
.p_crowns
) * 5000.0;
45 if (Player
.p_level
>= 3000.0 && Player
.p_specialtype
< SC_COUNCIL
)
46 /* make a member of the council */
48 mvaddstr(6, 0, "You have made it to the Council of the Wise.\n");
49 addstr("Good Luck on your search for the Holy Grail.\n");
51 Player
.p_specialtype
= SC_COUNCIL
;
53 /* no rings for council and above */
54 Player
.p_ring
.ring_type
= R_NONE
;
55 Player
.p_ring
.ring_duration
= 0;
57 Player
.p_lives
= 3; /* three extra lives */
59 if (Player
.p_level
> 9999.0 && Player
.p_specialtype
!= SC_VALAR
)
64 descrlocation(playerp
, shortflag
)
65 struct player
*playerp
;
68 double circle
; /* corresponding circle for coordinates */
69 int quadrant
; /* quandrant of grid */
70 const char *label
; /* pointer to place name */
71 static const char *const nametable
[4][4] = /* names of places */
73 {"Anorien", "Ithilien", "Rohan", "Lorien"},
74 {"Gondor", "Mordor", "Dunland", "Rovanion"},
75 {"South Gondor", "Khand", "Eriador", "The Iron Hills"},
76 {"Far Harad", "Near Harad", "The Northern Waste", "Rhun"}
79 if (playerp
->p_specialtype
== SC_VALAR
)
80 return (" is in Valhala");
82 if ((circle
= CIRCLE(playerp
->p_x
, playerp
->p_y
)) >= 1000.0) {
83 if (MAX(fabs(playerp
->p_x
), fabs(playerp
->p_y
)) > D_BEYOND
)
84 label
= "The Point of No Return";
86 label
= "The Ashen Mountains";
92 label
= "Kennaquahair";
95 label
= "The Dead Marshes";
98 label
= "The Outer Waste";
101 label
= "The Moors Adventurous";
103 if (playerp
->p_x
== 0.0 && playerp
->p_y
== 0.0)
104 label
= "The Lord's Chamber";
129 quadrant
= ((playerp
->p_x
> 0.0) ? 1 : 0);
130 quadrant
+= ((playerp
->p_y
>= 0.0) ? 2 : 0);
131 label
= nametable
[((int) circle
) - 1][quadrant
];
136 sprintf(Databuf
, "%.29s", label
);
138 sprintf(Databuf
, " is in %s (%.0f,%.0f)", label
, playerp
->p_x
, playerp
->p_y
);
146 double numitems
; /* number of items to purchase */
147 double cost
; /* cost of purchase */
148 double blessingcost
; /* cost of blessing */
150 int size
; /* size of the trading post */
151 int loop
; /* loop counter */
152 int cheat
= 0; /* number of times player has tried to cheat */
153 bool dishonest
= FALSE
; /* set when merchant is dishonest */
155 Player
.p_status
= S_TRADING
;
156 writerecord(&Player
, Fileloc
);
159 addstr("You are at a trading post. All purchases must be made with gold.");
161 size
= sqrt(fabs(Player
.p_x
/ 100)) + 1;
164 /* set up cost of blessing */
165 blessingcost
= 1000.0 * (Player
.p_level
+ 5.0);
169 for (loop
= 0; loop
< size
; ++loop
)
175 cost
= Menu
[loop
].cost
;
176 printw("(%d) %-12s: %6.0f\n", loop
+ 1, Menu
[loop
].item
, cost
);
179 mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? ");
182 adjuststats(); /* truncate any bad values */
184 /* print some important statistics */
185 mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n",
186 Player
.p_gold
, Player
.p_gems
, Player
.p_level
, Player
.p_charms
);
187 printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n",
188 Player
.p_shield
, Player
.p_sword
, Player
.p_quksilver
,
189 (Player
.p_blessing
? " True" : "False"));
190 printw("Brains: %9.0f Mana: %9.0f", Player
.p_brains
, Player
.p_mana
);
193 ch
= getanswer("LPS", FALSE
);
197 case 'L': /* leave */
199 altercoordinates(0.0, 0.0, A_NEAR
);
202 case 'P': /* make purchase */
203 mvaddstr(15, 0, "What what would you like to buy ? ");
204 ch
= getanswer(" 1234567", FALSE
);
209 addstr("Sorry, this merchant doesn't have that.");
213 printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ",
214 Menu
[0].cost
, floor(Player
.p_gold
/ Menu
[0].cost
));
215 cost
= (numitems
= floor(infloat())) * Menu
[0].cost
;
217 if (cost
> Player
.p_gold
|| numitems
< 0)
221 Player
.p_gold
-= cost
;
222 if (drandom() < 0.02)
225 Player
.p_mana
+= numitems
;
230 printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ",
231 Menu
[1].cost
, floor(Player
.p_gold
/ Menu
[1].cost
));
232 cost
= (numitems
= floor(infloat())) * Menu
[1].cost
;
237 if (cost
> Player
.p_gold
|| numitems
< 0)
240 if (numitems
< Player
.p_shield
)
244 Player
.p_gold
-= cost
;
245 if (drandom() < 0.02)
248 Player
.p_shield
= numitems
;
253 printw("A book costs %.0f gp. How many do you want (%.0f max) ? ",
254 Menu
[2].cost
, floor(Player
.p_gold
/ Menu
[2].cost
));
255 cost
= (numitems
= floor(infloat())) * Menu
[2].cost
;
257 if (cost
> Player
.p_gold
|| numitems
< 0)
261 Player
.p_gold
-= cost
;
262 if (drandom() < 0.02)
265 if (drandom() * numitems
> Player
.p_level
/ 10.0
267 printw("\nYou blew your mind!\n");
268 Player
.p_brains
/= 5;
270 Player
.p_brains
+= floor(numitems
) * ROLL(20, 8);
276 printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ",
277 Menu
[3].cost
, floor(Player
.p_gold
/ Menu
[3].cost
));
278 cost
= (numitems
= floor(infloat())) * Menu
[3].cost
;
283 if (cost
> Player
.p_gold
|| numitems
< 0)
286 if (numitems
< Player
.p_sword
)
290 Player
.p_gold
-= cost
;
291 if (drandom() < 0.02)
294 Player
.p_sword
= numitems
;
299 printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ",
300 Menu
[4].cost
, floor(Player
.p_gold
/ Menu
[4].cost
));
301 cost
= (numitems
= floor(infloat())) * Menu
[4].cost
;
303 if (cost
> Player
.p_gold
|| numitems
< 0)
307 Player
.p_gold
-= cost
;
308 if (drandom() < 0.02)
311 Player
.p_charms
+= numitems
;
316 printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ",
317 Menu
[5].cost
, floor(Player
.p_gold
/ Menu
[5].cost
));
318 cost
= (numitems
= floor(infloat())) * Menu
[5].cost
;
323 if (cost
> Player
.p_gold
|| numitems
< 0)
326 if (numitems
< Player
.p_quksilver
)
330 Player
.p_gold
-= cost
;
331 if (drandom() < 0.02)
334 Player
.p_quksilver
= numitems
;
339 if (Player
.p_blessing
) {
340 addstr("You already have a blessing.");
343 printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost
);
344 ch
= getanswer("NY", FALSE
);
347 if (Player
.p_gold
< blessingcost
)
351 Player
.p_gold
-= blessingcost
;
352 if (drandom() < 0.02)
355 Player
.p_blessing
= TRUE
;
362 case 'S': /* sell gems */
363 mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ",
364 (double) N_GEMVALUE
, Player
.p_gems
);
365 numitems
= floor(infloat());
367 if (numitems
> Player
.p_gems
|| numitems
< 0)
371 Player
.p_gems
-= numitems
;
372 Player
.p_gold
+= numitems
* N_GEMVALUE
;
377 mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n");
380 mvaddstr(17, 0, "You had your chance. This merchant happens to be\n");
381 printw("a %.0f level magic user, and you made %s mad!\n",
382 ROLL(Circle
* 20.0, 40.0), (drandom() < 0.5) ? "him" : "her");
383 altercoordinates(0.0, 0.0, A_FAR
);
384 Player
.p_energy
/= 2.0;
390 mvaddstr(17, 0, "The merchant stole your money!");
392 altercoordinates(Player
.p_x
- Player
.p_x
/ 10.0,
393 Player
.p_y
- Player
.p_y
/ 10.0, A_SPECIFIC
);
403 mvprintw(0, 0, "%s%s\n", Player
.p_name
, descrlocation(&Player
, FALSE
));
404 mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n",
405 Player
.p_level
, Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
,
406 Player
.p_mana
, Users
);
407 mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n",
408 Player
.p_speed
, Player
.p_quickness
+ Player
.p_quksilver
, Player
.p_might
,
409 Player
.p_strength
+ Player
.p_sword
, Player
.p_gold
, descrstatus(&Player
));
415 static const char *const flags
[] = /* to print value of some bools */
421 mvprintw(8, 0, "Type: %s\n", descrtype(&Player
, FALSE
));
423 mvprintw(10, 0, "Experience: %9.0f", Player
.p_experience
);
424 mvprintw(11, 0, "Brains : %9.0f", Player
.p_brains
);
425 mvprintw(12, 0, "Magic Lvl : %9.0f", Player
.p_magiclvl
);
426 mvprintw(13, 0, "Sin : %9.5f", Player
.p_sin
);
427 mvprintw(14, 0, "Poison : %9.5f", Player
.p_poison
);
428 mvprintw(15, 0, "Gems : %9.0f", Player
.p_gems
);
429 mvprintw(16, 0, "Age : %9ld", Player
.p_age
);
430 mvprintw(10, 40, "Holy Water: %9d", Player
.p_holywater
);
431 mvprintw(11, 40, "Amulets : %9d", Player
.p_amulets
);
432 mvprintw(12, 40, "Charms : %9d", Player
.p_charms
);
433 mvprintw(13, 40, "Crowns : %9d", Player
.p_crowns
);
434 mvprintw(14, 40, "Shield : %9.0f", Player
.p_shield
);
435 mvprintw(15, 40, "Sword : %9.0f", Player
.p_sword
);
436 mvprintw(16, 40, "Quickslver: %9.0f", Player
.p_quksilver
);
438 mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s",
439 flags
[(int)Player
.p_blessing
],
440 flags
[Player
.p_ring
.ring_type
!= R_NONE
],
441 flags
[(int)Player
.p_virgin
],
442 flags
[(int)Player
.p_palantir
]);
446 descrtype(playerp
, shortflag
)
447 struct player
*playerp
;
450 int type
; /* for caluculating result subscript */
451 static const char *const results
[] =/* description table */
453 " Magic User", " MU",
458 " Experimento", " EX",
461 " Council of Wise", " CW",
467 type
= playerp
->p_type
;
469 switch (playerp
->p_specialtype
) {
471 type
= playerp
->p_type
;
491 type
*= 2; /* calculate offset */
498 /* use short descriptions */
501 if (playerp
->p_crowns
> 0) {
502 strcpy(Databuf
, results
[type
]);
506 return (results
[type
]);
510 findname(name
, playerp
)
512 struct player
*playerp
;
514 long loc
= 0; /* location in the file */
516 fseek(Playersfp
, 0L, SEEK_SET
);
517 while (fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
518 if (strcmp(playerp
->p_name
, name
) == 0) {
519 if (playerp
->p_status
!= S_NOTUSED
|| Wizard
)
523 loc
+= SZ_PLAYERSTRUCT
;
532 long loc
= 0L; /* location in file */
534 fseek(Playersfp
, 0L, SEEK_SET
);
535 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
536 if (Other
.p_status
== S_NOTUSED
)
537 /* found an empty record */
540 loc
+= SZ_PLAYERSTRUCT
;
543 /* make a new record */
545 Player
.p_status
= S_OFF
;
546 writerecord(&Other
, loc
);
552 freerecord(playerp
, loc
)
553 struct player
*playerp
;
556 playerp
->p_name
[0] = CH_MARKDELETE
;
557 playerp
->p_status
= S_NOTUSED
;
558 writerecord(playerp
, loc
);
565 if (Player
.p_level
< 1.0)
566 /* delete character */
567 freerecord(&Player
, Fileloc
);
569 Player
.p_status
= S_OFF
;
570 writerecord(&Player
, Fileloc
);
581 FILE *fp
; /* for updating various files */
583 static const char *const deathmesg
[] =
584 /* add more messages here, if desired */
586 "You have been wounded beyond repair. ",
587 "You have been disemboweled. ",
588 "You've been mashed, mauled, and spit upon. (You're dead.)\n",
590 "You're a complete failure -- you've died!!\n",
591 "You have been dealt a fatal blow! "
596 if (strcmp(how
, "Stupidity") != 0) {
597 if (Player
.p_level
> 9999.0)
599 addstr("Characters must be retired upon reaching level 10000. Sorry.");
601 if (Player
.p_lives
> 0)
604 addstr("You should be more cautious. You've been killed.\n");
605 printw("You only have %d more chance(s).\n", --Player
.p_lives
);
607 Player
.p_energy
= Player
.p_maxenergy
;
610 if (Player
.p_specialtype
== SC_VALAR
) {
611 addstr("You had your chances, but Valar aren't totally\n");
612 addstr("immortal. You are now left to wither and die . . .\n");
614 Player
.p_brains
= Player
.p_level
/ 25.0;
615 Player
.p_energy
= Player
.p_maxenergy
/= 5.0;
616 Player
.p_quksilver
= Player
.p_sword
= 0.0;
617 Player
.p_specialtype
= SC_COUNCIL
;
620 if (Player
.p_ring
.ring_inuse
&&
621 (Player
.p_ring
.ring_type
== R_DLREG
|| Player
.p_ring
.ring_type
== R_NAZREG
))
622 /* good ring in use - saved
625 mvaddstr(4, 0, "Your ring saved you from death!\n");
627 Player
.p_ring
.ring_type
= R_NONE
;
628 Player
.p_energy
= Player
.p_maxenergy
/ 12.0 + 1.0;
629 if (Player
.p_crowns
> 0)
633 if (Player
.p_ring
.ring_type
== R_BAD
634 || Player
.p_ring
.ring_type
== R_SPOILED
)
637 * idiot after player */
640 "Your ring has taken control of you and turned you into a monster!\n");
641 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, SEEK_SET
);
642 fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
643 strcpy(Curmonster
.m_name
, Player
.p_name
);
644 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, SEEK_SET
);
645 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
649 enterscore(); /* update score board */
651 /* put info in last dead file */
652 fp
= fopen(_PATH_LASTDEAD
, "w");
653 fprintf(fp
, "%s (%s, run by %s, level %.0f, killed by %s)",
654 Player
.p_name
, descrtype(&Player
, TRUE
),
655 Player
.p_login
, Player
.p_level
, how
);
658 /* let other players know */
659 fp
= fopen(_PATH_MESS
, "w");
660 fprintf(fp
, "%s was killed by %s.", Player
.p_name
, how
);
663 freerecord(&Player
, Fileloc
);
667 addstr(deathmesg
[(int) ROLL(0.0, (double) sizeof(deathmesg
) / sizeof(char *))]);
668 addstr("Care to give it another try ? ");
669 ch
= getanswer("NY", FALSE
);
673 execl(_PATH_GAMEPROG
, "phantasia", "-s",
674 (Wizard
? "-S" : (char *) NULL
), 0);
683 writerecord(playerp
, place
)
684 struct player
*playerp
;
687 fseek(Playersfp
, place
, SEEK_SET
);
688 fwrite((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
696 if (experience
< 1.1e7
)
697 return (floor(pow((experience
/ 1000.0), 0.4875)));
699 return (floor(pow((experience
/ 1250.0), 0.4865)));
706 int length
; /* length of string */
708 length
= strlen(string
);
709 while (string
[--length
] == ' ')
710 string
[length
] = '\0';
714 altercoordinates(xnew
, ynew
, operation
)
720 case A_FORCED
: /* move with no checks */
723 case A_NEAR
: /* pick random coordinates near */
724 xnew
= Player
.p_x
+ ROLL(1.0, 5.0);
725 ynew
= Player
.p_y
- ROLL(1.0, 5.0);
726 /* fall through for check */
728 case A_SPECIFIC
: /* just move player */
729 if (Beyond
&& fabs(xnew
) < D_BEYOND
&& fabs(ynew
) < D_BEYOND
)
731 * cannot move back from point of no return
732 * pick the largest coordinate to remain unchanged
735 if (fabs(xnew
) > fabs(ynew
))
736 xnew
= SGN(Player
.p_x
) * MAX(fabs(Player
.p_x
), D_BEYOND
);
738 ynew
= SGN(Player
.p_y
) * MAX(fabs(Player
.p_y
), D_BEYOND
);
742 case A_FAR
: /* pick random coordinates far */
743 xnew
= Player
.p_x
+ SGN(Player
.p_x
) * ROLL(50 * Circle
, 250 * Circle
);
744 ynew
= Player
.p_y
+ SGN(Player
.p_y
) * ROLL(50 * Circle
, 250 * Circle
);
748 /* now set location flags and adjust coordinates */
749 Circle
= CIRCLE(Player
.p_x
= floor(xnew
), Player
.p_y
= floor(ynew
));
751 /* set up flags based upon location */
752 Throne
= Marsh
= Beyond
= FALSE
;
754 if (Player
.p_x
== 0.0 && Player
.p_y
== 0.0)
757 if (Circle
< 35 && Circle
>= 20)
760 if (MAX(fabs(Player
.p_x
), fabs(Player
.p_y
)) >= D_BEYOND
)
767 readrecord(playerp
, loc
)
768 struct player
*playerp
;
771 fseek(Playersfp
, loc
, SEEK_SET
);
772 fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
778 double dtemp
; /* for temporary calculations */
780 if (explevel(Player
.p_experience
) > Player
.p_level
)
781 /* move one or more levels */
784 if (Player
.p_level
> 5.0)
787 if (Player
.p_specialtype
== SC_VALAR
)
789 Circle
= Player
.p_level
/ 5.0;
791 /* calculate effective quickness */
792 dtemp
= ((Player
.p_gold
+ Player
.p_gems
/ 2.0) - 1000.0) / Statptr
->c_goldtote
794 dtemp
= MAX(0.0, dtemp
);/* gold slows player down */
795 Player
.p_speed
= Player
.p_quickness
+ Player
.p_quksilver
- dtemp
;
797 /* calculate effective strength */
798 if (Player
.p_poison
> 0.0)
799 /* poison makes player weaker */
801 dtemp
= 1.0 - Player
.p_poison
* Statptr
->c_weakness
/ 800.0;
802 dtemp
= MAX(0.1, dtemp
);
805 Player
.p_might
= dtemp
* Player
.p_strength
+ Player
.p_sword
;
807 /* insure that important things are within limits */
808 Player
.p_quksilver
= MIN(99.0, Player
.p_quksilver
);
809 Player
.p_mana
= MIN(Player
.p_mana
,
810 Player
.p_level
* Statptr
->c_maxmana
+ 1000.0);
811 Player
.p_brains
= MIN(Player
.p_brains
,
812 Player
.p_level
* Statptr
->c_maxbrains
+ 200.0);
813 Player
.p_charms
= MIN(Player
.p_charms
, Player
.p_level
+ 10.0);
816 * some implementations have problems with floating point compare
817 * we work around it with this stuff
819 Player
.p_gold
= floor(Player
.p_gold
) + 0.1;
820 Player
.p_gems
= floor(Player
.p_gems
) + 0.1;
821 Player
.p_mana
= floor(Player
.p_mana
) + 0.1;
823 if (Player
.p_ring
.ring_type
!= R_NONE
)
827 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
829 if (Player
.p_ring
.ring_duration
<= 0)
830 /* clean up expired rings */
831 switch (Player
.p_ring
.ring_type
) {
832 case R_BAD
: /* ring drives player crazy */
833 Player
.p_ring
.ring_type
= R_SPOILED
;
834 Player
.p_ring
.ring_duration
= (short) ROLL(10.0, 25.0);
837 case R_NAZREG
: /* ring disappears */
838 Player
.p_ring
.ring_type
= R_NONE
;
841 case R_SPOILED
: /* ring kills player */
842 death("A cursed ring");
845 case R_DLREG
: /* this ring doesn't expire */
846 Player
.p_ring
.ring_duration
= 0;
850 if (Player
.p_age
/ N_AGE
> Player
.p_degenerated
)
851 /* age player slightly */
853 ++Player
.p_degenerated
;
854 if (Player
.p_quickness
> 23.0)
855 Player
.p_quickness
*= 0.99;
856 Player
.p_strength
*= 0.97;
857 Player
.p_brains
*= 0.95;
858 Player
.p_magiclvl
*= 0.97;
859 Player
.p_maxenergy
*= 0.95;
860 Player
.p_quksilver
*= 0.95;
861 Player
.p_sword
*= 0.93;
862 Player
.p_shield
*= 0.93;
868 struct player
*playerp
;
870 playerp
->p_experience
=
872 playerp
->p_strength
=
876 playerp
->p_maxenergy
=
878 playerp
->p_quickness
=
879 playerp
->p_quksilver
=
881 playerp
->p_magiclvl
=
887 playerp
->p_1scratch
=
888 playerp
->p_2scratch
= 0.0;
890 playerp
->p_gold
= ROLL(50.0, 75.0) + 0.1; /* give some gold */
892 playerp
->p_x
= ROLL(-125.0, 251.0);
893 playerp
->p_y
= ROLL(-125.0, 251.0); /* give random x, y */
896 playerp
->p_ring
.ring_type
= R_NONE
;
897 playerp
->p_ring
.ring_duration
= 0;
898 playerp
->p_ring
.ring_inuse
= FALSE
;
902 playerp
->p_degenerated
= 1; /* don't degenerate initially */
904 playerp
->p_type
= C_FIGHTER
; /* default */
905 playerp
->p_specialtype
= SC_NONE
;
910 playerp
->p_holywater
=
911 playerp
->p_lastused
= 0;
912 playerp
->p_status
= S_NOTUSED
;
913 playerp
->p_tampered
= T_OFF
;
914 playerp
->p_istat
= I_OFF
;
916 playerp
->p_palantir
=
917 playerp
->p_blessing
=
919 playerp
->p_blindness
= FALSE
;
922 playerp
->p_password
[0] =
923 playerp
->p_login
[0] = '\0';
931 fseek(Messagefp
, 0L, SEEK_SET
);
932 if (fgets(Databuf
, SZ_DATABUF
, Messagefp
) != NULL
)
938 const char *whichfile
;
940 int (*funcp
) __P((const char *,...));
948 (*funcp
) ("An unrecoverable error has occurred reading %s. (errno = %d)\n", whichfile
, errno
);
949 (*funcp
) ("Please run 'setup' to determine the problem.\n");
955 distance(x1
, x2
, y1
, y2
)
956 double x1
, x2
, y1
, y2
;
958 double deltax
, deltay
;
962 return (sqrt(deltax
* deltax
+ deltay
* deltay
));
970 if (!(whichsig
== SIGINT
|| whichsig
== SIGQUIT
))
971 printw("Error: caught signal # %d.\n", whichsig
);
978 struct player
*playerp
;
980 switch (playerp
->p_status
) {
982 if (playerp
->p_energy
< 0.2 * (playerp
->p_maxenergy
+ playerp
->p_shield
))
983 return ("Low Energy");
985 if (playerp
->p_blindness
)
994 return ("In Battle");
997 return ("Encounter");
1016 if (sizeof(int) != 2)
1017 /* use only low bits */
1018 return ((double) (random() & 0x7fff) / 32768.0);
1020 return ((double) random() / 32768.0);
1024 collecttaxes(gold
, gems
)
1028 FILE *fp
; /* to update Goldfile */
1029 double dtemp
; /* for temporary calculations */
1030 double taxes
; /* tax liability */
1033 Player
.p_gold
+= gold
;
1034 Player
.p_gems
+= gems
;
1036 /* calculate tax liability */
1037 taxes
= N_TAXAMOUNT
/ 100.0 * (N_GEMVALUE
* gems
+ gold
);
1039 if (Player
.p_gold
< taxes
)
1040 /* not enough gold to pay taxes, must convert some gems to
1043 dtemp
= floor(taxes
/ N_GEMVALUE
+ 1.0); /* number of gems to
1046 if (Player
.p_gems
>= dtemp
)
1047 /* player has enough to convert */
1049 Player
.p_gems
-= dtemp
;
1050 Player
.p_gold
+= dtemp
* N_GEMVALUE
;
1052 /* take everything; this should never happen */
1054 Player
.p_gold
+= Player
.p_gems
* N_GEMVALUE
;
1055 Player
.p_gems
= 0.0;
1056 taxes
= Player
.p_gold
;
1059 Player
.p_gold
-= taxes
;
1061 if ((fp
= fopen(_PATH_GOLD
, "r+")) != NULL
)
1065 fread((char *) &dtemp
, sizeof(double), 1, fp
);
1066 dtemp
+= floor(taxes
);
1067 fseek(fp
, 0L, SEEK_SET
);
1068 fwrite((char *) &dtemp
, sizeof(double), 1, fp
);