annotate warning.c @ 3:5a977ccbc7a9 default tip

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