]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/misc.c
1 /* $NetBSD: misc.c,v 1.3 1997/10/13 02:18:30 lukem Exp $ */
4 * misc.c Phantasia miscellaneous support routines
13 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 char *label
; /* pointer to place name */
71 static char *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
;
361 case 'S': /* sell gems */
362 mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ",
363 (double) N_GEMVALUE
, Player
.p_gems
);
364 numitems
= floor(infloat());
366 if (numitems
> Player
.p_gems
|| numitems
< 0)
370 Player
.p_gems
-= numitems
;
371 Player
.p_gold
+= numitems
* N_GEMVALUE
;
376 mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n");
379 mvaddstr(17, 0, "You had your chance. This merchant happens to be\n");
380 printw("a %.0f level magic user, and you made %s mad!\n",
381 ROLL(Circle
* 20.0, 40.0), (drandom() < 0.5) ? "him" : "her");
382 altercoordinates(0.0, 0.0, A_FAR
);
383 Player
.p_energy
/= 2.0;
389 mvaddstr(17, 0, "The merchant stole your money!");
391 altercoordinates(Player
.p_x
- Player
.p_x
/ 10.0,
392 Player
.p_y
- Player
.p_y
/ 10.0, A_SPECIFIC
);
402 mvprintw(0, 0, "%s%s\n", Player
.p_name
, descrlocation(&Player
, FALSE
));
403 mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n",
404 Player
.p_level
, Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
,
405 Player
.p_mana
, Users
);
406 mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n",
407 Player
.p_speed
, Player
.p_quickness
+ Player
.p_quksilver
, Player
.p_might
,
408 Player
.p_strength
+ Player
.p_sword
, Player
.p_gold
, descrstatus(&Player
));
414 static char *flags
[] = /* to print value of some bools */
420 mvprintw(8, 0, "Type: %s\n", descrtype(&Player
, FALSE
));
422 mvprintw(10, 0, "Experience: %9.0f", Player
.p_experience
);
423 mvprintw(11, 0, "Brains : %9.0f", Player
.p_brains
);
424 mvprintw(12, 0, "Magic Lvl : %9.0f", Player
.p_magiclvl
);
425 mvprintw(13, 0, "Sin : %9.5f", Player
.p_sin
);
426 mvprintw(14, 0, "Poison : %9.5f", Player
.p_poison
);
427 mvprintw(15, 0, "Gems : %9.0f", Player
.p_gems
);
428 mvprintw(16, 0, "Age : %9d", Player
.p_age
);
429 mvprintw(10, 40, "Holy Water: %9d", Player
.p_holywater
);
430 mvprintw(11, 40, "Amulets : %9d", Player
.p_amulets
);
431 mvprintw(12, 40, "Charms : %9d", Player
.p_charms
);
432 mvprintw(13, 40, "Crowns : %9d", Player
.p_crowns
);
433 mvprintw(14, 40, "Shield : %9.0f", Player
.p_shield
);
434 mvprintw(15, 40, "Sword : %9.0f", Player
.p_sword
);
435 mvprintw(16, 40, "Quickslver: %9.0f", Player
.p_quksilver
);
437 mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s",
438 flags
[(int)Player
.p_blessing
],
439 flags
[Player
.p_ring
.ring_type
!= R_NONE
],
440 flags
[(int)Player
.p_virgin
],
441 flags
[(int)Player
.p_palantir
]);
445 descrtype(playerp
, shortflag
)
446 struct player
*playerp
;
449 int type
; /* for caluculating result subscript */
450 static char *results
[] =/* description table */
452 " Magic User", " MU",
457 " Experimento", " EX",
460 " Council of Wise", " CW",
466 type
= playerp
->p_type
;
468 switch (playerp
->p_specialtype
) {
470 type
= playerp
->p_type
;
490 type
*= 2; /* calculate offset */
497 /* use short descriptions */
500 if (playerp
->p_crowns
> 0) {
501 strcpy(Databuf
, results
[type
]);
505 return (results
[type
]);
509 findname(name
, playerp
)
511 struct player
*playerp
;
513 long loc
= 0; /* location in the file */
515 fseek(Playersfp
, 0L, 0);
516 while (fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
517 if (strcmp(playerp
->p_name
, name
) == 0) {
518 if (playerp
->p_status
!= S_NOTUSED
|| Wizard
)
522 loc
+= SZ_PLAYERSTRUCT
;
531 long loc
= 0L; /* location in file */
533 fseek(Playersfp
, 0L, 0);
534 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
535 if (Other
.p_status
== S_NOTUSED
)
536 /* found an empty record */
539 loc
+= SZ_PLAYERSTRUCT
;
542 /* make a new record */
544 Player
.p_status
= S_OFF
;
545 writerecord(&Other
, loc
);
551 freerecord(playerp
, loc
)
552 struct player
*playerp
;
555 playerp
->p_name
[0] = CH_MARKDELETE
;
556 playerp
->p_status
= S_NOTUSED
;
557 writerecord(playerp
, loc
);
564 if (Player
.p_level
< 1.0)
565 /* delete character */
566 freerecord(&Player
, Fileloc
);
568 Player
.p_status
= S_OFF
;
569 writerecord(&Player
, Fileloc
);
580 FILE *fp
; /* for updating various files */
582 static char *deathmesg
[] =
583 /* add more messages here, if desired */
585 "You have been wounded beyond repair. ",
586 "You have been disemboweled. ",
587 "You've been mashed, mauled, and spit upon. (You're dead.)\n",
589 "You're a complete failure -- you've died!!\n",
590 "You have been dealt a fatal blow! "
595 if (strcmp(how
, "Stupidity") != 0) {
596 if (Player
.p_level
> 9999.0)
598 addstr("Characters must be retired upon reaching level 10000. Sorry.");
600 if (Player
.p_lives
> 0)
603 addstr("You should be more cautious. You've been killed.\n");
604 printw("You only have %d more chance(s).\n", --Player
.p_lives
);
606 Player
.p_energy
= Player
.p_maxenergy
;
609 if (Player
.p_specialtype
== SC_VALAR
) {
610 addstr("You had your chances, but Valar aren't totally\n");
611 addstr("immortal. You are now left to wither and die . . .\n");
613 Player
.p_brains
= Player
.p_level
/ 25.0;
614 Player
.p_energy
= Player
.p_maxenergy
/= 5.0;
615 Player
.p_quksilver
= Player
.p_sword
= 0.0;
616 Player
.p_specialtype
= SC_COUNCIL
;
619 if (Player
.p_ring
.ring_inuse
&&
620 (Player
.p_ring
.ring_type
== R_DLREG
|| Player
.p_ring
.ring_type
== R_NAZREG
))
621 /* good ring in use - saved
624 mvaddstr(4, 0, "Your ring saved you from death!\n");
626 Player
.p_ring
.ring_type
= R_NONE
;
627 Player
.p_energy
= Player
.p_maxenergy
/ 12.0 + 1.0;
628 if (Player
.p_crowns
> 0)
632 if (Player
.p_ring
.ring_type
== R_BAD
633 || Player
.p_ring
.ring_type
== R_SPOILED
)
636 * idiot after player */
639 "Your ring has taken control of you and turned you into a monster!\n");
640 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, 0);
641 fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
642 strcpy(Curmonster
.m_name
, Player
.p_name
);
643 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, 0);
644 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
648 enterscore(); /* update score board */
650 /* put info in last dead file */
651 fp
= fopen(_PATH_LASTDEAD
, "w");
652 fprintf(fp
, "%s (%s, run by %s, level %.0f, killed by %s)",
653 Player
.p_name
, descrtype(&Player
, TRUE
),
654 Player
.p_login
, Player
.p_level
, how
);
657 /* let other players know */
658 fp
= fopen(_PATH_MESS
, "w");
659 fprintf(fp
, "%s was killed by %s.", Player
.p_name
, how
);
662 freerecord(&Player
, Fileloc
);
666 addstr(deathmesg
[(int) ROLL(0.0, (double) sizeof(deathmesg
) / sizeof(char *))]);
667 addstr("Care to give it another try ? ");
668 ch
= getanswer("NY", FALSE
);
672 execl(_PATH_GAMEPROG
, "phantasia", "-s",
673 (Wizard
? "-S" : (char *) NULL
), 0);
682 writerecord(playerp
, place
)
683 struct player
*playerp
;
686 fseek(Playersfp
, place
, 0);
687 fwrite((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
695 if (experience
< 1.1e7
)
696 return (floor(pow((experience
/ 1000.0), 0.4875)));
698 return (floor(pow((experience
/ 1250.0), 0.4865)));
705 int length
; /* length of string */
707 length
= strlen(string
);
708 while (string
[--length
] == ' ')
709 string
[length
] = '\0';
713 altercoordinates(xnew
, ynew
, operation
)
719 case A_FORCED
: /* move with no checks */
722 case A_NEAR
: /* pick random coordinates near */
723 xnew
= Player
.p_x
+ ROLL(1.0, 5.0);
724 ynew
= Player
.p_y
- ROLL(1.0, 5.0);
725 /* fall through for check */
727 case A_SPECIFIC
: /* just move player */
728 if (Beyond
&& fabs(xnew
) < D_BEYOND
&& fabs(ynew
) < D_BEYOND
)
730 * cannot move back from point of no return
731 * pick the largest coordinate to remain unchanged
734 if (fabs(xnew
) > fabs(ynew
))
735 xnew
= SGN(Player
.p_x
) * MAX(fabs(Player
.p_x
), D_BEYOND
);
737 ynew
= SGN(Player
.p_y
) * MAX(fabs(Player
.p_y
), D_BEYOND
);
741 case A_FAR
: /* pick random coordinates far */
742 xnew
= Player
.p_x
+ SGN(Player
.p_x
) * ROLL(50 * Circle
, 250 * Circle
);
743 ynew
= Player
.p_y
+ SGN(Player
.p_y
) * ROLL(50 * Circle
, 250 * Circle
);
747 /* now set location flags and adjust coordinates */
748 Circle
= CIRCLE(Player
.p_x
= floor(xnew
), Player
.p_y
= floor(ynew
));
750 /* set up flags based upon location */
751 Throne
= Marsh
= Beyond
= FALSE
;
753 if (Player
.p_x
== 0.0 && Player
.p_y
== 0.0)
756 if (Circle
< 35 && Circle
>= 20)
759 if (MAX(fabs(Player
.p_x
), fabs(Player
.p_y
)) >= D_BEYOND
)
766 readrecord(playerp
, loc
)
767 struct player
*playerp
;
770 fseek(Playersfp
, loc
, 0);
771 fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
777 double dtemp
; /* for temporary calculations */
779 if (explevel(Player
.p_experience
) > Player
.p_level
)
780 /* move one or more levels */
783 if (Player
.p_level
> 5.0)
786 if (Player
.p_specialtype
== SC_VALAR
)
788 Circle
= Player
.p_level
/ 5.0;
790 /* calculate effective quickness */
791 dtemp
= ((Player
.p_gold
+ Player
.p_gems
/ 2.0) - 1000.0) / Statptr
->c_goldtote
793 dtemp
= MAX(0.0, dtemp
);/* gold slows player down */
794 Player
.p_speed
= Player
.p_quickness
+ Player
.p_quksilver
- dtemp
;
796 /* calculate effective strength */
797 if (Player
.p_poison
> 0.0)
798 /* poison makes player weaker */
800 dtemp
= 1.0 - Player
.p_poison
* Statptr
->c_weakness
/ 800.0;
801 dtemp
= MAX(0.1, dtemp
);
804 Player
.p_might
= dtemp
* Player
.p_strength
+ Player
.p_sword
;
806 /* insure that important things are within limits */
807 Player
.p_quksilver
= MIN(99.0, Player
.p_quksilver
);
808 Player
.p_mana
= MIN(Player
.p_mana
,
809 Player
.p_level
* Statptr
->c_maxmana
+ 1000.0);
810 Player
.p_brains
= MIN(Player
.p_brains
,
811 Player
.p_level
* Statptr
->c_maxbrains
+ 200.0);
812 Player
.p_charms
= MIN(Player
.p_charms
, Player
.p_level
+ 10.0);
815 * some implementations have problems with floating point compare
816 * we work around it with this stuff
818 Player
.p_gold
= floor(Player
.p_gold
) + 0.1;
819 Player
.p_gems
= floor(Player
.p_gems
) + 0.1;
820 Player
.p_mana
= floor(Player
.p_mana
) + 0.1;
822 if (Player
.p_ring
.ring_type
!= R_NONE
)
826 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
828 if (Player
.p_ring
.ring_duration
<= 0)
829 /* clean up expired rings */
830 switch (Player
.p_ring
.ring_type
) {
831 case R_BAD
: /* ring drives player crazy */
832 Player
.p_ring
.ring_type
= R_SPOILED
;
833 Player
.p_ring
.ring_duration
= (short) ROLL(10.0, 25.0);
836 case R_NAZREG
: /* ring disappears */
837 Player
.p_ring
.ring_type
= R_NONE
;
840 case R_SPOILED
: /* ring kills player */
841 death("A cursed ring");
844 case R_DLREG
: /* this ring doesn't expire */
845 Player
.p_ring
.ring_duration
= 0;
849 if (Player
.p_age
/ N_AGE
> Player
.p_degenerated
)
850 /* age player slightly */
852 ++Player
.p_degenerated
;
853 if (Player
.p_quickness
> 23.0)
854 Player
.p_quickness
*= 0.99;
855 Player
.p_strength
*= 0.97;
856 Player
.p_brains
*= 0.95;
857 Player
.p_magiclvl
*= 0.97;
858 Player
.p_maxenergy
*= 0.95;
859 Player
.p_quksilver
*= 0.95;
860 Player
.p_sword
*= 0.93;
861 Player
.p_shield
*= 0.93;
867 struct player
*playerp
;
869 playerp
->p_experience
=
871 playerp
->p_strength
=
875 playerp
->p_maxenergy
=
877 playerp
->p_quickness
=
878 playerp
->p_quksilver
=
880 playerp
->p_magiclvl
=
886 playerp
->p_1scratch
=
887 playerp
->p_2scratch
= 0.0;
889 playerp
->p_gold
= ROLL(50.0, 75.0) + 0.1; /* give some gold */
891 playerp
->p_x
= ROLL(-125.0, 251.0);
892 playerp
->p_y
= ROLL(-125.0, 251.0); /* give random x, y */
895 playerp
->p_ring
.ring_type
= R_NONE
;
896 playerp
->p_ring
.ring_duration
= 0;
897 playerp
->p_ring
.ring_inuse
= FALSE
;
901 playerp
->p_degenerated
= 1; /* don't degenerate initially */
903 playerp
->p_type
= C_FIGHTER
; /* default */
904 playerp
->p_specialtype
= SC_NONE
;
909 playerp
->p_holywater
=
910 playerp
->p_lastused
= 0;
911 playerp
->p_status
= S_NOTUSED
;
912 playerp
->p_tampered
= T_OFF
;
913 playerp
->p_istat
= I_OFF
;
915 playerp
->p_palantir
=
916 playerp
->p_blessing
=
918 playerp
->p_blindness
= FALSE
;
921 playerp
->p_password
[0] =
922 playerp
->p_login
[0] = '\0';
930 fseek(Messagefp
, 0L, 0);
931 if (fgets(Databuf
, SZ_DATABUF
, Messagefp
) != NULL
)
939 int (*funcp
) __P((const char *,...));
947 (*funcp
) ("An unrecoverable error has occurred reading %s. (errno = %d)\n", whichfile
, errno
);
948 (*funcp
) ("Please run 'setup' to determine the problem.\n");
954 distance(x1
, x2
, y1
, y2
)
955 double x1
, x2
, y1
, y2
;
957 double deltax
, deltay
;
961 return (sqrt(deltax
* deltax
+ deltay
* deltay
));
969 if (!(whichsig
== SIGINT
|| whichsig
== SIGQUIT
))
970 printw("Error: caught signal # %d.\n", whichsig
);
977 struct player
*playerp
;
979 switch (playerp
->p_status
) {
981 if (playerp
->p_energy
< 0.2 * (playerp
->p_maxenergy
+ playerp
->p_shield
))
982 return ("Low Energy");
984 if (playerp
->p_blindness
)
993 return ("In Battle");
996 return ("Encounter");
1015 if (sizeof(int) != 2)
1016 /* use only low bits */
1017 return ((double) (random() & 0x7fff) / 32768.0);
1019 return ((double) random() / 32768.0);
1023 collecttaxes(gold
, gems
)
1027 FILE *fp
; /* to update Goldfile */
1028 double dtemp
; /* for temporary calculations */
1029 double taxes
; /* tax liability */
1032 Player
.p_gold
+= gold
;
1033 Player
.p_gems
+= gems
;
1035 /* calculate tax liability */
1036 taxes
= N_TAXAMOUNT
/ 100.0 * (N_GEMVALUE
* gems
+ gold
);
1038 if (Player
.p_gold
< taxes
)
1039 /* not enough gold to pay taxes, must convert some gems to
1042 dtemp
= floor(taxes
/ N_GEMVALUE
+ 1.0); /* number of gems to
1045 if (Player
.p_gems
>= dtemp
)
1046 /* player has enough to convert */
1048 Player
.p_gems
-= dtemp
;
1049 Player
.p_gold
+= dtemp
* N_GEMVALUE
;
1051 /* take everything; this should never happen */
1053 Player
.p_gold
+= Player
.p_gems
* N_GEMVALUE
;
1054 Player
.p_gems
= 0.0;
1055 taxes
= Player
.p_gold
;
1058 Player
.p_gold
-= taxes
;
1060 if ((fp
= fopen(_PATH_GOLD
, "r+")) != NULL
)
1064 fread((char *) &dtemp
, sizeof(double), 1, fp
);
1065 dtemp
+= floor(taxes
);
1067 fwrite((char *) &dtemp
, sizeof(double), 1, fp
);