./conv < data/1.levels > bd4.1
./conv < data/4.levels > bd4.4
etc.
Code: Select all
/* 2007-11-12T21:47:54Z
*
* convert bd4 caves to emc v6 caves
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
static const unsigned char map_v4[256] = { /* filter crap for v4 */
0,0,2,2,4,4,118,118,8,9,10,11,12,13,14,15,
16,16,18,18,20,21,22,23,24,25,26,27,28,28,118,28,
0,16,2,18,36,37,37,37,147,41,42,43,44,45,128,128,
128,148,148,148,45,45,45,148,0,153,153,59,60,61,62,63,
64,65,66,153,153,153,153,153,153,153,153,153,153,153,153,153,
153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,
153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,
153,118,114,115,131,118,118,119,120,121,122,118,118,118,118,118,
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,68,154,155,156,157,158,160,
160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,175,
153,153,153,153,153,153,153,153,153,153,153,153,153,153,68,153,
153,153,153,153,153,153,153,153,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,153,153,153,153,153,153,153,153,153,153,153,153,153,153,
};
unsigned char bd4[2432];
unsigned char emc[2172];
int main()
{
int num;
for(num = 0; fread(bd4, sizeof(bd4), 1, stdin) == 1; num++) {
int i, j;
if(bd4[98] != 32 && bd4[99] != 64) {
fprintf(stderr, "unrecognized bd4 cave (%d)\n", num);
continue;
}
memset(emc, 0, sizeof(emc));
emc[2106] = 255; emc[2107] = 54; emc[2108] = 48; emc[2109] = 48;
emc[2159] = 128;
for(i = 0; i < 2048; i++) emc[i] = map_v4[bd4[i + 100]]; /* cave */
for(i = 64; i < 2048; i++) if(emc[i] == 63) emc[i - 64] = 128;
for(i = 64; i < 2048; i++) if(emc[i] == 63) emc[i - 64] = 101;
for(i = 0; i < 36; i++) emc[i + 2048] = map_v4[bd4[i + 2149]]; /* eaters */
for(i = 0; i < 36; i++) emc[i + 2112] = map_v4[bd4[i + 2185]];
if(bd4[2148] == 4) {
for(i = 0; i < 36; i++) emc[i + 2112] = emc[i + 2048];
}
for(i = 0; i < 10; i++) emc[i + 2084] = bd4[i + 2221]; /* scores */
for(i = 0; i < 4; i += 2) { /* players */
j = bd4[i + 2236] << 8 | bd4[i + 2237];
j &= 2047;
emc[i + 2096] = j >> 8; emc[i + 2097] = j;
emc[j] = 128;
}
for(i = 0; i < 6; i += 2) { /* speed */
j = bd4[i + 2240] << 8 | bd4[i + 2241];
if(j > 9999) j = 9999;
emc[i + 2100] = j >> 8; emc[i + 2101] = j;
}
i = bd4[2231] << 16 | bd4[2232] << 8 | bd4[2233]; /* time */
i /= 50;
if(i > 9999) i = 9999;
emc[2110] = i >> 8; emc[2111] = i;
i = bd4[2234] << 8 | bd4[2235]; /* emeralds */
if(i > 255) i = 255;
emc[2095] = i;
if(fwrite(emc, sizeof(emc), 1, stdout) != 1) { perror("write failed"); return(1); }
}
return(0);
}
/*
structure of bd4 level disk files
elements are probably exactly the same as emerald mine v4
100 - cave data (64*32)
2148 - number of eater explosions
2149 - eater explosion 1
2158 - eater explosion 2
2167 - eater explosion 3
2176 - eater explosion 4
2185 - eater explosion 5
2194 - eater explosion 6
2203 - eater explosion 7
2212 - eater explosion 8
2221 - emerald score
2222 - diamond score
2223 - alien score
2224 - tank score
2225 - bug score
2226 - eater score
2227 - nut score
2228 - dynamite score
2229 - key score
2230 - bonus
2231 - time (seconds * 500)
2234 - emeralds needed
2236 - player 1 pos
2238 - player 2 pos
2240 - ameuba speed
2242 - wonderwall time
2244 - wheel time
2246
2432 - size
*/