comparison warning.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
comparison
equal deleted inserted replaced
2:fba0b6e6cdc7 3:5a977ccbc7a9
1 /* $Id: warning.c,v 1.1.1.1 1997/12/06 05:41:31 darius Exp $ */
2
3 /*
4 * warning.c
5 */
6 #include "copyright.h"
7
8 #include <stdio.h>
9 #include <math.h>
10 #include <signal.h>
11 #include "Wlib.h"
12 #include "defs.h"
13 #include "struct.h"
14 #include "data.h"
15 #ifdef hupx
16 #include <time.h>
17 #else /* hpux */
18 #include <sys/time.h>
19 #endif /* hpux */
20 #ifdef RS6K
21 struct tm {
22 int tm_sec; /* seconds (0 - 59) */
23 int tm_min; /* minutes (0 - 59) */
24 int tm_hour; /* hours (0 - 23) */
25 int tm_mday; /* day of month (1 - 31) */
26 int tm_mon; /* month of year (0 - 11) */
27 int tm_year; /* year - 1900 */
28 int tm_wday; /* day of week (Sunday = 0) */
29 int tm_yday; /* day of year (0 - 365) */
30 int tm_isdst; /* flag: daylight savings time in effect */
31 long tm_gmtoff; /* offset from GMT in seconds */
32 char *tm_zone; /* abbreviation of timezone name */
33
34 };
35
36 #endif
37
38 #define W_XOFF 5
39 #ifndef AMIGA
40 #define W_YOFF 5
41 #else
42 #define W_YOFF 1
43 #endif
44
45 char *
46 timeString(t)
47 time_t t;
48 /* returns a string of the form hour:minute:second */
49 {
50 static char *s = NULL;
51 struct tm *tm;
52
53 if (!s)
54 s = (char *) malloc(9);
55 if (t > 24 * 60 * 60) {
56 tm = localtime(&t);
57 sprintf(s, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
58 } else
59 sprintf(s, "%02d:%02d:%02d", (int) (t / (60 * 60)), (int) ((t % (60 * 60)) / 60),
60 (int) (t % 60));
61 return s;
62 }
63
64 /*
65 ** The warning in text will be printed in the warning window.
66 ** The message will last WARNTIME/10 seconds unless another message
67 ** comes through and overwrites it.
68 */
69
70 void
71 warning(text)
72 char *text;
73 {
74 /* long curtime; */
75 /* char timebuf[10]; */
76 /* struct tm *tm; */
77 char newtext[91]; /* infinite appending fix - jn */
78 int len;
79
80 char *d;
81 int dmg;
82 float phasRatio, avgDmg;
83 int thisHit = 0;
84
85 newtext[0] = '\0';
86 warntimer = udcounter + WARNTIME; /* set the line to be cleared */
87
88 if (warncount > 0) {
89 /* XFIX */
90 W_ClearArea(warnw, W_XOFF, W_YOFF, W_Textwidth * warncount, W_Textheight);
91 }
92 warncount = strlen(text);
93 W_WriteText(warnw, W_XOFF, W_YOFF, textColor, text, warncount, W_RegularFont);
94 if (strncmp(text, "Phaser", 6) == 0) {
95 if (strncmp(text + 7, "missed", 6) == 0) {
96 phasFired++;
97 if (!logPhaserMissed)
98 return;
99 thisHit = 0;
100 } else if (strncmp(text + 7, "burst", 5) != 0 &&
101 strncmp(text + 7, "shot", 4) != 0)
102 return;
103 else { /* a hit! */
104 phasFired++;
105 phasHits++;
106 thisHit = 1;
107 }
108
109 if (phaserStats) {
110 if (thisHit) {
111 d = &text[strlen(text)];
112
113 while (!isdigit(*d) && d > text) /* find the last number
114 in the string, should
115 be damage */
116 d--;
117 while (d > text && isdigit(*d))
118 d--;
119
120 if (d > text) {
121 dmg = atoi(d);
122 totalDmg += dmg;
123 avgDmg = (float) totalDmg / (float) phasHits;
124 phasRatio = (100 * phasHits) / (float) phasFired;
125 sprintf(newtext, "Av:%5.2f, Hit:%5.2f%%: ", avgDmg, phasRatio);
126 }
127 } else { /* a miss */
128 sprintf(newtext, "Hit: %d, Miss: %d, Dmg: %d: ", phasHits, phasFired - phasHits, totalDmg);
129 }
130 } else { /* not keeping phaser stats right now */
131 phasFired--;
132 if (thisHit)
133 phasHits--;
134 newtext[0] = '\0';
135 }
136 strncat(newtext, text, 80);
137 len = strlen(newtext);
138 newtext[len++] = ' ';
139 strcpy(newtext + len, timeString(time(NULL)));
140 warncount = warncount + 9;
141
142 dmessage(newtext, 0, 254, 0);
143
144 } else if (strncmp(text, "Missile away", 12) == 0) {
145 /* missile total kludge. No value until one is shot :( */
146 me->p_totmissiles = atoi(text + 13);
147 } else if (strcmp(text, "Prepping for warp jump") == 0) {
148 /* keep track of when in warp prep */
149 me->p_flags |= PFWARPPREP;
150 } else if (strcmp(text, "Warp drive aborted") == 0) {
151 me->p_flags &= ~PFWARPPREP;
152 }
153 }