src/industry_gui.cpp
changeset 6200 10efd7fb90d4
parent 6091 c8827d9ae04a
child 6201 bee01dc45e39
equal deleted inserted replaced
6199:707e6a239878 6200:10efd7fb90d4
   550 
   550 
   551 	if (_industry_sort_order & 1) r = -r;
   551 	if (_industry_sort_order & 1) r = -r;
   552 	return r;
   552 	return r;
   553 }
   553 }
   554 
   554 
       
   555 /**
       
   556  * Makes a sorted industry list.
       
   557  * When there are no industries, the list has to be made. This so when one
       
   558  * starts a new game without industries after playing a game with industries
       
   559  * the list is not populated with invalid industries from the previous game.
       
   560  */
   555 static void MakeSortedIndustryList(void)
   561 static void MakeSortedIndustryList(void)
   556 {
   562 {
   557 	const Industry* i;
   563 	const Industry* i;
   558 	int n = 0;
   564 	int n = 0;
   559 
       
   560 	/* Don't attempt a sort if there are no industries */
       
   561 	if (GetNumIndustries() == 0) return;
       
   562 
   565 
   563 	/* Create array for sorting */
   566 	/* Create array for sorting */
   564 	_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
   567 	_industry_sort = ReallocT(_industry_sort, GetMaxIndustryIndex() + 1);
   565 	if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
   568 	if (_industry_sort == NULL) error("Could not allocate memory for the industry-sorting-list");
   566 
   569 
   567 	FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
   570 	/* Don't attempt a sort if there are no industries */
       
   571 	if (GetNumIndustries() != 0) {
       
   572 		FOR_ALL_INDUSTRIES(i) _industry_sort[n++] = i;
       
   573 		qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
       
   574 	}
   568 
   575 
   569 	_num_industry_sort = n;
   576 	_num_industry_sort = n;
   570 	_last_industry = NULL; // used for "cache"
   577 	_last_industry = NULL; // used for "cache"
   571 
       
   572 	qsort((void*)_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
       
   573 
   578 
   574 	DEBUG(misc, 3, "Resorting industries list");
   579 	DEBUG(misc, 3, "Resorting industries list");
   575 }
   580 }
   576 
   581 
   577 
   582