Changeset - r19358:6fdb5dc2b851
[Not reviewed]
master
0 4 0
frosch - 12 years ago 2012-05-25 17:23:19
frosch@openttd.org
(svn r24273) -Fix: [NewGRF] GetReverseCargoTranslation() was unnecessary complicated and also returned the wrong thing for cargos not present in the translation table.
4 files changed with 2 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/newgrf_cargo.cpp
Show inline comments
 
@@ -117,27 +117,12 @@ CargoID GetCargoTranslation(uint8 cargo,
 
	/* Other cases use (possibly translated) cargobits */
 

	
 
	if (grffile->cargo_max > 0) {
 
		/* ...and the cargo is in bounds, then get the cargo ID for
 
		 * the label */
 
		if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
 
	} else {
 
		/* Else the cargo value is a 'climate independent' 'bitnum' */
 
		return GetCargoIDByBitnum(cargo);
 
	}
 
	return CT_INVALID;
 
}
 

	
 
uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile)
 
{
 
	/* Note: All grf versions use CargoBit here. Pre-version 7 do NOT use the 'climate dependent' ID. */
 
	const CargoSpec *cs = CargoSpec::Get(cargo);
 

	
 
	/* If the GRF contains a translation table (and the cargo is in the table)
 
	 * then get the cargo ID for the label */
 
	for (uint i = 0; i < grffile->cargo_max; i++) {
 
		if (cs->label == grffile->cargo_list[i]) return i;
 
	}
 

	
 
	/* No matching label was found, so we return the 'climate independent' 'bitnum' */
 
	return cs->bitnum;
 
}
src/newgrf_cargo.h
Show inline comments
 
@@ -18,15 +18,14 @@
 

	
 
static const CargoID CT_DEFAULT      = NUM_CARGO + 0;
 
static const CargoID CT_PURCHASE     = NUM_CARGO + 1;
 
static const CargoID CT_DEFAULT_NA   = NUM_CARGO + 2;
 

	
 
/* Forward declarations of structs used */
 
struct CargoSpec;
 
struct GRFFile;
 

	
 
SpriteID GetCustomCargoSprite(const CargoSpec *cs);
 
uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs);
 
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit = false);
 
uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile);
 

	
 
#endif /* NEWGRF_CARGO_H */
src/newgrf_industries.cpp
Show inline comments
 
@@ -648,18 +648,18 @@ void GetIndustryResolver(ResolverObject 
 
 * @param ind The industry to query.
 
 * @param cargo_type The cargo to get information about.
 
 * @pre cargo_type is in ind->accepts_cargo.
 
 * @return Whether the given industry refuses to accept this cargo type.
 
 */
 
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
 
{
 
	assert(cargo_type == ind->accepts_cargo[0] || cargo_type == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]);
 

	
 
	const IndustrySpec *indspec = GetIndustrySpec(ind->type);
 
	if (HasBit(indspec->callback_mask, CBM_IND_REFUSE_CARGO)) {
 
		uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO,
 
				0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile),
 
				0, indspec->grf_prop.grffile->cargo_map[cargo_type],
 
				ind, ind->type, ind->location.tile);
 
		if (res != CALLBACK_FAILED) return !ConvertBooleanCallback(indspec->grf_prop.grffile, CBID_INDUSTRY_REFUSE_CARGO, res);
 
	}
 
	return false;
 
}
src/newgrf_station.cpp
Show inline comments
 
@@ -949,25 +949,25 @@ void TriggerStationAnimation(BaseStation
 
	uint16 random_bits = Random();
 
	ETileArea area = ETileArea(st, tile, tas[trigger]);
 

	
 
	/* Check all tiles over the station to check if the specindex is still in use */
 
	TILE_AREA_LOOP(tile, area) {
 
		if (st->TileBelongsToRailStation(tile)) {
 
			const StationSpec *ss = GetStationSpec(tile);
 
			if (ss != NULL && HasBit(ss->animation.triggers, trigger)) {
 
				CargoID cargo;
 
				if (cargo_type == CT_INVALID) {
 
					cargo = CT_INVALID;
 
				} else {
 
					cargo = GetReverseCargoTranslation(cargo_type, ss->grf_prop.grffile);
 
					cargo = ss->grf_prop.grffile->cargo_map[cargo_type];
 
				}
 
				StationAnimationBase::ChangeAnimationFrame(CBID_STATION_ANIM_START_STOP, ss, st, tile, (random_bits << 16) | Random(), (uint8)trigger | (cargo << 8));
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Update the cached animation trigger bitmask for a station.
 
 * @param st Station to update.
 
 */
 
void StationUpdateAnimTriggers(BaseStation *st)
0 comments (0 inline, 0 general)