90 return industry->xy != 0; |
90 return industry->xy != 0; |
91 } |
91 } |
92 |
92 |
93 VARDEF int _total_industries; |
93 VARDEF int _total_industries; |
94 |
94 |
95 static inline IndustryID GetIndustryArraySize(void) |
95 static inline IndustryID GetMaxIndustryIndex(void) |
96 { |
96 { |
97 /* TODO - This isn't the real content of the function, but |
97 /* TODO - This isn't the real content of the function, but |
98 * with the new pool-system this will be replaced with one that |
98 * with the new pool-system this will be replaced with one that |
99 * _really_ returns the highest index + 1. Now it just returns |
99 * _really_ returns the highest index. Now it just returns |
100 * the next safe value we are sure about everything is below. |
100 * the next safe value we are sure about everything is below. |
101 */ |
101 */ |
|
102 return _total_industries - 1; |
|
103 } |
|
104 |
|
105 static inline uint GetNumIndustries(void) |
|
106 { |
102 return _total_industries; |
107 return _total_industries; |
103 } |
108 } |
104 |
109 |
105 /** |
110 /** |
106 * Return a random valid town. |
111 * Return a random valid town. |
107 */ |
112 */ |
108 static inline Industry *GetRandomIndustry(void) |
113 static inline Industry *GetRandomIndustry(void) |
109 { |
114 { |
110 uint num = RandomRange(GetIndustryArraySize()); |
115 uint num = RandomRange(GetNumIndustries()); |
111 uint index = 0; |
116 uint index = 0; |
112 |
117 |
113 if (GetIndustryArraySize() == 0) return NULL; |
118 if (GetNumIndustries() == 0) return NULL; |
114 |
119 |
115 while (num > 0) { |
120 while (num > 0) { |
116 num--; |
121 num--; |
117 |
122 |
118 index++; |
123 index++; |
119 /* Make sure we have a valid industry */ |
124 /* Make sure we have a valid industry */ |
120 while (GetIndustry(index) == NULL) { |
125 while (GetIndustry(index) == NULL) { |
121 index++; |
126 index++; |
122 if (index == GetIndustryArraySize()) index = 0; |
127 if (index > GetMaxIndustryIndex()) index = 0; |
123 } |
128 } |
124 } |
129 } |
125 |
130 |
126 return GetIndustry(index); |
131 return GetIndustry(index); |
127 } |
132 } |