diff warning.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/warning.c	Sat Dec 06 05:41:29 1997 +0000
@@ -0,0 +1,153 @@
+/* $Id: warning.c,v 1.1.1.1 1997/12/06 05:41:31 darius Exp $ */
+
+/*
+ * warning.c
+ */
+#include "copyright.h"
+
+#include <stdio.h>
+#include <math.h>
+#include <signal.h>
+#include "Wlib.h"
+#include "defs.h"
+#include "struct.h"
+#include "data.h"
+#ifdef hupx
+#include <time.h>
+#else				/* hpux */
+#include <sys/time.h>
+#endif				/* hpux */
+#ifdef RS6K
+struct tm {
+    int     tm_sec;		/* seconds (0 - 59) */
+    int     tm_min;		/* minutes (0 - 59) */
+    int     tm_hour;		/* hours (0 - 23) */
+    int     tm_mday;		/* day of month (1 - 31) */
+    int     tm_mon;		/* month of year (0 - 11) */
+    int     tm_year;		/* year - 1900 */
+    int     tm_wday;		/* day of week (Sunday = 0) */
+    int     tm_yday;		/* day of year (0 - 365) */
+    int     tm_isdst;		/* flag: daylight savings time in effect */
+    long    tm_gmtoff;		/* offset from GMT in seconds */
+    char   *tm_zone;		/* abbreviation of timezone name */
+
+};
+
+#endif
+
+#define W_XOFF 5
+#ifndef AMIGA
+#define W_YOFF 5
+#else
+#define W_YOFF 1
+#endif
+
+char   *
+timeString(t)
+    time_t  t;
+/* returns a string of the form hour:minute:second */
+{
+    static char *s = NULL;
+    struct tm *tm;
+
+    if (!s)
+	s = (char *) malloc(9);
+    if (t > 24 * 60 * 60) {
+	tm = localtime(&t);
+	sprintf(s, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
+    } else
+	sprintf(s, "%02d:%02d:%02d", (int) (t / (60 * 60)), (int) ((t % (60 * 60)) / 60),
+		(int) (t % 60));
+    return s;
+}
+
+/*
+   ** The warning in text will be printed in the warning window.
+   ** The message will last WARNTIME/10 seconds unless another message
+   ** comes through and overwrites it.
+ */
+
+void
+warning(text)
+    char   *text;
+{
+    /* long curtime; */
+    /* char timebuf[10]; */
+    /* struct tm *tm; */
+    char    newtext[91];	/* infinite appending fix - jn */
+    int     len;
+
+    char   *d;
+    int     dmg;
+    float   phasRatio, avgDmg;
+    int     thisHit = 0;
+
+    newtext[0] = '\0';
+    warntimer = udcounter + WARNTIME;	/* set the line to be cleared */
+
+    if (warncount > 0) {
+	/* XFIX */
+	W_ClearArea(warnw, W_XOFF, W_YOFF, W_Textwidth * warncount, W_Textheight);
+    }
+    warncount = strlen(text);
+    W_WriteText(warnw, W_XOFF, W_YOFF, textColor, text, warncount, W_RegularFont);
+    if (strncmp(text, "Phaser", 6) == 0) {
+	if (strncmp(text + 7, "missed", 6) == 0) {
+	    phasFired++;
+	    if (!logPhaserMissed)
+		return;
+	    thisHit = 0;
+	} else if (strncmp(text + 7, "burst", 5) != 0 &&
+		   strncmp(text + 7, "shot", 4) != 0)
+	    return;
+	else {			/* a hit! */
+	    phasFired++;
+	    phasHits++;
+	    thisHit = 1;
+	}
+
+	if (phaserStats) {
+	    if (thisHit) {
+		d = &text[strlen(text)];
+
+		while (!isdigit(*d) && d > text)	/* find the last number
+							   in the string, should
+							   be damage */
+		    d--;
+		while (d > text && isdigit(*d))
+		    d--;
+
+		if (d > text) {
+		    dmg = atoi(d);
+		    totalDmg += dmg;
+		    avgDmg = (float) totalDmg / (float) phasHits;
+		    phasRatio = (100 * phasHits) / (float) phasFired;
+		    sprintf(newtext, "Av:%5.2f, Hit:%5.2f%%: ", avgDmg, phasRatio);
+		}
+	    } else {		/* a miss */
+		sprintf(newtext, "Hit: %d, Miss: %d, Dmg: %d: ", phasHits, phasFired - phasHits, totalDmg);
+	    }
+	} else {		/* not keeping phaser stats right now */
+	    phasFired--;
+	    if (thisHit)
+		phasHits--;
+	    newtext[0] = '\0';
+	}
+	strncat(newtext, text, 80);
+	len = strlen(newtext);
+	newtext[len++] = ' ';
+	strcpy(newtext + len, timeString(time(NULL)));
+	warncount = warncount + 9;
+
+	dmessage(newtext, 0, 254, 0);
+
+    } else if (strncmp(text, "Missile away", 12) == 0) {
+	/* missile total kludge.  No value until one is shot :( */
+	me->p_totmissiles = atoi(text + 13);
+    } else if (strcmp(text, "Prepping for warp jump") == 0) {
+	/* keep track of when in warp prep */
+	me->p_flags |= PFWARPPREP;
+    } else if (strcmp(text, "Warp drive aborted") == 0) {
+	me->p_flags &= ~PFWARPPREP;
+    }
+}