src/gfxinit.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     3 /** @file gfxinit.cpp */
     3 /** @file gfxinit.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "debug.h"
     7 #include "debug.h"
     8 #include "functions.h"
       
     9 #include "gfx.h"
       
    10 #include "gfxinit.h"
     8 #include "gfxinit.h"
    11 #include "spritecache.h"
     9 #include "spritecache.h"
    12 #include "table/sprites.h"
       
    13 #include "fileio.h"
    10 #include "fileio.h"
    14 #include "fios.h"
    11 #include "fios.h"
    15 #include "string.h"
       
    16 #include "newgrf.h"
    12 #include "newgrf.h"
    17 #include "md5.h"
    13 #include "md5.h"
    18 #include "variables.h"
    14 #include "variables.h"
    19 #include "fontcache.h"
    15 #include "fontcache.h"
       
    16 #include "gfx_func.h"
       
    17 #include "core/alloc_func.hpp"
       
    18 #include "core/bitmath_func.hpp"
    20 #include <string.h>
    19 #include <string.h>
       
    20 #include "settings_type.h"
       
    21 
       
    22 #include "table/sprites.h"
    21 
    23 
    22 struct MD5File {
    24 struct MD5File {
    23 	const char * filename;     ///< filename
    25 	const char * filename;     ///< filename
    24 	md5_byte_t hash[16];       ///< md5 sum of the file
    26 	uint8 hash[16];            ///< md5 sum of the file
    25 };
    27 };
    26 
    28 
    27 struct FileList {
    29 struct FileList {
    28 	MD5File basic[2];     ///< GRF files that always have to be loaded
    30 	MD5File basic[2];     ///< GRF files that always have to be loaded
    29 	MD5File landscape[3]; ///< Landscape specific grf files
    31 	MD5File landscape[3]; ///< Landscape specific grf files
    30 	MD5File sound;        ///< Sound samples
    32 	MD5File sound;        ///< Sound samples
    31 	MD5File chars;        ///< GRF File with character replacements
       
    32 	MD5File openttd;      ///< GRF File with OTTD specific graphics
    33 	MD5File openttd;      ///< GRF File with OTTD specific graphics
    33 };
    34 };
    34 
    35 
    35 #include "table/files.h"
    36 #include "table/files.h"
    36 #include "table/landscape_sprite.h"
    37 #include "table/landscape_sprite.h"
   107 {
   108 {
   108 	size_t size;
   109 	size_t size;
   109 	FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
   110 	FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
   110 
   111 
   111 	if (f != NULL) {
   112 	if (f != NULL) {
   112 		md5_state_t filemd5state;
   113 		Md5 checksum;
   113 		md5_byte_t buffer[1024];
   114 		uint8 buffer[1024];
   114 		md5_byte_t digest[16];
   115 		uint8 digest[16];
   115 		size_t len;
   116 		size_t len;
   116 
   117 
   117 		md5_init(&filemd5state);
       
   118 		while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
   118 		while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
   119 			size -= len;
   119 			size -= len;
   120 			md5_append(&filemd5state, buffer, len);
   120 			checksum.Append(buffer, len);
   121 		}
   121 		}
   122 
   122 
   123 		FioFCloseFile(f);
   123 		FioFCloseFile(f);
   124 
   124 
   125 		md5_finish(&filemd5state, digest);
   125 		checksum.Finish(digest);
   126 		return memcmp(file.hash, digest, sizeof(file.hash)) == 0;
   126 		return memcmp(file.hash, digest, sizeof(file.hash)) == 0;
   127 	} else { // file not found
   127 	} else { // file not found
   128 		return false;
   128 		return false;
   129 	}
   129 	}
   130 }
   130 }
   187 		}
   187 		}
   188 	}
   188 	}
   189 
   189 
   190 	if (!FileMD5(files_win.sound) && !FileMD5(files_dos.sound)) {
   190 	if (!FileMD5(files_win.sound) && !FileMD5(files_dos.sound)) {
   191 		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n");
   191 		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n");
   192 	}
       
   193 
       
   194 	if (!FileMD5(files->chars)) {
       
   195 		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! The file was part of your installation.\n", files->chars.filename);
       
   196 	}
   192 	}
   197 
   193 
   198 	if (!FileMD5(files->openttd)) {
   194 	if (!FileMD5(files->openttd)) {
   199 		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! The file was part of your installation.\n", files->openttd.filename);
   195 		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! The file was part of your installation.\n", files->openttd.filename);
   200 	}
   196 	}
   281 /* Graphics */
   277 /* Graphics */
   282 	 674, 4792,
   278 	 674, 4792,
   283 	END
   279 	END
   284 };
   280 };
   285 
   281 
   286 /** Replace some letter sprites with some other letters */
       
   287 static const SpriteID _chars_grf_indexes[] = {
       
   288 	134, 134, ///<  euro symbol medium size
       
   289 	582, 582, ///<  euro symbol large size
       
   290 	358, 358, ///<  euro symbol tiny
       
   291 	648, 648, ///<  nordic char: æ
       
   292 	616, 616, ///<  nordic char: Æ
       
   293 	666, 666, ///<  nordic char: ø
       
   294 	634, 634, ///<  nordic char: Ø
       
   295 	382, 383, ///<  Œ œ tiny
       
   296 	158, 159, ///<  Œ œ medium
       
   297 	606, 607, ///<  Œ œ large
       
   298 	360, 360, ///<  Š tiny
       
   299 	362, 362, ///<  š tiny
       
   300 	136, 136, ///<  Š medium
       
   301 	138, 138, ///<  š medium
       
   302 	584, 584, ///<  Š large
       
   303 	586, 586, ///<  š large
       
   304 	626, 626, ///<  Ð large
       
   305 	658, 658, ///<  ð large
       
   306 	374, 374, ///<  Ž tiny
       
   307 	378, 378, ///<  ž tiny
       
   308 	150, 150, ///<  Ž medium
       
   309 	154, 154, ///<  ž medium
       
   310 	598, 598, ///<  Ž large
       
   311 	602, 602, ///<  ž large
       
   312 	640, 640, ///<  Þ large
       
   313 	672, 672, ///<  þ large
       
   314 	380, 380, ///<  º tiny
       
   315 	156, 156, ///<  º medium
       
   316 	604, 604, ///<  º large
       
   317 	317, 320, ///<  { | } ~ tiny
       
   318 	 93,  96, ///<  { | } ~ medium
       
   319 	541, 544, ///<  { | } ~ large
       
   320 	585, 585, ///<  § large
       
   321 	587, 587, ///<  © large
       
   322 	592, 592, ///<  ® large
       
   323 	594, 597, ///<  ° ± ² ³ large
       
   324 	633, 633, ///<  × large
       
   325 	665, 665, ///<  ÷ large
       
   326 	377, 377, ///<  · small
       
   327 	153, 153, ///<  · medium
       
   328 	601, 601, ///<  · large
       
   329 	END
       
   330 };
       
   331 
       
   332 
       
   333 static void LoadSpriteTables()
   282 static void LoadSpriteTables()
   334 {
   283 {
   335 	const FileList *files = _use_dos_palette ? &files_dos : &files_win;
   284 	const FileList *files = _use_dos_palette ? &files_dos : &files_win;
   336 	uint i = FIRST_GRF_SLOT;
   285 	uint i = FIRST_GRF_SLOT;
   337 
   286 
   358 			files->landscape[_opt.landscape - 1].filename,
   307 			files->landscape[_opt.landscape - 1].filename,
   359 			_landscape_spriteindexes[_opt.landscape - 1],
   308 			_landscape_spriteindexes[_opt.landscape - 1],
   360 			i++
   309 			i++
   361 		);
   310 		);
   362 	}
   311 	}
   363 
       
   364 	LoadGrfIndexed(files->chars.filename, _chars_grf_indexes, i++);
       
   365 
   312 
   366 	/* Initialize the unicode to sprite mapping table */
   313 	/* Initialize the unicode to sprite mapping table */
   367 	InitializeUnicodeGlyphMap();
   314 	InitializeUnicodeGlyphMap();
   368 
   315 
   369 	/*
   316 	/*