]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/interplayer.c
1 /* $NetBSD: interplayer.c,v 1.9 2005/02/15 12:58:21 jsm Exp $ */
4 * interplayer.c - player to player routines for Phantasia
14 long foeloc
= 0L; /* location in file of person to fight */
17 fseek(Playersfp
, 0L, SEEK_SET
);
19 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
20 if (Other
.p_status
!= S_OFF
21 && Other
.p_status
!= S_NOTUSED
22 && Other
.p_status
!= S_HUNGUP
23 && (Other
.p_status
!= S_CLOAKED
|| Other
.p_specialtype
!= SC_VALAR
))
24 /* player is on and not a cloaked valar */
28 if (Player
.p_x
== Other
.p_x
29 && Player
.p_y
== Other
.p_y
30 /* same coordinates */
33 && Player
.p_status
== S_PLAYING
34 && (Other
.p_status
== S_PLAYING
|| Other
.p_status
== S_INBATTLE
)
35 /* both are playing */
36 && Other
.p_specialtype
!= SC_VALAR
37 && Player
.p_specialtype
!= SC_VALAR
)
38 /* neither is valar */
44 foeloc
+= SZ_PLAYERSTRUCT
;
49 battleplayer(foeplace
)
52 double dtemp
; /* for temporary calculations */
53 double oldhits
= 0.0; /* previous damage inflicted by foe */
54 int loop
; /* for timing out */
56 short oldtampered
; /* old value of foe's p_tampered */
60 mvaddstr(4, 0, "Preparing for battle!\n");
67 /* set up variables, file, etc. */
68 Player
.p_status
= S_INBATTLE
;
69 Shield
= Player
.p_energy
;
71 /* if p_tampered is not 0, someone else may try to change it (king,
73 Player
.p_tampered
= oldtampered
= 1;
74 Player
.p_1scratch
= 0.0;
75 Player
.p_istat
= I_OFF
;
77 readrecord(&Other
, foeplace
);
78 if (fabs(Player
.p_level
- Other
.p_level
) > 20.0)
79 /* see if players are greatly mismatched */
81 dtemp
= (Player
.p_level
- Other
.p_level
) / MAX(Player
.p_level
, Other
.p_level
);
83 /* foe outweighs this one */
84 Player
.p_speed
*= 2.0;
86 writerecord(&Player
, Fileloc
); /* write out all our info */
88 if (Player
.p_blindness
)
89 Enemyname
= "someone";
91 Enemyname
= Other
.p_name
;
93 mvprintw(6, 0, "You have encountered %s Level: %.0f\n", Enemyname
, Other
.p_level
);
96 for (loop
= 0; Other
.p_status
!= S_INBATTLE
&& loop
< 30; ++loop
)
97 /* wait for foe to respond */
99 readrecord(&Other
, foeplace
);
103 if (Other
.p_status
!= S_INBATTLE
)
104 /* foe did not respond */
106 mvprintw(5, 0, "%s is not responding.\n", Enemyname
);
109 /* else, we are ready to battle */
115 * determine who is first master
116 * if neither player is faster, check level
117 * if neither level is greater, battle is not allowed
118 * (this should never happen, but we have to handle it)
120 if (Player
.p_speed
> Other
.p_speed
)
123 if (Other
.p_speed
> Player
.p_speed
)
126 if (Player
.p_level
> Other
.p_level
)
129 if (Other
.p_level
> Player
.p_level
)
132 /* no one is faster */
134 printw("You can't fight %s yet.", Enemyname
);
141 mvprintw(1, 26, "%20.0f", Shield
); /* overprint energy */
144 /* take action against foe */
147 /* wait for foe to take action */
149 mvaddstr(4, 0, "Waiting...\n");
153 for (loop
= 0; loop
< 20; ++loop
)
154 /* wait for foe to act */
156 readrecord(&Other
, foeplace
);
157 if (Other
.p_1scratch
!= oldhits
)
158 /* p_1scratch changes to indicate
162 /* wait and try again */
170 if (Other
.p_1scratch
== oldhits
) {
172 mvaddstr(22, 0, "Timeout: waiting for response. Do you want to wait ? ");
173 ch
= getanswer("NY", FALSE
);
181 /* foe took action */
183 switch (Other
.p_istat
) {
184 case I_RAN
: /* foe ran away */
185 mvprintw(Lines
++, 0, "%s ran away!", Enemyname
);
188 case I_STUCK
: /* foe tried to run, but
190 mvprintw(Lines
++, 0, "%s tried to run away.", Enemyname
);
193 case I_BLEWIT
: /* foe tried to luckout, but
195 mvprintw(Lines
++, 0, "%s tried to luckout!", Enemyname
);
199 dtemp
= Other
.p_1scratch
- oldhits
;
200 mvprintw(Lines
++, 0, "%s hit you %.0f times!", Enemyname
, dtemp
);
205 oldhits
= Other
.p_1scratch
; /* keep track of old
208 if (Other
.p_tampered
!= oldtampered
)
209 /* p_tampered changes to relinquish
212 oldtampered
= Other
.p_tampered
;
218 /* decide what happens next */
220 if (Lines
> LINES
- 2) {
225 if (Other
.p_istat
== I_KILLED
|| Shield
< 0.0)
228 Shield
= -2.0; /* insure this value is negative */
231 if (Player
.p_istat
== I_KILLED
)
232 /* we killed foe; award treasre */
234 mvprintw(Lines
++, 0, "You killed %s!", Enemyname
);
235 Player
.p_experience
+= Other
.p_experience
;
236 Player
.p_crowns
+= (Player
.p_level
< 1000.0) ? Other
.p_crowns
: 0;
237 Player
.p_amulets
+= Other
.p_amulets
;
238 Player
.p_charms
+= Other
.p_charms
;
239 collecttaxes(Other
.p_gold
, Other
.p_gems
);
240 Player
.p_sword
= MAX(Player
.p_sword
, Other
.p_sword
);
241 Player
.p_shield
= MAX(Player
.p_shield
, Other
.p_shield
);
242 Player
.p_quksilver
= MAX(Player
.p_quksilver
, Other
.p_quksilver
);
243 if (Other
.p_virgin
&& !Player
.p_virgin
) {
244 mvaddstr(Lines
++, 0, "You have rescued a virgin. Will you be honorable ? ");
245 if ((ch
= getanswer("YN", FALSE
)) == 'Y')
246 Player
.p_virgin
= TRUE
;
249 Player
.p_experience
+= 8000.0;
252 sleep(3); /* give other person time to die */
255 if (Player
.p_istat
== I_RAN
|| Other
.p_istat
== I_RAN
)
256 /* either player ran away */
261 /* clean up things and leave */
262 writerecord(&Player
, Fileloc
); /* update a final time */
263 altercoordinates(0.0, 0.0, A_NEAR
); /* move away from battle site */
264 Player
.p_energy
= Shield
; /* set energy to actual value */
265 Player
.p_tampered
= T_OFF
; /* clear p_tampered */
267 more(Lines
); /* pause */
270 clrtobot(); /* clear bottom area of screen */
272 if (Player
.p_energy
< 0.0)
274 death("Interterminal battle");
280 double dtemp
; /* for temporary calculations */
283 mvaddstr(7, 0, "1:Fight 2:Run Away! 3:Power Blast ");
287 addstr("4:Luckout ");
295 dtemp
= ROLL(2.0, Player
.p_might
);
297 mvprintw(Lines
++, 0, "You hit %s %.0f times!", Enemyname
, dtemp
);
299 Player
.p_1scratch
+= dtemp
;
300 Player
.p_istat
= I_OFF
;
303 case '2': /* run away */
304 Player
.p_1scratch
-= 1.0; /* change this to indicate
306 if (drandom() > 0.25) {
307 mvaddstr(Lines
++, 0, "You got away!");
308 Player
.p_istat
= I_RAN
;
310 mvprintw(Lines
++, 0, "%s is still after you!", Enemyname
);
311 Player
.p_istat
= I_STUCK
;
315 case '3': /* power blast */
316 dtemp
= MIN(Player
.p_mana
, Player
.p_level
* 5.0);
317 Player
.p_mana
-= dtemp
;
318 dtemp
*= (drandom() + 0.5) * Player
.p_magiclvl
* 0.2 + 2.0;
319 mvprintw(Lines
++, 0, "You blasted %s !", Enemyname
);
322 case '4': /* luckout */
323 if (Luckout
|| drandom() > 0.1) {
325 mvaddstr(Lines
++, 0, "You already tried that!");
327 mvaddstr(Lines
++, 0, "Not this time . . .");
331 Player
.p_1scratch
-= 1.0;
332 Player
.p_istat
= I_BLEWIT
;
334 mvaddstr(Lines
++, 0, "You just lucked out!");
335 Player
.p_1scratch
= Other
.p_energy
* 1.1;
341 Player
.p_1scratch
= floor(Player
.p_1scratch
); /* clean up any mess */
343 if (Player
.p_1scratch
> Other
.p_energy
)
344 Player
.p_istat
= I_KILLED
;
346 if (drandom() * Player
.p_speed
< drandom() * Other
.p_speed
)
347 /* relinquish control */
352 writerecord(&Player
, Fileloc
); /* let foe know what we did */
358 long loc
= 0L; /* location in energy void file */
360 /* first check for energy voids */
361 fseek(Energyvoidfp
, 0L, SEEK_SET
);
362 while (fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
) == 1)
363 if (Enrgyvoid
.ev_active
364 && Enrgyvoid
.ev_x
== Player
.p_x
365 && Enrgyvoid
.ev_y
== Player
.p_y
)
369 /* not the holy grail; inactivate energy void */
371 Enrgyvoid
.ev_active
= FALSE
;
372 writevoid(&Enrgyvoid
, loc
);
373 tampered(T_NRGVOID
, 0.0, 0.0);
375 if (Player
.p_status
!= S_CLOAKED
)
377 tampered(T_GRAIL
, 0.0, 0.0);
380 loc
+= SZ_VOIDSTRUCT
;
382 /* now check for other things */
383 readrecord(&Other
, Fileloc
);
384 if (Other
.p_tampered
!= T_OFF
)
385 tampered(Other
.p_tampered
, Other
.p_1scratch
, Other
.p_2scratch
);
389 tampered(what
, arg1
, arg2
)
394 long loc
; /* location in file of other players */
399 Player
.p_tampered
= T_OFF
; /* no longer tampered with */
403 addstr("You've hit an energy void !\n");
404 Player
.p_mana
/= 3.0;
405 Player
.p_energy
/= 2.0;
406 Player
.p_gold
= floor(Player
.p_gold
/ 1.25) + 0.1;
407 altercoordinates(0.0, 0.0, A_NEAR
);
411 addstr("The king transported you ! ");
412 if (Player
.p_charms
> 0) {
413 addstr("But your charm saved you. . .\n");
416 altercoordinates(0.0, 0.0, A_FAR
);
422 printw("The king has bestowed %.0f gold pieces on you !\n", arg1
);
423 Player
.p_gold
+= arg1
;
427 addstr("You've been cursed ! ");
428 if (Player
.p_blessing
) {
429 addstr("But your blessing saved you. . .\n");
430 Player
.p_blessing
= FALSE
;
433 Player
.p_poison
+= 2.0;
434 Player
.p_energy
= 10.0;
435 Player
.p_maxenergy
*= 0.95;
436 Player
.p_status
= S_PLAYING
; /* no longer cloaked */
441 addstr("You have been vaporized!\n");
443 death("Vaporization");
447 addstr("The Valar zapped you with a monster!\n");
449 encounter((int) arg1
);
453 addstr("The Valar has blessed you!\n");
454 Player
.p_energy
= (Player
.p_maxenergy
*= 1.05) + Player
.p_shield
;
455 Player
.p_mana
+= 500.0;
456 Player
.p_strength
+= 0.5;
457 Player
.p_brains
+= 0.5;
458 Player
.p_magiclvl
+= 0.5;
459 Player
.p_poison
= MIN(0.5, Player
.p_poison
);
463 addstr("You've been relocated. . .\n");
464 altercoordinates(arg1
, arg2
, A_FORCED
);
468 addstr("You've been healed!\n");
469 Player
.p_poison
-= 0.25;
470 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
474 addstr("You are no longer Valar!\n");
475 Player
.p_specialtype
= SC_COUNCIL
;
479 addstr("You have found The Holy Grail!!\n");
480 if (Player
.p_specialtype
< SC_COUNCIL
)
481 /* must be council of wise to behold grail */
483 addstr("However, you are not experienced enough to behold it.\n");
484 Player
.p_sin
*= Player
.p_sin
;
485 Player
.p_mana
+= 1000;
487 if (Player
.p_specialtype
== SC_VALAR
488 || Player
.p_specialtype
== SC_EXVALAR
) {
489 addstr("You have made it to the position of Valar once already.\n");
490 addstr("The Grail is of no more use to you now.\n");
492 addstr("It is now time to see if you are worthy to behold it. . .\n");
496 if (drandom() / 2.0 < Player
.p_sin
) {
497 addstr("You have failed!\n");
504 Player
.p_experience
=
505 Player
.p_quickness
= 1.0;
507 altercoordinates(1.0, 1.0, A_FORCED
);
508 Player
.p_level
= 0.0;
510 addstr("You made to position of Valar!\n");
511 Player
.p_specialtype
= SC_VALAR
;
513 fseek(Playersfp
, 0L, SEEK_SET
);
515 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
516 /* search for existing valar */
517 if (Other
.p_specialtype
== SC_VALAR
518 && Other
.p_status
!= S_NOTUSED
)
519 /* found old valar */
521 Other
.p_tampered
= T_EXVALAR
;
522 writerecord(&Other
, loc
);
525 loc
+= SZ_PLAYERSTRUCT
;
529 /* move grail to new location */
530 Enrgyvoid
.ev_active
= TRUE
;
531 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
532 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
533 writevoid(&Enrgyvoid
, 0L);
544 int numusers
= 0; /* number of users on file */
546 if (ingameflag
&& Player
.p_blindness
) {
547 mvaddstr(8, 0, "You cannot see anyone.\n");
550 fseek(Playersfp
, 0L, SEEK_SET
);
552 "Name X Y Lvl Type Login Status\n");
554 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
555 if (Other
.p_status
== S_NOTUSED
556 /* record is unused */
557 || (Other
.p_specialtype
== SC_VALAR
&& Other
.p_status
== S_CLOAKED
))
561 /* wizard can see everything on file */
567 /* must be playing for the rest of these conditions */
568 (Player
.p_specialtype
>= SC_KING
569 /* kings and higher can see others */
570 || Other
.p_specialtype
>= SC_KING
571 /* kings and higher can be seen by others */
572 || Circle
>= CIRCLE(Other
.p_x
, Other
.p_y
)
573 /* those nearer the origin can be seen */
574 || Player
.p_palantir
)
575 /* palantir enables one to see others */
576 && (Other
.p_status
!= S_CLOAKED
577 || (Player
.p_specialtype
== SC_VALAR
&& Player
.p_palantir
))
578 /* not cloaked; valar can see through cloak with a palantir */
579 && Other
.p_specialtype
!= SC_VALAR
)
581 /* coordinates should be printed */
582 printw("%-20s %8.0f %8.0f ",
583 Other
.p_name
, Other
.p_x
, Other
.p_y
);
585 /* cannot see player's coordinates */
586 printw("%-20s %19.19s ",
587 Other
.p_name
, descrlocation(&Other
, TRUE
));
589 printw("%6.0f %s %-9.9s%s\n", Other
.p_level
, descrtype(&Other
, TRUE
),
590 Other
.p_login
, descrstatus(&Other
));
592 if ((numusers
% (LINES
- 10)) == 0) {
599 printw("Total players on file = %d\n", numusers
);
606 FILE *fp
; /* to clear energy voids */
607 long loc
= 0L; /* location of old king in player file */
609 if (Player
.p_specialtype
< SC_KING
)
610 /* not already king -- assumes crown */
612 fseek(Playersfp
, 0L, SEEK_SET
);
613 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
614 if (Other
.p_specialtype
== SC_KING
&& Other
.p_status
!= S_NOTUSED
)
617 if (Other
.p_status
!= S_OFF
)
618 /* old king is playing */
620 mvaddstr(4, 0, "The king is playing, so you cannot steal his throne\n");
621 altercoordinates(0.0, 0.0, A_NEAR
);
625 /* old king is not playing - remove
628 Other
.p_specialtype
= SC_NONE
;
631 writerecord(&Other
, loc
);
635 loc
+= SZ_PLAYERSTRUCT
;
637 /* make player new king */
639 Player
.p_specialtype
= SC_KING
;
640 mvaddstr(4, 0, "You have become king!\n");
642 /* let everyone else know */
643 fp
= fopen(_PATH_MESS
, "w");
644 fprintf(fp
, "All hail the new king!");
647 /* clear all energy voids; retain location of holy grail */
648 fseek(Energyvoidfp
, 0L, SEEK_SET
);
649 fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
);
650 fp
= fopen(_PATH_VOID
, "w");
651 fwrite((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
654 mvaddstr(6, 0, "0:Decree ");
660 short tamper
; /* value for tampering with other players */
661 const char *option
; /* pointer to option description */
662 double temp1
= 0.0, temp2
= 0.0; /* other tampering values */
664 long loc
; /* location in energy void file */
665 FILE *fp
; /* for opening gold file */
669 if (Player
.p_specialtype
< SC_COUNCIL
&& !Wizard
)
672 addstr("1:Transport 2:Curse 3:Energy Void 4:Bestow 5:Collect Taxes ");
674 ch
= getanswer(" ", TRUE
);
679 case '1': /* transport someone */
680 tamper
= T_TRANSPORT
;
681 option
= "transport";
684 case '2': /* curse another */
689 case '3': /* create energy void */
690 if ((loc
= allocvoid()) > 20L * (long)SZ_VOIDSTRUCT
)
691 /* can only have 20 void active at once */
692 mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
694 addstr("Enter the X Y coordinates of void ? ");
695 getstring(Databuf
, SZ_DATABUF
);
696 sscanf(Databuf
, "%lf %lf", &temp1
, &temp2
);
697 Enrgyvoid
.ev_x
= floor(temp1
);
698 Enrgyvoid
.ev_y
= floor(temp2
);
699 Enrgyvoid
.ev_active
= TRUE
;
700 writevoid(&Enrgyvoid
, loc
);
701 mvaddstr(5, 0, "It is done.\n");
705 case '4': /* bestow gold to subject */
707 addstr("How much gold to bestow ? ");
709 if (temp1
> Player
.p_gold
|| temp1
< 0) {
710 mvaddstr(5, 0, "You don't have that !\n");
713 /* adjust gold after we are sure it will be given to
715 option
= "give gold to";
718 case '5': /* collect accumulated taxes */
719 if ((fp
= fopen(_PATH_GOLD
, "r+")) != NULL
)
722 fread((char *) &temp1
, sizeof(double), 1, fp
);
723 fseek(fp
, 0L, SEEK_SET
);
724 /* clear out value */
726 fwrite((char *) &temp2
, sizeof(double), 1, fp
);
729 mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1
);
730 Player
.p_gold
+= floor(temp1
);
736 /* end of king options */
738 /* council of wise, valar, wizard options */
741 if (Player
.p_palantir
|| Wizard
)
742 addstr("2:Seek Grail ");
743 if (Player
.p_specialtype
== SC_VALAR
|| Wizard
)
744 addstr("3:Throw Monster 4:Relocate 5:Bless ");
746 addstr("6:Vaporize ");
748 ch
= getanswer(" ", TRUE
);
750 if (ch
> '2' && Player
.p_specialtype
!= SC_VALAR
) {
754 if (Player
.p_mana
< MM_INTERVENE
) {
755 mvaddstr(5, 0, "No mana left.\n");
758 Player
.p_mana
-= MM_INTERVENE
;
761 case '1': /* heal another */
766 case '2': /* seek grail */
767 if (Player
.p_palantir
)
768 /* need a palantir to seek */
770 fseek(Energyvoidfp
, 0L, SEEK_SET
);
771 fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
);
772 temp1
= distance(Player
.p_x
, Enrgyvoid
.ev_x
, Player
.p_y
, Enrgyvoid
.ev_y
);
773 temp1
+= ROLL(-temp1
/ 10.0, temp1
/ 5.0); /* add some error */
774 mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1
);
777 mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
780 case '3': /* lob monster at someone */
781 mvaddstr(4, 0, "Which monster [0-99] ? ");
783 temp1
= MAX(0.0, MIN(99.0, temp1
));
785 option
= "throw a monster at";
788 case '4': /* move another player */
789 mvaddstr(4, 0, "New X Y coordinates ? ");
790 getstring(Databuf
, SZ_DATABUF
);
791 sscanf(Databuf
, "%lf %lf", &temp1
, &temp2
);
796 case '5': /* bless a player */
801 case '6': /* kill off a player */
803 tamper
= T_VAPORIZED
;
813 /* adjust age after we are sure intervention will be done */
814 /* end of valar, etc. options */
818 /* prompt for player to affect */
820 mvprintw(4, 0, "Who do you want to %s ? ", option
);
821 getstring(Databuf
, SZ_DATABUF
);
822 truncstring(Databuf
);
824 if (Databuf
[0] == '\0')
830 if (strcmp(Player
.p_name
, Databuf
) != 0)
831 /* name other than self */
833 if ((loc
= findname(Databuf
, &Other
)) >= 0L) {
834 if (Other
.p_tampered
!= T_OFF
) {
835 mvaddstr(5, 0, "That person has something pending already.\n");
838 if (tamper
== T_RELOCATE
839 && CIRCLE(temp1
, temp2
) < CIRCLE(Other
.p_x
, Other
.p_y
)
841 mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
843 if (tamper
== T_BESTOW
)
844 Player
.p_gold
-= floor(temp1
);
845 if (!Wizard
&& (tamper
== T_HEAL
|| tamper
== T_MONSTER
||
846 tamper
== T_RELOCATE
|| tamper
== T_BLESSED
))
847 Player
.p_age
+= N_AGE
; /* age penalty */
848 Other
.p_tampered
= tamper
;
849 Other
.p_1scratch
= floor(temp1
);
850 Other
.p_2scratch
= floor(temp2
);
851 writerecord(&Other
, loc
);
852 mvaddstr(5, 0, "It is done.\n");
857 /* player not found */
858 mvaddstr(5, 0, "There is no one by that name.\n");
861 mvaddstr(5, 0, "You may not do it to yourself!\n");
866 struct energyvoid
*vp
;
870 fseek(Energyvoidfp
, loc
, SEEK_SET
);
871 fwrite((char *) vp
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
);
872 fflush(Energyvoidfp
);
873 fseek(Energyvoidfp
, 0L, SEEK_SET
);
879 long loc
= 0L; /* location of new energy void */
881 fseek(Energyvoidfp
, 0L, SEEK_SET
);
882 while (fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
) == 1)
883 if (Enrgyvoid
.ev_active
)
884 loc
+= SZ_VOIDSTRUCT
;