]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - phantasia/fight.c
mention hex numbers
[bsdgames-darwin.git] / phantasia / fight.c
index cfcea5451cf72c577d1824c556ed23a6f4fdc7a0..0a1ab064dc5f03af6967f298469bdfe3563ed018 100644 (file)
@@ -1,27 +1,44 @@
-/*     $NetBSD: fight.c,v 1.3 1997/10/13 02:18:12 lukem Exp $  */
+/*     $NetBSD: fight.c,v 1.14 2019/02/03 03:19:25 mrg Exp $   */
 
 /*
  * fight.c   Phantasia monster fighting routines
  */
 
-#include "include.h"
+#include <math.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+#include "phantdefs.h"
+#include "phantstruct.h"
+#include "phantglobs.h"
+
+#undef bool
+#include <curses.h>
+
+static void awardtreasure(void);
+static void callmonster(int);
+static void cancelmonster(void);
+static void cursedtreasure(void);
+static void hitmonster(double);
+static void monsthits(void);
+static int pickmonster(void);
+static void playerhits(void);
+static void scramblestats(void);
+static void throwspell(void);
 
 void
-encounter(particular)
-       int     particular;
+encounter(int particular)
 {
-       bool    firsthit = Player.p_blessing;   /* set if player gets the
-                                                * first hit */
-       int     flockcnt = 1;   /* how many time flocked */
+       volatile bool    firsthit = Player.p_blessing;  /* set if player gets
+                                                        * the first hit */
+       volatile int     flockcnt = 1;  /* how many time flocked */
 
        /* 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();
 #endif
@@ -155,8 +172,8 @@ encounter(particular)
        clrtobot();
 }
 
-int
-pickmonster()
+static int
+pickmonster(void)
 {
        if (Player.p_specialtype == SC_VALAR)
                /* even chance of any monster */
@@ -195,21 +212,22 @@ pickmonster()
                                                return ((int) ROLL(14.0, 25.0));
 }
 
-void
-playerhits()
+static void
+playerhits(void)
 {
        double  inflict;        /* damage inflicted */
        int     ch;             /* input */
 
        mvaddstr(7, 0, "1:Melee  2:Skirmish  3:Evade  4:Spell  5:Nick  ");
 
-       if (!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 */
@@ -337,8 +355,8 @@ playerhits()
 
 }
 
-void
-monsthits()
+static void
+monsthits(void)
 {
        double  inflict;        /* damage inflicted */
        int     ch;             /* input */
@@ -395,7 +413,7 @@ monsthits()
                        /* 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!",
+                       mvprintw(Lines++, 0, "%s sapped %.0f of your strength!",
                            Enemyname, inflict);
                        Player.p_strength -= inflict;
                        Player.p_might -= inflict;
@@ -548,7 +566,7 @@ monsthits()
                        mvprintw(Lines++, 0,
                            "%s flew away, and left you to contend with one of its friends.",
                            Enemyname);
-                       Whichmonster = 55 + (drandom() > 0.5) ? 22 : 0;
+                       Whichmonster = 55 + ((drandom() > 0.5) ? 22 : 0);
                        longjmp(Fightenv, 0);
                        /* NOTREACHED */
 
@@ -587,8 +605,8 @@ SPECIALHIT:
        }
 }
 
-void
-cancelmonster()
+static void
+cancelmonster(void)
 {
        Curmonster.m_energy = 0.0;
        Curmonster.m_experience = 0.0;
@@ -596,9 +614,8 @@ cancelmonster()
        Curmonster.m_flock = 0.0;
 }
 
-void
-hitmonster(inflict)
-       double  inflict;
+static void
+hitmonster(double inflict)
 {
        mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict);
        Curmonster.m_energy -= inflict;
@@ -624,8 +641,8 @@ hitmonster(inflict)
        }
 }
 
-void
-throwspell()
+static void
+throwspell(void)
 {
        double  inflict;        /* damage inflicted */
        double  dtemp;          /* for dtemporary calculations */
@@ -834,16 +851,15 @@ throwspell()
                }
 }
 
-void
-callmonster(which)
-       int     which;
+static void
+callmonster(int which)
 {
        struct monster Othermonster;    /* to find a name for mimics */
 
        which = MIN(which, 99); /* make sure within range */
 
        /* fill structure */
-       fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0);
+       fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
        fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
 
        /* handle some special monsters */
@@ -868,7 +884,7 @@ callmonster(which)
                        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;
+                           + ((Player.p_specialtype == SC_EXVALAR) ? Player.p_speed : 0.0);
                        Curmonster.m_flock = 0.0;
                        Curmonster.m_treasuretype = 0;
                        Curmonster.m_experience = 0.0;
@@ -878,7 +894,7 @@ callmonster(which)
                        /* pick another name */
                {
                        which = (int) ROLL(0.0, 100.0);
-                       fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, 0);
+                       fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
                        fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
                        strcpy(Curmonster.m_name, Othermonster.m_name);
                }
@@ -912,8 +928,8 @@ callmonster(which)
        Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
 }
 
-void
-awardtreasure()
+static void
+awardtreasure(void)
 {
        int     whichtreasure;  /* calculated treasure to grant */
        int     temp;           /* temporary */
@@ -951,7 +967,7 @@ awardtreasure()
                ch = getanswer("NY", FALSE);
                addstr("\n\n");
 
-               if (ch == 'Y')
+               if (ch == 'Y') {
                        if (drandom() < treasuretype / 35.0 + 0.04)
                                /* cursed */
                        {
@@ -959,6 +975,7 @@ awardtreasure()
                                cursedtreasure();
                        } else
                                collecttaxes(gold, gems);
+               }
 
                return;
        } else
@@ -1299,6 +1316,7 @@ awardtreasure()
                                        /* fall through to treasure type 9 if
                                         * no treasure from above */
 
+                                       /* FALLTHROUGH */
                                case 9: /* treasure type 9 */
                                        switch (whichtreasure) {
                                        case 1:
@@ -1309,8 +1327,8 @@ awardtreasure()
                                                        ++Player.p_crowns;
                                                        break;
                                                }
-                                               /* fall through otherwise */
 
+                                               /* FALLTHROUGH */
                                        case 2:
                                                addstr("You've been blessed!\n");
                                                Player.p_blessing = TRUE;
@@ -1335,8 +1353,8 @@ awardtreasure()
        }
 }
 
-void
-cursedtreasure()
+static void
+cursedtreasure(void)
 {
        if (Player.p_charms > 0) {
                addstr("But your charm saved you!\n");
@@ -1352,8 +1370,8 @@ cursedtreasure()
                }
 }
 
-void
-scramblestats()
+static void
+scramblestats(void)
 {
        double  dbuf[6];        /* to put statistic in */
        double  dtemp1, dtemp2; /* for swapping values */