Changeset - r6636:cc9c312a5950
[Not reviewed]
master
0 8 0
belugas - 17 years ago 2007-05-18 00:33:47
belugas@openttd.org
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
8 files changed with 110 insertions and 158 deletions:
0 comments (0 inline, 0 general)
src/ai/default/default.cpp
Show inline comments
 
@@ -540,12 +540,13 @@ static void AiFindSubsidyPassengerRoute(
 
	fr->distance = DistanceManhattan(from->xy, to->xy);
 
}
 

	
 
static void AiFindRandomIndustryRoute(FoundRoute *fr)
 
{
 
	Industry* i;
 
	const IndustrySpec *indsp;
 
	uint32 r;
 
	CargoID cargo;
 

	
 
	// initially error
 
	fr->distance = -1;
 

	
 
@@ -553,29 +554,34 @@ static void AiFindRandomIndustryRoute(Fo
 

	
 
	// pick a source
 
	fr->from = i = AiFindRandomIndustry();
 
	if (i == NULL) return;
 

	
 
	// pick a random produced cargo
 
	cargo = i->produced_cargo[0];
 
	if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1];
 
	indsp = GetIndustrySpec(i->type);
 
	cargo = indsp->produced_cargo[0];
 
	if (r & 1 && indsp->produced_cargo[1] != CT_INVALID) cargo = indsp->produced_cargo[1];
 

	
 
	fr->cargo = cargo;
 

	
 
	// don't allow passengers
 
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) return;
 

	
 
	if (cargo != CT_GOODS && cargo != CT_FOOD) {
 
		// pick a dest, and see if it can receive
 
		Industry* i2 = AiFindRandomIndustry();
 

	
 
		if (i2 == NULL || i == i2 || (
 
					i2->accepts_cargo[0] != cargo &&
 
					i2->accepts_cargo[1] != cargo &&
 
					i2->accepts_cargo[2] != cargo)
 
				) {
 
		if (i2 == NULL) {
 
			return;
 
		}
 

	
 
		indsp = GetIndustrySpec(i2->type);
 

	
 
		if (i == i2 ||
 
				(indsp->accepts_cargo[0] != cargo &&
 
				indsp->accepts_cargo[1] != cargo &&
 
				indsp->accepts_cargo[2] != cargo)) {
 
			return;
 
		}
 

	
 
		fr->to = i2;
 
		fr->distance = DistanceManhattan(i->xy, i2->xy);
 
	} else {
 
@@ -661,15 +667,16 @@ static bool AiCheckIfRouteIsGood(Player 
 
		if (from->ratings[_current_player] < -100 ||
 
				to->ratings[_current_player] < -100) {
 
			return false;
 
		}
 
	} else {
 
		const Industry* i = (const Industry*)fr->from;
 

	
 
		if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 ||
 
				i->total_production[fr->cargo != i->produced_cargo[0]] == 0) {
 
		const IndustrySpec *indsp = GetIndustrySpec(i->type);
 

	
 
		if (i->pct_transported[fr->cargo != indsp->produced_cargo[0]] > 0x99 ||
 
				i->total_production[fr->cargo != indsp->produced_cargo[0]] == 0) {
 
			return false;
 
		}
 
	}
 

	
 
	p->ai.route_type_mask |= bitmask;
 
	return true;
src/ai/trolly/trolly.cpp
Show inline comments
 
@@ -268,21 +268,22 @@ static bool AiNew_Check_City_or_Industry
 

	
 
		// All check are okay, so we can build here!
 
		return true;
 
	}
 
	if (type == AI_INDUSTRY) {
 
		const Industry* i = GetIndustry(ic);
 
		const IndustrySpec *indsp = GetIndustrySpec(i->type);
 
		const Station* st;
 
		int count = 0;
 
		int j = 0;
 

	
 
		if (i->town != NULL && i->town->ratings[_current_player] < 0 && AI_CHANCE16(1, 4)) return false;
 

	
 
		// No limits on delevering stations!
 
		//  Or for industry that does not give anything yet
 
		if (i->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
 
		if (indsp->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
 

	
 
		if (i->total_production[0] - i->total_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
 

	
 
		// Check if we have build a station in this town the last 6 months
 
		//  else we don't do it. This is done, because stat updates can be slow
 
		//  and sometimes it takes up to 4 months before the stats are corectly.
 
@@ -299,19 +300,19 @@ static bool AiNew_Check_City_or_Industry
 
				count++;
 
			} else {
 
				// We do not own it, request some info about the station
 
				//  we want to know if this station gets the same good. If so,
 
				//  we want to know its rating. If it is too high, we are not going
 
				//  to build there
 
				if (i->produced_cargo[0] == CT_INVALID) continue;
 
				if (indsp->produced_cargo[0] == CT_INVALID) continue;
 
				// It does not take this cargo
 
				if (!st->goods[i->produced_cargo[0]].last_speed) continue;
 
				if (!st->goods[indsp->produced_cargo[0]].last_speed) continue;
 
				// Is it around our industry
 
				if (DistanceManhattan(st->xy, i->xy) > 5) continue;
 
				// It does take this cargo.. what is his rating?
 
				if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
 
				if (st->goods[indsp->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
 
				j++;
 
				// The rating is high.. a little chance that we still continue
 
				//  But if there are 2 stations of this size, we never go on...
 
				if (j == 1 && AI_CHANCE16(1, AI_CHECKCITY_CARGO_RATING_CHANCE)) continue;
 
				// We don't like this station :(
 
				return false;
 
@@ -455,37 +456,39 @@ static void AiNew_State_LocateRoute(Play
 
				p->ainew.to_tile = 0;
 

	
 
				return;
 
			}
 
		} else if (p->ainew.tbt == AI_TRUCK) {
 
			const Industry* ind_from = GetIndustry(p->ainew.from_ic);
 
			const IndustrySpec *indsp_from = GetIndustrySpec(ind_from->type);
 
			const Industry* ind_temp = GetIndustry(p->ainew.temp);
 
			const IndustrySpec *indsp_temp = GetIndustrySpec(ind_temp->type);
 
			bool found = false;
 
			int max_cargo = 0;
 
			uint i;
 

	
 
			// TODO: in max_cargo, also check other cargo (beside [0])
 
			// First we check if the from_ic produces cargo that this ic accepts
 
			if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
 
				for (i = 0; i < lengthof(ind_temp->accepts_cargo); i++) {
 
					if (ind_temp->accepts_cargo[i] == CT_INVALID) break;
 
					if (ind_from->produced_cargo[0] == ind_temp->accepts_cargo[i]) {
 
			if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
 
				for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) {
 
					if (indsp_temp->accepts_cargo[i] == CT_INVALID) break;
 
					if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) {
 
						// Found a compatible industry
 
						max_cargo = ind_from->total_production[0] - ind_from->total_transported[0];
 
						found = true;
 
						p->ainew.from_deliver = true;
 
						p->ainew.to_deliver = false;
 
						break;
 
					}
 
				}
 
			}
 
			if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
 
			if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
 
				// If not check if the current ic produces cargo that the from_ic accepts
 
				for (i = 0; i < lengthof(ind_from->accepts_cargo); i++) {
 
					if (ind_from->accepts_cargo[i] == CT_INVALID) break;
 
					if (ind_temp->produced_cargo[0] == ind_from->accepts_cargo[i]) {
 
				for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) {
 
					if (indsp_from->accepts_cargo[i] == CT_INVALID) break;
 
					if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) {
 
						// Found a compatbiel industry
 
						found = true;
 
						max_cargo = ind_temp->total_production[0] - ind_temp->total_transported[0];
 
						p->ainew.from_deliver = false;
 
						p->ainew.to_deliver = true;
 
						break;
 
@@ -498,15 +501,15 @@ static void AiNew_State_LocateRoute(Play
 
				uint distance = DistanceManhattan(ind_from->xy, ind_temp->xy);
 

	
 
				if (distance > AI_LOCATEROUTE_TRUCK_MIN_DISTANCE &&
 
						distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) {
 
					p->ainew.to_ic = p->ainew.temp;
 
					if (p->ainew.from_deliver) {
 
						p->ainew.cargo = ind_from->produced_cargo[0];
 
						p->ainew.cargo = indsp_from->produced_cargo[0];
 
					} else {
 
						p->ainew.cargo = ind_temp->produced_cargo[0];
 
						p->ainew.cargo = indsp_temp->produced_cargo[0];
 
					}
 
					p->ainew.state = AI_STATE_FIND_STATION;
 

	
 
					DEBUG(ai, 1, "[LocateRoute] found truck-route of %d tiles long (from %d to %d)",
 
						distance,
 
						p->ainew.from_ic,
src/economy.cpp
Show inline comments
 
@@ -954,27 +954,29 @@ static void FindSubsidyPassengerRoute(Fo
 
	fr->distance = DistanceManhattan(from->xy, to->xy);
 
}
 

	
 
static void FindSubsidyCargoRoute(FoundRoute *fr)
 
{
 
	Industry *i;
 
	const IndustrySpec *ind;
 
	int trans, total;
 
	CargoID cargo;
 

	
 
	fr->distance = (uint)-1;
 

	
 
	fr->from = i = GetRandomIndustry();
 
	if (i == NULL) return;
 
	ind = GetIndustrySpec(i->type);
 

	
 
	/* Randomize cargo type */
 
	if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
 
		cargo = i->produced_cargo[1];
 
	if (HASBIT(Random(), 0) && ind->produced_cargo[1] != CT_INVALID) {
 
		cargo = ind->produced_cargo[1];
 
		trans = i->pct_transported[1];
 
		total = i->total_production[1];
 
	} else {
 
		cargo = i->produced_cargo[0];
 
		cargo = ind->produced_cargo[0];
 
		trans = i->pct_transported[0];
 
		total = i->total_production[0];
 
	}
 

	
 
	/* Quit if no production in this industry
 
	 * or if the cargo type is passengers
 
@@ -995,19 +997,25 @@ static void FindSubsidyCargoRoute(FoundR
 

	
 
		fr->distance = DistanceManhattan(i->xy, t->xy);
 
		fr->to = t;
 
	} else {
 
		/* The destination is an industry */
 
		Industry *i2 = GetRandomIndustry();
 
		if (i2 == NULL) {
 
			return;
 
		}
 

	
 
		ind = GetIndustrySpec(i2->type);
 

	
 
		/* The industry must accept the cargo */
 
		if (i == i2 || i == NULL ||
 
				(cargo != i2->accepts_cargo[0] &&
 
				cargo != i2->accepts_cargo[1] &&
 
				cargo != i2->accepts_cargo[2]))
 
		if (i == i2 ||
 
				(cargo != ind->accepts_cargo[0] &&
 
				cargo != ind->accepts_cargo[1] &&
 
				cargo != ind->accepts_cargo[2])) {
 
			return;
 
		}
 
		fr->distance = DistanceManhattan(i->xy, i2->xy);
 
		fr->to = i2;
 
	}
 
}
 

	
 
static bool CheckSubsidyDuplicate(Subsidy *s)
src/industry.h
Show inline comments
 
@@ -64,16 +64,14 @@ DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour
 
 */
 
struct Industry {
 
	TileIndex xy;                   ///< coordinates of the primary tile the industry is built one
 
	byte width;
 
	byte height;
 
	const Town* town;               ///< Nearest town
 
	CargoID produced_cargo[2];      ///< 2 production cargo slots
 
	uint16 cargo_waiting[2];        ///< amount of cargo produced per cargo
 
	byte production_rate[2];        ///< production rate for each cargo
 
	CargoID accepts_cargo[3];       ///< 3 input cargo slots
 
	byte prod_level;                ///< general production level
 
	uint16 last_mo_production[2];   ///< stats of last month production per cargo
 
	uint16 last_mo_transported[2];  ///< stats of last month transport per cargo
 
	byte pct_transported[2];        ///< percentage transported per cargo
 
	uint16 total_production[2];     ///< total units produced per cargo
 
	uint16 total_transported[2];    ///< total units transported per cargo
src/industry_cmd.cpp
Show inline comments
 
@@ -52,32 +52,22 @@ static void IndustryPoolNewBlock(uint st
 
DEFINE_OLD_POOL(Industry, Industry, IndustryPoolNewBlock, NULL)
 

	
 
/**
 
 * Retrieve the type for this industry.  Although it is accessed by a tile,
 
 * it will return the general type of industry, and not the sprite index
 
 * as would do GetIndustryGfx.
 
 * The same information can be accessed by looking at Industry->type
 
 * @param tile that is queried
 
 * @pre IsTileType(tile, MP_INDUSTRY)
 
 * @return general type for this industry, as defined in industry.h
 
 **/
 
IndustryType GetIndustryType(TileIndex tile)
 
{
 
	IndustryGfx this_type = GetIndustryGfx(tile);
 
	IndustryType iloop;
 

	
 
	assert(IsTileType(tile, MP_INDUSTRY));
 

	
 
	for (iloop = IT_COAL_MINE; iloop < NUM_INDUSTRYTYPES; iloop += 1) {
 
		if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
 
				industry_gfx_Solver[iloop].MaxGfx + 1)) {
 
			return iloop;
 
		}
 
	}
 

	
 
	return IT_INVALID;  //we have not found equivalent, whatever the reason
 
	const Industry *ind = GetIndustry(GetIndustryIndex(tile));
 
	return IsValidIndustry(ind) ? ind->type : IT_INVALID;
 
}
 

	
 
/**
 
 * Accessor for array _industry_specs.
 
 * This will ensure at once : proper access and
 
 * not allowing modifications of it.
 
@@ -352,13 +342,13 @@ static void TransportIndustryGoods(TileI
 

	
 
		/* fluctuating economy? */
 
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
 

	
 
		i->last_mo_production[0] += cw;
 

	
 
		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
 
		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw);
 
		i->last_mo_transported[0] += am;
 
		if (am != 0) {
 
			uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
 

	
 
			if (newgfx != INDUTILE_NOANIM) {
 
				ResetIndustryConstructionStage(tile);
 
@@ -374,13 +364,13 @@ static void TransportIndustryGoods(TileI
 
		i->cargo_waiting[1] -= cw;
 

	
 
		if (_economy.fluct <= 0) cw = (cw + 1) / 2;
 

	
 
		i->last_mo_production[1] += cw;
 

	
 
		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
 
		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
 
		i->last_mo_transported[1] += am;
 
	}
 
}
 

	
 

	
 
static void AnimateTile_Industry(TileIndex tile)
 
@@ -749,13 +739,13 @@ static uint32 GetTileTrackStatus_Industr
 
{
 
	return 0;
 
}
 

	
 
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
 
{
 
	const Industry *i = GetIndustryByTile(tile);
 
	const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type);
 

	
 
	b[0] = i->produced_cargo[0];
 
	b[1] = i->produced_cargo[1];
 
}
 

	
 
static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, PlayerID new_player)
 
@@ -1330,13 +1320,13 @@ static bool CheckIfTooCloseToIndustry(Ti
 
		return true;
 

	
 
	FOR_ALL_INDUSTRIES(i) {
 
		/* check if an industry that accepts the same goods is nearby */
 
		if (DistanceMax(tile, i->xy) <= 14 &&
 
				indspec->accepts_cargo[0] != CT_INVALID &&
 
				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
 
				indspec->accepts_cargo[0] == indspec->accepts_cargo[0] && (
 
					_game_mode != GM_EDITOR ||
 
					!_patches.same_industry_close ||
 
					!_patches.multiple_industry_per_town
 
				)) {
 
			_error_message = STR_INDUSTRY_TOO_CLOSE;
 
			return false;
 
@@ -1381,17 +1371,12 @@ static void DoCreateNewIndustry(Industry
 

	
 
	_total_industries++;
 
	i->xy = tile;
 
	i->width = i->height = 0;
 
	i->type = 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];
 

	
 
	if (_patches.smooth_economy) {
 
		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);
 
@@ -1635,13 +1620,13 @@ static void ExtChangeIndustryProduction(
 
		case INDUSTRYLIFE_CLOSABLE:
 
			if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180))
 
				closeit = false;
 
			break;
 

	
 
		default: /* INDUSTRY_PRODUCTION */
 
			for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
 
			for (j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){
 
				uint32 r = Random();
 
				int old_prod, new_prod, percent;
 
				int mag;
 

	
 
				new_prod = old_prod = i->production_rate[j];
 
				if (CHANCE16I(20, 1024, r))
 
@@ -1661,13 +1646,13 @@ static void ExtChangeIndustryProduction(
 
				if (new_prod >= indspec->production_rate[j] / 4)
 
					closeit = false;
 

	
 
				mag = abs(percent);
 
				if (mag >= 10) {
 
					SetDParam(2, mag);
 
					SetDParam(0, GetCargo(i->produced_cargo[j])->name);
 
					SetDParam(0, GetCargo(indspec->produced_cargo[j])->name);
 
					SetDParam(1, i->index);
 
					AddNewsItem(
 
						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
 
						NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ECONOMY, 0),
 
						i->xy + TileDiffXY(1, 1), 0
 
					);
 
@@ -1690,46 +1675,32 @@ static void ExtChangeIndustryProduction(
 

	
 

	
 
static void UpdateIndustryStatistics(Industry *i)
 
{
 
	byte pct;
 
	bool refresh = false;
 
	const IndustrySpec *indsp = GetIndustrySpec(i->type);
 

	
 
	if (i->produced_cargo[0] != CT_INVALID) {
 
		pct = 0;
 
		if (i->last_mo_production[0] != 0) {
 
			i->last_prod_year = _cur_year;
 
			pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0], 255);
 
		}
 
		i->pct_transported[0] = pct;
 
	for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
 
		if (indsp->produced_cargo[j] != CT_INVALID) {
 
			pct = 0;
 
			if (i->last_mo_production[j] != 0) {
 
				i->last_prod_year = _cur_year;
 
				pct = min(i->last_mo_transported[j] * 256 / i->last_mo_production[j], 255);
 
			}
 
			i->pct_transported[j] = pct;
 

	
 
		i->total_production[0] = i->last_mo_production[0];
 
		i->last_mo_production[0] = 0;
 

	
 
		i->total_transported[0] = i->last_mo_transported[0];
 
		i->last_mo_transported[0] = 0;
 
		refresh = true;
 
	}
 

	
 
	if (i->produced_cargo[1] != CT_INVALID) {
 
		pct = 0;
 
		if (i->last_mo_production[1] != 0) {
 
			i->last_prod_year = _cur_year;
 
			pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1], 255);
 
			i->total_transported[j] = i->last_mo_transported[j];
 
			i->last_mo_transported[j] = 0;
 
			refresh = true;
 
		}
 
		i->pct_transported[1] = pct;
 

	
 
		i->total_production[1] = i->last_mo_production[1];
 
		i->last_mo_production[1] = 0;
 

	
 
		i->total_transported[1] = i->last_mo_transported[1];
 
		i->last_mo_transported[1] = 0;
 
		refresh = true;
 
	}
 

	
 

	
 
	if (refresh)
 
		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
 

	
 
	if (i->prod_level == 0) {
 
		DeleteIndustry(i);
 
	} else if (_patches.smooth_economy) {
 
@@ -1917,16 +1888,16 @@ extern const TileTypeProcs _tile_type_in
 
static const SaveLoad _industry_desc[] = {
 
	SLE_CONDVAR(Industry, xy,                  SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
 
	SLE_CONDVAR(Industry, xy,                  SLE_UINT32,                  6, SL_MAX_VERSION),
 
	    SLE_VAR(Industry, width,               SLE_UINT8),
 
	    SLE_VAR(Industry, height,              SLE_UINT8),
 
	    SLE_REF(Industry, town,                REF_TOWN),
 
	    SLE_ARR(Industry, produced_cargo,      SLE_UINT8,  2),
 
	SLE_CONDNULL( 2, 2, 60),       ///< used to be industry's produced_cargo
 
	    SLE_ARR(Industry, cargo_waiting,       SLE_UINT16, 2),
 
	    SLE_ARR(Industry, production_rate,     SLE_UINT8,  2),
 
	    SLE_ARR(Industry, accepts_cargo,       SLE_UINT8,  3),
 
	SLE_CONDNULL( 3, 2, 60),       ///< used to be industry's accepts_cargo
 
	    SLE_VAR(Industry, prod_level,          SLE_UINT8),
 
	    SLE_ARR(Industry, last_mo_production,  SLE_UINT16, 2),
 
	    SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2),
 
	    SLE_ARR(Industry, pct_transported,     SLE_UINT8,  2),
 
	    SLE_ARR(Industry, total_production,    SLE_UINT16, 2),
 
	    SLE_ARR(Industry, total_transported,   SLE_UINT16, 2),
src/industry_gui.cpp
Show inline comments
 
@@ -284,61 +284,63 @@ static inline bool isProductionMinimum(c
 
static inline bool isProductionMaximum(const Industry *i, int pt) {
 
	return i->production_rate[pt] == 255;
 
}
 

	
 
static inline bool IsProductionAlterable(const Industry *i)
 
{
 
	const IndustrySpec *ind = GetIndustrySpec(i->type);
 
	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
 
		     (i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
 
			(ind->accepts_cargo[0] == CT_INVALID || ind->accepts_cargo[0] == CT_VALUABLES));
 
}
 

	
 
static void IndustryViewWndProc(Window *w, WindowEvent *e)
 
{
 
	/* WP(w,vp2_d).data_1 is for the editbox line
 
	 * WP(w,vp2_d).data_2 is for the clickline
 
	 * WP(w,vp2_d).data_3 is for the click pos (left or right) */
 

	
 
	switch (e->event) {
 
	case WE_PAINT: {
 
		const Industry *i = GetIndustry(w->window_number);
 
		const IndustrySpec *ind = GetIndustrySpec(i->type);
 

	
 
		SetDParam(0, w->window_number);
 
		DrawWindowWidgets(w);
 

	
 
		if (i->accepts_cargo[0] != CT_INVALID) {
 
		if (ind->accepts_cargo[0] != CT_INVALID) {
 
			StringID str;
 

	
 
			SetDParam(0, GetCargo(i->accepts_cargo[0])->name);
 
			SetDParam(0, GetCargo(ind->accepts_cargo[0])->name);
 
			str = STR_4827_REQUIRES;
 
			if (i->accepts_cargo[1] != CT_INVALID) {
 
				SetDParam(1, GetCargo(i->accepts_cargo[1])->name);
 
			if (ind->accepts_cargo[1] != CT_INVALID) {
 
				SetDParam(1, GetCargo(ind->accepts_cargo[1])->name);
 
				str = STR_4828_REQUIRES;
 
				if (i->accepts_cargo[2] != CT_INVALID) {
 
					SetDParam(2, GetCargo(i->accepts_cargo[2])->name);
 
				if (ind->accepts_cargo[2] != CT_INVALID) {
 
					SetDParam(2, GetCargo(ind->accepts_cargo[2])->name);
 
					str = STR_4829_REQUIRES;
 
				}
 
			}
 
			DrawString(2, 107, str, 0);
 
		}
 

	
 
		if (i->produced_cargo[0] != CT_INVALID) {
 
		if (ind->produced_cargo[0] != CT_INVALID) {
 
			DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
 

	
 
			SetDParam(0, i->produced_cargo[0]);
 
			SetDParam(0, ind->produced_cargo[0]);
 
			SetDParam(1, i->total_production[0]);
 

	
 
			SetDParam(2, i->pct_transported[0] * 100 >> 8);
 
			DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 127, STR_482B_TRANSPORTED, 0);
 
			/* Let's put out those buttons.. */
 
			if (IsProductionAlterable(i)) {
 
				DrawArrowButtons(5, 127, 3, (WP(w, vp2_d).data_2 == 1) ? WP(w, vp2_d).data_3 : 0,
 
						!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
 
			}
 

	
 
			if (i->produced_cargo[1] != CT_INVALID) {
 
				SetDParam(0, i->produced_cargo[1]);
 
			if (ind->produced_cargo[1] != CT_INVALID) {
 
				SetDParam(0, ind->produced_cargo[1]);
 
				SetDParam(1, i->total_production[1]);
 
				SetDParam(2, i->pct_transported[1] * 100 >> 8);
 
				DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
 
				/* Let's put out those buttons.. */
 
				if (IsProductionAlterable(i)) {
 
					DrawArrowButtons(5, 137, 3, (WP(w, vp2_d).data_2 == 2) ? WP(w, vp2_d).data_3 : 0,
 
@@ -362,13 +364,14 @@ static void IndustryViewWndProc(Window *
 

	
 
			/* We should work if needed.. */
 
			if (!IsProductionAlterable(i)) return;
 

	
 
			x = e->we.click.pt.x;
 
			line = (e->we.click.pt.y - 127) / 10;
 
			if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
 
			if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) &&
 
					GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) {
 
				if (IS_INT_INSIDE(x, 5, 25) ) {
 
					/* Clicked buttons, decrease or increase production */
 
					if (x < 15) {
 
						if (isProductionMinimum(i, line)) return;
 
						i->production_rate[line] = max(i->production_rate[line] / 2, 1);
 
					} else {
 
@@ -413,17 +416,19 @@ static void IndustryViewWndProc(Window *
 
		}
 
	}
 
}
 

	
 
static void UpdateIndustryProduction(Industry *i)
 
{
 
	if (i->produced_cargo[0] != CT_INVALID)
 
		i->total_production[0] = 8 * i->production_rate[0];
 
	const IndustrySpec *ind = GetIndustrySpec(i->type);
 

	
 
	if (i->produced_cargo[1] != CT_INVALID)
 
		i->total_production[1] = 8 * i->production_rate[1];
 
	for (byte j = 0; j < lengthof(ind->produced_cargo); j++) {
 
		if (ind->produced_cargo[j] != CT_INVALID) {
 
			i->total_production[j] = 8 * i->production_rate[j];
 
		}
 
	}
 
}
 

	
 
static const Widget _industry_view_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,     9,     0,    10,     0,    13, STR_00C5,          STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,     9,    11,   247,     0,    13, STR_4801,          STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{  WWT_STICKYBOX,   RESIZE_NONE,     9,   248,   259,     0,    13, 0x0,               STR_STICKY_BUTTON},
 
@@ -479,12 +484,14 @@ static const Industry* _last_industry;
 
static byte _industry_sort_order;
 

	
 
static int CDECL GeneralIndustrySorter(const void *a, const void *b)
 
{
 
	const Industry* i = *(const Industry**)a;
 
	const Industry* j = *(const Industry**)b;
 
	const IndustrySpec *ind_i = GetIndustrySpec(i->type);
 
	const IndustrySpec *ind_j = GetIndustrySpec(j->type);
 
	int r;
 

	
 
	switch (_industry_sort_order >> 1) {
 
		default: NOT_REACHED();
 
		case 0: /* Sort by Name (handled later) */
 
			r = 0;
 
@@ -492,43 +499,43 @@ static int CDECL GeneralIndustrySorter(c
 

	
 
		case 1: /* Sort by Type */
 
			r = i->type - j->type;
 
			break;
 

	
 
		case 2: /* Sort by Production */
 
			if (i->produced_cargo[0] == CT_INVALID) {
 
				r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
 
			if (ind_i->produced_cargo[0] == CT_INVALID) {
 
				r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1);
 
			} else {
 
				if (j->produced_cargo[0] == CT_INVALID) {
 
				if (ind_j->produced_cargo[0] == CT_INVALID) {
 
					r = 1;
 
				} else {
 
					r =
 
						(i->total_production[0] + i->total_production[1]) -
 
						(j->total_production[0] + j->total_production[1]);
 
				}
 
			}
 
			break;
 

	
 
		case 3: /* Sort by transported fraction */
 
			if (i->produced_cargo[0] == CT_INVALID) {
 
				r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
 
			if (ind_i->produced_cargo[0] == CT_INVALID) {
 
				r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1);
 
			} else {
 
				if (j->produced_cargo[0] == CT_INVALID) {
 
				if (ind_j->produced_cargo[0] == CT_INVALID) {
 
					r = 1;
 
				} else {
 
					int pi;
 
					int pj;
 

	
 
					pi = i->pct_transported[0] * 100 >> 8;
 
					if (i->produced_cargo[1] != CT_INVALID) {
 
					if (ind_i->produced_cargo[1] != CT_INVALID) {
 
						int p = i->pct_transported[1] * 100 >> 8;
 
						if (p < pi) pi = p;
 
					}
 

	
 
					pj = j->pct_transported[0] * 100 >> 8;
 
					if (j->produced_cargo[1] != CT_INVALID) {
 
					if (ind_j->produced_cargo[1] != CT_INVALID) {
 
						int p = j->pct_transported[1] * 100 >> 8;
 
						if (p < pj) pj = p;
 
					}
 

	
 
					r = pi - pj;
 
				}
 
@@ -603,20 +610,21 @@ static void IndustryDirectoryWndProc(Win
 

	
 
		p = w->vscroll.pos;
 
		n = 0;
 

	
 
		while (p < _num_industry_sort) {
 
			const Industry* i = _industry_sort[p];
 
			const IndustrySpec *ind = GetIndustrySpec(i->type);
 

	
 
			SetDParam(0, i->index);
 
			if (i->produced_cargo[0] != CT_INVALID) {
 
				SetDParam(1, i->produced_cargo[0]);
 
			if (ind->produced_cargo[0] != CT_INVALID) {
 
				SetDParam(1, ind->produced_cargo[0]);
 
				SetDParam(2, i->total_production[0]);
 

	
 
				if (i->produced_cargo[1] != CT_INVALID) {
 
					SetDParam(3, i->produced_cargo[1]);
 
				if (ind->produced_cargo[1] != CT_INVALID) {
 
					SetDParam(3, ind->produced_cargo[1]);
 
					SetDParam(4, i->total_production[1]);
 
					SetDParam(5, i->pct_transported[0] * 100 >> 8);
 
					SetDParam(6, i->pct_transported[1] * 100 >> 8);
 
					DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, 0);
 
				} else {
 
					SetDParam(3, i->pct_transported[0] * 100 >> 8);
src/industry_map.h
Show inline comments
 
@@ -204,52 +204,12 @@ static inline void ResetIndustryConstruc
 
/** Structure used to make a mapping from industry gfx to industry type */
 
struct IndustryTypeSolver {
 
	IndustryGfx MinGfx; ///< The first gfx index for the industry type
 
	IndustryGfx MaxGfx; ///< The last gfx index for the industry type
 
};
 

	
 
/** Mapping of industry gfx to industry type */
 
static const IndustryTypeSolver industry_gfx_Solver[IT_END] = {
 
	{  0,   6}, ///< IT_COAL_MINE
 
	{  7,  10}, ///< IT_POWER_STATION,
 
	{ 11,  15}, ///< IT_SAWMILL,
 
	{ 16,  17}, ///< IT_FOREST,
 
	{ 18,  23}, ///< IT_OIL_REFINERY,
 
	{ 24,  28}, ///< IT_OIL_RIG,
 
	{ 29,  31}, ///< IT_OIL_WELL,
 
	{ 32,  38}, ///< IT_FARM,
 
	{ 39,  42}, ///< IT_FACTORY,
 
	{ 43,  46}, ///< IT_PRINTING_WORKS,
 
	{ 47,  51}, ///< IT_COPPER_MINE,
 
	{ 52,  57}, ///< IT_STEEL_MILL,
 
	{ 58,  59}, ///< IT_BANK_TEMP,
 
	{ 60,  63}, ///< IT_FOOD_PROCESS,
 
	{ 64,  71}, ///< IT_PAPER_MILL,
 
	{ 72,  88}, ///< IT_GOLD_MINE,
 
	{ 89,  90}, ///< IT_BANK_TROPIC_ARCTIC,
 
	{ 91,  99}, ///< IT_DIAMOND_MINE,
 
	{100, 115}, ///< IT_IRON_MINE,
 
	{116, 116}, ///< IT_FRUIT_PLANTATION,
 
	{117, 117}, ///< IT_RUBBER_PLANTATION,
 
	{118, 119}, ///< IT_WATER_SUPPLY,
 
	{120, 120}, ///< IT_WATER_TOWER,
 
	{121, 124}, ///< IT_FACTORY_2,
 
	{125, 128}, ///< IT_LUMBER_MILL,
 
	{129, 130}, ///< IT_COTTON_CANDY,
 
	{131, 134}, ///< IT_CANDY_FACTORY or sweet factory
 
	{135, 136}, ///< IT_BATTERY_FARM,
 
	{137, 137}, ///< IT_COLA_WELLS,
 
	{138, 141}, ///< IT_TOY_SHOP,
 
	{142, 147}, ///< IT_TOY_FACTORY,
 
	{148, 155}, ///< IT_PLASTIC_FOUNTAINS,
 
	{156, 159}, ///< IT_FIZZY_DRINK_FACTORY,
 
	{160, 163}, ///< IT_BUBBLE_GENERATOR,
 
	{164, 166}, ///< IT_TOFFEE_QUARRY,
 
	{167, 174}  ///< IT_SUGAR_MINE,
 
};
 

	
 
/**
 
 * Get the animation loop number
 
 * @param tile the tile to get the animation loop number of
 
 * @pre IsTileType(tile, MP_INDUSTRY)
 
 */
 
static inline byte GetIndustryAnimationLoop(TileIndex tile)
src/oldloader.cpp
Show inline comments
 
@@ -648,24 +648,21 @@ static bool LoadOldStation(LoadgameState
 

	
 
static const OldChunks industry_chunk[] = {
 
	OCL_SVAR(   OC_TILE, Industry, xy ),
 
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
 
	OCL_SVAR(  OC_UINT8, Industry, width ),
 
	OCL_SVAR(  OC_UINT8, Industry, height ),
 
	OCL_SVAR(  OC_UINT8, Industry, produced_cargo[0] ),
 
	OCL_SVAR(  OC_UINT8, Industry, produced_cargo[1] ),
 
	OCL_NULL( 2 ),  ///< used to be industry's produced_cargo
 

	
 
	OCL_SVAR( OC_UINT16, Industry, cargo_waiting[0] ),
 
	OCL_SVAR( OC_UINT16, Industry, cargo_waiting[1] ),
 

	
 
	OCL_SVAR(  OC_UINT8, Industry, production_rate[0] ),
 
	OCL_SVAR(  OC_UINT8, Industry, production_rate[1] ),
 

	
 
	OCL_SVAR(  OC_UINT8, Industry, accepts_cargo[0] ),
 
	OCL_SVAR(  OC_UINT8, Industry, accepts_cargo[1] ),
 
	OCL_SVAR(  OC_UINT8, Industry, accepts_cargo[2] ),
 
	OCL_NULL( 3 ),  ///< used to be industry's accepts_cargo
 

	
 
	OCL_SVAR(  OC_UINT8, Industry, prod_level ),
 

	
 
	OCL_SVAR( OC_UINT16, Industry, last_mo_production[0] ),
 
	OCL_SVAR( OC_UINT16, Industry, last_mo_production[1] ),
 
	OCL_SVAR( OC_UINT16, Industry, last_mo_transported[0] ),
0 comments (0 inline, 0 general)