208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
for(i=0;i<level_nindex;i++) level_index[i]=data[i+i]|(data[i+i+1]<<8);
free(data);
}
const char*load_level(int lvl) {
// Load level by ID. Returns null pointer if successful, or an error message if it failed.
long sz=0;
unsigned char*buf=lvl>=0?read_lump(FIL_LEVEL,lvl,&sz):0;
unsigned char*p=buf;
unsigned char*end=buf+sz;
unsigned char*q;
int i,n,x,y,z;
Uint16 lo=0;
Uint32 o;
|
>
|
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
for(i=0;i<level_nindex;i++) level_index[i]=data[i+i]|(data[i+i+1]<<8);
free(data);
}
const char*load_level(int lvl) {
// Load level by ID. Returns null pointer if successful, or an error message if it failed.
long sz=0;
Uint16 of=0;
unsigned char*buf=lvl>=0?read_lump(FIL_LEVEL,lvl,&sz):0;
unsigned char*p=buf;
unsigned char*end=buf+sz;
unsigned char*q;
int i,n,x,y,z;
Uint16 lo=0;
Uint32 o;
|
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
|
level_title=0;
annihilate();
generation_number=TY_MAXTYPE+1;
generation_number_inc=0;
level_version=p[0]|(p[1]<<8);
level_code=p[2]|(p[3]<<8);
p+=4;
pfwidth=(*p++&63)+1;
pfheight=(*p++&63)+1;
while(*p && p<end) p++; // skip text for now
p++; // skip null terminator
if(p>=end) goto bad1;
level_title=strdup(buf+6);
if(!level_title) fatal("Allocation failed\n");
x=0;
y=1;
n=0;
mru[0]=mru[1]=VOIDLINK;
for(;;) {
if(n) {
o=objalloc(objects[*mru]->class);
if(o==VOIDLINK) goto bad3;
objects[o]->image=objects[*mru]->image;
objects[o]->misc1=objects[*mru]->misc1;
objects[o]->misc2=objects[*mru]->misc2;
objects[o]->misc3=objects[*mru]->misc3;
objects[o]->dir=objects[*mru]->dir;
objects[o]->x=++x;
objects[o]->y=y;
if(x>pfwidth) goto bad2;
pflink(o);
--n;
} else {
if(p>=end) goto bad1;
z=*p++;
if(z==0xFF) break;
if(z&0x20) x=*p++;
if(z&0x10) y=*p++;
if(z&0x40) x++;
if(!x || !y || x>pfwidth || y>pfheight) goto bad2;
n=z&0x70?0:1;
if(z&0x80) {
// MRU
if(mru[n]==VOIDLINK) goto bad1;
o=objalloc(objects[mru[n]]->class);
if(o==VOIDLINK) goto bad3;
objects[o]->image=objects[mru[n]]->image;
objects[o]->misc1=objects[mru[n]]->misc1;
objects[o]->misc2=objects[mru[n]]->misc2;
objects[o]->misc3=objects[mru[n]]->misc3;
objects[o]->dir=objects[mru[n]]->dir;
objects[o]->x=x;
objects[o]->y=y;
pflink(o);
n=z&15;
} else {
// Not MRU
i=*p++;
i|=*p++<<8;
o=objalloc(i&0x3FFF);
if(o==VOIDLINK) goto bad3;
if(n!=2) mru[n]=o;
if(i&0x8000) {
n=objects[o]->class;
for(i=0;i<classes[n]->nimages;i++) {
if(classes[n]->images[i]&0x8000) {
objects[o]->image=i;
break;
|
>
>
>
<
>
|
>
>
>
>
>
>
|
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
|
level_title=0;
annihilate();
generation_number=TY_MAXTYPE+1;
generation_number_inc=0;
level_version=p[0]|(p[1]<<8);
level_code=p[2]|(p[3]<<8);
p+=4;
if(*p&0x80) of=OF_BIZARRO;
pfwidth=(*p++&63)+1;
pfheight=(*p++&63)+1;
while(*p && p<end) p++; // skip text for now
p++; // skip null terminator
if(p>=end) goto bad1;
level_title=strdup(buf+6);
if(!level_title) fatal("Allocation failed\n");
mru[0]=mru[1]=VOIDLINK;
restart:
x=0;
y=1;
n=0;
for(;;) {
if(n) {
o=objalloc(objects[*mru]->class);
if(o==VOIDLINK) goto bad3;
objects[o]->oflags=(objects[o]->oflags&~OF_BIZARRO)|of;
objects[o]->image=objects[*mru]->image;
objects[o]->misc1=objects[*mru]->misc1;
objects[o]->misc2=objects[*mru]->misc2;
objects[o]->misc3=objects[*mru]->misc3;
objects[o]->dir=objects[*mru]->dir;
objects[o]->x=++x;
objects[o]->y=y;
if(x>pfwidth) goto bad2;
pflink(o);
--n;
} else {
if(p>=end) goto bad1;
z=*p++;
if(z==0xFF) {
if(!of) break;
of=0;
goto restart;
}
if(z&0x20) x=*p++;
if(z&0x10) y=*p++;
if(z&0x40) x++;
if(!x || !y || x>pfwidth || y>pfheight) goto bad2;
n=z&0x70?0:1;
if(z&0x80) {
// MRU
if(mru[n]==VOIDLINK) goto bad1;
o=objalloc(objects[mru[n]]->class);
if(o==VOIDLINK) goto bad3;
objects[o]->oflags=(objects[o]->oflags&~OF_BIZARRO)|of;
objects[o]->image=objects[mru[n]]->image;
objects[o]->misc1=objects[mru[n]]->misc1;
objects[o]->misc2=objects[mru[n]]->misc2;
objects[o]->misc3=objects[mru[n]]->misc3;
objects[o]->dir=objects[mru[n]]->dir;
objects[o]->x=x;
objects[o]->y=y;
pflink(o);
n=z&15;
} else {
// Not MRU
i=*p++;
i|=*p++<<8;
o=objalloc(i&0x3FFF);
if(o==VOIDLINK) goto bad3;
objects[o]->oflags=(objects[o]->oflags&~OF_BIZARRO)|of;
if(n!=2) mru[n]=o;
if(i&0x8000) {
n=objects[o]->class;
for(i=0;i<classes[n]->nimages;i++) {
if(classes[n]->images[i]&0x8000) {
objects[o]->image=i;
break;
|