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
|
bit7-bit6 = How many (0=has Misc2 and Misc3, not Misc1)
bit5-bit4 = Misc3 type
bit3-bit2 = Misc2 type
bit1-bit0 = Misc1 type
* misc data (variable size)
Store/use MRU slot 0 if any bits of 0x70 set in flag byte; slot 1 otherwise
*/
Uint8 x=0;
Uint8 y=1;
const Object*m[2]={0,0};
sqlite3_str*str=sqlite3_str_new(0);
Uint32 n;
long sz;
char*data;
int i;
// Header
if(level_changed) version_change();
level_changed=0;
sqlite3_str_appendchar(str,1,level_version&255);
sqlite3_str_appendchar(str,1,level_version>>8);
sqlite3_str_appendchar(str,1,level_code&255);
sqlite3_str_appendchar(str,1,level_code>>8);
sqlite3_str_appendchar(str,1,pfwidth-1);
sqlite3_str_appendchar(str,1,pfheight-1);
if(level_title) sqlite3_str_appendall(str,level_title);
sqlite3_str_appendchar(str,1,0);
// Objects
for(i=0;i<64*64;i++) {
n=playfield[i];
while(n!=VOIDLINK) {
save_obj(str,objects[n],m,x,y);
x=objects[n]->x;
y=objects[n]->y;
n=objects[n]->up;
}
}
save_obj(str,0,m,x,y);
sqlite3_str_appendchar(str,1,0xFF);
// Level strings
for(i=0;i<nlevelstrings;i++) {
sqlite3_str_appendall(str,levelstrings[i]);
sqlite3_str_appendchar(str,1,0);
}
// Done
|
>
>
|
>
>
>
>
>
>
>
>
>
|
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
|
bit7-bit6 = How many (0=has Misc2 and Misc3, not Misc1)
bit5-bit4 = Misc3 type
bit3-bit2 = Misc2 type
bit1-bit0 = Misc1 type
* misc data (variable size)
Store/use MRU slot 0 if any bits of 0x70 set in flag byte; slot 1 otherwise
*/
Uint32*p=playfield;
Uint8 x=0;
Uint8 y=1;
const Object*m[2]={0,0};
sqlite3_str*str=sqlite3_str_new(0);
Uint32 n;
long sz;
char*data;
int i;
// Header
if(level_changed) version_change();
level_changed=0;
sqlite3_str_appendchar(str,1,level_version&255);
sqlite3_str_appendchar(str,1,level_version>>8);
sqlite3_str_appendchar(str,1,level_code&255);
sqlite3_str_appendchar(str,1,level_code>>8);
sqlite3_str_appendchar(str,1,pfwidth-1);
sqlite3_str_appendchar(str,1,pfheight-1);
if(level_title) sqlite3_str_appendall(str,level_title);
sqlite3_str_appendchar(str,1,0);
// Objects
again:
for(i=0;i<64*64;i++) {
n=p[i];
while(n!=VOIDLINK) {
save_obj(str,objects[n],m,x,y);
x=objects[n]->x;
y=objects[n]->y;
n=objects[n]->up;
}
}
save_obj(str,0,m,x,y);
if(p==playfield) {
p=bizplayfield;
for(i=0;i<64*64;i++) if(p[i]!=VOIDLINK) {
sqlite3_str_appendchar(str,1,0xFE);
x=0;
y=1;
goto again;
}
}
sqlite3_str_appendchar(str,1,0xFF);
// Level strings
for(i=0;i<nlevelstrings;i++) {
sqlite3_str_appendall(str,levelstrings[i]);
sqlite3_str_appendchar(str,1,0);
}
// Done
|
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
|
case TY_MESSAGE: fprintf(fp," %s%s",v.u<256?"":"#",v.u<256?standard_message_names[v.u]:messages[v.u-256]);
case TY_LEVELSTRING: fprintf(fp," %%%u",(int)v.u); break;
default: fprintf(fp," ???"); break;
}
}
static void export_level(const char*cmd) {
int i;
Uint32 n;
Object*o;
FILE*fp;
if(!cmd || !*cmd) return;
fp=popen(cmd,"w");
if(!fp) {
screen_message("Cannot open pipe");
return;
}
fprintf(fp,"; Free Hero Mesh exported level ID=%d ORD=%d\n",level_id,level_ord);
fprint_esc(fp,'@',level_title);
fprintf(fp,"C %d\nD %d %d\n",level_code,pfwidth,pfheight);
for(i=0;i<64*64;i++) {
n=playfield[i];
while(n!=VOIDLINK) {
o=objects[n];
fprintf(fp,"%d %d $%s %d",o->x,o->y,classes[o->class]->name,o->image);
fprint_misc(fp,o->misc1);
fprint_misc(fp,o->misc2);
fprint_misc(fp,o->misc3);
fprintf(fp," %d\n",o->dir);
n=o->up;
}
}
for(i=0;i<nlevelstrings;i++) fprint_esc(fp,'%',levelstrings[i]);
pclose(fp);
}
static char*import_numbers(char*p,int*x,int*y) {
if(!p) return 0;
while(*p==' ' || *p=='\t') p++;
|
>
>
|
>
>
>
>
>
>
>
>
>
|
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
|
case TY_MESSAGE: fprintf(fp," %s%s",v.u<256?"":"#",v.u<256?standard_message_names[v.u]:messages[v.u-256]);
case TY_LEVELSTRING: fprintf(fp," %%%u",(int)v.u); break;
default: fprintf(fp," ???"); break;
}
}
static void export_level(const char*cmd) {
Uint32*p=playfield;
int i;
Uint32 n;
Object*o;
FILE*fp;
if(!cmd || !*cmd) return;
fp=popen(cmd,"w");
if(!fp) {
screen_message("Cannot open pipe");
return;
}
fprintf(fp,"; Free Hero Mesh exported level ID=%d ORD=%d\n",level_id,level_ord);
fprint_esc(fp,'@',level_title);
fprintf(fp,"C %d\nD %d %d\n",level_code,pfwidth,pfheight);
again:
for(i=0;i<64*64;i++) {
n=p[i];
while(n!=VOIDLINK) {
o=objects[n];
fprintf(fp,"%d %d $%s %d",o->x,o->y,classes[o->class]->name,o->image);
fprint_misc(fp,o->misc1);
fprint_misc(fp,o->misc2);
fprint_misc(fp,o->misc3);
fprintf(fp," %d\n",o->dir);
n=o->up;
}
}
if(p==playfield) {
p=bizplayfield;
for(i=0;i<64*64;i++) if(p[i]!=VOIDLINK) {
fprintf(fp,"W\n");
goto again;
}
} else {
fprintf(fp,"W\n");
}
for(i=0;i<nlevelstrings;i++) fprint_esc(fp,'%',levelstrings[i]);
pclose(fp);
}
static char*import_numbers(char*p,int*x,int*y) {
if(!p) return 0;
while(*p==' ' || *p=='\t') p++;
|
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
|
break;
case 'V':
p=import_numbers(p+1,&x,0);
if(!p || *p) goto bad;
level_version=x;
level_changed=0;
break;
case '@':
free(level_title);
level_title=import_string(p+1);
break;
case '%':
if(nlevelstrings>0x2000) {
screen_message("Too many level strings");
|
>
>
>
>
|
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
|
break;
case 'V':
p=import_numbers(p+1,&x,0);
if(!p || *p) goto bad;
level_version=x;
level_changed=0;
break;
case 'W':
if(!d) goto missd;
swap_world();
break;
case '@':
free(level_title);
level_title=import_string(p+1);
break;
case '%':
if(nlevelstrings>0x2000) {
screen_message("Too many level strings");
|
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
|
return 0;
case '^s': // String list/edit
string_list();
return 0;
case '^u': // Add object (allow duplicates)
if(prev) return prev;
add_object_at(number&63?:64,number/64?:64,mru+curmru,0);
return 0;
case '^N': // New level
if(level_nindex>0xFFFE) return 0;
new_level();
return 1;
case '^P': // Play
return -2;
|
>
>
>
>
|
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
|
return 0;
case '^s': // String list/edit
string_list();
return 0;
case '^u': // Add object (allow duplicates)
if(prev) return prev;
add_object_at(number&63?:64,number/64?:64,mru+curmru,0);
return 0;
case '^w': // Swap world
swap_world();
level_changed=1;
return 0;
case '^N': // New level
if(level_nindex>0xFFFE) return 0;
new_level();
return 1;
case '^P': // Play
return -2;
|