diff options
Diffstat (limited to 'devtools/create_supernova/create_supernova.cpp')
-rw-r--r-- | devtools/create_supernova/create_supernova.cpp | 154 |
1 files changed, 131 insertions, 23 deletions
diff --git a/devtools/create_supernova/create_supernova.cpp b/devtools/create_supernova/create_supernova.cpp index 2022808303..b9571e4644 100644 --- a/devtools/create_supernova/create_supernova.cpp +++ b/devtools/create_supernova/create_supernova.cpp @@ -2,6 +2,7 @@ #include "gametext.h" #include "file.h" #include "po_parser.h" +#include <iostream> // HACK to allow building with the SDL backend on MinGW // see bug #1800764 "TOOLS: MinGW tools building broken" @@ -20,12 +21,62 @@ const char *lang[] = { NULL }; -void writeDocFile(File& outputFile, const char *fileExtension, const char* language) { +void writeDatafile(File& outputFile, int fileNumber, const char* language, int part) { + File dataFile; + char fileName[20]; + if (part == 1) + sprintf(fileName, "msn_data.%03d-%s", fileNumber, language); + if (part == 2) + sprintf(fileName, "ms2_data.%03d-%s", fileNumber, language); + if (!dataFile.open(fileName, kFileReadMode)) { + printf("Cannot find dataFile %s. This file will be skipped.\n", fileName); + return; + } + + // Write block header in output file (4 bytes). + // M(fileNumber) for example M015 + char number[4]; + sprintf(number, "%03d", fileNumber); + outputFile.writeByte('M'); + for (int i = 0 ; i < 3 ; ++i) { + outputFile.writeByte(number[i]); + } + // And write the language code on 4 bytes as well (padded with 0 if needed). + int languageLength = strlen(language); + for (int i = 0 ; i < 4 ; ++i) { + if (i < languageLength) + outputFile.writeByte(language[i]); + else + outputFile.writeByte(0); + } + + // Write block size + + dataFile.seek(0, SEEK_END); + int length = dataFile.pos(); + dataFile.seek(0, SEEK_SET); + outputFile.writeLong(length); + + // Write all the bytes. We should have w * h / 8 bytes + // However we need to invert the bits has the engine expects 1 for the background and 0 for the text (black) + // but pbm uses 0 for white and 1 for black. + for (int i = 0 ; i < length; ++i) { + byte b = dataFile.readByte(); + outputFile.writeByte(b); + } + + dataFile.close(); +} + +void writeDocFile(File& outputFile, const char *fileExtension, const char* language, int part) { File docFile; char fileName[20]; - sprintf(fileName, "msn.%s-%s", fileExtension, language); + if (part == 1) + sprintf(fileName, "msn.%s-%s", fileExtension, language); + if (part == 2) + sprintf(fileName, "ms2.%s-%s", fileExtension, language); if (!docFile.open(fileName, kFileReadMode)) { - printf("Cannot find file 'msn.%s' for language '%s'. This file will be skipped.\n", fileExtension, language); + printf("Cannot find file '%s'. This file will be skipped.\n", fileName); return; } @@ -37,7 +88,7 @@ void writeDocFile(File& outputFile, const char *fileExtension, const char* langu else outputFile.writeByte(fileExtension[i]); } - outputFile.writeByte('1'); + outputFile.writeByte((char) part + '0'); // And write the language code on 4 bytes as well (padded with 0 if needed). int languageLength = strlen(language); @@ -179,7 +230,7 @@ void writeImage(File& outputFile, const char *name, const char* language) { imgFile.close(); } -void writeGermanStrings(File& outputFile) { +void writeGermanStrings(File& outputFile, int part) { // Write header and language outputFile.write("TEXT", 4); outputFile.write("de\0\0", 4); @@ -190,7 +241,11 @@ void writeGermanStrings(File& outputFile) { outputFile.writeLong(blockSize); // Write all the strings - const char **s = &gameText[0]; + const char **s; + if (part == 1) + s = &gameText1[0]; + if (part == 2) + s = &gameText2[0]; while (*s) { outputFile.writeString(*s); blockSize += strlen(*s) + 1; @@ -203,9 +258,9 @@ void writeGermanStrings(File& outputFile) { outputFile.seek(0, SEEK_END); } -void writeStrings(File& outputFile, const char* language) { +void writeStrings(File& outputFile, const char* language, int part) { char fileName[16]; - sprintf(fileName, "strings-%s.po", language); + sprintf(fileName, "strings%d-%s.po", part, language); PoMessageList* poList = parsePoFile(fileName); if (!poList) { printf("Cannot find strings file for language '%s'.\n", language); @@ -231,7 +286,11 @@ void writeStrings(File& outputFile, const char* language) { // Write all the strings. // If a string is not translated we use the German one. - const char **s = &gameText[0]; + const char **s; + if (part == 1) + s = &gameText1[0]; + if (part == 2) + s = &gameText2[0]; while (*s) { const char* translation = poList->findTranslation(*s); if (translation) { @@ -247,10 +306,66 @@ void writeStrings(File& outputFile, const char* language) { // Now write the block size and then go back to the end of the file. outputFile.seek(blockSizePos, SEEK_SET); + outputFile.writeLong(blockSize); outputFile.seek(0, SEEK_END); } +void writeMS1(File &outputFile) { + // First part + outputFile.writeByte(1); + + // Reserve space for game block size + uint32 blockSizePos = outputFile.pos(); + uint32 blockSize = 0; + outputFile.writeLong(blockSize); + + // German strings + writeGermanStrings(outputFile, 1); + + // Other languages + const char **l = &lang[0]; + while(*l) { + writeImage(outputFile, "img1", *l); + writeImage(outputFile, "img2", *l); + writeStrings(outputFile, *l, 1); + writeDocFile(outputFile, "inf", *l, 1); + writeDocFile(outputFile, "doc", *l, 1); + ++l; + } + blockSize = outputFile.pos() - blockSizePos - 4; + outputFile.seek(blockSizePos, SEEK_SET); + outputFile.writeLong(blockSize); + outputFile.seek(0, SEEK_END); +} + +void writeMS2(File &outputFile) { + // Second part + outputFile.writeByte(2); + + // Reserve space for game block size + uint32 blockSizePos = outputFile.pos(); + uint32 blockSize = 0; + outputFile.writeLong(blockSize); + + // German strings + writeGermanStrings(outputFile, 2); + + // Other languages + const char **l = &lang[0]; + while(*l) { + writeDatafile(outputFile, 15, *l, 2); + writeDatafile(outputFile, 28, *l, 2); + writeStrings(outputFile, *l, 2); + writeDocFile(outputFile, "inf", *l, 2); + writeDocFile(outputFile, "doc", *l, 2); + ++l; + } + blockSize = outputFile.pos() - blockSizePos - 4; + outputFile.seek(blockSizePos, SEEK_SET); + outputFile.writeLong(blockSize); + outputFile.seek(0, SEEK_END); +} /** * Main method @@ -265,31 +380,24 @@ int main(int argc, char *argv[]) { // The generated file is of the form: // 3 bytes: 'MSN' // 1 byte: version + // - game blocks + // 1 byte: part (1 or 2) + // 4 bytes: game block size // -- data blocks // 4 bytes: header 'IMG1' and 'IMG2' for newspaper images (for file 1 and file 2 respectively), // 'TEXT' for strings // 4 bytes: language code ('en\0', 'de\0'- see common/language.cpp) // 4 bytes: block size n (uint32) // n bytes: data - // --- + // -- + // - // Header outputFile.write("MSN", 3); outputFile.writeByte(VERSION); - // German strings - writeGermanStrings(outputFile); - - // Other languages - const char **l = &lang[0]; - while(*l) { - writeImage(outputFile, "img1", *l); - writeImage(outputFile, "img2", *l); - writeStrings(outputFile, *l); - writeDocFile(outputFile, "inf", *l); - writeDocFile(outputFile, "doc", *l); - ++l; - } + writeMS1(outputFile); + writeMS2(outputFile); outputFile.close(); return 0; |