src/industry_cmd.cpp
changeset 10146 cfea97f96067
parent 9938 69311c7f3af3
child 10207 c291a21b304e
equal deleted inserted replaced
10145:849ba8b8626b 10146:cfea97f96067
  2233 			ns,
  2233 			ns,
  2234 			i->xy + TileDiffXY(1, 1), 0);
  2234 			i->xy + TileDiffXY(1, 1), 0);
  2235 	}
  2235 	}
  2236 }
  2236 }
  2237 
  2237 
       
  2238 /** Daily handler for the industry changes
       
  2239  * Taking the original map size of 256*256, the number of random changes was always of just one unit.
       
  2240  * But it cannot be the same on smaller or bigger maps. That number has to be scaled up or down.
       
  2241  * For small maps, it implies that less than one change per month is required, while on bigger maps,
       
  2242  * it would be way more. The daily loop handles those changes. */
       
  2243 void IndustryDailyLoop()
       
  2244 {
       
  2245 	_economy.industry_daily_change_counter += _economy.industry_daily_increment;
       
  2246 
       
  2247 	/* Bits 16-31 of industry_construction_counter contain the number of industries to change/create today,
       
  2248 	 * the lower 16 bit are a fractional part that might accumulate over several days until it
       
  2249 	 * is sufficient for an industry. */
       
  2250 	uint16 change_loop = _economy.industry_daily_change_counter >> 16;
       
  2251 
       
  2252 	/* Reset the active part of the counter, just keeping the "factional part" */
       
  2253 	_economy.industry_daily_change_counter &= 0xFFFF;
       
  2254 
       
  2255 	if (change_loop == 0) {
       
  2256 		return;  // Nothing to do? get out
       
  2257 	}
       
  2258 
       
  2259 	PlayerID old_player = _current_player;
       
  2260 	_current_player = OWNER_NONE;
       
  2261 
       
  2262 	/* perform the required industry changes for the day */
       
  2263 	for (uint16 j = 0; j < change_loop; j++) {
       
  2264 		/* 3% chance that we start a new industry */
       
  2265 		if (Chance16(3, 100)) {
       
  2266 			MaybeNewIndustry();
       
  2267 		} else {
       
  2268 			Industry *i = GetRandomIndustry();
       
  2269 			if (i != NULL) ChangeIndustryProduction(i, false);
       
  2270 		}
       
  2271 	}
       
  2272 
       
  2273 	_current_player = old_player;
       
  2274 
       
  2275 	/* production-change */
       
  2276 	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
       
  2277 }
       
  2278 
  2238 void IndustryMonthlyLoop()
  2279 void IndustryMonthlyLoop()
  2239 {
  2280 {
  2240 	Industry *i;
  2281 	Industry *i;
  2241 	PlayerID old_player = _current_player;
  2282 	PlayerID old_player = _current_player;
  2242 	_current_player = OWNER_NONE;
  2283 	_current_player = OWNER_NONE;
  2246 		if (i->prod_level == PRODLEVEL_CLOSURE) {
  2287 		if (i->prod_level == PRODLEVEL_CLOSURE) {
  2247 			delete i;
  2288 			delete i;
  2248 		} else {
  2289 		} else {
  2249 			ChangeIndustryProduction(i, true);
  2290 			ChangeIndustryProduction(i, true);
  2250 		}
  2291 		}
  2251 	}
       
  2252 
       
  2253 	/* 3% chance that we start a new industry */
       
  2254 	if (Chance16(3, 100)) {
       
  2255 		MaybeNewIndustry();
       
  2256 	} else {
       
  2257 		i = GetRandomIndustry();
       
  2258 		if (i != NULL) ChangeIndustryProduction(i, false);
       
  2259 	}
  2292 	}
  2260 
  2293 
  2261 	_current_player = old_player;
  2294 	_current_player = old_player;
  2262 
  2295 
  2263 	/* production-change */
  2296 	/* production-change */