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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
/*
viDOOM - level editor for DOOM
Copyright (C) 2000 Ian Cowburn (ianc@noddybox.demon.co.uk)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------
Handles definition and storage of the supported THINGS
*/
static const char rcs_id[]="$Id$";
#include "config.h"
#include "globals.h"
#include "platgui.h"
#include "gfx.h"
#include "things.h"
#include "mem.h"
#include "list.h"
#include "map.h"
/* ---------------------------------------- TYPES AND VARS
*/
#define DEFAULT_RAD 20
#define DEFAULT_COL V_RGB(0xff,0x80,0x80)
typedef struct
{
char *name;
int col;
} ThingClass;
typedef struct
{
int class;
int id;
char *name;
GFX_IMAGE img;
} ThingInfo;
typedef struct
{
int id;
int rad;
int col;
} ThingRad;
static int no_classes=0;
static Map thing_class=NULL;
static List thing_list=NULL;
static List rad_list=NULL;
static PLAT_IMG_PICKLIST **picklist=NULL;
static PLAT_MENU *thing_menu=NULL;
static char *thing_flags[17]=
{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
static char *thing_flags_sh[17]=
{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
/* ---------------------------------------- PRIVATE FUNCTIONS
*/
static PLAT_IMG_PICKLIST *ThingPicklist(int class)
{
ThingInfo *ti;
Iterator i;
int no;
int f;
if (picklist[class])
return(picklist[class]);
else
{
no=0;
i=ListIterator(thing_list);
while(i)
{
ti=IteratorData(i);
if (ti->class==class)
no++;
i=IteratorNext(i);
}
picklist[class]=Grab(sizeof(PLAT_IMG_PICKLIST)*(no+1));
i=ListIterator(thing_list);
f=0;
while(i)
{
ti=IteratorData(i);
if (ti->class==class)
{
picklist[class][f].text=ti->name;
picklist[class][f].img=ti->img;
picklist[class][f].client_index=ti->id;
f++;
}
i=IteratorNext(i);
}
picklist[class][f].text=NULL;
picklist[class][f].img=NULL;
return(picklist[class]);
}
}
/* ---------------------------------------- EXPORTED FUNCTIONS
*/
void ThingNewClass(char *class, int col)
{
ThingClass c;
if (!thing_class)
thing_class=MapNew(sizeof(ThingClass));
c.name=Strdup(class);
c.col=col;
MapAdd(thing_class,no_classes++,&c);
}
void ThingAdd(char *class,char *name,int id,int rad,GFX_IMAGE sprite)
{
ThingInfo *ti;
ThingRad *tr;
int i_class;
int col;
int f;
if (!thing_list)
{
thing_list=ListNew(sizeof(ThingInfo));
rad_list=ListNew(sizeof(ThingInfo));
}
i_class=-1;
col=DEFAULT_COL;
for(f=0;f<MapSize(thing_class);f++)
{
ThingClass *c;
c=MapElem(thing_class,f);
if (STREQ(c->name,class))
{
i_class=f;
col=c->col;
}
}
if (i_class==-1)
i_class=0;
ti=Grab(sizeof(ThingInfo));
ti->class=i_class;
ti->name=Strdup(name);
ti->id=id;
ti->img=sprite;
ListAppend(thing_list,ti);
tr=Grab(sizeof(ThingRad));
tr->id=id;
tr->rad=rad;
tr->col=col;
ListAppend(rad_list,tr);
}
int SelectThing(void)
{
int class;
int f;
int x,y;
if (!thing_menu)
{
thing_menu=Grab(sizeof(PLAT_MENU)*(no_classes+1));
picklist=Grab(sizeof(PLAT_IMG_PICKLIST *)*(no_classes+1));
for(f=0;f<no_classes;f++)
{
ThingClass *c;
c=MapElem(thing_class,f);
thing_menu[f].text=c->name;
thing_menu[f].client_index=f;
}
for(f=0;f<no_classes+1;f++)
picklist[f]=NULL;
thing_menu[no_classes].text=NULL;
}
GFX_mouse(&x,&y);
if (no_classes<2)
class=0;
else
class=GUI_menu("Pick class of THING",x,y,thing_menu,THING_NULLID);
if (class!=THING_NULLID)
class=GUI_image_picklist("THING",ThingPicklist(class),THING_NULLID);
return(class);
}
int ThingRadius(int id, int *col)
{
Iterator i;
ThingRad *r;
i=ListIterator(rad_list);
while(i)
{
r=IteratorData(i);
if (r->id==id)
{
IteratorClear(i);
if (col)
*col=r->col;
return(r->rad);
}
i=IteratorNext(i);
}
if (col)
*col=DEFAULT_COL;
return(DEFAULT_RAD);
}
char *ThingName(int id)
{
ThingInfo *ti;
Iterator i;
i=ListIterator(thing_list);
while(i)
{
ti=IteratorData(i);
if (ti->id==id)
{
IteratorClear(i);
return(ti->name);
}
i=IteratorNext(i);
}
return("UNKNOWN");
}
void ThingFlag(int bit,char *s,char *sh)
{
thing_flags[bit]=Strdup(s);
thing_flags_sh[bit]=Strdup(sh);
}
char **ThingFlagArray(void)
{
return(thing_flags);
}
char *ThingFlagText(int flags)
{
static char s[512];
int b;
s[0]=0;
for(b=0;b<16;b++)
if (flags&(1<<b))
if (thing_flags_sh[b])
if (!s[0])
strcpy(s,thing_flags_sh[b]);
else
{
strcat(s,",");
strcat(s,thing_flags_sh[b]);
}
return(s);
}
/* END OF FILE */
|