]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/interplayer.c
1 /* $NetBSD: interplayer.c,v 1.10 2009/05/25 23:08:45 dholland 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(long foeplace
)
51 double dtemp
; /* for temporary calculations */
52 double oldhits
= 0.0; /* previous damage inflicted by foe */
53 int loop
; /* for timing out */
55 short oldtampered
; /* old value of foe's p_tampered */
59 mvaddstr(4, 0, "Preparing for battle!\n");
66 /* set up variables, file, etc. */
67 Player
.p_status
= S_INBATTLE
;
68 Shield
= Player
.p_energy
;
70 /* if p_tampered is not 0, someone else may try to change it (king,
72 Player
.p_tampered
= oldtampered
= 1;
73 Player
.p_1scratch
= 0.0;
74 Player
.p_istat
= I_OFF
;
76 readrecord(&Other
, foeplace
);
77 if (fabs(Player
.p_level
- Other
.p_level
) > 20.0)
78 /* see if players are greatly mismatched */
80 dtemp
= (Player
.p_level
- Other
.p_level
) / MAX(Player
.p_level
, Other
.p_level
);
82 /* foe outweighs this one */
83 Player
.p_speed
*= 2.0;
85 writerecord(&Player
, Fileloc
); /* write out all our info */
87 if (Player
.p_blindness
)
88 Enemyname
= "someone";
90 Enemyname
= Other
.p_name
;
92 mvprintw(6, 0, "You have encountered %s Level: %.0f\n", Enemyname
, Other
.p_level
);
95 for (loop
= 0; Other
.p_status
!= S_INBATTLE
&& loop
< 30; ++loop
)
96 /* wait for foe to respond */
98 readrecord(&Other
, foeplace
);
102 if (Other
.p_status
!= S_INBATTLE
)
103 /* foe did not respond */
105 mvprintw(5, 0, "%s is not responding.\n", Enemyname
);
108 /* else, we are ready to battle */
114 * determine who is first master
115 * if neither player is faster, check level
116 * if neither level is greater, battle is not allowed
117 * (this should never happen, but we have to handle it)
119 if (Player
.p_speed
> Other
.p_speed
)
122 if (Other
.p_speed
> Player
.p_speed
)
125 if (Player
.p_level
> Other
.p_level
)
128 if (Other
.p_level
> Player
.p_level
)
131 /* no one is faster */
133 printw("You can't fight %s yet.", Enemyname
);
140 mvprintw(1, 26, "%20.0f", Shield
); /* overprint energy */
143 /* take action against foe */
146 /* wait for foe to take action */
148 mvaddstr(4, 0, "Waiting...\n");
152 for (loop
= 0; loop
< 20; ++loop
)
153 /* wait for foe to act */
155 readrecord(&Other
, foeplace
);
156 if (Other
.p_1scratch
!= oldhits
)
157 /* p_1scratch changes to indicate
161 /* wait and try again */
169 if (Other
.p_1scratch
== oldhits
) {
171 mvaddstr(22, 0, "Timeout: waiting for response. Do you want to wait ? ");
172 ch
= getanswer("NY", FALSE
);
180 /* foe took action */
182 switch (Other
.p_istat
) {
183 case I_RAN
: /* foe ran away */
184 mvprintw(Lines
++, 0, "%s ran away!", Enemyname
);
187 case I_STUCK
: /* foe tried to run, but
189 mvprintw(Lines
++, 0, "%s tried to run away.", Enemyname
);
192 case I_BLEWIT
: /* foe tried to luckout, but
194 mvprintw(Lines
++, 0, "%s tried to luckout!", Enemyname
);
198 dtemp
= Other
.p_1scratch
- oldhits
;
199 mvprintw(Lines
++, 0, "%s hit you %.0f times!", Enemyname
, dtemp
);
204 oldhits
= Other
.p_1scratch
; /* keep track of old
207 if (Other
.p_tampered
!= oldtampered
)
208 /* p_tampered changes to relinquish
211 oldtampered
= Other
.p_tampered
;
217 /* decide what happens next */
219 if (Lines
> LINES
- 2) {
224 if (Other
.p_istat
== I_KILLED
|| Shield
< 0.0)
227 Shield
= -2.0; /* insure this value is negative */
230 if (Player
.p_istat
== I_KILLED
)
231 /* we killed foe; award treasre */
233 mvprintw(Lines
++, 0, "You killed %s!", Enemyname
);
234 Player
.p_experience
+= Other
.p_experience
;
235 Player
.p_crowns
+= (Player
.p_level
< 1000.0) ? Other
.p_crowns
: 0;
236 Player
.p_amulets
+= Other
.p_amulets
;
237 Player
.p_charms
+= Other
.p_charms
;
238 collecttaxes(Other
.p_gold
, Other
.p_gems
);
239 Player
.p_sword
= MAX(Player
.p_sword
, Other
.p_sword
);
240 Player
.p_shield
= MAX(Player
.p_shield
, Other
.p_shield
);
241 Player
.p_quksilver
= MAX(Player
.p_quksilver
, Other
.p_quksilver
);
242 if (Other
.p_virgin
&& !Player
.p_virgin
) {
243 mvaddstr(Lines
++, 0, "You have rescued a virgin. Will you be honorable ? ");
244 if ((ch
= getanswer("YN", FALSE
)) == 'Y')
245 Player
.p_virgin
= TRUE
;
248 Player
.p_experience
+= 8000.0;
251 sleep(3); /* give other person time to die */
254 if (Player
.p_istat
== I_RAN
|| Other
.p_istat
== I_RAN
)
255 /* either player ran away */
260 /* clean up things and leave */
261 writerecord(&Player
, Fileloc
); /* update a final time */
262 altercoordinates(0.0, 0.0, A_NEAR
); /* move away from battle site */
263 Player
.p_energy
= Shield
; /* set energy to actual value */
264 Player
.p_tampered
= T_OFF
; /* clear p_tampered */
266 more(Lines
); /* pause */
269 clrtobot(); /* clear bottom area of screen */
271 if (Player
.p_energy
< 0.0)
273 death("Interterminal battle");
279 double dtemp
; /* for temporary calculations */
282 mvaddstr(7, 0, "1:Fight 2:Run Away! 3:Power Blast ");
286 addstr("4:Luckout ");
294 dtemp
= ROLL(2.0, Player
.p_might
);
296 mvprintw(Lines
++, 0, "You hit %s %.0f times!", Enemyname
, dtemp
);
298 Player
.p_1scratch
+= dtemp
;
299 Player
.p_istat
= I_OFF
;
302 case '2': /* run away */
303 Player
.p_1scratch
-= 1.0; /* change this to indicate
305 if (drandom() > 0.25) {
306 mvaddstr(Lines
++, 0, "You got away!");
307 Player
.p_istat
= I_RAN
;
309 mvprintw(Lines
++, 0, "%s is still after you!", Enemyname
);
310 Player
.p_istat
= I_STUCK
;
314 case '3': /* power blast */
315 dtemp
= MIN(Player
.p_mana
, Player
.p_level
* 5.0);
316 Player
.p_mana
-= dtemp
;
317 dtemp
*= (drandom() + 0.5) * Player
.p_magiclvl
* 0.2 + 2.0;
318 mvprintw(Lines
++, 0, "You blasted %s !", Enemyname
);
321 case '4': /* luckout */
322 if (Luckout
|| drandom() > 0.1) {
324 mvaddstr(Lines
++, 0, "You already tried that!");
326 mvaddstr(Lines
++, 0, "Not this time . . .");
330 Player
.p_1scratch
-= 1.0;
331 Player
.p_istat
= I_BLEWIT
;
333 mvaddstr(Lines
++, 0, "You just lucked out!");
334 Player
.p_1scratch
= Other
.p_energy
* 1.1;
340 Player
.p_1scratch
= floor(Player
.p_1scratch
); /* clean up any mess */
342 if (Player
.p_1scratch
> Other
.p_energy
)
343 Player
.p_istat
= I_KILLED
;
345 if (drandom() * Player
.p_speed
< drandom() * Other
.p_speed
)
346 /* relinquish control */
351 writerecord(&Player
, Fileloc
); /* let foe know what we did */
357 long loc
= 0L; /* location in energy void file */
359 /* first check for energy voids */
360 fseek(Energyvoidfp
, 0L, SEEK_SET
);
361 while (fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
) == 1)
362 if (Enrgyvoid
.ev_active
363 && Enrgyvoid
.ev_x
== Player
.p_x
364 && Enrgyvoid
.ev_y
== Player
.p_y
)
368 /* not the holy grail; inactivate energy void */
370 Enrgyvoid
.ev_active
= FALSE
;
371 writevoid(&Enrgyvoid
, loc
);
372 tampered(T_NRGVOID
, 0.0, 0.0);
374 if (Player
.p_status
!= S_CLOAKED
)
376 tampered(T_GRAIL
, 0.0, 0.0);
379 loc
+= SZ_VOIDSTRUCT
;
381 /* now check for other things */
382 readrecord(&Other
, Fileloc
);
383 if (Other
.p_tampered
!= T_OFF
)
384 tampered(Other
.p_tampered
, Other
.p_1scratch
, Other
.p_2scratch
);
388 tampered(int what
, double arg1
, double arg2
)
390 long loc
; /* location in file of other players */
395 Player
.p_tampered
= T_OFF
; /* no longer tampered with */
399 addstr("You've hit an energy void !\n");
400 Player
.p_mana
/= 3.0;
401 Player
.p_energy
/= 2.0;
402 Player
.p_gold
= floor(Player
.p_gold
/ 1.25) + 0.1;
403 altercoordinates(0.0, 0.0, A_NEAR
);
407 addstr("The king transported you ! ");
408 if (Player
.p_charms
> 0) {
409 addstr("But your charm saved you. . .\n");
412 altercoordinates(0.0, 0.0, A_FAR
);
418 printw("The king has bestowed %.0f gold pieces on you !\n", arg1
);
419 Player
.p_gold
+= arg1
;
423 addstr("You've been cursed ! ");
424 if (Player
.p_blessing
) {
425 addstr("But your blessing saved you. . .\n");
426 Player
.p_blessing
= FALSE
;
429 Player
.p_poison
+= 2.0;
430 Player
.p_energy
= 10.0;
431 Player
.p_maxenergy
*= 0.95;
432 Player
.p_status
= S_PLAYING
; /* no longer cloaked */
437 addstr("You have been vaporized!\n");
439 death("Vaporization");
443 addstr("The Valar zapped you with a monster!\n");
445 encounter((int) arg1
);
449 addstr("The Valar has blessed you!\n");
450 Player
.p_energy
= (Player
.p_maxenergy
*= 1.05) + Player
.p_shield
;
451 Player
.p_mana
+= 500.0;
452 Player
.p_strength
+= 0.5;
453 Player
.p_brains
+= 0.5;
454 Player
.p_magiclvl
+= 0.5;
455 Player
.p_poison
= MIN(0.5, Player
.p_poison
);
459 addstr("You've been relocated. . .\n");
460 altercoordinates(arg1
, arg2
, A_FORCED
);
464 addstr("You've been healed!\n");
465 Player
.p_poison
-= 0.25;
466 Player
.p_energy
= Player
.p_maxenergy
+ Player
.p_shield
;
470 addstr("You are no longer Valar!\n");
471 Player
.p_specialtype
= SC_COUNCIL
;
475 addstr("You have found The Holy Grail!!\n");
476 if (Player
.p_specialtype
< SC_COUNCIL
)
477 /* must be council of wise to behold grail */
479 addstr("However, you are not experienced enough to behold it.\n");
480 Player
.p_sin
*= Player
.p_sin
;
481 Player
.p_mana
+= 1000;
483 if (Player
.p_specialtype
== SC_VALAR
484 || Player
.p_specialtype
== SC_EXVALAR
) {
485 addstr("You have made it to the position of Valar once already.\n");
486 addstr("The Grail is of no more use to you now.\n");
488 addstr("It is now time to see if you are worthy to behold it. . .\n");
492 if (drandom() / 2.0 < Player
.p_sin
) {
493 addstr("You have failed!\n");
500 Player
.p_experience
=
501 Player
.p_quickness
= 1.0;
503 altercoordinates(1.0, 1.0, A_FORCED
);
504 Player
.p_level
= 0.0;
506 addstr("You made to position of Valar!\n");
507 Player
.p_specialtype
= SC_VALAR
;
509 fseek(Playersfp
, 0L, SEEK_SET
);
511 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
512 /* search for existing valar */
513 if (Other
.p_specialtype
== SC_VALAR
514 && Other
.p_status
!= S_NOTUSED
)
515 /* found old valar */
517 Other
.p_tampered
= T_EXVALAR
;
518 writerecord(&Other
, loc
);
521 loc
+= SZ_PLAYERSTRUCT
;
525 /* move grail to new location */
526 Enrgyvoid
.ev_active
= TRUE
;
527 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
528 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
529 writevoid(&Enrgyvoid
, 0L);
537 userlist(phbool ingameflag
)
539 int numusers
= 0; /* number of users on file */
541 if (ingameflag
&& Player
.p_blindness
) {
542 mvaddstr(8, 0, "You cannot see anyone.\n");
545 fseek(Playersfp
, 0L, SEEK_SET
);
547 "Name X Y Lvl Type Login Status\n");
549 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1) {
550 if (Other
.p_status
== S_NOTUSED
551 /* record is unused */
552 || (Other
.p_specialtype
== SC_VALAR
&& Other
.p_status
== S_CLOAKED
))
556 /* wizard can see everything on file */
562 /* must be playing for the rest of these conditions */
563 (Player
.p_specialtype
>= SC_KING
564 /* kings and higher can see others */
565 || Other
.p_specialtype
>= SC_KING
566 /* kings and higher can be seen by others */
567 || Circle
>= CIRCLE(Other
.p_x
, Other
.p_y
)
568 /* those nearer the origin can be seen */
569 || Player
.p_palantir
)
570 /* palantir enables one to see others */
571 && (Other
.p_status
!= S_CLOAKED
572 || (Player
.p_specialtype
== SC_VALAR
&& Player
.p_palantir
))
573 /* not cloaked; valar can see through cloak with a palantir */
574 && Other
.p_specialtype
!= SC_VALAR
)
576 /* coordinates should be printed */
577 printw("%-20s %8.0f %8.0f ",
578 Other
.p_name
, Other
.p_x
, Other
.p_y
);
580 /* cannot see player's coordinates */
581 printw("%-20s %19.19s ",
582 Other
.p_name
, descrlocation(&Other
, TRUE
));
584 printw("%6.0f %s %-9.9s%s\n", Other
.p_level
, descrtype(&Other
, TRUE
),
585 Other
.p_login
, descrstatus(&Other
));
587 if ((numusers
% (LINES
- 10)) == 0) {
594 printw("Total players on file = %d\n", numusers
);
601 FILE *fp
; /* to clear energy voids */
602 long loc
= 0L; /* location of old king in player file */
604 if (Player
.p_specialtype
< SC_KING
)
605 /* not already king -- assumes crown */
607 fseek(Playersfp
, 0L, SEEK_SET
);
608 while (fread((char *) &Other
, SZ_PLAYERSTRUCT
, 1, Playersfp
) == 1)
609 if (Other
.p_specialtype
== SC_KING
&& Other
.p_status
!= S_NOTUSED
)
612 if (Other
.p_status
!= S_OFF
)
613 /* old king is playing */
615 mvaddstr(4, 0, "The king is playing, so you cannot steal his throne\n");
616 altercoordinates(0.0, 0.0, A_NEAR
);
620 /* old king is not playing - remove
623 Other
.p_specialtype
= SC_NONE
;
626 writerecord(&Other
, loc
);
630 loc
+= SZ_PLAYERSTRUCT
;
632 /* make player new king */
634 Player
.p_specialtype
= SC_KING
;
635 mvaddstr(4, 0, "You have become king!\n");
637 /* let everyone else know */
638 fp
= fopen(_PATH_MESS
, "w");
639 fprintf(fp
, "All hail the new king!");
642 /* clear all energy voids; retain location of holy grail */
643 fseek(Energyvoidfp
, 0L, SEEK_SET
);
644 fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
);
645 fp
= fopen(_PATH_VOID
, "w");
646 fwrite((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
649 mvaddstr(6, 0, "0:Decree ");
655 short tamper
; /* value for tampering with other players */
656 const char *option
; /* pointer to option description */
657 double temp1
= 0.0, temp2
= 0.0; /* other tampering values */
659 long loc
; /* location in energy void file */
660 FILE *fp
; /* for opening gold file */
664 if (Player
.p_specialtype
< SC_COUNCIL
&& !Wizard
)
667 addstr("1:Transport 2:Curse 3:Energy Void 4:Bestow 5:Collect Taxes ");
669 ch
= getanswer(" ", TRUE
);
674 case '1': /* transport someone */
675 tamper
= T_TRANSPORT
;
676 option
= "transport";
679 case '2': /* curse another */
684 case '3': /* create energy void */
685 if ((loc
= allocvoid()) > 20L * (long)SZ_VOIDSTRUCT
)
686 /* can only have 20 void active at once */
687 mvaddstr(5, 0, "Sorry, void creation limit reached.\n");
689 addstr("Enter the X Y coordinates of void ? ");
690 getstring(Databuf
, SZ_DATABUF
);
691 sscanf(Databuf
, "%lf %lf", &temp1
, &temp2
);
692 Enrgyvoid
.ev_x
= floor(temp1
);
693 Enrgyvoid
.ev_y
= floor(temp2
);
694 Enrgyvoid
.ev_active
= TRUE
;
695 writevoid(&Enrgyvoid
, loc
);
696 mvaddstr(5, 0, "It is done.\n");
700 case '4': /* bestow gold to subject */
702 addstr("How much gold to bestow ? ");
704 if (temp1
> Player
.p_gold
|| temp1
< 0) {
705 mvaddstr(5, 0, "You don't have that !\n");
708 /* adjust gold after we are sure it will be given to
710 option
= "give gold to";
713 case '5': /* collect accumulated taxes */
714 if ((fp
= fopen(_PATH_GOLD
, "r+")) != NULL
)
717 fread((char *) &temp1
, sizeof(double), 1, fp
);
718 fseek(fp
, 0L, SEEK_SET
);
719 /* clear out value */
721 fwrite((char *) &temp2
, sizeof(double), 1, fp
);
724 mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1
);
725 Player
.p_gold
+= floor(temp1
);
731 /* end of king options */
733 /* council of wise, valar, wizard options */
736 if (Player
.p_palantir
|| Wizard
)
737 addstr("2:Seek Grail ");
738 if (Player
.p_specialtype
== SC_VALAR
|| Wizard
)
739 addstr("3:Throw Monster 4:Relocate 5:Bless ");
741 addstr("6:Vaporize ");
743 ch
= getanswer(" ", TRUE
);
745 if (ch
> '2' && Player
.p_specialtype
!= SC_VALAR
) {
749 if (Player
.p_mana
< MM_INTERVENE
) {
750 mvaddstr(5, 0, "No mana left.\n");
753 Player
.p_mana
-= MM_INTERVENE
;
756 case '1': /* heal another */
761 case '2': /* seek grail */
762 if (Player
.p_palantir
)
763 /* need a palantir to seek */
765 fseek(Energyvoidfp
, 0L, SEEK_SET
);
766 fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
);
767 temp1
= distance(Player
.p_x
, Enrgyvoid
.ev_x
, Player
.p_y
, Enrgyvoid
.ev_y
);
768 temp1
+= ROLL(-temp1
/ 10.0, temp1
/ 5.0); /* add some error */
769 mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1
);
772 mvaddstr(5, 0, "You need a palantir to seek the Grail.\n");
775 case '3': /* lob monster at someone */
776 mvaddstr(4, 0, "Which monster [0-99] ? ");
778 temp1
= MAX(0.0, MIN(99.0, temp1
));
780 option
= "throw a monster at";
783 case '4': /* move another player */
784 mvaddstr(4, 0, "New X Y coordinates ? ");
785 getstring(Databuf
, SZ_DATABUF
);
786 sscanf(Databuf
, "%lf %lf", &temp1
, &temp2
);
791 case '5': /* bless a player */
796 case '6': /* kill off a player */
798 tamper
= T_VAPORIZED
;
808 /* adjust age after we are sure intervention will be done */
809 /* end of valar, etc. options */
813 /* prompt for player to affect */
815 mvprintw(4, 0, "Who do you want to %s ? ", option
);
816 getstring(Databuf
, SZ_DATABUF
);
817 truncstring(Databuf
);
819 if (Databuf
[0] == '\0')
825 if (strcmp(Player
.p_name
, Databuf
) != 0)
826 /* name other than self */
828 if ((loc
= findname(Databuf
, &Other
)) >= 0L) {
829 if (Other
.p_tampered
!= T_OFF
) {
830 mvaddstr(5, 0, "That person has something pending already.\n");
833 if (tamper
== T_RELOCATE
834 && CIRCLE(temp1
, temp2
) < CIRCLE(Other
.p_x
, Other
.p_y
)
836 mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n");
838 if (tamper
== T_BESTOW
)
839 Player
.p_gold
-= floor(temp1
);
840 if (!Wizard
&& (tamper
== T_HEAL
|| tamper
== T_MONSTER
||
841 tamper
== T_RELOCATE
|| tamper
== T_BLESSED
))
842 Player
.p_age
+= N_AGE
; /* age penalty */
843 Other
.p_tampered
= tamper
;
844 Other
.p_1scratch
= floor(temp1
);
845 Other
.p_2scratch
= floor(temp2
);
846 writerecord(&Other
, loc
);
847 mvaddstr(5, 0, "It is done.\n");
852 /* player not found */
853 mvaddstr(5, 0, "There is no one by that name.\n");
856 mvaddstr(5, 0, "You may not do it to yourself!\n");
860 writevoid(struct energyvoid
*vp
, long loc
)
863 fseek(Energyvoidfp
, loc
, SEEK_SET
);
864 fwrite((char *) vp
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
);
865 fflush(Energyvoidfp
);
866 fseek(Energyvoidfp
, 0L, SEEK_SET
);
872 long loc
= 0L; /* location of new energy void */
874 fseek(Energyvoidfp
, 0L, SEEK_SET
);
875 while (fread((char *) &Enrgyvoid
, SZ_VOIDSTRUCT
, 1, Energyvoidfp
) == 1)
876 if (Enrgyvoid
.ev_active
)
877 loc
+= SZ_VOIDSTRUCT
;