]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/misc.c
1 /* $NetBSD: misc.c,v 1.11 2004/04/07 17:46:47 ross Exp $ */
4 * misc.c Phantasia miscellaneous support routines
14 const struct charstats
*statptr
; /* for pointing into Stattable */
15 double new; /* new level */
16 double inc
; /* increment between new and old levels */
20 if (Player
.p_type
== C_EXPER
)
21 /* roll a type to use for increment */
22 statptr
= &Stattable
[(int) ROLL(C_MAGIC
, C_HALFLING
- C_MAGIC
+ 1)];
26 new = explevel(Player
.p_experience
);
27 inc
= new - Player
.p_level
;
30 /* add increments to statistics */
31 Player
.p_strength
+= statptr
->c_strength
.increase
* inc
;
32 Player
.p_mana
+= statptr
->c_mana
.increase
* inc
;
33 Player
.p_brains
+= statptr
->c_brains
.increase
* inc
;
34 Player
.p_magiclvl
+= statptr
->c_magiclvl
.increase
* inc
;
35 Player
.p_maxenergy
+= statptr
->c_energy
.increase
* inc
;
37 /* rest to maximum upon reaching new level */
38 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
40 if (Player
.p_crowns
> 0 && Player
.p_level
>= 1000.0)
41 /* no longer able to be king -- turn crowns into cash */
43 Player
.p_gold
+= ((double) Player
.p_crowns
) * 5000.0;
46 if (Player
.p_level
>= 3000.0 && Player
.p_specialtype
< SC_COUNCIL
)
47 /* make a member of the council */
49 mvaddstr(6, 0, "You have made it to the Council of the Wise.\n");
50 addstr("Good Luck on your search for the Holy Grail.\n");
52 Player
.p_specialtype
= SC_COUNCIL
;
54 /* no rings for council and above */
55 Player
.p_ring
.ring_type
= R_NONE
;
56 Player
.p_ring
.ring_duration
= 0;
58 Player
.p_lives
= 3; /* three extra lives */
60 if (Player
.p_level
> 9999.0 && Player
.p_specialtype
!= SC_VALAR
)
65 descrlocation(playerp
, shortflag
)
66 struct player
*playerp
;
69 double circle
; /* corresponding circle for coordinates */
70 int quadrant
; /* quandrant of grid */
71 const char *label
; /* pointer to place name */
72 static const char *const nametable
[4][4] = /* names of places */
74 {"Anorien", "Ithilien", "Rohan", "Lorien"},
75 {"Gondor", "Mordor", "Dunland", "Rovanion"},
76 {"South Gondor", "Khand", "Eriador", "The Iron Hills"},
77 {"Far Harad", "Near Harad", "The Northern Waste", "Rhun"}
80 if (playerp
->p_specialtype
== SC_VALAR
)
81 return (" is in Valhala");
83 if ((circle
= CIRCLE(playerp
->p_x
, playerp
->p_y
)) >= 1000.0) {
84 if (MAX(fabs(playerp
->p_x
), fabs(playerp
->p_y
)) > D_BEYOND
)
85 label
= "The Point of No Return";
87 label
= "The Ashen Mountains";
93 label
= "Kennaquahair";
96 label
= "The Dead Marshes";
99 label
= "The Outer Waste";
102 label
= "The Moors Adventurous";
104 if (playerp
->p_x
== 0.0 && playerp
->p_y
== 0.0)
105 label
= "The Lord's Chamber";
130 quadrant
= ((playerp
->p_x
> 0.0) ? 1 : 0);
131 quadrant
+= ((playerp
->p_y
>= 0.0) ? 2 : 0);
132 label
= nametable
[((int) circle
) - 1][quadrant
];
137 sprintf(Databuf
, "%.29s", label
);
139 sprintf(Databuf
, " is in %s (%.0f,%.0f)", label
, playerp
->p_x
, playerp
->p_y
);
147 double numitems
; /* number of items to purchase */
148 double cost
; /* cost of purchase */
149 double blessingcost
; /* cost of blessing */
151 int size
; /* size of the trading post */
152 int loop
; /* loop counter */
153 int cheat
= 0; /* number of times player has tried to cheat */
154 bool dishonest
= FALSE
; /* set when merchant is dishonest */
156 Player
.p_status
= S_TRADING
;
157 writerecord(&Player
, Fileloc
);
160 addstr("You are at a trading post. All purchases must be made with gold.");
162 size
= sqrt(fabs(Player
.p_x
/ 100)) + 1;
165 /* set up cost of blessing */
166 blessingcost
= 1000.0 * (Player
.p_level
+ 5.0);
170 for (loop
= 0; loop
< size
; ++loop
)
176 cost
= Menu
[loop
].cost
;
177 printw("(%d) %-12s: %6.0f\n", loop
+ 1, Menu
[loop
].item
, cost
);
180 mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? ");
183 adjuststats(); /* truncate any bad values */
185 /* print some important statistics */
186 mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n",
187 Player
.p_gold
, Player
.p_gems
, Player
.p_level
, Player
.p_charms
);
188 printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n",
189 Player
.p_shield
, Player
.p_sword
, Player
.p_quksilver
,
190 (Player
.p_blessing
? " True" : "False"));
191 printw("Brains: %9.0f Mana: %9.0f", Player
.p_brains
, Player
.p_mana
);
194 ch
= getanswer("LPS", FALSE
);
198 case 'L': /* leave */
200 altercoordinates(0.0, 0.0, A_NEAR
);
203 case 'P': /* make purchase */
204 mvaddstr(15, 0, "What what would you like to buy ? ");
205 ch
= getanswer(" 1234567", FALSE
);
210 addstr("Sorry, this merchant doesn't have that.");
214 printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ",
215 Menu
[0].cost
, floor(Player
.p_gold
/ Menu
[0].cost
));
216 cost
= (numitems
= floor(infloat())) * Menu
[0].cost
;
218 if (cost
> Player
.p_gold
|| numitems
< 0)
222 Player
.p_gold
-= cost
;
223 if (drandom() < 0.02)
226 Player
.p_mana
+= numitems
;
231 printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ",
232 Menu
[1].cost
, floor(Player
.p_gold
/ Menu
[1].cost
));
233 cost
= (numitems
= floor(infloat())) * Menu
[1].cost
;
238 if (cost
> Player
.p_gold
|| numitems
< 0)
241 if (numitems
< Player
.p_shield
)
245 Player
.p_gold
-= cost
;
246 if (drandom() < 0.02)
249 Player
.p_shield
= numitems
;
254 printw("A book costs %.0f gp. How many do you want (%.0f max) ? ",
255 Menu
[2].cost
, floor(Player
.p_gold
/ Menu
[2].cost
));
256 cost
= (numitems
= floor(infloat())) * Menu
[2].cost
;
258 if (cost
> Player
.p_gold
|| numitems
< 0)
262 Player
.p_gold
-= cost
;
263 if (drandom() < 0.02)
266 if (drandom() * numitems
> Player
.p_level
/ 10.0
268 printw("\nYou blew your mind!\n");
269 Player
.p_brains
/= 5;
271 Player
.p_brains
+= floor(numitems
) * ROLL(20, 8);
277 printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ",
278 Menu
[3].cost
, floor(Player
.p_gold
/ Menu
[3].cost
));
279 cost
= (numitems
= floor(infloat())) * Menu
[3].cost
;
284 if (cost
> Player
.p_gold
|| numitems
< 0)
287 if (numitems
< Player
.p_sword
)
291 Player
.p_gold
-= cost
;
292 if (drandom() < 0.02)
295 Player
.p_sword
= numitems
;
300 printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ",
301 Menu
[4].cost
, floor(Player
.p_gold
/ Menu
[4].cost
));
302 cost
= (numitems
= floor(infloat())) * Menu
[4].cost
;
304 if (cost
> Player
.p_gold
|| numitems
< 0)
308 Player
.p_gold
-= cost
;
309 if (drandom() < 0.02)
312 Player
.p_charms
+= numitems
;
317 printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ",
318 Menu
[5].cost
, floor(Player
.p_gold
/ Menu
[5].cost
));
319 cost
= (numitems
= floor(infloat())) * Menu
[5].cost
;
324 if (cost
> Player
.p_gold
|| numitems
< 0)
327 if (numitems
< Player
.p_quksilver
)
331 Player
.p_gold
-= cost
;
332 if (drandom() < 0.02)
335 Player
.p_quksilver
= numitems
;
340 if (Player
.p_blessing
) {
341 addstr("You already have a blessing.");
344 printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost
);
345 ch
= getanswer("NY", FALSE
);
348 if (Player
.p_gold
< blessingcost
)
352 Player
.p_gold
-= blessingcost
;
353 if (drandom() < 0.02)
356 Player
.p_blessing
= TRUE
;
363 case 'S': /* sell gems */
364 mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ",
365 (double) N_GEMVALUE
, Player
.p_gems
);
366 numitems
= floor(infloat());
368 if (numitems
> Player
.p_gems
|| numitems
< 0)
372 Player
.p_gems
-= numitems
;
373 Player
.p_gold
+= numitems
* N_GEMVALUE
;
378 mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n");
381 mvaddstr(17, 0, "You had your chance. This merchant happens to be\n");
382 printw("a %.0f level magic user, and you made %s mad!\n",
383 ROLL(Circle
* 20.0, 40.0), (drandom() < 0.5) ? "him" : "her");
384 altercoordinates(0.0, 0.0, A_FAR
);
385 Player
.p_energy
/= 2.0;
391 mvaddstr(17, 0, "The merchant stole your money!");
393 altercoordinates(Player
.p_x
- Player
.p_x
/ 10.0,
394 Player
.p_y
- Player
.p_y
/ 10.0, A_SPECIFIC
);
404 mvprintw(0, 0, "%s%s\n", Player
.p_name
, descrlocation(&Player
, FALSE
));
405 mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n",
406 Player
.p_level
, Player
.p_energy
, Player
.p_maxenergy
+ Player
.p_shield
,
407 Player
.p_mana
, Users
);
408 mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n",
409 Player
.p_speed
, Player
.p_quickness
+ Player
.p_quksilver
, Player
.p_might
,
410 Player
.p_strength
+ Player
.p_sword
, Player
.p_gold
, descrstatus(&Player
));
416 static const char *const flags
[] = /* to print value of some bools */
422 mvprintw(8, 0, "Type: %s\n", descrtype(&Player
, FALSE
));
424 mvprintw(10, 0, "Experience: %9.0f", Player
.p_experience
);
425 mvprintw(11, 0, "Brains : %9.0f", Player
.p_brains
);
426 mvprintw(12, 0, "Magic Lvl : %9.0f", Player
.p_magiclvl
);
427 mvprintw(13, 0, "Sin : %9.5f", Player
.p_sin
);
428 mvprintw(14, 0, "Poison : %9.5f", Player
.p_poison
);
429 mvprintw(15, 0, "Gems : %9.0f", Player
.p_gems
);
430 mvprintw(16, 0, "Age : %9ld", Player
.p_age
);
431 mvprintw(10, 40, "Holy Water: %9d", Player
.p_holywater
);
432 mvprintw(11, 40, "Amulets : %9d", Player
.p_amulets
);
433 mvprintw(12, 40, "Charms : %9d", Player
.p_charms
);
434 mvprintw(13, 40, "Crowns : %9d", Player
.p_crowns
);
435 mvprintw(14, 40, "Shield : %9.0f", Player
.p_shield
);
436 mvprintw(15, 40, "Sword : %9.0f", Player
.p_sword
);
437 mvprintw(16, 40, "Quickslver: %9.0f", Player
.p_quksilver
);
439 mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s",
440 flags
[(int)Player
.p_blessing
],
441 flags
[Player
.p_ring
.ring_type
!= R_NONE
],
442 flags
[(int)Player
.p_virgin
],
443 flags
[(int)Player
.p_palantir
]);
447 descrtype(playerp
, shortflag
)
448 struct player
*playerp
;
451 int type
; /* for caluculating result subscript */
452 static const char *const results
[] =/* description table */
454 " Magic User", " MU",
459 " Experimento", " EX",
462 " Council of Wise", " CW",
468 type
= playerp
->p_type
;
470 switch (playerp
->p_specialtype
) {
472 type
= playerp
->p_type
;
492 type
*= 2; /* calculate offset */
499 /* use short descriptions */
502 if (playerp
->p_crowns
> 0) {
503 strcpy(Databuf
, results
[type
]);
507 return (results
[type
]);
511 findname(name
, playerp
)
513 struct player
*playerp
;
515 long loc
= 0; /* location in the file */
517 fseek(Playersfp
, 0L, SEEK_SET
);
518 while (fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
519 if (strcmp(playerp
->p_name
, name
) == 0) {
520 if (playerp
->p_status
!= S_NOTUSED
|| Wizard
)
524 loc
+= SZ_PLAYERSTRUCT
;
533 long loc
= 0L; /* location in file */
535 fseek(Playersfp
, 0L, SEEK_SET
);
536 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
537 if (Other
.p_status
== S_NOTUSED
)
538 /* found an empty record */
541 loc
+= SZ_PLAYERSTRUCT
;
544 /* make a new record */
546 Player
.p_status
= S_OFF
;
547 writerecord(&Other
, loc
);
553 freerecord(playerp
, loc
)
554 struct player
*playerp
;
557 playerp
->p_name
[0] = CH_MARKDELETE
;
558 playerp
->p_status
= S_NOTUSED
;
559 writerecord(playerp
, loc
);
566 if (Player
.p_level
< 1.0)
567 /* delete character */
568 freerecord(&Player
, Fileloc
);
570 Player
.p_status
= S_OFF
;
571 writerecord(&Player
, Fileloc
);
582 FILE *fp
; /* for updating various files */
584 static const char *const deathmesg
[] =
585 /* add more messages here, if desired */
587 "You have been wounded beyond repair. ",
588 "You have been disemboweled. ",
589 "You've been mashed, mauled, and spit upon. (You're dead.)\n",
591 "You're a complete failure -- you've died!!\n",
592 "You have been dealt a fatal blow! "
597 if (strcmp(how
, "Stupidity") != 0) {
598 if (Player
.p_level
> 9999.0)
600 addstr("Characters must be retired upon reaching level 10000. Sorry.");
602 if (Player
.p_lives
> 0)
605 addstr("You should be more cautious. You've been killed.\n");
606 printw("You only have %d more chance(s).\n", --Player
.p_lives
);
608 Player
.p_energy
= Player
.p_maxenergy
;
611 if (Player
.p_specialtype
== SC_VALAR
) {
612 addstr("You had your chances, but Valar aren't totally\n");
613 addstr("immortal. You are now left to wither and die . . .\n");
615 Player
.p_brains
= Player
.p_level
/ 25.0;
616 Player
.p_energy
= Player
.p_maxenergy
/= 5.0;
617 Player
.p_quksilver
= Player
.p_sword
= 0.0;
618 Player
.p_specialtype
= SC_COUNCIL
;
621 if (Player
.p_ring
.ring_inuse
&&
622 (Player
.p_ring
.ring_type
== R_DLREG
|| Player
.p_ring
.ring_type
== R_NAZREG
))
623 /* good ring in use - saved
626 mvaddstr(4, 0, "Your ring saved you from death!\n");
628 Player
.p_ring
.ring_type
= R_NONE
;
629 Player
.p_energy
= Player
.p_maxenergy
/ 12.0 + 1.0;
630 if (Player
.p_crowns
> 0)
634 if (Player
.p_ring
.ring_type
== R_BAD
635 || Player
.p_ring
.ring_type
== R_SPOILED
)
638 * idiot after player */
641 "Your ring has taken control of you and turned you into a monster!\n");
642 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, SEEK_SET
);
643 fread((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
644 strcpy(Curmonster
.m_name
, Player
.p_name
);
645 fseek(Monstfp
, 13L * SZ_MONSTERSTRUCT
, SEEK_SET
);
646 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
650 enterscore(); /* update score board */
652 /* put info in last dead file */
653 fp
= fopen(_PATH_LASTDEAD
, "w");
654 fprintf(fp
, "%s (%s, run by %s, level %.0f, killed by %s)",
655 Player
.p_name
, descrtype(&Player
, TRUE
),
656 Player
.p_login
, Player
.p_level
, how
);
659 /* let other players know */
660 fp
= fopen(_PATH_MESS
, "w");
661 fprintf(fp
, "%s was killed by %s.", Player
.p_name
, how
);
664 freerecord(&Player
, Fileloc
);
668 addstr(deathmesg
[(int) ROLL(0.0, (double) sizeof(deathmesg
) / sizeof(char *))]);
669 addstr("Care to give it another try ? ");
670 ch
= getanswer("NY", FALSE
);
674 execl(_PATH_GAMEPROG
, "phantasia", "-s",
675 (Wizard
? "-S" : (char *) NULL
), 0);
684 writerecord(playerp
, place
)
685 struct player
*playerp
;
688 fseek(Playersfp
, place
, SEEK_SET
);
689 fwrite((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
697 if (experience
< 1.1e7
)
698 return (floor(pow((experience
/ 1000.0), 0.4875)));
700 return (floor(pow((experience
/ 1250.0), 0.4865)));
707 int length
; /* length of string */
709 length
= strlen(string
);
710 while (string
[--length
] == ' ')
711 string
[length
] = '\0';
715 altercoordinates(xnew
, ynew
, operation
)
721 case A_FORCED
: /* move with no checks */
724 case A_NEAR
: /* pick random coordinates near */
725 xnew
= Player
.p_x
+ ROLL(1.0, 5.0);
726 ynew
= Player
.p_y
- ROLL(1.0, 5.0);
727 /* fall through for check */
729 case A_SPECIFIC
: /* just move player */
730 if (Beyond
&& fabs(xnew
) < D_BEYOND
&& fabs(ynew
) < D_BEYOND
)
732 * cannot move back from point of no return
733 * pick the largest coordinate to remain unchanged
736 if (fabs(xnew
) > fabs(ynew
))
737 xnew
= SGN(Player
.p_x
) * MAX(fabs(Player
.p_x
), D_BEYOND
);
739 ynew
= SGN(Player
.p_y
) * MAX(fabs(Player
.p_y
), D_BEYOND
);
743 case A_FAR
: /* pick random coordinates far */
744 xnew
= Player
.p_x
+ SGN(Player
.p_x
) * ROLL(50 * Circle
, 250 * Circle
);
745 ynew
= Player
.p_y
+ SGN(Player
.p_y
) * ROLL(50 * Circle
, 250 * Circle
);
749 /* now set location flags and adjust coordinates */
750 Circle
= CIRCLE(Player
.p_x
= floor(xnew
), Player
.p_y
= floor(ynew
));
752 /* set up flags based upon location */
753 Throne
= Marsh
= Beyond
= FALSE
;
755 if (Player
.p_x
== 0.0 && Player
.p_y
== 0.0)
758 if (Circle
< 35 && Circle
>= 20)
761 if (MAX(fabs(Player
.p_x
), fabs(Player
.p_y
)) >= D_BEYOND
)
768 readrecord(playerp
, loc
)
769 struct player
*playerp
;
772 fseek(Playersfp
, loc
, SEEK_SET
);
773 fread((char *) playerp
, SZ_PLAYERSTRUCT
, 1, Playersfp
);
779 double dtemp
; /* for temporary calculations */
781 if (explevel(Player
.p_experience
) > Player
.p_level
)
782 /* move one or more levels */
785 if (Player
.p_level
> 5.0)
788 if (Player
.p_specialtype
== SC_VALAR
)
790 Circle
= Player
.p_level
/ 5.0;
792 /* calculate effective quickness */
793 dtemp
= ((Player
.p_gold
+ Player
.p_gems
/ 2.0) - 1000.0) / Statptr
->c_goldtote
795 dtemp
= MAX(0.0, dtemp
);/* gold slows player down */
796 Player
.p_speed
= Player
.p_quickness
+ Player
.p_quksilver
- dtemp
;
798 /* calculate effective strength */
799 if (Player
.p_poison
> 0.0)
800 /* poison makes player weaker */
802 dtemp
= 1.0 - Player
.p_poison
* Statptr
->c_weakness
/ 800.0;
803 dtemp
= MAX(0.1, dtemp
);
806 Player
.p_might
= dtemp
* Player
.p_strength
+ Player
.p_sword
;
808 /* insure that important things are within limits */
809 Player
.p_quksilver
= MIN(99.0, Player
.p_quksilver
);
810 Player
.p_mana
= MIN(Player
.p_mana
,
811 Player
.p_level
* Statptr
->c_maxmana
+ 1000.0);
812 Player
.p_brains
= MIN(Player
.p_brains
,
813 Player
.p_level
* Statptr
->c_maxbrains
+ 200.0);
814 Player
.p_charms
= MIN(Player
.p_charms
, Player
.p_level
+ 10.0);
817 * some implementations have problems with floating point compare
818 * we work around it with this stuff
820 Player
.p_gold
= floor(Player
.p_gold
) + 0.1;
821 Player
.p_gems
= floor(Player
.p_gems
) + 0.1;
822 Player
.p_mana
= floor(Player
.p_mana
) + 0.1;
824 if (Player
.p_ring
.ring_type
!= R_NONE
)
828 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
830 if (Player
.p_ring
.ring_duration
<= 0)
831 /* clean up expired rings */
832 switch (Player
.p_ring
.ring_type
) {
833 case R_BAD
: /* ring drives player crazy */
834 Player
.p_ring
.ring_type
= R_SPOILED
;
835 Player
.p_ring
.ring_duration
= (short) ROLL(10.0, 25.0);
838 case R_NAZREG
: /* ring disappears */
839 Player
.p_ring
.ring_type
= R_NONE
;
842 case R_SPOILED
: /* ring kills player */
843 death("A cursed ring");
846 case R_DLREG
: /* this ring doesn't expire */
847 Player
.p_ring
.ring_duration
= 0;
851 if (Player
.p_age
/ N_AGE
> Player
.p_degenerated
)
852 /* age player slightly */
854 ++Player
.p_degenerated
;
855 if (Player
.p_quickness
> 23.0)
856 Player
.p_quickness
*= 0.99;
857 Player
.p_strength
*= 0.97;
858 Player
.p_brains
*= 0.95;
859 Player
.p_magiclvl
*= 0.97;
860 Player
.p_maxenergy
*= 0.95;
861 Player
.p_quksilver
*= 0.95;
862 Player
.p_sword
*= 0.93;
863 Player
.p_shield
*= 0.93;
869 struct player
*playerp
;
871 playerp
->p_experience
=
873 playerp
->p_strength
=
877 playerp
->p_maxenergy
=
879 playerp
->p_quickness
=
880 playerp
->p_quksilver
=
882 playerp
->p_magiclvl
=
888 playerp
->p_1scratch
=
889 playerp
->p_2scratch
= 0.0;
891 playerp
->p_gold
= ROLL(50.0, 75.0) + 0.1; /* give some gold */
893 playerp
->p_x
= ROLL(-125.0, 251.0);
894 playerp
->p_y
= ROLL(-125.0, 251.0); /* give random x, y */
897 playerp
->p_ring
.ring_type
= R_NONE
;
898 playerp
->p_ring
.ring_duration
= 0;
899 playerp
->p_ring
.ring_inuse
= FALSE
;
903 playerp
->p_degenerated
= 1; /* don't degenerate initially */
905 playerp
->p_type
= C_FIGHTER
; /* default */
906 playerp
->p_specialtype
= SC_NONE
;
911 playerp
->p_holywater
=
912 playerp
->p_lastused
= 0;
913 playerp
->p_status
= S_NOTUSED
;
914 playerp
->p_tampered
= T_OFF
;
915 playerp
->p_istat
= I_OFF
;
917 playerp
->p_palantir
=
918 playerp
->p_blessing
=
920 playerp
->p_blindness
= FALSE
;
923 playerp
->p_password
[0] =
924 playerp
->p_login
[0] = '\0';
932 fseek(Messagefp
, 0L, SEEK_SET
);
933 if (fgets(Databuf
, SZ_DATABUF
, Messagefp
) != NULL
)
939 const char *whichfile
;
941 int (*funcp
)(const char *,...);
949 (*funcp
) ("An unrecoverable error has occurred reading %s. (%s)\n", whichfile
, strerror(errno
));
950 (*funcp
) ("Please run 'setup' to determine the problem.\n");
956 distance(x1
, x2
, y1
, y2
)
957 double x1
, x2
, y1
, y2
;
959 double deltax
, deltay
;
963 return (sqrt(deltax
* deltax
+ deltay
* deltay
));
971 if (!(whichsig
== SIGINT
|| whichsig
== SIGQUIT
))
972 printw("Error: caught signal # %d.\n", whichsig
);
979 struct player
*playerp
;
981 switch (playerp
->p_status
) {
983 if (playerp
->p_energy
< 0.2 * (playerp
->p_maxenergy
+ playerp
->p_shield
))
984 return ("Low Energy");
986 if (playerp
->p_blindness
)
995 return ("In Battle");
998 return ("Encounter");
1017 if (sizeof(int) != 2)
1018 /* use only low bits */
1019 return ((double) (random() & 0x7fff) / 32768.0);
1021 return ((double) random() / 32768.0);
1025 collecttaxes(gold
, gems
)
1029 FILE *fp
; /* to update Goldfile */
1030 double dtemp
; /* for temporary calculations */
1031 double taxes
; /* tax liability */
1034 Player
.p_gold
+= gold
;
1035 Player
.p_gems
+= gems
;
1037 /* calculate tax liability */
1038 taxes
= N_TAXAMOUNT
/ 100.0 * (N_GEMVALUE
* gems
+ gold
);
1040 if (Player
.p_gold
< taxes
)
1041 /* not enough gold to pay taxes, must convert some gems to
1044 dtemp
= floor(taxes
/ N_GEMVALUE
+ 1.0); /* number of gems to
1047 if (Player
.p_gems
>= dtemp
)
1048 /* player has enough to convert */
1050 Player
.p_gems
-= dtemp
;
1051 Player
.p_gold
+= dtemp
* N_GEMVALUE
;
1053 /* take everything; this should never happen */
1055 Player
.p_gold
+= Player
.p_gems
* N_GEMVALUE
;
1056 Player
.p_gems
= 0.0;
1057 taxes
= Player
.p_gold
;
1060 Player
.p_gold
-= taxes
;
1062 if ((fp
= fopen(_PATH_GOLD
, "r+")) != NULL
)
1066 fread((char *) &dtemp
, sizeof(double), 1, fp
);
1067 dtemp
+= floor(taxes
);
1068 fseek(fp
, 0L, SEEK_SET
);
1069 fwrite((char *) &dtemp
, sizeof(double), 1, fp
);