-
Notifications
You must be signed in to change notification settings - Fork 7
/
globals.c
285 lines (261 loc) · 6.84 KB
/
globals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
harris - a strategy game
Copyright (C) 2012-2015 Edward Cree
licensed under GPLv3+ - see top of harris.c for details
globals: game entity data
*/
#include "globals.h"
#include "run_raid.h"
#include "ui.h"
const char * const navaids[NNAVAIDS]={"GEE","H2S","OBOE","GH"};
const char * const navpicfn[NNAVAIDS]={"art/navaids/gee.png", "art/navaids/h2s.png", "art/navaids/oboe.png", "art/navaids/g-h.png"};
unsigned int navevent[NNAVAIDS]={EVENT_GEE, EVENT_H2S, EVENT_OBOE, EVENT_GH};
unsigned int navprod[NNAVAIDS]={3, 7, 22, 12}; // 10/productionrate; later 25/productionrate
const char * const winpicfn[NWINLVLS]={"art/window/none.png", "art/window/normal.png", "art/window/extra.png", "art/window/full.png"};
double todays_delta, todays_eqn; // values for the almanack
date event[NEVENTS];
char *evtext[NEVENTS];
struct oboe oboe={.lat=95, .lon=63, .k=-1};
struct gee gee={.lat=107, .lon=64, .jrange=65};
struct bombloadinfo bombloads[NBOMBLOADS]=
{
[BL_ABNORMAL]={.name="Ab", .fn="art/bombloads/abnormal.png"},
[BL_PPLUS ]={.name="Pp", .fn="art/bombloads/plumduff-plus.png"},
[BL_PLUMDUFF]={.name="Pd", .fn="art/bombloads/plumduff.png"},
[BL_PONLY ]={.name="Po", .fn="art/bombloads/plumduff-only.png"},
[BL_USUAL ]={.name="Us", .fn="art/bombloads/usual.png"},
[BL_ARSON ]={.name="Ar", .fn="art/bombloads/arson.png"},
[BL_ILLUM ]={.name="Il", .fn="art/bombloads/illuminator.png"},
[BL_HALFHALF]={.name="Hh", .fn="art/bombloads/halfandhalf.png"},
};
struct overlay overlays[NUM_OVERLAYS] = {
[OVERLAY_CITY] = {.ifn="art/overlays/cities.png", .selected=true},
[OVERLAY_FLAK] = {.ifn="art/overlays/flak.png", .selected=true},
[OVERLAY_TARGET] = {.ifn="art/overlays/targets.png", .selected=true},
[OVERLAY_WEATHER] = {.ifn="art/overlays/weather.png", .selected=true},
[OVERLAY_ROUTE] = {.ifn="art/overlays/routes.png", .selected=true},
};
const char *tpipe_names[TPIPE__MAX] = {
[TPIPE_OTU] = "OTU",
[TPIPE_HCU] = "HCU",
[TPIPE_LFS] = "LFS",
};
unsigned int max_dwell[TPIPE__MAX] = {
[TPIPE_OTU] = 160,
[TPIPE_HCU] = 30,
[TPIPE_LFS] = 10,
};
char *tpipe_descs[TPIPE__MAX]={0};
char *tpipe_bt_desc=NULL;
unsigned int ntypes=0;
bombertype *types=NULL;
bombertype *rawtypes=NULL;
unsigned int nmods=0;
bmod *mods=NULL;
unsigned int nbases=0;
base *bases=NULL;
unsigned int nftypes=0;
fightertype *ftypes=NULL;
unsigned int nfbases=0;
ftrbase *fbases=NULL;
unsigned int nlocs=0;
locxn *locs=NULL;
unsigned int ntargs=0;
target *targs=NULL;
unsigned int nflaks=0;
flaksite *flaks=NULL;
unsigned int nstarts=0;
startpoint *starts=NULL;
SDL_Surface *terrain=NULL;
SDL_Surface *location=NULL;
SDL_Surface *yellowhair=NULL;
SDL_Surface *intelbtn=NULL;
SDL_Surface *nointelbtn=NULL;
SDL_Surface *navpic[NNAVAIDS];
SDL_Surface *winpic[NWINLVLS];
SDL_Surface *elitepic=NULL;
SDL_Surface *studentpic=NULL;
SDL_Surface *markpic[4];
SDL_Surface *grouppic[8];
SDL_Surface *england=NULL;
SDL_Surface *resizebtn=NULL;
SDL_Surface *fullbtn=NULL;
SDL_Surface *exitbtn=NULL;
SDL_Surface *tick=NULL, *cross=NULL;
SDL_Surface *intelscreenbtn[3];
SDL_Surface *grey_overlay=NULL, *yellow_overlay=NULL;
SDL_Surface *weather_overlay=NULL, *sun_overlay=NULL, *city_overlay=NULL, *target_overlay=NULL, *flak_overlay=NULL, *route_overlay=NULL, *xhair_overlay=NULL, *seltarg_overlay=NULL;
bool lorw[128][128]; // TRUE for water
unsigned char tnav[128][128]; // Recognisability of terrain. High for rivers, even higher for coastline
unsigned int nregions=0;
struct region *regions;
unsigned int region[256][256];
unsigned int mainsizex=default_w, mainsizey=default_h;
bool fullscreen=false;
#ifndef WINDOWS
bool localdat=false, localsav=false;
char *cwd;
#endif
int set_init_state(game *state)
{
state->nbombers=state->nfighters=0;
state->bombers=NULL;
state->fighters=NULL;
state->paving=-1;
state->nsquads=0;
state->squads=NULL;
state->nsnums=0;
state->ntargs=ntargs;
if(!(state->dmg=calloc(ntargs, sizeof(*state->dmg))))
{
perror("calloc");
return(1);
}
if(!(state->flk=calloc(ntargs, sizeof(*state->flk))))
{
perror("calloc");
return(1);
}
if(!(state->heat=calloc(ntargs, sizeof(*state->heat))))
{
perror("calloc");
return(1);
}
if(!(state->flam=calloc(ntargs, sizeof(*state->flam))))
{
perror("calloc");
return(1);
}
if(!(state->raids=malloc(ntargs*sizeof(*state->raids))))
{
perror("malloc");
return(1);
}
if(!(state->btypes=malloc(ntypes*sizeof(*state->btypes))))
{
perror("malloc");
return(1);
}
for(unsigned int n=0;n<NNAVAIDS;n++)
{
state->nap[n]=0;
state->napb[n]=0;
}
for(unsigned int i=0;i<ntargs;i++)
{
state->raids[i].bombers=NULL;
if(!(state->raids[i].loads=calloc(ntypes, sizeof(bombload))))
{
perror("malloc");
return(1);
}
if(!(state->raids[i].pffloads=calloc(ntypes, sizeof(bombload))))
{
perror("malloc");
return(1);
}
if(!(state->raids[i].window=calloc(ntypes, sizeof(winlvl))))
{
perror("malloc");
return(1);
}
for(unsigned int j=0;j<ntypes;j++)
{
state->raids[i].loads[j]=BL_USUAL;
int limit=0;
if(types[j].noarm)
state->raids[i].pffloads[j]=BL_ILLUM;
else if(types[j].lfs)
state->raids[i].pffloads[j]=BL_PPLUS;
else
state->raids[i].pffloads[j]=BL_ABNORMAL;
while(!types[j].load[state->raids[i].loads[j]])
{
state->raids[i].loads[j]=(state->raids[i].loads[j]+1)%NBOMBLOADS;
if(++limit>=NBOMBLOADS)
{
fprintf(stderr, "No valid bombloads for type %s\n", types[j].name);
return(1);
}
}
while(!types[j].load[state->raids[i].pffloads[j]])
{
state->raids[i].pffloads[j]=(state->raids[i].pffloads[j]+1)%NBOMBLOADS;
if(++limit>=NBOMBLOADS)
{
fprintf(stderr, "No valid PFF bombloads for type %s\n", types[j].name);
return(1);
}
}
state->raids[i].window[j]=WL_NORMAL;
}
}
clear_raids(state);
state->roe.idtar=true;
for(unsigned int i=0;i<MAXMSGS;i++)
state->msg[i]=NULL;
state->hist.nents=0;
state->hist.nalloc=0;
state->hist.ents=NULL;
for(unsigned int i=0;i<2;i++)
{
state->tfav[i]=T_CLASSES;
state->tfd[i]=0;
state->ifav[i]=I_CLASSES;
state->ifd[i]=0;
}
if(!(dij=malloc(ntargs*sizeof(int *))))
{
perror("malloc");
return(1);
}
if(!(nij=malloc(ntargs*sizeof(int *))))
{
perror("malloc");
return(1);
}
if(!(tij=malloc(ntargs*sizeof(int *))))
{
perror("malloc");
return(1);
}
if(!(lij=malloc(ntargs*sizeof(int *))))
{
perror("malloc");
return(1);
}
for(unsigned int i=0;i<ntargs;i++)
{
if(!(dij[i]=calloc(ntypes, sizeof(int))))
{
perror("calloc");
return(1);
}
if(!(nij[i]=calloc(ntypes, sizeof(int))))
{
perror("calloc");
return(1);
}
if(!(tij[i]=calloc(ntypes, sizeof(int))))
{
perror("calloc");
return(1);
}
if(!(lij[i]=calloc(ntypes, sizeof(int))))
{
perror("calloc");
return(1);
}
}
if(!(heat=calloc(ntargs, sizeof(unsigned int))))
{
perror("calloc");
return(1);
}
if(!(canscore=calloc(ntargs, sizeof(bool))))
{
perror("calloc");
return(1);
}
return(0);
}