diff --git a/Makefile b/Makefile index 6e4b99e..e2d8e20 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,6 @@ events.c: dat/events mkevents.py ./mkevents.py c >events.c widgets.o: widgets.c widgets.h bits.h render.h - $(CC) $(CFLAGS) $(CPPFLAGS) $(SDLFLAGS) -o $@ -c $< save/%.sav: save/%.sav.in gensave.py ./gensave.py --salt $< <$< >$@ @@ -103,3 +102,9 @@ static: all mkdir static cp -r art dat lib map save stats *.o static/ make -C static -f lib/Makefile -B harris + +windows: all + mkdir windows + cp -r art dat map save stats *.c *.h *.o *.py windows/ + cp lib-w/* windows/ + make -C windows -f Makefile.w32 -B diff --git a/bits.c b/bits.c index 5763dee..6433cf9 100644 --- a/bits.c +++ b/bits.c @@ -177,3 +177,14 @@ int gacid(const char from[8], acid *buf) } return(0); } + +#ifdef WINDOWS /* doesn't have strndup, we need to implement one */ +char *strndup(const char *s, size_t size) +{ + char *rv=(char *)malloc(size+1); + if(rv==NULL) return(NULL); + strncpy(rv, s, size); + rv[size]=0; + return(rv); +} +#endif diff --git a/bits.h b/bits.h index f7b610e..734fc47 100644 --- a/bits.h +++ b/bits.h @@ -31,3 +31,7 @@ void free_string(string *s); // frees a string (is just free(s->buf); really) void pacid(acid id, char buf[9]); // print an a/c id as hex int gacid(const char from[8], acid *buf); // parse an a/c id from hex + +#ifdef WINDOWS /* doesn't have strndup, we need to implement one */ +char *strndup(const char *s, size_t size); +#endif diff --git a/gensave.py b/gensave.py index 9d4a6f1..bb6d0ef 100755 --- a/gensave.py +++ b/gensave.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import sys, zlib +import sys, zlib, struct def multiply(line): if len(line) > 1: @@ -20,6 +20,8 @@ def genids(line, i): else: return line +windows = '--windows' in sys.argv + salt = '' if '--salt' in sys.argv: sarg = sys.argv.index('--salt') @@ -29,8 +31,26 @@ def genids(line, i): sys.stderr.write('--salt requires argument!\n') sys.exit(1) +def float_to_hex(value): + f = float(value) + bytes = struct.pack('>d', f) + i, = struct.unpack('>q', bytes) + return '%016x'%i + for line in sys.stdin.readlines(): lines = multiply(line) for i,line in enumerate(lines): line = genids(line, i) + if windows and ':' in line: + to_conv = {'Confid':(0,), + 'Morale':(0,), + 'IClass':(1,), + 'Targets init':(0,1,2,3), + 'Targ':(1,2,3,4),} + tag, values = line.rstrip('\n').split(':', 1) + values = values.split(',') + if tag in to_conv: + for pos in to_conv[tag]: + values[pos] = float_to_hex(values[pos]) + line = ':'.join((tag, ','.join(values))) + '\n' sys.stdout.write(line) diff --git a/harris.c b/harris.c index b43692e..e26a4fe 100644 --- a/harris.c +++ b/harris.c @@ -112,8 +112,10 @@ unsigned char tnav[128][128]; // Recognisability of terrain. High for rivers, e unsigned int mainsizex=default_w, mainsizey=default_h; bool fullscreen=false; +#ifndef WINDOWS bool localdat=false, localsav=false; char *cwd; +#endif game state; @@ -123,6 +125,7 @@ int main(int argc, char *argv[]) for(int arg=1;argevents.h + +events.c: dat/events mkevents.py + ./mkevents.py c >events.c + +save/%.sav: save/%.sav.in gensave.py + ./gensave.py --windows --salt $< <$< >$@ + +dat/targets: FORCE + sed -i dat/targets -e 's/ö/o/g' -e 's/ü/u/g' -e 's/Ø/O/g' + +dat/cities/Lubeck.pbm: dat/cities/Lübeck.pbm + cp dat/cities/Lübeck.pbm dat/cities/Lubeck.pbm + +dat/cities/Peenemunde.pbm: dat/cities/Peenemünde.pbm + cp dat/cities/Peenemünde.pbm dat/cities/Peenemunde.pbm + +%.o: %.c %.h + $(CC) $(CFLAGS) $(CPPFLAGS) $(SDLFLAGS) -o $@ -c $< + +FORCE: diff --git a/lib-w/SDL.dll b/lib-w/SDL.dll new file mode 100755 index 0000000..729ceef Binary files /dev/null and b/lib-w/SDL.dll differ diff --git a/lib-w/SDL_image.dll b/lib-w/SDL_image.dll new file mode 100755 index 0000000..1960353 Binary files /dev/null and b/lib-w/SDL_image.dll differ diff --git a/lib-w/SDL_ttf.dll b/lib-w/SDL_ttf.dll new file mode 100755 index 0000000..d860530 Binary files /dev/null and b/lib-w/SDL_ttf.dll differ diff --git a/lib-w/jpeg.dll b/lib-w/jpeg.dll new file mode 100755 index 0000000..12dfb0d Binary files /dev/null and b/lib-w/jpeg.dll differ diff --git a/lib-w/libSDL_gfx-13.dll b/lib-w/libSDL_gfx-13.dll new file mode 100755 index 0000000..831f48d Binary files /dev/null and b/lib-w/libSDL_gfx-13.dll differ diff --git a/lib-w/libatg.dll b/lib-w/libatg.dll new file mode 100755 index 0000000..5708042 Binary files /dev/null and b/lib-w/libatg.dll differ diff --git a/lib-w/libfreetype-6.dll b/lib-w/libfreetype-6.dll new file mode 100755 index 0000000..fed8bca Binary files /dev/null and b/lib-w/libfreetype-6.dll differ diff --git a/lib-w/libpng12-0.dll b/lib-w/libpng12-0.dll new file mode 100755 index 0000000..060fca9 Binary files /dev/null and b/lib-w/libpng12-0.dll differ diff --git a/lib-w/libtiff-3.dll b/lib-w/libtiff-3.dll new file mode 100755 index 0000000..737e0d0 Binary files /dev/null and b/lib-w/libtiff-3.dll differ diff --git a/lib-w/zlib1.dll b/lib-w/zlib1.dll new file mode 100755 index 0000000..91bd79c Binary files /dev/null and b/lib-w/zlib1.dll differ diff --git a/load_data.c b/load_data.c index d7769fa..1dc6cfe 100644 --- a/load_data.c +++ b/load_data.c @@ -20,6 +20,13 @@ #include "ui.h" #include "widgets.h" +#ifdef WINDOWS /* I hate having to put in these ugly warts */ +#define ssize_t int +#define zn "%n" +#else +#define zn "%zn" +#endif + int load_bombers(void) { FILE *typefp=fopen("dat/bombers", "r"); @@ -43,7 +50,7 @@ int load_bombers(void) this.manu=(char *)malloc(strcspn(next, ":")+1); ssize_t db; int e; - if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%zn", this.manu, this.name, &this.cost, &this.speed, &this.alt, &this.cap, &this.svp, &this.defn, &this.fail, &this.accu, &this.range, &this.blat, &this.blon, &db))!=13) + if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:%u:"zn, this.manu, this.name, &this.cost, &this.speed, &this.alt, &this.cap, &this.svp, &this.defn, &this.fail, &this.accu, &this.range, &this.blat, &this.blon, &db))!=13) { fprintf(stderr, "Malformed `bombers' line `%s'\n", next); fprintf(stderr, " sscanf returned %d\n", e); @@ -166,7 +173,7 @@ int load_fighters(void) this.manu=(char *)malloc(strcspn(next, ":")+1); ssize_t db; int e; - if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%hhu:%zn", this.manu, this.name, &this.cost, &this.speed, &this.arm, &this.mnv, &this.radpri, &db))!=7) + if((e=sscanf(next, "%[^:]:%[^:]:%u:%u:%u:%u:%hhu:"zn, this.manu, this.name, &this.cost, &this.speed, &this.arm, &this.mnv, &this.radpri, &db))!=7) { fprintf(stderr, "Malformed `fighters' line `%s'\n", next); fprintf(stderr, " sscanf returned %d\n", e); @@ -270,7 +277,7 @@ int load_ftrbases(void) // LAT:LONG:ENTRY:EXIT ssize_t db; int e; - if((e=sscanf(next, "%u:%u:%zn", &this.lat, &this.lon, &db))!=2) + if((e=sscanf(next, "%u:%u:"zn, &this.lat, &this.lon, &db))!=2) { fprintf(stderr, "Malformed `ftrbases' line `%s'\n", next); fprintf(stderr, " sscanf returned %d\n", e); @@ -321,7 +328,7 @@ int load_targets(void) this.p_intel=NULL; ssize_t db; int e; - if((e=sscanf(next, "%[^:]:%u:%u:%u:%u:%u:%zn", this.name, &this.prod, &this.flak, &this.esiz, &this.lat, &this.lon, &db))!=6) + if((e=sscanf(next, "%[^:]:%u:%u:%u:%u:%u:"zn, this.name, &this.prod, &this.flak, &this.esiz, &this.lat, &this.lon, &db))!=6) { fprintf(stderr, "Malformed `targets' line `%s'\n", next); fprintf(stderr, " sscanf returned %d\n", e); @@ -580,7 +587,7 @@ int load_flaksites(void) // STRENGTH:LAT:LONG:ENTRY:RADAR:EXIT ssize_t db; int e; - if((e=sscanf(next, "%u:%u:%u:%zn", &this.strength, &this.lat, &this.lon, &db))!=3) + if((e=sscanf(next, "%u:%u:%u:"zn, &this.strength, &this.lat, &this.lon, &db))!=3) { fprintf(stderr, "Malformed `flak' line `%s'\n", next); fprintf(stderr, " sscanf returned %d\n", e); diff --git a/saving.c b/saving.c index a03271e..8545f56 100644 --- a/saving.c +++ b/saving.c @@ -17,6 +17,16 @@ #include "rand.h" #include "version.h" +#ifdef WINDOWS /* Because of this little bugger, savegames from Windows won't work on Linux/Unix and vice-versa */ +#define FLOAT "%llx" +#define CAST_FLOAT_PTR (unsigned long long *) +#define CAST_FLOAT (unsigned long long) +#else +#define FLOAT "%la" +#define CAST_FLOAT_PTR +#define CAST_FLOAT +#endif + bool version_newer(const unsigned char v1[3], const unsigned char v2[3]) // true iff v1 newer than v2 { for(unsigned int i=0;i<3;i++) @@ -109,7 +119,7 @@ int loadgame(const char *fn, game *state) } else if(strcmp(tag, "Confid")==0) { - f=sscanf(dat, "%la\n", &state->confid); + f=sscanf(dat, FLOAT"\n", CAST_FLOAT_PTR &state->confid); if(f!=1) { fprintf(stderr, "1 Too few arguments to tag \"%s\"\n", tag); @@ -118,7 +128,7 @@ int loadgame(const char *fn, game *state) } else if(strcmp(tag, "Morale")==0) { - f=sscanf(dat, "%la\n", &state->morale); + f=sscanf(dat, FLOAT"\n", CAST_FLOAT_PTR &state->morale); if(f!=1) { fprintf(stderr, "1 Too few arguments to tag \"%s\"\n", tag); @@ -324,7 +334,7 @@ int loadgame(const char *fn, game *state) continue; } unsigned int j; - f=sscanf(line, "IClass %u:%la\n", &j, &state->gprod[i]); + f=sscanf(line, "IClass %u:"FLOAT"\n", &j, CAST_FLOAT_PTR &state->gprod[i]); if(f!=2) { fprintf(stderr, "1 Too few arguments to part %u of tag \"%s\"\n", i, tag); @@ -422,7 +432,7 @@ int loadgame(const char *fn, game *state) else if(strcmp(tag, "Targets init")==0) { double dmg,flk,heat,flam; - f=sscanf(dat, "%la,%la,%la,%la\n", &dmg, &flk, &heat, &flam); + f=sscanf(dat, FLOAT","FLOAT","FLOAT","FLOAT"\n", CAST_FLOAT_PTR &dmg, CAST_FLOAT_PTR &flk, CAST_FLOAT_PTR &heat, CAST_FLOAT_PTR &flam); if(f!=4) { fprintf(stderr, "1 Too few arguments to tag \"%s\"\n", tag); @@ -470,7 +480,7 @@ int loadgame(const char *fn, game *state) } unsigned int j; double dmg, flk, heat, flam; - f=sscanf(line, "Targ %u:%la,%la,%la,%la\n", &j, &dmg, &flk, &heat, &flam); + f=sscanf(line, "Targ %u:"FLOAT","FLOAT","FLOAT","FLOAT"\n", &j, CAST_FLOAT_PTR &dmg, CAST_FLOAT_PTR &flk, CAST_FLOAT_PTR &heat, CAST_FLOAT_PTR &flam); if(f!=5) { fprintf(stderr, "1 Too few arguments to part %u of tag \"%s\"\n", j, tag); @@ -501,7 +511,7 @@ int loadgame(const char *fn, game *state) else if(strcmp(tag, "Weather state")==0) { state->weather.seed=0; - f=sscanf(dat, "%la,%la\n", &state->weather.push, &state->weather.slant); + f=sscanf(dat, FLOAT","FLOAT"\n", CAST_FLOAT_PTR &state->weather.push, CAST_FLOAT_PTR &state->weather.slant); if(f!=2) { fprintf(stderr, "1 Too few arguments to tag \"%s\"\n", tag); @@ -522,7 +532,7 @@ int loadgame(const char *fn, game *state) for(unsigned int y=0;y<128;y++) { int bytes; - if(sscanf(line+p, "%la,%la,%n", &state->weather.p[x][y], &state->weather.t[x][y], &bytes)!=2) + if(sscanf(line+p, FLOAT","FLOAT",%n", CAST_FLOAT_PTR &state->weather.p[x][y], CAST_FLOAT_PTR &state->weather.t[x][y], &bytes)!=2) { fprintf(stderr, "1 Too few arguments to part (%u,%u) of tag \"%s\"\n", x, y, tag); e|=1; @@ -620,8 +630,13 @@ int loadgame(const char *fn, game *state) } else if(strcmp(tag, "History")==0) { + #ifdef WINDOWS + unsigned long nents; + f=sscanf(dat, "%lu\n", &nents); + #else size_t nents; f=sscanf(dat, "%zu\n", &nents); + #endif if(f!=1) { fprintf(stderr, "1 Too few arguments to tag \"%s\"\n", tag); @@ -663,8 +678,8 @@ int savegame(const char *fn, game state) fprintf(fs, "DATE:%02d-%02d-%04d\n", state.now.day, state.now.month, state.now.year); for(unsigned int i=0;i