Changeset - r9450:4c97b7e77fa9
[Not reviewed]
master
0 4 0
belugas - 16 years ago 2008-06-03 03:06:16
belugas@openttd.org
(svn r13368) -Codechange: give house's min/max_date a better name, as it is really year, not date
4 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -1383,61 +1383,61 @@ static bool TownHouseChangeInfo(uint hid
 
				memcpy(housespec, &_house_specs[subs_id], sizeof(_house_specs[subs_id]));
 

	
 
				housespec->enabled = true;
 
				housespec->local_id = hid + i;
 
				housespec->substitute_id = subs_id;
 
				housespec->grffile = _cur_grffile;
 
				housespec->random_colour[0] = 0x04;  // those 4 random colours are the base colour
 
				housespec->random_colour[1] = 0x08;  // for all new houses
 
				housespec->random_colour[2] = 0x0C;  // they stand for red, blue, orange and green
 
				housespec->random_colour[3] = 0x06;
 

	
 
				/* Make sure that the third cargo type is valid in this
 
				 * climate. This can cause problems when copying the properties
 
				 * of a house that accepts food, where the new house is valid
 
				 * in the temperate climate. */
 
				if (!GetCargo(housespec->accepts_cargo[2])->IsValid()) {
 
					housespec->cargo_acceptance[2] = 0;
 
				}
 

	
 
				/**
 
				 * New houses do not (currently) expect to have a default start
 
				 * date before 1930, as this breaks the build date stuff.
 
				 * @see FinaliseHouseArray() for more details.
 
				 */
 
				if (housespec->min_date < 1930) housespec->min_date = 1930;
 
				if (housespec->min_year < 1930) housespec->min_year = 1930;
 

	
 
				_loaded_newgrf_features.has_newhouses = true;
 
			} break;
 

	
 
			case 0x09: // Building flags
 
				housespec->building_flags = (BuildingFlags)grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x0A: { // Availability years
 
				uint16 years = grf_load_word(&buf);
 
				housespec->min_date = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8);
 
				housespec->max_date = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8);
 
				housespec->min_year = GB(years, 0, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 0, 8);
 
				housespec->max_year = GB(years, 8, 8) > 150 ? MAX_YEAR : ORIGINAL_BASE_YEAR + GB(years, 8, 8);
 
			} break;
 

	
 
			case 0x0B: // Population
 
				housespec->population = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x0C: // Mail generation multiplier
 
				housespec->mail_generation = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x0D: // Passenger acceptance
 
			case 0x0E: // Mail acceptance
 
				housespec->cargo_acceptance[prop - 0x0D] = grf_load_byte(&buf);
 
				break;
 

	
 
			case 0x0F: { // Goods/candy, food/fizzy drinks acceptance
 
				int8 goods = grf_load_byte(&buf);
 

	
 
				/* If value of goods is negative, it means in fact food or, if in toyland, fizzy_drink acceptance.
 
				 * Else, we have "standard" 3rd cargo type, goods or candy, for toyland once more */
 
				CargoID cid = (goods >= 0) ? ((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_CANDY : CT_GOODS) :
 
						((_settings_game.game_creation.landscape == LT_TOYLAND) ? CT_FIZZY_DRINKS : CT_FOOD);
 

	
 
				/* Make sure the cargo type is valid in this climate. */
 
@@ -5564,67 +5564,67 @@ static void CalculateRefitMasks()
 
				ShipVehicleInfo *svi = &e->u.ship;
 
				if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
 
				if (svi->cargo_type == CT_INVALID) ei->climates = 0x80;
 
				break;
 
			}
 
		}
 
	}
 
}
 

	
 
/** Add all new houses to the house array. House properties can be set at any
 
 * time in the GRF file, so we can only add a house spec to the house array
 
 * after the file has finished loading. We also need to check the dates, due to
 
 * the TTDPatch behaviour described below that we need to emulate. */
 
static void FinaliseHouseArray()
 
{
 
	/* If there are no houses with start dates before 1930, then all houses
 
	 * with start dates of 1930 have them reset to 0. This is in order to be
 
	 * compatible with TTDPatch, where if no houses have start dates before
 
	 * 1930 and the date is before 1930, the game pretends that this is 1930.
 
	 * If there have been any houses defined with start dates before 1930 then
 
	 * the dates are left alone.
 
	 * On the other hand, why 1930? Just 'fix' the houses with the lowest
 
	 * minimum introduction date to 0.
 
	 */
 
	Year min_date = MAX_YEAR;
 
	Year min_year = MAX_YEAR;
 

	
 
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
 
		if (file->housespec == NULL) continue;
 

	
 
		for (int i = 0; i < HOUSE_MAX; i++) {
 
			HouseSpec *hs = file->housespec[i];
 
			if (hs != NULL) {
 
				_house_mngr.SetEntitySpec(hs);
 
				if (hs->min_date < min_date) min_date = hs->min_date;
 
				if (hs->min_year < min_year) min_year = hs->min_year;
 
			}
 
		}
 
	}
 

	
 
	if (min_date != 0) {
 
	if (min_year != 0) {
 
		for (int i = 0; i < HOUSE_MAX; i++) {
 
			HouseSpec *hs = GetHouseSpecs(i);
 

	
 
			if (hs->enabled && hs->min_date == min_date) hs->min_date = 0;
 
			if (hs->enabled && hs->min_year == min_year) hs->min_year = 0;
 
		}
 
	}
 
}
 

	
 
/** Add all new industries to the industry array. Industry properties can be set at any
 
 * time in the GRF file, so we can only add a industry spec to the industry array
 
 * after the file has finished loading. */
 
static void FinaliseIndustriesArray()
 
{
 
	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
 
		if (file->industryspec != NULL) {
 
			for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
				IndustrySpec *indsp = file->industryspec[i];
 

	
 
				if (indsp != NULL && indsp->enabled) {
 
					StringID strid;
 
					/* process the conversion of text at the end, so to be sure everything will be fine
 
					 * and available.  Check if it does not return undefind marker, which is a very good sign of a
 
					 * substitute industry who has not changed the string been examined, thus using it as such */
 
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
 
					if (strid != STR_UNDEFINED) indsp->name = strid;
 

	
 
					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
 
					if (strid != STR_UNDEFINED) indsp->closure_text = strid;
src/table/town_land.h
Show inline comments
 
@@ -1788,50 +1788,50 @@ assert_compile(lengthof(_town_draw_tile_
 
 * @param mxd last year it can be built
 
 * @param p   population
 
 * @param rc  cost multiplier for removing it
 
 * @param bn  building name
 
 * @param rr  rating decrease if removed
 
 * @param mg  mail generation multiplier
 
 * @param ca1 acceptance for 1st CargoID
 
 * @param ca2 acceptance for 2nd CargoID
 
 * @param ca3 acceptance for 3rd CargoID
 
 * @param bf  building flags (size, stadium etc...)
 
 * @param ba  building availability (zone, climate...)
 
 * @param cg1 1st CargoID available
 
 * @param cg2 2nd CargoID available
 
 * @param cg3 3rd CargoID available
 
 * @see HouseSpec
 
 */
 
#define MS(mnd, mxd, p, rc, bn, rr, mg, ca1, ca2, ca3, bf, ba, cg1, cg2, cg3) \
 
	{mnd, mxd, p, rc, bn, rr, mg, {ca1, ca2, ca3}, {cg1, cg2, cg3}, bf, ba, true, \
 
	 0, NULL, 0, 0, {0, 0, 0, 0}, 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, 0, 2, 0, 0, 0, NULL}
 
/** House specifications from original data */
 
static const HouseSpec _original_house_specs[] = {
 
	/**
 
	 *                                                              remove_rating_decrease
 
	 *                                                               |    mail_generation
 
	 *     min_date                                                  |    |    1st CargoID acceptance
 
	 *     |         max_date                                        |    |    |    2nd CargoID acceptance
 
	 *     min_year                                                  |    |    1st CargoID acceptance
 
	 *     |         max_year                                        |    |    |    2nd CargoID acceptance
 
	 *     |         |    population                                 |    |    |    |    3th CargoID acceptance
 
	 *     |         |    |    removal_cost                          |    |    |    |    |
 
	 *     |         |    |    |    building_name                    |    |    |    |    |
 
	 *     |         |    |    |    |                                |    |    |    |    |
 
	 *     |         |    |    |    |                                |    |    |    |    |
 
	 * +-building_flags   |    |    |                                |    |    |    |    |
 
	 * +-building_availability |    |                                |    |    |    |    |
 
	 * +-cargoID accepted |    |    |                                |    |    |    |    |
 
	 * |   |         |    |    |    |                                |    |    |    |    | */
 
	MS(1963, MAX_YEAR, 187, 150, STR_200F_TALL_OFFICE_BLOCK,      140,  70,   8,   3,   4,
 
	   TILE_SIZE_1x1,
 
	   HZ_TEMP | HZ_ZON5,
 
	   CT_PASSENGERS, CT_MAIL, CT_GOODS), //00
 
	MS(1957, MAX_YEAR,  85, 140, STR_2010_OFFICE_BLOCK,           130,  55,   8,   3,   4,
 
	   TILE_SIZE_1x1,
 
	   HZ_TEMP | HZ_ZON5 | HZ_ZON4,
 
	   CT_PASSENGERS, CT_MAIL, CT_GOODS), //01
 
	MS(1968, MAX_YEAR,  40, 100, STR_2011_SMALL_BLOCK_OF_FLATS,    90,  20,   8,   3,   1,
 
	   TILE_SIZE_1x1,
 
	   HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2,
 
	   CT_PASSENGERS, CT_MAIL, CT_GOODS), //02
 
	MS(   0, MAX_YEAR,   5,  90, STR_2012_CHURCH,                 230,   2,   2,   0,   0,
 
	   BUILDING_IS_CHURCH | TILE_SIZE_1x1,
 
	   HZ_TEMP | HZ_ZON4 | HZ_ZON3 | HZ_ZON2 | HZ_ZON1,
src/town.h
Show inline comments
 
@@ -191,50 +191,50 @@ struct Town : PoolItem<Town, TownID, &_T
 
	/** Calculate the max town noise
 
	 * The value is counted using the population divided by the content of the
 
	 * entry in town_noise_population corespondig to the town's tolerance.
 
	 * To this result, we add 3, which is the noise of the lowest airport.
 
	 * So user can at least buld that airport
 
	 * @return the maximum noise level the town will tolerate */
 
	inline uint16 MaxTownNoise() const {
 
		if (this->population == 0) return 0; // no population? no noise
 

	
 
		return ((this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3);
 
	}
 
};
 

	
 
/**
 
 * Get the current valid layout for the town
 
 * @return the active layout for this town
 
 */
 
inline TownLayout Town::GetActiveLayout() const
 
{
 
	return (_settings_game.economy.town_layout == TL_RANDOM) ? this->layout : _settings_game.economy.town_layout;
 
}
 

	
 
struct HouseSpec {
 
	/* Standard properties */
 
	Year min_date;                     ///< introduction year of the house
 
	Year max_date;                     ///< last year it can be built
 
	Year min_year;                     ///< introduction year of the house
 
	Year max_year;                     ///< last year it can be built
 
	byte population;                   ///< population (Zero on other tiles in multi tile house.)
 
	byte removal_cost;                 ///< cost multiplier for removing it
 
	StringID building_name;            ///< building name
 
	uint16 remove_rating_decrease;     ///< rating decrease if removed
 
	byte mail_generation;              ///< mail generation multiplier (tile based, as the acceptances below)
 
	byte cargo_acceptance[3];          ///< acceptance level for the cargo slots
 
	CargoID accepts_cargo[3];          ///< 3 input cargo slots
 
	BuildingFlags building_flags;      ///< some flags that describe the house (size, stadium etc...)
 
	HouseZones building_availability;  ///< where can it be built (climates, zones)
 
	bool enabled;                      ///< the house is available to build (true by default, but can be disabled by newgrf)
 

	
 
	/* NewHouses properties */
 
	HouseID substitute_id;             ///< which original house this one is based on
 
	struct SpriteGroup *spritegroup;   ///< pointer to the different sprites of the house
 
	HouseID override;                  ///< which house this one replaces
 
	uint16 callback_mask;              ///< House callback flags
 
	byte random_colour[4];             ///< 4 "random" colours
 
	byte probability;                  ///< Relative probability of appearing (16 is the standard value)
 
	HouseExtraFlags extra_flags;       ///< some more flags
 
	HouseClassID class_id;             ///< defines the class this house has (grf file based) @See HouseGetVariable, prop 0x44
 
	byte animation_frames;             ///< number of animation frames
 
	byte animation_speed;              ///< amount of time between each of those frames
 
	byte processing_time;              ///< Periodic refresh multiplier
 
	byte minimum_life;                 ///< The minimum number of years this house will survive before the town rebuilds it
src/town_cmd.cpp
Show inline comments
 
@@ -1910,49 +1910,49 @@ static bool BuildTownHouse(Town *t, Tile
 
		HouseID house = houses[i];
 
		probability_max -= probs[i];
 

	
 
		/* remove tested house from the set */
 
		num--;
 
		houses[i] = houses[num];
 
		probs[i] = probs[num];
 

	
 
		const HouseSpec *hs = GetHouseSpecs(house);
 

	
 
		if (_loaded_newgrf_features.has_newhouses) {
 
			if (hs->override != 0) {
 
				house = hs->override;
 
				hs = GetHouseSpecs(house);
 
			}
 

	
 
			if ((hs->extra_flags & BUILDING_IS_HISTORICAL) && !_generating_world) continue;
 

	
 
			if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
 
				uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house, t, tile);
 
				if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) == 0) continue;
 
			}
 
		}
 

	
 
		if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue;
 
		if (_cur_year < hs->min_year || _cur_year > hs->max_year) continue;
 

	
 
		/* Special houses that there can be only one of. */
 
		uint oneof = 0;
 

	
 
		if (hs->building_flags & BUILDING_IS_CHURCH) {
 
			SetBit(oneof, TOWN_HAS_CHURCH);
 
		} else if (hs->building_flags & BUILDING_IS_STADIUM) {
 
			SetBit(oneof, TOWN_HAS_STADIUM);
 
		}
 

	
 
		if (HASBITS(t->flags12 , oneof)) continue;
 

	
 
		/* Make sure there is no slope? */
 
		bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0;
 
		if (noslope && slope != SLOPE_FLAT) continue;
 

	
 
		if (hs->building_flags & TILE_SIZE_2x2) {
 
			if (!CheckTownBuild2x2House(&tile, t, maxz, noslope)) continue;
 
		} else if (hs->building_flags & TILE_SIZE_2x1) {
 
			if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SW)) continue;
 
		} else if (hs->building_flags & TILE_SIZE_1x2) {
 
			if (!CheckTownBuild2House(&tile, t, maxz, noslope, DIAGDIR_SE)) continue;
 
		} else {
 
			/* 1x1 house checks are already done */
0 comments (0 inline, 0 general)