src/gfxinit.cpp
changeset 10048 a0e67d110e5a
parent 10039 1f236afd6cd1
child 10062 8ec5e3f048b7
equal deleted inserted replaced
10047:a5c34dea770c 10048:a0e67d110e5a
   167 
   167 
   168 /**
   168 /**
   169  * Determine the graphics pack that has to be used.
   169  * Determine the graphics pack that has to be used.
   170  * The one with the most correct files wins.
   170  * The one with the most correct files wins.
   171  */
   171  */
   172 static void DetermineGraphicsPack()
   172 static bool DetermineGraphicsPack()
   173 {
   173 {
   174 	if (_used_graphics_set != NULL) return;
   174 	if (_used_graphics_set != NULL) return true;
   175 
   175 
   176 	const GraphicsSet *best = _available_graphics_sets;
   176 	const GraphicsSet *best = _available_graphics_sets;
   177 	for (const GraphicsSet *c = _available_graphics_sets; c != NULL; c = c->next) {
   177 	for (const GraphicsSet *c = _available_graphics_sets; c != NULL; c = c->next) {
   178 		if (best->found_grfs < c->found_grfs ||
   178 		if (best->found_grfs < c->found_grfs ||
   179 				(best->found_grfs == c->found_grfs && best->shortname == c->shortname && best->version < c->version)) {
   179 				(best->found_grfs == c->found_grfs && best->shortname == c->shortname && best->version < c->version)) {
   180 			best = c;
   180 			best = c;
   181 		}
   181 		}
   182 	}
   182 	}
   183 
   183 
   184 	_used_graphics_set = best;
   184 	_used_graphics_set = best;
       
   185 	return _used_graphics_set != NULL;
   185 }
   186 }
   186 
   187 
   187 /**
   188 /**
   188  * Determine the palette that has to be used.
   189  * Determine the palette that has to be used.
   189  *  - forced palette via command line -> leave it that way
   190  *  - forced palette via command line -> leave it that way
   190  *  - otherwise -> palette based on the graphics pack
   191  *  - otherwise -> palette based on the graphics pack
   191  */
   192  */
   192 static void DeterminePalette()
   193 static void DeterminePalette()
   193 {
   194 {
       
   195 	assert(_used_graphics_set != NULL);
   194 	if (_use_palette < MAX_PAL) return;
   196 	if (_use_palette < MAX_PAL) return;
   195 
   197 
   196 	_use_palette = _used_graphics_set->palette;
   198 	_use_palette = _used_graphics_set->palette;
   197 }
   199 }
   198 
   200 
   201  *
   203  *
   202  * @note Also checks sample.cat and other required non-NewGRF GRFs for corruption.
   204  * @note Also checks sample.cat and other required non-NewGRF GRFs for corruption.
   203  */
   205  */
   204 void CheckExternalFiles()
   206 void CheckExternalFiles()
   205 {
   207 {
   206 	DetermineGraphicsPack();
       
   207 	DeterminePalette();
   208 	DeterminePalette();
   208 
   209 
   209 	static const size_t ERROR_MESSAGE_LENGTH = 128;
   210 	static const size_t ERROR_MESSAGE_LENGTH = 128;
   210 	char error_msg[ERROR_MESSAGE_LENGTH * (MAX_GFT + 1)];
   211 	char error_msg[ERROR_MESSAGE_LENGTH * (MAX_GFT + 1)];
   211 	error_msg[0] = '\0';
   212 	error_msg[0] = '\0';
   466  * @return true if it could be loaded
   467  * @return true if it could be loaded
   467  */
   468  */
   468 bool SetGraphicsSet(const char *name)
   469 bool SetGraphicsSet(const char *name)
   469 {
   470 {
   470 	if (StrEmpty(name)) {
   471 	if (StrEmpty(name)) {
   471 		DetermineGraphicsPack();
   472 		if (!DetermineGraphicsPack()) return false;
   472 		CheckExternalFiles();
   473 		CheckExternalFiles();
   473 		return true;
   474 		return true;
   474 	}
   475 	}
   475 
   476 
   476 	for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {
   477 	for (const GraphicsSet *g = _available_graphics_sets; g != NULL; g = g->next) {