comparison planetlist.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: planetlist.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
2
3 /*
4 * planetlist.c
5 */
6 #include "copyright.h"
7 #include <stdio.h>
8 #include <string.h>
9
10 #include "Wlib.h"
11 #include "defs.h"
12 #include "struct.h"
13 #include "data.h"
14 #include "proto.h"
15
16 /* Prototypes */
17 static void planet_list_paradise P((void));
18 static void planet_list_normal P((void));
19 static void print_planet P((W_Window wind, int line, struct planet * j));
20
21 static char *teamname[5] = {
22 "IND",
23 "FED",
24 "ROM",
25 "KLI",
26 "ORI"
27 };
28
29 /*
30 ** Open a window which contains all the planets and their current
31 ** statistics. Players will not know about planets that their team
32 ** has not orbited.
33 */
34
35 void
36 planetlist()
37 {
38 /*
39 W_ClearWindow(planetw);
40 */
41 if (!paradise) { /* if not a paradise server then */
42 planet_list_normal();
43 } else { /* else must be a paradise server */
44 planet_list_paradise();
45 }
46 }
47
48
49 /*This function provides the planet list for a normal server. */
50
51 static void
52 planet_list_normal()
53 {
54 int k = 0; /* for row number */
55 int i; /* looping var */
56 struct planet *j; /* to point to a planet */
57 char buf[100]; /* to sprintf into */
58 char buf1[40];
59 W_Window wind;
60
61 wind = planetw;
62
63 for (i = 0, j = &planets[i]; i < nplanets; i++, j++) {
64 if (i == 0 || i == nplanets / 2) {
65 if (i != 0) {
66 wind = planetw2;
67 }
68 sprintf(buf, "Planet name Own Armies Resources Info");
69 W_WriteText(wind, 2, 1, textColor, buf, strlen(buf), W_RegularFont);
70 k = 2;
71 }
72 sprintf(buf1, "%-16s ", j->pl_name);
73 if (j->pl_info & idx_to_mask(me->p_teami)) {
74 sprintf(buf, "%3s %3d %s%s%s %s ",
75 teamname[mask_to_idx(j->pl_owner) + 1],
76 j->pl_armies,
77 (j->pl_flags & PLREPAIR ? "REPR " : " "),
78 (j->pl_flags & PLFUEL ? "FUEL " : " "),
79 (j->pl_flags & PLAGRI ? "AGRI " : " "),
80 team_bit_string(j->pl_info));
81 W_WriteText(wind, 2, k, planetColor(j), buf1, strlen(buf1),
82 planetFont(j));
83 W_WriteText(wind, 24, k++, planetColor(j), buf, strlen(buf),
84 planetFont(j));
85 }
86 /* end of have info */
87 else { /* else no info on planet */
88 W_WriteText(wind, 2, k++, planetColor(j), buf1, strlen(buf1),
89 planetFont(j));
90 }
91 } /* end of for loop */
92
93 }
94
95
96
97 /*This function provides the planet list for a paradise server version 2.0 */
98
99 static void
100 planet_list_paradise()
101 {
102 typedef struct planet *plptr;
103
104 int k = 0; /* for row number */
105 int i, team_pnum; /* looping var */
106 plptr j; /* to point to a planet */
107 char buf[100]; /* to sprintf into */
108 W_Window wind;
109 extern int number_of_teams;
110 plptr **team_p;
111 int *team_pcount;
112
113 wind = planetw;
114
115 /* this malloc stuff will handle any number of teams/races */
116
117 /* team's planet counters */
118 team_pcount = (int *) malloc((number_of_teams + 1) * sizeof(int));
119 for (i = 0; i < number_of_teams + 1; i++)
120 team_pcount[i] = 0;
121
122 if (mapSort) {
123 /* make some memory */
124 team_p = (plptr **) malloc((number_of_teams + 1) * sizeof(struct planet *));
125 for (i = 0; i < (number_of_teams + 1); i++)
126 team_p[i] = (plptr *) malloc(nplanets * sizeof(struct planet *));
127
128 /* loop thru and put proper team planeter point on each planet */
129 for (i = 0, j = &planets[i]; i < nplanets; i++, j++) {
130 k = mask_to_idx(j->pl_owner) + 1; /* which team gets planet */
131 team_p[k][team_pcount[k]] = j;
132 team_pcount[k]++;
133 }
134
135 /* go thru each teams planet list and display */
136 for (i = 0, k = 0; i < (number_of_teams + 1); i++) {
137 for (team_pnum = 0; team_pnum < team_pcount[i]; team_pnum++, k++) {
138
139 j = team_p[i][team_pnum];
140 /* (nplanets+13)/2 is the height of window; from newwin.c */
141 if (k == 0 || k >= ((nplanets + 13) / 2)) {
142 if (k != 0)
143 wind = planetw2;
144 sprintf(buf, "Planet name sctr own armies RESOURCES SURFC ATMOS VISIT TIME");
145 W_WriteText(wind, 2, 1, textColor, buf, strlen(buf), W_RegularFont);
146 k = 2;
147 }
148 print_planet(wind, k, j);
149 } /* end of 2nd for */
150 if (team_pcount[i] > 0)
151 k++;
152 } /* end of 1st for */
153
154 for (i = 0; i < (number_of_teams + 1); i++)
155 free(team_p[i]);
156 free(team_p);
157 } else { /* do the original alpa only sort planet list */
158
159 for (i = 0, j = &planets[i]; i < nplanets; i++, j++, k++) {
160 if (i == 0 || i == nplanets / 2) {
161
162 sprintf(buf, "Planet name sctr own armies RESOURCES SURFC ATMOS VISIT TIME");
163
164 if (i != 0) {
165 wind = planetw2;
166 }
167 W_WriteText(wind, 2, 1, textColor, buf, strlen(buf), W_RegularFont);
168 k = 2;
169 }
170 team_pcount[mask_to_idx(j->pl_owner) + 1]++;
171 print_planet(wind, k, j);
172 }
173 }
174
175 k++;
176 for (i = 0; i < (number_of_teams + 1); i++) {
177 W_Color cur_color;
178
179 cur_color = shipCol[i];
180 sprintf(buf, "%s: ", teamname[i]);
181 W_WriteText(wind, i * 7 + 2, k, cur_color, buf, strlen(buf), W_RegularFont);
182 sprintf(buf, " %.2i", team_pcount[i]);
183 W_WriteText(wind, i * 7 + 2, k + 1, cur_color, buf, strlen(buf), W_RegularFont);
184 }
185
186 free(team_pcount);
187
188 } /* end of planet_list_paradise */
189
190
191 /****************************** print_planet() ************************/
192 static void
193 print_planet(wind, line, j)
194 W_Window wind;
195 int line;
196 struct planet *j;
197 {
198 char buf[100]; /* to sprintf into */
199
200 sprintf(buf, "%-16s %d-%d", j->pl_name, (j->pl_x / GRIDSIZE) + 1,
201 (j->pl_y / GRIDSIZE) + 1);
202 W_WriteText(wind, 2, line, textColor, buf, strlen(buf),
203 W_RegularFont);
204
205 if (j->pl_info & idx_to_mask(me->p_teami)) {
206 if (PL_TYPE(*j) == PLSTAR) { /* if planet actually a star */
207 W_WriteText(wind, 24, line, textColor, "---S T A R---", 13,
208 W_RegularFont);
209 } else if (PL_TYPE(*j) == PLWHOLE) { /* if wormhole... */
210 W_WriteText(wind, 24, line, textColor, "---W O R M H O L E---", 21,
211 W_RegularFont);
212 } else { /* else planet not a star */
213 char *s = NULL;
214
215 switch (j->pl_flags & PLATMASK) {
216 case PLPOISON:
217 s = "TOXC";
218 break;
219 case PLATYPE3:
220 s = "TNTD";
221 break;
222 case PLATYPE2:
223 s = "THIN";
224 break;
225 case PLATYPE1:
226 s = "STND";
227 break;
228 };
229 sprintf(buf, "%3s %3d %c%c%c%c %c%c%c %4s",
230 teamname[mask_to_idx(j->pl_owner) + 1],
231 j->pl_armies,
232 (j->pl_flags & PLREPAIR ? 'R' : ' '),
233 (j->pl_flags & PLFUEL ? 'F' : ' '),
234 (j->pl_flags & PLAGRI ? 'A' : ' '),
235 (j->pl_flags & PLSHIPYARD ? 'S' : ' '),
236 (j->pl_flags & PLDILYTH ? 'D' : ' '),
237 (j->pl_flags & PLMETAL ? 'M' : ' '),
238 (j->pl_flags & PLARABLE ? 'A' : ' '),
239 s);
240
241 W_WriteText(wind, 24, line, planetColor(j), buf, strlen(buf),
242 planetFont(j));
243
244 sprintf(buf, "%4s %3ld",
245 team_bit_string(j->pl_info),
246 ((idx_to_mask(me->p_teami) == j->pl_owner) ? 0 : (status2->clock - j->pl_timestamp)));
247
248 W_WriteText(wind, 64, line, planetColor(j), buf, strlen(buf),
249 planetFont(j));
250 }
251 } else {
252 sprintf(buf, "--- No info; Scout me ---");
253 W_WriteText(wind, 24, line, textColor, buf, strlen(buf),
254 W_RegularFont);
255 }
256 } /* end of print_planet */