src/newgrf_config.cpp
branchnoai
changeset 10455 22c441f5adf9
parent 9732 f8eb3e208514
child 10513 33cb70ff2f5d
equal deleted inserted replaced
10412:ef44f62cb8b9 10455:22c441f5adf9
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file newgrf_config.cpp */
     3 /** @file newgrf_config.cpp Finding NewGRFs and configuring them. */
     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 "variables.h"
     8 #include "variables.h"
    15 #include "string_func.h"
    15 #include "string_func.h"
    16 
    16 
    17 #include "fileio.h"
    17 #include "fileio.h"
    18 #include "fios.h"
    18 #include "fios.h"
    19 #include <sys/stat.h>
    19 #include <sys/stat.h>
    20 
       
    21 #ifdef WIN32
       
    22 # include <io.h>
       
    23 #endif /* WIN32 */
       
    24 
    20 
    25 
    21 
    26 GRFConfig *_all_grfs;
    22 GRFConfig *_all_grfs;
    27 GRFConfig *_grfconfig;
    23 GRFConfig *_grfconfig;
    28 GRFConfig *_grfconfig_newgame;
    24 GRFConfig *_grfconfig_newgame;
   408 
   404 
   409 	/* Sort the linked list using quicksort.
   405 	/* Sort the linked list using quicksort.
   410 	 * For that we first have to make an array, the qsort and
   406 	 * For that we first have to make an array, the qsort and
   411 	 * then remake the linked list. */
   407 	 * then remake the linked list. */
   412 	GRFConfig **to_sort = MallocT<GRFConfig*>(num);
   408 	GRFConfig **to_sort = MallocT<GRFConfig*>(num);
   413 	if (to_sort == NULL) return; // No memory, then don't sort
       
   414 
   409 
   415 	uint i = 0;
   410 	uint i = 0;
   416 	for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) {
   411 	for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) {
   417 		to_sort[i] = p;
   412 		to_sort[i] = p;
   418 	}
   413 	}
   424 	for (i = 1; i < num; i++) {
   419 	for (i = 1; i < num; i++) {
   425 		to_sort[i - 1]->next = to_sort[i];
   420 		to_sort[i - 1]->next = to_sort[i];
   426 	}
   421 	}
   427 	to_sort[num - 1]->next = NULL;
   422 	to_sort[num - 1]->next = NULL;
   428 	_all_grfs = to_sort[0];
   423 	_all_grfs = to_sort[0];
       
   424 
       
   425 	free(to_sort);
   429 }
   426 }
   430 
   427 
   431 
   428 
   432 /* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/
   429 /* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/
   433 const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
   430 const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)