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