annotate stats.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: stats.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 * stats.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 "Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include "defs.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11 #include "struct.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include "data.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #include "proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 #define BX_OFF() ((textWidth + 1) * W_Textwidth + S_IBORDER)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 #define BY_OFF(line) ((line) * (W_Textheight + S_IBORDER) + S_IBORDER)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 #define TX_OFF(len) ((textWidth - len) * W_Textwidth + S_IBORDER)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 #define TY_OFF(line) BY_OFF(line)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 #if 0
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 #define STAT_WIDTH 160
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 #else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 #define STAT_WIDTH st_width
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 #define STAT_HEIGHT BY_OFF(NUM_SLIDERS)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 #define STAT_BORDER 2
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 #define S_IBORDER 5
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 #define STAT_X 422
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 #define STAT_Y 13
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 #define SL_WID \
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 (STAT_WIDTH - 2 * S_IBORDER - (textWidth + 1) * W_Textwidth)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 #define SL_HEI (W_Textheight)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 #define NUM_ELS(a) (sizeof (a) / sizeof (*(a)))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 #define NUM_SLIDERS NUM_ELS(sliders)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 typedef struct slider {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 char *label;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42 int min, max;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 int red;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 int yellow;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 int label_length;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46 int diff;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 int *var;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 int lastVal;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 } SLIDER;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 typedef struct record {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 int *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 int last_value;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 } RECORD;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 static SLIDER sliders[] = {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 {"Shield Cond", 0, 100, 20, 100},
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 {"Hull Cond", 0, 100, 0, 0},
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 {"Fuel Cond", 0, 10000, 2000, 10000},
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 {"Weapon Temp", 0, 1200, 0, 800},
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 {"Engine Temp", 0, 1200, 0, 800},
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62 };
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 static int textWidth = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 static int initialized = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 /* Prototypes */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68 static void box
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 P((int filled, int x, int y, int wid, int hei,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 W_Color color));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 static void initStats P((void));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 static int st_width = -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 static void initStats()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 int i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 if (initialized)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 initialized = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 sliders[0].var = &(me->p_shield);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 sliders[1].var = &(me->p_damage);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 sliders[2].var = &(me->p_fuel);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 sliders[3].var = &(me->p_wtemp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 sliders[4].var = &(me->p_etemp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 for (i = 0; i < NUM_SLIDERS; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88 sliders[i].label_length = strlen(sliders[i].label);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 textWidth = MAX(textWidth, sliders[i].label_length);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 sliders[i].diff = sliders[i].max - sliders[i].min;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 sliders[i].lastVal = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 st_width = W_WindowWidth(statwin);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 redrawStats()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99 int i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 W_ClearWindow(statwin);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 initStats();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 for (i = 0; i < NUM_SLIDERS; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104 sliders[i].lastVal = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106 for (i = 0; i < NUM_SLIDERS; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 W_WriteText(statwin, TX_OFF(sliders[i].label_length), TY_OFF(i),
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 textColor, sliders[i].label, sliders[i].label_length,
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109 W_RegularFont);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110 box(0, BX_OFF() - 1, BY_OFF(i) - 1, SL_WID + 2, SL_HEI + 2, borderColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111 sliders[i].lastVal = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 updateStats()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118 int i, value, new_x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119 int r, y, t;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 SLIDER *s;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 initStats();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
123 for (i = 0; i < NUM_SLIDERS; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
124 s = &sliders[i];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
125 value = *(s->var);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
126 if ((i == 0) || (i == 2))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
127 value = s->max - value;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
128 if (value < s->min)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
129 value = s->min;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
130 else if (value > s->max)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
131 value = s->max;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
132 #if 0
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
133 if (value == s->lastVal)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
134 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
135 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
136 new_x = value * SL_WID / s->diff;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
137 y = s->yellow * SL_WID / s->diff;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
138 r = s->red * SL_WID / s->diff;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
139 t = s->max * SL_WID / s->diff;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
140 if (value > s->red) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
141 box(1, BX_OFF(), BY_OFF(i), y, SL_HEI, gColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
142 box(1, BX_OFF() + y, BY_OFF(i), r - y, SL_HEI, yColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
143 box(1, BX_OFF() + r, BY_OFF(i), new_x - r, SL_HEI, rColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
144 } else if (value > s->yellow) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
145 box(1, BX_OFF(), BY_OFF(i), y, SL_HEI, gColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
146 box(1, BX_OFF() + y, BY_OFF(i), new_x - y, SL_HEI, yColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
147 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
148 box(1, BX_OFF(), BY_OFF(i), new_x, SL_HEI, gColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
149 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
150 box(1, BX_OFF() + new_x, BY_OFF(i), t - new_x, SL_HEI, backColor);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
151 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
152 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
153
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
154 static void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
155 box(filled, x, y, wid, hei, color)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
156 int filled, x, y, wid, hei;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
157 W_Color color;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
158 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
159 if (wid == 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
160 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
161
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
162 if (filled) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
163 /* XFIX */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
164 W_FillArea(statwin, x, y, wid + 1, hei + 1, color);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
165 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
166 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
167 W_MakeLine(statwin, x, y, x + wid, y, color);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
168 W_MakeLine(statwin, x + wid, y, x + wid, y + hei, color);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
169 W_MakeLine(statwin, x + wid, y + hei, x, y + hei, color);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
170 W_MakeLine(statwin, x, y + hei, x, y, color);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
171 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
172
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
173
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
174 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
175 calibrate_stats()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
176 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
177 register int i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
178 sliders[0].min = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
179 sliders[0].max = me->p_ship->s_maxshield;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
180 sliders[0].yellow = .33 * ((double) sliders[0].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
181 sliders[0].red = .66 * ((double) sliders[0].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
182
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
183 sliders[1].min = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
184 sliders[1].max = me->p_ship->s_maxdamage;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
185 sliders[1].yellow = .33 * ((double) sliders[1].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
186 sliders[1].red = .66 * ((double) sliders[1].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
187
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
188 sliders[2].min = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
189 sliders[2].max = me->p_ship->s_maxfuel;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
190 sliders[2].yellow = .33 * ((double) sliders[2].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
191 sliders[2].red = .66 * ((double) sliders[2].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
192
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
193 sliders[3].min = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
194 sliders[3].max = 1.0 * ((double) me->p_ship->s_maxwpntemp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
195 sliders[3].yellow = .33 * ((double) sliders[3].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
196 sliders[3].red = .66 * ((double) sliders[3].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
197
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
198 sliders[4].min = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
199 sliders[4].max = 1.0 * ((double) me->p_ship->s_maxegntemp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
200 sliders[4].yellow = .33 * ((double) sliders[4].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
201 sliders[4].red = .66 * ((double) sliders[4].max);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
202
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
203 for (i = 0; i < NUM_SLIDERS; i++)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
204 sliders[i].diff = sliders[i].max - sliders[i].min;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
205
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
206 }