diff options
Diffstat (limited to 'games/phantasia')
-rw-r--r-- | games/phantasia/Makefile | 6 | ||||
-rw-r--r-- | games/phantasia/fight.c | 1586 | ||||
-rw-r--r-- | games/phantasia/gamesupport.c | 945 | ||||
-rw-r--r-- | games/phantasia/include.h | 7 | ||||
-rw-r--r-- | games/phantasia/interplayer.c | 1490 | ||||
-rw-r--r-- | games/phantasia/io.c | 344 | ||||
-rw-r--r-- | games/phantasia/macros.h | 1 | ||||
-rw-r--r-- | games/phantasia/main.c | 1542 | ||||
-rw-r--r-- | games/phantasia/misc.c | 1622 | ||||
-rw-r--r-- | games/phantasia/pathnames.h | 1 | ||||
-rw-r--r-- | games/phantasia/phantasia.6tbl | 1 | ||||
-rw-r--r-- | games/phantasia/phantdefs.h | 3 | ||||
-rw-r--r-- | games/phantasia/phantglobs.c | 88 | ||||
-rw-r--r-- | games/phantasia/phantglobs.h | 159 | ||||
-rw-r--r-- | games/phantasia/phantstruct.h | 1 | ||||
-rw-r--r-- | games/phantasia/setup.c | 33 |
16 files changed, 3876 insertions, 3953 deletions
diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile index 8e26565e94d..e09fc1f4891 100644 --- a/games/phantasia/Makefile +++ b/games/phantasia/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.12 1998/07/24 00:10:36 millert Exp $ +# $OpenBSD: Makefile,v 1.13 1998/11/29 19:56:54 pjanzen Exp $ PROG= phantasia SRCS= main.c fight.c io.c interplayer.c gamesupport.c misc.c phantglobs.c CFLAGS+=-DTERMIOS -DPADD= ${LIBM} ${LIBCURSES} ${LIBCOMPAT} -LDADD= -lm -lcurses -lcompat +DPADD= ${LIBM} ${LIBCURSES} +LDADD= -lm -lcurses HIDEGAME=hidegame MAN= phantasia.6 CLEANFILES+=map setup setup.o phantglobs.o.bld diff --git a/games/phantasia/fight.c b/games/phantasia/fight.c index d60401dfc84..6fd80cd9b3a 100644 --- a/games/phantasia/fight.c +++ b/games/phantasia/fight.c @@ -1,3 +1,4 @@ +/* $OpenBSD: fight.c,v 1.3 1998/11/29 19:56:55 pjanzen Exp $ */ /* $NetBSD: fight.c,v 1.2 1995/03/24 03:58:39 cgd Exp $ */ /* @@ -36,153 +37,153 @@ / *************************************************************************/ +void encounter(particular) -int particular; + int particular; { -bool firsthit = Player.p_blessing; /* set if player gets the first hit */ -int flockcnt = 1; /* how many time flocked */ + bool firsthit = Player.p_blessing; /* set if player gets the + * first hit */ + int flockcnt = 1; /* how many time flocked */ - /* let others know what we are doing */ - Player.p_status = S_MONSTER; - writerecord(&Player, Fileloc); + /* let others know what we are doing */ + Player.p_status = S_MONSTER; + writerecord(&Player, Fileloc); + +#if __GNUC__ + (void)&firsthit; /* XXX shut up gcc */ +#endif #ifdef SYS5 - flushinp(); + flushinp(); #endif - Shield = 0.0; /* no shield up yet */ + Shield = 0.0; /* no shield up yet */ - if (particular >= 0) - /* monster is specified */ - Whichmonster = particular; - else - /* pick random monster */ - Whichmonster = pickmonster(); + if (particular >= 0) + /* monster is specified */ + Whichmonster = particular; + else + /* pick random monster */ + Whichmonster = pickmonster(); - setjmp(Fightenv); /* this is to enable changing fight state */ + setjmp(Fightenv); /* this is to enable changing fight state */ - move(6, 0); - clrtobot(); /* clear bottom area of screen */ + move(6, 0); + clrtobot(); /* clear bottom area of screen */ - Lines = 9; - callmonster(Whichmonster); /* set up monster to fight */ + Lines = 9; + callmonster(Whichmonster); /* set up monster to fight */ - Luckout = FALSE; /* haven't tried to luckout yet */ + Luckout = FALSE; /* haven't tried to luckout yet */ - if (Curmonster.m_type == SM_MORGOTH) - mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n", - Enemyname); + if (Curmonster.m_type == SM_MORGOTH) + mvprintw(4, 0, "You've encountered %s, Bane of the Council and Valar.\n", + Enemyname); + + if (Curmonster.m_type == SM_UNICORN) { + if (Player.p_virgin) { + printw("You just subdued %s, thanks to the virgin.\n", Enemyname); + Player.p_virgin = FALSE; + } else { + printw("You just saw %s running away!\n", Enemyname); + Curmonster.m_experience = 0.0; + Curmonster.m_treasuretype = 0; + } + } else + /* not a special monster */ + for (;;) + /* print header, and arbitrate between player and + * monster */ + { + mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n", + Enemyname, Curmonster.m_experience, Circle); - if (Curmonster.m_type == SM_UNICORN) - { - if (Player.p_virgin) - { - printw("You just subdued %s, thanks to the virgin.\n", Enemyname); - Player.p_virgin = FALSE; - } - else - { - printw("You just saw %s running away!\n", Enemyname); - Curmonster.m_experience = 0.0; - Curmonster.m_treasuretype = 0; - } - } - else - /* not a special monster */ - for (;;) - /* print header, and arbitrate between player and monster */ - { - mvprintw(6, 0, "You are being attacked by %s, EXP: %.0f (Size: %.0f)\n", - Enemyname, Curmonster.m_experience, Circle); + displaystats(); + mvprintw(1, 26, "%20.0f", Player.p_energy + Shield); /* overprint energy */ + readmessage(); - displaystats(); - mvprintw(1, 26, "%20.0f", Player.p_energy + Shield); /* overprint energy */ - readmessage(); + if (Curmonster.m_type == SM_DARKLORD + && Player.p_blessing + && Player.p_charms > 0) + /* overpower Dark Lord with blessing and charm */ + { + mvprintw(7, 0, "You just overpowered %s!", Enemyname); + Lines = 8; + Player.p_blessing = FALSE; + --Player.p_charms; + break; + } + /* allow paralyzed monster to wake up */ + Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed); + + if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed + /* monster is faster */ + && Curmonster.m_type != SM_DARKLORD + /* not D. L. */ + && Curmonster.m_type != SM_SHRIEKER + /* not mimic */ + && !firsthit) + /* monster gets a hit */ + monsthits(); + else + /* player gets a hit */ + { + firsthit = FALSE; + playerhits(); + } - if (Curmonster.m_type == SM_DARKLORD - && Player.p_blessing - && Player.p_charms > 0) - /* overpower Dark Lord with blessing and charm */ - { - mvprintw(7, 0, "You just overpowered %s!", Enemyname); - Lines = 8; - Player.p_blessing = FALSE; - --Player.p_charms; - break; - } + refresh(); - /* allow paralyzed monster to wake up */ - Curmonster.m_speed = MIN(Curmonster.m_speed + 1.0, Curmonster.m_maxspeed); - - if (drandom() * Curmonster.m_speed > drandom() * Player.p_speed - /* monster is faster */ - && Curmonster.m_type != SM_DARKLORD - /* not D. L. */ - && Curmonster.m_type != SM_SHRIEKER - /* not mimic */ - && !firsthit) - /* monster gets a hit */ - monsthits(); - else - /* player gets a hit */ - { - firsthit = FALSE; - playerhits(); + if (Lines > LINES - 2) + /* near bottom of screen - pause */ + { + more(Lines); + move(Lines = 8, 0); + clrtobot(); + } + if (Player.p_energy <= 0.0) + /* player died */ + { + more(Lines); + death(Enemyname); + cancelmonster(); + break; /* fight ends if the player is saved + * from death */ + } + if (Curmonster.m_energy <= 0.0) + /* monster died */ + break; } - refresh(); + /* give player credit for killing monster */ + Player.p_experience += Curmonster.m_experience; - if (Lines > LINES - 2) - /* near bottom of screen - pause */ - { + if (drandom() < Curmonster.m_flock / 100.0) + /* monster flocks */ + { more(Lines); - move(Lines = 8, 0); - clrtobot(); - } - - if (Player.p_energy <= 0.0) - /* player died */ + ++flockcnt; + longjmp(Fightenv, 0); + /* NOTREACHED */ + } else + if (Circle > 1.0 + && Curmonster.m_treasuretype > 0 + && drandom() > 0.2 + pow(0.4, (double) (flockcnt / 3 + Circle / 3.0))) + /* monster has treasure; this takes # of flocks and + * size into account */ { - more(Lines); - death(Enemyname); - cancelmonster(); - break; /* fight ends if the player is saved from death */ + more(Lines); + awardtreasure(); } + /* pause before returning */ + getyx(stdscr, Lines, flockcnt); + more(Lines + 1); - if (Curmonster.m_energy <= 0.0) - /* monster died */ - break; - } + Player.p_ring.ring_inuse = FALSE; /* not using ring */ - /* give player credit for killing monster */ - Player.p_experience += Curmonster.m_experience; - - if (drandom() < Curmonster.m_flock / 100.0) - /* monster flocks */ - { - more(Lines); - ++flockcnt; - longjmp(Fightenv, 0); - /*NOTREACHED*/ - } - else if (Circle > 1.0 - && Curmonster.m_treasuretype > 0 - && drandom() > 0.2 + pow(0.4, (double) (flockcnt / 3 + Circle / 3.0))) - /* monster has treasure; this takes # of flocks and size into account */ - { - more(Lines); - awardtreasure(); - } - - /* pause before returning */ - getyx(stdscr, Lines, flockcnt); - more(Lines + 1); - - Player.p_ring.ring_inuse = FALSE; /* not using ring */ - - /* clean up the screen */ - move(4, 0); - clrtobot(); + /* clean up the screen */ + move(4, 0); + clrtobot(); } /**/ /************************************************************************ @@ -213,35 +214,36 @@ int flockcnt = 1; /* how many time flocked */ / *************************************************************************/ +int pickmonster() { - if (Player.p_specialtype == SC_VALAR) - /* even chance of any monster */ - return((int) ROLL(0.0, 100.0)); + if (Player.p_specialtype == SC_VALAR) + /* even chance of any monster */ + return ((int) ROLL(0.0, 100.0)); - if (Marsh) - /* water monsters */ - return((int) ROLL(0.0, 15.0)); + if (Marsh) + /* water monsters */ + return ((int) ROLL(0.0, 15.0)); - else if (Circle > 24) - /* even chance of all non-water monsters */ - return((int) ROLL(14.0, 86.0)); + else if (Circle > 24) + /* even chance of all non-water monsters */ + return ((int) ROLL(14.0, 86.0)); - else if (Circle > 15) - /* chance of all non-water monsters, weighted toward middle */ - return((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0))); + else if (Circle > 15) + /* chance of all non-water monsters, weighted toward middle */ + return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 37.0))); - else if (Circle > 8) - /* not all non-water monsters, weighted toward middle */ - return((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0))); + else if (Circle > 8) + /* not all non-water monsters, weighted toward middle */ + return ((int) (ROLL(0.0, 50.0) + ROLL(14.0, 26.0))); - else if (Circle > 3) - /* even chance of some tamer non-water monsters */ - return((int) ROLL(14.0, 50.0)); + else if (Circle > 3) + /* even chance of some tamer non-water monsters */ + return ((int) ROLL(14.0, 50.0)); - else - /* even chance of some of the tamest non-water monsters */ - return((int) ROLL(14.0, 25.0)); + else + /* even chance of some of the tamest non-water monsters */ + return ((int) ROLL(14.0, 25.0)); } /**/ /************************************************************************ @@ -269,152 +271,145 @@ pickmonster() / *************************************************************************/ +void playerhits() { -double inflict; /* damage inflicted */ -int ch; /* input */ + double inflict; /* damage inflicted */ + int ch; /* input */ - mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick "); + mvaddstr(7, 0, "1:Melee 2:Skirmish 3:Evade 4:Spell 5:Nick "); - if (!Luckout) - /* haven't tried to luckout yet */ - if (Curmonster.m_type == SM_MORGOTH) - /* cannot luckout against Morgoth */ - addstr("6:Ally "); - else - addstr("6:Luckout "); + if (!Luckout) { + /* haven't tried to luckout yet */ + if (Curmonster.m_type == SM_MORGOTH) + /* cannot luckout against Morgoth */ + addstr("6:Ally "); + else + addstr("6:Luckout "); + } - if (Player.p_ring.ring_type != R_NONE) - /* player has a ring */ - addstr("7:Use Ring "); - else - clrtoeol(); + if (Player.p_ring.ring_type != R_NONE) + /* player has a ring */ + addstr("7:Use Ring "); + else + clrtoeol(); - ch = inputoption(); + ch = inputoption(); - move(8, 0); - clrtobot(); /* clear any messages from before */ - Lines = 9; - mvaddstr(4, 0, "\n\n"); /* clear status area */ + move(8, 0); + clrtobot(); /* clear any messages from before */ + Lines = 9; + mvaddstr(4, 0, "\n\n"); /* clear status area */ - switch (ch) - { + switch (ch) { case 'T': /* timeout; lose turn */ - break; + break; case ' ': case '1': /* melee */ - /* melee affects monster's energy and strength */ - inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might) - + (Player.p_ring.ring_inuse ? Player.p_might : 0.0); - - Curmonster.m_melee += inflict; - Curmonster.m_strength = Curmonster.m_o_strength - - Curmonster.m_melee / Curmonster.m_o_energy - * Curmonster.m_o_strength / 4.0; - hitmonster(inflict); - break; + /* melee affects monster's energy and strength */ + inflict = ROLL(Player.p_might / 2.0 + 5.0, 1.3 * Player.p_might) + + (Player.p_ring.ring_inuse ? Player.p_might : 0.0); + + Curmonster.m_melee += inflict; + Curmonster.m_strength = Curmonster.m_o_strength + - Curmonster.m_melee / Curmonster.m_o_energy + * Curmonster.m_o_strength / 4.0; + hitmonster(inflict); + break; case '2': /* skirmish */ - /* skirmish affects monter's energy and speed */ - inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might) - + (Player.p_ring.ring_inuse ? Player.p_might : 0.0); - - Curmonster.m_skirmish += inflict; - Curmonster.m_maxspeed = Curmonster.m_o_speed - - Curmonster.m_skirmish / Curmonster.m_o_energy - * Curmonster.m_o_speed / 4.0; - hitmonster(inflict); - break; + /* skirmish affects monter's energy and speed */ + inflict = ROLL(Player.p_might / 3.0 + 3.0, 1.1 * Player.p_might) + + (Player.p_ring.ring_inuse ? Player.p_might : 0.0); + + Curmonster.m_skirmish += inflict; + Curmonster.m_maxspeed = Curmonster.m_o_speed + - Curmonster.m_skirmish / Curmonster.m_o_energy + * Curmonster.m_o_speed / 4.0; + hitmonster(inflict); + break; case '3': /* evade */ - /* use brains and speed to try to evade */ - if ((Curmonster.m_type == SM_DARKLORD - || Curmonster.m_type == SM_SHRIEKER + /* use brains and speed to try to evade */ + if ((Curmonster.m_type == SM_DARKLORD + || Curmonster.m_type == SM_SHRIEKER /* can always run from D. L. and shrieker */ - || drandom() * Player.p_speed * Player.p_brains - > drandom() * Curmonster.m_speed * Curmonster.m_brains) - && (Curmonster.m_type != SM_MIMIC)) - /* cannot run from mimic */ + || drandom() * Player.p_speed * Player.p_brains + > drandom() * Curmonster.m_speed * Curmonster.m_brains) + && (Curmonster.m_type != SM_MIMIC)) + /* cannot run from mimic */ { - mvaddstr(Lines++, 0, "You got away!"); - cancelmonster(); - altercoordinates(0.0, 0.0, A_NEAR); - } - else - mvprintw(Lines++, 0, "%s is still after you!", Enemyname); + mvaddstr(Lines++, 0, "You got away!"); + cancelmonster(); + altercoordinates(0.0, 0.0, A_NEAR); + } else + mvprintw(Lines++, 0, "%s is still after you!", Enemyname); - break; + break; case 'M': case '4': /* magic spell */ - throwspell(); - break; + throwspell(); + break; case '5': /* nick */ - /* hit 1 plus sword; give some experience */ - inflict = 1.0 + Player.p_sword; - Player.p_experience += floor(Curmonster.m_experience / 10.0); - Curmonster.m_experience *= 0.92; - /* monster gets meaner */ - Curmonster.m_maxspeed += 2.0; - Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0; - if (Curmonster.m_type == SM_DARKLORD) - /* Dark Lord; doesn't like to be nicked */ + /* hit 1 plus sword; give some experience */ + inflict = 1.0 + Player.p_sword; + Player.p_experience += floor(Curmonster.m_experience / 10.0); + Curmonster.m_experience *= 0.92; + /* monster gets meaner */ + Curmonster.m_maxspeed += 2.0; + Curmonster.m_speed = (Curmonster.m_speed < 0.0) ? 0.0 : Curmonster.m_speed + 2.0; + if (Curmonster.m_type == SM_DARKLORD) + /* Dark Lord; doesn't like to be nicked */ { - mvprintw(Lines++, 0, - "You hit %s %.0f times, and made him mad!", Enemyname, inflict); - Player.p_quickness /= 2.0; - altercoordinates(0.0, 0.0, A_FAR); - cancelmonster(); - } - else - hitmonster(inflict); - break; + mvprintw(Lines++, 0, + "You hit %s %.0f times, and made him mad!", Enemyname, inflict); + Player.p_quickness /= 2.0; + altercoordinates(0.0, 0.0, A_FAR); + cancelmonster(); + } else + hitmonster(inflict); + break; case 'B': - case '6': /* luckout */ - if (Luckout) - mvaddstr(Lines++, 0, "You already tried that."); - else - { - Luckout = TRUE; - if (Curmonster.m_type == SM_MORGOTH) - /* Morgoth; ally */ - { - if (drandom() < Player.p_sin / 100.0) + case '6': /* luckout */ + if (Luckout) + mvaddstr(Lines++, 0, "You already tried that."); + else { + Luckout = TRUE; + if (Curmonster.m_type == SM_MORGOTH) + /* Morgoth; ally */ { - mvprintw(Lines++, 0, "%s accepted!", Enemyname); - cancelmonster(); - } - else - mvaddstr(Lines++, 0, "Nope, he's not interested."); - } - else - /* normal monster; use brains for success */ - { - if ((drandom() + 0.333) * Player.p_brains - < (drandom() + 0.333) * Curmonster.m_brains) - mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name); - else + if (drandom() < Player.p_sin / 100.0) { + mvprintw(Lines++, 0, "%s accepted!", Enemyname); + cancelmonster(); + } else + mvaddstr(Lines++, 0, "Nope, he's not interested."); + } else + /* normal monster; use brains for success */ { - mvaddstr(Lines++, 0, "You made it!"); - Curmonster.m_energy = 0.0; + if ((drandom() + 0.333) * Player.p_brains + < (drandom() + 0.333) * Curmonster.m_brains) + mvprintw(Lines++, 0, "You blew it, %s.", Player.p_name); + else { + mvaddstr(Lines++, 0, "You made it!"); + Curmonster.m_energy = 0.0; + } } - } } - break; + break; case '7': /* use ring */ - if (Player.p_ring.ring_type != R_NONE) - { - mvaddstr(Lines++, 0, "Now using ring."); - Player.p_ring.ring_inuse = TRUE; - if (Player.p_ring.ring_type != R_DLREG) - /* age ring */ - --Player.p_ring.ring_duration; + if (Player.p_ring.ring_type != R_NONE) { + mvaddstr(Lines++, 0, "Now using ring."); + Player.p_ring.ring_inuse = TRUE; + if (Player.p_ring.ring_type != R_DLREG) + /* age ring */ + --Player.p_ring.ring_duration; } - break; + break; } } @@ -447,256 +442,253 @@ int ch; /* input */ / *************************************************************************/ +void monsthits() { -double inflict; /* damage inflicted */ -int ch; /* input */ + double inflict; /* damage inflicted */ + int ch; /* input */ - switch (Curmonster.m_type) - /* may be a special monster */ + switch (Curmonster.m_type) + /* may be a special monster */ { case SM_DARKLORD: - /* hits just enough to kill player */ - inflict = (Player.p_energy + Shield) * 1.02; - goto SPECIALHIT; + /* hits just enough to kill player */ + inflict = (Player.p_energy + Shield) * 1.02; + goto SPECIALHIT; case SM_SHRIEKER: - /* call a big monster */ - mvaddstr(Lines++, 0, - "Shrieeeek!! You scared it, and it called one of its friends."); - more(Lines); - Whichmonster = (int) ROLL(70.0, 30.0); - longjmp(Fightenv, 0); - /*NOTREACHED*/ + /* call a big monster */ + mvaddstr(Lines++, 0, + "Shrieeeek!! You scared it, and it called one of its friends."); + more(Lines); + Whichmonster = (int) ROLL(70.0, 30.0); + longjmp(Fightenv, 0); + /* NOTREACHED */ case SM_BALROG: - /* take experience away */ - inflict = ROLL(10.0, Curmonster.m_strength); - inflict = MIN(Player.p_experience, inflict); - mvprintw(Lines++, 0, - "%s took away %.0f experience points.", Enemyname, inflict); - Player.p_experience -= inflict; - return; + /* take experience away */ + inflict = ROLL(10.0, Curmonster.m_strength); + inflict = MIN(Player.p_experience, inflict); + mvprintw(Lines++, 0, + "%s took away %.0f experience points.", Enemyname, inflict); + Player.p_experience -= inflict; + return; case SM_FAERIES: - if (Player.p_holywater > 0) - /* holy water kills when monster tries to hit */ + if (Player.p_holywater > 0) + /* holy water kills when monster tries to hit */ { - mvprintw(Lines++, 0, "Your holy water killed it!"); - --Player.p_holywater; - Curmonster.m_energy = 0.0; - return; + mvprintw(Lines++, 0, "Your holy water killed it!"); + --Player.p_holywater; + Curmonster.m_energy = 0.0; + return; } - break; + break; case SM_NONE: - /* normal hit */ - break; - - default: - if (drandom() > 0.2) /* normal hit */ break; - /* else special things */ - switch (Curmonster.m_type) - { + default: + if (drandom() > 0.2) + /* normal hit */ + break; + + /* else special things */ + switch (Curmonster.m_type) { case SM_LEANAN: - /* takes some of the player's strength */ - inflict = ROLL(1.0, (Circle - 1.0) / 2.0); - inflict = MIN(Player.p_strength, inflict); - mvprintw(Lines++, 0, "%s sapped %0.f of your strength!", - Enemyname, inflict); - Player.p_strength -= inflict; - Player.p_might -= inflict; - break; + /* takes some of the player's strength */ + inflict = ROLL(1.0, (Circle - 1.0) / 2.0); + inflict = MIN(Player.p_strength, inflict); + mvprintw(Lines++, 0, "%s sapped %0.f of your strength!", + Enemyname, inflict); + Player.p_strength -= inflict; + Player.p_might -= inflict; + break; case SM_SARUMAN: - if (Player.p_palantir) - /* take away palantir */ - { - mvprintw(Lines++, 0, "Wormtongue stole your palantir!"); - Player.p_palantir = FALSE; - } - else if (drandom() > 0.5) - /* gems turn to gold */ - { - mvprintw(Lines++, 0, - "%s transformed your gems into gold!", Enemyname); - Player.p_gold += Player.p_gems; - Player.p_gems = 0.0; - } - else - /* scramble some stats */ + if (Player.p_palantir) + /* take away palantir */ { - mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname); - scramblestats(); - } - break; + mvprintw(Lines++, 0, "Wormtongue stole your palantir!"); + Player.p_palantir = FALSE; + } else + if (drandom() > 0.5) + /* gems turn to gold */ + { + mvprintw(Lines++, 0, + "%s transformed your gems into gold!", Enemyname); + Player.p_gold += Player.p_gems; + Player.p_gems = 0.0; + } else + /* scramble some stats */ + { + mvprintw(Lines++, 0, "%s scrambled your stats!", Enemyname); + scramblestats(); + } + break; case SM_THAUMATURG: - /* transport player */ - mvprintw(Lines++, 0, "%s transported you!", Enemyname); - altercoordinates(0.0, 0.0, A_FAR); - cancelmonster(); - break; + /* transport player */ + mvprintw(Lines++, 0, "%s transported you!", Enemyname); + altercoordinates(0.0, 0.0, A_FAR); + cancelmonster(); + break; case SM_VORTEX: - /* suck up some mana */ - inflict = ROLL(0, 7.5 * Circle); - inflict = MIN(Player.p_mana, floor(inflict)); - mvprintw(Lines++, 0, - "%s sucked up %.0f of your mana!", Enemyname, inflict); - Player.p_mana -= inflict; - break; + /* suck up some mana */ + inflict = ROLL(0, 7.5 * Circle); + inflict = MIN(Player.p_mana, floor(inflict)); + mvprintw(Lines++, 0, + "%s sucked up %.0f of your mana!", Enemyname, inflict); + Player.p_mana -= inflict; + break; case SM_NAZGUL: - /* try to take ring if player has one */ - if (Player.p_ring.ring_type != R_NONE) - /* player has a ring */ + /* try to take ring if player has one */ + if (Player.p_ring.ring_type != R_NONE) + /* player has a ring */ { - mvaddstr(Lines++, 0, "Will you relinguish your ring ? "); - ch = getanswer("YN", FALSE); - if (ch == 'Y') - /* take ring away */ - { - Player.p_ring.ring_type = R_NONE; - Player.p_ring.ring_inuse = FALSE; - cancelmonster(); - break; - } + mvaddstr(Lines++, 0, "Will you relinguish your ring ? "); + ch = getanswer("YN", FALSE); + if (ch == 'Y') + /* take ring away */ + { + Player.p_ring.ring_type = R_NONE; + Player.p_ring.ring_inuse = FALSE; + cancelmonster(); + break; + } } - - /* otherwise, take some brains */ - mvprintw(Lines++, 0, - "%s neutralized 1/5 of your brain!", Enemyname); - Player.p_brains *= 0.8; - break; + /* otherwise, take some brains */ + mvprintw(Lines++, 0, + "%s neutralized 1/5 of your brain!", Enemyname); + Player.p_brains *= 0.8; + break; case SM_TIAMAT: - /* take some gold and gems */ - mvprintw(Lines++, 0, - "%s took half your gold and gems and flew off.", Enemyname); - Player.p_gold /= 2.0; - Player.p_gems /= 2.0; - cancelmonster(); - break; + /* take some gold and gems */ + mvprintw(Lines++, 0, + "%s took half your gold and gems and flew off.", Enemyname); + Player.p_gold /= 2.0; + Player.p_gems /= 2.0; + cancelmonster(); + break; case SM_KOBOLD: - /* steal a gold piece and run */ - mvprintw(Lines++, 0, - "%s stole one gold piece and ran away.", Enemyname); - Player.p_gold = MAX(0.0, Player.p_gold - 1.0); - cancelmonster(); - break; + /* steal a gold piece and run */ + mvprintw(Lines++, 0, + "%s stole one gold piece and ran away.", Enemyname); + Player.p_gold = MAX(0.0, Player.p_gold - 1.0); + cancelmonster(); + break; case SM_SHELOB: - /* bite and (medium) poison */ - mvprintw(Lines++, 0, - "%s has bitten and poisoned you!", Enemyname); - Player.p_poison -= 1.0; - break; + /* bite and (medium) poison */ + mvprintw(Lines++, 0, + "%s has bitten and poisoned you!", Enemyname); + Player.p_poison -= 1.0; + break; case SM_LAMPREY: - /* bite and (small) poison */ - mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname); - Player.p_poison += 0.25; - break; + /* bite and (small) poison */ + mvprintw(Lines++, 0, "%s bit and poisoned you!", Enemyname); + Player.p_poison += 0.25; + break; case SM_BONNACON: - /* fart and run */ - mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname); - Player.p_energy /= 2.0; /* damage from fumes */ - cancelmonster(); - break; + /* fart and run */ + mvprintw(Lines++, 0, "%s farted and scampered off.", Enemyname); + Player.p_energy /= 2.0; /* damage from fumes */ + cancelmonster(); + break; case SM_SMEAGOL: - if (Player.p_ring.ring_type != R_NONE) - /* try to steal ring */ + if (Player.p_ring.ring_type != R_NONE) + /* try to steal ring */ { - mvprintw(Lines++, 0, - "%s tried to steal your ring, ", Enemyname); - if (drandom() > 0.1) - addstr("but was unsuccessful."); - else - { - addstr("and ran away with it!"); - Player.p_ring.ring_type = R_NONE; - cancelmonster(); - } + mvprintw(Lines++, 0, + "%s tried to steal your ring, ", Enemyname); + if (drandom() > 0.1) + addstr("but was unsuccessful."); + else { + addstr("and ran away with it!"); + Player.p_ring.ring_type = R_NONE; + cancelmonster(); + } } - break; + break; case SM_SUCCUBUS: - /* inflict damage through shield */ - inflict = ROLL(15.0, Circle * 10.0); - inflict = MIN(inflict, Player.p_energy); - mvprintw(Lines++, 0, "%s sapped %.0f of your energy.", - Enemyname, inflict); - Player.p_energy -= inflict; - break; + /* inflict damage through shield */ + inflict = ROLL(15.0, Circle * 10.0); + inflict = MIN(inflict, Player.p_energy); + mvprintw(Lines++, 0, "%s sapped %.0f of your energy.", + Enemyname, inflict); + Player.p_energy -= inflict; + break; case SM_CERBERUS: - /* take all metal treasures */ - mvprintw(Lines++, 0, - "%s took all your metal treasures!", Enemyname); - Player.p_crowns = 0; - Player.p_sword = - Player.p_shield = - Player.p_gold = 0.0; - cancelmonster(); - break; + /* take all metal treasures */ + mvprintw(Lines++, 0, + "%s took all your metal treasures!", Enemyname); + Player.p_crowns = 0; + Player.p_sword = + Player.p_shield = + Player.p_gold = 0.0; + cancelmonster(); + break; case SM_UNGOLIANT: - /* (large) poison and take a quickness */ - mvprintw(Lines++, 0, - "%s poisoned you, and took one quik.", Enemyname); - Player.p_poison += 5.0; - Player.p_quickness -= 1.0; - break; + /* (large) poison and take a quickness */ + mvprintw(Lines++, 0, + "%s poisoned you, and took one quik.", Enemyname); + Player.p_poison += 5.0; + Player.p_quickness -= 1.0; + break; case SM_JABBERWOCK: - /* fly away, and leave either a Jubjub bird or Bonnacon */ - mvprintw(Lines++, 0, - "%s flew away, and left you to contend with one of its friends.", - Enemyname); - Whichmonster = 55 + (drandom() > 0.5) ? 22 : 0; - longjmp(Fightenv, 0); - /*NOTREACHED*/ + /* fly away, and leave either a Jubjub bird or + * Bonnacon */ + mvprintw(Lines++, 0, + "%s flew away, and left you to contend with one of its friends.", + Enemyname); + Whichmonster = 55 + (drandom() > 0.5) ? 22 : 0; + longjmp(Fightenv, 0); + /* NOTREACHED */ case SM_TROLL: - /* partially regenerate monster */ - mvprintw(Lines++, 0, - "%s partially regenerated his energy.!", Enemyname); - Curmonster.m_energy += - floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0); - Curmonster.m_strength = Curmonster.m_o_strength; - Curmonster.m_melee = Curmonster.m_skirmish = 0.0; - Curmonster.m_maxspeed = Curmonster.m_o_speed; - break; + /* partially regenerate monster */ + mvprintw(Lines++, 0, + "%s partially regenerated his energy.!", Enemyname); + Curmonster.m_energy += + floor((Curmonster.m_o_energy - Curmonster.m_energy) / 2.0); + Curmonster.m_strength = Curmonster.m_o_strength; + Curmonster.m_melee = Curmonster.m_skirmish = 0.0; + Curmonster.m_maxspeed = Curmonster.m_o_speed; + break; case SM_WRAITH: - if (!Player.p_blindness) - /* make blind */ + if (!Player.p_blindness) + /* make blind */ { - mvprintw(Lines++, 0, "%s blinded you!", Enemyname); - Player.p_blindness = TRUE; - Enemyname = "A monster"; + mvprintw(Lines++, 0, "%s blinded you!", Enemyname); + Player.p_blindness = TRUE; + Enemyname = "A monster"; } - break; + break; } - return; + return; } - /* fall through to here if monster inflicts a normal hit */ - inflict = drandom() * Curmonster.m_strength + 0.5; + /* fall through to here if monster inflicts a normal hit */ + inflict = drandom() * Curmonster.m_strength + 0.5; SPECIALHIT: - mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict); + mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, inflict); - if ((Shield -= inflict) < 0) - { - Player.p_energy += Shield; - Shield = 0.0; + if ((Shield -= inflict) < 0) { + Player.p_energy += Shield; + Shield = 0.0; } } /**/ @@ -724,6 +716,7 @@ SPECIALHIT: / *************************************************************************/ +void cancelmonster() { Curmonster.m_energy = 0.0; @@ -757,32 +750,31 @@ cancelmonster() / *************************************************************************/ +void hitmonster(inflict) -double inflict; + double inflict; { - mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict); - Curmonster.m_energy -= inflict; - if (Curmonster.m_energy > 0.0) + mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict); + Curmonster.m_energy -= inflict; + if (Curmonster.m_energy > 0.0) { + if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER) + /* special monster didn't die */ + monsthits(); + } else + /* monster died. print message. */ { - if (Curmonster.m_type == SM_DARKLORD || Curmonster.m_type == SM_SHRIEKER) - /* special monster didn't die */ - monsthits(); - } - else - /* monster died. print message. */ - { - if (Curmonster.m_type == SM_MORGOTH) - mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . ."); - else - /* all other types of monsters */ - { - mvprintw(Lines++, 0, "You killed it. Good work, %s.", Player.p_name); + if (Curmonster.m_type == SM_MORGOTH) + mvaddstr(Lines++, 0, "You have defeated Morgoth, but he may return. . ."); + else + /* all other types of monsters */ + { + mvprintw(Lines++, 0, "You killed it. Good work, %s.", Player.p_name); - if (Curmonster.m_type == SM_MIMIC - && strcmp(Curmonster.m_name, "A Mimic") != 0 - && !Player.p_blindness) - mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic."); - } + if (Curmonster.m_type == SM_MIMIC + && strcmp(Curmonster.m_name, "A Mimic") != 0 + && !Player.p_blindness) + mvaddstr(Lines++, 0, "The body slowly changes into the form of a mimic."); + } } } /**/ @@ -812,216 +804,207 @@ double inflict; / *************************************************************************/ +void throwspell() { -double inflict; /* damage inflicted */ -double dtemp; /* for dtemporary calculations */ -int ch; /* input */ - - mvaddstr(7, 0, "\n\n"); /* clear menu area */ - - if (Player.p_magiclvl >= ML_ALLORNOTHING) - mvaddstr(7, 0, "1:All or Nothing "); - if (Player.p_magiclvl >= ML_MAGICBOLT) - addstr("2:Magic Bolt "); - if (Player.p_magiclvl >= ML_FORCEFIELD) - addstr("3:Force Field "); - if (Player.p_magiclvl >= ML_XFORM) - addstr("4:Transform "); - if (Player.p_magiclvl >= ML_INCRMIGHT) - addstr("5:Increase Might\n"); - if (Player.p_magiclvl >= ML_INVISIBLE) - mvaddstr(8, 0, "6:Invisibility "); - if (Player.p_magiclvl >= ML_XPORT) - addstr("7:Transport "); - if (Player.p_magiclvl >= ML_PARALYZE) - addstr("8:Paralyze "); - if (Player.p_specialtype >= SC_COUNCIL) - addstr("9:Specify"); - mvaddstr(4, 0, "Spell ? "); - - ch = getanswer(" ", TRUE); - - mvaddstr(7, 0, "\n\n"); /* clear menu area */ - - if (Curmonster.m_type == SM_MORGOTH && ch != '3') - /* can only throw force field against Morgoth */ - ILLSPELL(); - else - switch (ch) - { - case '1': /* all or nothing */ - if (drandom() < 0.25) - /* success */ - { - inflict = Curmonster.m_energy * 1.01 + 1.0; - - if (Curmonster.m_type == SM_DARKLORD) - /* all or nothing doesn't quite work against D. L. */ - inflict *= 0.9; - } - else - /* failure -- monster gets stronger and quicker */ - { - Curmonster.m_o_strength = Curmonster.m_strength *= 2.0; - Curmonster.m_maxspeed *= 2.0; - Curmonster.m_o_speed *= 2.0; - - /* paralyzed monsters wake up a bit */ - Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0); - } + double inflict; /* damage inflicted */ + double dtemp; /* for dtemporary calculations */ + int ch; /* input */ + + inflict = 0; + mvaddstr(7, 0, "\n\n"); /* clear menu area */ + + if (Player.p_magiclvl >= ML_ALLORNOTHING) + mvaddstr(7, 0, "1:All or Nothing "); + if (Player.p_magiclvl >= ML_MAGICBOLT) + addstr("2:Magic Bolt "); + if (Player.p_magiclvl >= ML_FORCEFIELD) + addstr("3:Force Field "); + if (Player.p_magiclvl >= ML_XFORM) + addstr("4:Transform "); + if (Player.p_magiclvl >= ML_INCRMIGHT) + addstr("5:Increase Might\n"); + if (Player.p_magiclvl >= ML_INVISIBLE) + mvaddstr(8, 0, "6:Invisibility "); + if (Player.p_magiclvl >= ML_XPORT) + addstr("7:Transport "); + if (Player.p_magiclvl >= ML_PARALYZE) + addstr("8:Paralyze "); + if (Player.p_specialtype >= SC_COUNCIL) + addstr("9:Specify"); + mvaddstr(4, 0, "Spell ? "); + + ch = getanswer(" ", TRUE); + + mvaddstr(7, 0, "\n\n"); /* clear menu area */ + + if (Curmonster.m_type == SM_MORGOTH && ch != '3') + /* can only throw force field against Morgoth */ + ILLSPELL(); + else + switch (ch) { + case '1': /* all or nothing */ + if (drandom() < 0.25) + /* success */ + { + inflict = Curmonster.m_energy * 1.01 + 1.0; + + if (Curmonster.m_type == SM_DARKLORD) + /* all or nothing doesn't quite work + * against D. L. */ + inflict *= 0.9; + } else + /* failure -- monster gets stronger and + * quicker */ + { + Curmonster.m_o_strength = Curmonster.m_strength *= 2.0; + Curmonster.m_maxspeed *= 2.0; + Curmonster.m_o_speed *= 2.0; - if (Player.p_mana >= MM_ALLORNOTHING) - /* take a mana if player has one */ - Player.p_mana -= MM_ALLORNOTHING; + /* paralyzed monsters wake up a bit */ + Curmonster.m_speed = MAX(1.0, Curmonster.m_speed * 2.0); + } - hitmonster(inflict); - break; + if (Player.p_mana >= MM_ALLORNOTHING) + /* take a mana if player has one */ + Player.p_mana -= MM_ALLORNOTHING; - case '2': /* magic bolt */ - if (Player.p_magiclvl < ML_MAGICBOLT) - ILLSPELL(); - else - { - do - /* prompt for amount to expend */ - { - mvaddstr(4, 0, "How much mana for bolt? "); - dtemp = floor(infloat()); - } - while (dtemp < 0.0 || dtemp > Player.p_mana); + hitmonster(inflict); + break; - Player.p_mana -= dtemp; + case '2': /* magic bolt */ + if (Player.p_magiclvl < ML_MAGICBOLT) + ILLSPELL(); + else { + do + /* prompt for amount to expend */ + { + mvaddstr(4, 0, "How much mana for bolt? "); + dtemp = floor(infloat()); + } + while (dtemp < 0.0 || dtemp > Player.p_mana); - if (Curmonster.m_type == SM_DARKLORD) - /* magic bolts don't work against D. L. */ - inflict = 0.0; - else - inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0)); - mvaddstr(5, 0, "Magic Bolt fired!\n"); - hitmonster(inflict); - } - break; + Player.p_mana -= dtemp; - case '3': /* force field */ - if (Player.p_magiclvl < ML_FORCEFIELD) - ILLSPELL(); - else if (Player.p_mana < MM_FORCEFIELD) - NOMANA(); - else - { - Player.p_mana -= MM_FORCEFIELD; - Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0; - mvaddstr(5, 0, "Force Field up.\n"); - } - break; + if (Curmonster.m_type == SM_DARKLORD) + /* magic bolts don't work against D. + * L. */ + inflict = 0.0; + else + inflict = dtemp * ROLL(15.0, sqrt(Player.p_magiclvl / 3.0 + 1.0)); + mvaddstr(5, 0, "Magic Bolt fired!\n"); + hitmonster(inflict); + } + break; - case '4': /* transform */ - if (Player.p_magiclvl < ML_XFORM) - ILLSPELL(); - else if (Player.p_mana < MM_XFORM) - NOMANA(); - else - { - Player.p_mana -= MM_XFORM; - Whichmonster = (int) ROLL(0.0, 100.0); - longjmp(Fightenv, 0); - /*NOTREACHED*/ - } - break; + case '3': /* force field */ + if (Player.p_magiclvl < ML_FORCEFIELD) + ILLSPELL(); + else if (Player.p_mana < MM_FORCEFIELD) + NOMANA(); + else { + Player.p_mana -= MM_FORCEFIELD; + Shield = (Player.p_maxenergy + Player.p_shield) * 4.2 + 45.0; + mvaddstr(5, 0, "Force Field up.\n"); + } + break; - case '5': /* increase might */ - if (Player.p_magiclvl < ML_INCRMIGHT) - ILLSPELL(); - else if (Player.p_mana < MM_INCRMIGHT) - NOMANA(); - else - { - Player.p_mana -= MM_INCRMIGHT; - Player.p_might += - (1.2 * (Player.p_strength + Player.p_sword) - + 5.0 - Player.p_might) / 2.0; - mvprintw(5, 0, "New strength: %.0f\n", Player.p_might); - } - break; + case '4': /* transform */ + if (Player.p_magiclvl < ML_XFORM) + ILLSPELL(); + else if (Player.p_mana < MM_XFORM) + NOMANA(); + else { + Player.p_mana -= MM_XFORM; + Whichmonster = (int) ROLL(0.0, 100.0); + longjmp(Fightenv, 0); + /* NOTREACHED */ + } + break; - case '6': /* invisible */ - if (Player.p_magiclvl < ML_INVISIBLE) - ILLSPELL(); - else if (Player.p_mana < MM_INVISIBLE) - NOMANA(); - else - { - Player.p_mana -= MM_INVISIBLE; - Player.p_speed += - (1.2 * (Player.p_quickness + Player.p_quksilver) - + 5.0 - Player.p_speed) / 2.0; - mvprintw(5, 0, "New quickness: %.0f\n", Player.p_speed); - } - break; + case '5': /* increase might */ + if (Player.p_magiclvl < ML_INCRMIGHT) + ILLSPELL(); + else if (Player.p_mana < MM_INCRMIGHT) + NOMANA(); + else { + Player.p_mana -= MM_INCRMIGHT; + Player.p_might += + (1.2 * (Player.p_strength + Player.p_sword) + + 5.0 - Player.p_might) / 2.0; + mvprintw(5, 0, "New strength: %.0f\n", Player.p_might); + } + break; - case '7': /* transport */ - if (Player.p_magiclvl < ML_XPORT) - ILLSPELL(); - else if (Player.p_mana < MM_XPORT) - NOMANA(); - else - { - Player.p_mana -= MM_XPORT; - if (Player.p_brains + Player.p_magiclvl - < Curmonster.m_experience / 200.0 * drandom()) - { - mvaddstr(5, 0, "Transport backfired!\n"); - altercoordinates(0.0, 0.0, A_FAR); - cancelmonster(); + case '6': /* invisible */ + if (Player.p_magiclvl < ML_INVISIBLE) + ILLSPELL(); + else if (Player.p_mana < MM_INVISIBLE) + NOMANA(); + else { + Player.p_mana -= MM_INVISIBLE; + Player.p_speed += + (1.2 * (Player.p_quickness + Player.p_quksilver) + + 5.0 - Player.p_speed) / 2.0; + mvprintw(5, 0, "New quickness: %.0f\n", Player.p_speed); } - else - { - mvprintw(5, 0, "%s is transported.\n", Enemyname); - if (drandom() < 0.3) - /* monster didn't drop its treasure */ - Curmonster.m_treasuretype = 0; + break; - Curmonster.m_energy = 0.0; + case '7': /* transport */ + if (Player.p_magiclvl < ML_XPORT) + ILLSPELL(); + else if (Player.p_mana < MM_XPORT) + NOMANA(); + else { + Player.p_mana -= MM_XPORT; + if (Player.p_brains + Player.p_magiclvl + < Curmonster.m_experience / 200.0 * drandom()) { + mvaddstr(5, 0, "Transport backfired!\n"); + altercoordinates(0.0, 0.0, A_FAR); + cancelmonster(); + } else { + mvprintw(5, 0, "%s is transported.\n", Enemyname); + if (drandom() < 0.3) + /* monster didn't drop + * its treasure */ + Curmonster.m_treasuretype = 0; + + Curmonster.m_energy = 0.0; + } } - } - break; + break; - case '8': /* paralyze */ - if (Player.p_magiclvl < ML_PARALYZE) - ILLSPELL(); - else if (Player.p_mana < MM_PARALYZE) - NOMANA(); - else - { - Player.p_mana -= MM_PARALYZE; - if (Player.p_magiclvl > - Curmonster.m_experience / 1000.0 * drandom()) - { - mvprintw(5, 0, "%s is held.\n", Enemyname); - Curmonster.m_speed = -2.0; + case '8': /* paralyze */ + if (Player.p_magiclvl < ML_PARALYZE) + ILLSPELL(); + else if (Player.p_mana < MM_PARALYZE) + NOMANA(); + else { + Player.p_mana -= MM_PARALYZE; + if (Player.p_magiclvl > + Curmonster.m_experience / 1000.0 * drandom()) { + mvprintw(5, 0, "%s is held.\n", Enemyname); + Curmonster.m_speed = -2.0; + } else + mvaddstr(5, 0, "Monster unaffected.\n"); } - else - mvaddstr(5, 0, "Monster unaffected.\n"); - } - break; + break; - case '9': /* specify */ - if (Player.p_specialtype < SC_COUNCIL) - ILLSPELL(); - else if (Player.p_mana < MM_SPECIFY) - NOMANA(); - else - { - Player.p_mana -= MM_SPECIFY; - mvaddstr(5, 0, "Which monster do you want [0-99] ? "); - Whichmonster = (int) infloat(); - Whichmonster = MAX(0, MIN(99, Whichmonster)); - longjmp(Fightenv, 0); - /*NOTREACHED*/ - } - break; - } + case '9': /* specify */ + if (Player.p_specialtype < SC_COUNCIL) + ILLSPELL(); + else if (Player.p_mana < MM_SPECIFY) + NOMANA(); + else { + Player.p_mana -= MM_SPECIFY; + mvaddstr(5, 0, "Which monster do you want [0-99] ? "); + Whichmonster = (int) infloat(); + Whichmonster = MAX(0, MIN(99, Whichmonster)); + longjmp(Fightenv, 0); + /* NOTREACHED */ + } + break; + } } /**/ /************************************************************************ @@ -1052,86 +1035,82 @@ int ch; /* input */ / *************************************************************************/ +void callmonster(which) -int which; + int which; { -struct monster Othermonster; /* to find a name for mimics */ - - which = MIN(which, 99); /* make sure within range */ + struct monster Othermonster; /* to find a name for mimics */ - /* fill structure */ - fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0); - fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); + which = MIN(which, 99); /* make sure within range */ - /* handle some special monsters */ - if (Curmonster.m_type == SM_MODNAR) - { - if (Player.p_specialtype < SC_COUNCIL) - /* randomize some stats */ - { - Curmonster.m_strength *= drandom() + 0.5; - Curmonster.m_brains *= drandom() + 0.5; - Curmonster.m_speed *= drandom() + 0.5; - Curmonster.m_energy *= drandom() + 0.5; - Curmonster.m_experience *= drandom() + 0.5; - Curmonster.m_treasuretype = - (int) ROLL(0.0, (double) Curmonster.m_treasuretype); - } - else - /* make Modnar into Morgoth */ - { - strcpy(Curmonster.m_name, "Morgoth"); - Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4 - + drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5; - Curmonster.m_brains = Player.p_brains; - Curmonster.m_energy = Player.p_might * 30.0; - Curmonster.m_type = SM_MORGOTH; - Curmonster.m_speed = Player.p_speed * 1.1 - + (Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0; - Curmonster.m_flock = 0.0; - Curmonster.m_treasuretype = 0; - Curmonster.m_experience = 0.0; - } - } - else if (Curmonster.m_type == SM_MIMIC) - /* pick another name */ - { - which = (int) ROLL(0.0, 100.0); + /* fill structure */ fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0); - fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp); - strcpy(Curmonster.m_name, Othermonster.m_name); - } + fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); - truncstring(Curmonster.m_name); + /* handle some special monsters */ + if (Curmonster.m_type == SM_MODNAR) { + if (Player.p_specialtype < SC_COUNCIL) + /* randomize some stats */ + { + Curmonster.m_strength *= drandom() + 0.5; + Curmonster.m_brains *= drandom() + 0.5; + Curmonster.m_speed *= drandom() + 0.5; + Curmonster.m_energy *= drandom() + 0.5; + Curmonster.m_experience *= drandom() + 0.5; + Curmonster.m_treasuretype = + (int) ROLL(0.0, (double) Curmonster.m_treasuretype); + } else + /* make Modnar into Morgoth */ + { + strcpy(Curmonster.m_name, "Morgoth"); + Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4 + + drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5; + Curmonster.m_brains = Player.p_brains; + Curmonster.m_energy = Player.p_might * 30.0; + Curmonster.m_type = SM_MORGOTH; + Curmonster.m_speed = Player.p_speed * 1.1 + + (Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0; + Curmonster.m_flock = 0.0; + Curmonster.m_treasuretype = 0; + Curmonster.m_experience = 0.0; + } + } else + if (Curmonster.m_type == SM_MIMIC) + /* pick another name */ + { + which = (int) ROLL(0.0, 100.0); + fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0); + fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp); + strcpy(Curmonster.m_name, Othermonster.m_name); + } + truncstring(Curmonster.m_name); - if (Curmonster.m_type != SM_MORGOTH) - /* adjust stats based on which circle player is in */ + if (Curmonster.m_type != SM_MORGOTH) + /* adjust stats based on which circle player is in */ { - Curmonster.m_strength *= (1.0 + Circle / 2.0); - Curmonster.m_brains *= Circle; - Curmonster.m_speed += Circle * 1.e-9; - Curmonster.m_energy *= Circle; - Curmonster.m_experience *= Circle; + Curmonster.m_strength *= (1.0 + Circle / 2.0); + Curmonster.m_brains *= Circle; + Curmonster.m_speed += Circle * 1.e-9; + Curmonster.m_energy *= Circle; + Curmonster.m_experience *= Circle; } + if (Player.p_blindness) + /* cannot see monster if blind */ + Enemyname = "A monster"; + else + Enemyname = Curmonster.m_name; - if (Player.p_blindness) - /* cannot see monster if blind */ - Enemyname = "A monster"; - else - Enemyname = Curmonster.m_name; - - if (Player.p_speed <= 0.0) - /* make Player.p_speed positive */ + if (Player.p_speed <= 0.0) + /* make Player.p_speed positive */ { - Curmonster.m_speed += -Player.p_speed; - Player.p_speed = 1.0; + Curmonster.m_speed += -Player.p_speed; + Player.p_speed = 1.0; } - - /* fill up the rest of the structure */ - Curmonster.m_o_strength = Curmonster.m_strength; - Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed; - Curmonster.m_o_energy = Curmonster.m_energy; - Curmonster.m_melee = Curmonster.m_skirmish = 0.0; + /* fill up the rest of the structure */ + Curmonster.m_o_strength = Curmonster.m_strength; + Curmonster.m_o_speed = Curmonster.m_maxspeed = Curmonster.m_speed; + Curmonster.m_o_energy = Curmonster.m_energy; + Curmonster.m_melee = Curmonster.m_skirmish = 0.0; } /**/ /************************************************************************ @@ -1162,15 +1141,16 @@ struct monster Othermonster; /* to find a name for mimics */ / *************************************************************************/ +void awardtreasure() { -register int whichtreasure; /* calculated treasure to grant */ -int temp; /* temporary */ -int ch; /* input */ -double treasuretype; /* monster's treasure type */ -double gold = 0.0; /* gold awarded */ -double gems = 0.0; /* gems awarded */ -double dtemp; /* for temporary calculations */ + int whichtreasure; /* calculated treasure to grant */ + int temp; /* temporary */ + int ch; /* input */ + double treasuretype; /* monster's treasure type */ + double gold = 0.0; /* gold awarded */ + double gems = 0.0; /* gems awarded */ + double dtemp; /* for temporary calculations */ whichtreasure = (int) ROLL(1.0, 3.0); /* pick a treasure */ treasuretype = (double) Curmonster.m_treasuretype; @@ -1188,8 +1168,7 @@ double dtemp; /* for temporary calculations */ gems = ROLL(1.0, (treasuretype - 7.0) * (treasuretype - 7.0) * (Circle - 1.0) / 4.0); printw("You have discovered %.0f gems!", gems); - } - else + } else /* gold */ { gold = ROLL(treasuretype * 10.0, treasuretype @@ -1201,7 +1180,7 @@ double dtemp; /* for temporary calculations */ ch = getanswer("NY", FALSE); addstr("\n\n"); - if (ch == 'Y') + if (ch == 'Y') { if (drandom() < treasuretype / 35.0 + 0.04) /* cursed */ { @@ -1210,6 +1189,7 @@ double dtemp; /* for temporary calculations */ } else collecttaxes(gold, gems); + } return; } @@ -1230,11 +1210,9 @@ double dtemp; /* for temporary calculations */ return; } else - switch (Curmonster.m_treasuretype) - { + switch (Curmonster.m_treasuretype) { case 1: /* treasure type 1 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: addstr("You've discovered a power booster!\n"); Player.p_mana += ROLL(Circle * 4.0, Circle * 30.0); @@ -1255,8 +1233,7 @@ double dtemp; /* for temporary calculations */ /* end treasure type 1 */ case 2: /* treasure type 2 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: addstr("You have found an amulet.\n"); ++Player.p_amulets; @@ -1277,8 +1254,7 @@ double dtemp; /* for temporary calculations */ /* end treasure type 2 */ case 3: /* treasure type 3 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: dtemp = ROLL(7.0, 30.0 + Circle / 10.0); printw("You've found a +%.0f shield!\n", dtemp); @@ -1315,8 +1291,7 @@ double dtemp; /* for temporary calculations */ addstr("\n\n"); if (ch == 'Y') - switch ((int) ROLL(1, 6)) - { + switch ((int) ROLL(1, 6)) { case 1: addstr("It throws up a shield for you next monster.\n"); getyx(stdscr, whichtreasure, ch); @@ -1325,7 +1300,7 @@ double dtemp; /* for temporary calculations */ (Player.p_maxenergy + Player.p_energy) * 5.5 + Circle * 50.0; Whichmonster = pickmonster(); longjmp(Fightenv, 0); - /*NOTREACHED*/ + /* NOTREACHED */ case 2: addstr("It makes you invisible for you next monster.\n"); @@ -1334,7 +1309,7 @@ double dtemp; /* for temporary calculations */ Player.p_speed = 1e6; Whichmonster = pickmonster(); longjmp(Fightenv, 0); - /*NOTREACHED*/ + /* NOTREACHED */ case 3: addstr("It increases your strength ten fold to fight your next monster.\n"); @@ -1343,7 +1318,7 @@ double dtemp; /* for temporary calculations */ Player.p_might *= 10.0; Whichmonster = pickmonster(); longjmp(Fightenv, 0); - /*NOTREACHED*/ + /* NOTREACHED */ case 4: addstr("It is a general knowledge scroll.\n"); @@ -1367,8 +1342,7 @@ double dtemp; /* for temporary calculations */ /* end treasure type 4 */ case 5: /* treasure type 5 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: dtemp = ROLL(Circle / 4.0 + 5.0, Circle / 2.0 + 9.0); printw("You've discovered a +%.0f dagger.\n", dtemp); @@ -1396,8 +1370,7 @@ double dtemp; /* for temporary calculations */ /* end treasure type 5 */ case 6: /* treasure type 6 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: addstr("You've found a priest.\n"); Player.p_energy = Player.p_maxenergy + Player.p_shield; @@ -1425,8 +1398,7 @@ double dtemp; /* for temporary calculations */ /* end treasure type 6 */ case 7: /* treasure type 7 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: addstr("You've discovered a charm!\n"); ++Player.p_charms; @@ -1452,8 +1424,7 @@ double dtemp; /* for temporary calculations */ /* end treasure type 7 */ case 8: /* treasure type 8 */ - switch (whichtreasure) - { + switch (whichtreasure) { case 1: addstr("You have found a healing potion.\n"); Player.p_poison = MIN(-2.0, Player.p_poison - 2.0); @@ -1463,8 +1434,7 @@ double dtemp; /* for temporary calculations */ addstr("You have discovered a transporter. Do you wish to go anywhere ? "); ch = getanswer("NY", FALSE); addstr("\n\n"); - if (ch == 'Y') - { + if (ch == 'Y') { double x, y; addstr("X Y Coordinates ? "); @@ -1490,10 +1460,8 @@ double dtemp; /* for temporary calculations */ case 11: case 12: case 13: /* treasure types 10 - 13 */ - if (drandom() < 0.33) - { - if (Curmonster.m_treasuretype == 10) - { + if (drandom() < 0.33) { + if (Curmonster.m_treasuretype == 10) { addstr("You've found a pair of elven boots!\n"); Player.p_quickness += 2.0; break; @@ -1610,23 +1578,21 @@ double dtemp; /* for temporary calculations */ / *************************************************************************/ +void cursedtreasure() { - if (Player.p_charms > 0) - { - addstr("But your charm saved you!\n"); - --Player.p_charms; - } - else if (Player.p_amulets > 0) - { - addstr("But your amulet saved you!\n"); - --Player.p_amulets; - } - else - { - Player.p_energy = (Player.p_maxenergy + Player.p_shield) / 10.0; - Player.p_poison += 0.25; - } + if (Player.p_charms > 0) { + addstr("But your charm saved you!\n"); + --Player.p_charms; + } else + if (Player.p_amulets > 0) { + addstr("But your amulet saved you!\n"); + --Player.p_amulets; + } else { + Player.p_energy = + (Player.p_maxenergy + Player.p_shield) / 10.0; + Player.p_poison += 0.25; + } } /**/ /************************************************************************ @@ -1652,39 +1618,41 @@ cursedtreasure() / *************************************************************************/ +void scramblestats() { -double dbuf[6]; /* to put statistic in */ -double dtemp1, dtemp2; /* for swapping values */ -register int first, second; /* indices for swapping */ -register double *dptr; /* pointer for filling and emptying buf[] */ - - /* fill buffer */ - dptr = &dbuf[0]; - *dptr++ = Player.p_strength; - *dptr++ = Player.p_mana; - *dptr++ = Player.p_brains; - *dptr++ = Player.p_magiclvl; - *dptr++ = Player.p_energy; - *dptr = Player.p_sin; - - /* pick values to swap */ - first = (int) ROLL(0, 5); - second = (int) ROLL(0, 5); - - /* swap values */ - dptr = &dbuf[0]; - dtemp1 = dptr[first]; - /* this expression is split to prevent a compiler loop on some compilers */ - dtemp2 = dptr[second]; - dptr[first] = dtemp2; - dptr[second] = dtemp1; - - /* empty buffer */ - Player.p_strength = *dptr++; - Player.p_mana = *dptr++; - Player.p_brains = *dptr++; - Player.p_magiclvl = *dptr++; - Player.p_energy = *dptr++; - Player.p_sin = *dptr; + double dbuf[6]; /* to put statistic in */ + double dtemp1, dtemp2; /* for swapping values */ + int first, second; /* indices for swapping */ + double *dptr; /* pointer for filling and emptying buf[] */ + + /* fill buffer */ + dptr = &dbuf[0]; + *dptr++ = Player.p_strength; + *dptr++ = Player.p_mana; + *dptr++ = Player.p_brains; + *dptr++ = Player.p_magiclvl; + *dptr++ = Player.p_energy; + *dptr = Player.p_sin; + + /* pick values to swap */ + first = (int) ROLL(0, 5); + second = (int) ROLL(0, 5); + + /* swap values */ + dptr = &dbuf[0]; + dtemp1 = dptr[first]; + /* this expression is split to prevent a compiler loop on some + * compilers */ + dtemp2 = dptr[second]; + dptr[first] = dtemp2; + dptr[second] = dtemp1; + + /* empty buffer */ + Player.p_strength = *dptr++; + Player.p_mana = *dptr++; + Player.p_brains = *dptr++; + Player.p_magiclvl = *dptr++; + Player.p_energy = *dptr++; + Player.p_sin = *dptr; } diff --git a/games/phantasia/gamesupport.c b/games/phantasia/gamesupport.c index 51c26a57740..82e3e38a2a0 100644 --- a/games/phantasia/gamesupport.c +++ b/games/phantasia/gamesupport.c @@ -1,3 +1,4 @@ +/* $OpenBSD: gamesupport.c,v 1.3 1998/11/29 19:56:56 pjanzen Exp $ */ /* $NetBSD: gamesupport.c,v 1.3 1995/04/24 12:24:28 cgd Exp $ */ /* @@ -52,440 +53,434 @@ / *************************************************************************/ +void changestats(ingameflag) -bool ingameflag; + bool ingameflag; { -static char flag[2] = /* for printing values of bools */ + static char flag[2] = /* for printing values of bools */ {'F', 'T'}; -register struct player *playerp;/* pointer to structure to alter */ -register char *prompt; /* pointer to prompt string */ -int c; /* input */ -int today; /* day of year of today */ -int temp; /* temporary variable */ -long loc; /* location in player file */ -time_t now; /* time now */ -double dtemp; /* temporary variable */ -bool *bptr; /* pointer to bool item to change */ -double *dptr; /* pointer to double item to change */ -short *sptr; /* pointer to short item to change */ - - clear(); - - for (;;) - /* get name of player to examine/alter */ + struct player *playerp; /* pointer to structure to alter */ + char *prompt; /* pointer to prompt string */ + int c; /* input */ + int today; /* day of year of today */ + int temp; /* temporary variable */ + long loc; /* location in player file */ + time_t now; /* time now */ + double dtemp; /* temporary variable */ + bool *bptr; /* pointer to bool item to change */ + double *dptr; /* pointer to double item to change */ + short *sptr; /* pointer to short item to change */ + + clear(); + + for (;;) + /* get name of player to examine/alter */ { - mvaddstr(5, 0, "Which character do you want to look at ? "); - getstring(Databuf, SZ_DATABUF); - truncstring(Databuf); + mvaddstr(5, 0, "Which character do you want to look at ? "); + getstring(Databuf, SZ_DATABUF); + truncstring(Databuf); - if (Databuf[0] == '\0') - userlist(ingameflag); - else - break; + if (Databuf[0] == '\0') + userlist(ingameflag); + else + break; } - loc = -1L; + loc = -1L; - if (!ingameflag) - /* use 'Player' structure */ - playerp = &Player; - else if (strcmp(Databuf, Player.p_name) == 0) - /* alter/examine current player */ + if (!ingameflag) + /* use 'Player' structure */ + playerp = &Player; + else + if (strcmp(Databuf, Player.p_name) == 0) + /* alter/examine current player */ + { + playerp = &Player; + loc = Fileloc; + } else + /* use 'Other' structure */ + playerp = &Other; + + /* find player on file */ + if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L) + /* didn't find player */ { - playerp = &Player; - loc = Fileloc; + clear(); + mvaddstr(11, 0, "Not found."); + return; } - else - /* use 'Other' structure */ - playerp = &Other; + time(&now); + today = localtime(&now)->tm_yday; - /* find player on file */ - if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L) - /* didn't find player */ - { clear(); - mvaddstr(11, 0, "Not found."); - return; - } - time(&now); - today = localtime(&now)->tm_yday; + for (;;) + /* print player structure, and prompt for action */ + { + mvprintw(0, 0, "A:Name %s\n", playerp->p_name); - clear(); + if (Wizard) + printw("B:Password %s\n", playerp->p_password); + else + addstr("B:Password XXXXXXXX\n"); + + printw(" :Login %s\n", playerp->p_login); + + printw("C:Experience %.0f\n", playerp->p_experience); + printw("D:Level %.0f\n", playerp->p_level); + printw("E:Strength %.0f\n", playerp->p_strength); + printw("F:Sword %.0f\n", playerp->p_sword); + printw(" :Might %.0f\n", playerp->p_might); + printw("G:Energy %.0f\n", playerp->p_energy); + printw("H:Max-Energy %.0f\n", playerp->p_maxenergy); + printw("I:Shield %.0f\n", playerp->p_shield); + printw("J:Quickness %.0f\n", playerp->p_quickness); + printw("K:Quicksilver %.0f\n", playerp->p_quksilver); + printw(" :Speed %.0f\n", playerp->p_speed); + printw("L:Magic Level %.0f\n", playerp->p_magiclvl); + printw("M:Mana %.0f\n", playerp->p_mana); + printw("N:Brains %.0f\n", playerp->p_brains); + + if (Wizard || playerp->p_specialtype != SC_VALAR) + mvaddstr(0, 40, descrstatus(playerp)); + + mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison); + mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold); + mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems); + mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin); + if (Wizard) { + mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x); + mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y); + } else { + mvaddstr(5, 40, "S:X-coord ?\n"); + mvaddstr(6, 40, "T:Y-coord ?\n"); + } - for (;;) - /* print player structure, and prompt for action */ - { - mvprintw(0, 0,"A:Name %s\n", playerp->p_name); + mvprintw(7, 40, "U:Age %ld\n", playerp->p_age); + mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated); + + mvprintw(9, 40, "W:Type %d (%s)\n", + playerp->p_type, descrtype(playerp, FALSE) + 1); + mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype); + mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives); + mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns); + mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms); + mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets); + mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater); + + temp = today - playerp->p_lastused; + if (temp < 0) + /* last year */ + temp += 365; + mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp); + + mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c", + flag[(int)playerp->p_palantir], + flag[(int)playerp->p_blessing], + flag[(int)playerp->p_virgin], + flag[(int)playerp->p_blindness]); - if (Wizard) - printw("B:Password %s\n", playerp->p_password); - else - addstr("B:Password XXXXXXXX\n"); - - printw(" :Login %s\n", playerp->p_login); - - printw("C:Experience %.0f\n", playerp->p_experience); - printw("D:Level %.0f\n", playerp->p_level); - printw("E:Strength %.0f\n", playerp->p_strength); - printw("F:Sword %.0f\n", playerp->p_sword); - printw(" :Might %.0f\n", playerp->p_might); - printw("G:Energy %.0f\n", playerp->p_energy); - printw("H:Max-Energy %.0f\n", playerp->p_maxenergy); - printw("I:Shield %.0f\n", playerp->p_shield); - printw("J:Quickness %.0f\n", playerp->p_quickness); - printw("K:Quicksilver %.0f\n", playerp->p_quksilver); - printw(" :Speed %.0f\n", playerp->p_speed); - printw("L:Magic Level %.0f\n", playerp->p_magiclvl); - printw("M:Mana %.0f\n", playerp->p_mana); - printw("N:Brains %.0f\n", playerp->p_brains); - - if (Wizard || playerp->p_specialtype != SC_VALAR) - mvaddstr(0, 40, descrstatus(playerp)); - - mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison); - mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold); - mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems); - mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin); - if (Wizard) - { - mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x); - mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y); - } - else - { - mvaddstr(5, 40, "S:X-coord ?\n"); - mvaddstr(6, 40, "T:Y-coord ?\n"); - } - - mvprintw(7, 40, "U:Age %ld\n", playerp->p_age); - mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated); - - mvprintw(9, 40, "W:Type %d (%s)\n", - playerp->p_type, descrtype(playerp, FALSE) + 1); - mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype); - mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives); - mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns); - mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms); - mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets); - mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater); - - temp = today - playerp->p_lastused; - if (temp < 0) - /* last year */ - temp += 365; - mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp); - - mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c", - flag[playerp->p_palantir], - flag[playerp->p_blessing], - flag[playerp->p_virgin], - flag[playerp->p_blindness]); - - if (!Wizard) - mvprintw(19, 8, "8:Ring %c", - flag[playerp->p_ring.ring_type != R_NONE]); - else - mvprintw(19, 8, "8:Ring %d 9:Duration %d", - playerp->p_ring.ring_type, playerp->p_ring.ring_duration); - - if (!Wizard - /* not wizard */ - && (ingameflag || strcmp(Login, playerp->p_login) != 0)) - /* in game or not examining own character */ - { - if (ingameflag) + if (!Wizard) + mvprintw(19, 8, "8:Ring %c", + flag[playerp->p_ring.ring_type != R_NONE]); + else + mvprintw(19, 8, "8:Ring %d 9:Duration %d", + playerp->p_ring.ring_type, playerp->p_ring.ring_duration); + + if (!Wizard + /* not wizard */ + && (ingameflag || strcmp(Login, playerp->p_login) != 0)) + /* in game or not examining own character */ { - more(LINES - 1); - clear(); - return; + if (ingameflag) { + more(LINES - 1); + clear(); + return; + } else + cleanup(TRUE); + /* NOTREACHED */ } - else - cleanup(TRUE); - /*NOTREACHED*/ - } + mvaddstr(20, 0, "!:Quit ?:Delete"); + mvaddstr(21, 0, "What would you like to change ? "); - mvaddstr(20, 0, "!:Quit ?:Delete"); - mvaddstr(21, 0, "What would you like to change ? "); + if (Wizard) + c = getanswer(" ", TRUE); + else + /* examining own player; allow to change name and + * password */ + c = getanswer("!BA", FALSE); + + switch (c) { + case 'A': /* change name */ + case 'B': /* change password */ + if (!Wizard) + /* prompt for password */ + { + mvaddstr(23, 0, "Password ? "); + Echo = FALSE; + getstring(Databuf, 9); + Echo = TRUE; + if (strcmp(Databuf, playerp->p_password) != 0) + continue; + } + if (c == 'A') + /* get new name */ + { + mvaddstr(23, 0, "New name: "); + getstring(Databuf, SZ_NAME); + truncstring(Databuf); + if (Databuf[0] != '\0') + if (Wizard || findname(Databuf, &Other) < 0L) + strcpy(playerp->p_name, Databuf); + } else + /* get new password */ + { + if (!Wizard) + Echo = FALSE; + + do + /* get two copies of new password + * until they match */ + { + /* get first copy */ + mvaddstr(23, 0, "New password ? "); + getstring(Databuf, SZ_PASSWORD); + if (Databuf[0] == '\0') + break; + + /* get second copy */ + mvaddstr(23, 0, "One more time ? "); + getstring(playerp->p_password, SZ_PASSWORD); + } + while (strcmp(playerp->p_password, Databuf) != 0); + + Echo = TRUE; + } - if (Wizard) - c = getanswer(" ", TRUE); - else - /* examining own player; allow to change name and password */ - c = getanswer("!BA", FALSE); + continue; - switch (c) - { - case 'A': /* change name */ - case 'B': /* change password */ - if (!Wizard) - /* prompt for password */ - { - mvaddstr(23, 0, "Password ? "); - Echo = FALSE; - getstring(Databuf, 9); - Echo = TRUE; - if (strcmp(Databuf, playerp->p_password) != 0) + case 'C': /* change experience */ + prompt = "experience"; + dptr = &playerp->p_experience; + goto DALTER; + + case 'D': /* change level */ + prompt = "level"; + dptr = &playerp->p_level; + goto DALTER; + + case 'E': /* change strength */ + prompt = "strength"; + dptr = &playerp->p_strength; + goto DALTER; + + case 'F': /* change swords */ + prompt = "sword"; + dptr = &playerp->p_sword; + goto DALTER; + + case 'G': /* change energy */ + prompt = "energy"; + dptr = &playerp->p_energy; + goto DALTER; + + case 'H': /* change maximum energy */ + prompt = "max energy"; + dptr = &playerp->p_maxenergy; + goto DALTER; + + case 'I': /* change shields */ + prompt = "shield"; + dptr = &playerp->p_shield; + goto DALTER; + + case 'J': /* change quickness */ + prompt = "quickness"; + dptr = &playerp->p_quickness; + goto DALTER; + + case 'K': /* change quicksilver */ + prompt = "quicksilver"; + dptr = &playerp->p_quksilver; + goto DALTER; + + case 'L': /* change magic */ + prompt = "magic level"; + dptr = &playerp->p_magiclvl; + goto DALTER; + + case 'M': /* change mana */ + prompt = "mana"; + dptr = &playerp->p_mana; + goto DALTER; + + case 'N': /* change brains */ + prompt = "brains"; + dptr = &playerp->p_brains; + goto DALTER; + + case 'O': /* change poison */ + prompt = "poison"; + dptr = &playerp->p_poison; + goto DALTER; + + case 'P': /* change gold */ + prompt = "gold"; + dptr = &playerp->p_gold; + goto DALTER; + + case 'Q': /* change gems */ + prompt = "gems"; + dptr = &playerp->p_gems; + goto DALTER; + + case 'R': /* change sin */ + prompt = "sin"; + dptr = &playerp->p_sin; + goto DALTER; + + case 'S': /* change x coord */ + prompt = "x"; + dptr = &playerp->p_x; + goto DALTER; + + case 'T': /* change y coord */ + prompt = "y"; + dptr = &playerp->p_y; + goto DALTER; + + case 'U': /* change age */ + mvprintw(23, 0, "age = %ld; age = ", playerp->p_age); + dtemp = infloat(); + if (dtemp != 0.0) + playerp->p_age = (long) dtemp; continue; - } - - if (c == 'A') - /* get new name */ - { - mvaddstr(23, 0, "New name: "); - getstring(Databuf, SZ_NAME); - truncstring(Databuf); - if (Databuf[0] != '\0') - if (Wizard || findname(Databuf, &Other) < 0L) - strcpy(playerp->p_name, Databuf); - } - else - /* get new password */ - { - if (!Wizard) - Echo = FALSE; - do - /* get two copies of new password until they match */ + case 'V': /* change degen */ + mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated); + dtemp = infloat(); + if (dtemp != 0.0) + playerp->p_degenerated = (int) dtemp; + continue; + + case 'W': /* change type */ + prompt = "type"; + sptr = &playerp->p_type; + goto SALTER; + + case 'X': /* change special type */ + prompt = "special type"; + sptr = &playerp->p_specialtype; + goto SALTER; + + case 'Y': /* change lives */ + prompt = "lives"; + sptr = &playerp->p_lives; + goto SALTER; + + case 'Z': /* change crowns */ + prompt = "crowns"; + sptr = &playerp->p_crowns; + goto SALTER; + + case '0': /* change charms */ + prompt = "charm"; + sptr = &playerp->p_charms; + goto SALTER; + + case '1': /* change amulet */ + prompt = "amulet"; + sptr = &playerp->p_amulets; + goto SALTER; + + case '2': /* change holy water */ + prompt = "holy water"; + sptr = &playerp->p_holywater; + goto SALTER; + + case '3': /* change last-used */ + prompt = "last-used"; + sptr = &playerp->p_lastused; + goto SALTER; + + case '4': /* change palantir */ + prompt = "palantir"; + bptr = &playerp->p_palantir; + goto BALTER; + + case '5': /* change blessing */ + prompt = "blessing"; + bptr = &playerp->p_blessing; + goto BALTER; + + case '6': /* change virgin */ + prompt = "virgin"; + bptr = &playerp->p_virgin; + goto BALTER; + + case '7': /* change blindness */ + prompt = "blindness"; + bptr = &playerp->p_blindness; + goto BALTER; + + case '8': /* change ring type */ + prompt = "ring-type"; + sptr = &playerp->p_ring.ring_type; + goto SALTER; + + case '9': /* change ring duration */ + prompt = "ring-duration"; + sptr = &playerp->p_ring.ring_duration; + goto SALTER; + + case '!': /* quit, update */ + if (Wizard && + (!ingameflag || playerp != &Player)) + /* turn off status if not modifying self */ { - /* get first copy */ - mvaddstr(23, 0, "New password ? "); - getstring(Databuf, SZ_PASSWORD); - if (Databuf[0] == '\0') - break; - - /* get second copy */ - mvaddstr(23, 0, "One more time ? "); - getstring(playerp->p_password, SZ_PASSWORD); + playerp->p_status = S_OFF; + playerp->p_tampered = T_OFF; } - while (strcmp(playerp->p_password, Databuf) != 0); + writerecord(playerp, loc); + clear(); + return; - Echo = TRUE; - } + case '?': /* delete player */ + if (ingameflag && playerp == &Player) + /* cannot delete self */ + continue; - continue; + freerecord(playerp, loc); + clear(); + return; - case 'C': /* change experience */ - prompt = "experience"; - dptr = &playerp->p_experience; - goto DALTER; - - case 'D': /* change level */ - prompt = "level"; - dptr = &playerp->p_level; - goto DALTER; - - case 'E': /* change strength */ - prompt = "strength"; - dptr = &playerp->p_strength; - goto DALTER; - - case 'F': /* change swords */ - prompt = "sword"; - dptr = &playerp->p_sword; - goto DALTER; - - case 'G': /* change energy */ - prompt = "energy"; - dptr = &playerp->p_energy; - goto DALTER; - - case 'H': /* change maximum energy */ - prompt = "max energy"; - dptr = &playerp->p_maxenergy; - goto DALTER; - - case 'I': /* change shields */ - prompt = "shield"; - dptr = &playerp->p_shield; - goto DALTER; - - case 'J': /* change quickness */ - prompt = "quickness"; - dptr = &playerp->p_quickness; - goto DALTER; - - case 'K': /* change quicksilver */ - prompt = "quicksilver"; - dptr = &playerp->p_quksilver; - goto DALTER; - - case 'L': /* change magic */ - prompt = "magic level"; - dptr = &playerp->p_magiclvl; - goto DALTER; - - case 'M': /* change mana */ - prompt = "mana"; - dptr = &playerp->p_mana; - goto DALTER; - - case 'N': /* change brains */ - prompt = "brains"; - dptr = &playerp->p_brains; - goto DALTER; - - case 'O': /* change poison */ - prompt = "poison"; - dptr = &playerp->p_poison; - goto DALTER; - - case 'P': /* change gold */ - prompt = "gold"; - dptr = &playerp->p_gold; - goto DALTER; - - case 'Q': /* change gems */ - prompt = "gems"; - dptr = &playerp->p_gems; - goto DALTER; - - case 'R': /* change sin */ - prompt = "sin"; - dptr = &playerp->p_sin; - goto DALTER; - - case 'S': /* change x coord */ - prompt = "x"; - dptr = &playerp->p_x; - goto DALTER; - - case 'T': /* change y coord */ - prompt = "y"; - dptr = &playerp->p_y; - goto DALTER; - - case 'U': /* change age */ - mvprintw(23, 0, "age = %ld; age = ", playerp->p_age); + default: + continue; + } +DALTER: + mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt); dtemp = infloat(); if (dtemp != 0.0) - playerp->p_age = (long) dtemp; + *dptr = dtemp; continue; - case 'V': /* change degen */ - mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated); +SALTER: + mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt); dtemp = infloat(); if (dtemp != 0.0) - playerp->p_degenerated = (int) dtemp; + *sptr = (short) dtemp; continue; - case 'W': /* change type */ - prompt = "type"; - sptr = &playerp->p_type; - goto SALTER; - - case 'X': /* change special type */ - prompt = "special type"; - sptr = &playerp->p_specialtype; - goto SALTER; - - case 'Y': /* change lives */ - prompt = "lives"; - sptr = &playerp->p_lives; - goto SALTER; - - case 'Z': /* change crowns */ - prompt = "crowns"; - sptr = &playerp->p_crowns; - goto SALTER; - - case '0': /* change charms */ - prompt = "charm"; - sptr = &playerp->p_charms; - goto SALTER; - - case '1': /* change amulet */ - prompt = "amulet"; - sptr = &playerp->p_amulets; - goto SALTER; - - case '2': /* change holy water */ - prompt = "holy water"; - sptr = &playerp->p_holywater; - goto SALTER; - - case '3': /* change last-used */ - prompt = "last-used"; - sptr = &playerp->p_lastused; - goto SALTER; - - case '4': /* change palantir */ - prompt = "palantir"; - bptr = &playerp->p_palantir; - goto BALTER; - - case '5': /* change blessing */ - prompt = "blessing"; - bptr = &playerp->p_blessing; - goto BALTER; - - case '6': /* change virgin */ - prompt = "virgin"; - bptr = &playerp->p_virgin; - goto BALTER; - - case '7': /* change blindness */ - prompt = "blindness"; - bptr = &playerp->p_blindness; - goto BALTER; - - case '8': /* change ring type */ - prompt = "ring-type"; - sptr = &playerp->p_ring.ring_type; - goto SALTER; - - case '9': /* change ring duration */ - prompt = "ring-duration"; - sptr = &playerp->p_ring.ring_duration; - goto SALTER; - - case '!': /* quit, update */ - if (Wizard && - (!ingameflag || playerp != &Player)) - /* turn off status if not modifying self */ - { - playerp->p_status = S_OFF; - playerp->p_tampered = T_OFF; - } - - writerecord(playerp, loc); - clear(); - return; - - case '?': /* delete player */ - if (ingameflag && playerp == &Player) - /* cannot delete self */ - continue; - - freerecord(playerp, loc); - clear(); - return; - - default: - continue; - } -DALTER: - mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt); - dtemp = infloat(); - if (dtemp != 0.0) - *dptr = dtemp; - continue; - -SALTER: - mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt); - dtemp = infloat(); - if (dtemp != 0.0) - *sptr = (short) dtemp; - continue; - BALTER: - mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt); - c = getanswer("\nTF", TRUE); - if (c == 'T') - *bptr = TRUE; - else if (c == 'F') - *bptr = FALSE; - continue; + mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[(int)*bptr], + prompt); + c = getanswer("\nTF", TRUE); + if (c == 'T') + *bptr = TRUE; + else + if (c == 'F') + *bptr = FALSE; + continue; } } /**/ @@ -512,17 +507,18 @@ BALTER: / *************************************************************************/ +void monstlist() { -register int count = 0; /* count in file */ - - puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n"); - fseek(Monstfp, 0L, 0); - while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1) - printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++, - Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains, - Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience, - Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock); + int count = 0; /* count in file */ + + puts(" #) Name Str Brain Quick Energy Exper Treas Type Flock%\n"); + fseek(Monstfp, 0L, 0); + while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1) + printf("%2d) %-20.20s%4.0f %4.0f %2.0f %5.0f %5.0f %2d %2d %3.0f\n", count++, + Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains, + Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience, + Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock); } /**/ /************************************************************************ @@ -548,17 +544,17 @@ register int count = 0; /* count in file */ / *************************************************************************/ +void scorelist() { -struct scoreboard sbuf; /* for reading entries */ -register FILE *fp; /* to open the file */ - - if ((fp = fopen(_PATH_SCORE, "r")) != NULL) - { - while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1) - printf("%-20s (%-9s) Level: %6.0f Type: %s\n", - sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type); - fclose(fp); + struct scoreboard sbuf; /* for reading entries */ + FILE *fp; /* to open the file */ + + if ((fp = fopen(_PATH_SCORE, "r")) != NULL) { + while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1) + printf("%-20s (%-9s) Level: %6.0f Type: %s\n", + sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type); + fclose(fp); } } /**/ @@ -585,16 +581,17 @@ register FILE *fp; /* to open the file */ / *************************************************************************/ +void activelist() { - fseek(Playersfp, 0L, 0); - printf("Current characters on file are:\n\n"); + fseek(Playersfp, 0L, 0); + printf("Current characters on file are:\n\n"); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - if (Other.p_status != S_NOTUSED) - printf("%-20s (%-9s) Level: %6.0f %s (%s)\n", - Other.p_name, Other.p_login, Other.p_level, - descrtype(&Other, FALSE), descrstatus(&Other)); + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + if (Other.p_status != S_NOTUSED) + printf("%-20s (%-9s) Level: %6.0f %s (%s)\n", + Other.p_name, Other.p_login, Other.p_level, + descrtype(&Other, FALSE), descrstatus(&Other)); } /**/ @@ -622,31 +619,32 @@ activelist() / *************************************************************************/ +void purgeoldplayers() { -int today; /* day of year for today */ -int daysold; /* how many days since the character has been used */ -time_t ltime; /* time in seconds */ -long loc = 0L; /* location in file */ + int today; /* day of year for today */ + int daysold; /* how many days since the character has been + * used */ + time_t ltime; /* time in seconds */ + long loc = 0L; /* location in file */ - time(<ime); - today = localtime(<ime)->tm_yday; + time(<ime); + today = localtime(<ime)->tm_yday; - for (;;) - { - fseek(Playersfp, loc, 0); - if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1) - break; + for (;;) { + fseek(Playersfp, loc, 0); + if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1) + break; - daysold = today - Other.p_lastused; - if (daysold < 0) - daysold += 365; + daysold = today - Other.p_lastused; + if (daysold < 0) + daysold += 365; - if (daysold > N_DAYSOLD) - /* player hasn't been used in a while; delete */ - freerecord(&Other, loc); + if (daysold > N_DAYSOLD) + /* player hasn't been used in a while; delete */ + freerecord(&Other, loc); - loc += SZ_PLAYERSTRUCT; + loc += SZ_PLAYERSTRUCT; } } /**/ @@ -678,47 +676,42 @@ long loc = 0L; /* location in file */ / *************************************************************************/ +void enterscore() { -struct scoreboard sbuf; /* buffer to read in scoreboard entries */ -FILE *fp; /* to open scoreboard file */ -long loc = 0L; /* location in scoreboard file */ -bool found = FALSE; /* set if we found an entry for this login */ - - if ((fp = fopen(_PATH_SCORE, "r+")) != NULL) - { - while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1) - if (strcmp(Player.p_login, sbuf.sb_login) == 0) - { - found = TRUE; - break; - } - else - loc += SZ_SCORESTRUCT; - } - else - { - error(_PATH_SCORE); - /*NOTREACHED*/ + struct scoreboard sbuf; /* buffer to read in scoreboard entries */ + FILE *fp; /* to open scoreboard file */ + long loc = 0L; /* location in scoreboard file */ + bool found = FALSE; /* set if we found an entry for this login */ + + if ((fp = fopen(_PATH_SCORE, "r+")) != NULL) { + while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1) + if (strcmp(Player.p_login, sbuf.sb_login) == 0) { + found = TRUE; + break; + } else + loc += SZ_SCORESTRUCT; + } else { + error(_PATH_SCORE); + /* NOTREACHED */ } - /* - * At this point, 'loc' will either indicate a point beyond - * the end of file, or the place where the previous entry - * was found. - */ + /* + * At this point, 'loc' will either indicate a point beyond + * the end of file, or the place where the previous entry + * was found. + */ - if ((!found) || Player.p_level > sbuf.sb_level) - /* put new entry in for this login */ + if ((!found) || Player.p_level > sbuf.sb_level) + /* put new entry in for this login */ { - strcpy(sbuf.sb_login, Player.p_login); - strcpy(sbuf.sb_name, Player.p_name); - sbuf.sb_level = Player.p_level; - strcpy(sbuf.sb_type, descrtype(&Player, TRUE)); + strcpy(sbuf.sb_login, Player.p_login); + strcpy(sbuf.sb_name, Player.p_name); + sbuf.sb_level = Player.p_level; + strcpy(sbuf.sb_type, descrtype(&Player, TRUE)); } - - /* update entry */ - fseek(fp, loc, 0); - fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp); - fclose(fp); + /* update entry */ + fseek(fp, loc, 0); + fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp); + fclose(fp); } diff --git a/games/phantasia/include.h b/games/phantasia/include.h index db661e3802c..447856657ad 100644 --- a/games/phantasia/include.h +++ b/games/phantasia/include.h @@ -1,3 +1,4 @@ +/* $OpenBSD: include.h,v 1.2 1998/11/29 19:56:56 pjanzen Exp $ */ /* $NetBSD: include.h,v 1.3 1995/04/24 12:24:31 cgd Exp $ */ /* @@ -6,12 +7,14 @@ #include <ctype.h> #include <curses.h> +#include <errno.h> #include <math.h> #include <setjmp.h> #include <signal.h> -#include <time.h> -#include <errno.h> +#include <stdlib.h> #include <string.h> +#include <time.h> +#include <unistd.h> #include "macros.h" #include "phantdefs.h" diff --git a/games/phantasia/interplayer.c b/games/phantasia/interplayer.c index 8794a0bf447..f457641c365 100644 --- a/games/phantasia/interplayer.c +++ b/games/phantasia/interplayer.c @@ -1,3 +1,4 @@ +/* $OpenBSD: interplayer.c,v 1.3 1998/11/29 19:56:56 pjanzen Exp $ */ /* $NetBSD: interplayer.c,v 1.2 1995/03/24 03:58:47 cgd Exp $ */ /* @@ -31,40 +32,40 @@ / *************************************************************************/ +void checkbattle() { -long foeloc = 0L; /* location in file of person to fight */ + long foeloc = 0L; /* location in file of person to fight */ - Users = 0; - fseek(Playersfp, 0L, 0); + Users = 0; + fseek(Playersfp, 0L, 0); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - { - if (Other.p_status != S_OFF - && Other.p_status != S_NOTUSED - && Other.p_status != S_HUNGUP - && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR)) - /* player is on and not a cloaked valar */ - { - ++Users; - - if (Player.p_x == Other.p_x - && Player.p_y == Other.p_y - /* same coordinates */ - && foeloc != Fileloc - /* not self */ - && Player.p_status == S_PLAYING - && (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE) - /* both are playing */ - && Other.p_specialtype != SC_VALAR - && Player.p_specialtype != SC_VALAR) - /* neither is valar */ + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) { + if (Other.p_status != S_OFF + && Other.p_status != S_NOTUSED + && Other.p_status != S_HUNGUP + && (Other.p_status != S_CLOAKED || Other.p_specialtype != SC_VALAR)) + /* player is on and not a cloaked valar */ { - battleplayer(foeloc); - return; + ++Users; + + if (Player.p_x == Other.p_x + && Player.p_y == Other.p_y + /* same coordinates */ + && foeloc != Fileloc + /* not self */ + && Player.p_status == S_PLAYING + && (Other.p_status == S_PLAYING || Other.p_status == S_INBATTLE) + /* both are playing */ + && Other.p_specialtype != SC_VALAR + && Player.p_specialtype != SC_VALAR) + /* neither is valar */ + { + battleplayer(foeloc); + return; + } } - } - foeloc += SZ_PLAYERSTRUCT; + foeloc += SZ_PLAYERSTRUCT; } } /**/ @@ -108,233 +109,229 @@ long foeloc = 0L; /* location in file of person to fight */ / *************************************************************************/ +void battleplayer(foeplace) -long foeplace; + long foeplace; { -double dtemp; /* for temporary calculations */ -double oldhits = 0.0; /* previous damage inflicted by foe */ -register int loop; /* for timing out */ -int ch; /* input */ -short oldtampered; /* old value of foe's p_tampered */ - - Lines = 8; - Luckout = FALSE; - mvaddstr(4, 0, "Preparing for battle!\n"); - refresh(); + double dtemp; /* for temporary calculations */ + double oldhits = 0.0; /* previous damage inflicted by foe */ + int loop; /* for timing out */ + int ch; /* input */ + short oldtampered; /* old value of foe's p_tampered */ + + Lines = 8; + Luckout = FALSE; + mvaddstr(4, 0, "Preparing for battle!\n"); + refresh(); #ifdef SYS5 - flushinp(); + flushinp(); #endif - /* set up variables, file, etc. */ - Player.p_status = S_INBATTLE; - Shield = Player.p_energy; + /* set up variables, file, etc. */ + Player.p_status = S_INBATTLE; + Shield = Player.p_energy; - /* if p_tampered is not 0, someone else may try to change it (king, etc.) */ - Player.p_tampered = oldtampered = 1; - Player.p_1scratch = 0.0; - Player.p_istat = I_OFF; + /* if p_tampered is not 0, someone else may try to change it (king, + * etc.) */ + Player.p_tampered = oldtampered = 1; + Player.p_1scratch = 0.0; + Player.p_istat = I_OFF; - readrecord(&Other, foeplace); - if (fabs(Player.p_level - Other.p_level) > 20.0) - /* see if players are greatly mismatched */ + readrecord(&Other, foeplace); + if (fabs(Player.p_level - Other.p_level) > 20.0) + /* see if players are greatly mismatched */ { - dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level); - if (dtemp < -0.5) - /* foe outweighs this one */ - Player.p_speed *= 2.0; + dtemp = (Player.p_level - Other.p_level) / MAX(Player.p_level, Other.p_level); + if (dtemp < -0.5) + /* foe outweighs this one */ + Player.p_speed *= 2.0; } + writerecord(&Player, Fileloc); /* write out all our info */ - writerecord(&Player, Fileloc); /* write out all our info */ - - if (Player.p_blindness) - Enemyname = "someone"; - else - Enemyname = Other.p_name; + if (Player.p_blindness) + Enemyname = "someone"; + else + Enemyname = Other.p_name; - mvprintw(6, 0, "You have encountered %s Level: %.0f\n", Enemyname, Other.p_level); - refresh(); + mvprintw(6, 0, "You have encountered %s Level: %.0f\n", Enemyname, Other.p_level); + refresh(); - for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop) - /* wait for foe to respond */ + for (loop = 0; Other.p_status != S_INBATTLE && loop < 30; ++loop) + /* wait for foe to respond */ { - readrecord(&Other, foeplace); - sleep(1); + readrecord(&Other, foeplace); + sleep(1); } - if (Other.p_status != S_INBATTLE) - /* foe did not respond */ + if (Other.p_status != S_INBATTLE) + /* foe did not respond */ { - mvprintw(5, 0, "%s is not responding.\n", Enemyname); - goto LEAVE; + mvprintw(5, 0, "%s is not responding.\n", Enemyname); + goto LEAVE; } - /* else, we are ready to battle */ - - move(4, 0); - clrtoeol(); - - /* - * determine who is first master - * if neither player is faster, check level - * if neither level is greater, battle is not allowed - * (this should never happen, but we have to handle it) - */ - if (Player.p_speed > Other.p_speed) - Foestrikes = FALSE; - else if (Other.p_speed > Player.p_speed) - Foestrikes = TRUE; - else if (Player.p_level > Other.p_level) - Foestrikes = FALSE; - else if (Other.p_level > Player.p_level) - Foestrikes = TRUE; - else - /* no one is faster */ - { - printw("You can't fight %s yet.", Enemyname); - goto LEAVE; + /* else, we are ready to battle */ + + move(4, 0); + clrtoeol(); + + /* + * determine who is first master + * if neither player is faster, check level + * if neither level is greater, battle is not allowed + * (this should never happen, but we have to handle it) + */ + if (Player.p_speed > Other.p_speed) + Foestrikes = FALSE; + else if (Other.p_speed > Player.p_speed) + Foestrikes = TRUE; + else if (Player.p_level > Other.p_level) + Foestrikes = FALSE; + else if (Other.p_level > Player.p_level) + Foestrikes = TRUE; + else { + /* no one is faster */ + printw("You can't fight %s yet.", Enemyname); + goto LEAVE; } - for (;;) - { - displaystats(); - readmessage(); - mvprintw(1, 26, "%20.0f", Shield); /* overprint energy */ + for (;;) { + displaystats(); + readmessage(); + mvprintw(1, 26, "%20.0f", Shield); /* overprint energy */ - if (!Foestrikes) - /* take action against foe */ - myturn(); - else - /* wait for foe to take action */ - { - mvaddstr(4, 0, "Waiting...\n"); - clrtoeol(); - refresh(); - - for (loop = 0; loop < 20; ++loop) - /* wait for foe to act */ - { - readrecord(&Other, foeplace); - if (Other.p_1scratch != oldhits) - /* p_1scratch changes to indicate action */ - break; + if (!Foestrikes) + /* take action against foe */ + myturn(); else - /* wait and try again */ - { - sleep(1); - addch('.'); - refresh(); - } + /* wait for foe to take action */ + { + mvaddstr(4, 0, "Waiting...\n"); + clrtoeol(); + refresh(); + + for (loop = 0; loop < 20; ++loop) + /* wait for foe to act */ + { + readrecord(&Other, foeplace); + if (Other.p_1scratch != oldhits) + /* p_1scratch changes to indicate + * action */ + break; + else + /* wait and try again */ + { + sleep(1); + addch('.'); + refresh(); + } + } + + if (Other.p_1scratch == oldhits) { + /* timeout */ + mvaddstr(22, 0, "Timeout: waiting for response. Do you want to wait ? "); + ch = getanswer("NY", FALSE); + move(22, 0); + clrtobot(); + if (ch == 'Y') + continue; + else + break; + } else + /* foe took action */ + { + switch (Other.p_istat) { + case I_RAN: /* foe ran away */ + mvprintw(Lines++, 0, "%s ran away!", Enemyname); + break; + + case I_STUCK: /* foe tried to run, but + * couldn't */ + mvprintw(Lines++, 0, "%s tried to run away.", Enemyname); + break; + + case I_BLEWIT: /* foe tried to luckout, but + * didn't */ + mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname); + break; + + default: + dtemp = Other.p_1scratch - oldhits; + mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp); + Shield -= dtemp; + break; + } + + oldhits = Other.p_1scratch; /* keep track of old + * hits */ + + if (Other.p_tampered != oldtampered) + /* p_tampered changes to relinquish + * turn */ + { + oldtampered = Other.p_tampered; + Foestrikes = FALSE; + } + } } - if (Other.p_1scratch == oldhits) - { - /* timeout */ - mvaddstr(22, 0, "Timeout: waiting for response. Do you want to wait ? "); - ch = getanswer("NY", FALSE); - move(22, 0); - clrtobot(); - if (ch == 'Y') - continue; - else - break; + /* decide what happens next */ + refresh(); + if (Lines > LINES - 2) { + more(Lines); + move(Lines = 8, 0); + clrtobot(); } - else - /* foe took action */ + if (Other.p_istat == I_KILLED || Shield < 0.0) + /* we died */ { - switch (Other.p_istat) - { - case I_RAN: /* foe ran away */ - mvprintw(Lines++, 0, "%s ran away!", Enemyname); - break; - - case I_STUCK: /* foe tried to run, but couldn't */ - mvprintw(Lines++, 0, "%s tried to run away.", Enemyname); - break; - - case I_BLEWIT: /* foe tried to luckout, but didn't */ - mvprintw(Lines++, 0, "%s tried to luckout!", Enemyname); + Shield = -2.0; /* insure this value is negative */ break; - - default: - dtemp = Other.p_1scratch - oldhits; - mvprintw(Lines++, 0, "%s hit you %.0f times!", Enemyname, dtemp); - Shield -= dtemp; - break; - } - - oldhits = Other.p_1scratch; /* keep track of old hits */ - - if (Other.p_tampered != oldtampered) - /* p_tampered changes to relinquish turn */ - { - oldtampered = Other.p_tampered; - Foestrikes = FALSE; - } } - } - - /* decide what happens next */ - refresh(); - if (Lines > LINES - 2) - { - more(Lines); - move(Lines = 8, 0); - clrtobot(); - } - - if (Other.p_istat == I_KILLED || Shield < 0.0) - /* we died */ - { - Shield = -2.0; /* insure this value is negative */ - break; - } - - if (Player.p_istat == I_KILLED) - /* we killed foe; award treasre */ - { - mvprintw(Lines++, 0, "You killed %s!", Enemyname); - Player.p_experience += Other.p_experience; - Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0; - Player.p_amulets += Other.p_amulets; - Player.p_charms += Other.p_charms; - collecttaxes(Other.p_gold, Other.p_gems); - Player.p_sword = MAX(Player.p_sword, Other.p_sword); - Player.p_shield = MAX(Player.p_shield, Other.p_shield); - Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver); - if (Other.p_virgin && !Player.p_virgin) + if (Player.p_istat == I_KILLED) + /* we killed foe; award treasre */ { - mvaddstr(Lines++, 0, "You have rescued a virgin. Will you be honorable ? "); - if ((ch = getanswer("YN", FALSE)) == 'Y') - Player.p_virgin = TRUE; - else - { - ++Player.p_sin; - Player.p_experience += 8000.0; - } - } - sleep(3); /* give other person time to die */ - break; - } - else if (Player.p_istat == I_RAN || Other.p_istat == I_RAN) - /* either player ran away */ - break; + mvprintw(Lines++, 0, "You killed %s!", Enemyname); + Player.p_experience += Other.p_experience; + Player.p_crowns += (Player.p_level < 1000.0) ? Other.p_crowns : 0; + Player.p_amulets += Other.p_amulets; + Player.p_charms += Other.p_charms; + collecttaxes(Other.p_gold, Other.p_gems); + Player.p_sword = MAX(Player.p_sword, Other.p_sword); + Player.p_shield = MAX(Player.p_shield, Other.p_shield); + Player.p_quksilver = MAX(Player.p_quksilver, Other.p_quksilver); + if (Other.p_virgin && !Player.p_virgin) { + mvaddstr(Lines++, 0, "You have rescued a virgin. Will you be honorable ? "); + if ((ch = getanswer("YN", FALSE)) == 'Y') + Player.p_virgin = TRUE; + else { + ++Player.p_sin; + Player.p_experience += 8000.0; + } + } + sleep(3); /* give other person time to die */ + break; + } else + if (Player.p_istat == I_RAN || Other.p_istat == I_RAN) + /* either player ran away */ + break; } LEAVE: - /* clean up things and leave */ - writerecord(&Player, Fileloc); /* update a final time */ - altercoordinates(0.0, 0.0, A_NEAR); /* move away from battle site */ - Player.p_energy = Shield; /* set energy to actual value */ - Player.p_tampered = T_OFF; /* clear p_tampered */ + /* clean up things and leave */ + writerecord(&Player, Fileloc); /* update a final time */ + altercoordinates(0.0, 0.0, A_NEAR); /* move away from battle site */ + Player.p_energy = Shield; /* set energy to actual value */ + Player.p_tampered = T_OFF; /* clear p_tampered */ - more(Lines); /* pause */ + more(Lines); /* pause */ - move(4, 0); - clrtobot(); /* clear bottom area of screen */ + move(4, 0); + clrtobot(); /* clear bottom area of screen */ - if (Player.p_energy < 0.0) - /* we are dead */ - death("Interterminal battle"); + if (Player.p_energy < 0.0) + /* we are dead */ + death("Interterminal battle"); } /**/ /************************************************************************ @@ -363,88 +360,82 @@ LEAVE: / *************************************************************************/ +void myturn() { -double dtemp; /* for temporary calculations */ -int ch; /* input */ + double dtemp; /* for temporary calculations */ + int ch; /* input */ - mvaddstr(7, 0, "1:Fight 2:Run Away! 3:Power Blast "); - if (Luckout) - clrtoeol(); - else - addstr("4:Luckout "); - - ch = inputoption(); - move(Lines = 8, 0); - clrtobot(); + mvaddstr(7, 0, "1:Fight 2:Run Away! 3:Power Blast "); + if (Luckout) + clrtoeol(); + else + addstr("4:Luckout "); + + ch = inputoption(); + move(Lines = 8, 0); + clrtobot(); + + switch (ch) { + default: /* fight */ + dtemp = ROLL(2.0, Player.p_might); +HIT: + mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp); + Player.p_sin += 0.5; + Player.p_1scratch += dtemp; + Player.p_istat = I_OFF; + break; - switch (ch) - { - default: /* fight */ - dtemp = ROLL(2.0, Player.p_might); -HIT: - mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, dtemp); - Player.p_sin += 0.5; - Player.p_1scratch += dtemp; - Player.p_istat = I_OFF; - break; - - case '2': /* run away */ - Player.p_1scratch -= 1.0; /* change this to indicate action */ - if (drandom() > 0.25) - { - mvaddstr(Lines++, 0, "You got away!"); - Player.p_istat = I_RAN; + case '2': /* run away */ + Player.p_1scratch -= 1.0; /* change this to indicate + * action */ + if (drandom() > 0.25) { + mvaddstr(Lines++, 0, "You got away!"); + Player.p_istat = I_RAN; + } else { + mvprintw(Lines++, 0, "%s is still after you!", Enemyname); + Player.p_istat = I_STUCK; } - else - { - mvprintw(Lines++, 0, "%s is still after you!", Enemyname); - Player.p_istat = I_STUCK; - } - break; - - case '3': /* power blast */ - dtemp = MIN(Player.p_mana, Player.p_level * 5.0); - Player.p_mana -= dtemp; - dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0; - mvprintw(Lines++, 0, "You blasted %s !", Enemyname); - goto HIT; - - case '4': /* luckout */ - if (Luckout || drandom() > 0.1) - { - if (Luckout) - mvaddstr(Lines++, 0, "You already tried that!"); - else - { - mvaddstr(Lines++, 0, "Not this time . . ."); - Luckout = TRUE; - } + break; - Player.p_1scratch -= 1.0; - Player.p_istat = I_BLEWIT; - } - else - { - mvaddstr(Lines++, 0, "You just lucked out!"); - Player.p_1scratch = Other.p_energy * 1.1; + case '3': /* power blast */ + dtemp = MIN(Player.p_mana, Player.p_level * 5.0); + Player.p_mana -= dtemp; + dtemp *= (drandom() + 0.5) * Player.p_magiclvl * 0.2 + 2.0; + mvprintw(Lines++, 0, "You blasted %s !", Enemyname); + goto HIT; + + case '4': /* luckout */ + if (Luckout || drandom() > 0.1) { + if (Luckout) + mvaddstr(Lines++, 0, "You already tried that!"); + else { + mvaddstr(Lines++, 0, "Not this time . . ."); + Luckout = TRUE; + } + + Player.p_1scratch -= 1.0; + Player.p_istat = I_BLEWIT; + } else { + mvaddstr(Lines++, 0, "You just lucked out!"); + Player.p_1scratch = Other.p_energy * 1.1; } - break; + break; } - refresh(); - Player.p_1scratch = floor(Player.p_1scratch); /* clean up any mess */ - - if (Player.p_1scratch > Other.p_energy) - Player.p_istat = I_KILLED; - else if (drandom() * Player.p_speed < drandom() * Other.p_speed) - /* relinquish control */ - { - ++Player.p_tampered; - Foestrikes = TRUE; - } + refresh(); + Player.p_1scratch = floor(Player.p_1scratch); /* clean up any mess */ - writerecord(&Player, Fileloc); /* let foe know what we did */ + if (Player.p_1scratch > Other.p_energy) + Player.p_istat = I_KILLED; + else + if (drandom() * Player.p_speed < drandom() * Other.p_speed) + /* relinquish control */ + { + ++Player.p_tampered; + Foestrikes = TRUE; + } + writerecord(&Player, Fileloc); /* let foe know what we did */ } /**/ /************************************************************************ @@ -471,37 +462,37 @@ HIT: / *************************************************************************/ +void checktampered() { -long loc = 0L; /* location in energy void file */ - - /* first check for energy voids */ - fseek(Energyvoidfp, 0L, 0); - while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1) - if (Enrgyvoid.ev_active - && Enrgyvoid.ev_x == Player.p_x - && Enrgyvoid.ev_y == Player.p_y) - /* sitting on one */ - { - if (loc > 0L) - /* not the holy grail; inactivate energy void */ + long loc = 0L; /* location in energy void file */ + + /* first check for energy voids */ + fseek(Energyvoidfp, 0L, 0); + while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1) + if (Enrgyvoid.ev_active + && Enrgyvoid.ev_x == Player.p_x + && Enrgyvoid.ev_y == Player.p_y) + /* sitting on one */ { - Enrgyvoid.ev_active = FALSE; - writevoid(&Enrgyvoid, loc); - tampered(T_NRGVOID, 0.0, 0.0); - } - else if (Player.p_status != S_CLOAKED) - /* holy grail */ - tampered(T_GRAIL, 0.0, 0.0); - break; - } - else - loc += SZ_VOIDSTRUCT; + if (loc > 0L) + /* not the holy grail; inactivate energy void */ + { + Enrgyvoid.ev_active = FALSE; + writevoid(&Enrgyvoid, loc); + tampered(T_NRGVOID, 0.0, 0.0); + } else + if (Player.p_status != S_CLOAKED) + /* holy grail */ + tampered(T_GRAIL, 0.0, 0.0); + break; + } else + loc += SZ_VOIDSTRUCT; - /* now check for other things */ - readrecord(&Other, Fileloc); - if (Other.p_tampered != T_OFF) - tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch); + /* now check for other things */ + readrecord(&Other, Fileloc); + if (Other.p_tampered != T_OFF) + tampered(Other.p_tampered, Other.p_1scratch, Other.p_2scratch); } /**/ /************************************************************************ @@ -532,169 +523,156 @@ long loc = 0L; /* location in energy void file */ / *************************************************************************/ +void tampered(what, arg1, arg2) -int what; -double arg1; -double arg2; + int what; + double arg1; + double arg2; { -long loc; /* location in file of other players */ + long loc; /* location in file of other players */ - Changed = TRUE; - move(4,0); + Changed = TRUE; + move(4, 0); - Player.p_tampered = T_OFF; /* no longer tampered with */ + Player.p_tampered = T_OFF; /* no longer tampered with */ - switch (what) - { + switch (what) { case T_NRGVOID: - addstr("You've hit an energy void !\n"); - Player.p_mana /= 3.0; - Player.p_energy /= 2.0; - Player.p_gold = floor(Player.p_gold/1.25) + 0.1; - altercoordinates(0.0, 0.0, A_NEAR); - break; + addstr("You've hit an energy void !\n"); + Player.p_mana /= 3.0; + Player.p_energy /= 2.0; + Player.p_gold = floor(Player.p_gold / 1.25) + 0.1; + altercoordinates(0.0, 0.0, A_NEAR); + break; case T_TRANSPORT: - addstr("The king transported you ! "); - if (Player.p_charms > 0) - { - addstr("But your charm saved you. . .\n"); - --Player.p_charms; + addstr("The king transported you ! "); + if (Player.p_charms > 0) { + addstr("But your charm saved you. . .\n"); + --Player.p_charms; + } else { + altercoordinates(0.0, 0.0, A_FAR); + addch('\n'); } - else - { - altercoordinates(0.0, 0.0, A_FAR); - addch('\n'); - } - break; + break; case T_BESTOW: - printw("The king has bestowed %.0f gold pieces on you !\n", arg1); - Player.p_gold += arg1; - break; + printw("The king has bestowed %.0f gold pieces on you !\n", arg1); + Player.p_gold += arg1; + break; case T_CURSED: - addstr("You've been cursed ! "); - if (Player.p_blessing) - { - addstr("But your blessing saved you. . .\n"); - Player.p_blessing = FALSE; - } - else - { - addch('\n'); - Player.p_poison += 2.0; - Player.p_energy = 10.0; - Player.p_maxenergy *= 0.95; - Player.p_status = S_PLAYING; /* no longer cloaked */ + addstr("You've been cursed ! "); + if (Player.p_blessing) { + addstr("But your blessing saved you. . .\n"); + Player.p_blessing = FALSE; + } else { + addch('\n'); + Player.p_poison += 2.0; + Player.p_energy = 10.0; + Player.p_maxenergy *= 0.95; + Player.p_status = S_PLAYING; /* no longer cloaked */ } - break; + break; case T_VAPORIZED: - addstr("You have been vaporized!\n"); - more(7); - death("Vaporization"); - break; + addstr("You have been vaporized!\n"); + more(7); + death("Vaporization"); + break; case T_MONSTER: - addstr("The Valar zapped you with a monster!\n"); - more(7); - encounter((int) arg1); - return; + addstr("The Valar zapped you with a monster!\n"); + more(7); + encounter((int) arg1); + return; case T_BLESSED: - addstr("The Valar has blessed you!\n"); - Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield; - Player.p_mana += 500.0; - Player.p_strength += 0.5; - Player.p_brains += 0.5; - Player.p_magiclvl += 0.5; - Player.p_poison = MIN(0.5, Player.p_poison); - break; + addstr("The Valar has blessed you!\n"); + Player.p_energy = (Player.p_maxenergy *= 1.05) + Player.p_shield; + Player.p_mana += 500.0; + Player.p_strength += 0.5; + Player.p_brains += 0.5; + Player.p_magiclvl += 0.5; + Player.p_poison = MIN(0.5, Player.p_poison); + break; case T_RELOCATE: - addstr("You've been relocated. . .\n"); - altercoordinates(arg1, arg2, A_FORCED); - break; + addstr("You've been relocated. . .\n"); + altercoordinates(arg1, arg2, A_FORCED); + break; case T_HEAL: - addstr("You've been healed!\n"); - Player.p_poison -= 0.25; - Player.p_energy = Player.p_maxenergy + Player.p_shield; - break; + addstr("You've been healed!\n"); + Player.p_poison -= 0.25; + Player.p_energy = Player.p_maxenergy + Player.p_shield; + break; case T_EXVALAR: - addstr("You are no longer Valar!\n"); - Player.p_specialtype = SC_COUNCIL; - break; + addstr("You are no longer Valar!\n"); + Player.p_specialtype = SC_COUNCIL; + break; case T_GRAIL: - addstr("You have found The Holy Grail!!\n"); - if (Player.p_specialtype < SC_COUNCIL) - /* must be council of wise to behold grail */ + addstr("You have found The Holy Grail!!\n"); + if (Player.p_specialtype < SC_COUNCIL) + /* must be council of wise to behold grail */ { - addstr("However, you are not experienced enough to behold it.\n"); - Player.p_sin *= Player.p_sin; - Player.p_mana += 1000; - } - else if (Player.p_specialtype == SC_VALAR - || Player.p_specialtype == SC_EXVALAR) - { - addstr("You have made it to the position of Valar once already.\n"); - addstr("The Grail is of no more use to you now.\n"); - } - else - { - addstr("It is now time to see if you are worthy to behold it. . .\n"); - refresh(); - sleep(4); - - if (drandom() / 2.0 < Player.p_sin) - { - addstr("You have failed!\n"); - Player.p_strength = - Player.p_mana = - Player.p_energy = - Player.p_maxenergy = - Player.p_magiclvl = - Player.p_brains = - Player.p_experience = - Player.p_quickness = 1.0; - - altercoordinates(1.0, 1.0, A_FORCED); - Player.p_level = 0.0; - } - else - { - addstr("You made to position of Valar!\n"); - Player.p_specialtype = SC_VALAR; - Player.p_lives = 5; - fseek(Playersfp, 0L, 0); - loc = 0L; - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - /* search for existing valar */ - if (Other.p_specialtype == SC_VALAR - && Other.p_status != S_NOTUSED) - /* found old valar */ - { - Other.p_tampered = T_EXVALAR; - writerecord(&Other, loc); - break; - } - else - loc += SZ_PLAYERSTRUCT; - } - } - - /* move grail to new location */ - Enrgyvoid.ev_active = TRUE; - Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6); - Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6); - writevoid(&Enrgyvoid, 0L); - break; + addstr("However, you are not experienced enough to behold it.\n"); + Player.p_sin *= Player.p_sin; + Player.p_mana += 1000; + } else + if (Player.p_specialtype == SC_VALAR + || Player.p_specialtype == SC_EXVALAR) { + addstr("You have made it to the position of Valar once already.\n"); + addstr("The Grail is of no more use to you now.\n"); + } else { + addstr("It is now time to see if you are worthy to behold it. . .\n"); + refresh(); + sleep(4); + + if (drandom() / 2.0 < Player.p_sin) { + addstr("You have failed!\n"); + Player.p_strength = + Player.p_mana = + Player.p_energy = + Player.p_maxenergy = + Player.p_magiclvl = + Player.p_brains = + Player.p_experience = + Player.p_quickness = 1.0; + + altercoordinates(1.0, 1.0, A_FORCED); + Player.p_level = 0.0; + } else { + addstr("You made to position of Valar!\n"); + Player.p_specialtype = SC_VALAR; + Player.p_lives = 5; + fseek(Playersfp, 0L, 0); + loc = 0L; + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + /* search for existing valar */ + if (Other.p_specialtype == SC_VALAR + && Other.p_status != S_NOTUSED) + /* found old valar */ + { + Other.p_tampered = T_EXVALAR; + writerecord(&Other, loc); + break; + } else + loc += SZ_PLAYERSTRUCT; + } + } + + /* move grail to new location */ + Enrgyvoid.ev_active = TRUE; + Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6); + Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6); + writevoid(&Enrgyvoid, 0L); + break; } - refresh(); - sleep(2); + refresh(); + sleep(2); } /**/ /************************************************************************ @@ -729,71 +707,67 @@ long loc; /* location in file of other players */ / *************************************************************************/ +void userlist(ingameflag) -bool ingameflag; + bool ingameflag; { -register int numusers = 0; /* number of users on file */ + int numusers = 0; /* number of users on file */ - if (ingameflag && Player.p_blindness) - { - mvaddstr(8, 0, "You cannot see anyone.\n"); - return; + if (ingameflag && Player.p_blindness) { + mvaddstr(8, 0, "You cannot see anyone.\n"); + return; } + fseek(Playersfp, 0L, 0); + mvaddstr(8, 0, + "Name X Y Lvl Type Login Status\n"); + + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) { + if (Other.p_status == S_NOTUSED + /* record is unused */ + || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED)) + /* cloaked valar */ + { + if (!Wizard) + /* wizard can see everything on file */ + continue; + } + ++numusers; - fseek(Playersfp, 0L, 0); - mvaddstr(8, 0, - "Name X Y Lvl Type Login Status\n"); - - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - { - if (Other.p_status == S_NOTUSED - /* record is unused */ - || (Other.p_specialtype == SC_VALAR && Other.p_status == S_CLOAKED)) - /* cloaked valar */ - { - if (!Wizard) - /* wizard can see everything on file */ - continue; - } - - ++numusers; - - if (ingameflag && + if (ingameflag && /* must be playing for the rest of these conditions */ - (Player.p_specialtype >= SC_KING + (Player.p_specialtype >= SC_KING /* kings and higher can see others */ - || Other.p_specialtype >= SC_KING + || Other.p_specialtype >= SC_KING /* kings and higher can be seen by others */ - || Circle >= CIRCLE(Other.p_x, Other.p_y) + || Circle >= CIRCLE(Other.p_x, Other.p_y) /* those nearer the origin can be seen */ - || Player.p_palantir) + || Player.p_palantir) /* palantir enables one to see others */ - && (Other.p_status != S_CLOAKED - || (Player.p_specialtype == SC_VALAR && Player.p_palantir)) + && (Other.p_status != S_CLOAKED + || (Player.p_specialtype == SC_VALAR && Player.p_palantir)) /* not cloaked; valar can see through cloak with a palantir */ - && Other.p_specialtype != SC_VALAR) - /* not a valar */ - /* coordinates should be printed */ - printw("%-20s %8.0f %8.0f ", - Other.p_name, Other.p_x, Other.p_y); - else - /* cannot see player's coordinates */ - printw("%-20s %19.19s ", - Other.p_name, descrlocation(&Other, TRUE)); - - printw("%6.0f %s %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE), - Other.p_login, descrstatus(&Other)); - - if ((numusers % (LINES - 10)) == 0) - { - more(LINES - 1); - move(9, 0); - clrtobot(); - } + && Other.p_specialtype != SC_VALAR) + /* not a valar */ + /* coordinates should be printed */ + printw("%-20s %8.0f %8.0f ", + Other.p_name, Other.p_x, Other.p_y); + else + /* cannot see player's coordinates */ + printw("%-20s %19.19s ", + Other.p_name, descrlocation(&Other, TRUE)); + + printw("%6.0f %s %-9.9s%s\n", Other.p_level, descrtype(&Other, TRUE), + Other.p_login, descrstatus(&Other)); + + if ((numusers % (LINES - 10)) == 0) { + more(LINES - 1); + move(9, 0); + clrtobot(); + } } - printw("Total players on file = %d\n", numusers); - refresh(); + printw("Total players on file = %d\n", numusers); + refresh(); } /**/ /************************************************************************ @@ -824,59 +798,58 @@ register int numusers = 0; /* number of users on file */ / *************************************************************************/ +void throneroom() { -FILE *fp; /* to clear energy voids */ -long loc = 0L; /* location of old king in player file */ + FILE *fp; /* to clear energy voids */ + long loc = 0L; /* location of old king in player file */ - if (Player.p_specialtype < SC_KING) - /* not already king -- assumes crown */ + if (Player.p_specialtype < SC_KING) + /* not already king -- assumes crown */ { - fseek(Playersfp, 0L, 0); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED) - /* found old king */ - { - if (Other.p_status != S_OFF) - /* old king is playing */ - { - mvaddstr( 4, 0, "The king is playing, so you cannot steal his throne\n"); - altercoordinates(0.0, 0.0, A_NEAR); - move(6, 0); - return; - } - else - /* old king is not playing - remove him/her */ - { - Other.p_specialtype = SC_NONE; - if (Other.p_crowns) - --Other.p_crowns; - writerecord(&Other, loc); - break; - } - } - else - loc += SZ_PLAYERSTRUCT; - - /* make player new king */ - Changed = TRUE; - Player.p_specialtype = SC_KING; - mvaddstr(4, 0, "You have become king!\n"); - - /* let everyone else know */ - fp = fopen(_PATH_MESS, "w"); - fprintf(fp, "All hail the new king!"); - fclose(fp); - - /* clear all energy voids; retain location of holy grail */ - fseek(Energyvoidfp, 0L, 0); - fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp); - fp = fopen(_PATH_VOID, "w"); - fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp); - fclose(fp); + fseek(Playersfp, 0L, 0); + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED) + /* found old king */ + { + if (Other.p_status != S_OFF) + /* old king is playing */ + { + mvaddstr(4, 0, "The king is playing, so you cannot steal his throne\n"); + altercoordinates(0.0, 0.0, A_NEAR); + move(6, 0); + return; + } else + /* old king is not playing - remove + * him/her */ + { + Other.p_specialtype = SC_NONE; + if (Other.p_crowns) + --Other.p_crowns; + writerecord(&Other, loc); + break; + } + } else + loc += SZ_PLAYERSTRUCT; + + /* make player new king */ + Changed = TRUE; + Player.p_specialtype = SC_KING; + mvaddstr(4, 0, "You have become king!\n"); + + /* let everyone else know */ + fp = fopen(_PATH_MESS, "w"); + fprintf(fp, "All hail the new king!"); + fclose(fp); + + /* clear all energy voids; retain location of holy grail */ + fseek(Energyvoidfp, 0L, 0); + fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp); + fp = fopen(_PATH_VOID, "w"); + fwrite((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, fp); + fclose(fp); } - - mvaddstr(6, 0, "0:Decree "); + mvaddstr(6, 0, "0:Decree "); } /**/ /************************************************************************ @@ -906,231 +879,211 @@ long loc = 0L; /* location of old king in player file */ / *************************************************************************/ +void dotampered() { -short tamper; /* value for tampering with other players */ -char *option; /* pointer to option description */ -double temp1 = 0.0, temp2 = 0.0; /* other tampering values */ -int ch; /* input */ -long loc; /* location in energy void file */ -FILE *fp; /* for opening gold file */ - - move(6, 0); - clrtoeol(); - if (Player.p_specialtype < SC_COUNCIL && !Wizard) - /* king options */ - { - addstr("1:Transport 2:Curse 3:Energy Void 4:Bestow 5:Collect Taxes "); + short tamper; /* value for tampering with other players */ + char *option; /* pointer to option description */ + double temp1 = 0.0, temp2 = 0.0; /* other tampering values */ + int ch; /* input */ + long loc; /* location in energy void file */ + FILE *fp; /* for opening gold file */ - ch = getanswer(" ", TRUE); move(6, 0); clrtoeol(); - move(4, 0); - switch (ch) - { - case '1': /* transport someone */ - tamper = T_TRANSPORT; - option = "transport"; - break; - - case '2': /* curse another */ - tamper = T_CURSED; - option = "curse"; - break; - - case '3': /* create energy void */ - if ((loc = allocvoid()) > 20L * SZ_VOIDSTRUCT) - /* can only have 20 void active at once */ - mvaddstr(5, 0, "Sorry, void creation limit reached.\n"); - else - { - addstr("Enter the X Y coordinates of void ? "); - getstring(Databuf, SZ_DATABUF); - sscanf(Databuf, "%lf %lf", &temp1, &temp2); - Enrgyvoid.ev_x = floor(temp1); - Enrgyvoid.ev_y = floor(temp2); - Enrgyvoid.ev_active = TRUE; - writevoid(&Enrgyvoid, loc); - mvaddstr(5, 0, "It is done.\n"); - } - return; + if (Player.p_specialtype < SC_COUNCIL && !Wizard) + /* king options */ + { + addstr("1:Transport 2:Curse 3:Energy Void 4:Bestow 5:Collect Taxes "); + + ch = getanswer(" ", TRUE); + move(6, 0); + clrtoeol(); + move(4, 0); + switch (ch) { + case '1': /* transport someone */ + tamper = T_TRANSPORT; + option = "transport"; + break; - case '4': /* bestow gold to subject */ - tamper = T_BESTOW; - addstr("How much gold to bestow ? "); - temp1 = infloat(); - if (temp1 > Player.p_gold || temp1 < 0) - { - mvaddstr(5, 0, "You don't have that !\n"); - return; - } - - /* adjust gold after we are sure it will be given to someone */ - option = "give gold to"; - break; + case '2': /* curse another */ + tamper = T_CURSED; + option = "curse"; + break; - case '5': /* collect accumulated taxes */ - if ((fp = fopen(_PATH_GOLD, "r+")) != NULL) - /* collect taxes */ - { - fread((char *) &temp1, sizeof(double), 1, fp); - fseek(fp, 0L, 0); - /* clear out value */ - temp2 = 0.0; - fwrite((char *) &temp2, sizeof(double), 1, fp); - fclose(fp); - } - - mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1); - Player.p_gold += floor(temp1); - return; + case '3': /* create energy void */ + if ((loc = allocvoid()) > 20L * SZ_VOIDSTRUCT) + /* can only have 20 void active at once */ + mvaddstr(5, 0, "Sorry, void creation limit reached.\n"); + else { + addstr("Enter the X Y coordinates of void ? "); + getstring(Databuf, SZ_DATABUF); + sscanf(Databuf, "%lf %lf", &temp1, &temp2); + Enrgyvoid.ev_x = floor(temp1); + Enrgyvoid.ev_y = floor(temp2); + Enrgyvoid.ev_active = TRUE; + writevoid(&Enrgyvoid, loc); + mvaddstr(5, 0, "It is done.\n"); + } + return; + + case '4': /* bestow gold to subject */ + tamper = T_BESTOW; + addstr("How much gold to bestow ? "); + temp1 = infloat(); + if (temp1 > Player.p_gold || temp1 < 0) { + mvaddstr(5, 0, "You don't have that !\n"); + return; + } + /* adjust gold after we are sure it will be given to + * someone */ + option = "give gold to"; + break; - default: - return; - } - /* end of king options */ - } - else - /* council of wise, valar, wizard options */ - { - addstr("1:Heal "); - if (Player.p_palantir || Wizard) - addstr("2:Seek Grail "); - if (Player.p_specialtype == SC_VALAR || Wizard) - addstr("3:Throw Monster 4:Relocate 5:Bless "); - if (Wizard) - addstr("6:Vaporize "); - - ch = getanswer(" ", TRUE); - if (!Wizard) - { - if (ch > '2' && Player.p_specialtype != SC_VALAR) - { - ILLCMD(); - return; + case '5': /* collect accumulated taxes */ + if ((fp = fopen(_PATH_GOLD, "r+")) != NULL) + /* collect taxes */ + { + fread((char *) &temp1, sizeof(double), 1, fp); + fseek(fp, 0L, 0); + /* clear out value */ + temp2 = 0.0; + fwrite((char *) &temp2, sizeof(double), 1, fp); + fclose(fp); + } + mvprintw(4, 0, "You have collected %.0f in gold.\n", temp1); + Player.p_gold += floor(temp1); + return; + + default: + return; } - - if (Player.p_mana < MM_INTERVENE) - { - mvaddstr(5, 0, "No mana left.\n"); - return; + /* end of king options */ + } else + /* council of wise, valar, wizard options */ + { + addstr("1:Heal "); + if (Player.p_palantir || Wizard) + addstr("2:Seek Grail "); + if (Player.p_specialtype == SC_VALAR || Wizard) + addstr("3:Throw Monster 4:Relocate 5:Bless "); + if (Wizard) + addstr("6:Vaporize "); + + ch = getanswer(" ", TRUE); + if (!Wizard) { + if (ch > '2' && Player.p_specialtype != SC_VALAR) { + ILLCMD(); + return; + } + if (Player.p_mana < MM_INTERVENE) { + mvaddstr(5, 0, "No mana left.\n"); + return; + } else + Player.p_mana -= MM_INTERVENE; } - else - Player.p_mana -= MM_INTERVENE; - } - - switch (ch) - { - case '1': /* heal another */ - tamper = T_HEAL; - option = "heal"; - break; + switch (ch) { + case '1': /* heal another */ + tamper = T_HEAL; + option = "heal"; + break; - case '2': /* seek grail */ - if (Player.p_palantir) - /* need a palantir to seek */ - { - fseek(Energyvoidfp, 0L, 0); - fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp); - temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y); - temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0); /* add some error */ - mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1); - } - else - /* no palantir */ - mvaddstr(5, 0, "You need a palantir to seek the Grail.\n"); - return; + case '2': /* seek grail */ + if (Player.p_palantir) + /* need a palantir to seek */ + { + fseek(Energyvoidfp, 0L, 0); + fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp); + temp1 = distance(Player.p_x, Enrgyvoid.ev_x, Player.p_y, Enrgyvoid.ev_y); + temp1 += ROLL(-temp1 / 10.0, temp1 / 5.0); /* add some error */ + mvprintw(5, 0, "The palantir says the Grail is about %.0f away.\n", temp1); + } else + /* no palantir */ + mvaddstr(5, 0, "You need a palantir to seek the Grail.\n"); + return; + + case '3': /* lob monster at someone */ + mvaddstr(4, 0, "Which monster [0-99] ? "); + temp1 = infloat(); + temp1 = MAX(0.0, MIN(99.0, temp1)); + tamper = T_MONSTER; + option = "throw a monster at"; + break; - case '3': /* lob monster at someone */ - mvaddstr(4, 0, "Which monster [0-99] ? "); - temp1 = infloat(); - temp1 = MAX(0.0, MIN(99.0, temp1)); - tamper = T_MONSTER; - option = "throw a monster at"; - break; + case '4': /* move another player */ + mvaddstr(4, 0, "New X Y coordinates ? "); + getstring(Databuf, SZ_DATABUF); + sscanf(Databuf, "%lf %lf", &temp1, &temp2); + tamper = T_RELOCATE; + option = "relocate"; + break; - case '4': /* move another player */ - mvaddstr(4, 0, "New X Y coordinates ? "); - getstring(Databuf, SZ_DATABUF); - sscanf(Databuf, "%lf %lf", &temp1, &temp2); - tamper = T_RELOCATE; - option = "relocate"; - break; + case '5': /* bless a player */ + tamper = T_BLESSED; + option = "bless"; + break; - case '5': /* bless a player */ - tamper = T_BLESSED; - option = "bless"; - break; + case '6': /* kill off a player */ + if (Wizard) { + tamper = T_VAPORIZED; + option = "vaporize"; + break; + } else + return; - case '6': /* kill off a player */ - if (Wizard) - { - tamper = T_VAPORIZED; - option = "vaporize"; - break; - } - else - return; - - default: - return; - } + default: + return; + } - /* adjust age after we are sure intervention will be done */ - /* end of valar, etc. options */ + /* adjust age after we are sure intervention will be done */ + /* end of valar, etc. options */ } - for (;;) - /* prompt for player to affect */ + for (;;) + /* prompt for player to affect */ { - mvprintw(4, 0, "Who do you want to %s ? ", option); - getstring(Databuf, SZ_DATABUF); - truncstring(Databuf); + mvprintw(4, 0, "Who do you want to %s ? ", option); + getstring(Databuf, SZ_DATABUF); + truncstring(Databuf); - if (Databuf[0] == '\0') - userlist(TRUE); - else - break; + if (Databuf[0] == '\0') + userlist(TRUE); + else + break; } - if (strcmp(Player.p_name, Databuf) != 0) - /* name other than self */ + if (strcmp(Player.p_name, Databuf) != 0) + /* name other than self */ { - if ((loc = findname(Databuf, &Other)) >= 0L) - { - if (Other.p_tampered != T_OFF) - { - mvaddstr(5, 0, "That person has something pending already.\n"); - return; - } - else - { - if (tamper == T_RELOCATE - && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y) - && !Wizard) - mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n"); - else - { - if (tamper == T_BESTOW) Player.p_gold -= floor(temp1); - if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER || - tamper == T_RELOCATE || tamper == T_BLESSED)) - Player.p_age += N_AGE; /* age penalty */ - Other.p_tampered = tamper; - Other.p_1scratch = floor(temp1); - Other.p_2scratch = floor(temp2); - writerecord(&Other, loc); - mvaddstr(5, 0, "It is done.\n"); - } - return; - } - } - else - /* player not found */ - mvaddstr(5, 0, "There is no one by that name.\n"); - } - else - /* self */ - mvaddstr(5, 0, "You may not do it to yourself!\n"); + if ((loc = findname(Databuf, &Other)) >= 0L) { + if (Other.p_tampered != T_OFF) { + mvaddstr(5, 0, "That person has something pending already.\n"); + return; + } else { + if (tamper == T_RELOCATE + && CIRCLE(temp1, temp2) < CIRCLE(Other.p_x, Other.p_y) + && !Wizard) + mvaddstr(5, 0, "Cannot move someone closer to the Lord's Chamber.\n"); + else { + if (tamper == T_BESTOW) + Player.p_gold -= floor(temp1); + if (!Wizard && (tamper == T_HEAL || tamper == T_MONSTER || + tamper == T_RELOCATE || tamper == T_BLESSED)) + Player.p_age += N_AGE; /* age penalty */ + Other.p_tampered = tamper; + Other.p_1scratch = floor(temp1); + Other.p_2scratch = floor(temp2); + writerecord(&Other, loc); + mvaddstr(5, 0, "It is done.\n"); + } + return; + } + } else + /* player not found */ + mvaddstr(5, 0, "There is no one by that name.\n"); + } else + /* self */ + mvaddstr(5, 0, "You may not do it to yourself!\n"); } /**/ /************************************************************************ @@ -1158,15 +1111,16 @@ FILE *fp; /* for opening gold file */ / *************************************************************************/ +void writevoid(vp, loc) -register struct energyvoid *vp; -long loc; + struct energyvoid *vp; + long loc; { - fseek(Energyvoidfp, loc, 0); - fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp); - fflush(Energyvoidfp); - fseek(Energyvoidfp, 0L, 0); + fseek(Energyvoidfp, loc, 0); + fwrite((char *) vp, SZ_VOIDSTRUCT, 1, Energyvoidfp); + fflush(Energyvoidfp); + fseek(Energyvoidfp, 0L, 0); } /**/ /************************************************************************ @@ -1197,14 +1151,14 @@ long loc; long allocvoid() { -long loc = 0L; /* location of new energy void */ + long loc = 0L; /* location of new energy void */ - fseek(Energyvoidfp, 0L, 0); - while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1) - if (Enrgyvoid.ev_active) - loc += SZ_VOIDSTRUCT; - else - break; + fseek(Energyvoidfp, 0L, 0); + while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1) + if (Enrgyvoid.ev_active) + loc += SZ_VOIDSTRUCT; + else + break; - return(loc); + return (loc); } diff --git a/games/phantasia/io.c b/games/phantasia/io.c index 3a55d2bd12e..47ca6909d1f 100644 --- a/games/phantasia/io.c +++ b/games/phantasia/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.3 1998/07/10 09:46:46 downsj Exp $ */ +/* $OpenBSD: io.c,v 1.4 1998/11/29 19:56:57 pjanzen Exp $ */ /* $NetBSD: io.c,v 1.2 1995/03/24 03:58:50 cgd Exp $ */ /* @@ -42,56 +42,56 @@ / *************************************************************************/ +void getstring(cp, mx) -register char *cp; -register int mx; + char *cp; + int mx; { -register char *inptr; /* pointer into string for next string */ -int x, y; /* original x, y coordinates on screen */ -int ch; /* input */ + char *inptr; /* pointer into string for next string */ + int x, y; /* original x, y coordinates on screen */ + int ch; /* input */ - getyx(stdscr, y, x); /* get coordinates on screen */ - inptr = cp; - *inptr = '\0'; /* clear string to start */ - --mx; /* reserve room in string for nul terminator */ + getyx(stdscr, y, x); /* get coordinates on screen */ + inptr = cp; + *inptr = '\0'; /* clear string to start */ + --mx; /* reserve room in string for nul terminator */ - do - /* get characters and process */ + do + /* get characters and process */ { - if (Echo) - mvaddstr(y, x, cp); /* print string on screen */ - clrtoeol(); /* clear any data after string */ - refresh(); /* update screen */ - - ch = getchar(); /* get character */ - - switch (ch) - { - case CH_NEWLINE: /* terminate string */ - case CH_RETURN: - break; - - case CH_REDRAW: /* redraw screen */ - clearok(stdscr, TRUE); - continue; - - default: /* put data in string */ - if (ch == Ch_Erase) { /* back up one character */ - if (inptr > cp) - --inptr; - break; - } else if (ch == Ch_Kill) { /* back up to original location */ - inptr = cp; - break; - } else if (isprint(ch) || Wizard) { - /* printing char; put in string */ - *inptr++ = ch; + if (Echo) + mvaddstr(y, x, cp); /* print string on screen */ + clrtoeol(); /* clear any data after string */ + refresh(); /* update screen */ + + ch = getchar(); /* get character */ + + switch (ch) { + case CH_NEWLINE: /* terminate string */ + case CH_RETURN: + break; + + case CH_REDRAW: /* redraw screen */ + clearok(stdscr, TRUE); + continue; + + default: /* put data in string */ + if (ch == Ch_Erase) { /* back up one character */ + if (inptr > cp) + --inptr; + break; + } else if (ch == Ch_Kill) { /* back up to original location */ + inptr = cp; + break; + } else if (isprint(ch) || Wizard) { + /* printing char; put in string */ + *inptr++ = ch; + } } - } - *inptr = '\0'; /* terminate string */ + *inptr = '\0'; /* terminate string */ } - while (ch != CH_NEWLINE && ch != CH_RETURN && inptr < cp + mx); + while (ch != CH_NEWLINE && ch != CH_RETURN && inptr < cp + mx); } /**/ /************************************************************************ @@ -118,11 +118,12 @@ int ch; /* input */ / *************************************************************************/ +void more(where) -int where; + int where; { - mvaddstr(where, 0, "-- more --"); - getanswer(" ", FALSE); + mvaddstr(where, 0, "-- more --"); + getanswer(" ", FALSE); } /**/ /************************************************************************ @@ -153,14 +154,14 @@ int where; double infloat() { -double result; /* return value */ + double result; /* return value */ - getstring(Databuf, SZ_DATABUF); - if (sscanf(Databuf, "%lf", &result) < 1) - /* no valid number entered */ - result = 0.0; + getstring(Databuf, SZ_DATABUF); + if (sscanf(Databuf, "%lf", &result) < 1) + /* no valid number entered */ + result = 0.0; - return(result); + return (result); } /**/ /************************************************************************ @@ -188,18 +189,19 @@ double result; /* return value */ / *************************************************************************/ +int inputoption() { - ++Player.p_age; /* increase age */ + ++Player.p_age; /* increase age */ - if (Player.p_ring.ring_type != R_SPOILED) - /* ring ok */ - return(getanswer("T ", TRUE)); - else - /* bad ring */ + if (Player.p_ring.ring_type != R_SPOILED) + /* ring ok */ + return (getanswer("T ", TRUE)); + else + /* bad ring */ { - getanswer(" ", TRUE); - return((int) ROLL(0.0, 5.0) + '0'); + getanswer(" ", TRUE); + return ((int) ROLL(0.0, 5.0) + '0'); } } /**/ @@ -216,9 +218,8 @@ inputoption() / RETURN VALUE: none / / MODULES CALLED: fork(), exit(), wait(), death(), alarm(), execl(), wmove(), -/ getgid(), signal(), getenv(), wclear(), setuid(), getuid(), setgid(), -/ crmode(), clearok(), waddstr(), cleanup(), wrefresh(), leavegame(), -/ getanswer() +/ signal(), getenv(), wclear(), crmode(), clearok(), waddstr(), +/ cleanup(), wrefresh(), leavegame(), getanswer() / / GLOBAL INPUTS: Player, *stdscr / @@ -231,62 +232,60 @@ inputoption() / *************************************************************************/ +void interrupt() { -char line[81]; /* a place to store data already on screen */ -register int loop; /* counter */ -int x, y; /* coordinates on screen */ -int ch; /* input */ -unsigned savealarm; /* to save alarm value */ + char line[81]; /* a place to store data already on screen */ + int loop; /* counter */ + int x, y; /* coordinates on screen */ + int ch; /* input */ + unsigned savealarm; /* to save alarm value */ #ifdef SYS3 - signal(SIGINT, SIG_IGN); + signal(SIGINT, SIG_IGN); #endif #ifdef SYS5 - signal(SIGINT, SIG_IGN); + signal(SIGINT, SIG_IGN); #endif - savealarm = alarm(0); /* turn off any alarms */ + savealarm = alarm(0); /* turn off any alarms */ - getyx(stdscr, y, x); /* save cursor location */ + getyx(stdscr, y, x); /* save cursor location */ - for (loop = 0; loop < 80; ++loop) /* save line on screen */ - { - move(4, loop); - line[loop] = inch(); + for (loop = 0; loop < 80; ++loop) { /* save line on screen */ + move(4, loop); + line[loop] = inch(); } - line[80] = '\0'; /* nul terminate */ + line[80] = '\0'; /* nul terminate */ - if (Player.p_status == S_INBATTLE || Player.p_status == S_MONSTER) - /* in midst of fighting */ - { - mvaddstr(4, 0, "Quitting now will automatically kill your character. Still want to ? "); - ch = getanswer("NY", FALSE); - if (ch == 'Y') - death("Bailing out"); - /*NOTREACHED*/ - } - else + if (Player.p_status == S_INBATTLE || Player.p_status == S_MONSTER) + /* in midst of fighting */ { - mvaddstr(4, 0, "Do you really want to quit ? "); - ch = getanswer("NY", FALSE); - if (ch == 'Y') - leavegame(); - /*NOTREACHED*/ + mvaddstr(4, 0, "Quitting now will automatically kill your character. Still want to ? "); + ch = getanswer("NY", FALSE); + if (ch == 'Y') + death("Bailing out"); + /* NOTREACHED */ + } else { + mvaddstr(4, 0, "Do you really want to quit ? "); + ch = getanswer("NY", FALSE); + if (ch == 'Y') + leavegame(); + /* NOTREACHED */ } - mvaddstr(4, 0, line); /* restore data on screen */ - move(y, x); /* restore cursor */ - refresh(); + mvaddstr(4, 0, line); /* restore data on screen */ + move(y, x); /* restore cursor */ + refresh(); #ifdef SYS3 - signal(SIGINT, interrupt); + signal(SIGINT, interrupt); #endif #ifdef SYS5 - signal(SIGINT, interrupt); + signal(SIGINT, interrupt); #endif - alarm(savealarm); /* restore alarm */ + alarm(savealarm); /* restore alarm */ } /**/ /************************************************************************ @@ -321,91 +320,87 @@ unsigned savealarm; /* to save alarm value */ / *************************************************************************/ +int getanswer(choices, def) -char *choices; -bool def; + char *choices; + bool def; { -int ch; /* input */ -int loop; /* counter */ -int oldx, oldy; /* original coordinates on screen */ + int ch; /* input */ + int loop; /* counter */ + int oldx, oldy; /* original coordinates on screen */ - getyx(stdscr, oldy, oldx); - alarm(0); /* make sure alarm is off */ + getyx(stdscr, oldy, oldx); + alarm(0); /* make sure alarm is off */ - for (loop = 3; loop; --loop) - /* try for 3 times */ +#if __GNUC__ + (void)&loop; /* XXX quiet gcc */ +#endif + for (loop = 3; loop; --loop) + for (loop = 3; loop; --loop) + /* try for 3 times */ { - if (setjmp(Timeoenv) != 0) - /* timed out waiting for response */ - { - if (def || loop <= 1) - /* return default answer */ - break; - else - /* prompt, and try again */ - goto YELL; - } - else - /* wait for response */ - { - clrtoeol(); - refresh(); + if (setjmp(Timeoenv) != 0) + /* timed out waiting for response */ + { + if (def || loop <= 1) + /* return default answer */ + break; + else + /* prompt, and try again */ + goto YELL; + } else + /* wait for response */ + { + clrtoeol(); + refresh(); #ifdef BSD41 - sigset(SIGALRM, catchalarm); + sigset(SIGALRM, catchalarm); #else - signal(SIGALRM, catchalarm); + signal(SIGALRM, catchalarm); #endif - /* set timeout */ - if (Timeout) - alarm(7); /* short */ - else - alarm(600); /* long */ - - ch = getchar(); - - alarm(0); /* turn off timeout */ - - if (ch < 0) - /* caught some signal */ - { - ++loop; - continue; - } - else if (ch == CH_REDRAW) - /* redraw screen */ - { - clearok(stdscr, TRUE); /* force clear screen */ - ++loop; /* don't count this input */ - continue; - } - else if (Echo) - { - addch(ch); /* echo character */ - refresh(); - } - - if (islower(ch)) - /* convert to upper case */ - ch = toupper(ch); - - if (def || strchr(choices, ch) != NULL) - /* valid choice */ - return(ch); - else if (!def && loop > 1) - /* bad choice; prompt, and try again */ - { -YELL: mvprintw(oldy + 1, 0, "Please choose one of : [%s]\n", choices); - move(oldy, oldx); - clrtoeol(); - continue; + /* set timeout */ + if (Timeout) + alarm(7); /* short */ + else + alarm(600); /* long */ + + ch = getchar(); + + alarm(0); /* turn off timeout */ + + if (ch < 0) { + /* caught some signal */ + ++loop; + continue; + } else if (ch == CH_REDRAW) { + /* redraw screen */ + clearok(stdscr, TRUE); /* force clear screen */ + ++loop; /* don't count this input */ + continue; + } else if (Echo) { + addch(ch); /* echo character */ + refresh(); + } + if (islower(ch)) + /* convert to upper case */ + ch = toupper(ch); + + if (def || strchr(choices, ch) != NULL) + /* valid choice */ + return (ch); + else if (!def && loop > 1) { + /* bad choice; prompt, and try again */ + YELL: mvprintw(oldy + 1, 0, "Please choose one of : [%s]\n", choices); + move(oldy, oldx); + clrtoeol(); + continue; + } else + /* return default answer */ + break; } - else - /* return default answer */ - break; - } } - return(*choices); + return (*choices); } /**/ /************************************************************************ @@ -433,7 +428,8 @@ YELL: mvprintw(oldy + 1, 0, "Please choose one of : [%s]\n", choices); *************************************************************************/ void -catchalarm() +catchalarm(dummy) + int dummy; { - longjmp(Timeoenv, 1); + longjmp(Timeoenv, 1); } diff --git a/games/phantasia/macros.h b/games/phantasia/macros.h index 39b003c3480..70f34c1c842 100644 --- a/games/phantasia/macros.h +++ b/games/phantasia/macros.h @@ -1,3 +1,4 @@ +/* $OpenBSD: macros.h,v 1.2 1998/11/29 19:56:57 pjanzen Exp $ */ /* $NetBSD: macros.h,v 1.3 1995/04/24 12:24:34 cgd Exp $ */ /* diff --git a/games/phantasia/main.c b/games/phantasia/main.c index d157d7484a8..0a51032aae4 100644 --- a/games/phantasia/main.c +++ b/games/phantasia/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.5 1998/11/28 09:25:53 pjanzen Exp $ */ +/* $OpenBSD: main.c,v 1.6 1998/11/29 19:56:57 pjanzen Exp $ */ /* $NetBSD: main.c,v 1.3 1995/04/24 12:24:37 cgd Exp $ */ /* @@ -54,10 +54,6 @@ * to be updated. */ -/* - * All source files are set up for 'vi' with shiftwidth=4, tabstop=8. - */ - /**/ /* @@ -99,218 +95,210 @@ / ****************************************************************************/ +int main(argc, argv) -int argc; -char **argv; + int argc; + char **argv; { -bool noheader = FALSE; /* set if don't want header */ -bool headeronly = FALSE; /* set if only want header */ -bool examine = FALSE; /* set if examine a character */ -time_t seconds; /* for time of day */ -double dtemp; /* for temporary calculations */ - - initialstate(); /* init globals */ - - /* process arguments */ - while (--argc && (*++argv)[0] == '-') - switch ((*argv)[1]) - { - case 's': /* short */ - noheader = TRUE; - break; - - case 'H': /* Header */ - headeronly = TRUE; - break; + bool noheader = FALSE; /* set if don't want header */ + bool headeronly = FALSE; /* set if only want header */ + bool examine = FALSE; /* set if examine a character */ + time_t seconds; /* for time of day */ + double dtemp; /* for temporary calculations */ + + initialstate(); /* init globals */ + + /* process arguments */ + while (--argc && (*++argv)[0] == '-') + switch ((*argv)[1]) { + case 's': /* short */ + noheader = TRUE; + break; + + case 'H': /* Header */ + headeronly = TRUE; + break; + + case 'a': /* all users */ + activelist(); + cleanup(TRUE); + /* NOTREACHED */ - case 'a': /* all users */ - activelist(); - cleanup(TRUE); - /*NOTREACHED*/ + case 'p': /* purge old players */ + purgeoldplayers(); + cleanup(TRUE); + /* NOTREACHED */ - case 'p': /* purge old players */ - purgeoldplayers(); - cleanup(TRUE); - /*NOTREACHED*/ + case 'S': /* set 'Wizard' */ + Wizard = !getuid(); + break; - case 'S': /* set 'Wizard' */ - Wizard = !getuid(); - break; + case 'x': /* examine */ + examine = TRUE; + break; - case 'x': /* examine */ - examine = TRUE; - break; - - case 'm': /* monsters */ - monstlist(); - cleanup(TRUE); - /*NOTREACHED*/ + case 'm': /* monsters */ + monstlist(); + cleanup(TRUE); + /* NOTREACHED */ - case 'b': /* scoreboard */ - scorelist(); - cleanup(TRUE); - /*NOTREACHED*/ + case 'b': /* scoreboard */ + scorelist(); + cleanup(TRUE); + /* NOTREACHED */ } - if (!isatty(0)) /* don't let non-tty's play */ - cleanup(TRUE); - /*NOTREACHED*/ + if (!isatty(0)) /* don't let non-tty's play */ + cleanup(TRUE); + /* NOTREACHED */ - playinit(); /* set up to catch signals, init curses */ + playinit(); /* set up to catch signals, init curses */ - if (examine) - { - changestats(FALSE); - cleanup(TRUE); - /*NOTREACHED*/ + if (examine) { + changestats(FALSE); + cleanup(TRUE); + /* NOTREACHED */ } - - if (!noheader) - { - titlelist(); - purgeoldplayers(); /* clean up old characters */ + if (!noheader) { + titlelist(); + purgeoldplayers(); /* clean up old characters */ } + if (headeronly) + cleanup(TRUE); + /* NOTREACHED */ - if (headeronly) - cleanup(TRUE); - /*NOTREACHED*/ - - do - /* get the player structure filled */ + do + /* get the player structure filled */ { - Fileloc = -1L; + Fileloc = -1L; - mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? "); + mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? "); - switch (getanswer("NYQ", FALSE)) - { - case 'Y': - Fileloc = recallplayer(); - break; + switch (getanswer("NYQ", FALSE)) { + case 'Y': + Fileloc = recallplayer(); + break; - case 'Q': - cleanup(TRUE); - /*NOTREACHED*/ + case 'Q': + cleanup(TRUE); + /* NOTREACHED */ - default: - Fileloc = rollnewplayer(); - break; - } - clear(); + default: + Fileloc = rollnewplayer(); + break; + } + clear(); } - while (Fileloc < 0L); + while (Fileloc < 0L); - if (Player.p_level > 5.0) - /* low level players have long timeout */ - Timeout = TRUE; + if (Player.p_level > 5.0) + /* low level players have long timeout */ + Timeout = TRUE; - /* update some important player statistics */ - strcpy(Player.p_login, Login); - time(&seconds); - Player.p_lastused = localtime(&seconds)->tm_yday; - Player.p_status = S_PLAYING; - writerecord(&Player, Fileloc); + /* update some important player statistics */ + strcpy(Player.p_login, Login); + time(&seconds); + Player.p_lastused = localtime(&seconds)->tm_yday; + Player.p_status = S_PLAYING; + writerecord(&Player, Fileloc); - Statptr = &Stattable[Player.p_type]; /* initialize pointer */ + Statptr = &Stattable[Player.p_type]; /* initialize pointer */ - /* catch interrupts */ + /* catch interrupts */ #ifdef BSD41 - sigset(SIGINT, interrupt); + sigset(SIGINT, interrupt); #endif #ifdef BSD42 - signal(SIGINT, interrupt); + signal(SIGINT, interrupt); #endif #ifdef SYS3 - signal(SIGINT, interrupt); + signal(SIGINT, interrupt); #endif #ifdef SYS5 - signal(SIGINT, interrupt); + signal(SIGINT, interrupt); #endif - altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */ + altercoordinates(Player.p_x, Player.p_y, A_FORCED); /* set some flags */ - clear(); + clear(); - for (;;) - /* loop forever, processing input */ + for (;;) + /* loop forever, processing input */ { - adjuststats(); /* cleanup stats */ - - if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING) - /* not allowed on throne -- move */ - { - mvaddstr(5,0,"You're not allowed in the Lord's Chamber without a crown.\n"); - altercoordinates(0.0, 0.0, A_NEAR); - } - - checktampered(); /* check for energy voids, etc. */ - - if (Player.p_status != S_CLOAKED - /* not cloaked */ - && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y) - /* |x| = |y| */ - && !Throne) - /* not on throne */ - { - dtemp = sqrt(dtemp / 100.0); - if (floor(dtemp) == dtemp) - /* |x| / 100 == n*n; at a trading post */ + adjuststats(); /* cleanup stats */ + + if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING) + /* not allowed on throne -- move */ { - tradingpost(); - clear(); + mvaddstr(5, 0, "You're not allowed in the Lord's Chamber without a crown.\n"); + altercoordinates(0.0, 0.0, A_NEAR); + } + checktampered();/* check for energy voids, etc. */ + + if (Player.p_status != S_CLOAKED + /* not cloaked */ + && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y) + /* |x| = |y| */ + && !Throne) + /* not on throne */ + { + dtemp = sqrt(dtemp / 100.0); + if (floor(dtemp) == dtemp) + /* |x| / 100 == n*n; at a trading post */ + { + tradingpost(); + clear(); + } } - } + checkbattle(); /* check for player to player battle */ + neatstuff(); /* gurus, medics, etc. */ - checkbattle(); /* check for player to player battle */ - neatstuff(); /* gurus, medics, etc. */ + if (Player.p_status == S_CLOAKED) { + /* costs 3 mana per turn to be cloaked */ + if (Player.p_mana > 3.0) + Player.p_mana -= 3.0; + else + /* ran out of mana, uncloak */ + { + Player.p_status = S_PLAYING; + Changed = TRUE; + } + } - if (Player.p_status == S_CLOAKED) - /* costs 3 mana per turn to be cloaked */ - if (Player.p_mana > 3.0) - Player.p_mana -= 3.0; - else - /* ran out of mana, uncloak */ + if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) + /* change status back to S_PLAYING */ + { + Player.p_status = S_PLAYING; + Changed = TRUE; + } + if (Changed) + /* update file only if important stuff has changed */ { - Player.p_status = S_PLAYING; - Changed = TRUE; + writerecord(&Player, Fileloc); + Changed = FALSE; + continue; } + readmessage(); /* read message, if any */ - if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) - /* change status back to S_PLAYING */ - { - Player.p_status = S_PLAYING; - Changed = TRUE; - } - - if (Changed) - /* update file only if important stuff has changed */ - { - writerecord(&Player, Fileloc); - Changed = FALSE; - continue; - } - - readmessage(); /* read message, if any */ - - displaystats(); /* print statistics */ - - move(6, 0); - - if (Throne) - /* maybe make king, print prompt, etc. */ - throneroom(); - - /* print status line */ - addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit "); - if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK) - addstr("6:Cloak "); - if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT) - addstr("7:Teleport "); - if (Player.p_specialtype >= SC_COUNCIL || Wizard) - addstr("8:Intervene "); - - procmain(); /* process input */ + displaystats(); /* print statistics */ + + move(6, 0); + + if (Throne) + /* maybe make king, print prompt, etc. */ + throneroom(); + + /* print status line */ + addstr("1:Move 2:Players 3:Talk 4:Stats 5:Quit "); + if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK) + addstr("6:Cloak "); + if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT) + addstr("7:Teleport "); + if (Player.p_specialtype >= SC_COUNCIL || Wizard) + addstr("8:Intervene "); + + procmain(); /* process input */ } } /**/ @@ -340,58 +328,59 @@ double dtemp; /* for temporary calculations */ / *************************************************************************/ +void initialstate() { #ifdef TERMIOS struct termios tty; #endif - Beyond = FALSE; - Marsh = FALSE; - Throne = FALSE; - Changed = FALSE; - Wizard = FALSE; - Timeout = FALSE; - Users = 0; - Windows = FALSE; - Echo = TRUE; + Beyond = FALSE; + Marsh = FALSE; + Throne = FALSE; + Changed = FALSE; + Wizard = FALSE; + Timeout = FALSE; + Users = 0; + Windows = FALSE; + Echo = TRUE; #ifdef TERMIOS - /* setup terminal keys */ - if (tcgetattr(0, &tty) == 0) { - Ch_Erase = tty.c_cc[VERASE]; - Ch_Kill = tty.c_cc[VKILL]; - } else { + /* setup terminal keys */ + if (tcgetattr(0, &tty) == 0) { + Ch_Erase = tty.c_cc[VERASE]; + Ch_Kill = tty.c_cc[VKILL]; + } else { + Ch_Erase = CH_ERASE; + Ch_Kill = CH_KILL; + } +#else Ch_Erase = CH_ERASE; Ch_Kill = CH_KILL; - } -#else - Ch_Erase = CH_ERASE; - Ch_Kill = CH_KILL; #endif - /* setup login name */ - if ((Login = getlogin()) == NULL) - Login = getpwuid(getuid())->pw_name; - - /* open some files */ - if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL) - error(_PATH_PEOPLE); - /*NOTREACHED*/ + /* setup login name */ + if ((Login = getlogin()) == NULL) + Login = getpwuid(getuid())->pw_name; + + /* open some files */ + if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL) + error(_PATH_PEOPLE); + /* NOTREACHED */ - if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL) - error(_PATH_MONST); - /*NOTREACHED*/ + if ((Monstfp = fopen(_PATH_MONST, "r+")) == NULL) + error(_PATH_MONST); + /* NOTREACHED */ - if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL) - error(_PATH_MESS); - /*NOTREACHED*/ + if ((Messagefp = fopen(_PATH_MESS, "r")) == NULL) + error(_PATH_MESS); + /* NOTREACHED */ - if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL) - error(_PATH_VOID); - /*NOTREACHED*/ + if ((Energyvoidfp = fopen(_PATH_VOID, "r+")) == NULL) + error(_PATH_VOID); + /* NOTREACHED */ - srandom((unsigned) time(NULL)); /* prime random numbers */ + srandom((unsigned) time(NULL)); /* prime random numbers */ } /**/ /************************************************************************ @@ -422,93 +411,91 @@ initialstate() long rollnewplayer() { -int chartype; /* character type */ -int ch; /* input */ + int chartype; /* character type */ + int ch; /* input */ - initplayer(&Player); /* initialize player structure */ + initplayer(&Player); /* initialize player structure */ - clear(); - mvaddstr(4, 21, "Which type of character do you want:"); - mvaddstr(8, 4, "1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento "); - if (Wizard) { - addstr("7:Super ? "); - chartype = getanswer("1234567", FALSE); - } - else { - addstr("? "); - chartype = getanswer("123456", FALSE); + clear(); + mvaddstr(4, 21, "Which type of character do you want:"); + mvaddstr(8, 4, +"1:Magic User 2:Fighter 3:Elf 4:Dwarf 5:Halfling 6:Experimento "); + if (Wizard) { + addstr("7:Super ? "); + chartype = getanswer("1234567", FALSE); + } else { + addstr("? "); + chartype = getanswer("123456", FALSE); } - do - { - genchar(chartype); /* roll up a character */ + do { + genchar(chartype); /* roll up a character */ - /* print out results */ - mvprintw(12, 14, - "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n", - Player.p_strength, Player.p_quickness, Player.p_mana); - mvprintw(13, 14, - "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n", - Player.p_energy, Player.p_brains, Player.p_magiclvl); + /* print out results */ + mvprintw(12, 14, + "Strength : %2.0f Quickness: %2.0f Mana : %2.0f\n", + Player.p_strength, Player.p_quickness, Player.p_mana); + mvprintw(13, 14, + "Energy Level: %2.0f Brains : %2.0f Magic Level: %2.0f\n", + Player.p_energy, Player.p_brains, Player.p_magiclvl); - if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) - break; + if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) + break; - mvaddstr(14, 14, "Type '1' to keep >"); - ch = getanswer(" ", TRUE); + mvaddstr(14, 14, "Type '1' to keep >"); + ch = getanswer(" ", TRUE); } - while (ch != '1'); + while (ch != '1'); - if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) - /* get coordinates for experimento */ - for (;;) - { - mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? "); - getstring(Databuf, SZ_DATABUF); - sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y); - - if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER) - mvaddstr(17, 0, "Invalid coordinates. Try again.\n"); - else - break; - } + if (Player.p_type == C_EXPER || Player.p_type == C_SUPER) + /* get coordinates for experimento */ + for (;;) { + mvaddstr(16, 0, "Enter the X Y coordinates of your experimento ? "); + getstring(Databuf, SZ_DATABUF); + sscanf(Databuf, "%lf %lf", &Player.p_x, &Player.p_y); + + if (fabs(Player.p_x) > D_EXPER || fabs(Player.p_y) > D_EXPER) + mvaddstr(17, 0, "Invalid coordinates. Try again.\n"); + else + break; + } - for (;;) - /* name the new character */ + for (;;) + /* name the new character */ { - mvprintw(18, 0, - "Give your character a name [up to %d characters] ? ", SZ_NAME - 1); - getstring(Player.p_name, SZ_NAME); - truncstring(Player.p_name); /* remove trailing blanks */ - - if (Player.p_name[0] == '\0') - /* no null names */ - mvaddstr(19, 0, "Invalid name."); - else if (findname(Player.p_name, &Other) >= 0L) - /* cannot have duplicate names */ - mvaddstr(19, 0, "Name already in use."); - else - /* name is acceptable */ - break; - - addstr(" Pick another.\n"); + mvprintw(18, 0, + "Give your character a name [up to %d characters] ? ", SZ_NAME - 1); + getstring(Player.p_name, SZ_NAME); + truncstring(Player.p_name); /* remove trailing blanks */ + + if (Player.p_name[0] == '\0') + /* no null names */ + mvaddstr(19, 0, "Invalid name."); + else + if (findname(Player.p_name, &Other) >= 0L) + /* cannot have duplicate names */ + mvaddstr(19, 0, "Name already in use."); + else + /* name is acceptable */ + break; + + addstr(" Pick another.\n"); } - /* get a password for character */ - Echo = FALSE; + /* get a password for character */ + Echo = FALSE; - do - { - mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? "); - getstring(Player.p_password, SZ_PASSWORD); - mvaddstr(21, 0, "One more time to verify ? "); - getstring(Databuf, SZ_PASSWORD); + do { + mvaddstr(20, 0, "Give your character a password [up to 8 characters] ? "); + getstring(Player.p_password, SZ_PASSWORD); + mvaddstr(21, 0, "One more time to verify ? "); + getstring(Databuf, SZ_PASSWORD); } - while (strcmp(Player.p_password, Databuf) != 0); + while (strcmp(Player.p_password, Databuf) != 0); - Echo = TRUE; + Echo = TRUE; - return(allocrecord()); + return (allocrecord()); } /**/ /************************************************************************ @@ -538,212 +525,213 @@ int ch; /* input */ / *************************************************************************/ +void procmain() { -int ch; /* input */ -double x; /* desired new x coordinate */ -double y; /* desired new y coordinate */ -double temp; /* for temporary calculations */ -FILE *fp; /* for opening files */ -register int loop; /* a loop counter */ -bool hasmoved = FALSE; /* set if player has moved */ + int ch; /* input */ + double x; /* desired new x coordinate */ + double y; /* desired new y coordinate */ + double temp; /* for temporary calculations */ + FILE *fp; /* for opening files */ + int loop; /* a loop counter */ + bool hasmoved = FALSE; /* set if player has moved */ - ch = inputoption(); - mvaddstr(4, 0, "\n\n"); /* clear status area */ + ch = inputoption(); + mvaddstr(4, 0, "\n\n"); /* clear status area */ - move(7, 0); - clrtobot(); /* clear data on bottom area of screen */ + move(7, 0); + clrtobot(); /* clear data on bottom area of screen */ - if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7')) - /* valar cannot move */ - ch = ' '; + if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7')) + /* valar cannot move */ + ch = ' '; - switch (ch) - { + switch (ch) { case 'K': /* move up/north */ case 'N': - x = Player.p_x; - y = Player.p_y + MAXMOVE(); - hasmoved = TRUE; - break; + x = Player.p_x; + y = Player.p_y + MAXMOVE(); + hasmoved = TRUE; + break; case 'J': /* move down/south */ case 'S': - x = Player.p_x; - y = Player.p_y - MAXMOVE(); - hasmoved = TRUE; - break; + x = Player.p_x; + y = Player.p_y - MAXMOVE(); + hasmoved = TRUE; + break; case 'L': /* move right/east */ case 'E': - x = Player.p_x + MAXMOVE(); - y = Player.p_y; - hasmoved = TRUE; - break; + x = Player.p_x + MAXMOVE(); + y = Player.p_y; + hasmoved = TRUE; + break; case 'H': /* move left/west */ case 'W': - x = Player.p_x - MAXMOVE(); - y = Player.p_y; - hasmoved = TRUE; - break; - - default: /* rest */ - Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0 - + Player.p_level / 3.0 + 2.0; - Player.p_energy = - MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield); + x = Player.p_x - MAXMOVE(); + y = Player.p_y; + hasmoved = TRUE; + break; + + default: /* rest */ + Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0 + + Player.p_level / 3.0 + 2.0; + Player.p_energy = + MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield); - if (Player.p_status != S_CLOAKED) - /* cannot find mana if cloaked */ + if (Player.p_status != S_CLOAKED) + /* cannot find mana if cloaked */ { - Player.p_mana += (Circle + Player.p_level) / 4.0; + Player.p_mana += (Circle + Player.p_level) / 4.0; - if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) - /* wandering monster */ - encounter(-1); + if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) + /* wandering monster */ + encounter(-1); } - break; + break; case 'X': /* change/examine a character */ - changestats(TRUE); - break; + changestats(TRUE); + break; case '1': /* move */ - for (loop = 3; loop; --loop) - { - mvaddstr(4, 0, "X Y Coordinates ? "); - getstring(Databuf, SZ_DATABUF); + for (loop = 3; loop; --loop) { + mvaddstr(4, 0, "X Y Coordinates ? "); + getstring(Databuf, SZ_DATABUF); - if (sscanf(Databuf, "%lf %lf", &x, &y) != 2) - mvaddstr(5, 0, "Try again\n"); - else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE()) - ILLMOVE(); - else - { - hasmoved = TRUE; - break; - } + if (sscanf(Databuf, "%lf %lf", &x, &y) != 2) + mvaddstr(5, 0, "Try again\n"); + else + if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE()) + ILLMOVE(); + else { + hasmoved = TRUE; + break; + } } - break; + break; case '2': /* players */ - userlist(TRUE); - break; + userlist(TRUE); + break; case '3': /* message */ - mvaddstr(4, 0, "Message ? "); - getstring(Databuf, SZ_DATABUF); - /* we open the file for writing to erase any data which is already there */ - fp = fopen(_PATH_MESS, "w"); - if (Databuf[0] != '\0') - fprintf(fp, "%s: %s", Player.p_name, Databuf); - fclose(fp); - break; + mvaddstr(4, 0, "Message ? "); + getstring(Databuf, SZ_DATABUF); + /* we open the file for writing to erase any data which is + * already there */ + fp = fopen(_PATH_MESS, "w"); + if (Databuf[0] != '\0') + fprintf(fp, "%s: %s", Player.p_name, Databuf); + fclose(fp); + break; case '4': /* stats */ - allstatslist(); - break; + allstatslist(); + break; case '5': /* good-bye */ - leavegame(); - /*NOTREACHED*/ + leavegame(); + /* NOTREACHED */ case '6': /* cloak */ - if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK) - ILLCMD(); - else if (Player.p_status == S_CLOAKED) - Player.p_status = S_PLAYING; - else if (Player.p_mana < MM_CLOAK) - mvaddstr(5, 0, "No mana left.\n"); - else - { - Changed = TRUE; - Player.p_mana -= MM_CLOAK; - Player.p_status = S_CLOAKED; - } - break; - - case '7': /* teleport */ - /* - * conditions for teleport - * - 20 per (level plus magic level) - * - OR council of the wise or valar or ex-valar - * - OR transport from throne - * transports from throne cost no mana - */ - if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT) - ILLCMD(); - else - for (loop = 3; loop; --loop) - { - mvaddstr(4, 0, "X Y Coordinates ? "); - getstring(Databuf, SZ_DATABUF); - - if (sscanf(Databuf, "%lf %lf", &x, &y) == 2) - { - temp = distance(Player.p_x, x, Player.p_y, y); - if (!Throne - /* can transport anywhere from throne */ - && Player.p_specialtype <= SC_COUNCIL - /* council, valar can transport anywhere */ - && temp > (Player.p_level + Player.p_magiclvl) * 20.0) - /* can only move 20 per exp. level + mag. level */ - ILLMOVE(); + if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK) + ILLCMD(); + else + if (Player.p_status == S_CLOAKED) + Player.p_status = S_PLAYING; else - { - temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */ + if (Player.p_mana < MM_CLOAK) + mvaddstr(5, 0, "No mana left.\n"); + else { + Changed = TRUE; + Player.p_mana -= MM_CLOAK; + Player.p_status = S_CLOAKED; + } + break; - if (!Throne && temp > Player.p_mana) - mvaddstr(5, 0, "Not enough power for that distance.\n"); - else - { - if (!Throne) - Player.p_mana -= temp; - hasmoved = TRUE; - break; + case '7': /* teleport */ + /* + * conditions for teleport + * - 20 per (level plus magic level) + * - OR council of the wise or valar or ex-valar + * - OR transport from throne + * transports from throne cost no mana + */ + if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT) + ILLCMD(); + else + for (loop = 3; loop; --loop) { + mvaddstr(4, 0, "X Y Coordinates ? "); + getstring(Databuf, SZ_DATABUF); + + if (sscanf(Databuf, "%lf %lf", &x, &y) == 2) { + temp = distance(Player.p_x, x, Player.p_y, y); + if (!Throne + /* can transport anywhere from throne */ + && Player.p_specialtype <= SC_COUNCIL + /* council, valar can transport + * anywhere */ + && temp > (Player.p_level + Player.p_magiclvl) * 20.0) + /* can only move 20 per exp. + * level + mag. level */ + ILLMOVE(); + else { + temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */ + + if (!Throne && temp > Player.p_mana) + mvaddstr(5, 0, "Not enough power for that distance.\n"); + else { + if (!Throne) + Player.p_mana -= temp; + hasmoved = TRUE; + break; + } + } } - } } - } - break; + break; case 'C': case '9': /* monster */ - if (Throne) - /* no monsters while on throne */ - mvaddstr(5, 0, "No monsters in the chamber!\n"); - else if (Player.p_specialtype != SC_VALAR) - /* the valar cannot call monsters */ - { - Player.p_sin += 1e-6; - encounter(-1); - } - break; + if (Throne) + /* no monsters while on throne */ + mvaddstr(5, 0, "No monsters in the chamber!\n"); + else + if (Player.p_specialtype != SC_VALAR) + /* the valar cannot call monsters */ + { + Player.p_sin += 1e-6; + encounter(-1); + } + break; case '0': /* decree */ - if (Wizard || Player.p_specialtype == SC_KING && Throne) - /* kings must be on throne to decree */ - dotampered(); - else - ILLCMD(); - break; + if (Wizard || (Player.p_specialtype == SC_KING && Throne)) + /* kings must be on throne to decree */ + dotampered(); + else + ILLCMD(); + break; case '8': /* intervention */ - if (Wizard || Player.p_specialtype >= SC_COUNCIL) - dotampered(); - else - ILLCMD(); - break; + if (Wizard || Player.p_specialtype >= SC_COUNCIL) + dotampered(); + else + ILLCMD(); + break; } - if (hasmoved) - /* player has moved -- alter coordinates, and do random monster */ + if (hasmoved) + /* player has moved -- alter coordinates, and do random + * monster */ { - altercoordinates(x, y, A_SPECIFIC); + altercoordinates(x, y, A_SPECIFIC); - if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) - encounter(-1); + if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) + encounter(-1); } } /**/ @@ -771,112 +759,108 @@ bool hasmoved = FALSE; /* set if player has moved */ / *************************************************************************/ +void titlelist() { -register FILE *fp; /* used for opening various files */ -bool councilfound = FALSE; /* set if we find a member of the council */ -bool kingfound = FALSE; /* set if we find a king */ -double hiexp, nxtexp; /* used for finding the two highest players */ -double hilvl, nxtlvl; /* used for finding the two highest players */ -char hiname[21], nxtname[21];/* used for finding the two highest players */ - - mvaddstr(0, 14, "W e l c o m e t o P h a n t a s i a (vers. 3.3.2)!"); - - /* print message of the day */ - if ((fp = fopen(_PATH_MOTD, "r")) != NULL - && fgets(Databuf, SZ_DATABUF, fp) != NULL) - { - mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf); - fclose(fp); + FILE *fp; /* used for opening various files */ + bool councilfound = FALSE; /* set if we find a member of the + * council */ + bool kingfound = FALSE; /* set if we find a king */ + double hiexp, nxtexp; /* used for finding the two highest players */ + double hilvl, nxtlvl; /* used for finding the two highest players */ + char hiname[21], nxtname[21]; /* used for finding the two + * highest players */ + + nxtexp = 0; + mvaddstr(0, 14, + "W e l c o m e t o P h a n t a s i a (vers. 3.3.2)!"); + + /* print message of the day */ + if ((fp = fopen(_PATH_MOTD, "r")) != NULL + && fgets(Databuf, SZ_DATABUF, fp) != NULL) { + mvaddstr(2, 40 - strlen(Databuf) / 2, Databuf); + fclose(fp); } - - /* search for king */ - fseek(Playersfp, 0L, 0); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - if (Other.p_specialtype == SC_KING && Other.p_status != S_NOTUSED) - /* found the king */ - { - sprintf(Databuf, "The present ruler is %s Level:%.0f", - Other.p_name, Other.p_level); - mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf); - kingfound = TRUE; - break; - } - - if (!kingfound) - mvaddstr(4, 24, "There is no ruler at this time."); - - /* search for valar */ - fseek(Playersfp, 0L, 0); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED) - /* found the valar */ - { - sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login); - mvaddstr(6, 40 - strlen(Databuf) / 2 , Databuf); - break; - } - - /* search for council of the wise */ - fseek(Playersfp, 0L, 0); - Lines = 10; - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED) - /* found a member of the council */ - { - if (!councilfound) + /* search for king */ + fseek(Playersfp, 0L, 0); + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + if (Other.p_specialtype == SC_KING && + Other.p_status != S_NOTUSED) + /* found the king */ { - mvaddstr(8, 30, "Council of the Wise:"); - councilfound = TRUE; + sprintf(Databuf, "The present ruler is %s Level:%.0f", + Other.p_name, Other.p_level); + mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf); + kingfound = TRUE; + break; } - - /* This assumes a finite (<=5) number of C.O.W.: */ - sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login); - mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf); - } - - /* search for the two highest players */ - nxtname[0] = hiname[0] = '\0'; - hiexp = 0.0; - nxtlvl = hilvl = 0; - - fseek(Playersfp, 0L, 0); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED) - /* highest found so far */ - { - nxtexp = hiexp; - hiexp = Other.p_experience; - nxtlvl = hilvl; - hilvl = Other.p_level; - strcpy(nxtname, hiname); - strcpy(hiname, Other.p_name); - } - else if (Other.p_experience > nxtexp - && Other.p_specialtype <= SC_KING - && Other.p_status != S_NOTUSED) - /* next highest found so far */ - { - nxtexp = Other.p_experience; - nxtlvl = Other.p_level; - strcpy(nxtname, Other.p_name); - } - - mvaddstr(15, 28, "Highest characters are:"); - sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f", - hiname, hilvl, nxtname, nxtlvl); - mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf); - - /* print last to die */ - if ((fp = fopen(_PATH_LASTDEAD,"r")) != NULL - && fgets(Databuf, SZ_DATABUF, fp) != NULL) - { - mvaddstr(19, 25, "The last character to die was:"); - mvaddstr(20, 40 - strlen(Databuf) / 2,Databuf); - fclose(fp); + if (!kingfound) + mvaddstr(4, 24, "There is no ruler at this time."); + + /* search for valar */ + fseek(Playersfp, 0L, 0); + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED) + /* found the valar */ + { + sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login); + mvaddstr(6, 40 - strlen(Databuf) / 2, Databuf); + break; + } + /* search for council of the wise */ + fseek(Playersfp, 0L, 0); + Lines = 10; + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + if (Other.p_specialtype == SC_COUNCIL && Other.p_status != S_NOTUSED) + /* found a member of the council */ + { + if (!councilfound) { + mvaddstr(8, 30, "Council of the Wise:"); + councilfound = TRUE; + } + /* This assumes a finite (<=5) number of C.O.W.: */ + sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login); + mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf); + } + /* search for the two highest players */ + nxtname[0] = hiname[0] = '\0'; + hiexp = 0.0; + nxtlvl = hilvl = 0; + + fseek(Playersfp, 0L, 0); + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) + if (Other.p_experience > hiexp && Other.p_specialtype <= SC_KING && Other.p_status != S_NOTUSED) + /* highest found so far */ + { + nxtexp = hiexp; + hiexp = Other.p_experience; + nxtlvl = hilvl; + hilvl = Other.p_level; + strcpy(nxtname, hiname); + strcpy(hiname, Other.p_name); + } else + if (Other.p_experience > nxtexp + && Other.p_specialtype <= SC_KING + && Other.p_status != S_NOTUSED) + /* next highest found so far */ + { + nxtexp = Other.p_experience; + nxtlvl = Other.p_level; + strcpy(nxtname, Other.p_name); + } + mvaddstr(15, 28, "Highest characters are:"); + sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f", + hiname, hilvl, nxtname, nxtlvl); + mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf); + + /* print last to die */ + if ((fp = fopen(_PATH_LASTDEAD, "r")) != NULL + && fgets(Databuf, SZ_DATABUF, fp) != NULL) { + mvaddstr(19, 25, "The last character to die was:"); + mvaddstr(20, 40 - strlen(Databuf) / 2, Databuf); + fclose(fp); } - - refresh(); + refresh(); } /**/ /************************************************************************ @@ -907,63 +891,60 @@ char hiname[21], nxtname[21];/* used for finding the two highest players */ long recallplayer() { -long loc = 0L; /* location in player file */ -register int loop; /* loop counter */ -int ch; /* input */ + long loc = 0L; /* location in player file */ + int loop; /* loop counter */ + int ch; /* input */ - clear(); - mvprintw(10, 0, "What was your character's name ? "); - getstring(Databuf, SZ_NAME); - truncstring(Databuf); + clear(); + mvprintw(10, 0, "What was your character's name ? "); + getstring(Databuf, SZ_NAME); + truncstring(Databuf); - if ((loc = findname(Databuf, &Player)) >= 0L) - /* found character */ + if ((loc = findname(Databuf, &Player)) >= 0L) + /* found character */ { - Echo = FALSE; - - for (loop = 0; loop < 2; ++loop) - { - /* prompt for password */ - mvaddstr(11, 0, "Password ? "); - getstring(Databuf, SZ_PASSWORD); - if (strcmp(Databuf, Player.p_password) == 0) - /* password good */ - { - Echo = TRUE; - - if (Player.p_status != S_OFF) - /* player did not exit normally last time */ - { - clear(); - addstr("Your character did not exit normally last time.\n"); - addstr("If you think you have good cause to have your character saved,\n"); - printw("you may quit and mail your reason to 'root'.\n"); - addstr("Otherwise, continuing spells certain death.\n"); - addstr("Do you want to quit ? "); - ch = getanswer("YN", FALSE); - if (ch == 'Y') + Echo = FALSE; + + for (loop = 0; loop < 2; ++loop) { + /* prompt for password */ + mvaddstr(11, 0, "Password ? "); + getstring(Databuf, SZ_PASSWORD); + if (strcmp(Databuf, Player.p_password) == 0) + /* password good */ { - Player.p_status = S_HUNGUP; - writerecord(&Player, loc); - cleanup(TRUE); - /*NOTREACHED*/ - } - death("Stupidity"); - /*NOTREACHED*/ - } - return(loc); + Echo = TRUE; + + if (Player.p_status != S_OFF) + /* player did not exit normally last + * time */ + { + clear(); + addstr("Your character did not exit normally last time.\n"); + addstr("If you think you have good cause to have your character saved,\n"); + printw("you may quit and mail your reason to 'root'.\n"); + addstr("Otherwise, continuing spells certain death.\n"); + addstr("Do you want to quit ? "); + ch = getanswer("YN", FALSE); + if (ch == 'Y') { + Player.p_status = S_HUNGUP; + writerecord(&Player, loc); + cleanup(TRUE); + /* NOTREACHED */ + } + death("Stupidity"); + /* NOTREACHED */ + } + return (loc); + } else + mvaddstr(12, 0, "No good.\n"); } - else - mvaddstr(12, 0, "No good.\n"); - } - Echo = TRUE; - } - else - mvaddstr(11, 0, "Not found.\n"); + Echo = TRUE; + } else + mvaddstr(11, 0, "Not found.\n"); - more(13); - return(-1L); + more(13); + return (-1L); } /**/ /************************************************************************ @@ -990,113 +971,103 @@ int ch; /* input */ / *************************************************************************/ +void neatstuff() { -double temp; /* for temporary calculations */ -int ch; /* input */ + double temp; /* for temporary calculations */ + int ch; /* input */ - switch ((int) ROLL(0.0, 100.0)) - { + switch ((int) ROLL(0.0, 100.0)) { case 1: case 2: - if (Player.p_poison > 0.0) - { - mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? "); - temp = floor(infloat()); - if (temp < 0.0 || temp > Player.p_gold) - /* negative gold, or more than available */ - { - mvaddstr(6, 0, "He was not amused, and made you worse.\n"); - Player.p_poison += 1.0; - } - else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1)) - /* medic wants 1/2 of available gold */ - mvaddstr(5, 0, "Sorry, he wasn't interested.\n"); - else - { - mvaddstr(5, 0, "He accepted."); - Player.p_poison = MAX(0.0, Player.p_poison - 1.0); - Player.p_gold -= temp; - } + if (Player.p_poison > 0.0) { + mvaddstr(4, 0, "You've found a medic! How much will you offer to be cured ? "); + temp = floor(infloat()); + if (temp < 0.0 || temp > Player.p_gold) + /* negative gold, or more than available */ + { + mvaddstr(6, 0, "He was not amused, and made you worse.\n"); + Player.p_poison += 1.0; + } else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1)) + /* medic wants 1/2 of available gold */ + mvaddstr(5, 0, "Sorry, he wasn't interested.\n"); + else { + mvaddstr(5, 0, "He accepted."); + Player.p_poison = MAX(0.0, Player.p_poison - 1.0); + Player.p_gold -= temp; + } } - break; + break; case 3: - mvaddstr(4, 0, "You've been caught raping and pillaging!\n"); - Player.p_experience += 4000.0; - Player.p_sin += 0.5; - break; + mvaddstr(4, 0, "You've been caught raping and pillaging!\n"); + Player.p_experience += 4000.0; + Player.p_sin += 0.5; + break; case 4: - temp = ROLL(10.0, 75.0); - mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp); - ch = getanswer("NY", FALSE); + temp = ROLL(10.0, 75.0); + mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp); + ch = getanswer("NY", FALSE); - if (ch == 'Y') - collecttaxes(temp, 0.0); - break; + if (ch == 'Y') + collecttaxes(temp, 0.0); + break; case 5: - if (Player.p_sin > 1.0) - { - mvaddstr(4, 0, "You've found a Holy Orb!\n"); - Player.p_sin -= 0.25; + if (Player.p_sin > 1.0) { + mvaddstr(4, 0, "You've found a Holy Orb!\n"); + Player.p_sin -= 0.25; } - break; + break; case 6: - if (Player.p_poison < 1.0) - { - mvaddstr(4, 0, "You've been hit with a plague!\n"); - Player.p_poison += 1.0; + if (Player.p_poison < 1.0) { + mvaddstr(4, 0, "You've been hit with a plague!\n"); + Player.p_poison += 1.0; } - break; + break; case 7: - mvaddstr(4, 0, "You've found some holy water.\n"); - ++Player.p_holywater; - break; + mvaddstr(4, 0, "You've found some holy water.\n"); + ++Player.p_holywater; + break; case 8: - mvaddstr(4, 0, "You've met a Guru. . ."); - if (drandom() * Player.p_sin > 1.0) - addstr("You disgusted him with your sins!\n"); - else if (Player.p_poison > 0.0) - { - addstr("He looked kindly upon you, and cured you.\n"); - Player.p_poison = 0.0; + mvaddstr(4, 0, "You've met a Guru. . ."); + if (drandom() * Player.p_sin > 1.0) + addstr("You disgusted him with your sins!\n"); + else if (Player.p_poison > 0.0) { + addstr("He looked kindly upon you, and cured you.\n"); + Player.p_poison = 0.0; + } else { + addstr("He rewarded you for your virtue.\n"); + Player.p_mana += 50.0; + Player.p_shield += 2.0; } - else - { - addstr("He rewarded you for your virtue.\n"); - Player.p_mana += 50.0; - Player.p_shield += 2.0; - } - break; + break; case 9: - mvaddstr(4, 0, "You've found an amulet.\n"); - ++Player.p_amulets; - break; + mvaddstr(4, 0, "You've found an amulet.\n"); + ++Player.p_amulets; + break; case 10: - if (Player.p_blindness) - { - mvaddstr(4, 0, "You've regained your sight!\n"); - Player.p_blindness = FALSE; + if (Player.p_blindness) { + mvaddstr(4, 0, "You've regained your sight!\n"); + Player.p_blindness = FALSE; } - break; + break; - default: /* deal with poison */ - if (Player.p_poison > 0.0) - { - temp = Player.p_poison * Statptr->c_weakness - * Player.p_maxenergy / 600.0; - if (Player.p_energy > Player.p_maxenergy / 10.0 - && temp + 5.0 < Player.p_energy) - Player.p_energy -= temp; + default: /* deal with poison */ + if (Player.p_poison > 0.0) { + temp = Player.p_poison * Statptr->c_weakness + * Player.p_maxenergy / 600.0; + if (Player.p_energy > Player.p_maxenergy / 10.0 + && temp + 5.0 < Player.p_energy) + Player.p_energy -= temp; } - break; + break; } } /**/ @@ -1124,40 +1095,41 @@ int ch; /* input */ / *************************************************************************/ +void genchar(type) -int type; + int type; { -register int subscript; /* used for subscripting into Stattable */ -register struct charstats *statptr;/* for pointing into Stattable */ - - subscript = type - '1'; - - if (subscript < C_MAGIC || subscript > C_EXPER) - if (subscript != C_SUPER || !Wizard) - /* fighter is default */ - subscript = C_FIGHTER; - - statptr = &Stattable[subscript]; - - Player.p_quickness = - ROLL(statptr->c_quickness.base, statptr->c_quickness.interval); - Player.p_strength = - ROLL(statptr->c_strength.base, statptr->c_strength.interval); - Player.p_mana = - ROLL(statptr->c_mana.base, statptr->c_mana.interval); - Player.p_maxenergy = - Player.p_energy = - ROLL(statptr->c_energy.base, statptr->c_energy.interval); - Player.p_brains = - ROLL(statptr->c_brains.base, statptr->c_brains.interval); - Player.p_magiclvl = - ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval); - - Player.p_type = subscript; - - if (Player.p_type == C_HALFLING) - /* give halfling some experience */ - Player.p_experience = ROLL(600.0, 200.0); + int subscript; /* used for subscripting into Stattable */ + struct charstats *statptr; /* for pointing into Stattable */ + + subscript = type - '1'; + + if (subscript < C_MAGIC || subscript > C_EXPER) + if (subscript != C_SUPER || !Wizard) + /* fighter is default */ + subscript = C_FIGHTER; + + statptr = &Stattable[subscript]; + + Player.p_quickness = + ROLL(statptr->c_quickness.base, statptr->c_quickness.interval); + Player.p_strength = + ROLL(statptr->c_strength.base, statptr->c_strength.interval); + Player.p_mana = + ROLL(statptr->c_mana.base, statptr->c_mana.interval); + Player.p_maxenergy = + Player.p_energy = + ROLL(statptr->c_energy.base, statptr->c_energy.interval); + Player.p_brains = + ROLL(statptr->c_brains.base, statptr->c_brains.interval); + Player.p_magiclvl = + ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval); + + Player.p_type = subscript; + + if (Player.p_type == C_HALFLING) + /* give halfling some experience */ + Player.p_experience = ROLL(600.0, 200.0); } /**/ /************************************************************************ @@ -1184,85 +1156,85 @@ register struct charstats *statptr;/* for pointing into Stattable */ / *************************************************************************/ +void playinit() { - /* catch/ingnore signals */ + /* catch/ignore signals */ #ifdef BSD41 - sigignore(SIGQUIT); - sigignore(SIGALRM); - sigignore(SIGTERM); - sigignore(SIGTSTP); - sigignore(SIGTTIN); - sigignore(SIGTTOU); - sighold(SIGINT); - sigset(SIGHUP, ill_sig); - sigset(SIGTRAP, ill_sig); - sigset(SIGIOT, ill_sig); - sigset(SIGEMT, ill_sig); - sigset(SIGFPE, ill_sig); - sigset(SIGBUS, ill_sig); - sigset(SIGSEGV, ill_sig); - sigset(SIGSYS, ill_sig); - sigset(SIGPIPE, ill_sig); + sigignore(SIGQUIT); + sigignore(SIGALRM); + sigignore(SIGTERM); + sigignore(SIGTSTP); + sigignore(SIGTTIN); + sigignore(SIGTTOU); + sighold(SIGINT); + sigset(SIGHUP, ill_sig); + sigset(SIGTRAP, ill_sig); + sigset(SIGIOT, ill_sig); + sigset(SIGEMT, ill_sig); + sigset(SIGFPE, ill_sig); + sigset(SIGBUS, ill_sig); + sigset(SIGSEGV, ill_sig); + sigset(SIGSYS, ill_sig); + sigset(SIGPIPE, ill_sig); #endif #ifdef BSD42 - signal(SIGQUIT, ill_sig); - signal(SIGALRM, SIG_IGN); - signal(SIGTERM, SIG_IGN); - signal(SIGTSTP, SIG_IGN); - signal(SIGTTIN, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - signal(SIGINT, ill_sig); - signal(SIGHUP, SIG_DFL); - signal(SIGTRAP, ill_sig); - signal(SIGIOT, ill_sig); - signal(SIGEMT, ill_sig); - signal(SIGFPE, ill_sig); - signal(SIGBUS, ill_sig); - signal(SIGSEGV, ill_sig); - signal(SIGSYS, ill_sig); - signal(SIGPIPE, ill_sig); + signal(SIGQUIT, ill_sig); + signal(SIGALRM, SIG_IGN); + signal(SIGTERM, SIG_IGN); + signal(SIGTSTP, SIG_IGN); + signal(SIGTTIN, SIG_IGN); + signal(SIGTTOU, SIG_IGN); + signal(SIGINT, ill_sig); + signal(SIGHUP, SIG_DFL); + signal(SIGTRAP, ill_sig); + signal(SIGIOT, ill_sig); + signal(SIGEMT, ill_sig); + signal(SIGFPE, ill_sig); + signal(SIGBUS, ill_sig); + signal(SIGSEGV, ill_sig); + signal(SIGSYS, ill_sig); + signal(SIGPIPE, ill_sig); #endif #ifdef SYS3 - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGTERM, SIG_IGN); - signal(SIGALRM, SIG_IGN); - signal(SIGHUP, ill_sig); - signal(SIGTRAP, ill_sig); - signal(SIGIOT, ill_sig); - signal(SIGEMT, ill_sig); - signal(SIGFPE, ill_sig); - signal(SIGBUS, ill_sig); - signal(SIGSEGV, ill_sig); - signal(SIGSYS, ill_sig); - signal(SIGPIPE, ill_sig); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + signal(SIGALRM, SIG_IGN); + signal(SIGHUP, ill_sig); + signal(SIGTRAP, ill_sig); + signal(SIGIOT, ill_sig); + signal(SIGEMT, ill_sig); + signal(SIGFPE, ill_sig); + signal(SIGBUS, ill_sig); + signal(SIGSEGV, ill_sig); + signal(SIGSYS, ill_sig); + signal(SIGPIPE, ill_sig); #endif #ifdef SYS5 - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGTERM, SIG_IGN); - signal(SIGALRM, SIG_IGN); - signal(SIGHUP, ill_sig); - signal(SIGTRAP, ill_sig); - signal(SIGIOT, ill_sig); - signal(SIGEMT, ill_sig); - signal(SIGFPE, ill_sig); - signal(SIGBUS, ill_sig); - signal(SIGSEGV, ill_sig); - signal(SIGSYS, ill_sig); - signal(SIGPIPE, ill_sig); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + signal(SIGTERM, SIG_IGN); + signal(SIGALRM, SIG_IGN); + signal(SIGHUP, ill_sig); + signal(SIGTRAP, ill_sig); + signal(SIGIOT, ill_sig); + signal(SIGEMT, ill_sig); + signal(SIGFPE, ill_sig); + signal(SIGBUS, ill_sig); + signal(SIGSEGV, ill_sig); + signal(SIGSYS, ill_sig); + signal(SIGPIPE, ill_sig); #endif - initscr(); /* turn on curses */ - noecho(); /* do not echo input */ - crmode(); /* do not process erase, kill */ - clear(); - refresh(); - Windows = TRUE; /* mark the state */ + initscr(); /* turn on curses */ + noecho(); /* do not echo input */ + crmode(); /* do not process erase, kill */ + clear(); + refresh(); + Windows = TRUE; /* mark the state */ } - /**/ /************************************************************************ / @@ -1290,34 +1262,34 @@ playinit() / *************************************************************************/ +void cleanup(doexit) -bool doexit; + int doexit; { - if (Windows) - { - move(LINES - 2, 0); - refresh(); - nocrmode(); - endwin(); + if (Windows) { + move(LINES - 2, 0); + refresh(); + nocrmode(); + endwin(); + } + + if (Playersfp) { + fclose(Playersfp); + Playersfp = NULL; + } + if (Monstfp) { + fclose(Monstfp); + Monstfp = NULL; + } + if (Messagefp) { + fclose(Messagefp); + Messagefp = NULL; + } + if (Energyvoidfp) { + fclose(Energyvoidfp); + Energyvoidfp = NULL; } - if (Playersfp) { - fclose(Playersfp); - Playersfp = NULL; - } - if (Monstfp) { - fclose(Monstfp); - Monstfp = NULL; - } - if (Messagefp) { - fclose(Messagefp); - Messagefp = NULL; - } - if (Energyvoidfp) { - fclose(Energyvoidfp); - Energyvoidfp = NULL; - } - - if (doexit) - exit(0); + if (doexit) + exit(0); } diff --git a/games/phantasia/misc.c b/games/phantasia/misc.c index ef7c9535dd1..cdffc8cf414 100644 --- a/games/phantasia/misc.c +++ b/games/phantasia/misc.c @@ -1,3 +1,4 @@ +/* $OpenBSD: misc.c,v 1.5 1998/11/29 19:56:58 pjanzen Exp $ */ /* $NetBSD: misc.c,v 1.2 1995/03/24 03:59:03 cgd Exp $ */ /* @@ -34,58 +35,57 @@ / *************************************************************************/ +void movelevel() { -register struct charstats *statptr; /* for pointing into Stattable */ -double new; /* new level */ -double inc; /* increment between new and old levels */ - - Changed = TRUE; - - if (Player.p_type == C_EXPER) - /* roll a type to use for increment */ - statptr = &Stattable[(int) ROLL(C_MAGIC, C_HALFLING - C_MAGIC + 1)]; - else - statptr = Statptr; - - new = explevel(Player.p_experience); - inc = new - Player.p_level; - Player.p_level = new; - - /* add increments to statistics */ - Player.p_strength += statptr->c_strength.increase * inc; - Player.p_mana += statptr->c_mana.increase * inc; - Player.p_brains += statptr->c_brains.increase * inc; - Player.p_magiclvl += statptr->c_magiclvl.increase * inc; - Player.p_maxenergy += statptr->c_energy.increase * inc; - - /* rest to maximum upon reaching new level */ - Player.p_energy = Player.p_maxenergy + Player.p_shield; - - if (Player.p_crowns > 0 && Player.p_level >= 1000.0) - /* no longer able to be king -- turn crowns into cash */ + struct charstats *statptr; /* for pointing into Stattable */ + double new; /* new level */ + double inc; /* increment between new and old levels */ + + Changed = TRUE; + + if (Player.p_type == C_EXPER) + /* roll a type to use for increment */ + statptr = &Stattable[(int) ROLL(C_MAGIC, C_HALFLING - C_MAGIC + 1)]; + else + statptr = Statptr; + + new = explevel(Player.p_experience); + inc = new - Player.p_level; + Player.p_level = new; + + /* add increments to statistics */ + Player.p_strength += statptr->c_strength.increase * inc; + Player.p_mana += statptr->c_mana.increase * inc; + Player.p_brains += statptr->c_brains.increase * inc; + Player.p_magiclvl += statptr->c_magiclvl.increase * inc; + Player.p_maxenergy += statptr->c_energy.increase * inc; + + /* rest to maximum upon reaching new level */ + Player.p_energy = Player.p_maxenergy + Player.p_shield; + + if (Player.p_crowns > 0 && Player.p_level >= 1000.0) + /* no longer able to be king -- turn crowns into cash */ { - Player.p_gold += ((double) Player.p_crowns) * 5000.0; - Player.p_crowns = 0; + Player.p_gold += ((double) Player.p_crowns) * 5000.0; + Player.p_crowns = 0; } - - if (Player.p_level >= 3000.0 && Player.p_specialtype < SC_COUNCIL) - /* make a member of the council */ + if (Player.p_level >= 3000.0 && Player.p_specialtype < SC_COUNCIL) + /* make a member of the council */ { - mvaddstr(6, 0, "You have made it to the Council of the Wise.\n"); - addstr("Good Luck on your search for the Holy Grail.\n"); + mvaddstr(6, 0, "You have made it to the Council of the Wise.\n"); + addstr("Good Luck on your search for the Holy Grail.\n"); - Player.p_specialtype = SC_COUNCIL; + Player.p_specialtype = SC_COUNCIL; - /* no rings for council and above */ - Player.p_ring.ring_type = R_NONE; - Player.p_ring.ring_duration = 0; + /* no rings for council and above */ + Player.p_ring.ring_type = R_NONE; + Player.p_ring.ring_duration = 0; - Player.p_lives = 3; /* three extra lives */ + Player.p_lives = 3; /* three extra lives */ } - - if (Player.p_level > 9999.0 && Player.p_specialtype != SC_VALAR) - death("Old age"); + if (Player.p_level > 9999.0 && Player.p_specialtype != SC_VALAR) + death("Old age"); } /**/ /************************************************************************ @@ -114,60 +114,57 @@ double inc; /* increment between new and old levels */ / *************************************************************************/ -char * +char * descrlocation(playerp, shortflag) -struct player *playerp; -bool shortflag; + struct player *playerp; + bool shortflag; { -double circle; /* corresponding circle for coordinates */ -register int quadrant; /* quandrant of grid */ -register char *label; /* pointer to place name */ -static char *nametable[4][4] = /* names of places */ + double circle; /* corresponding circle for coordinates */ + int quadrant; /* quandrant of grid */ + char *label; /* pointer to place name */ + static char *nametable[4][4] = /* names of places */ { - "Anorien", "Ithilien", "Rohan", "Lorien", - "Gondor", "Mordor", "Dunland", "Rovanion", - "South Gondor", "Khand", "Eriador", "The Iron Hills", - "Far Harad", "Near Harad", "The Northern Waste", "Rhun" + {"Anorien", "Ithilien", "Rohan", "Lorien"}, + {"Gondor", "Mordor", "Dunland", "Rovanion"}, + {"South Gondor", "Khand", "Eriador", "The Iron Hills"}, + {"Far Harad", "Near Harad", "The Northern Waste", "Rhun"} }; - if (playerp->p_specialtype == SC_VALAR) - return(" is in Valhala"); - else if ((circle = CIRCLE(playerp->p_x, playerp->p_y)) >= 1000.0) - { - if (MAX(fabs(playerp->p_x), fabs(playerp->p_y)) > D_BEYOND) - label = "The Point of No Return"; - else - label = "The Ashen Mountains"; - } - else if (circle >= 55) - label = "Morannon"; - else if (circle >= 35) - label = "Kennaquahair"; - else if (circle >= 20) - label = "The Dead Marshes"; - else if (circle >= 9) - label = "The Outer Waste"; - else if (circle >= 5) - label = "The Moors Adventurous"; - else - { - if (playerp->p_x == 0.0 && playerp->p_y == 0.0) - label = "The Lord's Chamber"; - else - { - /* this expression is split to prevent compiler loop with some compilers */ - quadrant = ((playerp->p_x > 0.0) ? 1 : 0); - quadrant += ((playerp->p_y >= 0.0) ? 2 : 0); - label = nametable[((int) circle) - 1][quadrant]; - } + if (playerp->p_specialtype == SC_VALAR) + return (" is in Valhala"); + else if ((circle = CIRCLE(playerp->p_x, playerp->p_y)) >= 1000.0) { + if (MAX(fabs(playerp->p_x), fabs(playerp->p_y)) > D_BEYOND) + label = "The Point of No Return"; + else + label = "The Ashen Mountains"; + } else if (circle >= 55) + label = "Morannon"; + else if (circle >= 35) + label = "Kennaquahair"; + else if (circle >= 20) + label = "The Dead Marshes"; + else if (circle >= 9) + label = "The Outer Waste"; + else if (circle >= 5) + label = "The Moors Adventurous"; + else { + if (playerp->p_x == 0.0 && playerp->p_y == 0.0) + label = "The Lord's Chamber"; + else { + /* this expression is split to prevent compiler + * loop with some compilers */ + quadrant = ((playerp->p_x > 0.0) ? 1 : 0); + quadrant += ((playerp->p_y >= 0.0) ? 2 : 0); + label = nametable[((int) circle) - 1][quadrant]; + } } - if (shortflag) - sprintf(Databuf, "%.29s", label); - else - sprintf(Databuf, " is in %s (%.0f,%.0f)", label, playerp->p_x, playerp->p_y); + if (shortflag) + sprintf(Databuf, "%.29s", label); + else + sprintf(Databuf, " is in %s (%.0f,%.0f)", label, playerp->p_x, playerp->p_y); - return(Databuf); + return (Databuf); } /**/ /************************************************************************ @@ -215,268 +212,251 @@ static char *nametable[4][4] = /* names of places */ / *************************************************************************/ +void tradingpost() { -double numitems; /* number of items to purchase */ -double cost; /* cost of purchase */ -double blessingcost; /* cost of blessing */ -int ch; /* input */ -register int size; /* size of the trading post */ -register int loop; /* loop counter */ -int cheat = 0; /* number of times player has tried to cheat */ -bool dishonest = FALSE;/* set when merchant is dishonest */ - - Player.p_status = S_TRADING; - writerecord(&Player, Fileloc); - - clear(); - addstr("You are at a trading post. All purchases must be made with gold."); - - size = sqrt(fabs(Player.p_x / 100)) + 1; - size = MIN(7, size); - - /* set up cost of blessing */ - blessingcost = 1000.0 * (Player.p_level + 5.0); - - /* print Menu */ - move(7, 0); - for (loop = 0; loop < size; ++loop) - /* print Menu */ - { - if (loop == 6) - cost = blessingcost; - else - cost = Menu[loop].cost; - printw("(%d) %-12s: %6.0f\n", loop + 1, Menu[loop].item, cost); - } - - mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? "); - - for (;;) - { - adjuststats(); /* truncate any bad values */ - - /* print some important statistics */ - mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n", - Player.p_gold, Player.p_gems, Player.p_level, Player.p_charms); - printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n", - Player.p_shield, Player.p_sword, Player.p_quksilver, - (Player.p_blessing ? " True" : "False")); - printw("Brains: %9.0f Mana: %9.0f", Player.p_brains, Player.p_mana); - - move(5, 36); - ch = getanswer("LPS", FALSE); - move(15, 0); - clrtobot(); - switch(ch) - { - case 'L': /* leave */ - case '\n': - altercoordinates(0.0, 0.0, A_NEAR); - return; - - case 'P': /* make purchase */ - mvaddstr(15, 0, "What what would you like to buy ? "); - ch = getanswer(" 1234567", FALSE); - move(15, 0); - clrtoeol(); - - if (ch - '0' > size) - addstr("Sorry, this merchant doesn't have that."); - else - switch (ch) - { - case '1': - printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ", - Menu[0].cost, floor(Player.p_gold / Menu[0].cost)); - cost = (numitems = floor(infloat())) * Menu[0].cost; - - if (cost > Player.p_gold || numitems < 0) - ++cheat; - else - { - cheat = 0; - Player.p_gold -= cost; - if (drandom() < 0.02) - dishonest = TRUE; - else - Player.p_mana += numitems; - } - break; + double numitems; /* number of items to purchase */ + double cost; /* cost of purchase */ + double blessingcost; /* cost of blessing */ + int ch; /* input */ + int size; /* size of the trading post */ + int loop; /* loop counter */ + int cheat = 0; /* number of times player has tried to cheat */ + bool dishonest = FALSE; /* set when merchant is dishonest */ + + Player.p_status = S_TRADING; + writerecord(&Player, Fileloc); - case '2': - printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ", - Menu[1].cost, floor(Player.p_gold / Menu[1].cost)); - cost = (numitems = floor(infloat())) * Menu[1].cost; + clear(); + addstr("You are at a trading post. All purchases must be made with gold."); - if (numitems == 0.0) - break; - else if (cost > Player.p_gold || numitems < 0) - ++cheat; - else if (numitems < Player.p_shield) - NOBETTER(); - else - { - cheat = 0; - Player.p_gold -= cost; - if (drandom() < 0.02) - dishonest = TRUE; - else - Player.p_shield = numitems; - } - break; + size = sqrt(fabs(Player.p_x / 100)) + 1; + size = MIN(7, size); - case '3': - printw("A book costs %.0f gp. How many do you want (%.0f max) ? ", - Menu[2].cost, floor(Player.p_gold / Menu[2].cost)); - cost = (numitems = floor(infloat())) * Menu[2].cost; + /* set up cost of blessing */ + blessingcost = 1000.0 * (Player.p_level + 5.0); - if (cost > Player.p_gold || numitems < 0) - ++cheat; - else - { - cheat = 0; - Player.p_gold -= cost; - if (drandom() < 0.02) - dishonest = TRUE; - else if (drandom() * numitems > Player.p_level / 10.0 - && numitems != 1) - { - printw("\nYou blew your mind!\n"); - Player.p_brains /= 5; - } - else - { - Player.p_brains += floor(numitems) * ROLL(20, 8); - } - } - break; + /* print Menu */ + move(7, 0); + for (loop = 0; loop < size; ++loop) + /* print Menu */ + { + if (loop == 6) + cost = blessingcost; + else + cost = Menu[loop].cost; + printw("(%d) %-12s: %6.0f\n", loop + 1, Menu[loop].item, cost); + } - case '4': - printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ", - Menu[3].cost, floor(Player.p_gold / Menu[3].cost)); - cost = (numitems = floor(infloat())) * Menu[3].cost; + mvprintw(5, 0, "L:Leave P:Purchase S:Sell Gems ? "); - if (numitems == 0.0) - break; - else if (cost > Player.p_gold || numitems < 0) - ++cheat; - else if (numitems < Player.p_sword) - NOBETTER(); - else - { - cheat = 0; - Player.p_gold -= cost; - if (drandom() < 0.02) - dishonest = TRUE; - else - Player.p_sword = numitems; - } - break; + for (;;) { + adjuststats(); /* truncate any bad values */ - case '5': - printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ", - Menu[4].cost, floor(Player.p_gold / Menu[4].cost)); - cost = (numitems = floor(infloat())) * Menu[4].cost; + /* print some important statistics */ + mvprintw(1, 0, "Gold: %9.0f Gems: %9.0f Level: %6.0f Charms: %6d\n", + Player.p_gold, Player.p_gems, Player.p_level, Player.p_charms); + printw("Shield: %9.0f Sword: %9.0f Quicksilver:%3.0f Blessed: %s\n", + Player.p_shield, Player.p_sword, Player.p_quksilver, + (Player.p_blessing ? " True" : "False")); + printw("Brains: %9.0f Mana: %9.0f", Player.p_brains, Player.p_mana); - if (cost > Player.p_gold || numitems < 0) - ++cheat; - else - { - cheat = 0; - Player.p_gold -= cost; - if (drandom() < 0.02) - dishonest = TRUE; - else - Player.p_charms += numitems; + move(5, 36); + ch = getanswer("LPS", FALSE); + move(15, 0); + clrtobot(); + switch (ch) { + case 'L': /* leave */ + case '\n': + altercoordinates(0.0, 0.0, A_NEAR); + return; + + case 'P': /* make purchase */ + mvaddstr(15, 0, "What what would you like to buy ? "); + ch = getanswer(" 1234567", FALSE); + move(15, 0); + clrtoeol(); + + if (ch - '0' > size) + addstr("Sorry, this merchant doesn't have that."); + else + switch (ch) { + case '1': + printw("Mana is one per %.0f gold piece. How many do you want (%.0f max) ? ", + Menu[0].cost, floor(Player.p_gold / Menu[0].cost)); + cost = (numitems = floor(infloat())) * Menu[0].cost; + + if (cost > Player.p_gold || numitems < 0) + ++cheat; + else { + cheat = 0; + Player.p_gold -= cost; + if (drandom() < 0.02) + dishonest = TRUE; + else + Player.p_mana += numitems; + } + break; + + case '2': + printw("Shields are %.0f per +1. How many do you want (%.0f max) ? ", + Menu[1].cost, floor(Player.p_gold / Menu[1].cost)); + cost = (numitems = floor(infloat())) * Menu[1].cost; + + if (numitems == 0.0) + break; + else if (cost > Player.p_gold || numitems < 0) + ++cheat; + else if (numitems < Player.p_shield) + NOBETTER(); + else { + cheat = 0; + Player.p_gold -= cost; + if (drandom() < 0.02) + dishonest = TRUE; + else + Player.p_shield = numitems; + } + break; + + case '3': + printw("A book costs %.0f gp. How many do you want (%.0f max) ? ", + Menu[2].cost, floor(Player.p_gold / Menu[2].cost)); + cost = (numitems = floor(infloat())) * Menu[2].cost; + + if (cost > Player.p_gold || numitems < 0) + ++cheat; + else { + cheat = 0; + Player.p_gold -= cost; + if (drandom() < 0.02) + dishonest = TRUE; + else if (drandom() * numitems > Player.p_level / 10.0 + && numitems != 1) { + printw("\nYou blew your mind!\n"); + Player.p_brains /= 5; + } else { + Player.p_brains += floor(numitems) * ROLL(20, 8); + } + } + break; + + case '4': + printw("Swords are %.0f gp per +1. How many + do you want (%.0f max) ? ", + Menu[3].cost, floor(Player.p_gold / Menu[3].cost)); + cost = (numitems = floor(infloat())) * Menu[3].cost; + + if (numitems == 0.0) + break; + else if (cost > Player.p_gold || numitems < 0) + ++cheat; + else if (numitems < Player.p_sword) + NOBETTER(); + else { + cheat = 0; + Player.p_gold -= cost; + if (drandom() < 0.02) + dishonest = TRUE; + else + Player.p_sword = numitems; + } + break; + + case '5': + printw("A charm costs %.0f gp. How many do you want (%.0f max) ? ", + Menu[4].cost, floor(Player.p_gold / Menu[4].cost)); + cost = (numitems = floor(infloat())) * Menu[4].cost; + + if (cost > Player.p_gold || numitems < 0) + ++cheat; + else { + cheat = 0; + Player.p_gold -= cost; + if (drandom() < 0.02) + dishonest = TRUE; + else + Player.p_charms += numitems; + } + break; + + case '6': + printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ", + Menu[5].cost, floor(Player.p_gold / Menu[5].cost)); + cost = (numitems = floor(infloat())) * Menu[5].cost; + + if (numitems == 0.0) + break; + else if (cost > Player.p_gold || numitems < 0) + ++cheat; + else if (numitems < Player.p_quksilver) + NOBETTER(); + else { + cheat = 0; + Player.p_gold -= cost; + if (drandom() < 0.02) + dishonest = TRUE; + else + Player.p_quksilver = numitems; + } + break; + + case '7': + if (Player.p_blessing) { + addstr("You already have a blessing."); + break; + } + printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost); + ch = getanswer("NY", FALSE); + + if (ch == 'Y') { + if (Player.p_gold < blessingcost) + ++cheat; + else { + cheat = 0; + Player.p_gold -= blessingcost; + if (drandom() < 0.02) + dishonest = TRUE; + else + Player.p_blessing = TRUE; + } + } + break; } - break; + break; - case '6': - printw("Quicksilver is %.0f gp per +1. How many + do you want (%.0f max) ? ", - Menu[5].cost, floor(Player.p_gold / Menu[5].cost)); - cost = (numitems = floor(infloat())) * Menu[5].cost; + case 'S': /* sell gems */ + mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ", + (double) N_GEMVALUE, Player.p_gems); + numitems = floor(infloat()); - if (numitems == 0.0) - break; - else if (cost > Player.p_gold || numitems < 0) + if (numitems > Player.p_gems || numitems < 0) ++cheat; - else if (numitems < Player.p_quksilver) - NOBETTER(); - else - { + else { cheat = 0; - Player.p_gold -= cost; - if (drandom() < 0.02) - dishonest = TRUE; - else - Player.p_quksilver = numitems; - } - break; - - case '7': - if (Player.p_blessing) - { - addstr("You already have a blessing."); - break; - } - - printw("A blessing requires a %.0f gp donation. Still want one ? ", blessingcost); - ch = getanswer("NY", FALSE); - - if (ch == 'Y') - if (Player.p_gold < blessingcost) - ++cheat; - else - { - cheat = 0; - Player.p_gold -= blessingcost; - if (drandom() < 0.02) - dishonest = TRUE; - else - Player.p_blessing = TRUE; - } - break; + Player.p_gems -= numitems; + Player.p_gold += numitems * N_GEMVALUE; } - break; - - case 'S': /* sell gems */ - mvprintw(15, 0, "A gem is worth %.0f gp. How many do you want to sell (%.0f max) ? ", - (double) N_GEMVALUE, Player.p_gems); - numitems = floor(infloat()); + } - if (numitems > Player.p_gems || numitems < 0) - ++cheat; - else - { - cheat = 0; - Player.p_gems -= numitems; - Player.p_gold += numitems * N_GEMVALUE; - } - } - - if (cheat == 1) - mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n"); - else if (cheat == 2) - { - mvaddstr(17, 0, "You had your chance. This merchant happens to be\n"); - printw("a %.0f level magic user, and you made %s mad!\n", - ROLL(Circle * 20.0, 40.0), (drandom() < 0.5) ? "him" : "her"); - altercoordinates(0.0, 0.0, A_FAR); - Player.p_energy /= 2.0; - ++Player.p_sin; - more(23); - return; - } - else if (dishonest) - { - mvaddstr(17, 0, "The merchant stole your money!"); - refresh(); - altercoordinates(Player.p_x - Player.p_x / 10.0, - Player.p_y - Player.p_y / 10.0, A_SPECIFIC); - sleep(2); - return; - } + if (cheat == 1) + mvaddstr(17, 0, "Come on, merchants aren't stupid. Stop cheating.\n"); + else if (cheat == 2) { + mvaddstr(17, 0, "You had your chance. This merchant happens to be\n"); + printw("a %.0f level magic user, and you made %s mad!\n", + ROLL(Circle * 20.0, 40.0), (drandom() < 0.5) ? "him" : "her"); + altercoordinates(0.0, 0.0, A_FAR); + Player.p_energy /= 2.0; + ++Player.p_sin; + more(23); + return; + } else if (dishonest) { + mvaddstr(17, 0, "The merchant stole your money!"); + refresh(); + altercoordinates(Player.p_x - Player.p_x / 10.0, + Player.p_y - Player.p_y / 10.0, A_SPECIFIC); + sleep(2); + return; + } } } /**/ @@ -503,15 +483,16 @@ bool dishonest = FALSE;/* set when merchant is dishonest */ / *************************************************************************/ +void displaystats() { - mvprintw(0, 0, "%s%s\n", Player.p_name, descrlocation(&Player, FALSE)); - mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n", - Player.p_level, Player.p_energy, Player.p_maxenergy + Player.p_shield, - Player.p_mana, Users); - mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n", - Player.p_speed, Player.p_quickness + Player.p_quksilver, Player.p_might, - Player.p_strength + Player.p_sword, Player.p_gold, descrstatus(&Player)); + mvprintw(0, 0, "%s%s\n", Player.p_name, descrlocation(&Player, FALSE)); + mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n", + Player.p_level, Player.p_energy, Player.p_maxenergy + Player.p_shield, + Player.p_mana, Users); + mvprintw(2, 0, "Quick :%3.0f(%3.0f) Strength:%9.0f(%9.0f) Gold :%9.0f %s\n", + Player.p_speed, Player.p_quickness + Player.p_quksilver, Player.p_might, + Player.p_strength + Player.p_sword, Player.p_gold, descrstatus(&Player)); } /**/ /************************************************************************ @@ -537,34 +518,37 @@ displaystats() / *************************************************************************/ +void allstatslist() { -static char *flags[] = /* to print value of some bools */ - { - "False", - " True" - }; - - mvprintw( 8, 0, "Type: %s\n", descrtype(&Player, FALSE)); - - mvprintw(10, 0, "Experience: %9.0f", Player.p_experience); - mvprintw(11, 0, "Brains : %9.0f", Player.p_brains); - mvprintw(12, 0, "Magic Lvl : %9.0f", Player.p_magiclvl); - mvprintw(13, 0, "Sin : %9.5f", Player.p_sin); - mvprintw(14, 0, "Poison : %9.5f", Player.p_poison); - mvprintw(15, 0, "Gems : %9.0f", Player.p_gems); - mvprintw(16, 0, "Age : %9d", Player.p_age); - mvprintw(10, 40, "Holy Water: %9d", Player.p_holywater); - mvprintw(11, 40, "Amulets : %9d", Player.p_amulets); - mvprintw(12, 40, "Charms : %9d", Player.p_charms); - mvprintw(13, 40, "Crowns : %9d", Player.p_crowns); - mvprintw(14, 40, "Shield : %9.0f", Player.p_shield); - mvprintw(15, 40, "Sword : %9.0f", Player.p_sword); - mvprintw(16, 40, "Quickslver: %9.0f", Player.p_quksilver); - - mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s", - flags[Player.p_blessing], flags[Player.p_ring.ring_type != R_NONE], - flags[Player.p_virgin], flags[Player.p_palantir]); + static char *flags[] = /* to print value of some bools */ + { + "False", + " True" + }; + + mvprintw(8, 0, "Type: %s\n", descrtype(&Player, FALSE)); + + mvprintw(10, 0, "Experience: %9.0f", Player.p_experience); + mvprintw(11, 0, "Brains : %9.0f", Player.p_brains); + mvprintw(12, 0, "Magic Lvl : %9.0f", Player.p_magiclvl); + mvprintw(13, 0, "Sin : %9.5f", Player.p_sin); + mvprintw(14, 0, "Poison : %9.5f", Player.p_poison); + mvprintw(15, 0, "Gems : %9.0f", Player.p_gems); + mvprintw(16, 0, "Age : %9d", Player.p_age); + mvprintw(10, 40, "Holy Water: %9d", Player.p_holywater); + mvprintw(11, 40, "Amulets : %9d", Player.p_amulets); + mvprintw(12, 40, "Charms : %9d", Player.p_charms); + mvprintw(13, 40, "Crowns : %9d", Player.p_crowns); + mvprintw(14, 40, "Shield : %9.0f", Player.p_shield); + mvprintw(15, 40, "Sword : %9.0f", Player.p_sword); + mvprintw(16, 40, "Quickslver: %9.0f", Player.p_quksilver); + + mvprintw(18, 0, "Blessing: %s Ring: %s Virgin: %s Palantir: %s", + flags[(int)Player.p_blessing], + flags[Player.p_ring.ring_type != R_NONE], + flags[(int)Player.p_virgin], + flags[(int)Player.p_palantir]); } /**/ /************************************************************************ @@ -596,71 +580,68 @@ static char *flags[] = /* to print value of some bools */ / *************************************************************************/ -char * +char * descrtype(playerp, shortflag) -struct player *playerp; -bool shortflag; + struct player *playerp; + bool shortflag; { -register int type; /* for caluculating result subscript */ -static char *results[] = /* description table */ - { - " Magic User", " MU", - " Fighter", " F ", - " Elf", " E ", - " Dwarf", " D ", - " Halfling", " H ", - " Experimento", " EX", - " Super", " S ", - " King", " K ", - " Council of Wise", " CW", - " Ex-Valar", " EV", - " Valar", " V ", - " ? ", " ? " - }; - - type = playerp->p_type; - - switch (playerp->p_specialtype) + int type; /* for caluculating result subscript */ + static char *results[] =/* description table */ { + " Magic User", " MU", + " Fighter", " F ", + " Elf", " E ", + " Dwarf", " D ", + " Halfling", " H ", + " Experimento", " EX", + " Super", " S ", + " King", " K ", + " Council of Wise", " CW", + " Ex-Valar", " EV", + " Valar", " V ", + " ? ", " ? " + }; + + type = playerp->p_type; + + switch (playerp->p_specialtype) { case SC_NONE: - type = playerp->p_type; - break; + type = playerp->p_type; + break; case SC_KING: - type = 7; - break; + type = 7; + break; case SC_COUNCIL: - type = 8; - break; + type = 8; + break; case SC_EXVALAR: - type = 9; - break; + type = 9; + break; case SC_VALAR: - type = 10; - break; + type = 10; + break; } - type *= 2; /* calculate offset */ + type *= 2; /* calculate offset */ - if (type > 20) - /* error */ - type = 22; + if (type > 20) + /* error */ + type = 22; - if (shortflag) - /* use short descriptions */ - ++type; + if (shortflag) + /* use short descriptions */ + ++type; - if (playerp->p_crowns > 0) - { - strcpy(Databuf, results[type]); - Databuf[0] = '*'; - return(Databuf); - } - else - return(results[type]); + if (playerp->p_crowns > 0) { + strcpy(Databuf, results[type]); + Databuf[0] = '*'; + return (Databuf); + } else + return (results[type]); } /**/ /************************************************************************ @@ -691,24 +672,22 @@ static char *results[] = /* description table */ long findname(name, playerp) -register char *name; -register struct player *playerp; + char *name; + struct player *playerp; { -long loc = 0; /* location in the file */ - - fseek(Playersfp, 0L, 0); - while (fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - { - if (strcmp(playerp->p_name, name) == 0) - { - if (playerp->p_status != S_NOTUSED || Wizard) - /* found it */ - return(loc); - } - loc += SZ_PLAYERSTRUCT; + long loc = 0; /* location in the file */ + + fseek(Playersfp, 0L, 0); + while (fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) { + if (strcmp(playerp->p_name, name) == 0) { + if (playerp->p_status != S_NOTUSED || Wizard) + /* found it */ + return (loc); + } + loc += SZ_PLAYERSTRUCT; } - return(-1); + return (-1); } /**/ /************************************************************************ @@ -738,24 +717,23 @@ long loc = 0; /* location in the file */ long allocrecord() { -long loc = 0L; /* location in file */ + long loc = 0L; /* location in file */ - fseek(Playersfp, 0L, 0); - while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) - { - if (Other.p_status == S_NOTUSED) - /* found an empty record */ - return(loc); - else - loc += SZ_PLAYERSTRUCT; + fseek(Playersfp, 0L, 0); + while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) { + if (Other.p_status == S_NOTUSED) + /* found an empty record */ + return (loc); + else + loc += SZ_PLAYERSTRUCT; } - /* make a new record */ - initplayer(&Other); - Player.p_status = S_OFF; - writerecord(&Other, loc); + /* make a new record */ + initplayer(&Other); + Player.p_status = S_OFF; + writerecord(&Other, loc); - return(loc); + return (loc); } /**/ /************************************************************************ @@ -783,13 +761,14 @@ long loc = 0L; /* location in file */ / *************************************************************************/ +void freerecord(playerp, loc) -struct player *playerp; -long loc; + struct player *playerp; + long loc; { - playerp->p_name[0] = CH_MARKDELETE; - playerp->p_status = S_NOTUSED; - writerecord(playerp, loc); + playerp->p_name[0] = CH_MARKDELETE; + playerp->p_status = S_NOTUSED; + writerecord(playerp, loc); } /**/ /************************************************************************ @@ -816,20 +795,20 @@ long loc; / *************************************************************************/ +void leavegame() { - if (Player.p_level < 1.0) - /* delete character */ - freerecord(&Player, Fileloc); - else - { - Player.p_status = S_OFF; - writerecord(&Player, Fileloc); + if (Player.p_level < 1.0) + /* delete character */ + freerecord(&Player, Fileloc); + else { + Player.p_status = S_OFF; + writerecord(&Player, Fileloc); } - cleanup(TRUE); - /*NOTREACHED*/ + cleanup(TRUE); + /* NOTREACHED */ } /**/ /************************************************************************ @@ -863,109 +842,101 @@ leavegame() / *************************************************************************/ +void death(how) -char *how; + char *how; { -FILE *fp; /* for updating various files */ -int ch; /* input */ -static char *deathmesg[] = + FILE *fp; /* for updating various files */ + int ch; /* input */ + static char *deathmesg[] = /* add more messages here, if desired */ { - "You have been wounded beyond repair. ", - "You have been disemboweled. ", - "You've been mashed, mauled, and spit upon. (You're dead.)\n", - "You died! ", - "You're a complete failure -- you've died!!\n", - "You have been dealt a fatal blow! " + "You have been wounded beyond repair. ", + "You have been disemboweled. ", + "You've been mashed, mauled, and spit upon. (You're dead.)\n", + "You died! ", + "You're a complete failure -- you've died!!\n", + "You have been dealt a fatal blow! " }; - clear(); + clear(); - if (strcmp(how, "Stupidity") != 0) - { - if (Player.p_level > 9999.0) - /* old age */ - addstr("Characters must be retired upon reaching level 10000. Sorry."); - else if (Player.p_lives > 0) - /* extra lives */ - { - addstr("You should be more cautious. You've been killed.\n"); - printw("You only have %d more chance(s).\n", --Player.p_lives); - more(3); - Player.p_energy = Player.p_maxenergy; - return; - } - else if (Player.p_specialtype == SC_VALAR) - { - addstr("You had your chances, but Valar aren't totally\n"); - addstr("immortal. You are now left to wither and die . . .\n"); - more(3); - Player.p_brains = Player.p_level / 25.0; - Player.p_energy = Player.p_maxenergy /= 5.0; - Player.p_quksilver = Player.p_sword = 0.0; - Player.p_specialtype = SC_COUNCIL; - return; - } - else if (Player.p_ring.ring_inuse && - (Player.p_ring.ring_type == R_DLREG || Player.p_ring.ring_type == R_NAZREG)) - /* good ring in use - saved from death */ - { - mvaddstr(4, 0, "Your ring saved you from death!\n"); - refresh(); - Player.p_ring.ring_type = R_NONE; - Player.p_energy = Player.p_maxenergy / 12.0 + 1.0; - if (Player.p_crowns > 0) - --Player.p_crowns; - return; - } - else if (Player.p_ring.ring_type == R_BAD - || Player.p_ring.ring_type == R_SPOILED) - /* bad ring in possession; name idiot after player */ - { - mvaddstr(4, 0, - "Your ring has taken control of you and turned you into a monster!\n"); - fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0); - fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); - strcpy(Curmonster.m_name, Player.p_name); - fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0); - fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); - fflush(Monstfp); - } + if (strcmp(how, "Stupidity") != 0) { + if (Player.p_level > 9999.0) + /* old age */ + addstr("Characters must be retired upon reaching level 10000. Sorry."); + else if (Player.p_lives > 0) { + /* extra lives */ + addstr("You should be more cautious. You've been killed.\n"); + printw("You only have %d more chance(s).\n", --Player.p_lives); + more(3); + Player.p_energy = Player.p_maxenergy; + return; + } else if (Player.p_specialtype == SC_VALAR) { + addstr("You had your chances, but Valar aren't totally\n"); + addstr("immortal. You are now left to wither and die . . .\n"); + more(3); + Player.p_brains = Player.p_level / 25.0; + Player.p_energy = Player.p_maxenergy /= 5.0; + Player.p_quksilver = Player.p_sword = 0.0; + Player.p_specialtype = SC_COUNCIL; + return; + } else if (Player.p_ring.ring_inuse && + (Player.p_ring.ring_type == R_DLREG || Player.p_ring.ring_type == R_NAZREG)) + /* good ring in use - saved from death */ + { + mvaddstr(4, 0, "Your ring saved you from death!\n"); + refresh(); + Player.p_ring.ring_type = R_NONE; + Player.p_energy = Player.p_maxenergy / 12.0 + 1.0; + if (Player.p_crowns > 0) + --Player.p_crowns; + return; + } else if (Player.p_ring.ring_type == R_BAD + || Player.p_ring.ring_type == R_SPOILED) + /* bad ring in possession; name idiot after player */ + { + mvaddstr(4, 0, + "Your ring has taken control of you and turned you into a monster!\n"); + fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0); + fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); + strcpy(Curmonster.m_name, Player.p_name); + fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0); + fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp); + fflush(Monstfp); + } } + enterscore(); /* update score board */ - enterscore(); /* update score board */ - - /* put info in last dead file */ - fp = fopen(_PATH_LASTDEAD, "w"); - fprintf(fp,"%s (%s, run by %s, level %.0f, killed by %s)", - Player.p_name, descrtype(&Player, TRUE), - Player.p_login, Player.p_level, how); - fclose(fp); - - /* let other players know */ - fp = fopen(_PATH_MESS, "w"); - fprintf(fp, "%s was killed by %s.", Player.p_name, how); - fclose(fp); + /* put info in last dead file */ + fp = fopen(_PATH_LASTDEAD, "w"); + fprintf(fp, "%s (%s, run by %s, level %.0f, killed by %s)", + Player.p_name, descrtype(&Player, TRUE), + Player.p_login, Player.p_level, how); + fclose(fp); - freerecord(&Player, Fileloc); + /* let other players know */ + fp = fopen(_PATH_MESS, "w"); + fprintf(fp, "%s was killed by %s.", Player.p_name, how); + fclose(fp); - clear(); - move(10, 0); - addstr(deathmesg[(int) ROLL(0.0, (double) sizeof(deathmesg) / sizeof(char *))]); - addstr("Care to give it another try ? "); - ch = getanswer("NY", FALSE); + freerecord(&Player, Fileloc); - if (ch == 'Y') - { - cleanup(FALSE); - execl(_PATH_GAMEPROG, "phantasia", "-s", - (Wizard ? "-S": (char *) NULL), 0); - exit(0); - /*NOTREACHED*/ + clear(); + move(10, 0); + addstr(deathmesg[(int) ROLL(0.0, (double) sizeof(deathmesg) / sizeof(char *))]); + addstr("Care to give it another try ? "); + ch = getanswer("NY", FALSE); + + if (ch == 'Y') { + cleanup(FALSE); + execl(_PATH_GAMEPROG, "phantasia", "-s", + (Wizard ? "-S" : (char *) NULL), 0); + exit(0); + /* NOTREACHED */ } - - cleanup(TRUE); - /*NOTREACHED*/ + cleanup(TRUE); + /* NOTREACHED */ } /**/ /************************************************************************ @@ -993,13 +964,14 @@ static char *deathmesg[] = / *************************************************************************/ +void writerecord(playerp, place) -register struct player *playerp; -long place; + struct player *playerp; + long place; { - fseek(Playersfp, place, 0); - fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp); - fflush(Playersfp); + fseek(Playersfp, place, 0); + fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp); + fflush(Playersfp); } /**/ /************************************************************************ @@ -1029,12 +1001,12 @@ long place; double explevel(experience) -double experience; + double experience; { - if (experience < 1.1e7) - return(floor(pow((experience / 1000.0), 0.4875))); - else - return(floor(pow((experience / 1250.0), 0.4865))); + if (experience < 1.1e7) + return (floor(pow((experience / 1000.0), 0.4875))); + else + return (floor(pow((experience / 1250.0), 0.4865))); } /**/ /************************************************************************ @@ -1061,14 +1033,15 @@ double experience; / *************************************************************************/ +void truncstring(string) -register char *string; + char *string; { -register int length; /* length of string */ + int length; /* length of string */ - length = strlen(string); - while (string[--length] == ' ') - string[length] = '\0'; + length = strlen(string); + while (string[--length] == ' ') + string[length] = '\0'; } /**/ /************************************************************************ @@ -1098,55 +1071,55 @@ register int length; /* length of string */ / *************************************************************************/ +void altercoordinates(xnew, ynew, operation) -double xnew; -double ynew; -int operation; + double xnew; + double ynew; + int operation; { - switch (operation) - { - case A_FORCED: /* move with no checks */ - break; + switch (operation) { + case A_FORCED: /* move with no checks */ + break; - case A_NEAR: /* pick random coordinates near */ - xnew = Player.p_x + ROLL(1.0, 5.0); - ynew = Player.p_y - ROLL(1.0, 5.0); - /* fall through for check */ + case A_NEAR: /* pick random coordinates near */ + xnew = Player.p_x + ROLL(1.0, 5.0); + ynew = Player.p_y - ROLL(1.0, 5.0); + /* fall through for check */ case A_SPECIFIC: /* just move player */ - if (Beyond && fabs(xnew) < D_BEYOND && fabs(ynew) < D_BEYOND) - /* - * cannot move back from point of no return - * pick the largest coordinate to remain unchanged - */ + if (Beyond && fabs(xnew) < D_BEYOND && fabs(ynew) < D_BEYOND) + /* + * cannot move back from point of no return + * pick the largest coordinate to remain unchanged + */ { - if (fabs(xnew) > fabs(ynew)) - xnew = SGN(Player.p_x) * MAX(fabs(Player.p_x), D_BEYOND); - else - ynew = SGN(Player.p_y) * MAX(fabs(Player.p_y), D_BEYOND); + if (fabs(xnew) > fabs(ynew)) + xnew = SGN(Player.p_x) * MAX(fabs(Player.p_x), D_BEYOND); + else + ynew = SGN(Player.p_y) * MAX(fabs(Player.p_y), D_BEYOND); } - break; + break; - case A_FAR: /* pick random coordinates far */ - xnew = Player.p_x + SGN(Player.p_x) * ROLL(50 * Circle, 250 * Circle); - ynew = Player.p_y + SGN(Player.p_y) * ROLL(50 * Circle, 250 * Circle); - break; + case A_FAR: /* pick random coordinates far */ + xnew = Player.p_x + SGN(Player.p_x) * ROLL(50 * Circle, 250 * Circle); + ynew = Player.p_y + SGN(Player.p_y) * ROLL(50 * Circle, 250 * Circle); + break; } - - /* now set location flags and adjust coordinates */ - Circle = CIRCLE(Player.p_x = floor(xnew), Player.p_y = floor(ynew)); - /* set up flags based upon location */ - Throne = Marsh = Beyond = FALSE; + /* now set location flags and adjust coordinates */ + Circle = CIRCLE(Player.p_x = floor(xnew), Player.p_y = floor(ynew)); + + /* set up flags based upon location */ + Throne = Marsh = Beyond = FALSE; - if (Player.p_x == 0.0 && Player.p_y == 0.0) - Throne = TRUE; - else if (Circle < 35 && Circle >= 20) - Marsh = TRUE; - else if (MAX(fabs(Player.p_x), fabs(Player.p_y)) >= D_BEYOND) - Beyond = TRUE; + if (Player.p_x == 0.0 && Player.p_y == 0.0) + Throne = TRUE; + else if (Circle < 35 && Circle >= 20) + Marsh = TRUE; + else if (MAX(fabs(Player.p_x), fabs(Player.p_y)) >= D_BEYOND) + Beyond = TRUE; - Changed = TRUE; + Changed = TRUE; } /**/ /************************************************************************ @@ -1174,12 +1147,13 @@ int operation; / *************************************************************************/ +void readrecord(playerp, loc) -register struct player *playerp; -long loc; + struct player *playerp; + long loc; { - fseek(Playersfp, loc, 0); - fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp); + fseek(Playersfp, loc, 0); + fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp); } /**/ /************************************************************************ @@ -1205,97 +1179,94 @@ long loc; / *************************************************************************/ +void adjuststats() { -double dtemp; /* for temporary calculations */ + double dtemp; /* for temporary calculations */ - if (explevel(Player.p_experience) > Player.p_level) - /* move one or more levels */ + if (explevel(Player.p_experience) > Player.p_level) + /* move one or more levels */ { - movelevel(); - if (Player.p_level > 5.0) - Timeout = TRUE; + movelevel(); + if (Player.p_level > 5.0) + Timeout = TRUE; } - - if (Player.p_specialtype == SC_VALAR) - /* valar */ - Circle = Player.p_level / 5.0; - - /* calculate effective quickness */ - dtemp = ((Player.p_gold + Player.p_gems / 2.0) - 1000.0) / Statptr->c_goldtote - - Player.p_level;; - dtemp = MAX(0.0, dtemp); /* gold slows player down */ - Player.p_speed = Player.p_quickness + Player.p_quksilver - dtemp; - - /* calculate effective strength */ - if (Player.p_poison > 0.0) - /* poison makes player weaker */ + if (Player.p_specialtype == SC_VALAR) + /* valar */ + Circle = Player.p_level / 5.0; + + /* calculate effective quickness */ + dtemp = ((Player.p_gold + Player.p_gems / 2.0) - 1000.0) / Statptr->c_goldtote + - Player.p_level;; + dtemp = MAX(0.0, dtemp);/* gold slows player down */ + Player.p_speed = Player.p_quickness + Player.p_quksilver - dtemp; + + /* calculate effective strength */ + if (Player.p_poison > 0.0) + /* poison makes player weaker */ { - dtemp = 1.0 - Player.p_poison * Statptr->c_weakness / 800.0; - dtemp = MAX(0.1, dtemp); - } - else - dtemp = 1.0; - Player.p_might = dtemp * Player.p_strength + Player.p_sword; - - /* insure that important things are within limits */ - Player.p_quksilver = MIN(99.0, Player.p_quksilver); - Player.p_mana = MIN(Player.p_mana, - Player.p_level * Statptr->c_maxmana + 1000.0); - Player.p_brains = MIN(Player.p_brains, - Player.p_level * Statptr->c_maxbrains + 200.0); - Player.p_charms = MIN(Player.p_charms, Player.p_level + 10.0); - - /* - * some implementations have problems with floating point compare - * we work around it with this stuff - */ - Player.p_gold = floor(Player.p_gold) + 0.1; - Player.p_gems = floor(Player.p_gems) + 0.1; - Player.p_mana = floor(Player.p_mana) + 0.1; - - if (Player.p_ring.ring_type != R_NONE) - /* do ring things */ + dtemp = 1.0 - Player.p_poison * Statptr->c_weakness / 800.0; + dtemp = MAX(0.1, dtemp); + } else + dtemp = 1.0; + Player.p_might = dtemp * Player.p_strength + Player.p_sword; + + /* insure that important things are within limits */ + Player.p_quksilver = MIN(99.0, Player.p_quksilver); + Player.p_mana = MIN(Player.p_mana, + Player.p_level * Statptr->c_maxmana + 1000.0); + Player.p_brains = MIN(Player.p_brains, + Player.p_level * Statptr->c_maxbrains + 200.0); + Player.p_charms = MIN(Player.p_charms, Player.p_level + 10.0); + + /* + * some implementations have problems with floating point compare + * we work around it with this stuff + */ + Player.p_gold = floor(Player.p_gold) + 0.1; + Player.p_gems = floor(Player.p_gems) + 0.1; + Player.p_mana = floor(Player.p_mana) + 0.1; + + if (Player.p_ring.ring_type != R_NONE) + /* do ring things */ { - /* rest to max */ - Player.p_energy = Player.p_maxenergy + Player.p_shield; + /* rest to max */ + Player.p_energy = Player.p_maxenergy + Player.p_shield; + + if (Player.p_ring.ring_duration <= 0) + /* clean up expired rings */ + switch (Player.p_ring.ring_type) { + case R_BAD: /* ring drives player crazy */ + Player.p_ring.ring_type = R_SPOILED; + Player.p_ring.ring_duration = (short) ROLL(10.0, 25.0); + break; - if (Player.p_ring.ring_duration <= 0) - /* clean up expired rings */ - switch (Player.p_ring.ring_type) - { - case R_BAD: /* ring drives player crazy */ - Player.p_ring.ring_type = R_SPOILED; - Player.p_ring.ring_duration = (short) ROLL(10.0, 25.0); - break; - - case R_NAZREG: /* ring disappears */ - Player.p_ring.ring_type = R_NONE; - break; - - case R_SPOILED: /* ring kills player */ - death("A cursed ring"); - break; - - case R_DLREG: /* this ring doesn't expire */ - Player.p_ring.ring_duration = 0; - break; - } - } + case R_NAZREG: /* ring disappears */ + Player.p_ring.ring_type = R_NONE; + break; - if (Player.p_age / N_AGE > Player.p_degenerated) - /* age player slightly */ + case R_SPOILED: /* ring kills player */ + death("A cursed ring"); + break; + + case R_DLREG: /* this ring doesn't expire */ + Player.p_ring.ring_duration = 0; + break; + } + } + if (Player.p_age / N_AGE > Player.p_degenerated) + /* age player slightly */ { - ++Player.p_degenerated; - if (Player.p_quickness > 23.0) - Player.p_quickness *= 0.99; - Player.p_strength *= 0.97; - Player.p_brains *= 0.95; - Player.p_magiclvl *= 0.97; - Player.p_maxenergy *= 0.95; - Player.p_quksilver *= 0.95; - Player.p_sword *= 0.93; - Player.p_shield *= 0.93; + ++Player.p_degenerated; + if (Player.p_quickness > 23.0) + Player.p_quickness *= 0.99; + Player.p_strength *= 0.97; + Player.p_brains *= 0.95; + Player.p_magiclvl *= 0.97; + Player.p_maxenergy *= 0.95; + Player.p_quksilver *= 0.95; + Player.p_sword *= 0.93; + Player.p_shield *= 0.93; } } /**/ @@ -1323,63 +1294,64 @@ double dtemp; /* for temporary calculations */ / *************************************************************************/ +void initplayer(playerp) -register struct player *playerp; + struct player *playerp; { - playerp->p_experience = - playerp->p_level = - playerp->p_strength = - playerp->p_sword = - playerp->p_might = - playerp->p_energy = - playerp->p_maxenergy = - playerp->p_shield = - playerp->p_quickness = - playerp->p_quksilver = - playerp->p_speed = - playerp->p_magiclvl = - playerp->p_mana = - playerp->p_brains = - playerp->p_poison = - playerp->p_gems = - playerp->p_sin = - playerp->p_1scratch = - playerp->p_2scratch = 0.0; - - playerp->p_gold = ROLL(50.0, 75.0) + 0.1; /* give some gold */ - - playerp->p_x = ROLL(-125.0, 251.0); - playerp->p_y = ROLL(-125.0, 251.0); /* give random x, y */ - - /* clear ring */ - playerp->p_ring.ring_type = R_NONE; - playerp->p_ring.ring_duration = 0; - playerp->p_ring.ring_inuse = FALSE; - - playerp->p_age = 0L; - - playerp->p_degenerated = 1; /* don't degenerate initially */ - - playerp->p_type = C_FIGHTER; /* default */ - playerp->p_specialtype = SC_NONE; - playerp->p_lives = - playerp->p_crowns = - playerp->p_charms = - playerp->p_amulets = - playerp->p_holywater = - playerp->p_lastused = 0; - playerp->p_status = S_NOTUSED; - playerp->p_tampered = T_OFF; - playerp->p_istat = I_OFF; - - playerp->p_palantir = - playerp->p_blessing = - playerp->p_virgin = - playerp->p_blindness = FALSE; - - playerp->p_name[0] = - playerp->p_password[0] = - playerp->p_login[0] = '\0'; + playerp->p_experience = + playerp->p_level = + playerp->p_strength = + playerp->p_sword = + playerp->p_might = + playerp->p_energy = + playerp->p_maxenergy = + playerp->p_shield = + playerp->p_quickness = + playerp->p_quksilver = + playerp->p_speed = + playerp->p_magiclvl = + playerp->p_mana = + playerp->p_brains = + playerp->p_poison = + playerp->p_gems = + playerp->p_sin = + playerp->p_1scratch = + playerp->p_2scratch = 0.0; + + playerp->p_gold = ROLL(50.0, 75.0) + 0.1; /* give some gold */ + + playerp->p_x = ROLL(-125.0, 251.0); + playerp->p_y = ROLL(-125.0, 251.0); /* give random x, y */ + + /* clear ring */ + playerp->p_ring.ring_type = R_NONE; + playerp->p_ring.ring_duration = 0; + playerp->p_ring.ring_inuse = FALSE; + + playerp->p_age = 0L; + + playerp->p_degenerated = 1; /* don't degenerate initially */ + + playerp->p_type = C_FIGHTER; /* default */ + playerp->p_specialtype = SC_NONE; + playerp->p_lives = + playerp->p_crowns = + playerp->p_charms = + playerp->p_amulets = + playerp->p_holywater = + playerp->p_lastused = 0; + playerp->p_status = S_NOTUSED; + playerp->p_tampered = T_OFF; + playerp->p_istat = I_OFF; + + playerp->p_palantir = + playerp->p_blessing = + playerp->p_virgin = + playerp->p_blindness = FALSE; + + playerp->p_name[0] = + playerp->p_password[0] = + playerp->p_login[0] = '\0'; } /**/ /************************************************************************ @@ -1405,13 +1377,14 @@ register struct player *playerp; / *************************************************************************/ +void readmessage() { - move(3, 0); - clrtoeol(); - fseek(Messagefp, 0L, 0); - if (fgets(Databuf, SZ_DATABUF, Messagefp) != NULL) - addstr(Databuf); + move(3, 0); + clrtoeol(); + fseek(Messagefp, 0L, 0); + if (fgets(Databuf, SZ_DATABUF, Messagefp) != NULL) + addstr(Databuf); } /**/ /************************************************************************ @@ -1438,20 +1411,19 @@ readmessage() / *************************************************************************/ +void error(whichfile) char *whichfile; { - int er; - er = errno; - if (Windows) - clear(); - cleanup(FALSE); + if (Windows) + clear(); + cleanup(FALSE); - printf("An unrecoverable error has occurred reading %s.\n(errno = %d)\n", whichfile, er); - printf("Please run 'setup' to determine the problem.\n"); - exit(1); - /*NOTREACHED*/ + printf("An unrecoverable error has occurred reading %s. (errno = %d)\n", whichfile, errno); + printf("Please run 'setup' to determine the problem.\n"); + exit(1); + /* NOTREACHED */ } /**/ /************************************************************************ @@ -1482,15 +1454,14 @@ error(whichfile) double distance(x1, x2, y1, y2) -double x1, x2, y1, y2; + double x1, x2, y1, y2; { -double deltax, deltay; + double deltax, deltay; - deltax = x1 - x2; - deltay = y1 - y2; - return(sqrt(deltax * deltax + deltay * deltay)); + deltax = x1 - x2; + deltay = y1 - y2; + return (sqrt(deltax * deltax + deltay * deltay)); } - /**/ /************************************************************************ / @@ -1516,14 +1487,15 @@ double deltax, deltay; / *************************************************************************/ +void ill_sig(whichsig) -int whichsig; + int whichsig; { - clear(); - if (!(whichsig == SIGINT || whichsig == SIGQUIT)) - printw("Error: caught signal # %d.\n", whichsig); - cleanup(TRUE); - /*NOTREACHED*/ + clear(); + if (!(whichsig == SIGINT || whichsig == SIGQUIT)) + printw("Error: caught signal # %d.\n", whichsig); + cleanup(TRUE); + /* NOTREACHED */ } /**/ /************************************************************************ @@ -1551,40 +1523,39 @@ int whichsig; / *************************************************************************/ -char * +char * descrstatus(playerp) -register struct player *playerp; + struct player *playerp; { - switch (playerp->p_status) - { + switch (playerp->p_status) { case S_PLAYING: - if (playerp->p_energy < 0.2 * (playerp->p_maxenergy + playerp->p_shield)) - return("Low Energy"); - else if (playerp->p_blindness) - return("Blind"); - else - return("In game"); + if (playerp->p_energy < 0.2 * (playerp->p_maxenergy + playerp->p_shield)) + return ("Low Energy"); + else if (playerp->p_blindness) + return ("Blind"); + else + return ("In game"); case S_CLOAKED: - return("Cloaked"); + return ("Cloaked"); case S_INBATTLE: - return("In Battle"); + return ("In Battle"); case S_MONSTER: - return("Encounter"); + return ("Encounter"); case S_TRADING: - return("Trading"); + return ("Trading"); case S_OFF: - return("Off"); + return ("Off"); case S_HUNGUP: - return("Hung up"); + return ("Hung up"); default: - return(""); + return (""); } } /**/ @@ -1617,11 +1588,11 @@ register struct player *playerp; double drandom() { - if (sizeof(int) != 2) - /* use only low bits */ - return((double) (random() & 0x7fff) / 32768.0); - else - return((double) random() / 32768.0); + if (sizeof(int) != 2) + /* use only low bits */ + return ((double) (random() & 0x7fff) / 32768.0); + else + return ((double) random() / 32768.0); } /**/ /************************************************************************ @@ -1652,51 +1623,52 @@ drandom() / *************************************************************************/ +void collecttaxes(gold, gems) -double gold; -double gems; + double gold; + double gems; { -FILE *fp; /* to update Goldfile */ -double dtemp; /* for temporary calculations */ -double taxes; /* tax liability */ + FILE *fp; /* to update Goldfile */ + double dtemp; /* for temporary calculations */ + double taxes; /* tax liability */ - /* add to cache */ - Player.p_gold += gold; - Player.p_gems += gems; + /* add to cache */ + Player.p_gold += gold; + Player.p_gems += gems; - /* calculate tax liability */ - taxes = N_TAXAMOUNT / 100.0 * (N_GEMVALUE * gems + gold); + /* calculate tax liability */ + taxes = N_TAXAMOUNT / 100.0 * (N_GEMVALUE * gems + gold); - if (Player.p_gold < taxes) - /* not enough gold to pay taxes, must convert some gems to gold */ + if (Player.p_gold < taxes) + /* not enough gold to pay taxes, must convert some gems to + * gold */ { - dtemp = floor(taxes / N_GEMVALUE + 1.0); /* number of gems to convert */ - - if (Player.p_gems >= dtemp) - /* player has enough to convert */ - { - Player.p_gems -= dtemp; - Player.p_gold += dtemp * N_GEMVALUE; - } - else - /* take everything; this should never happen */ - { - Player.p_gold += Player.p_gems * N_GEMVALUE; - Player.p_gems = 0.0; - taxes = Player.p_gold; - } - } + dtemp = floor(taxes / N_GEMVALUE + 1.0); /* number of gems to + * convert */ - Player.p_gold -= taxes; + if (Player.p_gems >= dtemp) + /* player has enough to convert */ + { + Player.p_gems -= dtemp; + Player.p_gold += dtemp * N_GEMVALUE; + } else + /* take everything; this should never happen */ + { + Player.p_gold += Player.p_gems * N_GEMVALUE; + Player.p_gems = 0.0; + taxes = Player.p_gold; + } + } + Player.p_gold -= taxes; - if ((fp = fopen(_PATH_GOLD, "r+")) != NULL) - /* update taxes */ + if ((fp = fopen(_PATH_GOLD, "r+")) != NULL) + /* update taxes */ { - dtemp = 0.0; - fread((char *) &dtemp, sizeof(double), 1, fp); - dtemp += floor(taxes); - fseek(fp, 0L, 0); - fwrite((char *) &dtemp, sizeof(double), 1, fp); - fclose(fp); + dtemp = 0.0; + fread((char *) &dtemp, sizeof(double), 1, fp); + dtemp += floor(taxes); + fseek(fp, 0L, 0); + fwrite((char *) &dtemp, sizeof(double), 1, fp); + fclose(fp); } } diff --git a/games/phantasia/pathnames.h b/games/phantasia/pathnames.h index 3def81b28b8..bd36dc76f4d 100644 --- a/games/phantasia/pathnames.h +++ b/games/phantasia/pathnames.h @@ -1,3 +1,4 @@ +/* $OpenBSD: pathnames.h,v 1.2 1998/11/29 19:57:00 pjanzen Exp $ */ /* $NetBSD: pathnames.h,v 1.2 1995/03/24 03:59:17 cgd Exp $ */ /*- diff --git a/games/phantasia/phantasia.6tbl b/games/phantasia/phantasia.6tbl index ba0e0e0653d..0f208fa9bdb 100644 --- a/games/phantasia/phantasia.6tbl +++ b/games/phantasia/phantasia.6tbl @@ -1,3 +1,4 @@ +.\" $OpenBSD: phantasia.6tbl,v 1.2 1998/11/29 19:57:00 pjanzen Exp $ .\" $NetBSD: phantasia.6,v 1.2 1995/03/24 03:59:23 cgd Exp $ .\" .de sh diff --git a/games/phantasia/phantdefs.h b/games/phantasia/phantdefs.h index bd0a12480df..ef571b7f7a7 100644 --- a/games/phantasia/phantdefs.h +++ b/games/phantasia/phantdefs.h @@ -1,3 +1,4 @@ +/* $OpenBSD: phantdefs.h,v 1.3 1998/11/29 19:57:01 pjanzen Exp $ */ /* $NetBSD: phantdefs.h,v 1.2 1995/03/24 03:59:28 cgd Exp $ */ /* @@ -138,5 +139,5 @@ #define CH_KILL '\030' /* kill character (ctrl-X) */ #define CH_ERASE '\010' /* erase character (ctrl-H) */ #define CH_NEWLINE '\n' /* newline */ -#define CH_RETURN '\r' /* carriage return */ +#define CH_RETURN '\r' /* carriage return */ #define CH_REDRAW '\014' /* redraw screen character (ctrl-L) */ diff --git a/games/phantasia/phantglobs.c b/games/phantasia/phantglobs.c index ff3abcd0704..d29d2faa782 100644 --- a/games/phantasia/phantglobs.c +++ b/games/phantasia/phantglobs.c @@ -1,3 +1,4 @@ +/* $OpenBSD: phantglobs.c,v 1.3 1998/11/29 19:57:01 pjanzen Exp $ */ /* $NetBSD: phantglobs.c,v 1.2 1995/03/24 03:59:33 cgd Exp $ */ /* @@ -32,7 +33,7 @@ jmp_buf Timeoenv; /* used for timing out waiting for input */ long Fileloc; /* location in file of player statistics */ -char *Login; /* pointer to login of player */ +const char *Login; /* pointer to login of player */ char *Enemyname; /* pointer name of monster/player we are battling*/ struct player Player; /* stats for player */ @@ -45,62 +46,65 @@ struct energyvoid Enrgyvoid;/* energy void buffer */ struct charstats *Statptr;/* pointer into Stattable[] */ /* lookup table for character type dependent statistics */ -struct charstats Stattable[7] = - { +struct charstats Stattable[7] = { /* MAGIC USER */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 15.0, 200.0, 18.0, 175.0, 10, - /* quickness strength mana energy brains magic lvl */ - 30, 6, 0.0, 10, 6, 2.0, 50,51,75.0, 30,16,20.0, 60,26, 6.0, 5, 5,2.75, + { + 15.0, 200.0, 18.0, 175.0, 10, + {30, 6, 0.0}, {10, 6, 2.0}, {50, 51, 75.0}, + {30, 16, 20.0}, {60, 26, 6.0}, {5, 5, 2.75} + }, /* FIGHTER */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 10.0, 110.0, 15.0, 220.0, 20, - /* quickness strength mana energy brains magic lvl */ - 30, 6, 0.0, 40,16, 3.0, 30,21,40.0, 45,26,30.0, 25,21, 3.0, 3, 4, 1.5, + { + 10.0, 110.0, 15.0, 220.0, 20, + {30, 6, 0.0}, {40, 16, 3.0}, {30, 21, 40.0}, + {45, 26, 30.0}, {25, 21, 3.0}, {3, 4, 1.5} + }, /* ELF */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 12.0, 150.0, 17.0, 190.0, 13, - /* quickness strength mana energy brains magic lvl */ - 32, 7, 0.0, 35,11, 2.5, 45,46,65.0, 30,21,25.0, 40,26, 4.0, 4, 4, 2.0, + { + 12.0, 150.0, 17.0, 190.0, 13, + {32, 7, 0.0}, {35, 11, 2.5}, {45, 46, 65.0}, + {30, 21, 25.0}, {40, 26, 4.0}, {4, 4, 2.0} + }, /* DWARF */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 7.0, 80.0, 13.0, 255.0, 25, - /* quickness strength mana energy brains magic lvl */ - 25, 6, 0.0, 50,21, 5.0, 25,21,30.0, 60,41,35.0, 20,21, 2.5, 2, 4, 1.0, + { 7.0, 80.0, 13.0, 255.0, 25, + {25, 6, 0.0}, {50, 21, 5.0}, {25, 21, 30.0}, + {60, 41, 35.0}, {20, 21, 2.5}, {2, 4, 1.0} + }, /* HALFLING */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 11.0, 80.0, 10.0, 125.0, 40, - /* quickness strength mana energy brains magic lvl */ - 34, 0, 0.0, 20, 6, 2.0, 25,21,30.0, 55,36,30.0, 40,36, 4.5, 1, 4, 1.0, + { + 11.0, 80.0, 10.0, 125.0, 40, + {34, 0, 0.0}, {20, 6, 2.0}, {25, 21, 30.0}, + {55, 36, 30.0}, {40, 36, 4.5}, {1, 4, 1.0} + }, /* EXPERIMENTO */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 9.0, 90.0, 16.0, 160.0, 20, - /* quickness strength mana energy brains magic lvl */ - 27, 0, 0.0, 25, 0, 0.0, 100,0, 0.0, 35, 0, 0.0, 25, 0, 0.0, 2, 0, 0.0, + { 9.0, 90.0, 16.0, 160.0, 20, + {27, 0, 0.0}, {25, 0, 0.0}, {100, 0, 0.0}, + {35, 0, 0.0}, {25, 0, 0.0}, {2, 0, 0.0} + }, /* SUPER */ - /* max brains, max mana, weakness, gold tote, ring duration */ - 15.0, 200.0, 10.0, 225.0, 40, - /* quickness strength mana energy brains magic lvl */ - 38, 0, 0.0, 65, 0, 5.0, 100,0,75.0, 80, 0,35.0, 85, 0, 6.0, 9, 0,2.75 - }; + { + 15.0, 200.0, 10.0, 225.0, 40, + {38, 0, 0.0}, {65, 0, 5.0}, {100, 0, 75.0}, + {80, 0, 35.0}, {85, 0, 6.0}, {9, 0, 2.75} + } +}; /* menu of items for purchase */ -struct menuitem Menu[] = - { - "Mana", 1, - "Shield", 5, - "Book", 200, - "Sword", 500, - "Charm", 1000, - "Quicksilver", 2500, - "Blessing", 1000, - }; +struct menuitem Menu[] = { + {"Mana", 1}, + {"Shield", 5}, + {"Book", 200}, + {"Sword", 500}, + {"Charm", 1000}, + {"Quicksilver", 2500}, + {"Blessing", 1000}, +}; FILE *Playersfp; /* pointer to open player file */ FILE *Monstfp; /* pointer to open monster file */ diff --git a/games/phantasia/phantglobs.h b/games/phantasia/phantglobs.h index 5e024e476f6..980eb7d8a8f 100644 --- a/games/phantasia/phantglobs.h +++ b/games/phantasia/phantglobs.h @@ -1,58 +1,58 @@ -/* $OpenBSD: phantglobs.h,v 1.2 1998/07/10 09:46:50 downsj Exp $ */ +/* $OpenBSD: phantglobs.h,v 1.3 1998/11/29 19:57:01 pjanzen Exp $ */ /* $NetBSD: phantglobs.h,v 1.3 1995/04/24 12:24:39 cgd Exp $ */ /* * phantglobs.h - global declarations for Phantasia */ -extern double Circle; /* which circle player is in */ -extern double Shield; /* force field thrown up in monster battle */ - -extern bool Beyond; /* set if player is beyond point of no return */ -extern bool Marsh; /* set if player is in dead marshes */ -extern bool Throne; /* set if player is on throne */ -extern bool Changed; /* set if important player stats have changed */ -extern bool Wizard; /* set if player is the 'wizard' of the game */ -extern bool Timeout; /* set if short timeout waiting for input */ -extern bool Windows; /* set if we are set up for curses stuff */ -extern bool Luckout; /* set if we have tried to luck out in fight */ +extern double Circle; /* which circle player is in */ +extern double Shield; /* force field thrown up in monster battle */ + +extern bool Beyond; /* set if player is beyond point of no return */ +extern bool Marsh; /* set if player is in dead marshes */ +extern bool Throne; /* set if player is on throne */ +extern bool Changed; /* set if important player stats have changed */ +extern bool Wizard; /* set if player is the 'wizard' of the game */ +extern bool Timeout; /* set if short timeout waiting for input */ +extern bool Windows; /* set if we are set up for curses stuff */ +extern bool Luckout; /* set if we have tried to luck out in fight */ extern bool Foestrikes; /* set if foe gets a chance to hit in battleplayer()*/ -extern bool Echo; /* set if echo input to terminal */ +extern bool Echo; /* set if echo input to terminal */ -extern int Users; /* number of users currently playing */ -extern int Whichmonster; /* which monster we are fighting */ -extern int Lines; /* line on screen counter for fight routines */ +extern int Users; /* number of users currently playing */ +extern int Whichmonster; /* which monster we are fighting */ +extern int Lines; /* line on screen counter for fight routines */ extern char Ch_Erase; /* backspace key */ extern char Ch_Kill; /* linekill key */ -extern jmp_buf Fightenv; /* used to jump into fight routine */ -extern jmp_buf Timeoenv; /* used for timing out waiting for input */ +extern jmp_buf Fightenv; /* used to jump into fight routine */ +extern jmp_buf Timeoenv; /* used for timing out waiting for input */ -extern long Fileloc; /* location in file of player statistics */ +extern long Fileloc; /* location in file of player statistics */ -extern char *Login; /* pointer to login of current player */ +extern const char *Login; /* pointer to login of current player */ extern char *Enemyname; /* pointer name of monster/player we are battling*/ -extern struct player Player; /* stats for player */ -extern struct player Other; /* stats for another player */ +extern struct player Player; /* stats for player */ +extern struct player Other; /* stats for another player */ -extern struct monster Curmonster;/* stats for current monster */ +extern struct monster Curmonster;/* stats for current monster */ -extern struct energyvoid Enrgyvoid;/* energy void buffer */ +extern struct energyvoid Enrgyvoid;/* energy void buffer */ extern struct charstats Stattable[];/* used for rolling and changing player stats*/ -extern struct charstats *Statptr;/* pointer into Stattable[] */ +extern struct charstats *Statptr;/* pointer into Stattable[] */ -extern struct menuitem Menu[]; /* menu of items for purchase */ +extern struct menuitem Menu[]; /* menu of items for purchase */ -extern FILE *Playersfp; /* pointer to open player file */ -extern FILE *Monstfp; /* pointer to open monster file */ -extern FILE *Messagefp; /* pointer to open message file */ -extern FILE *Energyvoidfp; /* pointer to open energy void file */ +extern FILE *Playersfp; /* pointer to open player file */ +extern FILE *Monstfp; /* pointer to open monster file */ +extern FILE *Messagefp; /* pointer to open message file */ +extern FILE *Energyvoidfp; /* pointer to open energy void file */ -extern char Databuf[]; /* a place to read data into */ +extern char Databuf[]; /* a place to read data into */ /* some canned strings for messages */ extern char Illcmd[]; @@ -62,31 +62,74 @@ extern char Nomana[]; extern char Somebetter[]; extern char Nobetter[]; -/* library functions and system calls */ -/* extern long time(); */ -extern char *getlogin(); -extern char *getpass(); -extern char *strchr(); -extern char *strcat(); -extern char *strcpy(); -extern char *strncpy(); -extern char *getenv(); -struct passwd *getpwuid(); -extern char *fgets(); - /* functions which we need to know about */ -extern int interrupt(); -extern int ill_sig(); -extern void catchalarm(); -extern long recallplayer(); -extern long findname(); -extern long allocrecord(); -extern long rollnewplayer(); -extern long allocvoid(); -extern double drandom(); -extern double distance(); -extern double infloat(); -extern double explevel(); -extern char *descrlocation(); -extern char *descrtype(); -extern char *descrstatus(); + +char *descrlocation __P((struct player *, bool)); +char *descrstatus __P((struct player *)); +char *descrtype __P((struct player *, bool)); +void activelist __P((void)); +void adjuststats __P((void)); +long allocrecord __P((void)); +long allocvoid __P((void)); +void allstatslist __P((void)); +void altercoordinates __P((double, double, int)); +void awardtreasure __P((void)); +void battleplayer __P((long)); +void callmonster __P((int)); +void cancelmonster __P((void)); +void catchalarm __P((int)); +void changestats __P((bool)); +void checkbattle __P((void)); +void checktampered __P((void)); +void cleanup __P((int)); +void collecttaxes __P((double, double)); +void cursedtreasure __P((void)); +void death __P((char *)); +void displaystats __P((void)); +double distance __P((double, double, double, double)); +void dotampered __P((void)); +double drandom __P((void)); +void encounter __P((int)); +void enterscore __P((void)); +void error __P((char *)); +double explevel __P((double)); +long findname __P((char *, struct player *)); +void freerecord __P((struct player *, long)); +void genchar __P((int)); +int getanswer __P((char *, bool)); +void getstring __P((char *, int)); +void hitmonster __P((double)); +void ill_sig __P((int)); +double infloat __P((void)); +void initialstate __P((void)); +void initplayer __P((struct player *)); +int inputoption __P((void)); +void interrupt __P((void)); +void leavegame __P((void)); +void monsthits __P((void)); +void monstlist __P((void)); +void more __P((int)); +void movelevel __P((void)); +void myturn __P((void)); +void neatstuff __P((void)); +int pickmonster __P((void)); +void playerhits __P((void)); +void playinit __P((void)); +void procmain __P((void)); +void purgeoldplayers __P((void)); +void readmessage __P((void)); +void readrecord __P((struct player *, long)); +long recallplayer __P((void)); +long recallplayer __P((void)); +long rollnewplayer __P((void)); +void scorelist __P((void)); +void scramblestats __P((void)); +void tampered __P((int, double, double)); +void throneroom __P((void)); +void throwspell __P((void)); +void titlelist __P((void)); +void tradingpost __P((void)); +void truncstring __P((char *)); +void userlist __P((bool)); +void writerecord __P((struct player *, long)); +void writevoid __P((struct energyvoid *, long)); diff --git a/games/phantasia/phantstruct.h b/games/phantasia/phantstruct.h index c7ada2260d6..599d9faf8aa 100644 --- a/games/phantasia/phantstruct.h +++ b/games/phantasia/phantstruct.h @@ -1,3 +1,4 @@ +/* $OpenBSD: phantstruct.h,v 1.2 1998/11/29 19:57:02 pjanzen Exp $ */ /* $NetBSD: phantstruct.h,v 1.2 1995/03/24 04:00:11 cgd Exp $ */ /* diff --git a/games/phantasia/setup.c b/games/phantasia/setup.c index c315de7fa03..e97596c6645 100644 --- a/games/phantasia/setup.c +++ b/games/phantasia/setup.c @@ -1,3 +1,4 @@ +/* $OpenBSD: setup.c,v 1.4 1998/11/29 19:57:02 pjanzen Exp $ */ /* $NetBSD: setup.c,v 1.4 1995/04/24 12:24:41 cgd Exp $ */ /* @@ -5,8 +6,12 @@ */ #include <sys/param.h> #include <sys/stat.h> -#include <stdlib.h> +#include <sys/types.h> #include "include.h" +#include <fcntl.h> + +void Error __P((char *, char *)); + /**/ /************************************************************************ / @@ -20,8 +25,8 @@ / / RETURN VALUE: none / -/ MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(), -/ fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(), +/ MODULES CALLED: time(), exit(), stat(), Error(), open(), close(), fopen(), +/ fgets(), floor(), srandom(), umask(), strcpy(), / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf() / / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid @@ -99,12 +104,19 @@ main(argc, argv) continue; } + if (!strcmp(*filename, _PATH_SCORE)) + /* do not reset score file if it already exists */ + { + ++filename; + continue; + } + if (unlink(path) < 0) Error("Cannot unlink %s.\n", path); /*NOTREACHED*/ } - if ((fd = creat(path, 0660)) < 0) + if ((fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0660)) < 0) Error("Cannot create %s.\n", path); /*NOTREACHED*/ @@ -228,14 +240,15 @@ main(argc, argv) / *************************************************************************/ +void Error(str, file) -char *str, *file; + char *str, *file; { - fprintf(stderr, "Error: "); - fprintf(stderr, str, file); - perror(file); - exit(1); - /*NOTREACHED*/ + fprintf(stderr, "Error: "); + fprintf(stderr, str, file); + perror(file); + exit(1); + /* NOTREACHED */ } /**/ /************************************************************************ |