town.h
changeset 4356 ec4e13f21cd0
parent 4354 10f4ce894eb1
child 4357 aaba385fa723
equal deleted inserted replaced
4355:40a44dbba8d3 4356:ec4e13f21cd0
   189 	 *  the next safe value we are sure about everything is below.
   189 	 *  the next safe value we are sure about everything is below.
   190 	 */
   190 	 */
   191 	return _total_towns + 1;
   191 	return _total_towns + 1;
   192 }
   192 }
   193 
   193 
       
   194 /**
       
   195  * Return a random valid town.
       
   196  */
       
   197 static inline Town *GetRandomTown(void)
       
   198 {
       
   199 	uint num = RandomRange(GetTownArraySize());
       
   200 	uint index = 0;
       
   201 
       
   202 	while (num > 0) {
       
   203 		num--;
       
   204 
       
   205 		index++;
       
   206 		/* Make sure we have a valid industry */
       
   207 		while (GetTown(index) == NULL) {
       
   208 			index++;
       
   209 			if (index == GetTownArraySize()) index = 0;
       
   210 		}
       
   211 	}
       
   212 
       
   213 	return GetTown(index);
       
   214 }
       
   215 
   194 static inline bool IsValidTownID(uint index)
   216 static inline bool IsValidTownID(uint index)
   195 {
   217 {
   196 	return index < GetTownPoolSize() && IsValidTown(GetTown(index));
   218 	return index < GetTownPoolSize() && IsValidTown(GetTown(index));
   197 }
   219 }
   198 
   220