Changeset - r7947:2da5c8f07e0d
[Not reviewed]
master
0 1 0
glx - 17 years ago 2007-11-23 16:50:54
glx@openttd.org
(svn r11502) -Fix (r11144): don't do standard production change if callbacks 29/35 failed
-Fix (r11144): disable smooth economy for industries using callbacks 29/35
1 file changed with 11 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1419,26 +1419,29 @@ static void DoCreateNewIndustry(Industry
 
	i->width = i->height = 0;
 
	i->type = type;
 
	IncIndustryTypeCount(type);
 

	
 
	i->produced_cargo[0] = indspec->produced_cargo[0];
 
	i->produced_cargo[1] = indspec->produced_cargo[1];
 
	i->accepts_cargo[0] = indspec->accepts_cargo[0];
 
	i->accepts_cargo[1] = indspec->accepts_cargo[1];
 
	i->accepts_cargo[2] = indspec->accepts_cargo[2];
 
	i->production_rate[0] = indspec->production_rate[0];
 
	i->production_rate[1] = indspec->production_rate[1];
 

	
 
	/* don't use smooth economy for industries using production callbacks */
 
	if (_patches.smooth_economy  && !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL))) {
 
	/* don't use smooth economy for industries using production related callbacks */
 
	if (_patches.smooth_economy &&
 
	    !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
 
	    !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE))             // production change callbacks
 
	) {
 
		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
 
		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
 
	}
 

	
 
	i->town = t;
 
	i->owner = owner;
 

	
 
	r = Random();
 
	i->random_color = GB(r, 0, 4);
 
	i->counter = GB(r, 4, 12);
 
	i->random = GB(r, 16, 16);
 
	i->produced_cargo_waiting[0] = 0;
 
@@ -1992,33 +1995,36 @@ enum {
 
/** Change industry production or do closure
 
 * @param i Industry for which changes are performed
 
 * @param monthly true if it's the monthly call, false if it's the random call
 
 */
 
static void ChangeIndustryProduction(Industry *i, bool monthly)
 
{
 
	extern StringID MapGRFStringID(uint32 grfid, StringID str);
 
	StringID str = STR_NULL;
 
	bool closeit = false;
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 
	bool standard = true;
 
	bool suppress_message = false;
 
	/* don't use smooth economy for industries using production callbacks */
 
	bool smooth_economy = _patches.smooth_economy && !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL));
 
	/* don't use smooth economy for industries using production related callbacks */
 
	bool smooth_economy = _patches.smooth_economy &&
 
	                      !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
 
	                      !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE));            // production change callbacks
 
	byte div = 0;
 
	byte mul = 0;
 

	
 
	if (HasBit(indspec->callback_flags, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE)) {
 
		uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy);
 
		standard = false;
 
		monthly = false; // smooth economy is disabled so we need to fake random industry production change to allow 'use standard' result
 
		if (res != CALLBACK_FAILED) {
 
			standard = false;
 
			suppress_message = HasBit(res, 7);
 
			/* Get the custom message if any */
 
			if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grffile->grfid, GB(GetRegister(0x100), 0, 16));
 
			res = GB(res, 0, 4);
 
			switch(res) {
 
				default: NOT_REACHED();
 
				case 0x0: break;                  // Do nothing, but show the custom message if any
 
				case 0x1: div = 1; break;         // Halve industry production. If production reaches the quarter of the default, the industry is closed instead.
 
				case 0x2: mul = 1; break;         // Double industry production if it hasn't reached eight times of the original yet.
 
				case 0x3: closeit = true; break;  // The industry announces imminent closure, and is physically removed from the map next month.
 
				case 0x4: standard = true; break; // Do the standard random production change as if this industry was a primary one.
 
				case 0x5: case 0x6: case 0x7:     // Divide production by 4, 8, 16
0 comments (0 inline, 0 general)