-/* $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
clrtobot();
}
-int
-pickmonster()
+static int
+pickmonster(void)
{
if (Player.p_specialtype == SC_VALAR)
/* even chance of any monster */
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 */
}
-void
-monsthits()
+static void
+monsthits(void)
{
double inflict; /* damage inflicted */
int ch; /* input */
/* 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;
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 */
}
}
-void
-cancelmonster()
+static void
+cancelmonster(void)
{
Curmonster.m_energy = 0.0;
Curmonster.m_experience = 0.0;
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;
}
}
-void
-throwspell()
+static void
+throwspell(void)
{
double inflict; /* damage inflicted */
double dtemp; /* for dtemporary calculations */
}
}
-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 */
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;
/* 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);
}
Curmonster.m_melee = Curmonster.m_skirmish = 0.0;
}
-void
-awardtreasure()
+static void
+awardtreasure(void)
{
int whichtreasure; /* calculated treasure to grant */
int temp; /* temporary */
ch = getanswer("NY", FALSE);
addstr("\n\n");
- if (ch == 'Y')
+ if (ch == 'Y') {
if (drandom() < treasuretype / 35.0 + 0.04)
/* cursed */
{
cursedtreasure();
} else
collecttaxes(gold, gems);
+ }
return;
} else
/* fall through to treasure type 9 if
* no treasure from above */
+ /* FALLTHROUGH */
case 9: /* treasure type 9 */
switch (whichtreasure) {
case 1:
++Player.p_crowns;
break;
}
- /* fall through otherwise */
+ /* FALLTHROUGH */
case 2:
addstr("You've been blessed!\n");
Player.p_blessing = TRUE;
}
}
-void
-cursedtreasure()
+static void
+cursedtreasure(void)
{
if (Player.p_charms > 0) {
addstr("But your charm saved you!\n");
}
}
-void
-scramblestats()
+static void
+scramblestats(void)
{
double dbuf[6]; /* to put statistic in */
double dtemp1, dtemp2; /* for swapping values */